454 lines
28 KiB
Java
454 lines
28 KiB
Java
package tqq9.lc123.cloud.app.api.controller;
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.drew.lang.annotations.NotNull;
|
|
import kd.bos.dataentity.OperateOption;
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
import kd.bos.dataentity.utils.StringUtils;
|
|
import kd.bos.entity.botp.runtime.ConvertOperationResult;
|
|
import kd.bos.entity.botp.runtime.PushArgs;
|
|
import kd.bos.entity.botp.runtime.SourceBillReport;
|
|
import kd.bos.entity.operate.result.IOperateInfo;
|
|
import kd.bos.entity.operate.result.OperationResult;
|
|
import kd.bos.openapi.common.custom.annotation.ApiController;
|
|
import kd.bos.openapi.common.custom.annotation.ApiParam;
|
|
import kd.bos.openapi.common.custom.annotation.ApiPostMapping;
|
|
import kd.bos.openapi.common.result.CustomApiResult;
|
|
import kd.bos.orm.query.QCP;
|
|
import kd.bos.orm.query.QFilter;
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
import kd.bos.servicehelper.botp.ConvertServiceHelper;
|
|
import kd.bos.servicehelper.operation.OperationServiceHelper;
|
|
import tqq9.lc123.cloud.app.api.utils.ApiResultExt;
|
|
import tqq9.lc123.cloud.app.api.utils.Constants;
|
|
import tqq9.lc123.cloud.app.plugin.utils.BotpParamUtils;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.util.*;
|
|
|
|
/**
|
|
* 出库回传java接口插件
|
|
*/
|
|
@ApiController(value = "WMSSaleOutController", desc = "WMS-出库回传")
|
|
|
|
public class WMSSaleOutController {
|
|
|
|
private static String SM_DELIVERNOTICE = "sm_delivernotice";//发货通知单
|
|
private static String IM_SALOUTBILL = "im_saloutbill";//销售出库单
|
|
private static String BILLENTRY = "billentry";//分录
|
|
private static String SM_RETURNAPPLY = "sm_returnapply";//销售退货申请单
|
|
private static String TQQ9_OTHEROUTAPPLY = "tqq9_otheroutapply";//其他出库申请
|
|
private static String IM_OTHEROUTBILL = "im_otheroutbill";//其他出库
|
|
|
|
@ApiPostMapping(value = "/WMS_SaleOutnPush", desc = "WMS-出库回传")
|
|
public CustomApiResult<ApiResultExt> WMS_SaleOutnPush
|
|
(@NotNull @ApiParam(value = "入参", example = "") HashMap<String, Object> data) {
|
|
//返回值初始化
|
|
ApiResultExt resultExt = new ApiResultExt();
|
|
List<ApiResultExt.ResultBean> results = new ArrayList<>();
|
|
resultExt.setResult(results);
|
|
String VoucherType = (String) data.get("VoucherType");//单据类型
|
|
String billno = (String) data.get("erpOrderCode");//单据编号
|
|
JSONArray details = (JSONArray) data.get("details");
|
|
ApiResultExt.ResultBean resultBean = new ApiResultExt.ResultBean();
|
|
results.add(resultBean);
|
|
JSONObject key = new JSONObject();
|
|
key.put("billno", billno);
|
|
resultBean.setKeys(key);
|
|
ApiResultExt.Error error =new ApiResultExt.Error();
|
|
resultBean.setErrors(error);
|
|
ArrayList<String> rowmsg = new ArrayList<>();
|
|
error.setRowMsg(rowmsg);
|
|
String errormsg = null;
|
|
resultBean.setBillIndex(0);
|
|
resultBean.setKeys(key);
|
|
resultBean.setNumber(billno);
|
|
resultBean.setType(Constants.TYPE_PUSH);
|
|
//判断回传类型
|
|
String entityType = "";
|
|
switch (VoucherType) {
|
|
case "sm_delivernotice":
|
|
entityType = "im_saloutbill";
|
|
break;
|
|
case "sm_returnapply":
|
|
entityType = "im_saloutbill";
|
|
break;
|
|
case "tqq9_otheroutapply":
|
|
entityType = "im_otheroutbill";
|
|
break;
|
|
default:
|
|
errormsg = "传入参数 VoucherType 为无效值";
|
|
resultExt = ApiResultExt.errorRetrun(entityType, errormsg, error, resultExt);
|
|
return CustomApiResult.success(resultExt);
|
|
}
|
|
//必填项校验
|
|
if (ApiResultExt.validateRequired(VoucherType, "String")) {
|
|
errormsg = "传入参数 VoucherType 为空";
|
|
resultExt = ApiResultExt.errorRetrun(entityType, errormsg, error, resultExt);
|
|
}
|
|
if (ApiResultExt.validateRequired(billno, "String")) {
|
|
errormsg = "传入参数 erpOrderCode 为空";
|
|
resultExt = ApiResultExt.errorRetrun(entityType, errormsg, error, resultExt);
|
|
}
|
|
for (int i = 0; i < details.size(); i++) {
|
|
Object detali = details.get(i);
|
|
JSONObject detali1 = (JSONObject) detali;
|
|
BigDecimal quantity = detali1.getBigDecimal("quantity");//入库数量
|
|
String entryId = detali1.getString("erpDetailId");//金蝶源头单据细单号
|
|
if (detali1.getString("erpDetailId").length() > 19) {
|
|
errormsg = "Value " + entryId + " is out of range for a Long. Using default value.";
|
|
resultExt = ApiResultExt.errorRetrun(entityType, errormsg, error, resultExt);
|
|
return CustomApiResult.success(resultExt);
|
|
}
|
|
DynamicObject isexsit = BusinessDataServiceHelper.loadSingle(VoucherType, new QFilter[]{new QFilter("billentry.id", QCP.equals, detali1.getLong("erpDetailId"))});
|
|
if(isexsit==null){
|
|
errormsg = "传入参数 erpDetailId 在金蝶系统中未查询到对应单据";
|
|
resultExt = ApiResultExt.errorRetrun(entityType, errormsg, error, resultExt);
|
|
return CustomApiResult.success(resultExt);
|
|
}
|
|
if (ApiResultExt.validateRequired(quantity, "BigDecimal")) {
|
|
errormsg = "传入参数 quantity 为空";
|
|
resultExt = ApiResultExt.errorRetrun(entityType, errormsg, error, resultExt);
|
|
}
|
|
if (ApiResultExt.validateRequired(entryId, "String")) {
|
|
errormsg = "传入参数 erpDetailId 为空";
|
|
resultExt = ApiResultExt.errorRetrun(entityType, errormsg, error, resultExt);
|
|
}
|
|
}
|
|
rowmsg = resultExt.getResult().get(0).getErrors().getRowMsg();
|
|
if (!rowmsg.isEmpty()) {
|
|
return CustomApiResult.success(resultExt);
|
|
}
|
|
//发货通知单
|
|
if (StringUtils.equals("sm_delivernotice", VoucherType)) {
|
|
//查询单据在金蝶系统中是否存在
|
|
DynamicObject sm_delivernotice = BusinessDataServiceHelper.loadSingle(SM_DELIVERNOTICE, new QFilter[]{new QFilter("billno", QCP.equals, billno)});
|
|
if (sm_delivernotice == null) {
|
|
errormsg = "根据传入编号:" + billno + "未找到对应发货通知单";
|
|
resultExt = ApiResultExt.errorRetrun(entityType, errormsg, error, resultExt);
|
|
return CustomApiResult.success(resultExt);
|
|
}
|
|
//参数值组装
|
|
Long id = sm_delivernotice.getLong("id");
|
|
Map<String, Object> param = new HashMap<>();//传入转换规则处理参数
|
|
HashMap<Long, Set<Long>> entitypkMap = new HashMap<>();//上下游id映射Map
|
|
JSONObject detailObject = new JSONObject();
|
|
for (Object detail : details) {
|
|
JSONObject detail1 = (JSONObject) detail;
|
|
String entryId = detail1.getString("erpDetailId");//金蝶源头单据细单号
|
|
BigDecimal quantity = detail1.getBigDecimal("quantity");//入库数量
|
|
String uniqueCode = detail1.getString("uniqueCode");//商品编码
|
|
Date manufactureDate = detail1.getDate("manufactureDate");//生产日期
|
|
Date expirationDate = detail1.getDate("expirationDate");//失效期
|
|
String batch = detail1.getString("batch");//批次
|
|
String registrationCode = detail1.getString("registrationCode");//注册证号
|
|
String licenceCode = detail1.getString("licenceCode");//生产许可证
|
|
String producer = detail1.getString("producer");//生产厂商
|
|
detailObject.put("entryId", entryId);
|
|
detailObject.put("uniqueCode", uniqueCode);
|
|
detailObject.put("quantity", quantity);
|
|
detailObject.put("manufactureDate", manufactureDate);
|
|
detailObject.put("expirationDate", expirationDate);
|
|
detailObject.put("batch", batch);
|
|
detailObject.put("registrationCode", registrationCode);
|
|
detailObject.put("licenceCode", licenceCode);
|
|
detailObject.put("producer", producer);
|
|
detailObject.put("VoucherType", VoucherType);
|
|
entitypkMap.computeIfAbsent(id, k -> new HashSet<>()).add(detail1.getLong("erpDetailId"));
|
|
param.put(entryId, detailObject);
|
|
}
|
|
//开始下推
|
|
String rule = BotpParamUtils.getBotpRuleId(SM_DELIVERNOTICE, IM_SALOUTBILL, "发货通知单_销售出库单_转换规则_扩展");
|
|
PushArgs pushArgs = BotpParamUtils.getPushArgs(SM_DELIVERNOTICE, IM_SALOUTBILL, BILLENTRY, param, entitypkMap, rule);
|
|
ConvertOperationResult pushResult = ConvertServiceHelper.pushAndSave(pushArgs);
|
|
List<SourceBillReport> billReports = pushResult.getBillReports();
|
|
//下推失败直接返回
|
|
if (!pushResult.isSuccess()) {
|
|
for (SourceBillReport billReport : billReports) {
|
|
String billMessage = billReport.getFailMessage();
|
|
resultExt = ApiResultExt.errorRetrun(entityType, billMessage, error, resultExt);
|
|
}
|
|
rowmsg = resultExt.getResult().get(0).getErrors().getRowMsg();
|
|
if (!rowmsg.isEmpty()) {
|
|
return CustomApiResult.success(resultExt);
|
|
}
|
|
}
|
|
//获取下推单据id准备提交审核操作
|
|
Set<Object> targetBillIds = pushResult.getTargetBillIds();
|
|
DynamicObject[] load = new DynamicObject[targetBillIds.size()];
|
|
Iterator<Object> iterator = targetBillIds.iterator();
|
|
for (int i = 0; iterator.hasNext(); i++) {
|
|
Object next = iterator.next();
|
|
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(IM_SALOUTBILL, new QFilter[]{new QFilter("id", QCP.equals, next)});
|
|
load[i] = dynamicObject;
|
|
resultBean.setId(next.toString());
|
|
resultBean.setBillStatus(true);
|
|
}
|
|
// results.add(resultBean);
|
|
//开始提交
|
|
OperateOption operateOption = OperateOption.create();
|
|
OperationResult sumbitResult = OperationServiceHelper.executeOperate(Constants.TYPE_SUBMIT, SM_DELIVERNOTICE, load, operateOption);
|
|
if (!sumbitResult.isSuccess()) {
|
|
List<IOperateInfo> allErrorOrValidateInfo = sumbitResult.getAllErrorOrValidateInfo();
|
|
if (allErrorOrValidateInfo.size() != 0) {
|
|
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
|
|
HashMap<String, Object> returnMap = resultExt.addErrorToResultBeanByNumber(results, iOperateInfo, IM_SALOUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
}
|
|
} else if (StringUtils.isNotBlank(sumbitResult.getMessage())) {
|
|
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, sumbitResult.getMessage(), IM_SALOUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
} else {
|
|
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, sumbitResult.getInteractionContext().getSimpleMessage(), IM_SALOUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
}
|
|
} else {
|
|
//开始审核
|
|
OperationResult auditResult = OperationServiceHelper.executeOperate(Constants.TYPE_AUDIT, SM_DELIVERNOTICE, load, operateOption);
|
|
if (!auditResult.isSuccess()) {
|
|
List<IOperateInfo> allErrorOrValidateInfo1 = auditResult.getAllErrorOrValidateInfo();
|
|
if (allErrorOrValidateInfo1.size() != 0) {
|
|
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo1) {
|
|
HashMap<String, Object> returnMap = resultExt.addErrorToResultBeanByNumber(results, iOperateInfo, IM_SALOUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
}
|
|
} else if (StringUtils.isNotBlank(auditResult.getMessage())) {
|
|
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, auditResult.getMessage(), IM_SALOUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
} else {
|
|
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, auditResult.getInteractionContext().getSimpleMessage(), IM_SALOUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
}
|
|
}
|
|
}
|
|
//销售退货单
|
|
} else if (StringUtils.equals("sm_returnapply", VoucherType)) {
|
|
//查询单据在金蝶系统中是否存在
|
|
DynamicObject sm_returnapply = BusinessDataServiceHelper.loadSingle(SM_RETURNAPPLY, new QFilter[]{new QFilter("billno", QCP.equals, billno)});
|
|
if (sm_returnapply == null) {
|
|
errormsg = "根据传入编号:" + billno + "未找到对应销售退货单";
|
|
resultExt = ApiResultExt.errorRetrun(entityType, errormsg, error, resultExt);
|
|
return CustomApiResult.success(resultExt);
|
|
}
|
|
//参数值组装
|
|
Long id = sm_returnapply.getLong("id");
|
|
Map<String, Object> param = new HashMap<>();//传入转换规则处理参数
|
|
HashMap<Long, Set<Long>> entitypkMap = new HashMap<>();//上下游id映射Map
|
|
JSONObject detailObject = new JSONObject();
|
|
for (Object detail : details) {
|
|
JSONObject detail1 = (JSONObject) detail;
|
|
String entryId = detail1.getString("erpDetailId");//金蝶源头单据细单号
|
|
BigDecimal quantity = detail1.getBigDecimal("quantity");//入库数量
|
|
String uniqueCode = detail1.getString("uniqueCode");//商品编码
|
|
Date manufactureDate = detail1.getDate("manufactureDate");//生产日期
|
|
Date expirationDate = detail1.getDate("expirationDate");//失效期
|
|
String batch = detail1.getString("batch");//批次
|
|
String registrationCode = detail1.getString("registrationCode");//注册证号
|
|
String licenceCode = detail1.getString("licenceCode");//生产许可证
|
|
String producer = detail1.getString("producer");//生产厂商
|
|
detailObject.put("entryId", entryId);
|
|
detailObject.put("uniqueCode", uniqueCode);
|
|
detailObject.put("quantity", quantity);
|
|
detailObject.put("manufactureDate", manufactureDate);
|
|
detailObject.put("expirationDate", expirationDate);
|
|
detailObject.put("batch", batch);
|
|
detailObject.put("registrationCode", registrationCode);
|
|
detailObject.put("licenceCode", licenceCode);
|
|
detailObject.put("producer", producer);
|
|
detailObject.put("VoucherType", VoucherType);
|
|
entitypkMap.computeIfAbsent(id, k -> new HashSet<>()).add(detail1.getLong("erpDetailId"));
|
|
param.put(entryId, detailObject);
|
|
}
|
|
//开始下推
|
|
String rule = BotpParamUtils.getBotpRuleId(SM_RETURNAPPLY, IM_SALOUTBILL, "销售退货申请单_销售出库单_转换规则_扩展");
|
|
PushArgs pushArgs = BotpParamUtils.getPushArgs(SM_RETURNAPPLY, IM_SALOUTBILL, BILLENTRY, param, entitypkMap, rule);
|
|
ConvertOperationResult pushResult = ConvertServiceHelper.pushAndSave(pushArgs);
|
|
List<SourceBillReport> billReports = pushResult.getBillReports();
|
|
if (!pushResult.isSuccess()) {
|
|
for (SourceBillReport billReport : billReports) {
|
|
String billMessage = billReport.getFailMessage();
|
|
resultExt = ApiResultExt.errorRetrun(entityType, billMessage, error, resultExt);
|
|
}
|
|
rowmsg = resultExt.getResult().get(0).getErrors().getRowMsg();
|
|
if (!rowmsg.isEmpty()) {
|
|
return CustomApiResult.success(resultExt);
|
|
}
|
|
}
|
|
//获取下推单据id准备提交审核操作
|
|
Set<Object> targetBillIds = pushResult.getTargetBillIds();
|
|
DynamicObject[] load = new DynamicObject[targetBillIds.size()];
|
|
HashMap<Object, String> reMap = new HashMap<Object, String>();
|
|
Iterator<Object> iterator = targetBillIds.iterator();
|
|
for (int i = 0; iterator.hasNext(); i++) {
|
|
Object next = iterator.next();
|
|
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(IM_SALOUTBILL, new QFilter[]{new QFilter("id", QCP.equals, next)});
|
|
load[i] = dynamicObject;
|
|
reMap.put(dynamicObject.get("id"), dynamicObject.getString("billno"));
|
|
resultBean.setId(next.toString());
|
|
resultBean.setBillStatus(true);
|
|
}
|
|
// results.add(resultBean);
|
|
//开始提交
|
|
OperateOption operateOption = OperateOption.create();
|
|
OperationResult sumbitResult = OperationServiceHelper.executeOperate(Constants.TYPE_SUBMIT, SM_RETURNAPPLY, load, operateOption);
|
|
if (!sumbitResult.isSuccess()) {
|
|
List<IOperateInfo> allErrorOrValidateInfo = sumbitResult.getAllErrorOrValidateInfo();
|
|
if (allErrorOrValidateInfo.size() != 0) {
|
|
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
|
|
HashMap<String, Object> returnMap = resultExt.addErrorToResultBeanByNumber(results, iOperateInfo, IM_SALOUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
}
|
|
} else if (StringUtils.isNotBlank(sumbitResult.getMessage())) {
|
|
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, sumbitResult.getMessage(), IM_SALOUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
} else {
|
|
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, sumbitResult.getInteractionContext().getSimpleMessage(), IM_SALOUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
}
|
|
} else {
|
|
//开始审核
|
|
OperationResult auditResult = OperationServiceHelper.executeOperate(Constants.TYPE_AUDIT, SM_RETURNAPPLY, load, operateOption);
|
|
if (!auditResult.isSuccess()) {
|
|
List<IOperateInfo> allErrorOrValidateInfo1 = auditResult.getAllErrorOrValidateInfo();
|
|
if (allErrorOrValidateInfo1.size() != 0) {
|
|
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo1) {
|
|
HashMap<String, Object> returnMap = resultExt.addErrorToResultBeanByNumber(results, iOperateInfo, IM_SALOUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
}
|
|
} else if (StringUtils.isNotBlank(auditResult.getMessage())) {
|
|
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, auditResult.getMessage(), IM_SALOUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
} else {
|
|
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, auditResult.getInteractionContext().getSimpleMessage(), IM_SALOUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
}
|
|
}
|
|
}
|
|
//销售退货单
|
|
} else if (StringUtils.equals("tqq9_otheroutapply", VoucherType)) {
|
|
//查询单据在金蝶系统中是否存在
|
|
DynamicObject tqq9_otheroutapply = BusinessDataServiceHelper.loadSingle(TQQ9_OTHEROUTAPPLY, new QFilter[]{new QFilter("billno", QCP.equals, billno)});
|
|
if (tqq9_otheroutapply == null) {
|
|
errormsg = "根据传入编号:" + billno + "未找到对应其他出库申请单";
|
|
resultExt = ApiResultExt.errorRetrun(entityType, errormsg, error, resultExt);
|
|
return CustomApiResult.success(resultExt);
|
|
}
|
|
//根据业务类型判断转换规则名称
|
|
DynamicObject bd_biztype = tqq9_otheroutapply.getDynamicObject("tqq9_biztype");//业务类型
|
|
String rulanema = null;
|
|
if (!StringUtils.equals("612", bd_biztype.getString("number"))) {
|
|
rulanema = "除调拨类型";
|
|
} else {
|
|
String tqq9_dblx = tqq9_otheroutapply.getString("tqq9_dblx");//调拨类型
|
|
if (StringUtils.equals("A", tqq9_dblx)) {
|
|
rulanema = "组织内调拨";
|
|
} else {
|
|
rulanema = "跨组织调拨";
|
|
}
|
|
}
|
|
String rule = BotpParamUtils.getBotpRuleId(TQQ9_OTHEROUTAPPLY, IM_OTHEROUTBILL, rulanema);
|
|
//组装参数值
|
|
Long id = tqq9_otheroutapply.getLong("id");
|
|
Map<String, Object> param = new HashMap<>();//传入转换规则处理参数
|
|
HashMap<Long, Set<Long>> entitypkMap = new HashMap<>();//上下游id映射Map
|
|
JSONObject detailObject = new JSONObject();
|
|
for (Object detail : details) {
|
|
JSONObject detail1 = (JSONObject) detail;
|
|
String entryId = detail1.getString("erpDetailId");//金蝶源头单据细单号
|
|
BigDecimal quantity = detail1.getBigDecimal("quantity");//入库数量
|
|
String uniqueCode = detail1.getString("uniqueCode");//商品编码
|
|
Date manufactureDate = detail1.getDate("manufactureDate");//生产日期
|
|
Date expirationDate = detail1.getDate("expirationDate");//失效期
|
|
String batch = detail1.getString("batch");//批次
|
|
String registrationCode = detail1.getString("registrationCode");//注册证号
|
|
String licenceCode = detail1.getString("licenceCode");//生产许可证
|
|
String producer = detail1.getString("producer");//生产厂商
|
|
detailObject.put("entryId", entryId);
|
|
detailObject.put("uniqueCode", uniqueCode);
|
|
detailObject.put("quantity", quantity);
|
|
detailObject.put("manufactureDate", manufactureDate);
|
|
detailObject.put("expirationDate", expirationDate);
|
|
detailObject.put("batch", batch);
|
|
detailObject.put("registrationCode", registrationCode);
|
|
detailObject.put("licenceCode", licenceCode);
|
|
detailObject.put("producer", producer);
|
|
detailObject.put("VoucherType", VoucherType);
|
|
entitypkMap.computeIfAbsent(id, k -> new HashSet<>()).add(detail1.getLong("erpDetailId"));
|
|
param.put(entryId, detailObject);
|
|
}
|
|
//开始下推
|
|
PushArgs pushArgs = BotpParamUtils.getPushArgs(TQQ9_OTHEROUTAPPLY, IM_OTHEROUTBILL, BILLENTRY, param, entitypkMap, rule);
|
|
ConvertOperationResult pushResult = ConvertServiceHelper.pushAndSave(pushArgs);
|
|
List<SourceBillReport> billReports = pushResult.getBillReports();
|
|
if (!pushResult.isSuccess()) {
|
|
for (SourceBillReport billReport : billReports) {
|
|
String billMessage = billReport.getFailMessage();
|
|
resultExt = ApiResultExt.errorRetrun(entityType, billMessage, error, resultExt);
|
|
}
|
|
rowmsg = resultExt.getResult().get(0).getErrors().getRowMsg();
|
|
if (!rowmsg.isEmpty()) {
|
|
return CustomApiResult.success(resultExt);
|
|
}
|
|
}
|
|
//获取下推单据id准备提交审核操作
|
|
Set<Object> targetBillIds = pushResult.getTargetBillIds();
|
|
DynamicObject[] load = new DynamicObject[targetBillIds.size()];
|
|
Iterator<Object> iterator = targetBillIds.iterator();
|
|
for (int i = 0; iterator.hasNext(); i++) {
|
|
Object next = iterator.next();
|
|
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(IM_OTHEROUTBILL, new QFilter[]{new QFilter("id", QCP.equals, next)});
|
|
load[i] = dynamicObject;
|
|
resultBean.setId(next.toString());
|
|
resultBean.setBillStatus(true);
|
|
}
|
|
// results.add(resultBean);
|
|
//开始提交
|
|
OperateOption operateOption = OperateOption.create();
|
|
OperationResult sumbitResult = OperationServiceHelper.executeOperate(Constants.TYPE_SUBMIT, TQQ9_OTHEROUTAPPLY, load, operateOption);
|
|
if (!sumbitResult.isSuccess()) {
|
|
List<IOperateInfo> allErrorOrValidateInfo = sumbitResult.getAllErrorOrValidateInfo();
|
|
if (allErrorOrValidateInfo.size() != 0) {
|
|
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
|
|
HashMap<String, Object> returnMap = resultExt.addErrorToResultBeanByNumber(results, iOperateInfo, IM_OTHEROUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
}
|
|
} else if (StringUtils.isNotBlank(sumbitResult.getMessage())) {
|
|
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, sumbitResult.getMessage(), IM_OTHEROUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
} else {
|
|
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, sumbitResult.getInteractionContext().getSimpleMessage(), IM_OTHEROUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
}
|
|
} else {
|
|
//开始审核
|
|
OperationResult auditResult = OperationServiceHelper.executeOperate(Constants.TYPE_AUDIT, TQQ9_OTHEROUTAPPLY, load, operateOption);
|
|
if (!auditResult.isSuccess()) {
|
|
List<IOperateInfo> allErrorOrValidateInfo1 = auditResult.getAllErrorOrValidateInfo();
|
|
if (allErrorOrValidateInfo1.size() != 0) {
|
|
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo1) {
|
|
HashMap<String, Object> returnMap = resultExt.addErrorToResultBeanByNumber(results, iOperateInfo, IM_OTHEROUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
}
|
|
} else if (StringUtils.isNotBlank(auditResult.getMessage())) {
|
|
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, auditResult.getMessage(), IM_OTHEROUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
} else {
|
|
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, auditResult.getInteractionContext().getSimpleMessage(), IM_OTHEROUTBILL);
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//回传成功
|
|
int failCount = 0;//失败数量
|
|
int successCount = 1;//成功数量
|
|
resultExt.setFailCount(failCount);
|
|
resultExt.setSuccessCount(successCount);
|
|
resultExt.setResult(results);
|
|
return CustomApiResult.success(resultExt);
|
|
|
|
|
|
}
|
|
|
|
} |