Browse Source

盘存修改

master
yangpeilai 3 months ago
parent
commit
c9dd859126

+ 36
- 32
zhywpt-app-invw/src/main/java/cn/com/taiji/invw/manager/stocktaking/InvwStocktakingInfoManagerImpl.java View File

List<InvwStocktakingInfoStockModel> stockModels = req.getStockModels(); List<InvwStocktakingInfoStockModel> stockModels = req.getStockModels();
List<String> storeCodes = new ArrayList<>(); List<String> storeCodes = new ArrayList<>();


if (stockModels != null || stockModels.size() == 0) {
if (stockModels == null || stockModels.size() == 0) {
stockModels = new ArrayList<>(); stockModels = new ArrayList<>();
// 查询仓库 // 查询仓库
List<InvwWarehouse> warehouses = warehouseRepo.findAllByStatus(1); List<InvwWarehouse> warehouses = warehouseRepo.findAllByStatus(1);
stocktakingInfo.setStartTime(startTime); stocktakingInfo.setStartTime(startTime);
stocktakingInfo.setCreateTime(startTime); stocktakingInfo.setCreateTime(startTime);
stocktakingInfo.setType(1); stocktakingInfo.setType(1);
stocktakingInfo.setOpenId(findOpenIdByToken(req.getAccessToken()));
// stocktakingInfo.setOpenId("1");
// stocktakingInfo.setOpenId(findOpenIdByToken(req.getAccessToken()));
stocktakingInfo.setOpenId("1");
stocktakingInfos.add(stocktakingInfo); stocktakingInfos.add(stocktakingInfo);
} }
stocktakingInfoRepo.saveAll(stocktakingInfos); stocktakingInfoRepo.saveAll(stocktakingInfos);
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);
List<InvwStocktakingResultModel> balanceStat = mergeResultList(bopStat, incomeStat, outStat, realityStat);
//更新库存信息表 //更新库存信息表
updateStocktakingInfo(info, balanceStat); updateStocktakingInfo(info, balanceStat);
} catch (Exception e) { } catch (Exception e) {
inMap.setInitCount(NumberUtil.add(inMap.getInitCount(), model.getInitCount()).intValue()); inMap.setInitCount(NumberUtil.add(inMap.getInitCount(), model.getInitCount()).intValue());
} }
//入库 //入库
if (NumberUtil.add(inMap.getEnterCount(), model.getEnterCount()) != null) {
inMap.setEnterCount(NumberUtil.add(inMap.getEnterCount(), model.getEnterCount()).intValue());
}
// if (NumberUtil.add(inMap.getEnterCount(), model.getEnterCount()) != null) {
// inMap.setEnterCount(NumberUtil.add(inMap.getEnterCount(), model.getEnterCount()).intValue());
// }
//出库 //出库
if (NumberUtil.add(inMap.getTransferCount(), model.getTransferCount()) != null) {
inMap.setTransferCount(NumberUtil.add(inMap.getTransferCount(), model.getTransferCount()).intValue());
}
// if (NumberUtil.add(inMap.getTransferCount(), model.getTransferCount()) != null) {
// inMap.setTransferCount(NumberUtil.add(inMap.getTransferCount(), model.getTransferCount()).intValue());
// }
//结存 = 期初 + 入库 - 出库 //结存 = 期初 + 入库 - 出库
BigDecimal balanceCount = NumberUtil.sub(NumberUtil.add(inMap.getInitCount(), inMap.getEnterCount()), inMap.getTransferCount());
inMap.setBalanceCount(balanceCount.intValue());
// BigDecimal balanceCount = NumberUtil.sub(NumberUtil.add(inMap.getInitCount(), inMap.getEnterCount()), inMap.getTransferCount());
// inMap.setBalanceCount(balanceCount.intValue());
resultModelMap.put(uniqueKey, inMap); resultModelMap.put(uniqueKey, inMap);
}); });
//计算结果转成list //计算结果转成list
inMap.setVersion(model.getVersion()); inMap.setVersion(model.getVersion());


//期初 //期初
if (NumberUtil.add(inMap.getInitCount(), model.getInitCount()) != null) {
inMap.setInitCount(NumberUtil.add(inMap.getInitCount(), model.getInitCount()).intValue());
}
// if (NumberUtil.add(inMap.getInitCount(), model.getInitCount()) != null) {
// inMap.setInitCount(NumberUtil.add(inMap.getInitCount(), model.getInitCount()).intValue());
// }
//入库 //入库
if (NumberUtil.add(inMap.getEnterCount(), model.getEnterCount()) != null) {
inMap.setEnterCount(NumberUtil.add(inMap.getEnterCount(), model.getEnterCount()).intValue());
}
// if (NumberUtil.add(inMap.getEnterCount(), model.getEnterCount()) != null) {
// inMap.setEnterCount(NumberUtil.add(inMap.getEnterCount(), model.getEnterCount()).intValue());
// }
//出库 //出库
if (NumberUtil.add(inMap.getTransferCount(), model.getTransferCount()) != null) { if (NumberUtil.add(inMap.getTransferCount(), model.getTransferCount()) != null) {
inMap.setTransferCount(NumberUtil.add(inMap.getTransferCount(), model.getTransferCount()).intValue()); inMap.setTransferCount(NumberUtil.add(inMap.getTransferCount(), model.getTransferCount()).intValue());
} }
//结存 = 期初 + 入库 - 出库 //结存 = 期初 + 入库 - 出库
BigDecimal balanceCount = NumberUtil.sub(NumberUtil.add(inMap.getInitCount(), inMap.getEnterCount()), inMap.getTransferCount());
inMap.setBalanceCount(balanceCount.intValue());
// BigDecimal balanceCount = NumberUtil.sub(NumberUtil.add(inMap.getInitCount(), inMap.getEnterCount()), inMap.getTransferCount());
// inMap.setBalanceCount(balanceCount.intValue());
resultModelMap.put(uniqueKey, inMap); resultModelMap.put(uniqueKey, inMap);
}); });
//计算结果转成list //计算结果转成list


