|
|
@@ -232,6 +232,7 @@ public class InvwStocktakingInfoManagerImpl extends AbstractCommManager implemen |
|
|
|
stocktakingInfo.setCreateTime(startTime); |
|
|
|
stocktakingInfo.setType(1); |
|
|
|
stocktakingInfo.setOpenId(findOpenIdByToken(req.getAccessToken())); |
|
|
|
// stocktakingInfo.setOpenId("1"); |
|
|
|
stocktakingInfos.add(stocktakingInfo); |
|
|
|
} |
|
|
|
stocktakingInfoRepo.saveAll(stocktakingInfos); |
|
|
@@ -241,11 +242,10 @@ public class InvwStocktakingInfoManagerImpl extends AbstractCommManager implemen |
|
|
|
// 执行盘库 |
|
|
|
public void doStocktaking(List<InvwStocktakingInfoModel> infoModels, List<String> storeCodes) { |
|
|
|
// 使用并行流异步执行每个仓库的库存检查 |
|
|
|
logger.info("开始盘存"); |
|
|
|
storeCodes.parallelStream().forEach(storeCode -> { |
|
|
|
// asyncServiceExecutor.execute(() -> { |
|
|
|
try { |
|
|
|
logger.info("{} 开始盘存...", storeCode); |
|
|
|
|
|
|
|
// 查找对应的库存检查信息 |
|
|
|
InvwStocktakingInfoModel info = infoModels.stream() |
|
|
|
.filter(s -> storeCode.equals(s.getStoreCode())).findFirst() |
|
|
@@ -253,13 +253,12 @@ public class InvwStocktakingInfoManagerImpl extends AbstractCommManager implemen |
|
|
|
|
|
|
|
// 开始库存检查 |
|
|
|
startStocktakingByStoreCodes(info); |
|
|
|
|
|
|
|
logger.info("{} 盘存结束!!!", storeCode); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("在storeCodes {}盘存过程中发生错误", storeCodes, e); |
|
|
|
} |
|
|
|
// }); |
|
|
|
}); |
|
|
|
logger.info("盘存结束"); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@@ -275,14 +274,14 @@ public class InvwStocktakingInfoManagerImpl extends AbstractCommManager implemen |
|
|
|
} |
|
|
|
//期初 (上次最新的盘存记录) |
|
|
|
List<InvwStocktakingResultModel> bopStat = getBopStat(stocktakingInfo); |
|
|
|
//入库 (申请采购、调拨入库、回收入库) |
|
|
|
//入库 (申请入库、调拨入库、回收入库) |
|
|
|
List<InvwStocktakingResultModel> incomeStat = getInStat(storeCode, lastDoneTime, info.getStartTime(), mainId); |
|
|
|
//出库 (使用掉的、调拨出库、回收入库) |
|
|
|
//出库 (调拨出库、回收出库) |
|
|
|
List<InvwStocktakingResultModel> outStat = getOutStat(storeCode, lastDoneTime, info.getStartTime(), mainId); |
|
|
|
//实际结存 |
|
|
|
List<InvwStocktakingResultModel> realityStat = getRealityStat(storeCode, lastDoneTime, info.getStartTime(), mainId); |
|
|
|
// List<InvwStocktakingResultModel> realityStat = getRealityStat(storeCode, lastDoneTime, info.getStartTime(), mainId); |
|
|
|
//结存 |
|
|
|
List<InvwStocktakingResultModel> balanceStat = mergeResultList(bopStat, incomeStat, outStat, realityStat); |
|
|
|
List<InvwStocktakingResultModel> balanceStat = mergeResultList(bopStat, incomeStat, outStat); |
|
|
|
//更新库存信息表 |
|
|
|
updateStocktakingInfo(info, balanceStat); |
|
|
|
} catch (Exception e) { |
|
|
@@ -324,7 +323,7 @@ public class InvwStocktakingInfoManagerImpl extends AbstractCommManager implemen |
|
|
|
} |
|
|
|
|
|
|
|
private List<InvwStocktakingResultModel> getInStat(String storeCode, LocalDateTime lastDoneTime, LocalDateTime startTime, String mainId) { |
|
|
|
//申请采购、调拨入库、回收入库 |
|
|
|
//申请入库、调拨入库、回收入库 |
|
|
|
//新增入库数据 |
|
|
|
List<Object[]> initialWarehouse = null; |
|
|
|
if (lastDoneTime == null) { |
|
|
@@ -359,9 +358,6 @@ public class InvwStocktakingInfoManagerImpl extends AbstractCommManager implemen |
|
|
|
@SafeVarargs |
|
|
|
private List<InvwStocktakingResultModel> mergeInList(List<Object[]>... lists) { |
|
|
|
List<InvwStocktakingResultModel> result = new ArrayList<>(); |
|
|
|
if (lists.length <= 0) { |
|
|
|
return result; |
|
|
|
} |
|
|
|
List<InvwStocktakingResultModel> argList = new ArrayList<>(); |
|
|
|
for (List<Object[]> r : lists) { |
|
|
|
for (Object[] card : r) { |
|
|
@@ -406,9 +402,7 @@ public class InvwStocktakingInfoManagerImpl extends AbstractCommManager implemen |
|
|
|
resultModelMap.put(uniqueKey, inMap); |
|
|
|
}); |
|
|
|
//计算结果转成list |
|
|
|
resultModelMap.forEach((k, v) -> { |
|
|
|
result.add(v); |
|
|
|
}); |
|
|
|
result.addAll(resultModelMap.values()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
@@ -443,9 +437,6 @@ public class InvwStocktakingInfoManagerImpl extends AbstractCommManager implemen |
|
|
|
@SafeVarargs |
|
|
|
private List<InvwStocktakingResultModel> mergeOutList(List<Object[]>... lists) { |
|
|
|
List<InvwStocktakingResultModel> result = new ArrayList<>(); |
|
|
|
if (lists.length <= 0) { |
|
|
|
return result; |
|
|
|
} |
|
|
|
List<InvwStocktakingResultModel> argList = new ArrayList<>(); |
|
|
|
for (List<Object[]> r : lists) { |
|
|
|
for (Object[] card : r) { |
|
|
@@ -490,9 +481,7 @@ public class InvwStocktakingInfoManagerImpl extends AbstractCommManager implemen |
|
|
|
resultModelMap.put(uniqueKey, inMap); |
|
|
|
}); |
|
|
|
//计算结果转成list |
|
|
|
resultModelMap.forEach((k, v) -> { |
|
|
|
result.add(v); |
|
|
|
}); |
|
|
|
result.addAll(resultModelMap.values()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
@@ -579,9 +568,7 @@ public class InvwStocktakingInfoManagerImpl extends AbstractCommManager implemen |
|
|
|
resultModelMap.put(uniqueKey, inMap); |
|
|
|
}); |
|
|
|
//计算结果转成list |
|
|
|
resultModelMap.forEach((k, v) -> { |
|
|
|
result.add(v); |
|
|
|
}); |
|
|
|
result.addAll(resultModelMap.values()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
@@ -589,7 +576,7 @@ public class InvwStocktakingInfoManagerImpl extends AbstractCommManager implemen |
|
|
|
|
|
|
|
List<InvwStocktakingInfo> lastInfo = stocktakingInfoRepo.findFirstByStoreCode(model.getStoreCode()); |
|
|
|
if (CollectionUtil.isEmpty(lastInfo)) { |
|
|
|
logger.error("{} 更新盘存记录状态失败,没有此盘存记录 id={}", model.getStoreCode(), model.getId()); |
|
|
|
logger.error("{} 盘存失败,没有此盘存记录 id={}", model.getStoreCode(), model.getId()); |
|
|
|
} else { |
|
|
|
LocalDateTime finishTime = LocalDateTime.now(); //完成时间 |
|
|
|
InvwStocktakingInfo stocktakingInfo = ConvertUtils.sourceToTarget(lastInfo.get(0), InvwStocktakingInfo.class); |
|
|
@@ -607,7 +594,7 @@ public class InvwStocktakingInfoManagerImpl extends AbstractCommManager implemen |
|
|
|
}); |
|
|
|
stocktakingResultRepo.saveAll(stocktakingResults); |
|
|
|
} |
|
|
|
logger.info("{} 更新盘存记录状态成功,id={}", model.getStoreCode(), model.getId()); |
|
|
|
logger.info("{} 盘存完成,id={}", model.getStoreCode(), model.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |