234 lines
		
	
	
		
			6.6 KiB
		
	
	
	
		
			Java
		
	
	
	
			
		
		
	
	
			234 lines
		
	
	
		
			6.6 KiB
		
	
	
	
		
			Java
		
	
	
	
| package tqq9.lc123.cloud.app.api.utils;
 | |
| 
 | |
| import com.alibaba.fastjson.JSONObject;
 | |
| import kd.bos.dataentity.entity.DynamicObject;
 | |
| import kd.bos.dataentity.utils.StringUtils;
 | |
| import kd.bos.entity.operate.result.IOperateInfo;
 | |
| import kd.bos.openapi.common.custom.annotation.ApiModel;
 | |
| import kd.bos.openapi.common.custom.annotation.ApiParam;
 | |
| 
 | |
| import java.io.Serializable;
 | |
| import java.util.*;
 | |
| 
 | |
| @ApiModel
 | |
| public class ApiResultExt implements Serializable {
 | |
|     @ApiParam("操作失败数量")
 | |
|     private int failCount;
 | |
|     @ApiParam("操作成功数量")
 | |
|     private int successCount;
 | |
|     @ApiParam("返回结果")
 | |
|     private List<ResultBean> result;
 | |
| 
 | |
|     public int getFailCount() {
 | |
|         return failCount;
 | |
|     }
 | |
| 
 | |
|     public void setFailCount(int failCount) {
 | |
|         this.failCount = failCount;
 | |
|     }
 | |
| 
 | |
|     public int getSuccessCount() {
 | |
|         return successCount;
 | |
|     }
 | |
| 
 | |
|     public void setSuccessCount(int successCount) {
 | |
|         this.successCount = successCount;
 | |
|     }
 | |
| 
 | |
|     public List<ResultBean> getResult() {
 | |
|         return result;
 | |
|     }
 | |
| 
 | |
|     public void setResult(List<ResultBean> result) {
 | |
|         this.result = result;
 | |
|     }
 | |
| 
 | |
|     @ApiModel
 | |
|     public static class ResultBean implements Serializable {
 | |
| 
 | |
| 
 | |
|         @ApiParam("数据索引")
 | |
|         private int billIndex;
 | |
|         @ApiParam("接口操作是否成功")
 | |
|         private boolean billStatus;
 | |
|         @ApiParam("错误信息")
 | |
|         private Error errors;
 | |
|         @ApiParam("金蝶单据id")
 | |
|         private String id;
 | |
|         @ApiParam("候选键信息")
 | |
|         private JSONObject keys;
 | |
|         @ApiParam("金蝶单据编号")
 | |
|         private String number;
 | |
|         @ApiParam("接口操作类型")
 | |
|         private String type;
 | |
| 
 | |
|         public int getBillIndex() {
 | |
|             return billIndex;
 | |
|         }
 | |
| 
 | |
|         public void setBillIndex(int billIndex) {
 | |
|             this.billIndex = billIndex;
 | |
|         }
 | |
| 
 | |
|         public boolean isBillStatus() {
 | |
|             return billStatus;
 | |
|         }
 | |
| 
 | |
|         public void setBillStatus(boolean billStatus) {
 | |
|             this.billStatus = billStatus;
 | |
|         }
 | |
| 
 | |
|         public Error getErrors() {
 | |
|             return errors;
 | |
|         }
 | |
| 
 | |
|         public void setErrors(Error errors) {
 | |
|             this.errors = errors;
 | |
|         }
 | |
| 
 | |
|         public String getId() {
 | |
|             return id;
 | |
|         }
 | |
| 
 | |
|         public void setId(String id) {
 | |
|             this.id = id;
 | |
|         }
 | |
| 
 | |
|         public JSONObject getKeys() {
 | |
|             return keys;
 | |
|         }
 | |
| 
 | |
|         public void setKeys(JSONObject keys) {
 | |
|             this.keys = keys;
 | |
|         }
 | |
| 
 | |
|         public String getNumber() {
 | |
|             return number;
 | |
|         }
 | |
| 
 | |
|         public void setNumber(String number) {
 | |
|             this.number = number;
 | |
|         }
 | |
| 
 | |
|         public String getType() {
 | |
|             return type;
 | |
|         }
 | |
| 
 | |
|         public void setType(String type) {
 | |
|             this.type = type;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public static class Error implements Serializable {
 | |
|         private String entityKey;
 | |
|         private String entryRowIndex;
 | |
|         private JSONObject keys;
 | |
|         private List<String> rowMsg;
 | |
|         private String subEntryRowIndex;
 | |
| 
 | |
|         // Getter 和 Setter
 | |
|         public String getEntityKey() {
 | |
|             return entityKey;
 | |
|         }
 | |
| 
 | |
|         public void setEntityKey(String entityKey) {
 | |
|             this.entityKey = entityKey;
 | |
|         }
 | |
| 
 | |
|         public String getEntryRowIndex() {
 | |
|             return entryRowIndex;
 | |
|         }
 | |
| 
 | |
|         public void setEntryRowIndex(String entryRowIndex) {
 | |
|             this.entryRowIndex = entryRowIndex;
 | |
|         }
 | |
| 
 | |
|         public JSONObject getKeys() {
 | |
|             return keys;
 | |
|         }
 | |
| 
 | |
|         public void setKeys(JSONObject keys) {
 | |
|             this.keys = keys;
 | |
|         }
 | |
| 
 | |
|         public List<String> getRowMsg() {
 | |
|             return rowMsg;
 | |
|         }
 | |
| 
 | |
|         public void setRowMsg(List<String> rowMsg) {
 | |
|             this.rowMsg = rowMsg;
 | |
|         }
 | |
| 
 | |
|         public String getSubEntryRowIndex() {
 | |
|             return subEntryRowIndex;
 | |
|         }
 | |
| 
 | |
|         public void setSubEntryRowIndex(String subEntryRowIndex) {
 | |
|             this.subEntryRowIndex = subEntryRowIndex;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public HashMap<String,Object> addErrorToResultBeanByNumber(List<ResultBean> resultBeans, IOperateInfo iOperateInfo, String entityKey) {
 | |
|         Set<String> idSet = new HashSet<>();
 | |
|         for (ResultBean resultBean : resultBeans) {
 | |
|             Error error = resultBean.getErrors();
 | |
|             String message = iOperateInfo.getMessage();
 | |
|             String id  = iOperateInfo.getPkValue().toString();
 | |
|             if (StringUtils.equals(resultBean.getId(),id)) {
 | |
|                 resultBean.setBillStatus(false);
 | |
|                 if (error == null) {
 | |
|                     error = new Error();
 | |
|                     error.setRowMsg(new ArrayList<String>());
 | |
|                 }
 | |
|                 error.setKeys(resultBean.getKeys());
 | |
|                 error.setEntityKey(entityKey);
 | |
|                 List<String> rowMsg = error.getRowMsg();
 | |
|                 rowMsg.add(message);
 | |
|                 error.setRowMsg(rowMsg);
 | |
|                 resultBean.setErrors(error);
 | |
|                 break;
 | |
|             }
 | |
|         }
 | |
|         HashMap<String, Object> returnMap = new HashMap<>();
 | |
|         returnMap.put("ResultBeanList",resultBeans);
 | |
|         return returnMap;
 | |
|     }
 | |
| 
 | |
|     public HashMap<String,Object> addOneErrorToResultBeanByNumber(List<ResultBean> resultBeans, String errormsg, String entityKey) {
 | |
|         Set<String> idSet = new HashSet<>();
 | |
|         for (ResultBean resultBean : resultBeans) {
 | |
|             Error error = resultBean.getErrors();
 | |
|                 resultBean.setBillStatus(false);
 | |
|                 if (error == null) {
 | |
|                     error = new Error();
 | |
|                     error.setRowMsg(new ArrayList<String>());
 | |
|                 }
 | |
|                 error.setKeys(resultBean.getKeys());
 | |
|                 error.setEntityKey(entityKey);
 | |
|                 List<String> rowMsg = error.getRowMsg();
 | |
|                 rowMsg.add(errormsg);
 | |
|                 error.setRowMsg(rowMsg);
 | |
|                 resultBean.setErrors(error);
 | |
|                 break;
 | |
|         }
 | |
|         HashMap<String, Object> returnMap = new HashMap<>();
 | |
|         returnMap.put("ResultBeanList",resultBeans);
 | |
|         return returnMap;
 | |
|     }
 | |
| 
 | |
|     public static DynamicObject[] removeBillByBillno(DynamicObject[] bills, Set<String> idSet) {
 | |
|         DynamicObject[] tempBills = new DynamicObject[bills.length];
 | |
|         int index = 0;
 | |
| 
 | |
|         // 遍历原数组,复制不需要删除的元素到 tempBills
 | |
|         for (DynamicObject bill : bills) {
 | |
|             if (!idSet.contains(bill.getString("id"))) {
 | |
|                 tempBills[index++] = bill;
 | |
|             }
 | |
|         }
 | |
|         // 使用 Arrays.copyOf 修剪数组到实际大小
 | |
|         return Arrays.copyOf(tempBills, index);
 | |
|     }
 | |
| 
 | |
| }
 |