1.WMS入库确认格式调整

2.WMS出库确认开发 50%
This commit is contained in:
龚豆豆 2025-09-29 18:03:10 +08:00
parent 752bcdf1be
commit aa20736f52
2 changed files with 545 additions and 13 deletions

View File

@ -477,7 +477,7 @@ public class WMSPurInController {
erpOrderTypes.add(PM_PURREFUNDAPPLYBILL);
erpOrderTypes.add(TQQ9_OTHERINAPPLY);
if (!erpOrderTypes.contains(erpOrderType)) {
errormsg = errormsg.append(",").append("传入参数 VoucherType 为无效值");
errormsg = errormsg.append(",").append("传入参数 erpOrderType 为无效值");
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
@ -602,8 +602,6 @@ public class WMSPurInController {
JSONObject container = containers.getJSONObject("container");
JSONObject receiptDetail = detail.getJSONObject("receiptDetail");
Long id = receiptnotice.getLong("id");
// Map<String, Object> param = new HashMap<>();//传入转换规则处理参数
// HashMap<Long, Set<Long>> entitypkMap = new HashMap<>();//上下游id映射Map
JSONObject detailObject = new JSONObject();
JSONObject receiptContainer = container.getJSONObject("receiptContainer");
String erpOrderLineNum = receiptDetail.getString("erpOrderLineNum");//金蝶源头单据细单号
@ -629,8 +627,6 @@ public class WMSPurInController {
param.put(erpOrderLineNum, detailObject);
}
}
//开始下推
String rule = BotpParamUtils.getBotpRuleId(RECEIPTNOTICE, PURINBILL, "收货通知单_采购入库单_转换规则");
PushArgs pushArgs = BotpParamUtils.getPushArgs(RECEIPTNOTICE, PURINBILL, BILLENTRY, param, entitypkMap, rule);
@ -686,9 +682,9 @@ public class WMSPurInController {
errormsg = errormsg.append(",").append(message);
}
} else if (StringUtils.isNotBlank(auditResult.getMessage())) {
errormsg = errormsg.append(",").append(sumbitResult.getMessage());
errormsg = errormsg.append(",").append(auditResult.getMessage());
} else {
errormsg = errormsg.append(",").append(sumbitResult.getInteractionContext().getSimpleMessage());
errormsg = errormsg.append(",").append(auditResult.getInteractionContext().getSimpleMessage());
}
response.setMessage(errormsg.substring(1));
response.setCode("-1");
@ -830,9 +826,9 @@ public class WMSPurInController {
errormsg = errormsg.append(",").append(message);
}
} else if (StringUtils.isNotBlank(auditResult.getMessage())) {
errormsg = errormsg.append(",").append(sumbitResult.getMessage());
errormsg = errormsg.append(",").append(auditResult.getMessage());
} else {
errormsg = errormsg.append(",").append(sumbitResult.getInteractionContext().getSimpleMessage());
errormsg = errormsg.append(",").append(auditResult.getInteractionContext().getSimpleMessage());
}
response.setMessage(errormsg.substring(1));
response.setCode("-1");
@ -961,7 +957,6 @@ public class WMSPurInController {
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
} else {
//开始审核
OperationResult auditResult = OperationServiceHelper.executeOperate(Constants.TYPE_AUDIT, IM_OTHERINBILL, load, operateOption);
@ -973,10 +968,9 @@ public class WMSPurInController {
errormsg = errormsg.append(",").append(billMessage);
}
} else if (StringUtils.isNotBlank(auditResult.getMessage())) {
errormsg = errormsg.append(",").append(sumbitResult.getMessage());
errormsg = errormsg.append(",").append(auditResult.getMessage());
} else {
errormsg = errormsg.append(",").append(sumbitResult.getInteractionContext().getSimpleMessage());
errormsg = errormsg.append(",").append(auditResult.getInteractionContext().getSimpleMessage());
}
response.setMessage(errormsg.substring(1));
response.setCode("-1");

View File