private List<InvwStocktakingResultModel> getRealityStat(String storeCode, LocalDateTime lastDoneTime, LocalDateTime startTime, String mainId) { private List<InvwStocktakingResultModel> getRealityStat(String storeCode, LocalDateTime lastDoneTime, LocalDateTime startTime, String mainId) {
List<InvwStocktakingResultModel> result = new ArrayList<>(); List<InvwStocktakingResultModel> result = new ArrayList<>();
//查询卡签实际库存
//查询卡签实际非在库库存
List<Object[]> cardDetails = null; List<Object[]> cardDetails = null;
List<Object[]> obuDetails = null; List<Object[]> obuDetails = null;
if (lastDoneTime == null) {
// if (lastDoneTime == null) {
cardDetails = cardDetailsRepo.countByStoreCodeAndTime(storeCode, startTime.format(DF)); cardDetails = cardDetailsRepo.countByStoreCodeAndTime(storeCode, startTime.format(DF));
obuDetails = obuDetailsRepo.countByStoreCodeAndTime(storeCode, startTime.format(DF)); obuDetails = obuDetailsRepo.countByStoreCodeAndTime(storeCode, startTime.format(DF));
} else {
cardDetails = cardDetailsRepo.countByStoreCodeAndTime(storeCode, lastDoneTime.format(DF), startTime.format(DF));
obuDetails = obuDetailsRepo.countByStoreCodeAndTime(storeCode, lastDoneTime.format(DF), startTime.format(DF));
}
// } else {
// cardDetails = cardDetailsRepo.countByStoreCodeAndTime(storeCode, lastDoneTime.format(DF), startTime.format(DF));
// obuDetails = obuDetailsRepo.countByStoreCodeAndTime(storeCode, lastDoneTime.format(DF), startTime.format(DF));
// }


if (CollectionUtil.isNotEmpty(cardDetails)) { if (CollectionUtil.isNotEmpty(cardDetails)) {
for (Object[] card : cardDetails) { for (Object[] card : cardDetails) {
l.setBrand(card[2] + ""); l.setBrand(card[2] + "");
l.setInventoryType(InventoryType.CARD); l.setInventoryType(InventoryType.CARD);
l.setVersion(card[3] == null ? null : DeviceVersion.valueOf(card[3] + "")); l.setVersion(card[3] == null ? null : DeviceVersion.valueOf(card[3] + ""));
l.setTransferCount(card[4] == null ? 0 : Integer.parseInt(card[4] + ""));
l.setBalanceCount(card[4] == null ? 0 : Integer.parseInt(card[4] + ""));
result.add(l); result.add(l);
} }
} }
l.setBrand(obu[2] + ""); l.setBrand(obu[2] + "");
l.setInventoryType(InventoryType.OBU); l.setInventoryType(InventoryType.OBU);
l.setVersion(obu[3] == null ? null : DeviceVersion.valueOf(obu[3] + "")); l.setVersion(obu[3] == null ? null : DeviceVersion.valueOf(obu[3] + ""));
l.setTransferCount(obu[4] == null ? 0 : Integer.parseInt(obu[4] + ""));
l.setBalanceCount(obu[4] == null ? 0 : Integer.parseInt(obu[4] + ""));
result.add(l); result.add(l);
} }
} }
if (NumberUtil.add(inMap.getTransferCount(), model.getTransferCount()) != null) { if (NumberUtil.add(inMap.getTransferCount(), model.getTransferCount()) != null) {
inMap.setTransferCount(NumberUtil.add(inMap.getTransferCount(), model.getTransferCount()).intValue()); inMap.setTransferCount(NumberUtil.add(inMap.getTransferCount(), model.getTransferCount()).intValue());
} }
//结存
if (NumberUtil.add(inMap.getBalanceCount(), model.getBalanceCount()) != null) {
inMap.setBalanceCount(NumberUtil.add(inMap.getBalanceCount(), model.getBalanceCount()).intValue());
}
//结存 = 期初 + 入库 - 出库 //结存 = 期初 + 入库 - 出库
BigDecimal balanceCount = NumberUtil.sub(NumberUtil.add(inMap.getInitCount(), inMap.getEnterCount()), inMap.getTransferCount());
inMap.setBalanceCount(balanceCount.intValue());
// BigDecimal balanceCount = NumberUtil.sub(NumberUtil.add(inMap.getInitCount(), inMap.getEnterCount()), inMap.getTransferCount());
// inMap.setBalanceCount(balanceCount.intValue());
resultModelMap.put(uniqueKey, inMap); resultModelMap.put(uniqueKey, inMap);
}); });
//计算结果转成list //计算结果转成list

Loading…
Cancel
Save