From 6375237773dc1cf25cf32a6b3be4fd69887922a6 Mon Sep 17 00:00:00 2001 From: "tanfengling@x-ri.com" <123456> Date: Thu, 25 Sep 2025 18:10:16 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=B7=A5=E5=85=B7=E7=B1=BB=E3=80=91?= =?UTF-8?q?=E5=9F=BA=E7=A1=80=E6=95=B0=E6=8D=AE=E6=98=A0=E5=B0=84=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=20=E3=80=90=E6=8E=A5=E5=8F=A3=E3=80=91=E5=BD=A2?= =?UTF-8?q?=E6=80=81=E8=BD=AC=E6=8D=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WMSAdjustBillController.java | 326 ++++++++++++++++++ .../app/plugin/utils/BaseDataMatchUtils.java | 83 +++++ 2 files changed, 409 insertions(+) create mode 100644 lc123/cloud/app/api/controller/WMSAdjustBillController.java create mode 100644 lc123/cloud/app/plugin/utils/BaseDataMatchUtils.java diff --git a/lc123/cloud/app/api/controller/WMSAdjustBillController.java b/lc123/cloud/app/api/controller/WMSAdjustBillController.java new file mode 100644 index 0000000..da5d494 --- /dev/null +++ b/lc123/cloud/app/api/controller/WMSAdjustBillController.java @@ -0,0 +1,326 @@ +package tqq9.lc123.cloud.app.api.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +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.entity.DynamicObjectCollection; +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.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import kd.bos.servicehelper.operation.OperationServiceHelper; +import kd.bos.util.StringUtils; +import tqq9.lc123.cloud.app.api.utils.ApiResultExt; +import tqq9.lc123.cloud.app.api.utils.Constants; +import tqq9.lc123.cloud.app.plugin.utils.BaseDataMatchUtils; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; + +/** + * WMS形态转换单接口--库存异动 + */ +@ApiController(value = "WMSAdjustBillController", desc = "WMS-形态转换单接口bg") +public class WMSAdjustBillController { + + @ApiPostMapping(value = "/WMSAdjustBill", desc = "WMS库存异动api") + public CustomApiResult wmsAdjustBill + (@NotNull @ApiParam(value = "入参", example = "") String data) { + ApiResultExt resultExt = new ApiResultExt(); + List results = new ArrayList<>(); + ApiResultExt.ResultBean resultBean = new ApiResultExt.ResultBean(); + ApiResultExt.Error error = new ApiResultExt.Error(); + ArrayList rowMsg = new ArrayList<>(); + JSONObject keys = new JSONObject(); + boolean billStatus = true; + + JSONObject obj = JSON.parseObject(data); + String cPACode = obj.getString("cPACode");//调整单号 + String cWhCode = obj.getString("cWhCode");//仓库编码 + String BelongTo = obj.getString("BelongTo");//归属组织 + + if(StringUtils.isBlank(cPACode)){ + rowMsg.add("入参调整单号字段cPACode为空"); + billStatus = false; + }else { + keys.put("cPACode", cPACode); + } + //仓库 + DynamicObject warehouse = null; + if(StringUtils.isBlank(cWhCode)){ + rowMsg.add("入参仓库编码字段cWhCode为空"); + billStatus = false; + }else{ + QFilter f = new QFilter("number", "=", cWhCode); + DynamicObject[] whArr = BusinessDataServiceHelper.load("bos_warehouse", "id,name,number", new QFilter[]{f}); + if(whArr == null || whArr.length == 0){ + rowMsg.add("根据仓库编码字段cWhCode【"+cWhCode+"】在金蝶系统中没有查询到对应的仓库信息"); + billStatus = false; + }else { + warehouse = whArr[0]; + } + } + + //库存组织 + DynamicObject org = null; + if(StringUtils.isBlank(BelongTo)){ + rowMsg.add("入参归属字段BelongTo为空"); + billStatus = false; + }else{ + QFilter f = new QFilter("number", "=", BelongTo); + DynamicObject[] orgArr = BusinessDataServiceHelper.load("bos_org", "id,name,number", new QFilter[]{f}); + if(orgArr == null || orgArr.length == 0){ + rowMsg.add("根据归属字段BelongTo【"+BelongTo+"】在金蝶系统中没有查询到对应的组织信息"); + billStatus = false; + }else { + org = orgArr[0]; + } + } + + JSONArray Details = obj.getJSONArray("Details"); + if(Details != null && Details.size() > 0){ + for (int i = 0; i < Details.size(); i++) { + JSONObject detail = Details.getJSONObject(i); + String cInvCode = detail.getString("cInvCode");//产品编码 + String cOBatch = detail.getString("cOBatch");//挑战前批次 + String cIBatch = detail.getString("cIBatch");//调整后批次 + Integer iPAQuantity = detail.getInteger("iPAQuantity");//数量 + + if(StringUtils.isBlank(cInvCode)){ + rowMsg.add("入参产品编码字段cInvCode为空"); + billStatus = false; + } else { + QFilter f = new QFilter("number", "=", cInvCode); + DynamicObject[] materialArr = BusinessDataServiceHelper.load("bd_material", "id,number,name", new QFilter[]{f}); + if(materialArr == null || materialArr.length == 0){ + rowMsg.add("根据产品编码字段cInvCode【"+cInvCode+"】在金蝶系统中没有查询到对应的物料信息"); + billStatus = false; + } + } + if(StringUtils.isBlank(cOBatch)){ + rowMsg.add("入参挑战前批次字段cOBatch为空"); + billStatus = false; + }else { + QFilter f = new QFilter("number", "=", cOBatch); + DynamicObject[] lotArr = BusinessDataServiceHelper.load("bd_lot", "id,number,name", new QFilter[]{f}); + if(lotArr == null || lotArr.length == 0){ + rowMsg.add("根据挑战前批次字段cOBatch【"+cOBatch+"】在金蝶系统中没有查询到对应的批次信息"); + billStatus = false; + } + + } + if(StringUtils.isBlank(cIBatch)){ + rowMsg.add("入参调整后批次字段cIBatch为空"); + billStatus = false; + }else { + QFilter f = new QFilter("number", "=", cIBatch); + DynamicObject[] lotArr = BusinessDataServiceHelper.load("bd_lot", "id,number,name", new QFilter[]{f}); + if(lotArr == null || lotArr.length == 0){ + rowMsg.add("根据调整后批次字段cIBatch【"+cIBatch+"】在金蝶系统中没有查询到对应的批次信息"); + billStatus = false; + } + } + if(iPAQuantity == null || iPAQuantity == 0){ + rowMsg.add("入参数量字段iPAQuantity为空或为零"); + billStatus = false; + } + } + }else{ + rowMsg.add("入参明细字段Details为空"); + billStatus = false; + } + + resultBean.setBillIndex(0); + resultBean.setKeys(keys); + resultBean.setNumber(cPACode); + if(billStatus){ + //出现错误后返回 + error.setKeys(keys); + error.setRowMsg(rowMsg); + error.setEntityKey("im_adjustbill"); + resultBean.setId(""); + resultBean.setBillStatus(billStatus); + resultBean.setErrors(error); + results.add(resultBean); + resultExt.setFailCount(0); + resultExt.setSuccessCount(1); + }else{ + //常量准备-查询单据类型 + QFilter f = new QFilter("number", "=", "im_Adjustbill_STD_BT_S"); + DynamicObject[] billtypeArr = BusinessDataServiceHelper.load("bos_billtype", "id,name,number", new QFilter[]{f}); + DynamicObject billtype = billtypeArr[0]; + //业务类型 + f = new QFilter("number", "=", "511"); + DynamicObject[] biztypeArr = BusinessDataServiceHelper.load("bd_biztype", "id,name,number", new QFilter[]{f}); + DynamicObject biztype = biztypeArr[0]; + //出库库存类型 + f = new QFilter("number", "=", "110"); + DynamicObject[] invtypeArr = BusinessDataServiceHelper.load("bd_invtype", "id,number,name", new QFilter[]{f}); + DynamicObject invtype = invtypeArr[0]; + //出库库存状态 + f = new QFilter("number", "=", "110"); + DynamicObject[] invstatusArr = BusinessDataServiceHelper.load("bd_invstatus", "id,number,name", new QFilter[]{f}); + DynamicObject invstatus = invstatusArr[0]; + + //必填校验通过,构建并保存数据 + DynamicObject adjustbill = BusinessDataServiceHelper.newDynamicObject("im_adjustbill"); + adjustbill.set("billno", cPACode); + adjustbill.set("biztime", new Date()); + adjustbill.set("org", org); + adjustbill.set("billtype", billtype); + adjustbill.set("biztype", biztype); + adjustbill.set("billstatus", "A"); + adjustbill.set("billcretype", "1"); + DynamicObjectCollection beforeEntries = adjustbill.getDynamicObjectCollection("billentry");//调整前明细 + for (int i = 0; i < Details.size(); i++) { + JSONObject detail = Details.getJSONObject(i); + String cInvCode = detail.getString("cInvCode");//产品编码 + String cOBatch = detail.getString("cOBatch");//挑战前批次 + Date dOMDate = detail.getDate("dOMDate");//挑战前生产日期 + Date dOVDate = detail.getDate("dOVDate");//挑战前有效期至 + String cIBatch = detail.getString("cIBatch");//调整后批次 + Date dIMDate = detail.getDate("dIMDate");//调整入生产日期 + Date dIVDate = detail.getDate("dIVDate");//调整入有效期至 + Integer iPAQuantity = detail.getInteger("iPAQuantity");//数量 + + //物料 + f = new QFilter("number", "=", cInvCode); + DynamicObject[] materialArr = BusinessDataServiceHelper.load("bd_material", "id,number,name,baseunit", new QFilter[]{f}); + DynamicObject material = materialArr[0]; + //物料库存信息 + f = new QFilter("masterid.id", "=", material.getPkValue()); + DynamicObject[] materialinvArr = BusinessDataServiceHelper.load("bd_materialinventoryinfo", "id,number,name,baseunit", new QFilter[]{f}); + DynamicObject materialinv = materialinvArr[0]; + //调整前商品 + DynamicObject oGoods = null; + DynamicObject[] oGoodsArr = BaseDataMatchUtils.materialMatchGoods("cInvCode", cOBatch, true); + if(oGoodsArr != null && oGoodsArr.length > 0){ + oGoods = oGoodsArr[0]; + } + //调整后商品 + DynamicObject iGoods = null; + DynamicObject[] iGoodsArr = BaseDataMatchUtils.materialMatchGoods("cInvCode", cIBatch, true); + if(iGoodsArr != null && iGoodsArr.length > 0){ + iGoods = iGoodsArr[0]; + } + //调整前批号 + f = new QFilter("number", "=", cOBatch); + DynamicObject[] olotArr = BusinessDataServiceHelper.load("bd_lot", "id,number,name", new QFilter[]{f}); + DynamicObject olot = olotArr[0]; + //调整后批次 + f = new QFilter("number", "=", cIBatch); + DynamicObject[] ilotArr = BusinessDataServiceHelper.load("bd_lot", "id,number,name", new QFilter[]{f}); + DynamicObject ilot = ilotArr[0]; + + //调整前明细 + DynamicObject beforeEntry = beforeEntries.addNew(); + beforeEntry.set("materialmasterid", material); + beforeEntry.set("material", materialinv); + beforeEntry.set("tqq9_goods", oGoods); + beforeEntry.set("unit", material.getDynamicObject("baseunit")); + beforeEntry.set("qty", iPAQuantity); + beforeEntry.set("baseunit", material.getDynamicObject("baseunit")); + beforeEntry.set("baseqty", iPAQuantity); + beforeEntry.set("lot", olot); + beforeEntry.set("lotnumber", cOBatch); + beforeEntry.set("producedate", dOMDate); + beforeEntry.set("expirydate", dOVDate); + beforeEntry.set("warehouse", warehouse); + beforeEntry.set("invtype", invtype); + beforeEntry.set("invstatus", invstatus); + beforeEntry.set("ownertype", "bos_org"); + beforeEntry.set("owner", org); + beforeEntry.set("keepertype", "bos_org"); + beforeEntry.set("keeper", org); + DynamicObjectCollection afterEntries = beforeEntry.getDynamicObjectCollection("afterentity"); + //调整后明细 + DynamicObject afterEntry = afterEntries.addNew(); + afterEntry.set("materialmasterid1", material); + afterEntry.set("material1", materialinv); + beforeEntry.set("tqq9_goods1", iGoods); + afterEntry.set("unit1", material.getDynamicObject("baseunit")); + afterEntry.set("qty1", iPAQuantity); + afterEntry.set("baseunit1", material.getDynamicObject("baseunit")); + afterEntry.set("baseqty1", iPAQuantity); + afterEntry.set("lot1", ilot); + afterEntry.set("lotnumber1", cIBatch); + afterEntry.set("producedate1", dIMDate); + afterEntry.set("expirydate1", dIVDate); + afterEntry.set("warehouse1", warehouse); + afterEntry.set("invtype1", invtype); + afterEntry.set("invstatus1", invstatus); + afterEntry.set("ownertype1", "bos_org"); + afterEntry.set("owner1", org); + afterEntry.set("keepertype1", "bos_org"); + afterEntry.set("keeper1", org); + } + OperationResult operationResult = OperationServiceHelper.executeOperate("save", "im_adjustbill", new DynamicObject[]{adjustbill}, OperateOption.create()); + if(!operationResult.isSuccess()){ + List allErrorOrValidateInfo = operationResult.getAllErrorOrValidateInfo(); + for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) { + rowMsg.add(iOperateInfo.getMessage()); + } + error.setKeys(keys); + error.setRowMsg(rowMsg); + error.setEntityKey("im_adjustbill"); + resultBean.setId(""); + resultBean.setBillStatus(false); + resultBean.setErrors(error); + results.add(resultBean); + resultExt.setFailCount(0); + resultExt.setSuccessCount(1); + }else { + operationResult = OperationServiceHelper.executeOperate("submit", "im_adjustbill", new DynamicObject[]{adjustbill}, OperateOption.create()); + if(!operationResult.isSuccess()){ + List allErrorOrValidateInfo = operationResult.getAllErrorOrValidateInfo(); + for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) { + rowMsg.add(iOperateInfo.getMessage()); + } + error.setKeys(keys); + error.setRowMsg(rowMsg); + error.setEntityKey("im_adjustbill"); + resultBean.setId(""); + resultBean.setBillStatus(false); + resultBean.setErrors(error); + results.add(resultBean); + resultExt.setFailCount(0); + resultExt.setSuccessCount(1); + }else { + operationResult = OperationServiceHelper.executeOperate("audit", "im_adjustbill", new DynamicObject[]{adjustbill}, OperateOption.create()); + if(!operationResult.isSuccess()){ + List allErrorOrValidateInfo = operationResult.getAllErrorOrValidateInfo(); + for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) { + rowMsg.add(iOperateInfo.getMessage()); + } + error.setKeys(keys); + error.setRowMsg(rowMsg); + error.setEntityKey("im_adjustbill"); + resultBean.setId(""); + resultBean.setBillStatus(false); + resultBean.setErrors(error); + results.add(resultBean); + resultExt.setFailCount(0); + resultExt.setSuccessCount(1); + }else { + resultBean.setId(adjustbill.getString("id")); + resultBean.setBillStatus(true); + results.add(resultBean); + resultExt.setFailCount(1); + resultExt.setSuccessCount(0); + } + } + } + } + resultExt.setResult(results); + return CustomApiResult.success(resultExt); + } +} diff --git a/lc123/cloud/app/plugin/utils/BaseDataMatchUtils.java b/lc123/cloud/app/plugin/utils/BaseDataMatchUtils.java new file mode 100644 index 0000000..19a6297 --- /dev/null +++ b/lc123/cloud/app/plugin/utils/BaseDataMatchUtils.java @@ -0,0 +1,83 @@ +package tqq9.lc123.cloud.app.plugin.utils; + +import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; +import org.apache.poi.util.ArrayUtil; +import scala.Dynamic; + +import java.util.ArrayList; +import java.util.List; + +/** + * 基础数据匹配查询 + */ +public class BaseDataMatchUtils { + + /** + * 根据商品编码查询物料信息 + * @param goodsNumber 商品编码 + * @return + */ + public static DynamicObject goodsMatchMaterial(String goodsNumber){ + QFilter f = new QFilter("number", "=", goodsNumber); + DynamicObject[] goodsArr = BusinessDataServiceHelper.load("tqq9_goodspackage", "id,number,name,tqq9_mater", new QFilter[]{f}); + if(goodsArr != null && goodsArr.length > 0){ + return goodsArr[0].getDynamicObject("tqq9_mater"); + } + return null; + } + + + /** + * 根据物料编码查找对应商品 + * @param materialNumber 物料编码 + * @param lotNumber 批号 + * @param isauto 是否自动封装的商品 + * @return + */ + public static DynamicObject[] materialMatchGoods(String materialNumber, String lotNumber, boolean isauto){ + QFilter f1 = new QFilter("tqq9_mater.number", "=", materialNumber); + QFilter f2 = new QFilter("tqq9_entry.tqq9_lot.number", "=", lotNumber); + QFilter f3 = new QFilter("isauto", "=", isauto); + DynamicObject[] goodsA = BusinessDataServiceHelper.load("tqq9_goodspackage", + "id,number,name,tqq9_mater.baseunit,tqq9_mater.modelnum,tqq9_isauto", + new QFilter[]{f1, f2, f3}); + if(goodsA != null && goodsA.length > 0){ + List goodsList = new ArrayList<>(); + for (DynamicObject goods : goodsA) { + goodsList.add(goods); + } + // 或预先分配大小(性能更优) + DynamicObject[] goodsArr = goodsList.toArray(new DynamicObject[goodsList.size()]); + return goodsArr; + } + + return null; + } + + + /** + * 总仓匹配--外部仓库对应金蝶仓库 + * @param wmsWhNumber 外部WMS系统仓库编码 + * @return + */ + public static DynamicObject getKDWarehouse(String wmsWhNumber){ + + + return null; + } + + + /** + * 总仓匹配--金蝶仓库查找对应的外部wms仓库编码 + * @param kdWhNumber + * @return + */ + public static String getOutWarehouse(String kdWhNumber){ + + + return null; + } + +}