Commit 15625736 by shiwenbo

给场站和购砂单位系统提供common/batch接口

parent 4aa5060b
...@@ -5,6 +5,8 @@ import java.util.ArrayList; ...@@ -5,6 +5,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -36,6 +38,12 @@ import com.beecode.bcp.biz.BusinessException; ...@@ -36,6 +38,12 @@ import com.beecode.bcp.biz.BusinessException;
import com.beecode.bcp.query.scene.ScenePrecidate; import com.beecode.bcp.query.scene.ScenePrecidate;
import com.beecode.bcp.type.KObject; import com.beecode.bcp.type.KObject;
import com.beecode.bcp.type.json.JSONObjectUtils; import com.beecode.bcp.type.json.JSONObjectUtils;
import com.beecode.inz.common.BatchDeleteItem;
import com.beecode.inz.common.BatchDiscardItem;
import com.beecode.inz.common.BatchUpdatePICItem;
import com.beecode.inz.common.enumeration.BatchOperationEnum;
import com.beecode.inz.common.service.CommonService;
import com.beecode.inz.common.service.FollowerService;
import com.beecode.inz.query.define.QueryDefinition; import com.beecode.inz.query.define.QueryDefinition;
import com.beecode.inz.query.entity.PaginationResult; import com.beecode.inz.query.entity.PaginationResult;
import com.beecode.inz.query.exception.QueryException; import com.beecode.inz.query.exception.QueryException;
...@@ -61,6 +69,15 @@ public class SandQueryController { ...@@ -61,6 +69,15 @@ public class SandQueryController {
private PrivilegeService privilegeService; private PrivilegeService privilegeService;
@Autowired @Autowired
private HttpServletRequest request;
@Autowired
private CommonService commonService;
@Autowired
private FollowerService followerService;
@Autowired
MultipartProperties multipartProperties; MultipartProperties multipartProperties;
...@@ -69,6 +86,95 @@ public class SandQueryController { ...@@ -69,6 +86,95 @@ public class SandQueryController {
private static final ObjectMapper OBJECTMAPPER = new ObjectMapper(); private static final ObjectMapper OBJECTMAPPER = new ObjectMapper();
@ResponseBody @ResponseBody
@RequestMapping(value = "/sand/user/common/batch", method = RequestMethod.PUT)
public void batchOperation(@RequestBody String body){
String operation = request.getHeader("operation");
BatchOperationEnum oper = null;
try {
oper = BatchOperationEnum.valueOf(operation.toUpperCase());
} catch (Exception e) {
logger.error("not support common batch operation,operation: {}", operation);
throw new UnsupportedOperationException("not support common batch operation,operation: " + operation);
}
switch (oper) {
case BATCH_UPDATE_PIC:
BatchUpdatePICItem[] batchUpdatePICs = handleBatchUpdatePICInputs(body);
commonService.batchUpdatePIC(batchUpdatePICs);
//如果负责人已经在相关团队里面了,从相关团队里面移除
for (BatchUpdatePICItem batchUpdatePICItem : batchUpdatePICs) {
UUID[] entityIds = batchUpdatePICItem.getIds();
for (UUID entityID : entityIds) {
followerService.removeStaff(batchUpdatePICItem.getDatamodelName(), entityID, batchUpdatePICItem.getPic().getId());
}
}
return;
case BATCH_DISCARD:
BatchDiscardItem[] batchDiscards = handleBatchDiscardInputs(body);
commonService.batchDiscard(batchDiscards);
return;
case BATCH_DELETE:
BatchDeleteItem[] batchDeletes = handleBatchDeleteInputs(body);
commonService.batchDelete(batchDeletes);
return;
default:
logger.error("not support common batch operation,operation: {}", operation);
throw new UnsupportedOperationException("not support common batch operation,operation: " + operation);
}
}
private BatchUpdatePICItem[] handleBatchUpdatePICInputs(String body){
try{
List<BatchUpdatePICItem> list = new ArrayList<BatchUpdatePICItem>();
JSONArray arr = new JSONArray(body);
if(arr.length() == 0){
throw new RuntimeException("batch update PIC items must not be 0!");
}
for(int i = 0; i < arr.length(); i ++){
list.add(new BatchUpdatePICItem(arr.getJSONObject(i)));
};
return list.toArray(new BatchUpdatePICItem[0]);
}catch(Exception e){
logger.error("illegal Argument,body: {}", body);
throw new IllegalArgumentException("illegal Argument,body: " + body, e);
}
}
private BatchDiscardItem[] handleBatchDiscardInputs(String body){
try{
List<BatchDiscardItem> list = new ArrayList<BatchDiscardItem>();
JSONArray arr = new JSONArray(body);
if(arr.length() == 0){
throw new RuntimeException("batch discard items must not be 0!");
}
for(int i = 0; i < arr.length(); i ++){
list.add(new BatchDiscardItem(arr.getJSONObject(i)));
};
return list.toArray(new BatchDiscardItem[0]);
}catch(Exception e){
logger.error("illegal Argument,body: {}", body);
throw new IllegalArgumentException("illegal Argument,body: " + body, e);
}
}
private BatchDeleteItem[] handleBatchDeleteInputs(String body) {
try{
List<BatchDeleteItem> list = new ArrayList<BatchDeleteItem>();
JSONArray arr = new JSONArray(body);
if(arr.length() == 0){
throw new RuntimeException("batch delete items must not be 0!");
}
for(int i = 0; i < arr.length(); i ++){
list.add(new BatchDeleteItem(arr.getJSONObject(i)));
};
return list.toArray(new BatchDeleteItem[0]);
}catch(Exception e){
logger.error("illegal Argument,body: {}", body);
throw new IllegalArgumentException("illegal Argument,body: " + body, e);
}
}
@ResponseBody
@RequestMapping(value="/sand/user/common/config/getMaxFileSize", method = RequestMethod.GET, consumes = "application/json") @RequestMapping(value="/sand/user/common/config/getMaxFileSize", method = RequestMethod.GET, consumes = "application/json")
public String getMaxFileSize() { public String getMaxFileSize() {
JSONObject o = new JSONObject(); JSONObject o = new JSONObject();
......
...@@ -5,6 +5,8 @@ import java.util.ArrayList; ...@@ -5,6 +5,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -36,6 +38,12 @@ import com.beecode.bcp.biz.BusinessException; ...@@ -36,6 +38,12 @@ import com.beecode.bcp.biz.BusinessException;
import com.beecode.bcp.query.scene.ScenePrecidate; import com.beecode.bcp.query.scene.ScenePrecidate;
import com.beecode.bcp.type.KObject; import com.beecode.bcp.type.KObject;
import com.beecode.bcp.type.json.JSONObjectUtils; import com.beecode.bcp.type.json.JSONObjectUtils;
import com.beecode.inz.common.BatchDeleteItem;
import com.beecode.inz.common.BatchDiscardItem;
import com.beecode.inz.common.BatchUpdatePICItem;
import com.beecode.inz.common.enumeration.BatchOperationEnum;
import com.beecode.inz.common.service.CommonService;
import com.beecode.inz.common.service.FollowerService;
import com.beecode.inz.query.define.QueryDefinition; import com.beecode.inz.query.define.QueryDefinition;
import com.beecode.inz.query.entity.PaginationResult; import com.beecode.inz.query.entity.PaginationResult;
import com.beecode.inz.query.exception.QueryException; import com.beecode.inz.query.exception.QueryException;
...@@ -61,6 +69,15 @@ public class WarehouseQueryController { ...@@ -61,6 +69,15 @@ public class WarehouseQueryController {
private PrivilegeService privilegeService; private PrivilegeService privilegeService;
@Autowired @Autowired
private HttpServletRequest request;
@Autowired
private CommonService commonService;
@Autowired
private FollowerService followerService;
@Autowired
MultipartProperties multipartProperties; MultipartProperties multipartProperties;
...@@ -69,6 +86,95 @@ public class WarehouseQueryController { ...@@ -69,6 +86,95 @@ public class WarehouseQueryController {
private static final ObjectMapper OBJECTMAPPER = new ObjectMapper(); private static final ObjectMapper OBJECTMAPPER = new ObjectMapper();
@ResponseBody @ResponseBody
@RequestMapping(value = "/warehouse/api/common/batch", method = RequestMethod.PUT)
public void batchOperation(@RequestBody String body){
String operation = request.getHeader("operation");
BatchOperationEnum oper = null;
try {
oper = BatchOperationEnum.valueOf(operation.toUpperCase());
} catch (Exception e) {
logger.error("not support common batch operation,operation: {}", operation);
throw new UnsupportedOperationException("not support common batch operation,operation: " + operation);
}
switch (oper) {
case BATCH_UPDATE_PIC:
BatchUpdatePICItem[] batchUpdatePICs = handleBatchUpdatePICInputs(body);
commonService.batchUpdatePIC(batchUpdatePICs);
//如果负责人已经在相关团队里面了,从相关团队里面移除
for (BatchUpdatePICItem batchUpdatePICItem : batchUpdatePICs) {
UUID[] entityIds = batchUpdatePICItem.getIds();
for (UUID entityID : entityIds) {
followerService.removeStaff(batchUpdatePICItem.getDatamodelName(), entityID, batchUpdatePICItem.getPic().getId());
}
}
return;
case BATCH_DISCARD:
BatchDiscardItem[] batchDiscards = handleBatchDiscardInputs(body);
commonService.batchDiscard(batchDiscards);
return;
case BATCH_DELETE:
BatchDeleteItem[] batchDeletes = handleBatchDeleteInputs(body);
commonService.batchDelete(batchDeletes);
return;
default:
logger.error("not support common batch operation,operation: {}", operation);
throw new UnsupportedOperationException("not support common batch operation,operation: " + operation);
}
}
private BatchUpdatePICItem[] handleBatchUpdatePICInputs(String body){
try{
List<BatchUpdatePICItem> list = new ArrayList<BatchUpdatePICItem>();
JSONArray arr = new JSONArray(body);
if(arr.length() == 0){
throw new RuntimeException("batch update PIC items must not be 0!");
}
for(int i = 0; i < arr.length(); i ++){
list.add(new BatchUpdatePICItem(arr.getJSONObject(i)));
};
return list.toArray(new BatchUpdatePICItem[0]);
}catch(Exception e){
logger.error("illegal Argument,body: {}", body);
throw new IllegalArgumentException("illegal Argument,body: " + body, e);
}
}
private BatchDiscardItem[] handleBatchDiscardInputs(String body){
try{
List<BatchDiscardItem> list = new ArrayList<BatchDiscardItem>();
JSONArray arr = new JSONArray(body);
if(arr.length() == 0){
throw new RuntimeException("batch discard items must not be 0!");
}
for(int i = 0; i < arr.length(); i ++){
list.add(new BatchDiscardItem(arr.getJSONObject(i)));
};
return list.toArray(new BatchDiscardItem[0]);
}catch(Exception e){
logger.error("illegal Argument,body: {}", body);
throw new IllegalArgumentException("illegal Argument,body: " + body, e);
}
}
private BatchDeleteItem[] handleBatchDeleteInputs(String body) {
try{
List<BatchDeleteItem> list = new ArrayList<BatchDeleteItem>();
JSONArray arr = new JSONArray(body);
if(arr.length() == 0){
throw new RuntimeException("batch delete items must not be 0!");
}
for(int i = 0; i < arr.length(); i ++){
list.add(new BatchDeleteItem(arr.getJSONObject(i)));
};
return list.toArray(new BatchDeleteItem[0]);
}catch(Exception e){
logger.error("illegal Argument,body: {}", body);
throw new IllegalArgumentException("illegal Argument,body: " + body, e);
}
}
@ResponseBody
@RequestMapping(value="/warehouse/api/common/config/getMaxFileSize", method = RequestMethod.GET, consumes = "application/json") @RequestMapping(value="/warehouse/api/common/config/getMaxFileSize", method = RequestMethod.GET, consumes = "application/json")
public String getMaxFileSize() { public String getMaxFileSize() {
JSONObject o = new JSONObject(); JSONObject o = new JSONObject();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment