Bläddra i källkod

盘存、调拨修改

master
yangpeilai 3 månader sedan
förälder
incheckning
fa9c423269

+ 13
- 26
zhywpt-app-invw/src/main/java/cn/com/taiji/invw/manager/stocktaking/InvwStocktakingInfoManagerImpl.java Visa fil

stocktakingInfo.setCreateTime(startTime); stocktakingInfo.setCreateTime(startTime);
stocktakingInfo.setType(1); stocktakingInfo.setType(1);
stocktakingInfo.setOpenId(findOpenIdByToken(req.getAccessToken())); stocktakingInfo.setOpenId(findOpenIdByToken(req.getAccessToken()));
// stocktakingInfo.setOpenId("1");
stocktakingInfos.add(stocktakingInfo); stocktakingInfos.add(stocktakingInfo);
} }
stocktakingInfoRepo.saveAll(stocktakingInfos); stocktakingInfoRepo.saveAll(stocktakingInfos);
// 执行盘库 // 执行盘库
public void doStocktaking(List<InvwStocktakingInfoModel> infoModels, List<String> storeCodes) { public void doStocktaking(List<InvwStocktakingInfoModel> infoModels, List<String> storeCodes) {
// 使用并行流异步执行每个仓库的库存检查 // 使用并行流异步执行每个仓库的库存检查
logger.info("开始盘存");
storeCodes.parallelStream().forEach(storeCode -> { storeCodes.parallelStream().forEach(storeCode -> {
// asyncServiceExecutor.execute(() -> { // asyncServiceExecutor.execute(() -> {
try { try {
logger.info("{} 开始盘存...", storeCode);

// 查找对应的库存检查信息 // 查找对应的库存检查信息
InvwStocktakingInfoModel info = infoModels.stream() InvwStocktakingInfoModel info = infoModels.stream()
.filter(s -> storeCode.equals(s.getStoreCode())).findFirst() .filter(s -> storeCode.equals(s.getStoreCode())).findFirst()


// 开始库存检查 // 开始库存检查
startStocktakingByStoreCodes(info); startStocktakingByStoreCodes(info);

logger.info("{} 盘存结束!!!", storeCode);
} catch (Exception e) { } catch (Exception e) {
logger.error("在storeCodes {}盘存过程中发生错误", storeCodes, e); logger.error("在storeCodes {}盘存过程中发生错误", storeCodes, e);
} }
// }); // });
}); });
logger.info("盘存结束");
} }


@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
} }
//期初 (上次最新的盘存记录) //期初 (上次最新的盘存记录)
List<InvwStocktakingResultModel> bopStat = getBopStat(stocktakingInfo); List<InvwStocktakingResultModel> bopStat = getBopStat(stocktakingInfo);
//入库 (申请采购、调拨入库、回收入库)
//入库 (申请入库、调拨入库、回收入库)
List<InvwStocktakingResultModel> incomeStat = getInStat(storeCode, lastDoneTime, info.getStartTime(), mainId); List<InvwStocktakingResultModel> incomeStat = getInStat(storeCode, lastDoneTime, info.getStartTime(), mainId);
//出库 (使用掉的、调拨出库、回收入库)
//出库 (调拨出库、回收出库)
List<InvwStocktakingResultModel> outStat = getOutStat(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); updateStocktakingInfo(info, balanceStat);
} catch (Exception e) { } catch (Exception e) {
} }


private List<InvwStocktakingResultModel> getInStat(String storeCode, LocalDateTime lastDoneTime, LocalDateTime startTime, String mainId) { private List<InvwStocktakingResultModel> getInStat(String storeCode, LocalDateTime lastDoneTime, LocalDateTime startTime, String mainId) {
//申请采购、调拨入库、回收入库
//申请入库、调拨入库、回收入库
//新增入库数据 //新增入库数据
List<Object[]> initialWarehouse = null; List<Object[]> initialWarehouse = null;
if (lastDoneTime == null) { if (lastDoneTime == null) {
@SafeVarargs @SafeVarargs
private List<InvwStocktakingResultModel> mergeInList(List<Object[]>... lists) { private List<InvwStocktakingResultModel> mergeInList(List<Object[]>... lists) {
List<InvwStocktakingResultModel> result = new ArrayList<>(); List<InvwStocktakingResultModel> result = new ArrayList<>();
if (lists.length <= 0) {
return result;
}
List<InvwStocktakingResultModel> argList = new ArrayList<>(); List<InvwStocktakingResultModel> argList = new ArrayList<>();
for (List<Object[]> r : lists) { for (List<Object[]> r : lists) {
for (Object[] card : r) { for (Object[] card : r) {
resultModelMap.put(uniqueKey, inMap); resultModelMap.put(uniqueKey, inMap);
}); });
//计算结果转成list //计算结果转成list
resultModelMap.forEach((k, v) -> {
result.add(v);
});
result.addAll(resultModelMap.values());
return result; return result;
} }


@SafeVarargs @SafeVarargs
private List<InvwStocktakingResultModel> mergeOutList(List<Object[]>... lists) { private List<InvwStocktakingResultModel> mergeOutList(List<Object[]>... lists) {
List<InvwStocktakingResultModel> result = new ArrayList<>(); List<InvwStocktakingResultModel> result = new ArrayList<>();
if (lists.length <= 0) {
return result;
}
List<InvwStocktakingResultModel> argList = new ArrayList<>(); List<InvwStocktakingResultModel> argList = new ArrayList<>();
for (List<Object[]> r : lists) { for (List<Object[]> r : lists) {
for (Object[] card : r) { for (Object[] card : r) {
resultModelMap.put(uniqueKey, inMap); resultModelMap.put(uniqueKey, inMap);
}); });
//计算结果转成list //计算结果转成list
resultModelMap.forEach((k, v) -> {
result.add(v);
});
result.addAll(resultModelMap.values());
return result; return result;
} }


resultModelMap.put(uniqueKey, inMap); resultModelMap.put(uniqueKey, inMap);
}); });
//计算结果转成list //计算结果转成list
resultModelMap.forEach((k, v) -> {
result.add(v);
});
result.addAll(resultModelMap.values());
return result; return result;
} }




