|
|
@ -6,8 +6,12 @@ import com.hw.common.core.domain.R;
|
|
|
|
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;
|
|
|
|
|
|
|
|
import com.hw.wms.domain.WmsProductInstock;
|
|
|
|
|
|
|
|
import com.hw.wms.domain.WmsProductOutstock;
|
|
|
|
import com.hw.wms.domain.WmsRawInstock;
|
|
|
|
import com.hw.wms.domain.WmsRawInstock;
|
|
|
|
import com.hw.wms.domain.WmsRawOutstock;
|
|
|
|
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.WmsRawInstockMapper;
|
|
|
|
import com.hw.wms.mapper.WmsRawOutstockMapper;
|
|
|
|
import com.hw.wms.mapper.WmsRawOutstockMapper;
|
|
|
|
import com.hw.wms.service.IWmsErpScheduledTaskService;
|
|
|
|
import com.hw.wms.service.IWmsErpScheduledTaskService;
|
|
|
@ -18,8 +22,9 @@ import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -39,6 +44,12 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private WmsRawOutstockMapper wmsRawOutstockMapper;
|
|
|
|
private WmsRawOutstockMapper wmsRawOutstockMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private WmsProductInstockMapper wmsProductInstockMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private WmsProductOutstockMapper wmsProductOutstockMapper;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private RemoteJindieService remoteJindieService;
|
|
|
|
private RemoteJindieService remoteJindieService;
|
|
|
|
|
|
|
|
|
|
|
@ -96,6 +107,7 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 定时同步原材料出库信息给ERP
|
|
|
|
* 定时同步原材料出库信息给ERP
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -144,7 +156,134 @@ public class WmsErpScheduledTaskServiceImpl implements IWmsErpScheduledTaskServi
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
log.error("synchronizeRawMaterialDeliveryInformationToERP失败:" + paramsResult.toString());
|
|
|
|
log.error("synchronizeRawMaterialDeliveryInformationToERP失败:" + paramsResult.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 定时同步成品入库信息给ERP
|
|
|
|
|
|
|
|
* @param days 同步days天前数据
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public int synchronizeProductInstockInformationToERP(Integer days) {
|
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
WmsProductInstock wmsProductInstock = new WmsProductInstock();
|
|
|
|
|
|
|
|
HashMap<String, Object> paramMap = new HashMap<>();
|
|
|
|
|
|
|
|
String beginTime= subtractDaysFromCurrentDate(days);
|
|
|
|
|
|
|
|
paramMap.put("beginTime", beginTime);
|
|
|
|
|
|
|
|
paramMap.put("endTime", DateUtils.getTime());
|
|
|
|
|
|
|
|
wmsProductInstock.setParams(paramMap);
|
|
|
|
|
|
|
|
List<WmsProductInstock> productInstockList = wmsProductInstockMapper.selectWmsProductInstockERPNotSynchronized(wmsProductInstock);
|
|
|
|
|
|
|
|
Map<Long, List<WmsProductInstock>> productIdMap = productInstockList.stream().collect(Collectors.groupingBy(WmsProductInstock::getProductId));
|
|
|
|
|
|
|
|
for (Long productId : productIdMap.keySet()) {
|
|
|
|
|
|
|
|
syncProductInstockInformation(productIdMap, productId, result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
|
|
|
|
|
|
|
void syncProductInstockInformation(Map<Long, List<WmsProductInstock>> productIdMap, Long productId, int result) {
|
|
|
|
|
|
|
|
List<WmsProductInstock> wmsProductInstockList = productIdMap.get(productId);
|
|
|
|
|
|
|
|
JSONObject data = new JSONObject();
|
|
|
|
|
|
|
|
double FRealQty = wmsProductInstockList.stream().mapToDouble(item -> item.getInstockAmount().subtract(item.getErpAmount()).doubleValue()).sum();
|
|
|
|
|
|
|
|
WmsProductInstock instock = wmsProductInstockList.get(0);
|
|
|
|
|
|
|
|
data.put("FDate", DateUtils.getTime());
|
|
|
|
|
|
|
|
data.put("FMaterialId", instock.getMaterialCode());
|
|
|
|
|
|
|
|
data.put("FAuxPropId", instock.getSpecificationParameter());
|
|
|
|
|
|
|
|
data.put("FUnitID", instock.getUnitCode());
|
|
|
|
|
|
|
|
data.put("FQty", FRealQty);
|
|
|
|
|
|
|
|
data.put("FPrice", instock.getPrice());
|
|
|
|
|
|
|
|
data.put("FStockId", FStockId);
|
|
|
|
|
|
|
|
String params = data.toJSONString();
|
|
|
|
|
|
|
|
R<AjaxResult> paramsResult = remoteJindieService.saveOtherInStorage(params, SecurityConstants.INNER);
|
|
|
|
|
|
|
|
String paramsResultData = paramsResult.getMsg();
|
|
|
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(paramsResultData);
|
|
|
|
|
|
|
|
Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess");
|
|
|
|
|
|
|
|
if (isSuccess) {
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.error("synchronizeProductInstockInformationToERP失败:" + paramsResult.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 定时同步成品出库信息给ERP
|
|
|
|
|
|
|
|
* @param days 同步days天前数据
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public int synchronizeProductOutstockInformationToERP(Integer days) {
|
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
WmsProductOutstock wmsProductOutstock = new WmsProductOutstock();
|
|
|
|
|
|
|
|
HashMap<String, Object> paramMap = new HashMap<>();
|
|
|
|
|
|
|
|
String beginTime= subtractDaysFromCurrentDate(days);
|
|
|
|
|
|
|
|
paramMap.put("beginTime", beginTime);
|
|
|
|
|
|
|
|
paramMap.put("endTime", DateUtils.getTime());
|
|
|
|
|
|
|
|
wmsProductOutstock.setParams(paramMap);
|
|
|
|
|
|
|
|
List<WmsProductOutstock> productOutstockList = wmsProductOutstockMapper.selectWmsProductOutstockERPNotSynchronized(wmsProductOutstock);
|
|
|
|
|
|
|
|
Map<Long, List<WmsProductOutstock>> productIdMap = productOutstockList.stream().collect(Collectors.groupingBy(WmsProductOutstock::getProductId));
|
|
|
|
|
|
|
|
for (Long productId : productIdMap.keySet()) {
|
|
|
|
|
|
|
|
syncProductOutstockInformation(productIdMap, productId, result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
|
|
|
|
|
|
|
void syncProductOutstockInformation(Map<Long, List<WmsProductOutstock>> productIdMap, Long productId, int result) {
|
|
|
|
|
|
|
|
List<WmsProductOutstock> wmsProductOutstockList = productIdMap.get(productId);
|
|
|
|
|
|
|
|
JSONObject data = new JSONObject();
|
|
|
|
|
|
|
|
double FRealQty = wmsProductOutstockList.stream().mapToDouble(item -> item.getOutstockQty().subtract(item.getErpAmount()).doubleValue()).sum();
|
|
|
|
|
|
|
|
WmsProductOutstock outstock = wmsProductOutstockList.get(0);
|
|
|
|
|
|
|
|
data.put("FDate", DateUtils.getTime());
|
|
|
|
|
|
|
|
data.put("FMaterialId", outstock.getMaterialCode());
|
|
|
|
|
|
|
|
data.put("FAuxPropId", outstock.getSpecificationParameter());
|
|
|
|
|
|
|
|
data.put("FUnitID", outstock.getUnitCode());
|
|
|
|
|
|
|
|
data.put("FQty", FRealQty);
|
|
|
|
|
|
|
|
data.put("FPrice", outstock.getPrice());
|
|
|
|
|
|
|
|
data.put("FStockId", FStockId);
|
|
|
|
|
|
|
|
String params = data.toJSONString();
|
|
|
|
|
|
|
|
R<AjaxResult> paramsResult = remoteJindieService.saveOtherOutStorage(params, SecurityConstants.INNER);
|
|
|
|
|
|
|
|
String paramsResultData = paramsResult.getMsg();
|
|
|
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(paramsResultData);
|
|
|
|
|
|
|
|
Boolean isSuccess = (Boolean) jsonObject.get("IsSuccess");
|
|
|
|
|
|
|
|
if (isSuccess) {
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.error("synchronizeProductOutstockInformationToERP失败:" + paramsResult.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 从当前日期减去指定的天数,并返回结果日期(字符串格式,包括时分秒)
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param daysToSubtract 要减去的天数(如果为空,则默认为 180 天)
|
|
|
|
|
|
|
|
* @return 减去指定天数后的日期(字符串格式,包括时分秒)
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static String subtractDaysFromCurrentDate(Integer daysToSubtract) {
|
|
|
|
|
|
|
|
// 如果 daysToSubtract 为空,则默认为 180 天
|
|
|
|
|
|
|
|
daysToSubtract = Optional.ofNullable(daysToSubtract).orElse(180);
|
|
|
|
|
|
|
|
// 获取当前日期时间
|
|
|
|
|
|
|
|
LocalDateTime currentDateTime = LocalDateTime.now();
|
|
|
|
|
|
|
|
// 减去指定的天数
|
|
|
|
|
|
|
|
LocalDateTime resultDateTime = currentDateTime.minusDays(daysToSubtract);
|
|
|
|
|
|
|
|
// 定义日期时间格式
|
|
|
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
// 格式化结果日期时间
|
|
|
|
|
|
|
|
return resultDateTime.format(formatter);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|