Browse Source

Merge remote-tracking branch 'origin/master'

guoyujia 2 days ago
parent
commit
ed98b54eff

+ 45 - 9
src/main/java/cn/ezhizao/project/business/controller/BizTakeStockPeriodController.java

@@ -178,11 +178,52 @@ public class BizTakeStockPeriodController extends BaseController
             //已生产的批次
             List<BizDaywork> dayworkList = bizDayworkService.selectNeedTakeStock(bizTakeStockPeriod.getTenantId());
             List<BizTaksStockLot> list = new ArrayList<>();
+            //获取已经完成的批次id
+            List<Long> lotIds =dayworkList.stream().filter(daywork -> daywork.getStatus() == 2).map(BizDaywork::getLotId).distinct().collect(Collectors.toList());
+            //根据批次id查询到对应批次的零存或领取信息
+            List<BizStorageRetrieval> storageRetrievalList = bizStorageRetrievalService.query().in("lot_id", lotIds).or().in("retrieval_lot_id", lotIds).list();
+            //根据批次id查询是否有入库信息
+            List<BizInboundOrderDetail> inboundOrderDetailList = bizInboundOrderDetailService.query().in("lot_id", lotIds).list();
+
+            // 创建映射,计算以完成批次的零存数量
+            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)
+                    ));
+
+            // 提取所有入库批次ID到Set中以提高查找效率
+            Set<Long> inboundLotIds = inboundOrderDetailList.stream()
+                    .map(BizInboundOrderDetail::getLotId)
+                    .collect(Collectors.toSet());
+
+
             dayworkList.forEach(item -> {
-//                BizDayworkItem conditions = new BizDayworkItem();
-//                conditions.setDayworkId(item.getId());
-//                BizDayworkItem latestItem = bizDayworkItemService.getLastItem(conditions);
+
                 BizTaksStockLot bizTaksStockLot = new BizTaksStockLot();
+
+                // 如果批次在目标集合中,则计算生产数量
+                if (lotIds.contains(item.getLotId())) {
+                    Long retrievalNum = storageNumByRetrievalLotId.getOrDefault(item.getLotId(), 0L);//领取数量
+                    Long storageNum = storageNumByLotId.getOrDefault(item.getLotId(), 0L);//零存数量
+
+                    // 计算并设置生产数量
+                    long calculatedProdNum = item.getProdNum() + retrievalNum - storageNum;
+                    bizTaksStockLot.setProdNum(Math.toIntExact(calculatedProdNum));
+                } else {
+                    // 不在目标集合中则保持原值
+                    bizTaksStockLot.setProdNum(item.getProdNum());
+                }
+                // 如果批次ID在入库明细中存在,设置isEstablishInbound为1表示为已经创建入库单,否则为0
+                bizTaksStockLot.setIsEstablishInbound(inboundLotIds.contains(item.getLotId()) ? 1 : 0);
+
                 bizTaksStockLot.setStockYear(bizTakeStockPeriod.getStockYear());
                 bizTaksStockLot.setStockMonth(bizTakeStockPeriod.getStockMonth());
                 bizTaksStockLot.setDrawingNumber(item.getDrawingNumber());
@@ -204,7 +245,6 @@ public class BizTakeStockPeriodController extends BaseController
                 bizTaksStockLot.setProcessAlias(item.getProcessAlias());
                 bizTaksStockLot.setProcessId(item.getProcessId());
                 bizTaksStockLot.setTechnologicalProcessId(item.getTechnologicalProcessId());
-                bizTaksStockLot.setProdNum(item.getProdNum());
                 bizTaksStockLot.setIsLast(item.getIsLast());
                 bizTaksStockLot.setIsWasteRecycling(item.getIsWasteRecycling());
                 bizTaksStockLot.setIsAmend(item.getIsAmend());
@@ -212,13 +252,9 @@ public class BizTakeStockPeriodController extends BaseController
                 bizTaksStockLot.setRemark(item.getRemark());
                 bizTaksStockLot.setStatus(item.getStatus());
                 bizTaksStockLot.setHasSpecial(item.getHasSpecial());
-                bizTaksStockLot.setIsProductStatus(1);
+                bizTaksStockLot.setIsProductStatus(item.getStatus());
                 bizTaksStockLot.setOutsourceFormNo(item.getOutsourceFormNo());
                 bizTaksStockLot.setStatusLabel(item.getReportStatus());
-//                if (latestItem != null) {
-//                    bizTaksStockLot.setOutsourceFormNo(latestItem.getOutsourceFormNo());
-//                    bizTaksStockLot.setStatusLabel(latestItem.getStatus());
-//                }
 
                 list.add(bizTaksStockLot);
             });

+ 10 - 0
src/main/java/cn/ezhizao/project/business/domain/BizTaksStockLot.java

@@ -107,6 +107,16 @@ public class BizTaksStockLot extends BaseEntity
     @Excel(name = "批次生产状态", readConverterExp = "0=未开始,1=进行中,2=已完成",sort = 11)
     private Integer status;
 
+    /** 批次生产状态(0:未开始,1:进行中,2:已完成) */
+    @ApiModelProperty(value = "是否入库")
+    @Excel(name = "是否入库", readConverterExp = "0=否,1=是",sort = 14)
+    private Integer isInbound;
+
+    /** 批次生产状态(0:未开始,1:进行中,2:已完成) */
+    @ApiModelProperty(value = "是否创建入库单")
+    @Excel(name = "是否创建入库单", readConverterExp = "0=否,1=是")
+    private Integer isEstablishInbound;
+
     /** 是否经过特殊报工(0:否,1:是) */
     @ApiModelProperty(value = "是否经过特殊报工")
     private Integer hasSpecial;

+ 2 - 1
src/main/resources/mybatis/business/BizTaksStockLotMapper.xml

@@ -18,11 +18,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         left join sys_dept t2 on t1.dept_id = t2.dept_id
         left join biz_production_plan_detail t3 on t1.production_plan_detail_id = t3.id
         <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
-            t1.deleted = 0 and t1.take_stock_period_id = #{takeStockPeriodId} and t1.is_waste = 0 and t1.status &lt;2
+            t1.deleted = 0 and t1.take_stock_period_id = #{takeStockPeriodId} and t1.is_waste = 0  AND t1.is_establish_inbound=0
             <if test="productDescription != null  and productDescription != ''"> AND t1.product_description like concat('%', #{productDescription}, '%')</if>
             <if test="lotCode != null  and lotCode != ''"> AND t1.lot_code like concat('%', #{lotCode},'%')</if>
             <if test="isTaksStock != null "> AND t1.is_taks_stock = #{isTaksStock}</if>
             <if test="deptId != null and deptId != 0"> AND t1.dept_id = #{deptId}</if>
+            <if test="isInbound != null "> AND t1.is_inbound = #{isInbound}</if>
             <if test="isProductStatus != null "> AND t1.is_product_status = #{isProductStatus}</if>
             <if test="lotIds != null and lotIds.size > 0">
                 AND t1.lot_id in