lc/lc123/cloud/app/api/controller/WMSSaleOutCloseController.java

440 lines
24 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package tqq9.lc123.cloud.app.api.controller;
import com.alibaba.fastjson.JSONObject;
import com.drew.lang.annotations.NotNull;
import com.google.gson.Gson;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.utils.StringUtils;
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 tqq9.lc123.cloud.app.api.model.WMSXmlReturn;
import tqq9.lc123.cloud.app.api.utils.ApiResultExt;
import tqq9.lc123.cloud.app.api.utils.Constants;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static tqq9.lc123.cloud.app.plugin.form.result.CloneBill.cloneOperation;
@ApiController(value = "WMSSaleOutCloseController", desc = "WMS-出库关闭")
public class WMSSaleOutCloseController {
private static String SM_DELIVERNOTICE = "sm_delivernotice";//发货通知单
private static String SM_RETURNAPPLY = "sm_returnapply";//销售退货申请单
private static String TQQ9_OTHEROUTAPPLY = "tqq9_otheroutapply";//其他出库申请
private static String PM_PURREFUNDAPPLYBILL = "pm_purrefundapplybill";//采购退货申请
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 = "/WMSSaleOutClose", desc = "WMS-出库关闭")
public CustomApiResult<ApiResultExt> WMSSaleOutClose
(
@NotNull @ApiParam(value = "来源单据号", required = true) String cVouCode,
@NotNull @ApiParam(value = "单据类型", required = true) String VoucherType,
@NotNull @ApiParam(value = "归属", required = true) String BelongTo) {
//返回值初始化
ApiResultExt resultExt = new ApiResultExt();
List<ApiResultExt.ResultBean> results = new ArrayList<>();
resultExt.setResult(results);
String billno = cVouCode;//单据编号
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);
int failCount = 0;//失败数量
int successCount = 1;//成功数量
//必填项校验
VoucherType = billTypeMap.get(VoucherType);
if (ApiResultExt.validateRequired(VoucherType, "String")) {
errormsg = "传入参数 VoucherType 为空";
resultExt = ApiResultExt.errorRetrun(VoucherType, errormsg, error, resultExt);
}
if (ApiResultExt.validateRequired(billno, "String")) {
errormsg = "传入参数 cVouCode 为空";
resultExt = ApiResultExt.errorRetrun(VoucherType, errormsg, error, resultExt);
}
rowmsg = resultExt.getResult().get(0).getErrors().getRowMsg();
if (!rowmsg.isEmpty()) {
return CustomApiResult.success(resultExt);
}
ArrayList<String> VoucherTypes = new ArrayList<>();
VoucherTypes.add(SM_DELIVERNOTICE);
VoucherTypes.add(PM_PURREFUNDAPPLYBILL);
VoucherTypes.add(TQQ9_OTHEROUTAPPLY);
if (!VoucherTypes.contains(VoucherType)) {
errormsg = "传入参数 VoucherType 为无效值";
resultExt = ApiResultExt.errorRetrun(VoucherType, errormsg, error, resultExt);
return CustomApiResult.success(resultExt);
}
//发货通知单
if (StringUtils.equals("sm_delivernotice", VoucherType)) {
//查询单据在金蝶系统中是否存在
DynamicObject delivernotice = BusinessDataServiceHelper.loadSingle(SM_DELIVERNOTICE, new QFilter[]{new QFilter("billno", QCP.equals, billno)});
if (delivernotice == null) {
errormsg = "根据传入编号:" + billno + "未找到对应发货通知单";
resultExt = ApiResultExt.errorRetrun(VoucherType, errormsg, error, resultExt);
return CustomApiResult.success(resultExt);
}
resultBean.setId(delivernotice.getString("id"));
resultBean.setBillStatus(true);
if (!StringUtils.equals("C", delivernotice.getString("billstatus"))) {
errormsg = "编号:" + billno + "的单据状态非审核,无法关闭";
resultExt = ApiResultExt.errorRetrun(VoucherType, errormsg, error, resultExt);
return CustomApiResult.success(resultExt);
}
/*if (StringUtils.equals("B",delivernotice.getString("closestatus"))) {
errormsg = "编号:" + billno + "的单据已关闭,无法重复关闭";
resultExt = ApiResultExt.errorRetrun(VoucherType, errormsg, error, resultExt);
return CustomApiResult.success(resultExt);
}*/
//开始关闭
String message = cloneOperation(delivernotice, "发货通知单", "sm_salorder");
if (message.length() > 0) {
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, message, SM_DELIVERNOTICE);
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
failCount = 1;
successCount = 0;
}
/*OperateOption operateOption = OperateOption.create();
OperationResult closeResult = OperationServiceHelper.executeOperate(Constants.TYPE_CLOSE, SM_DELIVERNOTICE, new DynamicObject[]{delivernotice}, operateOption);
if (!closeResult.isSuccess()) {
List<IOperateInfo> allErrorOrValidateInfo = closeResult.getAllErrorOrValidateInfo();
if (allErrorOrValidateInfo.size() != 0) {
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
HashMap<String, Object> returnMap = resultExt.addErrorToResultBeanByNumber(results, iOperateInfo, SM_DELIVERNOTICE);
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
}
} else if (StringUtils.isNotBlank(closeResult.getMessage())) {
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, closeResult.getMessage(), SM_DELIVERNOTICE);
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
} else {
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, closeResult.getInteractionContext().getSimpleMessage(), SM_DELIVERNOTICE);
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(VoucherType, errormsg, error, resultExt);
return CustomApiResult.success(resultExt);
}
resultBean.setId(pm_purrefundapplybill.getString("id"));
resultBean.setBillStatus(true);
if (!StringUtils.equals("C", pm_purrefundapplybill.getString("billstatus"))) {
errormsg = "编号:" + billno + "的单据状态非审核,无法关闭";
resultExt = ApiResultExt.errorRetrun(VoucherType, errormsg, error, resultExt);
return CustomApiResult.success(resultExt);
}
/*if (StringUtils.equals("B",sm_returnapply.getString("closestatus"))) {
errormsg = "编号:" + billno + "的单据已关闭,无法重复关闭";
resultExt = ApiResultExt.errorRetrun(VoucherType, errormsg, error, resultExt);
return CustomApiResult.success(resultExt);
}*/
//开始关闭
String message = cloneOperation(pm_purrefundapplybill, "采购退货申请", "pm_purorderbill");
if (message.length() > 0) {
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, message, PM_PURREFUNDAPPLYBILL);
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
failCount = 1;
successCount = 0;
}
/*OperateOption operateOption = OperateOption.create();
OperationResult closeResult = OperationServiceHelper.executeOperate(Constants.TYPE_CLOSE, SM_RETURNAPPLY, new DynamicObject[]{sm_returnapply}, operateOption);
if (!closeResult.isSuccess()) {
List<IOperateInfo> allErrorOrValidateInfo = closeResult.getAllErrorOrValidateInfo();
if (allErrorOrValidateInfo.size() != 0) {
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
HashMap<String, Object> returnMap = resultExt.addErrorToResultBeanByNumber(results, iOperateInfo, SM_RETURNAPPLY);
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
}
} else if (StringUtils.isNotBlank(closeResult.getMessage())) {
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, closeResult.getMessage(), SM_RETURNAPPLY);
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
} else {
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, closeResult.getInteractionContext().getSimpleMessage(), SM_RETURNAPPLY);
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(VoucherType, errormsg, error, resultExt);
return CustomApiResult.success(resultExt);
}
resultBean.setId(tqq9_otheroutapply.getString("id"));
resultBean.setBillStatus(true);
if (!StringUtils.equals("C", tqq9_otheroutapply.getString("billstatus"))) {
errormsg = "编号:" + billno + "的单据状态非审核,无法关闭";
resultExt = ApiResultExt.errorRetrun(VoucherType, errormsg, error, resultExt);
return CustomApiResult.success(resultExt);
}
/*if (tqq9_otheroutapply.getBoolean("tqq9_isclose")) {
errormsg = "编号:" + billno + "的单据已关闭,无法重复关闭";
resultExt = ApiResultExt.errorRetrun(VoucherType, errormsg, error, resultExt);
return CustomApiResult.success(resultExt);
}*/
//开始关闭
String message = cloneOperation(tqq9_otheroutapply, "其他出库申请单", "pm_purrefundapplybill");
if (message.length() > 0) {
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, message, TQQ9_OTHEROUTAPPLY);
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
failCount = 1;
successCount = 0;
}
// tqq9_otheroutapply.set("tqq9_isclose",true);
// SaveServiceHelper.save(new DynamicObject[]{tqq9_otheroutapply});
}
//回传成功
// int failCount = 0;//失败数量
// int successCount = 1;//成功数量
resultExt.setFailCount(failCount);
resultExt.setSuccessCount(successCount);
resultExt.setResult(results);
return CustomApiResult.success(resultExt);
}
@ApiPostMapping(value = "/WMSSaleOutClose_SH", desc = "WMS-出库关闭")
public CustomApiResult<WMSXmlReturn> WMSSaleOutClose_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");
String billno = request.getString("orderCode");
String orderType = request.getString("orderType");
orderType = billTypeMap.get(orderType);
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(SM_DELIVERNOTICE);
entryOrderTypes.add(PM_PURREFUNDAPPLYBILL);
entryOrderTypes.add(TQQ9_OTHEROUTAPPLY);
if (!entryOrderTypes.contains(orderType)) {
errormsg = errormsg.append("").append("传入参数 orderType 为无效值");
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}
//必填项校验
if (ApiResultExt.validateRequired(orderType, "String")) {
errormsg = errormsg.append("").append("传入参数 orderType 为空");
}
if (ApiResultExt.validateRequired(billno, "String")) {
errormsg = errormsg.append("").append("传入参数 deliveryOrderCode 为空");
}
//发货通知单
if (StringUtils.equals("sm_delivernotice", orderType)) {
//查询单据在金蝶系统中是否存在
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);
}
if (!StringUtils.equals("C", sm_delivernotice.getString("billstatus"))) {
errormsg = errormsg.append("").append("编号:" + billno + "的单据状态非审核,无法关闭");
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}
/* if (sm_delivernotice.getBoolean("closestatus")) {
errormsg = errormsg.append("").append("编号:" + billno + "的单据已关闭,无法重复关闭");
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}*/
//开始关闭
String message = cloneOperation(sm_delivernotice, "发货通知单", "sm_salorder");
if (message.length() > 0) {
errormsg.append(message);
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}
/*OperateOption operateOption = OperateOption.create();
OperationResult closeResult = OperationServiceHelper.executeOperate(Constants.TYPE_CLOSE, SM_RETURNAPPLY, new DynamicObject[]{sm_delivernotice}, operateOption);
if (!closeResult.isSuccess()) {
List<IOperateInfo> allErrorOrValidateInfo = closeResult.getAllErrorOrValidateInfo();
if (allErrorOrValidateInfo.size() != 0) {
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
String billMessage = iOperateInfo.getMessage();
errormsg = errormsg.append("").append(billMessage);
}
} else if (StringUtils.isNotBlank(closeResult.getMessage())) {
errormsg = errormsg.append("").append(closeResult.getMessage());
} else {
errormsg = errormsg.append("").append(closeResult.getInteractionContext().getSimpleMessage());
}
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}*/
//采购退货申请
} else if (StringUtils.equals("pm_purrefundapplybill", orderType)) {
//查询单据在金蝶系统中是否存在
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);
}
if (!StringUtils.equals("C", pm_purrefundapplybill.getString("billstatus"))) {
errormsg = errormsg.append("").append("编号:" + billno + "的单据状态非审核,无法关闭");
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}
/*if (sm_returnapply.getBoolean("closestatus")) {
errormsg = errormsg.append("").append("编号:" + billno + "的单据已关闭,无法重复关闭");
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}*/
//开始关闭
String message = cloneOperation(pm_purrefundapplybill, "采购退货申请", "pm_purorderbill");
if (message.length() > 0) {
errormsg.append(message);
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}
/*OperateOption operateOption = OperateOption.create();
OperationResult closeResult = OperationServiceHelper.executeOperate(Constants.TYPE_CLOSE, SM_RETURNAPPLY, new DynamicObject[]{sm_returnapply}, operateOption);
if (!closeResult.isSuccess()) {
List<IOperateInfo> allErrorOrValidateInfo = closeResult.getAllErrorOrValidateInfo();
if (allErrorOrValidateInfo.size() != 0) {
for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
String billMessage = iOperateInfo.getMessage();
errormsg = errormsg.append("").append(billMessage);
}
} else if (StringUtils.isNotBlank(closeResult.getMessage())) {
errormsg = errormsg.append("").append(closeResult.getMessage());
} else {
errormsg = errormsg.append("").append(closeResult.getInteractionContext().getSimpleMessage());
}
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}*/
//其他出库申请
} else if (StringUtils.equals("tqq9_otheroutapply", orderType)) {
//查询单据在金蝶系统中是否存在
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);
}
if (!StringUtils.equals("C", tqq9_otheroutapply.getString("billstatus"))) {
errormsg = errormsg.append("").append("编号:" + billno + "的单据状态非审核,无法关闭");
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}
/*if (tqq9_otheroutapply.getBoolean("tqq9_isclose")) {
errormsg = errormsg.append("").append("编号:" + billno + "的单据已关闭,无法重复关闭");
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}*/
//开始关闭
String message = cloneOperation(tqq9_otheroutapply, "其他出库申请单", "pm_purrefundapplybill");
if (message.length() > 0) {
errormsg.append(message);
response.setMessage(errormsg.substring(1));
response.setCode("-1");
response.setFlag("failure");
return CustomApiResult.success(wmsXmlReturn);
}
// tqq9_otheroutapply.set("tqq9_isclose",true);
// SaveServiceHelper.save(new DynamicObject[]{tqq9_otheroutapply});
}
//回传成功
return CustomApiResult.success(wmsXmlReturn);
}
}