620 lines
		
	
	
		
			34 KiB
		
	
	
	
		
			Java
		
	
	
	
			
		
		
	
	
			620 lines
		
	
	
		
			34 KiB
		
	
	
	
		
			Java
		
	
	
	
| 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.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.BaseDataMatchUtils;
 | ||
| 
 | ||
| import java.util.*;
 | ||
| 
 | ||
| /**
 | ||
|  * WMS形态转换单接口--库存异动
 | ||
|  */
 | ||
| @ApiController(value = "WMSAdjustBillController", desc = "WMS-形态转换单接口bg")
 | ||
| public class WMSAdjustBillController {
 | ||
| 
 | ||
|     @ApiPostMapping(value = "/WMSAdjustBill", desc = "WMS库存异动api")
 | ||
|     public CustomApiResult<ApiResultExt> wmsAdjustBill
 | ||
|             (@NotNull @ApiParam(value = "调整单号", required = true) String cPACode,
 | ||
|              @NotNull @ApiParam(value = "归属", required = true) String BelongTo,
 | ||
|              @NotNull @ApiParam(value = "仓库编码", required = true) String cWhCode,
 | ||
|              @NotNull @ApiParam(value = "明细", required = true) String Details) {
 | ||
|         ApiResultExt resultExt = new ApiResultExt();
 | ||
|         List<ApiResultExt.ResultBean> results = new ArrayList<>();
 | ||
|         ApiResultExt.ResultBean resultBean = new ApiResultExt.ResultBean();
 | ||
|         ApiResultExt.Error error = new ApiResultExt.Error();
 | ||
|         ArrayList<String> rowMsg = new ArrayList<>();
 | ||
|         JSONObject keys = new JSONObject();
 | ||
|         boolean billStatus = true;
 | ||
| 
 | ||
|         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("bd_warehouse", "id,name,number", new QFilter[]{f});
 | ||
|             if(whArr == null || whArr.length == 0){
 | ||
|                 rowMsg.add("根据仓库编码字段cWhCode【"+cWhCode+"】在金蝶系统中没有查询到对应的仓库信息");
 | ||
|                 billStatus = false;
 | ||
|             }else {
 | ||
|                 warehouse = whArr[0];
 | ||
|                 warehouse = BusinessDataServiceHelper.loadSingle(warehouse.getPkValue(), "bd_warehouse");
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         //库存组织
 | ||
|         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 DetailsArr = JSON.parseArray(Details);
 | ||
|         if(DetailsArr != null && DetailsArr.size() > 0){
 | ||
|             for (int i = 0; i < DetailsArr.size(); i++) {
 | ||
|                 JSONObject detail = DetailsArr.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(1);
 | ||
|             resultExt.setSuccessCount(0);
 | ||
|         }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 = null;
 | ||
|             QFilter qFilter = new QFilter("billno", "=", cPACode);
 | ||
|             DynamicObject[] billArr = BusinessDataServiceHelper.load("im_adjustbill", "id,billno", new QFilter[]{qFilter});
 | ||
|             if(billArr != null && billArr.length > 0){
 | ||
|                 adjustbill = billArr[0];
 | ||
|                 adjustbill = BusinessDataServiceHelper.loadSingle(adjustbill.getPkValue(), "im_adjustbill");
 | ||
|                 DynamicObjectCollection beforeEntries = adjustbill.getDynamicObjectCollection("billentry");
 | ||
|                 if(beforeEntries != null && beforeEntries.size() > 0){
 | ||
|                     beforeEntries.clear();
 | ||
|                 }
 | ||
|             }else {
 | ||
|                 adjustbill = BusinessDataServiceHelper.newDynamicObject("im_adjustbill");
 | ||
|                 adjustbill.set("billno", cPACode);
 | ||
|             }
 | ||
|             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 < DetailsArr.size(); i++) {
 | ||
|                 JSONObject detail = DetailsArr.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", new QFilter[]{f});
 | ||
|                 DynamicObject materialinv = materialinvArr[0];
 | ||
|                 materialinv = BusinessDataServiceHelper.loadSingle(materialinv.getPkValue(), "bd_materialinventoryinfo");
 | ||
|                 //调整前商品
 | ||
|                 DynamicObject oGoods = null;
 | ||
|                 DynamicObject[] oGoodsArr = BaseDataMatchUtils.materialMatchGoods(cInvCode, cOBatch, dOMDate, dOVDate, true);
 | ||
|                 if(oGoodsArr != null && oGoodsArr.length > 0){
 | ||
|                     oGoods = oGoodsArr[0];
 | ||
|                 }
 | ||
|                 //调整后商品
 | ||
|                 DynamicObject iGoods = null;
 | ||
|                 DynamicObject[] iGoodsArr = BaseDataMatchUtils.materialMatchGoods(cInvCode, cIBatch, dIMDate, dIVDate, 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);
 | ||
|                 afterEntry.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<IOperateInfo> 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(1);
 | ||
|                 resultExt.setSuccessCount(0);
 | ||
|             }else {
 | ||
|                 operationResult = OperationServiceHelper.executeOperate("submit", "im_adjustbill", new DynamicObject[]{adjustbill}, OperateOption.create());
 | ||
|                 if(!operationResult.isSuccess()){
 | ||
|                     List<IOperateInfo> allErrorOrValidateInfo = operationResult.getAllErrorOrValidateInfo();
 | ||
|                     for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
 | ||
|                         rowMsg.add(iOperateInfo.getMessage());
 | ||
|                     }
 | ||
|                     error.setKeys(keys);
 | ||
|                     error.setRowMsg(rowMsg);
 | ||
|                     error.setEntityKey("im_adjustbill");
 | ||
|                     resultBean.setId(adjustbill.getString("id"));
 | ||
|                     resultBean.setBillStatus(false);
 | ||
|                     resultBean.setErrors(error);
 | ||
|                     results.add(resultBean);
 | ||
|                     resultExt.setFailCount(1);
 | ||
|                     resultExt.setSuccessCount(0);
 | ||
|                 }else {
 | ||
|                     operationResult = OperationServiceHelper.executeOperate("audit", "im_adjustbill", new DynamicObject[]{adjustbill}, OperateOption.create());
 | ||
|                     if(!operationResult.isSuccess()){
 | ||
|                         List<IOperateInfo> allErrorOrValidateInfo = operationResult.getAllErrorOrValidateInfo();
 | ||
|                         for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
 | ||
|                             rowMsg.add(iOperateInfo.getMessage());
 | ||
|                         }
 | ||
|                         error.setKeys(keys);
 | ||
|                         error.setRowMsg(rowMsg);
 | ||
|                         error.setEntityKey("im_adjustbill");
 | ||
|                         resultBean.setId(adjustbill.getString("id"));
 | ||
|                         resultBean.setBillStatus(false);
 | ||
|                         resultBean.setErrors(error);
 | ||
|                         results.add(resultBean);
 | ||
|                         resultExt.setFailCount(1);
 | ||
|                         resultExt.setSuccessCount(0);
 | ||
|                     }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);
 | ||
|     }
 | ||
| 
 | ||
| 
 | ||
|     @ApiPostMapping(value = "/WMSAdjustBill_SH", desc = "WMS上海库存异动api")
 | ||
|     public CustomApiResult<WMSXmlReturn> wmsAdjustBill_SH
 | ||
|             (@NotNull @ApiParam(value = "入参", required = true) Map<String, Object> dataMap) {
 | ||
|         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();
 | ||
| 
 | ||
|         JSONObject data = new JSONObject(dataMap);
 | ||
|         JSONObject request = data.getJSONObject("request");
 | ||
|         JSONObject items = request.getJSONObject("items");
 | ||
|         JSONArray itemArr = items.getJSONArray("item");
 | ||
|         if (itemArr != null && itemArr.size() == 2){
 | ||
|             JSONObject ckObj = null;
 | ||
|             JSONObject rkObj = null;
 | ||
|             JSONObject jsonObj0 = (JSONObject) itemArr.get(0);
 | ||
|             JSONObject jsonObj1 = (JSONObject) itemArr.get(1);
 | ||
|             //区分入库明细与出库明细
 | ||
|             String orderType0 = jsonObj0.getString("orderType");//单据类型
 | ||
|             if (ApiResultExt.validateRequired(orderType0, "String")) {
 | ||
|                 errormsg = errormsg.append(";").append("传入参数 ownerCode 为空");
 | ||
|             }else {
 | ||
|                 if ("QTRK".equals(orderType0)) {
 | ||
|                     ckObj = jsonObj0;
 | ||
|                     rkObj = jsonObj1;
 | ||
|                 } else {
 | ||
|                     ckObj = jsonObj1;
 | ||
|                     rkObj = jsonObj0;
 | ||
|                 }
 | ||
|             }
 | ||
|             String ownerCode = ckObj.getString("ownerCode");//货主编码-必填
 | ||
|             DynamicObject org = null;
 | ||
|             if (ApiResultExt.validateRequired(ownerCode, "String")) {
 | ||
|                 errormsg = errormsg.append(";").append("传入参数 ownerCode 为空");
 | ||
|             }else{
 | ||
|                 QFilter f = new QFilter("number", "=", ownerCode);
 | ||
|                 DynamicObject[] bos_orgs = BusinessDataServiceHelper.load("bos_org", "id,number,name", new QFilter[]{f});
 | ||
|                 if(bos_orgs != null && bos_orgs.length > 0){
 | ||
|                     org = bos_orgs[0];
 | ||
|                 }else{
 | ||
|                     errormsg = errormsg.append(";").append("根据传入参数 ownerCode:"+ ownerCode +" 没有查询到对应组织信息");
 | ||
|                 }
 | ||
|             }
 | ||
|             String warehouseCode = ckObj.getString("warehouseCode");//仓库编码-必填
 | ||
|             DynamicObject warehouse = null;
 | ||
|             if (ApiResultExt.validateRequired(warehouseCode, "String")) {
 | ||
|                 errormsg = errormsg.append(";").append("传入参数 warehouseCode 为空");
 | ||
|             }else{
 | ||
|                 QFilter f = new QFilter("number", "=", warehouseCode);
 | ||
|                 DynamicObject[] whArr = BusinessDataServiceHelper.load("bd_warehouse", "id,name,number", new QFilter[]{f});
 | ||
|                 if(whArr == null || whArr.length == 0){
 | ||
|                     errormsg = errormsg.append(";").append("根据传入参数 warehouseCode:"+ warehouseCode +" 没有查询到对应苍鹭信息");
 | ||
|                 }else {
 | ||
|                     warehouse = whArr[0];
 | ||
|                     warehouse = BusinessDataServiceHelper.loadSingle(warehouse.getPkValue(), "bd_warehouse");
 | ||
|                 }
 | ||
|             }
 | ||
|             String orderCode = ckObj.getString("orderCode");//异动单据编码-必填
 | ||
|             if (ApiResultExt.validateRequired(orderCode, "String")) {
 | ||
|                 errormsg = errormsg.append(";").append("传入参数 orderCode 为空");
 | ||
|             }
 | ||
| 
 | ||
|             String outBizCode = ckObj.getString("outBizCode");//外部业务编码,用于去重-必填
 | ||
|             String itemCode = ckObj.getString("itemCode");//物料编码-必填
 | ||
|             DynamicObject material = null;
 | ||
|             DynamicObject materialinv = null;
 | ||
|             if (ApiResultExt.validateRequired(itemCode, "String")) {
 | ||
|                 errormsg = errormsg.append(";").append("传入参数 itemCode 为空");
 | ||
|             }else{
 | ||
|                 //物料
 | ||
|                 QFilter f = new QFilter("number", "=", itemCode);
 | ||
|                 DynamicObject[] materialArr = BusinessDataServiceHelper.load("bd_material", "id,number,name,baseunit", new QFilter[]{f});
 | ||
|                 if(materialArr != null && materialArr.length > 0){
 | ||
|                     material = materialArr[0];
 | ||
|                     //物料库存信息
 | ||
|                     f = new QFilter("masterid.id", "=", material.getPkValue());
 | ||
|                     DynamicObject[] materialinvArr = BusinessDataServiceHelper.load("bd_materialinventoryinfo", "id,number,name", new QFilter[]{f});
 | ||
|                     if(materialinvArr != null && materialinvArr.length > 0){
 | ||
|                         materialinv = materialinvArr[0];
 | ||
|                         materialinv = BusinessDataServiceHelper.loadSingle(materialinv.getPkValue(), "bd_materialinventoryinfo");
 | ||
|                     }else{
 | ||
|                         errormsg = errormsg.append(";").append("物料编码:"+ itemCode +" 没有生成对应物料库存信息");
 | ||
|                     }
 | ||
|                 }else{
 | ||
|                     errormsg = errormsg.append(";").append("根据传入参数 itemCode:"+ itemCode +" 没有查询到对应物料信息");
 | ||
|                 }
 | ||
|             }
 | ||
|             String itemId = ckObj.getString("itemId");//仓储系统商品ID-条件必填
 | ||
|             String inventoryType = ckObj.getString("inventoryType");//库存类型-ZP=正品, CC=残次,JS=机损, XS= 箱损, ZT=在途库存,DJ=冻结
 | ||
|             String quantity = ckObj.getString("quantity");//异动数量-必填,有正负
 | ||
|             if (ApiResultExt.validateRequired(quantity, "int")) {
 | ||
|                 errormsg = errormsg.append(";").append("传入参数 quantity 为空");
 | ||
|             }
 | ||
|             String batchCode = ckObj.getString("batchCode");//批次编码-必填
 | ||
|             DynamicObject olot = null;
 | ||
|             if (ApiResultExt.validateRequired(batchCode, "String")) {
 | ||
|                 errormsg = errormsg.append(";").append("传入参数 batchCode 为空");
 | ||
|             }else{
 | ||
|                 //调整前批号
 | ||
|                 QFilter f = new QFilter("number", "=", batchCode);
 | ||
|                 DynamicObject[] olotArr = BusinessDataServiceHelper.load("bd_lot", "id,number,name", new QFilter[]{f});
 | ||
|                 if(olotArr != null && olotArr.length > 0){
 | ||
|                     olot = olotArr[0];
 | ||
|                 }else{
 | ||
|                     errormsg = errormsg.append(";").append("根据传入参数 batchCode:"+ batchCode +" 没有查询到对应批次信息");
 | ||
|                 }
 | ||
|             }
 | ||
|             Date productDate = ckObj.getDate("productDate");//生产日期
 | ||
|             Date expireDate = ckObj.getDate("expireDate");//过期日期
 | ||
|             String produceCode = ckObj.getString("produceCode");//生产批号
 | ||
|             Date changeTime = ckObj.getDate("changeTime");//异动时间-必填
 | ||
|             if (ApiResultExt.validateRequired(changeTime, "Date")) {
 | ||
|                 errormsg = errormsg.append(";").append("传入参数 changeTime 为空");
 | ||
|             }
 | ||
|             String remark = ckObj.getString("remark");//备注
 | ||
|             //调整前商品
 | ||
|             DynamicObject oGoods = null;
 | ||
|             DynamicObject[] oGoodsArr = BaseDataMatchUtils.materialMatchGoods(itemCode, batchCode, productDate, expireDate, true);
 | ||
|             if(oGoodsArr != null && oGoodsArr.length > 0){
 | ||
|                 oGoods = oGoodsArr[0];
 | ||
|             }else{
 | ||
|                 errormsg = errormsg.append(";").append("根据物料编码 itemCode:"+ itemCode +",批次编号batchCode:"+batchCode+" 没有查询到对应商品信息");
 | ||
|             }
 | ||
| 
 | ||
|             String batchCode_e = rkObj.getString("batchCode");//入库批号
 | ||
|             //调整后生产日期
 | ||
|             Date productDate_e = rkObj.getDate("productDate");
 | ||
|             //调整后有效期
 | ||
|             Date expireDate_e = rkObj.getDate("expireDate");
 | ||
|             //调整后商品
 | ||
|             DynamicObject iGoods = null;
 | ||
|             DynamicObject[] iGoodsArr = BaseDataMatchUtils.materialMatchGoods(itemCode, batchCode_e, productDate, expireDate, true);
 | ||
|             if(iGoodsArr != null && iGoodsArr.length > 0){
 | ||
|                 iGoods = iGoodsArr[0];
 | ||
|             }else{
 | ||
|                 errormsg = errormsg.append(";").append("根据物料编码 itemCode:"+ itemCode +",批次编号 batch-batchCode:"+batchCode_e+" 没有查询到对应商品信息");
 | ||
|             }
 | ||
|             //调整后批次
 | ||
|             DynamicObject ilot = null;
 | ||
|             if (ApiResultExt.validateRequired(batchCode_e, "String")) {
 | ||
|                 errormsg = errormsg.append(";").append("传入参数 batch-batchCode 为空");
 | ||
|             }else{
 | ||
|                 QFilter f = new QFilter("number", "=", batchCode_e);
 | ||
|                 DynamicObject[] ilotArr = BusinessDataServiceHelper.load("bd_lot", "id,number,name", new QFilter[]{f});
 | ||
|                 if(ilotArr != null && ilotArr.length > 0){
 | ||
|                     ilot = ilotArr[0];
 | ||
|                 }else{
 | ||
|                     errormsg = errormsg.append(";").append("根据传入参数 batch-batchCode:"+ batchCode_e +" 没有查询到对应批次信息");
 | ||
|                 }
 | ||
|             }
 | ||
|             int quantity_e = rkObj.getInteger("quantity");
 | ||
| 
 | ||
|             //常量准备-查询单据类型
 | ||
|             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];
 | ||
| 
 | ||
|             if (errormsg.length() > 0) {
 | ||
|                 response.setMessage(errormsg.substring(1));
 | ||
|                 response.setCode("-1");
 | ||
|                 response.setFlag("failure");
 | ||
|                 return CustomApiResult.success(wmsXmlReturn);
 | ||
|             }else {
 | ||
|                 //单据构建
 | ||
|                 DynamicObject adjustbill = BusinessDataServiceHelper.newDynamicObject("im_adjustbill");
 | ||
|                 adjustbill.set("billno", orderCode);
 | ||
|                 adjustbill.set("biztime", changeTime);
 | ||
|                 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");//调整前明细
 | ||
|                 //调整前明细
 | ||
|                 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", quantity);
 | ||
|                 beforeEntry.set("baseunit", material.getDynamicObject("baseunit"));
 | ||
|                 beforeEntry.set("baseqty", quantity);
 | ||
|                 beforeEntry.set("lot", olot);
 | ||
|                 beforeEntry.set("lotnumber", batchCode);
 | ||
|                 beforeEntry.set("producedate", productDate);
 | ||
|                 beforeEntry.set("expirydate", expireDate);
 | ||
|                 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);
 | ||
|                 afterEntry.set("tqq9_goods1", iGoods);
 | ||
|                 afterEntry.set("unit1", material.getDynamicObject("baseunit"));
 | ||
|                 afterEntry.set("qty1", quantity_e);
 | ||
|                 afterEntry.set("baseunit1", material.getDynamicObject("baseunit"));
 | ||
|                 afterEntry.set("baseqty1", quantity_e);
 | ||
|                 afterEntry.set("lot1", ilot);
 | ||
|                 afterEntry.set("lotnumber1", batchCode_e);
 | ||
|                 afterEntry.set("producedate1", productDate_e);
 | ||
|                 afterEntry.set("expirydate1", expireDate_e);
 | ||
|                 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<IOperateInfo> allErrorOrValidateInfo = operationResult.getAllErrorOrValidateInfo();
 | ||
|                     for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
 | ||
|                         errormsg = errormsg.append(";").append(iOperateInfo.getMessage());
 | ||
|                     }
 | ||
|                     response.setMessage(errormsg.substring(1));
 | ||
|                     response.setCode("-1");
 | ||
|                     response.setFlag("failure");
 | ||
|                     return CustomApiResult.success(wmsXmlReturn);
 | ||
|                 }else {
 | ||
|                     //提交
 | ||
|                     operationResult = OperationServiceHelper.executeOperate("submit", "im_adjustbill", new DynamicObject[]{adjustbill}, OperateOption.create());
 | ||
|                     if(!operationResult.isSuccess()){
 | ||
|                         List<IOperateInfo> allErrorOrValidateInfo = operationResult.getAllErrorOrValidateInfo();
 | ||
|                         for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
 | ||
|                             errormsg = errormsg.append(";").append(iOperateInfo.getMessage());
 | ||
|                         }
 | ||
|                         response.setMessage(errormsg.substring(1));
 | ||
|                         response.setCode("-1");
 | ||
|                         response.setFlag("failure");
 | ||
|                         return CustomApiResult.success(wmsXmlReturn);
 | ||
|                     }else {
 | ||
|                         //审核
 | ||
|                         operationResult = OperationServiceHelper.executeOperate("audit", "im_adjustbill", new DynamicObject[]{adjustbill}, OperateOption.create());
 | ||
|                         if(!operationResult.isSuccess()){
 | ||
|                             List<IOperateInfo> allErrorOrValidateInfo = operationResult.getAllErrorOrValidateInfo();
 | ||
|                             for (IOperateInfo iOperateInfo : allErrorOrValidateInfo) {
 | ||
|                                 errormsg = errormsg.append(";").append(iOperateInfo.getMessage());
 | ||
|                             }
 | ||
|                             response.setMessage(errormsg.substring(1));
 | ||
|                             response.setCode("-1");
 | ||
|                             response.setFlag("failure");
 | ||
|                             return CustomApiResult.success(wmsXmlReturn);
 | ||
|                         }
 | ||
|                     }
 | ||
|                 }
 | ||
| 
 | ||
|                 response.setCode("0");
 | ||
|                 response.setFlag("success");
 | ||
|                 response.setMessage("成功");
 | ||
|                 return CustomApiResult.success(wmsXmlReturn);
 | ||
|             }
 | ||
|         }else{
 | ||
|             response.setMessage("传入参数items为空或者items数量不对");
 | ||
|             response.setCode("-1");
 | ||
|             response.setFlag("failure");
 | ||
|             return CustomApiResult.success(wmsXmlReturn);
 | ||
|         }
 | ||
|     }
 | ||
| }
 |