change - 采购申请单多物料上传ERP逻辑优化

master
yinq 4 months ago
parent 8a643eb67a
commit cf5583f3b6

@ -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;
/**
* erpService
*
* @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<WmsRawInstock> inStockList = wmsRawInstockMapper.selectWmsRawInstockERPNotSynchronized(wmsRawInstock);
Map<Long, List<WmsRawInstock>> materialIdMap = inStockList.stream().collect(Collectors.groupingBy(WmsRawInstock::getMaterialId));
for (Long materialId : materialIdMap.keySet()) {
List<WmsRawInstock> 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<AjaxResult> 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;
}
}

@ -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;
/**
* erpService
*
* @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<WmsRawInstock> inStockList = wmsRawInstockMapper.selectWmsRawInstockERPNotSynchronized(wmsRawInstock);
Map<Long, List<WmsRawInstock>> 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<Long, List<WmsRawInstock>> materialIdMap, Long materialId, int result) {
List<WmsRawInstock> 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<AjaxResult> 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());
}
}
}
Loading…
Cancel
Save