2025-09-25 07:56:49 +00:00
|
|
|
package tqq9.lc123.cloud.app.api.controller;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.drew.lang.annotations.NotNull;
|
|
|
|
|
import kd.bos.dataentity.OperateOption;
|
|
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
|
import kd.bos.dataentity.utils.StringUtils;
|
|
|
|
|
import kd.bos.entity.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.operation.OperationServiceHelper;
|
|
|
|
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
@ApiController(value = "WMSPurInCloseController", desc = "WMS-入库关闭")
|
|
|
|
|
public class WMSPurInCloseController {
|
|
|
|
|
private static String RECEIPTNOTICE = "pm_receiptnotice";//收货通知单
|
|
|
|
|
private static String PM_PURREFUNDAPPLYBILL = "pm_purrefundapplybill";//采购退货申请单
|
|
|
|
|
private static String TQQ9_OTHERINAPPLY = "tqq9_otherinapply";//其他入库申请
|
|
|
|
|
|
|
|
|
|
@ApiPostMapping(value = "/WMSPurInClose", desc = "WMS-入库关闭")
|
|
|
|
|
public CustomApiResult<ApiResultExt> WMSPurInClose
|
2025-09-26 09:42:35 +00:00
|
|
|
(
|
|
|
|
|
@NotNull @ApiParam(value = "来源单据号", required = true) String cVouCode,
|
|
|
|
|
@NotNull @ApiParam(value = "单据类型", required = true) String VoucherType,
|
|
|
|
|
@NotNull @ApiParam(value = "归属", required = true) String BelongTo
|
|
|
|
|
) {
|
2025-09-25 07:56:49 +00:00
|
|
|
//返回值初始化
|
|
|
|
|
ApiResultExt resultExt = new ApiResultExt();
|
|
|
|
|
List<ApiResultExt.ResultBean> results = new ArrayList<>();
|
|
|
|
|
resultExt.setResult(results);
|
2025-09-26 09:42:35 +00:00
|
|
|
// Gson gson = new Gson();
|
|
|
|
|
// HashMap<String, Object> data = gson.fromJson(dataString, HashMap.class);
|
|
|
|
|
// String VoucherType = (String) data.get("VoucherType");//单据类型
|
|
|
|
|
String billno = cVouCode;//单据编号
|
2025-09-25 07:56:49 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//必填项校验
|
|
|
|
|
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(RECEIPTNOTICE);
|
|
|
|
|
VoucherTypes.add(PM_PURREFUNDAPPLYBILL);
|
|
|
|
|
VoucherTypes.add(TQQ9_OTHERINAPPLY);
|
|
|
|
|
if(!VoucherTypes.contains(VoucherType)){
|
|
|
|
|
errormsg = "传入参数 VoucherType 为无效值";
|
|
|
|
|
resultExt = ApiResultExt.errorRetrun(VoucherType, errormsg, error, resultExt);
|
|
|
|
|
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(VoucherType, errormsg, error, resultExt);
|
|
|
|
|
return CustomApiResult.success(resultExt);
|
|
|
|
|
}
|
|
|
|
|
resultBean.setId(receiptnotice.getString("id"));
|
|
|
|
|
resultBean.setBillStatus(true);
|
|
|
|
|
if (StringUtils.equals("B",receiptnotice.getString("closestatus"))) {
|
|
|
|
|
errormsg = "编号:" + billno + "的单据已关闭,无法重复关闭";
|
|
|
|
|
resultExt = ApiResultExt.errorRetrun(VoucherType, errormsg, error, resultExt);
|
|
|
|
|
return CustomApiResult.success(resultExt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//开始关闭
|
|
|
|
|
OperateOption operateOption = OperateOption.create();
|
|
|
|
|
OperationResult closeResult = OperationServiceHelper.executeOperate(Constants.TYPE_CLOSE, RECEIPTNOTICE, new DynamicObject[]{receiptnotice}, 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, RECEIPTNOTICE);
|
|
|
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
|
|
|
}
|
|
|
|
|
} else if (StringUtils.isNotBlank(closeResult.getMessage())) {
|
|
|
|
|
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, closeResult.getMessage(), RECEIPTNOTICE);
|
|
|
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
|
|
|
} else {
|
|
|
|
|
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, closeResult.getInteractionContext().getSimpleMessage(), RECEIPTNOTICE);
|
|
|
|
|
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",pm_purrefundapplybill.getString("closestatus"))) {
|
|
|
|
|
errormsg = "编号:" + billno + "的单据已关闭,无法重复关闭";
|
|
|
|
|
resultExt = ApiResultExt.errorRetrun(VoucherType, errormsg, error, resultExt);
|
|
|
|
|
return CustomApiResult.success(resultExt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//开始关闭
|
|
|
|
|
OperateOption operateOption = OperateOption.create();
|
|
|
|
|
OperationResult closeResult = OperationServiceHelper.executeOperate(Constants.TYPE_CLOSE, PM_PURREFUNDAPPLYBILL, new DynamicObject[]{pm_purrefundapplybill}, 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, PM_PURREFUNDAPPLYBILL);
|
|
|
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
|
|
|
}
|
|
|
|
|
} else if (StringUtils.isNotBlank(closeResult.getMessage())) {
|
|
|
|
|
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, closeResult.getMessage(), PM_PURREFUNDAPPLYBILL);
|
|
|
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
|
|
|
} else {
|
|
|
|
|
HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, closeResult.getInteractionContext().getSimpleMessage(), PM_PURREFUNDAPPLYBILL);
|
|
|
|
|
results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//其他入库申请单
|
|
|
|
|
} 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(VoucherType, errormsg, error, resultExt);
|
|
|
|
|
return CustomApiResult.success(resultExt);
|
|
|
|
|
}
|
|
|
|
|
resultBean.setId(tqq9_otherinapply.getString("id"));
|
|
|
|
|
resultBean.setBillStatus(true);
|
|
|
|
|
if (!StringUtils.equals("C",tqq9_otherinapply.getString("billstatus"))) {
|
|
|
|
|
errormsg = "编号:" + billno + "的单据状态非审核,无法关闭";
|
|
|
|
|
resultExt = ApiResultExt.errorRetrun(VoucherType, errormsg, error, resultExt);
|
|
|
|
|
return CustomApiResult.success(resultExt);
|
|
|
|
|
}
|
|
|
|
|
if (tqq9_otherinapply.getBoolean("tqq9_isclose")) {
|
|
|
|
|
errormsg = "编号:" + billno + "的单据已关闭,无法重复关闭";
|
|
|
|
|
resultExt = ApiResultExt.errorRetrun(VoucherType, errormsg, error, resultExt);
|
|
|
|
|
return CustomApiResult.success(resultExt);
|
|
|
|
|
}
|
|
|
|
|
tqq9_otherinapply.set("tqq9_isclose",true);
|
|
|
|
|
SaveServiceHelper.save(new DynamicObject[]{tqq9_otherinapply});
|
|
|
|
|
|
|
|
|
|
// //开始提交
|
|
|
|
|
// OperateOption operateOption = OperateOption.create();
|
|
|
|
|
// OperationResult closeResult = OperationServiceHelper.executeOperate(Constants.TYPE_CLOSE, TQQ9_OTHERINAPPLY, new DynamicObject[]{tqq9_otherinapply}, 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, TQQ9_OTHERINAPPLY);
|
|
|
|
|
// results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
|
|
|
// }
|
|
|
|
|
// } else if (StringUtils.isNotBlank(closeResult.getMessage())) {
|
|
|
|
|
// HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, closeResult.getMessage(), TQQ9_OTHERINAPPLY);
|
|
|
|
|
// results = (List<ApiResultExt.ResultBean>) returnMap.get("ResultBeanList");
|
|
|
|
|
// } else {
|
|
|
|
|
// HashMap<String, Object> returnMap = resultExt.addOneErrorToResultBeanByNumber(results, closeResult.getInteractionContext().getSimpleMessage(), TQQ9_OTHERINAPPLY);
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
}
|