List<InvwStocktakingInfo> lastInfo = stocktakingInfoRepo.findFirstByStoreCode(model.getStoreCode()); List<InvwStocktakingInfo> lastInfo = stocktakingInfoRepo.findFirstByStoreCode(model.getStoreCode());
if (CollectionUtil.isEmpty(lastInfo)) { if (CollectionUtil.isEmpty(lastInfo)) {
logger.error("{} 更新盘存记录状态失败,没有此盘存记录 id={}", model.getStoreCode(), model.getId());
logger.error("{} 盘存失败,没有此盘存记录 id={}", model.getStoreCode(), model.getId());
} else { } else {
LocalDateTime finishTime = LocalDateTime.now(); //完成时间 LocalDateTime finishTime = LocalDateTime.now(); //完成时间
InvwStocktakingInfo stocktakingInfo = ConvertUtils.sourceToTarget(lastInfo.get(0), InvwStocktakingInfo.class); InvwStocktakingInfo stocktakingInfo = ConvertUtils.sourceToTarget(lastInfo.get(0), InvwStocktakingInfo.class);
}); });
stocktakingResultRepo.saveAll(stocktakingResults); stocktakingResultRepo.saveAll(stocktakingResults);
} }
logger.info("{} 更新盘存记录状态成功,id={}", model.getStoreCode(), model.getId());
logger.info("{} 盘存完成,id={}", model.getStoreCode(), model.getId());
} }


@Override @Override

+ 5
- 5
zhywpt-app-invw/src/main/java/cn/com/taiji/invw/manager/transfer/InvwTransferApplyManagerImpl.java Visa fil

if (applyDetails.size() == 0) { if (applyDetails.size() == 0) {
throw new ManagerException("调拨申请无明细"); throw new ManagerException("调拨申请无明细");
} }
InvwWarehouse receiveWarehouse = warehouseRepo.findById(transferApply.getReceiveStoreCode()).orElse(null);
InvwWarehouse receiveWarehouse = warehouseRepo.findByCode(transferApply.getReceiveStoreCode());
if (receiveWarehouse == null) { if (receiveWarehouse == null) {
throw new ManagerException("调拨申请接收仓库不存在"); throw new ManagerException("调拨申请接收仓库不存在");
} }
setupTransfer(transferApply, transferApplyModel); setupTransfer(transferApply, transferApplyModel);


//查询发货仓库信息 //查询发货仓库信息
InvwWarehouse sendAgency = warehouseRepo.findById(transferApplyModel.getSendStoreCode()).orElse(null);
InvwWarehouse sendAgency = warehouseRepo.findByCode(transferApplyModel.getSendStoreCode());
if(sendAgency == null) { if(sendAgency == null) {
throw new ManagerException("调拨申请失败,请检查发货仓库是否正确"); throw new ManagerException("调拨申请失败,请检查发货仓库是否正确");
} }
//查询收货仓库信息 //查询收货仓库信息
InvwWarehouse receiveAgency = warehouseRepo.findById(transferApplyModel.getReceiveStoreCode()).orElse(null);
InvwWarehouse receiveAgency = warehouseRepo.findByCode(transferApplyModel.getReceiveStoreCode());
if(receiveAgency == null) { if(receiveAgency == null) {
throw new ManagerException("调拨申请失败,请检查收货仓库是否正确"); throw new ManagerException("调拨申请失败,请检查收货仓库是否正确");
} }
// 设置申请单详情 // 设置申请单详情
private void setupTransferApplyDetails(InvwTransferApply transferApply, InvwTransferApplyCommModel transferApplyModel) throws ManagerException { private void setupTransferApplyDetails(InvwTransferApply transferApply, InvwTransferApplyCommModel transferApplyModel) throws ManagerException {
//查询发货仓库信息 //查询发货仓库信息
InvwWarehouse sendAgency = warehouseRepo.findById(transferApplyModel.getSendStoreCode()).orElse(null);
InvwWarehouse sendAgency = warehouseRepo.findByCode(transferApplyModel.getSendStoreCode());
if(sendAgency == null) { if(sendAgency == null) {
throw new ManagerException("调拨申请失败,请检查发货仓库是否正确"); throw new ManagerException("调拨申请失败,请检查发货仓库是否正确");
} }
//查询收货仓库信息 //查询收货仓库信息
InvwWarehouse receiveAgency = warehouseRepo.findById(transferApplyModel.getReceiveStoreCode()).orElse(null);
InvwWarehouse receiveAgency = warehouseRepo.findByCode(transferApplyModel.getReceiveStoreCode());
if(receiveAgency == null) { if(receiveAgency == null) {
throw new ManagerException("调拨申请失败,请检查收货仓库是否正确"); throw new ManagerException("调拨申请失败,请检查收货仓库是否正确");
} }

Laddar…
Avbryt
Spara