diff --git a/hw-api/hw-api-wms/src/main/java/com/hw/wms/api/RemoteWmsService.java b/hw-api/hw-api-wms/src/main/java/com/hw/wms/api/RemoteWmsService.java index 9f89ccfc..2f175f11 100644 --- a/hw-api/hw-api-wms/src/main/java/com/hw/wms/api/RemoteWmsService.java +++ b/hw-api/hw-api-wms/src/main/java/com/hw/wms/api/RemoteWmsService.java @@ -37,6 +37,14 @@ public interface RemoteWmsService { @PostMapping("/api/synchronizeRawMaterialDeliveryInformationToERP") public R synchronizeRawMaterialDeliveryInformationToERP(@RequestHeader(SecurityConstants.FROM_SOURCE) String source); + /** + * 定时同步原材料退库信息给ERP + * @param source + * @return + */ + @PostMapping("/api/synchronizeRawReturnInformationToERP") + public R synchronizeRawReturnInformationToERP(@RequestHeader(SecurityConstants.FROM_SOURCE) String source); + @PostMapping("/rawstock/isExistRawStock") public R isExistRawStock(@Validated @RequestBody WmsRawStockVo queryRawStockVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); diff --git a/hw-api/hw-api-wms/src/main/java/com/hw/wms/api/factory/RemoteWmsFallbackFactory.java b/hw-api/hw-api-wms/src/main/java/com/hw/wms/api/factory/RemoteWmsFallbackFactory.java index 0befa0af..43f4185f 100644 --- a/hw-api/hw-api-wms/src/main/java/com/hw/wms/api/factory/RemoteWmsFallbackFactory.java +++ b/hw-api/hw-api-wms/src/main/java/com/hw/wms/api/factory/RemoteWmsFallbackFactory.java @@ -37,6 +37,11 @@ public class RemoteWmsFallbackFactory implements FallbackFactory synchronizeRawReturnInformationToERP(String source) { + return R.fail("定时同步原材料退库给ERP失败:" + throwable.getMessage()); + } + @Override public R synchronizeProductInstockInformationToERP(Integer days, String inner) { return R.fail("定时同步成品入库给ERP失败:" + throwable.getMessage()); diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/config/WmsConfig.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/config/WmsConfig.java index ff954935..5d265579 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/config/WmsConfig.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/config/WmsConfig.java @@ -63,6 +63,11 @@ public class WmsConfig { */ private String wcsAgvContinueUrl; + /** + * 同步ERP的仓库编码 + */ + private String fStockId; + public String getFifthAssembleStationCode() { return fifthAssembleStationCode; } @@ -142,4 +147,12 @@ public class WmsConfig { public void setWcsAgvContinueUrl(String wcsAgvContinueUrl) { this.wcsAgvContinueUrl = wcsAgvContinueUrl; } + + public String getfStockId() { + return fStockId; + } + + public void setfStockId(String fStockId) { + this.fStockId = fStockId; + } } diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/controller/WmsApiController.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/controller/WmsApiController.java index 21fc4dcd..20d26f89 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/controller/WmsApiController.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/controller/WmsApiController.java @@ -259,6 +259,17 @@ public class WmsApiController extends BaseController { return toAjax(wmsErpScheduledTaskService.synchronizeRawMaterialDeliveryInformationToERP()); } + + /** + * 定时同步原材料退库信息给ERP + * + * @return + */ + @PostMapping(("/synchronizeRawReturnInformationToERP")) + public AjaxResult synchronizeRawReturnInformationToERP() { + return toAjax(wmsErpScheduledTaskService.synchronizeRawReturnInformationToERP()); + } + /** * 定时同步成品入库信息给ERP * diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsRawReturnDetail.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsRawReturnDetail.java index edc6cd7c..c95606d9 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsRawReturnDetail.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/domain/WmsRawReturnDetail.java @@ -111,6 +111,10 @@ public class WmsRawReturnDetail extends BaseEntity private String taskCode; + private Long purchaseOrderId; + + private String unitCode; + public void setRawReturnDetailId(Long rawReturnDetailId) { @@ -341,6 +345,22 @@ public class WmsRawReturnDetail extends BaseEntity this.taskCode = taskCode; } + public Long getPurchaseOrderId() { + return purchaseOrderId; + } + + public void setPurchaseOrderId(Long purchaseOrderId) { + this.purchaseOrderId = purchaseOrderId; + } + + public String getUnitCode() { + return unitCode; + } + + public void setUnitCode(String unitCode) { + this.unitCode = unitCode; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/mapper/WmsRawReturnDetailMapper.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/mapper/WmsRawReturnDetailMapper.java index 177403f0..62498518 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/mapper/WmsRawReturnDetailMapper.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/mapper/WmsRawReturnDetailMapper.java @@ -76,4 +76,14 @@ public interface WmsRawReturnDetailMapper { * @return 原材料退库记录明细集合 */ public List selectWmsRawReturnDetailJoinMaterialList(WmsRawReturnDetail wmsRawReturnDetail); + + + /** + * 查询未同步完成的原材料退库记录明细列表 + * + * @param wmsRawReturnDetail 原材料退库记录明细 + * @return 原材料退库记录明细集合 + */ + public List selectWmsRawReturnDetailERPNotSynchronized(WmsRawReturnDetail wmsRawReturnDetail); + } diff --git a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/IWmsErpScheduledTaskService.java b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/IWmsErpScheduledTaskService.java index 9749e5d1..407a4867 100644 --- a/hw-modules/hw-wms/src/main/java/com/hw/wms/service/IWmsErpScheduledTaskService.java +++ b/hw-modules/hw-wms/src/main/java/com/hw/wms/service/IWmsErpScheduledTaskService.java @@ -22,6 +22,13 @@ public interface IWmsErpScheduledTaskService { */ int synchronizeRawMaterialDeliveryInformationToERP(); + /** + * 定时同步退库信息给ERP + * + * @return + */ + public int synchronizeRawReturnInformationToERP(); + /** * 定时同步成品入库信息给ERP * @param days 同步days天前数据 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 index d50cf2a3..9dea0ff6 100644 --- 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 @@ -11,14 +11,9 @@ import com.hw.common.core.web.domain.AjaxResult; import com.hw.jindie.api.RemoteJindieService; import com.hw.mes.api.RemoteMesService; import com.hw.mes.api.domain.MesPurchaseOrder; -import com.hw.wms.domain.WmsProductInstock; -import com.hw.wms.domain.WmsProductOutstock; -import com.hw.wms.domain.WmsRawInstock; -import com.hw.wms.domain.WmsRawOutstock; -import com.hw.wms.mapper.WmsProductInstockMapper; -import com.hw.wms.mapper.WmsProductOutstockMapper; -import com.hw.wms.mapper.WmsRawInstockMapper; -import com.hw.wms.mapper.WmsRawOutstockMapper; +import com.hw.wms.config.WmsConfig; +import com.hw.wms.domain.*; +import com.hw.wms.mapper.*; import com.hw.wms.service.IWmsErpScheduledTaskService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,14 +50,20 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi @Autowired private WmsProductOutstockMapper wmsProductOutstockMapper; + @Autowired + private WmsRawReturnDetailMapper wmsRawReturnDetailMapper; + @Autowired private RemoteMesService remoteMesService; @Autowired private RemoteJindieService remoteJindieService; + @Autowired + private WmsConfig wmsConfig; + //仓库编码 - private String FStockId = "CK050"; +// private String FStockId = "CK050"; /** * 定时同步入库信息给ERP @@ -110,7 +111,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi data.put("FSrcBillNo", instock.getSrcBillNo()); data.put("FUnitID", instock.getUnitCode()); data.put("FRealQty", FRealQty); - data.put("FStockId", FStockId); + data.put("FStockId", wmsConfig.getfStockId()); data.put("FSupplierCode", supplierCode); data.put("FTondBase", projectNo); String params = data.toJSONString(); @@ -155,6 +156,76 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi return result; } + /** + * 定时同步退库信息给ERP + * + * @return + */ + @Override +// @Transactional + public int synchronizeRawReturnInformationToERP() { + WmsRawReturnDetail wmsRawReturnDetail = new WmsRawReturnDetail(); + int result = 0; + List returnDetailList = wmsRawReturnDetailMapper.selectWmsRawReturnDetailERPNotSynchronized(wmsRawReturnDetail); + Map> purchaseOrderIdMap = returnDetailList.stream().collect(Collectors.groupingBy(WmsRawReturnDetail::getPurchaseOrderId)); + + for (Long purchaseOrderId : purchaseOrderIdMap.keySet()) { + syncRawReturnInformation(purchaseOrderIdMap, purchaseOrderId, result); + } + return result; + } + + + @Transactional(propagation = Propagation.REQUIRES_NEW) + public void syncRawReturnInformation(Map> purchaseOrderIdMap, Long purchaseOrderId, int result) { + R purchaseOrderData = remoteMesService.selectPurchaseOrderJoinSupplierProjectByOrderId(purchaseOrderId, SecurityConstants.INNER); + MesPurchaseOrder mesPurchaseOrder = null; + if (purchaseOrderData != null) { + mesPurchaseOrder = purchaseOrderData.getData(); + + String supplierCode = mesPurchaseOrder == null ? "" : mesPurchaseOrder.getSupplierCode(); + String projectNo = mesPurchaseOrder == null ? "" : mesPurchaseOrder.getProjectNo(); + String srcBillNo = mesPurchaseOrder.getSrcBillNo(); + + List wmsRawReturnDetaiList = purchaseOrderIdMap.get(purchaseOrderId); + JSONObject data = new JSONObject(); + double FRealQty = wmsRawReturnDetaiList.stream().mapToDouble(item -> item.getReturnAmount().subtract(item.getErpAmount()).doubleValue()).sum(); + WmsRawReturnDetail rawReturnDetail = wmsRawReturnDetaiList.get(0); + String specificationParameter = StringUtils.isNotEmpty(mesPurchaseOrder.getSpecificationParameter()) ? mesPurchaseOrder.getSpecificationParameter() : rawReturnDetail.getMaterialSpec(); + if (StringUtils.isNotEmpty(specificationParameter)) { + + for (WmsRawReturnDetail wmsRawReturnDetail : wmsRawReturnDetaiList) { + wmsRawReturnDetail.setErpStatus("1");//同步ERP状态(0:失败,1成功) + wmsRawReturnDetail.setErpAmount(wmsRawReturnDetail.getReturnAmount()); + wmsRawReturnDetail.setUpdateDate(DateUtils.getNowDate()); + wmsRawReturnDetailMapper.updateWmsRawReturnDetail(wmsRawReturnDetail); + } + data.put("FDate", DateUtils.getTime()); + data.put("FMaterialId", rawReturnDetail.getMaterialCode()); + data.put("FAuxPropId", specificationParameter); + data.put("FSrcBillNo", srcBillNo); + data.put("FUnitID", rawReturnDetail.getUnitCode()); + data.put("FRealQty", FRealQty); + data.put("FStockId", wmsConfig.getfStockId()); + data.put("FSupplierCode", supplierCode); + data.put("FTondBase", projectNo); + 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()); + throw new ServiceException("同步原材料入库失败" + paramsResult.toString()); + } + } + } + } + + @Transactional(propagation = Propagation.REQUIRES_NEW) public int syncOutstockInformation(Map> materialIdMap, Long materialId, String taskType) { int result = 0; @@ -186,7 +257,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi data.put("FUnitID", outstock.getUnitCode()); data.put("FQty", FRealQty); data.put("FPrice", outstock.getPrice()); - data.put("FStockId", FStockId); + data.put("FStockId", wmsConfig.getfStockId()); String params = data.toJSONString(); R paramsResult = remoteJindieService.saveOtherOutStorage(params, SecurityConstants.INNER); @@ -246,7 +317,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi data.put("FUnitID", instock.getUnitCode()); data.put("FQty", FRealQty); data.put("FPrice", instock.getPrice()); - data.put("FStockId", FStockId); + data.put("FStockId", wmsConfig.getfStockId()); String params = data.toJSONString(); R paramsResult = remoteJindieService.saveOtherInStorage(params, SecurityConstants.INNER); String paramsResultData = paramsResult.getMsg(); @@ -303,7 +374,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi data.put("FUnitID", outstock.getUnitCode()); data.put("FQty", FRealQty); data.put("FPrice", outstock.getPrice()); - data.put("FStockId", FStockId); + data.put("FStockId", wmsConfig.getfStockId()); data.put("FTONDCombo", "一般领料"); String params = data.toJSONString(); R paramsResult = remoteJindieService.saveOtherOutStorage(params, SecurityConstants.INNER); diff --git a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsRawReturnDetailMapper.xml b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsRawReturnDetailMapper.xml index 5ef8e559..b1350f11 100644 --- a/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsRawReturnDetailMapper.xml +++ b/hw-modules/hw-wms/src/main/resources/mapper/wms/WmsRawReturnDetailMapper.xml @@ -30,8 +30,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + select raw_return_detail_id, raw_return_id, location_code, material_barcode, material_id, instock_batch, material_production_Date, plan_amount, return_amount, execute_status, erp_status, return_person, return_time, return_way, machine_name, quality_status, create_by, create_date, update_by, update_date, stack_amount from wms_raw_return_detail @@ -204,4 +209,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and stack_amount = #{stackAmount} + + + + + + +