@ -3,6 +3,7 @@ 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;
@ -20,6 +21,7 @@ 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;
@ -448,8 +450,544 @@ public class WMSSaleOutController {
resultExt.setSuccessCount(successCount);
resultExt.setResult(results);
return CustomApiResult.success(resultExt);
}
@ApiPostMapping(value = "/WMS_SaleOutnPush_SH", desc = "WMS-出库回传")
public CustomApiResult<WMSXmlReturn> WMS_SaleOutnPush_SH
(@NotNull @ApiParam(value = "入参", required = true) Map<String, Object> dataMap) {
//返回值初始化
Gson gson = new Gson();
JSONObject data = gson.fromJson(dataMap.toString(), JSONObject.class);
JSONObject receipt = data.getJSONObject("receipt");
JSONObject header = receipt.getJSONObject("header");
JSONObject receiptHeader = header.getJSONObject("receiptHeader");
String billno = receiptHeader.getString("erpOrderCode");//单据编号
String erpOrderType = receiptHeader.getString("erpOrderType");//单据类型
JSONObject details = receipt.getJSONObject("details");
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> erpOrderTypes = new ArrayList<>();
erpOrderTypes.add(SM_DELIVERNOTICE);
erpOrderTypes.add(SM_RETURNAPPLY);
erpOrderTypes.add(TQQ9_OTHEROUTAPPLY);
if (!erpOrderTypes.contains(erpOrderType)) {
errormsg = errormsg.append(",").append("传入参数 erpOrderType 为无效值");
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}
//必填项校验
if (ApiResultExt.validateRequired(erpOrderType, "String")) {
errormsg = errormsg.append(",").append("传入参数 erpOrderType 为空");
}
if (ApiResultExt.validateRequired(billno, "String")) {
errormsg = errormsg.append(",").append("传入参数 erpOrderCode 为空");
}
if (details.get("detail") instanceof Map) {
JSONObject detail = details.getJSONObject("detail");
JSONObject receiptDetail = detail.getJSONObject("receiptDetail");
BigDecimal quantity = receiptDetail.getBigDecimal("quantity");//出库数量
String erpOrderLineNum = receiptDetail.getString("erpOrderLineNum");//金蝶源头单据细单号
if (receiptDetail.getString("erpOrderLineNum").length() > 19) {
errormsg = errormsg.append(",").append("Value " + erpOrderLineNum + " 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(erpOrderType, new QFilter[]{new QFilter("billentry.id", QCP.equals, receiptDetail.getLong("erpOrderLineNum"))});
if (isexsit == null) {
errormsg = errormsg.append(",").append("传入参数 erpOrderLineNum 在金蝶系统中未查询到对应单据");
}
if (ApiResultExt.validateRequired(quantity, "BigDecimal")) {
errormsg = errormsg.append(",").append("传入参数 quantity 为空");
}
if (ApiResultExt.validateRequired(erpOrderLineNum, "String")) {
errormsg = errormsg.append(",").append("传入参数 erpOrderLineNum 为空");
}
if (errormsg.length() > 0) {
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}
} else {
JSONArray detail1 = details.getJSONArray("detail");
for (Object obj : detail1) {
JSONObject detail = gson.fromJson(gson.toJson(obj), JSONObject.class);
JSONObject receiptDetail = detail.getJSONObject("receiptDetail");
BigDecimal quantity = receiptDetail.getBigDecimal("quantity");//出库数量
String erpOrderLineNum = receiptDetail.getString("erpOrderLineNum");//金蝶源头单据细单号
if (receiptDetail.getString("erpOrderLineNum").length() > 19) {
errormsg = errormsg.append(",").append("Value " + erpOrderLineNum + " 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(erpOrderType, new QFilter[]{new QFilter("billentry.id", QCP.equals, receiptDetail.getLong("erpOrderLineNum"))});
if (isexsit == null) {
errormsg = errormsg.append(",").append("传入参数 erpOrderLineNum 在金蝶系统中未查询到对应单据");
}
if (ApiResultExt.validateRequired(quantity, "BigDecimal")) {
errormsg = errormsg.append(",").append("传入参数 quantity 为空");
}
if (ApiResultExt.validateRequired(erpOrderLineNum, "String")) {
errormsg = errormsg.append(",").append("传入参数 erpOrderLineNum 为空");
}
}
if (errormsg.length() > 0) {
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}
}
//发货通知单
if (StringUtils.equals("sm_delivernotice", erpOrderType)) {
//查询单据在金蝶系统中是否存在
DynamicObject sm_delivernotice = BusinessDataServiceHelper.loadSingle(SM_DELIVERNOTICE, new QFilter[]{new QFilter("billno", QCP.equals, billno)});
if (sm_delivernotice == null) {
errormsg = errormsg.append(",").append("根据传入编号:" + billno + "未找到对应发货通知单");
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}
//参数值组装
Map<String, Object> param = new HashMap<>();//传入转换规则处理参数
HashMap<Long, Set<Long>> entitypkMap = new HashMap<>();//上下游id映射Map
if (details.get("detail") instanceof Map) {
JSONObject detail = details.getJSONObject("detail");
JSONObject containers = detail.getJSONObject("containers");
JSONObject container = containers.getJSONObject("container");
JSONObject receiptDetail = detail.getJSONObject("receiptDetail");
Long id = sm_delivernotice.getLong("id");
JSONObject detailObject = new JSONObject();
JSONObject receiptContainer = container.getJSONObject("receiptContainer");
String erpOrderLineNum = receiptDetail.getString("erpOrderLineNum");//金蝶源头单据细单号
BigDecimal quantity = receiptDetail.getBigDecimal("quantity");//出库数量
String uniqueCode = receiptContainer.getString("itemCode");//商品编码
Date manufactureDate = receiptContainer.getDate("created");//生产日期
Date expirationDate = receiptContainer.getDate("lastUpdated");//失效期
String batch = receiptContainer.getString("batch");//批次
String attribute1 = receiptContainer.getString("attribute1");//注册证号
String attribute3 = receiptContainer.getString("attribute3");//生产许可证
String attribute2 = receiptContainer.getString("attribute2");//生产厂商
detailObject.put("entryId", erpOrderLineNum);
detailObject.put("uniqueCode", uniqueCode);
detailObject.put("quantity", quantity);
detailObject.put("manufactureDate", manufactureDate);
detailObject.put("expirationDate", expirationDate);
detailObject.put("batch", batch);
detailObject.put("registrationCode", attribute1);
detailObject.put("licenceCode", attribute3);
detailObject.put("producer", attribute2);
detailObject.put("VoucherType", erpOrderType);
entitypkMap.computeIfAbsent(id, k -> new HashSet<>()).add(receiptDetail.getLong("erpOrderLineNum"));
param.put(erpOrderLineNum, detailObject);
}else {
JSONArray detail1 = details.getJSONArray("detail");
for (Object obj : detail1) {
JSONObject detail = gson.fromJson(gson.toJson(obj), JSONObject.class);
JSONObject containers = detail.getJSONObject("containers");
JSONObject container = containers.getJSONObject("container");
JSONObject receiptDetail = detail.getJSONObject("receiptDetail");
Long id = sm_delivernotice.getLong("id");
JSONObject detailObject = new JSONObject();
JSONObject receiptContainer = container.getJSONObject("receiptContainer");
String erpOrderLineNum = receiptDetail.getString("erpOrderLineNum");//金蝶源头单据细单号
BigDecimal quantity = receiptDetail.getBigDecimal("quantity");//入库数量
String uniqueCode = receiptContainer.getString("itemCode");//商品编码
Date manufactureDate = receiptContainer.getDate("created");//生产日期
Date expirationDate = receiptContainer.getDate("lastUpdated");//失效期
String batch = receiptContainer.getString("batch");//批次
String attribute1 = receiptContainer.getString("attribute1");//注册证号
String attribute3 = receiptContainer.getString("attribute3");//生产许可证
String attribute2 = receiptContainer.getString("attribute2");//生产厂商
detailObject.put("entryId", erpOrderLineNum);
detailObject.put("uniqueCode", uniqueCode);
detailObject.put("quantity", quantity);
detailObject.put("manufactureDate", manufactureDate);
detailObject.put("expirationDate", expirationDate);
detailObject.put("batch", batch);
detailObject.put("registrationCode", attribute1);
detailObject.put("licenceCode", attribute3);
detailObject.put("producer", attribute2);
detailObject.put("VoucherType", erpOrderType);
entitypkMap.computeIfAbsent(id, k -> new HashSet<>()).add(receiptDetail.getLong("erpOrderLineNum"));
param.put(erpOrderLineNum, 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();
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_SALOUTBILL, new QFilter[]{new QFilter("id", QCP.equals, next)});
load[i] = dynamicObject;
}
//开始提交
OperateOption operateOption = OperateOption.create();
OperationResult sumbitResult = OperationServiceHelper.executeOperate(Constants.TYPE_SUBMIT, IM_SALOUTBILL, 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, IM_SALOUTBILL, 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("sm_returnapply", erpOrderType)) {
//查询单据在金蝶系统中是否存在
DynamicObject sm_returnapply = BusinessDataServiceHelper.loadSingle(SM_RETURNAPPLY, new QFilter[]{new QFilter("billno", QCP.equals, billno)});
if (sm_returnapply == null) {
errormsg = errormsg.append(",").append("根据传入编号:" + billno + "未找到对应销售退货单");
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}
//参数值组装
Map<String, Object> param = new HashMap<>();//传入转换规则处理参数
HashMap<Long, Set<Long>> entitypkMap = new HashMap<>();//上下游id映射Map
if (details.get("detail") instanceof JSONObject) {
JSONObject detail = details.getJSONObject("detail");
JSONObject containers = detail.getJSONObject("containers");
JSONObject container = containers.getJSONObject("container");
JSONObject receiptDetail = detail.getJSONObject("receiptDetail");
Long id = sm_returnapply.getLong("id");
JSONObject detailObject = new JSONObject();
JSONObject receiptContainer = container.getJSONObject("receiptContainer");
String erpOrderLineNum = receiptDetail.getString("erpOrderLineNum");//金蝶源头单据细单号
BigDecimal quantity = receiptDetail.getBigDecimal("quantity");//入库数量
String uniqueCode = receiptContainer.getString("itemCode");//商品编码
Date manufactureDate = receiptContainer.getDate("created");//生产日期
Date expirationDate = receiptContainer.getDate("lastUpdated");//失效期
String batch = receiptContainer.getString("batch");//批次
String attribute1 = receiptContainer.getString("attribute1");//注册证号
String attribute3 = receiptContainer.getString("attribute3");//生产许可证
String attribute2 = receiptContainer.getString("attribute2");//生产厂商
detailObject.put("entryId", erpOrderLineNum);
detailObject.put("uniqueCode", uniqueCode);
detailObject.put("quantity", quantity);
detailObject.put("manufactureDate", manufactureDate);
detailObject.put("expirationDate", expirationDate);
detailObject.put("batch", batch);
detailObject.put("registrationCode", attribute1);
detailObject.put("licenceCode", attribute3);
detailObject.put("producer", attribute2);
detailObject.put("VoucherType", erpOrderType);
entitypkMap.computeIfAbsent(id, k -> new HashSet<>()).add(receiptDetail.getLong("erpOrderLineNum"));
param.put(erpOrderLineNum, detailObject);
} else {
JSONArray detail1 = details.getJSONArray("detail");
for (Object obj : detail1) {
JSONObject detail = gson.fromJson(gson.toJson(obj), JSONObject.class);
JSONObject containers = detail.getJSONObject("containers");
JSONObject container = containers.getJSONObject("container");
JSONObject receiptDetail = detail.getJSONObject("receiptDetail");
Long id = sm_returnapply.getLong("id");
JSONObject detailObject = new JSONObject();
JSONObject receiptContainer = container.getJSONObject("receiptContainer");
String erpOrderLineNum = receiptDetail.getString("erpOrderLineNum");//金蝶源头单据细单号
BigDecimal quantity = receiptDetail.getBigDecimal("quantity");//入库数量
String uniqueCode = receiptContainer.getString("itemCode");//商品编码
Date manufactureDate = receiptContainer.getDate("created");//生产日期
Date expirationDate = receiptContainer.getDate("lastUpdated");//失效期
String batch = receiptContainer.getString("batch");//批次
String attribute1 = receiptContainer.getString("attribute1");//注册证号
String attribute3 = receiptContainer.getString("attribute3");//生产许可证
String attribute2 = receiptContainer.getString("attribute2");//生产厂商
detailObject.put("entryId", erpOrderLineNum);
detailObject.put("uniqueCode", uniqueCode);
detailObject.put("quantity", quantity);
detailObject.put("manufactureDate", manufactureDate);
detailObject.put("expirationDate", expirationDate);
detailObject.put("batch", batch);
detailObject.put("registrationCode", attribute1);
detailObject.put("licenceCode", attribute3);
detailObject.put("producer", attribute2);
detailObject.put("VoucherType", erpOrderType);
entitypkMap.computeIfAbsent(id, k -> new HashSet<>()).add(receiptDetail.getLong("erpOrderLineNum"));
param.put(erpOrderLineNum, 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();
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_SALOUTBILL, new QFilter[]{new QFilter("id", QCP.equals, next)});
load[i] = dynamicObject;
}
//开始提交
OperateOption operateOption = OperateOption.create();
OperationResult sumbitResult = OperationServiceHelper.executeOperate(Constants.TYPE_SUBMIT, IM_SALOUTBILL, 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_SALOUTBILL, 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);
}
}
//销售退货单
} else if (StringUtils.equals("tqq9_otheroutapply", erpOrderType)) {
//查询单据在金蝶系统中是否存在
DynamicObject tqq9_otheroutapply = BusinessDataServiceHelper.loadSingle(TQQ9_OTHEROUTAPPLY, new QFilter[]{new QFilter("billno", QCP.equals, billno)});
if (tqq9_otheroutapply == null) {
errormsg = errormsg.append(",").append("根据传入编号:" + billno + "未找到对应其他出库申请单");
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}
//根据业务类型判断转换规则名称
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);
//组装参数值
Map<String, Object> param = new HashMap<>();//传入转换规则处理参数
HashMap<Long, Set<Long>> entitypkMap = new HashMap<>();//上下游id映射Map
if (details.get("detail") instanceof JSONObject) {
JSONObject detail = details.getJSONObject("detail");
JSONObject containers = detail.getJSONObject("containers");
JSONObject container = containers.getJSONObject("container");
JSONObject receiptDetail = detail.getJSONObject("receiptDetail");
Long id = tqq9_otheroutapply.getLong("id");
JSONObject detailObject = new JSONObject();
JSONObject receiptContainer = container.getJSONObject("receiptContainer");
String erpOrderLineNum = receiptDetail.getString("erpOrderLineNum");//金蝶源头单据细单号
BigDecimal quantity = receiptDetail.getBigDecimal("quantity");//入库数量
String uniqueCode = receiptContainer.getString("itemCode");//商品编码
Date manufactureDate = receiptContainer.getDate("created");//生产日期
Date expirationDate = receiptContainer.getDate("lastUpdated");//失效期
String batch = receiptContainer.getString("batch");//批次
String attribute1 = receiptContainer.getString("attribute1");//注册证号
String attribute3 = receiptContainer.getString("attribute3");//生产许可证
String attribute2 = receiptContainer.getString("attribute2");//生产厂商
detailObject.put("entryId", erpOrderLineNum);
detailObject.put("uniqueCode", uniqueCode);
detailObject.put("quantity", quantity);
detailObject.put("manufactureDate", manufactureDate);
detailObject.put("expirationDate", expirationDate);
detailObject.put("batch", batch);
detailObject.put("registrationCode", attribute1);
detailObject.put("licenceCode", attribute3);
detailObject.put("producer", attribute2);
detailObject.put("VoucherType", erpOrderType);
entitypkMap.computeIfAbsent(id, k -> new HashSet<>()).add(receiptDetail.getLong("erpOrderLineNum"));
param.put(erpOrderLineNum, detailObject);
} else {
JSONArray detail1 = details.getJSONArray("detail");
for (Object obj : detail1) {
JSONObject detail = gson.fromJson(gson.toJson(obj), JSONObject.class);
JSONObject containers = detail.getJSONObject("containers");
JSONObject container = containers.getJSONObject("container");
JSONObject receiptDetail = detail.getJSONObject("receiptDetail");
Long id = tqq9_otheroutapply.getLong("id");
JSONObject detailObject = new JSONObject();
JSONObject receiptContainer = container.getJSONObject("receiptContainer");
String erpOrderLineNum = receiptDetail.getString("erpOrderLineNum");//金蝶源头单据细单号
BigDecimal quantity = receiptDetail.getBigDecimal("quantity");//入库数量
String uniqueCode = receiptContainer.getString("itemCode");//商品编码
Date manufactureDate = receiptContainer.getDate("created");//生产日期
Date expirationDate = receiptContainer.getDate("lastUpdated");//失效期
String batch = receiptContainer.getString("batch");//批次
String attribute1 = receiptContainer.getString("attribute1");//注册证号
String attribute3 = receiptContainer.getString("attribute3");//生产许可证
String attribute2 = receiptContainer.getString("attribute2");//生产厂商
detailObject.put("entryId", erpOrderLineNum);
detailObject.put("uniqueCode", uniqueCode);
detailObject.put("quantity", quantity);
detailObject.put("manufactureDate", manufactureDate);
detailObject.put("expirationDate", expirationDate);
detailObject.put("batch", batch);
detailObject.put("registrationCode", attribute1);
detailObject.put("licenceCode", attribute3);
detailObject.put("producer", attribute2);
detailObject.put("VoucherType", erpOrderType);
entitypkMap.computeIfAbsent(id, k -> new HashSet<>()).add(receiptDetail.getLong("erpOrderLineNum"));
param.put(erpOrderLineNum, 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();
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_OTHEROUTBILL, new QFilter[]{new QFilter("id", QCP.equals, next)});
load[i] = dynamicObject;
}
//开始提交
OperateOption operateOption = OperateOption.create();
OperationResult sumbitResult = OperationServiceHelper.executeOperate(Constants.TYPE_SUBMIT, IM_OTHEROUTBILL, 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_OTHEROUTBILL, 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);
}
}