From cf5583f3b693e41345f9bef3d4cc587db719f07a Mon Sep 17 00:00:00 2001 From: yinq Date: Sat, 27 Jul 2024 18:58:35 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E9=87=87=E8=B4=AD=E7=94=B3?= =?UTF-8?q?=E8=AF=B7=E5=8D=95=E5=A4=9A=E7=89=A9=E6=96=99=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?ERP=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/IWmsErpScheduledTaskServiceImpl.java | 84 ----------------- .../impl/WmsErpScheduledTaskServiceImpl.java | 92 +++++++++++++++++++ 2 files changed, 92 insertions(+), 84 deletions(-) delete mode 100644 hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/IWmsErpScheduledTaskServiceImpl.java create mode 100644 hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsErpScheduledTaskServiceImpl.java diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/IWmsErpScheduledTaskServiceImpl.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/IWmsErpScheduledTaskServiceImpl.java deleted file mode 100644 index 4c95807..0000000 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/IWmsErpScheduledTaskServiceImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.hw.wms.service.impl; - -import com.alibaba.fastjson2.JSONObject; -import com.hw.common.core.constant.SecurityConstants; -import com.hw.common.core.domain.R; -import com.hw.common.core.utils.DateUtils; -import com.hw.common.core.web.domain.AjaxResult; -import com.hw.jindie.api.RemoteJindieService; -import com.hw.wms.domain.WmsRawInstock; -import com.hw.wms.mapper.WmsRawInstockMapper; -import com.hw.wms.service.IWmsErpScheduledTaskService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * erp定时任务Service业务层处理 - * - * @author Yinq - * @date 2024-07-25 - */ -@Service -public class IWmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskService { - - private static final Logger log = LoggerFactory.getLogger(IWmsErpScheduledTaskServiceImpl.class); - - @Autowired - private WmsRawInstockMapper wmsRawInstockMapper; - - @Autowired - private RemoteJindieService remoteJindieService; - - /** - * 定时同步入库信息给ERP - * - * @return - */ - @Override - public int synchronizeInventoryInformationToERP() { - //仓库编码 - String FStockId = "CK050"; - WmsRawInstock wmsRawInstock = new WmsRawInstock(); - int result = 0; - List inStockList = wmsRawInstockMapper.selectWmsRawInstockERPNotSynchronized(wmsRawInstock); - Map> materialIdMap = inStockList.stream().collect(Collectors.groupingBy(WmsRawInstock::getMaterialId)); - for (Long materialId : materialIdMap.keySet()) { - List wmsRawInstockList = materialIdMap.get(materialId); - JSONObject data = new JSONObject(); - double FRealQty = wmsRawInstockList.stream().mapToDouble(item -> item.getInstockAmount().subtract(item.getErpAmount()).doubleValue()).sum(); - WmsRawInstock instock = wmsRawInstockList.get(0); - data.put("FDate", DateUtils.getTime()); - data.put("FMaterialId", instock.getMaterialCode()); - data.put("FAuxPropId", instock.getSpecificationParameter()); - data.put("FSrcBillNo", instock.getPoNo()); - data.put("FUnitID", instock.getUnitCode()); - data.put("FRealQty", FRealQty); - data.put("FStockId", FStockId); - String params = data.toJSONString(); - R paramsResult = remoteJindieService.savePurchaseStorage(params, SecurityConstants.INNER); - String paramsResultData = paramsResult.getMsg(); - JSONObject jsonObject = JSONObject.parseObject(paramsResultData); - Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess"); - if (isSuccess) { - result++; - for (WmsRawInstock rawInstock : wmsRawInstockList) { - rawInstock.setErpStatus("1");//同步ERP状态(0:失败,1成功) - rawInstock.setErpAmount(rawInstock.getInstockAmount()); - rawInstock.setUpdateDate(DateUtils.getNowDate()); - wmsRawInstockMapper.updateWmsRawInstock(rawInstock); - } - log.info("synchronizeInventoryInformationToERP成功:" + paramsResult.toString()); - } else { - log.error("synchronizeInventoryInformationToERP失败:" + paramsResult.toString()); - } - } - return result; - } - -} diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsErpScheduledTaskServiceImpl.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsErpScheduledTaskServiceImpl.java new file mode 100644 index 0000000..4a5eb47 --- /dev/null +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/impl/WmsErpScheduledTaskServiceImpl.java @@ -0,0 +1,92 @@ +package com.hw.wms.service.impl; + +import com.alibaba.fastjson2.JSONObject; +import com.hw.common.core.constant.SecurityConstants; +import com.hw.common.core.domain.R; +import com.hw.common.core.utils.DateUtils; +import com.hw.common.core.web.domain.AjaxResult; +import com.hw.jindie.api.RemoteJindieService; +import com.hw.wms.domain.WmsRawInstock; +import com.hw.wms.mapper.WmsRawInstockMapper; +import com.hw.wms.service.IWmsErpScheduledTaskService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * erp定时任务Service业务层处理 + * + * @author Yinq + * @date 2024-07-25 + */ +@Service +public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskService { + + private static final Logger log = LoggerFactory.getLogger(WmsErpScheduledTaskServiceImpl.class); + + @Autowired + private WmsRawInstockMapper wmsRawInstockMapper; + + @Autowired + private RemoteJindieService remoteJindieService; + + //仓库编码 + private String FStockId = "CK050"; + + /** + * 定时同步入库信息给ERP + * + * @return + */ + @Override + public int synchronizeInventoryInformationToERP() { + WmsRawInstock wmsRawInstock = new WmsRawInstock(); + int result = 0; + List inStockList = wmsRawInstockMapper.selectWmsRawInstockERPNotSynchronized(wmsRawInstock); + Map> materialIdMap = inStockList.stream().collect(Collectors.groupingBy(WmsRawInstock::getMaterialId)); + for (Long materialId : materialIdMap.keySet()) { + syncInventoryInformation(materialIdMap, materialId, result); + } + return result; + } + + @Transactional(propagation = Propagation.REQUIRES_NEW) + void syncInventoryInformation(Map> materialIdMap, Long materialId, int result) { + List wmsRawInstockList = materialIdMap.get(materialId); + JSONObject data = new JSONObject(); + double FRealQty = wmsRawInstockList.stream().mapToDouble(item -> item.getInstockAmount().subtract(item.getErpAmount()).doubleValue()).sum(); + WmsRawInstock instock = wmsRawInstockList.get(0); + for (WmsRawInstock rawInstock : wmsRawInstockList) { + rawInstock.setErpStatus("1");//同步ERP状态(0:失败,1成功) + rawInstock.setErpAmount(rawInstock.getInstockAmount()); + rawInstock.setUpdateDate(DateUtils.getNowDate()); + wmsRawInstockMapper.updateWmsRawInstock(rawInstock); + } + data.put("FDate", DateUtils.getTime()); + data.put("FMaterialId", instock.getMaterialCode()); + data.put("FAuxPropId", instock.getSpecificationParameter()); + data.put("FSrcBillNo", instock.getPoNo()); + data.put("FUnitID", instock.getUnitCode()); + data.put("FRealQty", FRealQty); + data.put("FStockId", FStockId); + String params = data.toJSONString(); + R paramsResult = remoteJindieService.savePurchaseStorage(params, SecurityConstants.INNER); + String paramsResultData = paramsResult.getMsg(); + JSONObject jsonObject = JSONObject.parseObject(paramsResultData); + Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess"); + if (isSuccess) { + result++; + log.info("synchronizeInventoryInformationToERP成功:" + paramsResult.toString()); + } else { + log.error("synchronizeInventoryInformationToERP失败:" + paramsResult.toString()); + } + } + +}