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 = "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";//其他出库申请 @ApiPostMapping(value = "/WMSSaleOutClose", desc = "WMS-出库关闭") public CustomApiResult 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 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 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 VoucherTypes = new ArrayList<>(); VoucherTypes.add(SM_DELIVERNOTICE); VoucherTypes.add(SM_RETURNAPPLY); 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); } //开始关闭 OperateOption operateOption = OperateOption.create(); OperationResult closeResult = OperationServiceHelper.executeOperate(Constants.TYPE_CLOSE, SM_DELIVERNOTICE, new DynamicObject[]{delivernotice}, operateOption); if (!closeResult.isSuccess()) { List allErrorOrValidateInfo = closeResult.getAllErrorOrValidateInfo(); if (allErrorOrValidateInfo.size() != 0) { for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) { HashMap returnMap = resultExt.addErrorToResultBeanByNumber(results, iOperateInfo, SM_DELIVERNOTICE); results = (List) returnMap.get("ResultBeanList"); } } else if (StringUtils.isNotBlank(closeResult.getMessage())) { HashMap returnMap = resultExt.addOneErrorToResultBeanByNumber(results, closeResult.getMessage(), SM_DELIVERNOTICE); results = (List) returnMap.get("ResultBeanList"); } else { HashMap returnMap = resultExt.addOneErrorToResultBeanByNumber(results, closeResult.getInteractionContext().getSimpleMessage(), SM_DELIVERNOTICE); results = (List) returnMap.get("ResultBeanList"); } } //销售退货单 } else if (StringUtils.equals("sm_returnapply", VoucherType)) { //查询单据在金蝶系统中是否存在 DynamicObject sm_returnapply = BusinessDataServiceHelper.loadSingle(SM_RETURNAPPLY, new QFilter[]{new QFilter("billno", QCP.equals, billno)}); if (sm_returnapply == null) { errormsg = "根据传入编号:" + billno + "未找到对应销售退货单"; resultExt = ApiResultExt.errorRetrun(VoucherType, errormsg, error, resultExt); return CustomApiResult.success(resultExt); } resultBean.setId(sm_returnapply.getString("id")); resultBean.setBillStatus(true); if (!StringUtils.equals("C",sm_returnapply.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); } //开始关闭 OperateOption operateOption = OperateOption.create(); OperationResult closeResult = OperationServiceHelper.executeOperate(Constants.TYPE_CLOSE, SM_RETURNAPPLY, new DynamicObject[]{sm_returnapply}, operateOption); if (!closeResult.isSuccess()) { List allErrorOrValidateInfo = closeResult.getAllErrorOrValidateInfo(); if (allErrorOrValidateInfo.size() != 0) { for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) { HashMap returnMap = resultExt.addErrorToResultBeanByNumber(results, iOperateInfo, SM_RETURNAPPLY); results = (List) returnMap.get("ResultBeanList"); } } else if (StringUtils.isNotBlank(closeResult.getMessage())) { HashMap returnMap = resultExt.addOneErrorToResultBeanByNumber(results, closeResult.getMessage(), SM_RETURNAPPLY); results = (List) returnMap.get("ResultBeanList"); } else { HashMap returnMap = resultExt.addOneErrorToResultBeanByNumber(results, closeResult.getInteractionContext().getSimpleMessage(), SM_RETURNAPPLY); results = (List) 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); } //开始关闭 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); } }