WMS:
完善同步原材料入库信息给ERP、同步原材料出库信息给ERP、同步成品入库信息给ERP和同步成品出库信息给ERP
master
xs 3 months ago
parent 4b477a3e4e
commit c2066b4477

@ -221,7 +221,7 @@ public class WmsApiController extends BaseController {
/** /**
* ERP * ERP
* @return * @return
*/ */
@PostMapping(("/synchronizeInventoryInformationToERP")) @PostMapping(("/synchronizeInventoryInformationToERP"))

@ -134,6 +134,8 @@ public class WmsRawInstock extends BaseEntity
/** 规格参数 */ /** 规格参数 */
private String specificationParameter; private String specificationParameter;
private String srcBillNo;
public String getSpecificationParameter() { public String getSpecificationParameter() {
return specificationParameter; return specificationParameter;
} }
@ -399,6 +401,14 @@ public class WmsRawInstock extends BaseEntity
this.materialName = materialName; this.materialName = materialName;
} }
public String getSrcBillNo() {
return srcBillNo;
}
public void setSrcBillNo(String srcBillNo) {
this.srcBillNo = srcBillNo;
}
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

@ -3,6 +3,7 @@ package com.hw.wms.service.impl;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.hw.common.core.constant.SecurityConstants; import com.hw.common.core.constant.SecurityConstants;
import com.hw.common.core.domain.R; import com.hw.common.core.domain.R;
import com.hw.common.core.exception.ServiceException;
import com.hw.common.core.utils.DateUtils; import com.hw.common.core.utils.DateUtils;
import com.hw.common.core.web.domain.AjaxResult; import com.hw.common.core.web.domain.AjaxResult;
import com.hw.jindie.api.RemoteJindieService; import com.hw.jindie.api.RemoteJindieService;
@ -62,20 +63,22 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
* @return * @return
*/ */
@Override @Override
@Transactional
public int synchronizeInventoryInformationToERP() { public int synchronizeInventoryInformationToERP() {
WmsRawInstock wmsRawInstock = new WmsRawInstock(); WmsRawInstock wmsRawInstock = new WmsRawInstock();
int result = 0; int result = 0;
List<WmsRawInstock> inStockList = wmsRawInstockMapper.selectWmsRawInstockERPNotSynchronized(wmsRawInstock); List<WmsRawInstock> inStockList = wmsRawInstockMapper.selectWmsRawInstockERPNotSynchronized(wmsRawInstock);
Map<Long, List<WmsRawInstock>> materialIdMap = inStockList.stream().collect(Collectors.groupingBy(WmsRawInstock::getMaterialId)); Map<Long, List<WmsRawInstock>> purchaseOrderIdMap = inStockList.stream().collect(Collectors.groupingBy(WmsRawInstock::getPurchaseOrderId));
for (Long materialId : materialIdMap.keySet()) {
syncInventoryInformation(materialIdMap, materialId, result); for (Long purchaseOrderId : purchaseOrderIdMap.keySet()) {
syncInventoryInformation(purchaseOrderIdMap, purchaseOrderId, result);
} }
return result; return result;
} }
@Transactional(propagation = Propagation.REQUIRES_NEW) @Transactional(propagation = Propagation.REQUIRES_NEW)
void syncInventoryInformation(Map<Long, List<WmsRawInstock>> materialIdMap, Long materialId, int result) { public void syncInventoryInformation(Map<Long, List<WmsRawInstock>> purchaseOrderIdMap, Long purchaseOrderId, int result) {
List<WmsRawInstock> wmsRawInstockList = materialIdMap.get(materialId); List<WmsRawInstock> wmsRawInstockList = purchaseOrderIdMap.get(purchaseOrderId);
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
double FRealQty = wmsRawInstockList.stream().mapToDouble(item -> item.getInstockAmount().subtract(item.getErpAmount()).doubleValue()).sum(); double FRealQty = wmsRawInstockList.stream().mapToDouble(item -> item.getInstockAmount().subtract(item.getErpAmount()).doubleValue()).sum();
WmsRawInstock instock = wmsRawInstockList.get(0); WmsRawInstock instock = wmsRawInstockList.get(0);
@ -88,7 +91,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
data.put("FDate", DateUtils.getTime()); data.put("FDate", DateUtils.getTime());
data.put("FMaterialId", instock.getMaterialCode()); data.put("FMaterialId", instock.getMaterialCode());
data.put("FAuxPropId", instock.getSpecificationParameter()); data.put("FAuxPropId", instock.getSpecificationParameter());
data.put("FSrcBillNo", instock.getPoNo()); data.put("FSrcBillNo", instock.getSrcBillNo());
data.put("FUnitID", instock.getUnitCode()); data.put("FUnitID", instock.getUnitCode());
data.put("FRealQty", FRealQty); data.put("FRealQty", FRealQty);
data.put("FStockId", FStockId); data.put("FStockId", FStockId);
@ -99,9 +102,10 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess"); Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess");
if (isSuccess) { if (isSuccess) {
result++; result++;
log.info("synchronizeInventoryInformationToERP成功:" + paramsResult.toString()); log.info("synchronizeInventoryInformationToERP同步原材料入库成功:" + paramsResult.toString());
} else { } else {
log.error("synchronizeInventoryInformationToERP失败:" + paramsResult.toString()); log.error("synchronizeInventoryInformationToERP同步原材料入库失败:" + paramsResult.toString());
throw new RuntimeException("同步原材料入库失败"+paramsResult.toString());
} }
} }
@ -111,6 +115,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
* @return * @return
*/ */
@Override @Override
@Transactional
public int synchronizeRawMaterialDeliveryInformationToERP() { public int synchronizeRawMaterialDeliveryInformationToERP() {
WmsRawOutstock rawOutstock = new WmsRawOutstock(); WmsRawOutstock rawOutstock = new WmsRawOutstock();
int result = 0; int result = 0;
@ -123,11 +128,22 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
} }
@Transactional(propagation = Propagation.REQUIRES_NEW) @Transactional(propagation = Propagation.REQUIRES_NEW)
void syncOutstockInformation(Map<Long, List<WmsRawOutstock>> materialIdMap, Long materialId, int result) { public void syncOutstockInformation(Map<Long, List<WmsRawOutstock>> materialIdMap, Long materialId, int result) {
List<WmsRawOutstock> wmsRawOutstockList = materialIdMap.get(materialId); List<WmsRawOutstock> wmsRawOutstockList = materialIdMap.get(materialId);
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
double FRealQty = wmsRawOutstockList.stream().mapToDouble(item -> item.getRealOutstockAmount().subtract(item.getErpAmount()).doubleValue()).sum(); double FRealQty = wmsRawOutstockList.stream().mapToDouble(item -> item.getRealOutstockAmount().subtract(item.getErpAmount()).doubleValue()).sum();
WmsRawOutstock outstock = wmsRawOutstockList.get(0); WmsRawOutstock outstock = wmsRawOutstockList.get(0);
for (WmsRawOutstock wmsRawOutstock : wmsRawOutstockList) {
if (wmsRawOutstock.getRealOutstockAmount().equals(wmsRawOutstock.getOutstockAmount())) {
wmsRawOutstock.setErpStatus("1");//同步ERP状态(0:失败,1成功,2同步中)
} else {
wmsRawOutstock.setErpStatus("2");//同步ERP状态(0:失败,1成功,2同步中)
}
wmsRawOutstock.setErpAmount(wmsRawOutstock.getRealOutstockAmount());
wmsRawOutstock.setUpdateDate(DateUtils.getNowDate());
wmsRawOutstockMapper.updateWmsRawOutstock(wmsRawOutstock);
}
data.put("FDate", DateUtils.getTime()); data.put("FDate", DateUtils.getTime());
data.put("FMaterialId", outstock.getMaterialCode()); data.put("FMaterialId", outstock.getMaterialCode());
data.put("FAuxPropId", outstock.getSpecificationParameter()); data.put("FAuxPropId", outstock.getSpecificationParameter());
@ -142,19 +158,10 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess"); Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess");
if (isSuccess) { if (isSuccess) {
result++; result++;
for (WmsRawOutstock wmsRawOutstock : wmsRawOutstockList) {
if (wmsRawOutstock.getRealOutstockAmount().equals(wmsRawOutstock.getOutstockAmount())) {
wmsRawOutstock.setErpStatus("1");//同步ERP状态(0:失败,1成功,2同步中)
} else {
wmsRawOutstock.setErpStatus("2");//同步ERP状态(0:失败,1成功,2同步中)
}
wmsRawOutstock.setErpAmount(wmsRawOutstock.getRealOutstockAmount());
wmsRawOutstock.setUpdateDate(DateUtils.getNowDate());
wmsRawOutstockMapper.updateWmsRawOutstock(wmsRawOutstock);
}
log.info("synchronizeRawMaterialDeliveryInformationToERP成功:" + paramsResult.toString()); log.info("synchronizeRawMaterialDeliveryInformationToERP成功:" + paramsResult.toString());
} else { } else {
log.error("synchronizeRawMaterialDeliveryInformationToERP失败:" + paramsResult.toString()); log.error("synchronizeRawMaterialDeliveryInformationToERP失败:" + paramsResult.toString());
throw new RuntimeException("synchronizeRawMaterialDeliveryInformationToERP失败:" + paramsResult.toString());
} }
} }
@ -164,6 +171,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
* @return * @return
*/ */
@Override @Override
@Transactional
public int synchronizeProductInstockInformationToERP(Integer days) { public int synchronizeProductInstockInformationToERP(Integer days) {
int result = 0; int result = 0;
WmsProductInstock wmsProductInstock = new WmsProductInstock(); WmsProductInstock wmsProductInstock = new WmsProductInstock();
@ -181,11 +189,18 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
} }
@Transactional(propagation = Propagation.REQUIRES_NEW) @Transactional(propagation = Propagation.REQUIRES_NEW)
void syncProductInstockInformation(Map<Long, List<WmsProductInstock>> productIdMap, Long productId, int result) { public void syncProductInstockInformation(Map<Long, List<WmsProductInstock>> productIdMap, Long productId, int result) {
List<WmsProductInstock> wmsProductInstockList = productIdMap.get(productId); List<WmsProductInstock> wmsProductInstockList = productIdMap.get(productId);
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
double FRealQty = wmsProductInstockList.stream().mapToDouble(item -> item.getInstockAmount().subtract(item.getErpAmount()).doubleValue()).sum(); double FRealQty = wmsProductInstockList.stream().mapToDouble(item -> item.getInstockAmount().subtract(item.getErpAmount()).doubleValue()).sum();
WmsProductInstock instock = wmsProductInstockList.get(0); WmsProductInstock instock = wmsProductInstockList.get(0);
for (WmsProductInstock wmsProductInstock : wmsProductInstockList) {
wmsProductInstock.setErpStatus("1");//同步ERP状态(0:失败,1成功)
wmsProductInstock.setErpAmount(wmsProductInstock.getInstockAmount());
wmsProductInstock.setUpdateDate(DateUtils.getNowDate());
wmsProductInstockMapper.updateWmsProductInstock(wmsProductInstock);
}
data.put("FDate", DateUtils.getTime()); data.put("FDate", DateUtils.getTime());
data.put("FMaterialId", instock.getMaterialCode()); data.put("FMaterialId", instock.getMaterialCode());
data.put("FAuxPropId", instock.getSpecificationParameter()); data.put("FAuxPropId", instock.getSpecificationParameter());
@ -200,15 +215,10 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess"); Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess");
if (isSuccess) { if (isSuccess) {
result++; result++;
for (WmsProductInstock wmsProductInstock : wmsProductInstockList) {
wmsProductInstock.setErpStatus("1");//同步ERP状态(0:失败,1成功)
wmsProductInstock.setErpAmount(wmsProductInstock.getInstockAmount());
wmsProductInstock.setUpdateDate(DateUtils.getNowDate());
wmsProductInstockMapper.updateWmsProductInstock(wmsProductInstock);
}
log.info("synchronizeProductInstockInformationToERP成功:" + paramsResult.toString()); log.info("synchronizeProductInstockInformationToERP成功:" + paramsResult.toString());
} else { } else {
log.error("synchronizeProductInstockInformationToERP失败:" + paramsResult.toString()); log.error("synchronizeProductInstockInformationToERP失败:" + paramsResult.toString());
throw new RuntimeException("synchronizeProductInstockInformationToERP失败:" + paramsResult.toString());
} }
} }
@ -218,6 +228,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
* @return * @return
*/ */
@Override @Override
@Transactional
public int synchronizeProductOutstockInformationToERP(Integer days) { public int synchronizeProductOutstockInformationToERP(Integer days) {
int result = 0; int result = 0;
WmsProductOutstock wmsProductOutstock = new WmsProductOutstock(); WmsProductOutstock wmsProductOutstock = new WmsProductOutstock();
@ -235,11 +246,17 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
} }
@Transactional(propagation = Propagation.REQUIRES_NEW) @Transactional(propagation = Propagation.REQUIRES_NEW)
void syncProductOutstockInformation(Map<Long, List<WmsProductOutstock>> productIdMap, Long productId, int result) { public void syncProductOutstockInformation(Map<Long, List<WmsProductOutstock>> productIdMap, Long productId, int result) {
List<WmsProductOutstock> wmsProductOutstockList = productIdMap.get(productId); List<WmsProductOutstock> wmsProductOutstockList = productIdMap.get(productId);
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
double FRealQty = wmsProductOutstockList.stream().mapToDouble(item -> item.getOutstockQty().subtract(item.getErpAmount()).doubleValue()).sum(); double FRealQty = wmsProductOutstockList.stream().mapToDouble(item -> item.getOutstockQty().subtract(item.getErpAmount()).doubleValue()).sum();
WmsProductOutstock outstock = wmsProductOutstockList.get(0); WmsProductOutstock outstock = wmsProductOutstockList.get(0);
for (WmsProductOutstock wmsProductOutstock : wmsProductOutstockList) {
wmsProductOutstock.setErpStatus("1");//同步ERP状态(0:失败,1成功)
wmsProductOutstock.setErpAmount(wmsProductOutstock.getOutstockQty());
wmsProductOutstock.setUpdateDate(DateUtils.getNowDate());
wmsProductOutstockMapper.updateWmsProductOutstock(wmsProductOutstock);
}
data.put("FDate", DateUtils.getTime()); data.put("FDate", DateUtils.getTime());
data.put("FMaterialId", outstock.getMaterialCode()); data.put("FMaterialId", outstock.getMaterialCode());
data.put("FAuxPropId", outstock.getSpecificationParameter()); data.put("FAuxPropId", outstock.getSpecificationParameter());
@ -254,15 +271,11 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess"); Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess");
if (isSuccess) { if (isSuccess) {
result++; result++;
for (WmsProductOutstock wmsProductOutstock : wmsProductOutstockList) {
wmsProductOutstock.setErpStatus("1");//同步ERP状态(0:失败,1成功)
wmsProductOutstock.setErpAmount(wmsProductOutstock.getOutstockQty());
wmsProductOutstock.setUpdateDate(DateUtils.getNowDate());
wmsProductOutstockMapper.updateWmsProductOutstock(wmsProductOutstock);
}
log.info("synchronizeProductOutstockInformationToERP成功:" + paramsResult.toString()); log.info("synchronizeProductOutstockInformationToERP成功:" + paramsResult.toString());
} else { } else {
log.error("synchronizeProductOutstockInformationToERP失败:" + paramsResult.toString()); log.error("synchronizeProductOutstockInformationToERP失败:" + paramsResult.toString());
throw new RuntimeException("synchronizeProductOutstockInformationToERP失败:" + paramsResult.toString());
} }
} }

