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()); + } + } + +}