1083 lines
66 KiB
Java
1083 lines
66 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 com.google.gson.Gson;
|
||
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.model.WMSXmlReturn;
|
||
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 = "WMSPurInController", desc = "WMS-入库回传")
|
||
public class WMSPurInController {
|
||
|
||
private static String RECEIPTNOTICE = "pm_receiptnotice";//收货通知单
|
||
private static String PURINBILL = "im_purinbill";//采购入库单
|
||
private static String BILLENTRY = "billentry";//收货通知单分录,采购退货申请单分录
|
||
private static String PM_PURREFUNDAPPLYBILL = "pm_purrefundapplybill";//采购退货申请单
|
||
private static String TQQ9_OTHERINAPPLY = "tqq9_otherinapply";//其他入库申请
|
||
private static String IM_OTHERINBILL = "im_otherinbill";//其他入库
|
||
private final static HashMap<String, String> billTypeMap = new HashMap<String, String>() {{
|
||
put("采购订单", "pm_receiptnotice");
|
||
put("其他入库单", "tqq9_otherinapply");
|
||
put("销售退货单", "sm_returnapply");
|
||
put("调拨入库单", "tqq9_otherinapply");
|
||
put("采购退货单", "pm_purrefundapplybill");
|
||
put("销售订单", "sm_delivernotice");
|
||
put("其他出库单", "tqq9_otheroutapply");
|
||
put("调拨出库单", "tqq9_otheroutapply");
|
||
put("PTCK", "sm_delivernotice");
|
||
put("CGTH", "pm_purrefundapplybill");
|
||
put("DBCK", "tqq9_otheroutapply");
|
||
put("PKCK", "tqq9_otheroutapply");
|
||
put("TZCK", "tqq9_otheroutapply");
|
||
put("YPCK", "tqq9_otheroutapply");
|
||
put("BSCK", "tqq9_otheroutapply");
|
||
put("GQCK", "tqq9_otheroutapply");
|
||
put("CGRK", "pm_receiptnotice");
|
||
put("DBRK", "tqq9_otherinapply");
|
||
put("THRK", "sm_returnapply");
|
||
put("ZPRK", "tqq9_otherinapply");
|
||
put("PYRK", "tqq9_otherinapply");
|
||
put("TZRK", "tqq9_otherinapply");
|
||
}};
|
||
|
||
@ApiPostMapping(value = "/WMSPushPurIn", desc = "WMS-入库回传")
|
||
public CustomApiResult<ApiResultExt> WMS_PurInPush
|
||
(
|
||
@NotNull @ApiParam(value = "金蝶源头单据号", required = true) String erpOrderCode,
|
||
@NotNull @ApiParam(value = "WMS入库单号", required = true) String wmsOrderCode,
|
||
@NotNull @ApiParam(value = "单据类型", required = true) String VoucherType,
|
||
@NotNull @ApiParam(value = "库区编号", required = true) String wareCode,
|
||
@NotNull @ApiParam(value = "归属", required = true) String companyType,
|
||
@NotNull @ApiParam(value = "明细", required = true) JSONArray details
|
||
) {
|
||
//返回值初始化
|
||
ApiResultExt resultExt = new ApiResultExt();
|
||
List<ApiResultExt.ResultBean> results = new ArrayList<>();
|
||
resultExt.setResult(results);
|
||
String billno = erpOrderCode;//收货通知单编号
|
||
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);
|
||
|
||
//判断回传类型
|
||
VoucherType=billTypeMap.get(VoucherType);
|
||
String entityType = "";
|
||
switch (VoucherType) {
|
||
case "pm_receiptnotice":
|
||
entityType = "im_purinbill";
|
||
break;
|
||
case "pm_purrefundapplybill":
|
||
entityType = "im_purinbill";
|
||
break;
|
||
case "tqq9_otherinapply":
|
||
entityType = "im_otherinbill";
|
||
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 (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);
|
||
}
|
||
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("pm_receiptnotice", VoucherType)) {
|
||
//查询单据在金蝶系统中是否存在
|
||
DynamicObject receiptnotice = BusinessDataServiceHelper.loadSingle(RECEIPTNOTICE, new QFilter[]{new QFilter("billno", QCP.equals, billno)});
|
||
if (receiptnotice == null) {
|
||
errormsg = "根据传入编号:" + billno + "未找到对应收货通知单";
|
||
resultExt = ApiResultExt.errorRetrun(entityType, errormsg, error, resultExt);
|
||
return CustomApiResult.success(resultExt);
|
||
}
|
||
//参数值组装
|
||
Long id = receiptnotice.getLong("id");
|
||
Map<String, Set<JSONObject>> param = new HashMap<>();//传入转换规则处理参数
|
||
HashMap<Long, Set<Long>> entitypkMap = new HashMap<>();//上下游id映射Map
|
||
for (Object detail : details) {
|
||
JSONObject detailObject = new JSONObject();
|
||
JSONObject detail1 = (JSONObject) detail;
|
||
String entryId = detail1.getString("erpDetailId");//金蝶源头单据细单号
|
||
String wmsDetailId = detail1.getString("wmsDetailId");//WMS入库单细单号
|
||
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("wmsDetailId", wmsDetailId);
|
||
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.computeIfAbsent(entryId, k -> new HashSet<>()).add(detailObject);
|
||
|
||
}
|
||
//开始下推
|
||
String rule = BotpParamUtils.getBotpRuleId(RECEIPTNOTICE, PURINBILL, "收货通知单_采购入库单_转换规则");
|
||
PushArgs pushArgs = BotpParamUtils.getPushArgs(RECEIPTNOTICE, PURINBILL, 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(PURINBILL, 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, PURINBILL, 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, PURINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
}
|
||
} else if (StringUtils.isNotBlank(sumbitResult.getMessage())) {
|
||
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, sumbitResult.getMessage(), PURINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
} else {
|
||
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, sumbitResult.getInteractionContext().getSimpleMessage(), PURINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
}
|
||
} else {
|
||
//开始审核
|
||
OperationResult auditResult = OperationServiceHelper.executeOperate(Constants.TYPE_AUDIT, PURINBILL, 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, PURINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
}
|
||
} else if (StringUtils.isNotBlank(auditResult.getMessage())) {
|
||
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, auditResult.getMessage(), PURINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
} else {
|
||
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, auditResult.getInteractionContext().getSimpleMessage(), PURINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
}
|
||
}
|
||
}
|
||
//采购退货单
|
||
} else if (StringUtils.equals("pm_purrefundapplybill", VoucherType)) {
|
||
//查询单据在金蝶系统中是否存在
|
||
DynamicObject pm_purrefundapplybill = BusinessDataServiceHelper.loadSingle(PM_PURREFUNDAPPLYBILL, new QFilter[]{new QFilter("billno", QCP.equals, billno)});
|
||
if (pm_purrefundapplybill == null) {
|
||
errormsg = "根据传入编号:" + billno + "未找到对应采购退货单";
|
||
resultExt = ApiResultExt.errorRetrun(entityType, errormsg, error, resultExt);
|
||
return CustomApiResult.success(resultExt);
|
||
}
|
||
//参数值组装
|
||
Long id = pm_purrefundapplybill.getLong("id");
|
||
Map<String, Set<JSONObject>> param = new HashMap<>();//传入转换规则处理参数
|
||
HashMap<Long, Set<Long>> entitypkMap = new HashMap<>();//上下游id映射Map
|
||
for (Object detail : details) {
|
||
JSONObject detailObject = new JSONObject();
|
||
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.computeIfAbsent(entryId, k -> new HashSet<>()).add(detailObject);
|
||
}
|
||
//开始下推
|
||
String rule = BotpParamUtils.getBotpRuleId(PM_PURREFUNDAPPLYBILL, PURINBILL, "采购退货申请_采购入库_转换规则_扩展");
|
||
PushArgs pushArgs = BotpParamUtils.getPushArgs(PM_PURREFUNDAPPLYBILL, PURINBILL, 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(PURINBILL, 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, PURINBILL, 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, PURINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
}
|
||
} else if (StringUtils.isNotBlank(sumbitResult.getMessage())) {
|
||
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, sumbitResult.getMessage(), PURINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
} else {
|
||
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, sumbitResult.getInteractionContext().getSimpleMessage(), PURINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
}
|
||
} else {
|
||
//开始审核
|
||
OperationResult auditResult = OperationServiceHelper.executeOperate(Constants.TYPE_AUDIT, PURINBILL, 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, PURINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
}
|
||
} else if (StringUtils.isNotBlank(auditResult.getMessage())) {
|
||
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, auditResult.getMessage(), PURINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
} else {
|
||
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, auditResult.getInteractionContext().getSimpleMessage(), PURINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
}
|
||
}
|
||
}
|
||
//其他入库申请单
|
||
} else if (StringUtils.equals("tqq9_otherinapply", VoucherType)) {
|
||
//查询单据在金蝶系统中是否存在
|
||
DynamicObject tqq9_otherinapply = BusinessDataServiceHelper.loadSingle(TQQ9_OTHERINAPPLY, new QFilter[]{new QFilter("billno", QCP.equals, billno)});
|
||
if (tqq9_otherinapply == null) {
|
||
errormsg = "根据传入编号:" + billno + "未找到对应其他入库申请单";
|
||
resultExt = ApiResultExt.errorRetrun(entityType, errormsg, error, resultExt);
|
||
return CustomApiResult.success(resultExt);
|
||
}
|
||
//组装参数值
|
||
Long id = tqq9_otherinapply.getLong("id");
|
||
Map<String, Set<JSONObject>> param = new HashMap<>();//传入转换规则处理参数
|
||
HashMap<Long, Set<Long>> entitypkMap = new HashMap<>();//上下游id映射Map
|
||
for (Object detail : details) {
|
||
JSONObject detailObject = new JSONObject();
|
||
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.computeIfAbsent(entryId, k -> new HashSet<>()).add(detailObject);
|
||
}
|
||
//开始下推
|
||
String rule = BotpParamUtils.getBotpRuleId(TQQ9_OTHERINAPPLY, IM_OTHERINBILL, "其他入库申请_其他入库_转换规则");
|
||
PushArgs pushArgs = BotpParamUtils.getPushArgs(TQQ9_OTHERINAPPLY, IM_OTHERINBILL, 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_OTHERINBILL, 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, IM_OTHERINBILL, 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_OTHERINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
}
|
||
} else if (StringUtils.isNotBlank(sumbitResult.getMessage())) {
|
||
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, sumbitResult.getMessage(), IM_OTHERINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
} else {
|
||
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, sumbitResult.getInteractionContext().getSimpleMessage(), IM_OTHERINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
}
|
||
|
||
} else {
|
||
//开始审核
|
||
OperationResult auditResult = OperationServiceHelper.executeOperate(Constants.TYPE_AUDIT, IM_OTHERINBILL, 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_OTHERINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
}
|
||
} else if (StringUtils.isNotBlank(auditResult.getMessage())) {
|
||
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, auditResult.getMessage(), IM_OTHERINBILL);
|
||
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
||
} else {
|
||
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, auditResult.getInteractionContext().getSimpleMessage(), IM_OTHERINBILL);
|
||
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);
|
||
|
||
|
||
}
|
||
|
||
@ApiPostMapping(value = "/WMSPushPurIn_SH", desc = "WMS-入库回传")
|
||
public CustomApiResult<WMSXmlReturn> WMS_PurInPush_SH(@NotNull @ApiParam(value = "入参", required = true) Map<String, Object> dataMap) {
|
||
//返回值初始化
|
||
Gson gson = new Gson();
|
||
JSONObject data = gson.fromJson(dataMap.toString(), JSONObject.class);
|
||
JSONObject request = data.getJSONObject("request");
|
||
JSONObject entryOrder = request.getJSONObject("entryOrder");
|
||
String billno = entryOrder.getString("entryOrderCode");
|
||
String entryOrderType = entryOrder.getString("entryOrderType");
|
||
entryOrderType=billTypeMap.get(entryOrderType);
|
||
JSONObject orderLines = request.getJSONObject("orderLines");
|
||
WMSXmlReturn wmsXmlReturn = new WMSXmlReturn();
|
||
WMSXmlReturn.Response response = new WMSXmlReturn.Response();
|
||
wmsXmlReturn.setResponse(response);
|
||
response.setCode("0");
|
||
response.setFlag("success");
|
||
response.setMessage("成功");
|
||
StringBuilder errormsg = new StringBuilder();
|
||
ArrayList<String> entryOrderTypes = new ArrayList<>();
|
||
entryOrderTypes.add(RECEIPTNOTICE);
|
||
entryOrderTypes.add(PM_PURREFUNDAPPLYBILL);
|
||
entryOrderTypes.add(TQQ9_OTHERINAPPLY);
|
||
if (!entryOrderTypes.contains(entryOrderType)) {
|
||
errormsg = errormsg.append(";").append("传入参数 entryOrderType 为无效值");
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
}
|
||
//必填项校验
|
||
if (ApiResultExt.validateRequired(entryOrderType, "String")) {
|
||
errormsg = errormsg.append(";").append("传入参数 entryOrderType 为空");
|
||
}
|
||
if (ApiResultExt.validateRequired(billno, "String")) {
|
||
errormsg = errormsg.append(";").append("传入参数 entryOrderCode 为空");
|
||
}
|
||
if (orderLines.get("orderLine") instanceof Map) {
|
||
JSONObject orderLine = orderLines.getJSONObject("orderLine");
|
||
BigDecimal actualQty = orderLine.getBigDecimal("actualQty");//入库数量
|
||
String orderLineNo = orderLine.getString("orderLineNo");//金蝶源头单据细单号
|
||
if (orderLine.getString("orderLineNo").length() > 19) {
|
||
errormsg = errormsg.append(";").append("Value " + orderLineNo + " is out of range for a Long. Using default value");
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
}
|
||
DynamicObject isexsit = BusinessDataServiceHelper.loadSingle(entryOrderType, new QFilter[]{new QFilter("billentry.id", QCP.equals, orderLine.getLong("orderLineNo"))});
|
||
if (isexsit == null) {
|
||
errormsg = errormsg.append(";").append("传入参数 orderLineNo 在金蝶系统中未查询到对应单据");
|
||
}
|
||
if (ApiResultExt.validateRequired(actualQty, "BigDecimal")) {
|
||
errormsg = errormsg.append(";").append("传入参数 actualQty 为空");
|
||
}
|
||
if (ApiResultExt.validateRequired(orderLineNo, "String")) {
|
||
errormsg = errormsg.append(";").append("传入参数 orderLineNo 为空");
|
||
}
|
||
if (errormsg.length() > 0) {
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
}
|
||
} else {
|
||
JSONArray orderLine = orderLines.getJSONArray("orderLine");
|
||
for (Object obj : orderLine) {
|
||
JSONObject orderLine1 = gson.fromJson(gson.toJson(obj), JSONObject.class);
|
||
BigDecimal actualQty = orderLine1.getBigDecimal("actualQty");//入库数量
|
||
String orderLineNo = orderLine1.getString("orderLineNo");//金蝶源头单据细单号
|
||
if (orderLineNo.length() > 19) {
|
||
errormsg = errormsg.append(";").append("Value " + orderLineNo + " is out of range for a Long. Using default value");
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
}
|
||
DynamicObject isexsit = BusinessDataServiceHelper.loadSingle(entryOrderType, new QFilter[]{new QFilter("billentry.id", QCP.equals, orderLine1.getLong("orderLineNo"))});
|
||
if (isexsit == null) {
|
||
errormsg = errormsg.append(";").append("传入参数 orderLineNo 在金蝶系统中未查询到对应单据");
|
||
}
|
||
if (ApiResultExt.validateRequired(actualQty, "BigDecimal")) {
|
||
errormsg = errormsg.append(";").append("传入参数 actualQty 为空");
|
||
}
|
||
if (ApiResultExt.validateRequired(orderLineNo, "String")) {
|
||
errormsg = errormsg.append(";").append("传入参数 orderLineNo 为空");
|
||
}
|
||
}
|
||
if (errormsg.length() > 0) {
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
}
|
||
}
|
||
//收货通知单
|
||
if (StringUtils.equals("pm_receiptnotice", entryOrderType)) {
|
||
//查询单据在金蝶系统中是否存在
|
||
DynamicObject receiptnotice = BusinessDataServiceHelper.loadSingle(RECEIPTNOTICE, new QFilter[]{new QFilter("billno", QCP.equals, billno)});
|
||
if (receiptnotice == null) {
|
||
errormsg = errormsg.append(";").append("根据传入编号:" + billno + "未找到对应收货通知单");
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
}
|
||
Map<String, Set<JSONObject>> param = new HashMap<>();//传入转换规则处理参数
|
||
HashMap<Long, Set<Long>> entitypkMap = new HashMap<>();//上下游id映射Map
|
||
//参数值组装
|
||
if (orderLines.get("orderLine") instanceof Map) {
|
||
JSONObject orderLine = orderLines.getJSONObject("orderLine");
|
||
Long id = receiptnotice.getLong("id");
|
||
JSONObject detailObject = new JSONObject();
|
||
String orderLineNo = orderLine.getString("orderLineNo");//金蝶源头单据细单号
|
||
BigDecimal actualQty = orderLine.getBigDecimal("actualQty");//入库数量
|
||
String itemCode = orderLine.getString("itemCode");//商品编码
|
||
Date productDate = orderLine.getDate("productDate");//生产日期
|
||
Date expireDate = orderLine.getDate("expireDate");//失效期
|
||
String batchCode = orderLine.getString("batchCode");//批次
|
||
String key1 = null;//注册证号
|
||
String key3 = null;//生产许可证
|
||
String key2 = null;//生产厂商
|
||
if (orderLine.get("extendProps") instanceof Map) {
|
||
JSONObject extendProps = orderLine.getJSONObject("extendProps");//批次信息
|
||
key1 = extendProps.getString("key1");//注册证号
|
||
key3 = extendProps.getString("key3");//生产许可证
|
||
key2 = extendProps.getString("key2");//生产厂商
|
||
}else{
|
||
JSONArray extendProps = orderLine.getJSONArray("extendProps");
|
||
for (Object o : extendProps) {
|
||
JSONObject extendProp = gson.fromJson(gson.toJson(o), JSONObject.class);
|
||
if(extendProp.getString("key1")!=null){
|
||
key1 = extendProp.getString("key1");//注册证号
|
||
key3 = extendProp.getString("key3");//生产许可证
|
||
key2 = extendProp.getString("key2");//生产厂商
|
||
}
|
||
}
|
||
}
|
||
detailObject.put("entryId", orderLineNo);
|
||
detailObject.put("uniqueCode", itemCode);
|
||
detailObject.put("quantity", actualQty);
|
||
detailObject.put("manufactureDate", productDate);
|
||
detailObject.put("expirationDate", expireDate);
|
||
detailObject.put("batch", batchCode);
|
||
detailObject.put("registrationCode", key1);
|
||
detailObject.put("licenceCode", key3);
|
||
detailObject.put("producer", key2);
|
||
detailObject.put("VoucherType", entryOrderType);
|
||
entitypkMap.computeIfAbsent(id, k -> new HashSet<>()).add(orderLine.getLong("orderLineNo"));
|
||
param.computeIfAbsent(orderLineNo, k -> new HashSet<>()).add(detailObject);
|
||
} else {
|
||
JSONArray orderLine = orderLines.getJSONArray("orderLine");
|
||
for (Object obj : orderLine) {
|
||
JSONObject orderLine1 = gson.fromJson(gson.toJson(obj), JSONObject.class);
|
||
Long id = receiptnotice.getLong("id");
|
||
JSONObject detailObject = new JSONObject();
|
||
String orderLineNo = orderLine1.getString("orderLineNo");//金蝶源头单据细单号
|
||
BigDecimal actualQty = orderLine1.getBigDecimal("actualQty");//入库数量
|
||
String itemCode = orderLine1.getString("itemCode");//商品编码
|
||
Date productDate = orderLine1.getDate("productDate");//生产日期
|
||
Date expireDate = orderLine1.getDate("expireDate");//失效期
|
||
String batchCode = orderLine1.getString("batchCode");//批次
|
||
String key1 = null;//注册证号
|
||
String key3 = null;//生产许可证
|
||
String key2 = null;//生产厂商
|
||
if (orderLine1.get("extendProps") instanceof Map) {
|
||
JSONObject extendProps = orderLine1.getJSONObject("extendProps");//批次信息
|
||
key1 = extendProps.getString("key1");//注册证号
|
||
key3 = extendProps.getString("key3");//生产许可证
|
||
key2 = extendProps.getString("key2");//生产厂商
|
||
}else{
|
||
JSONArray extendProps = orderLine1.getJSONArray("extendProps");
|
||
for (Object o : extendProps) {
|
||
JSONObject extendProp = gson.fromJson(gson.toJson(o), JSONObject.class);
|
||
if(extendProp.getString("key1")!=null){
|
||
key1 = extendProp.getString("key1");//注册证号
|
||
key3 = extendProp.getString("key3");//生产许可证
|
||
key2 = extendProp.getString("key2");//生产厂商
|
||
}
|
||
}
|
||
}
|
||
detailObject.put("entryId", orderLineNo);
|
||
detailObject.put("uniqueCode", itemCode);
|
||
detailObject.put("quantity", actualQty);
|
||
detailObject.put("manufactureDate", productDate);
|
||
detailObject.put("expirationDate", expireDate);
|
||
detailObject.put("batch", batchCode);
|
||
detailObject.put("registrationCode", key1);
|
||
detailObject.put("licenceCode", key3);
|
||
detailObject.put("producer", key2);
|
||
detailObject.put("VoucherType", entryOrderType);
|
||
entitypkMap.computeIfAbsent(id, k -> new HashSet<>()).add(orderLine1.getLong("orderLineNo"));
|
||
param.computeIfAbsent(orderLineNo, k -> new HashSet<>()).add(detailObject);
|
||
}
|
||
}
|
||
//开始下推
|
||
String rule = BotpParamUtils.getBotpRuleId(RECEIPTNOTICE, PURINBILL, "收货通知单_采购入库单_转换规则");
|
||
PushArgs pushArgs = BotpParamUtils.getPushArgs(RECEIPTNOTICE, PURINBILL, 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();
|
||
errormsg = errormsg.append(";").append(billMessage);
|
||
}
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
}
|
||
//获取下推单据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(PURINBILL, new QFilter[]{new QFilter("id", QCP.equals, next)});
|
||
load[i] = dynamicObject;
|
||
}
|
||
//开始提交
|
||
OperateOption operateOption = OperateOption.create();
|
||
OperationResult sumbitResult = OperationServiceHelper.executeOperate(Constants.TYPE_SUBMIT, PURINBILL, load, operateOption);
|
||
if (!sumbitResult.isSuccess()) {
|
||
List<IOperateInfo> allErrorOrValidateInfo = sumbitResult.getAllErrorOrValidateInfo();
|
||
if (allErrorOrValidateInfo.size() != 0) {
|
||
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
|
||
String message = iOperateInfo.getMessage();
|
||
errormsg = errormsg.append(";").append(message);
|
||
}
|
||
} else if (StringUtils.isNotBlank(sumbitResult.getMessage())) {
|
||
errormsg = errormsg.append(";").append(sumbitResult.getMessage());
|
||
} else {
|
||
errormsg = errormsg.append(";").append(sumbitResult.getInteractionContext().getSimpleMessage());
|
||
}
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
} else {
|
||
//开始审核
|
||
OperationResult auditResult = OperationServiceHelper.executeOperate(Constants.TYPE_AUDIT, PURINBILL, load, operateOption);
|
||
if (!auditResult.isSuccess()) {
|
||
List<IOperateInfo> allErrorOrValidateInfo1 = auditResult.getAllErrorOrValidateInfo();
|
||
if (allErrorOrValidateInfo1.size() != 0) {
|
||
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo1) {
|
||
String message = iOperateInfo.getMessage();
|
||
errormsg = errormsg.append(";").append(message);
|
||
}
|
||
} else if (StringUtils.isNotBlank(auditResult.getMessage())) {
|
||
errormsg = errormsg.append(";").append(auditResult.getMessage());
|
||
} else {
|
||
errormsg = errormsg.append(";").append(auditResult.getInteractionContext().getSimpleMessage());
|
||
}
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
}
|
||
}
|
||
//采购退货单
|
||
} else if (StringUtils.equals("pm_purrefundapplybill", entryOrderType)) {
|
||
//查询单据在金蝶系统中是否存在
|
||
DynamicObject pm_purrefundapplybill = BusinessDataServiceHelper.loadSingle(PM_PURREFUNDAPPLYBILL, new QFilter[]{new QFilter("billno", QCP.equals, billno)});
|
||
if (pm_purrefundapplybill == null) {
|
||
errormsg = errormsg.append(";").append("根据传入编号:" + billno + "未找到对应采购退货单");
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
}
|
||
Map<String, Set<JSONObject>> param = new HashMap<>();//传入转换规则处理参数
|
||
HashMap<Long, Set<Long>> entitypkMap = new HashMap<>();//上下游id映射Map
|
||
//参数值组装
|
||
if (orderLines.get("orderLine") instanceof Map) {
|
||
JSONObject orderLine = orderLines.getJSONObject("orderLine");
|
||
Long id = pm_purrefundapplybill.getLong("id");
|
||
JSONObject detailObject = new JSONObject();
|
||
String orderLineNo = orderLine.getString("orderLineNo");//金蝶源头单据细单号
|
||
BigDecimal actualQty = orderLine.getBigDecimal("actualQty");//入库数量
|
||
String itemCode = orderLine.getString("itemCode");//商品编码
|
||
Date productDate = orderLine.getDate("productDate");//生产日期
|
||
Date expireDate = orderLine.getDate("expireDate");//失效期
|
||
String batchCode = orderLine.getString("batchCode");//批次
|
||
String key1 = null;//注册证号
|
||
String key3 = null;//生产许可证
|
||
String key2 = null;//生产厂商
|
||
if (orderLine.get("extendProps") instanceof Map) {
|
||
JSONObject extendProps = orderLine.getJSONObject("extendProps");//批次信息
|
||
key1 = extendProps.getString("key1");//注册证号
|
||
key3 = extendProps.getString("key3");//生产许可证
|
||
key2 = extendProps.getString("key2");//生产厂商
|
||
}else{
|
||
JSONArray extendProps = orderLine.getJSONArray("extendProps");
|
||
for (Object o : extendProps) {
|
||
JSONObject extendProp = gson.fromJson(gson.toJson(o), JSONObject.class);
|
||
if(extendProp.getString("key1")!=null){
|
||
key1 = extendProp.getString("key1");//注册证号
|
||
key3 = extendProp.getString("key3");//生产许可证
|
||
key2 = extendProp.getString("key2");//生产厂商
|
||
}
|
||
}
|
||
}
|
||
detailObject.put("entryId", orderLineNo);
|
||
detailObject.put("uniqueCode", itemCode);
|
||
detailObject.put("quantity", actualQty);
|
||
detailObject.put("manufactureDate", productDate);
|
||
detailObject.put("expirationDate", expireDate);
|
||
detailObject.put("batch", batchCode);
|
||
detailObject.put("registrationCode", key1);
|
||
detailObject.put("licenceCode", key3);
|
||
detailObject.put("producer", key2);
|
||
detailObject.put("VoucherType", entryOrderType);
|
||
entitypkMap.computeIfAbsent(id, k -> new HashSet<>()).add(orderLine.getLong("orderLineNo"));
|
||
param.computeIfAbsent(orderLineNo, k -> new HashSet<>()).add(detailObject);
|
||
} else {
|
||
JSONArray orderLine = orderLines.getJSONArray("orderLine");
|
||
for (Object obj : orderLine) {
|
||
JSONObject orderLine1 = gson.fromJson(gson.toJson(obj), JSONObject.class);
|
||
Long id = pm_purrefundapplybill.getLong("id");
|
||
JSONObject detailObject = new JSONObject();
|
||
String orderLineNo = orderLine1.getString("orderLineNo");//金蝶源头单据细单号
|
||
BigDecimal actualQty = orderLine1.getBigDecimal("actualQty");//入库数量
|
||
String itemCode = orderLine1.getString("itemCode");//商品编码
|
||
Date productDate = orderLine1.getDate("productDate");//生产日期
|
||
Date expireDate = orderLine1.getDate("expireDate");//失效期
|
||
String batchCode = orderLine1.getString("batchCode");//批次
|
||
String key1 = null;//注册证号
|
||
String key3 = null;//生产许可证
|
||
String key2 = null;//生产厂商
|
||
if (orderLine1.get("extendProps") instanceof Map) {
|
||
JSONObject extendProps = orderLine1.getJSONObject("extendProps");//批次信息
|
||
key1 = extendProps.getString("key1");//注册证号
|
||
key3 = extendProps.getString("key3");//生产许可证
|
||
key2 = extendProps.getString("key2");//生产厂商
|
||
}else{
|
||
JSONArray extendProps = orderLine1.getJSONArray("extendProps");
|
||
for (Object o : extendProps) {
|
||
JSONObject extendProp = gson.fromJson(gson.toJson(o), JSONObject.class);
|
||
if(extendProp.getString("key1")!=null){
|
||
key1 = extendProp.getString("key1");//注册证号
|
||
key3 = extendProp.getString("key3");//生产许可证
|
||
key2 = extendProp.getString("key2");//生产厂商
|
||
}
|
||
}
|
||
}
|
||
detailObject.put("entryId", orderLineNo);
|
||
detailObject.put("uniqueCode", itemCode);
|
||
detailObject.put("quantity", actualQty);
|
||
detailObject.put("manufactureDate", productDate);
|
||
detailObject.put("expirationDate", expireDate);
|
||
detailObject.put("batch", batchCode);
|
||
detailObject.put("registrationCode", key1);
|
||
detailObject.put("licenceCode", key3);
|
||
detailObject.put("producer", key2);
|
||
detailObject.put("VoucherType", entryOrderType);
|
||
entitypkMap.computeIfAbsent(id, k -> new HashSet<>()).add(orderLine1.getLong("orderLineNo"));
|
||
param.computeIfAbsent(orderLineNo, k -> new HashSet<>()).add(detailObject);
|
||
}
|
||
}
|
||
|
||
//开始下推
|
||
String rule = BotpParamUtils.getBotpRuleId(PM_PURREFUNDAPPLYBILL, PURINBILL, "采购退货申请_采购入库_转换规则_扩展");
|
||
PushArgs pushArgs = BotpParamUtils.getPushArgs(PM_PURREFUNDAPPLYBILL, PURINBILL, 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();
|
||
errormsg = errormsg.append(";").append(billMessage);
|
||
}
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
|
||
}
|
||
//获取下推单据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(PURINBILL, new QFilter[]{new QFilter("id", QCP.equals, next)});
|
||
load[i] = dynamicObject;
|
||
}
|
||
//开始提交
|
||
OperateOption operateOption = OperateOption.create();
|
||
OperationResult sumbitResult = OperationServiceHelper.executeOperate(Constants.TYPE_SUBMIT, PURINBILL, load, operateOption);
|
||
if (!sumbitResult.isSuccess()) {
|
||
List<IOperateInfo> allErrorOrValidateInfo = sumbitResult.getAllErrorOrValidateInfo();
|
||
if (allErrorOrValidateInfo.size() != 0) {
|
||
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
|
||
String message = iOperateInfo.getMessage();
|
||
errormsg = errormsg.append(";").append(message);
|
||
}
|
||
} else if (StringUtils.isNotBlank(sumbitResult.getMessage())) {
|
||
errormsg = errormsg.append(";").append(sumbitResult.getMessage());
|
||
|
||
} else {
|
||
errormsg = errormsg.append(";").append(sumbitResult.getInteractionContext().getSimpleMessage());
|
||
}
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
} else {
|
||
//开始审核
|
||
OperationResult auditResult = OperationServiceHelper.executeOperate(Constants.TYPE_AUDIT, PURINBILL, load, operateOption);
|
||
if (!auditResult.isSuccess()) {
|
||
List<IOperateInfo> allErrorOrValidateInfo1 = auditResult.getAllErrorOrValidateInfo();
|
||
if (allErrorOrValidateInfo1.size() != 0) {
|
||
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo1) {
|
||
String message = iOperateInfo.getMessage();
|
||
errormsg = errormsg.append(";").append(message);
|
||
}
|
||
} else if (StringUtils.isNotBlank(auditResult.getMessage())) {
|
||
errormsg = errormsg.append(";").append(auditResult.getMessage());
|
||
} else {
|
||
errormsg = errormsg.append(";").append(auditResult.getInteractionContext().getSimpleMessage());
|
||
}
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
}
|
||
}
|
||
//其他入库申请单
|
||
} else if (StringUtils.equals("tqq9_otherinapply", entryOrderType)) {
|
||
//查询单据在金蝶系统中是否存在
|
||
DynamicObject tqq9_otherinapply = BusinessDataServiceHelper.loadSingle(TQQ9_OTHERINAPPLY, new QFilter[]{new QFilter("billno", QCP.equals, billno)});
|
||
if (tqq9_otherinapply == null) {
|
||
errormsg = errormsg.append(";").append("根据传入编号:" + billno + "未找到对应其他入库申请单");
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
}
|
||
Map<String, Set<JSONObject>> param = new HashMap<>();//传入转换规则处理参数
|
||
HashMap<Long, Set<Long>> entitypkMap = new HashMap<>();//上下游id映射Map
|
||
//参数值组装
|
||
if (orderLines.get("orderLine") instanceof Map) {
|
||
JSONObject orderLine = orderLines.getJSONObject("orderLine");
|
||
Long id = tqq9_otherinapply.getLong("id");
|
||
JSONObject detailObject = new JSONObject();
|
||
String orderLineNo = orderLine.getString("orderLineNo");//金蝶源头单据细单号
|
||
BigDecimal actualQty = orderLine.getBigDecimal("actualQty");//入库数量
|
||
String itemCode = orderLine.getString("itemCode");//商品编码
|
||
Date productDate = orderLine.getDate("productDate");//生产日期
|
||
Date expireDate = orderLine.getDate("expireDate");//失效期
|
||
String batchCode = orderLine.getString("batchCode");//批次
|
||
String key1 = null;//注册证号
|
||
String key3 = null;//生产许可证
|
||
String key2 = null;//生产厂商
|
||
if (orderLine.get("extendProps") instanceof Map) {
|
||
JSONObject extendProps = orderLine.getJSONObject("extendProps");//批次信息
|
||
key1 = extendProps.getString("key1");//注册证号
|
||
key3 = extendProps.getString("key3");//生产许可证
|
||
key2 = extendProps.getString("key2");//生产厂商
|
||
}else{
|
||
JSONArray extendProps = orderLine.getJSONArray("extendProps");
|
||
for (Object o : extendProps) {
|
||
JSONObject extendProp = gson.fromJson(gson.toJson(o), JSONObject.class);
|
||
if(extendProp.getString("key1")!=null){
|
||
key1 = extendProp.getString("key1");//注册证号
|
||
key3 = extendProp.getString("key3");//生产许可证
|
||
key2 = extendProp.getString("key2");//生产厂商
|
||
}
|
||
}
|
||
}
|
||
detailObject.put("entryId", orderLineNo);
|
||
detailObject.put("uniqueCode", itemCode);
|
||
detailObject.put("quantity", actualQty);
|
||
detailObject.put("manufactureDate", productDate);
|
||
detailObject.put("expirationDate", expireDate);
|
||
detailObject.put("batch", batchCode);
|
||
detailObject.put("registrationCode", key1);
|
||
detailObject.put("licenceCode", key3);
|
||
detailObject.put("producer", key2);
|
||
detailObject.put("VoucherType", entryOrderType);
|
||
entitypkMap.computeIfAbsent(id, k -> new HashSet<>()).add(orderLine.getLong("orderLineNo"));
|
||
param.computeIfAbsent(orderLineNo, k -> new HashSet<>()).add(detailObject);
|
||
} else {
|
||
JSONArray orderLine = orderLines.getJSONArray("orderLine");
|
||
for (Object obj : orderLine) {
|
||
JSONObject orderLine1 = gson.fromJson(gson.toJson(obj), JSONObject.class);
|
||
Long id = tqq9_otherinapply.getLong("id");
|
||
JSONObject detailObject = new JSONObject();
|
||
String orderLineNo = orderLine1.getString("orderLineNo");//金蝶源头单据细单号
|
||
BigDecimal actualQty = orderLine1.getBigDecimal("actualQty");//入库数量
|
||
String itemCode = orderLine1.getString("itemCode");//商品编码
|
||
Date productDate = orderLine1.getDate("productDate");//生产日期
|
||
Date expireDate = orderLine1.getDate("expireDate");//失效期
|
||
String batchCode = orderLine1.getString("batchCode");//批次
|
||
String key1 = null;//注册证号
|
||
String key3 = null;//生产许可证
|
||
String key2 = null;//生产厂商
|
||
if (orderLine1.get("extendProps") instanceof Map) {
|
||
JSONObject extendProps = orderLine1.getJSONObject("extendProps");//批次信息
|
||
key1 = extendProps.getString("key1");//注册证号
|
||
key3 = extendProps.getString("key3");//生产许可证
|
||
key2 = extendProps.getString("key2");//生产厂商
|
||
}else{
|
||
JSONArray extendProps = orderLine1.getJSONArray("extendProps");
|
||
for (Object o : extendProps) {
|
||
JSONObject extendProp = gson.fromJson(gson.toJson(o), JSONObject.class);
|
||
if(extendProp.getString("key1")!=null){
|
||
key1 = extendProp.getString("key1");//注册证号
|
||
key3 = extendProp.getString("key3");//生产许可证
|
||
key2 = extendProp.getString("key2");//生产厂商
|
||
}
|
||
}
|
||
}
|
||
detailObject.put("entryId", orderLineNo);
|
||
detailObject.put("uniqueCode", itemCode);
|
||
detailObject.put("quantity", actualQty);
|
||
detailObject.put("manufactureDate", productDate);
|
||
detailObject.put("expirationDate", expireDate);
|
||
detailObject.put("batch", batchCode);
|
||
detailObject.put("registrationCode", key1);
|
||
detailObject.put("licenceCode", key3);
|
||
detailObject.put("producer", key2);
|
||
detailObject.put("VoucherType", entryOrderType);
|
||
entitypkMap.computeIfAbsent(id, k -> new HashSet<>()).add(orderLine1.getLong("orderLineNo"));
|
||
param.computeIfAbsent(orderLineNo, k -> new HashSet<>()).add(detailObject);
|
||
}
|
||
}
|
||
|
||
//开始下推
|
||
String rule = BotpParamUtils.getBotpRuleId(TQQ9_OTHERINAPPLY, IM_OTHERINBILL, "其他入库申请_其他入库_转换规则");
|
||
PushArgs pushArgs = BotpParamUtils.getPushArgs(TQQ9_OTHERINAPPLY, IM_OTHERINBILL, 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();
|
||
errormsg = errormsg.append(";").append(billMessage);
|
||
}
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
}
|
||
//获取下推单据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_OTHERINBILL, new QFilter[]{new QFilter("id", QCP.equals, next)});
|
||
load[i] = dynamicObject;
|
||
}
|
||
//开始提交
|
||
OperateOption operateOption = OperateOption.create();
|
||
OperationResult sumbitResult = OperationServiceHelper.executeOperate(Constants.TYPE_SUBMIT, IM_OTHERINBILL, load, operateOption);
|
||
if (!sumbitResult.isSuccess()) {
|
||
List<IOperateInfo> allErrorOrValidateInfo = sumbitResult.getAllErrorOrValidateInfo();
|
||
if (allErrorOrValidateInfo.size() != 0) {
|
||
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
|
||
String billMessage = iOperateInfo.getMessage();
|
||
errormsg = errormsg.append(";").append(billMessage);
|
||
}
|
||
} else if (StringUtils.isNotBlank(sumbitResult.getMessage())) {
|
||
errormsg = errormsg.append(";").append(sumbitResult.getMessage());
|
||
} else {
|
||
errormsg = errormsg.append(";").append(sumbitResult.getInteractionContext().getSimpleMessage());
|
||
}
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
} else {
|
||
//开始审核
|
||
OperationResult auditResult = OperationServiceHelper.executeOperate(Constants.TYPE_AUDIT, IM_OTHERINBILL, load, operateOption);
|
||
if (!auditResult.isSuccess()) {
|
||
List<IOperateInfo> allErrorOrValidateInfo1 = auditResult.getAllErrorOrValidateInfo();
|
||
if (allErrorOrValidateInfo1.size() != 0) {
|
||
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo1) {
|
||
String billMessage = iOperateInfo.getMessage();
|
||
errormsg = errormsg.append(";").append(billMessage);
|
||
}
|
||
} else if (StringUtils.isNotBlank(auditResult.getMessage())) {
|
||
errormsg = errormsg.append(";").append(auditResult.getMessage());
|
||
} else {
|
||
errormsg = errormsg.append(";").append(auditResult.getInteractionContext().getSimpleMessage());
|
||
}
|
||
response.setMessage(errormsg.substring(1));
|
||
response.setCode("-1");
|
||
response.setFlag("failure");
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
}
|
||
}
|
||
}
|
||
//回传成功
|
||
return CustomApiResult.success(wmsXmlReturn);
|
||
}
|
||
|
||
} |