@ -314,8 +314,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from wms_product_outstock wpo from wms_product_outstock wpo
left join mes_base_material_info mbmi on mbmi.material_id = wpo.product_id left join mes_base_material_info mbmi on mbmi.material_id = wpo.product_id
left join mes_base_unit_info mbui on mbui.erp_id = mbmi.material_unit_id left join mes_base_unit_info mbui on mbui.erp_id = mbmi.material_unit_id
left join mes_product_plan mpp on mpp.plan_code = wpo.plan_code left join mes_sale_order mso on mso.sale_order_id = wpo.sale_order_id
left join mes_sale_order mso on mso.sale_order_id = mpp.sale_order_id
where wpo.outstock_type = '1' where wpo.outstock_type = '1'
and wpo.outstock_qty > 0 and wpo.outstock_qty > 0
and wpo.apply_qty >= wpo.outstock_qty and wpo.apply_qty >= wpo.outstock_qty

@ -38,6 +38,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="unitCode" column="unit_code" /> <result property="unitCode" column="unit_code" />
<result property="warehouseCode" column="warehouse_code" /> <result property="warehouseCode" column="warehouse_code" />
<result property="specificationParameter" column="specification_parameter" /> <result property="specificationParameter" column="specification_parameter" />
<result property="srcBillNo" column="src_bill_no" />
</resultMap> </resultMap>
<sql id="selectWmsRawInstockVo"> <sql id="selectWmsRawInstockVo">
@ -211,7 +212,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
wri.instock_type, wri.instock_type,
wri.material_id, wri.material_id,
wri.po_no, wri.po_no,
wri.purchase_order_id,
mpo.specification_parameter, mpo.specification_parameter,
mpo.src_bill_no,
mbmi.material_code, mbmi.material_code,
mbui.unit_code, mbui.unit_code,
wri.instock_amount, wri.instock_amount,
@ -221,13 +224,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
left join wms_base_warehouse wbw on wbw.warehouse_id = wri.warehouse_id left join wms_base_warehouse wbw on wbw.warehouse_id = wri.warehouse_id
left join mes_base_material_info mbmi on mbmi.material_id = wri.material_id left join mes_base_material_info mbmi on mbmi.material_id = wri.material_id
left join mes_base_unit_info mbui on mbui.erp_id = mbmi.material_unit_id left join mes_base_unit_info mbui on mbui.erp_id = mbmi.material_unit_id
join (select po_no, material_id, max(specification_parameter) specification_parameter left join mes_purchase_order mpo on wri.purchase_order_id = mpo.purchase_order_id
from mes_purchase_order
group by po_no, material_id) mpo on mpo.po_no = wri.po_no and mpo.material_id = wri.material_id
where wri.execute_status = 2 where wri.execute_status = 2
and (wri.erp_status != 1 or wri.erp_status is null) and (wri.erp_status != 1 or wri.erp_status is null)
and wri.instock_type in (1, 3) and wri.instock_type in (1, 3)
and wri.instock_amount > if(wri.erp_amount is null, 0, wri.erp_amount) and wri.instock_amount > if(wri.erp_amount is null, 0, wri.erp_amount)
and wri.purchase_order_id is not null and wri.purchase_order_id !=0
</select> </select>

@ -357,7 +357,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select wro.raw_outstock_id, select wro.raw_outstock_id,
wro.task_code, wro.task_code,
wro.warehouse_id, wro.warehouse_id,
wbw.warehouse_code,
wro.operation_type, wro.operation_type,
wro.material_id, wro.material_id,
mbmi.material_code, mbmi.material_code,
@ -369,7 +368,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
mso.price, mso.price,
mso.specification_parameter mso.specification_parameter
from wms_raw_outstock wro from wms_raw_outstock wro
left join wms_base_warehouse wbw on wbw.warehouse_id = wro.warehouse_id
left join mes_base_material_info mbmi on mbmi.material_id = wro.material_id left join mes_base_material_info mbmi on mbmi.material_id = wro.material_id
left join mes_base_unit_info mbui on mbui.erp_id = mbmi.material_unit_id left join mes_base_unit_info mbui on mbui.erp_id = mbmi.material_unit_id
left join mes_product_plan mpp on mpp.plan_code = wro.plan_code left join mes_product_plan mpp on mpp.plan_code = wro.plan_code

Loading…
Cancel
Save