|
@@ -275,11 +275,73 @@ public class BizTakeStockPeriodController extends BaseController
|
|
bizTaksStockStorageRetrievalService.saveBatch(needAddList);
|
|
bizTaksStockStorageRetrievalService.saveBatch(needAddList);
|
|
}
|
|
}
|
|
//盘点入库信息表
|
|
//盘点入库信息表
|
|
|
|
+ //拿到所有部分入库的入库单信息
|
|
List<BizTaksStockInboundOrderDetail> taskStockList = bizInboundOrderDetailService.getTaskStockList();
|
|
List<BizTaksStockInboundOrderDetail> taskStockList = bizInboundOrderDetailService.getTaskStockList();
|
|
if(taskStockList.size()>0) {
|
|
if(taskStockList.size()>0) {
|
|
|
|
+
|
|
|
|
+ //获取所有批次的id
|
|
List<Long> lotIds = taskStockList.stream().map(BizTaksStockInboundOrderDetail::getLotId).distinct().collect(Collectors.toList());
|
|
List<Long> lotIds = taskStockList.stream().map(BizTaksStockInboundOrderDetail::getLotId).distinct().collect(Collectors.toList());
|
|
|
|
+ //根据批次id查询到对应批次的零存或领取信息
|
|
|
|
+ List<BizStorageRetrieval> storageRetrievalList = bizStorageRetrievalService.query().in("lot_id", lotIds).or().in("retrieval_lotId", lotIds).list();
|
|
|
|
+ //根据批次id查询到对应批次已经上架的入库单信息
|
|
|
|
+ List<BizInboundOrderDetail> inboundOrderDetailList = bizInboundOrderDetailService.query().in("lot_id", lotIds).eq("is_inbound", 1).list();
|
|
|
|
+ //根据批次id查询到对应批次的盘点批次信息
|
|
|
|
+ List<BizTaksStockLot> filteredList = list.stream().filter(item -> lotIds.contains(item.getLotId())).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ // 创建映射,计算每个批次的零存数量
|
|
|
|
+ Map<Long, Long> storageNumByLotId = storageRetrievalList.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
|
+ BizStorageRetrieval::getLotId,
|
|
|
|
+ Collectors.summingLong(BizStorageRetrieval::getStorageNum)
|
|
|
|
+ ));
|
|
|
|
+
|
|
|
|
+ // 创建映射,计算每个批次的领取数量
|
|
|
|
+ Map<Long, Long> storageNumByRetrievalLotId = storageRetrievalList.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
|
+ BizStorageRetrieval::getRetrievalLotId,
|
|
|
|
+ Collectors.summingLong(BizStorageRetrieval::getStorageNum)
|
|
|
|
+ ));
|
|
|
|
+
|
|
|
|
+ // 创建映射,计算每个批次的入库数量
|
|
|
|
+ Map<Long, Long> inboundNumByLotId = inboundOrderDetailList.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
|
+ BizInboundOrderDetail::getLotId,
|
|
|
|
+ Collectors.summingLong(BizInboundOrderDetail::getInboundNum)
|
|
|
|
+ ));
|
|
|
|
+
|
|
|
|
+ // 已经全部上架的批次id
|
|
|
|
+ List<Long> endIds=new ArrayList<>();
|
|
|
|
+ for (BizTaksStockLot item : filteredList) {
|
|
|
|
+ //拿到当前批次的盘点数量
|
|
|
|
+ long resultNum = item.getProdNum();
|
|
|
|
+
|
|
|
|
+ // 减去零存数量
|
|
|
|
+ resultNum -= storageNumByLotId.getOrDefault(item.getLotId(), 0L);
|
|
|
|
+
|
|
|
|
+ // 加上领取数量
|
|
|
|
+ resultNum += storageNumByRetrievalLotId.getOrDefault(item.getLotId(), 0L);
|
|
|
|
+
|
|
|
|
+ // 减去inboundOrderDetailList中lotId对应的inboundNum总和
|
|
|
|
+ resultNum -= inboundNumByLotId.getOrDefault(item.getLotId(), 0L);
|
|
|
|
+
|
|
|
|
+ // 判断当前批次的盘点数量是否为0
|
|
|
|
+ // 如果为0,则表示该批次已经全部入库
|
|
|
|
+ if (resultNum == 0) {
|
|
|
|
+ endIds.add(item.getId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 将已将全部上架的批次从taskStockList与lotIds中移除
|
|
|
|
+ taskStockList.removeIf(item -> endIds.contains(item.getId()));
|
|
|
|
+ lotIds.removeAll(endIds);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //拿到所有批次的信息
|
|
List<BizLot> lotList = bizLotService.query().in("id", lotIds).list();
|
|
List<BizLot> lotList = bizLotService.query().in("id", lotIds).list();
|
|
|
|
+ //拿到所有合格证id
|
|
List<Long> certificateLotIds = taskStockList.stream().map(BizTaksStockInboundOrderDetail::getCertificateLotId).distinct().collect(Collectors.toList());
|
|
List<Long> certificateLotIds = taskStockList.stream().map(BizTaksStockInboundOrderDetail::getCertificateLotId).distinct().collect(Collectors.toList());
|
|
|
|
+ //拿到所有合格证信息
|
|
List<BizCertificateLot> certificateLotList = bizCertificateLotService.query().in("id", certificateLotIds).list();
|
|
List<BizCertificateLot> certificateLotList = bizCertificateLotService.query().in("id", certificateLotIds).list();
|
|
for (BizTaksStockInboundOrderDetail item : taskStockList) {
|
|
for (BizTaksStockInboundOrderDetail item : taskStockList) {
|
|
item.setTakeStockPeriodId(bizTakeStockPeriod.getId());
|
|
item.setTakeStockPeriodId(bizTakeStockPeriod.getId());
|