Browse Source

车间看板添加物料使用量

yzc 11 months ago
parent
commit
033390f1a1

+ 6 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/production/bo/WorkshopReportBo.java

@@ -4,6 +4,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 @Getter
 @Setter
@@ -89,4 +90,9 @@ public class WorkshopReportBo {
      * 明天完成数量
      */
     private BigDecimal tomorrowSchedulingQuantity;
+
+    /**
+     * 物料使用列表
+     */
+    private List<WorkshopReportMaterialsUsedBo> materialsUsedList;
 }

+ 25 - 0
hx-mes/src/main/java/com/fjhx/mes/entity/production/bo/WorkshopReportMaterialsUsedBo.java

@@ -0,0 +1,25 @@
+package com.fjhx.mes.entity.production.bo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+@Getter
+@Setter
+public class WorkshopReportMaterialsUsedBo {
+    private Long productionOrderDetailId;
+    private Long materialId;
+    private String materialName;
+    private String materialCode;
+    private BigDecimal materialLength;
+    private BigDecimal materialWidth;
+    private BigDecimal materialHeight;
+    private BigDecimal materialNetWeight;
+    private String materialUnit;
+    private String materialColor;
+    private BigDecimal quantity;
+    private BigDecimal usedQuantity;
+    private BigDecimal lossQuantity;
+    private BigDecimal surplusQuantity;
+}

+ 3 - 0
hx-mes/src/main/java/com/fjhx/mes/mapper/production/ProductionTaskProgressMapper.java

@@ -3,6 +3,7 @@ package com.fjhx.mes.mapper.production;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.mes.entity.production.bo.WorkshopReportBo;
+import com.fjhx.mes.entity.production.bo.WorkshopReportMaterialsUsedBo;
 import com.fjhx.mes.entity.production.po.ProductionTaskProgress;
 import com.fjhx.mes.entity.production.vo.ProductionTaskProgressVo;
 import com.ruoyi.common.utils.wrapper.IWrapper;
@@ -33,4 +34,6 @@ public interface ProductionTaskProgressMapper extends BaseMapper<ProductionTaskP
 
     Page<WorkshopReportBo> workshopReport(@Param("page") Page<Object> page, @Param("ew") IWrapper<ProductionTaskProgress> wrapper);
 
+    List<WorkshopReportMaterialsUsedBo> workshopReportMaterialsUsed(@Param("ew") IWrapper wrapper);
+
 }

+ 51 - 9
hx-mes/src/main/java/com/fjhx/mes/service/production/impl/ProductionTaskProgressServiceImpl.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.item.service.product.ProductInfoService;
 import com.fjhx.mes.entity.production.bo.WorkshopReportBo;
+import com.fjhx.mes.entity.production.bo.WorkshopReportMaterialsUsedBo;
 import com.fjhx.mes.entity.production.dto.ProductionTaskProgressSelectDto;
 import com.fjhx.mes.entity.production.po.ProductionTaskProgress;
 import com.fjhx.mes.entity.production.vo.ProductionTaskProgressVo;
@@ -12,10 +13,13 @@ import com.fjhx.mes.mapper.production.ProductionTaskProgressMapper;
 import com.fjhx.mes.service.production.ProductionTaskProgressService;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.wrapper.IWrapper;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 
 /**
@@ -23,16 +27,19 @@ import java.util.List;
  * 生产任务进度 服务实现类
  * </p>
  *
- * @author
+ * @author _
  * @since 2024-01-15
  */
 @Service
 public class ProductionTaskProgressServiceImpl extends ServiceImpl<ProductionTaskProgressMapper, ProductionTaskProgress> implements ProductionTaskProgressService {
 
-    @Autowired
-    private ProductInfoService productInfoService;
+    private final ProductInfoService productInfoService;
 
-    private IWrapper<ProductionTaskProgress> getWorkshopReportWrapper(ProductionTaskProgressSelectDto dto) {
+    public ProductionTaskProgressServiceImpl(ProductInfoService productInfoService) {
+        this.productInfoService = productInfoService;
+    }
+
+    private IWrapper<ProductionTaskProgress> getWorkshopReportWrapper() {
         IWrapper<ProductionTaskProgress> wrapper = getWrapper();
         wrapper.in("pod.company_id", SecurityUtils.getCompanyIds());
         return wrapper;
@@ -40,16 +47,15 @@ public class ProductionTaskProgressServiceImpl extends ServiceImpl<ProductionTas
 
     @Override
     public List<ProductionTaskProgressVo> workshopReportStatistics(ProductionTaskProgressSelectDto dto) {
-        IWrapper<ProductionTaskProgress> wrapper = getWorkshopReportWrapper(dto);
+        IWrapper<ProductionTaskProgress> wrapper = getWorkshopReportWrapper();
         wrapper.eq("DATEDIFF(  ps.scheduling_date,now() )", 0);
         wrapper.groupBy("ptp.processes_id");
-        List<ProductionTaskProgressVo> workshopReportStatistics = baseMapper.workshopReportStatistics(wrapper);
-        return workshopReportStatistics;
+        return baseMapper.workshopReportStatistics(wrapper);
     }
 
     @Override
     public Page<WorkshopReportBo> workshopReport(ProductionTaskProgressSelectDto dto) {
-        IWrapper<ProductionTaskProgress> wrapper = getWorkshopReportWrapper(dto);
+        IWrapper<ProductionTaskProgress> wrapper = getWorkshopReportWrapper();
 
         //过滤 昨天 今天 明天
         wrapper.in("DATEDIFF(ps.scheduling_date, now())", -1, 0, 1);
@@ -69,6 +75,42 @@ public class ProductionTaskProgressServiceImpl extends ServiceImpl<ProductionTas
             item.setProductHeight(productInfo.getHeight());
             item.setProductColor(productInfo.getColor());
         });
+
+        //赋值已用料数据
+        List<Long> taskIds = records.stream().map(WorkshopReportBo::getTaskId).collect(Collectors.toList());
+        List<WorkshopReportMaterialsUsedBo> materialsUsedBos = baseMapper.workshopReportMaterialsUsed(IWrapper.getWrapper()
+                .in("pod.id", taskIds)
+                .ne("cpb.type", 3)
+        );
+        for (WorkshopReportMaterialsUsedBo materialsUsedBo : materialsUsedBos) {
+            BigDecimal quantity = materialsUsedBo.getQuantity().setScale(2, BigDecimal.ROUND_HALF_UP);
+            BigDecimal usedQuantity = materialsUsedBo.getUsedQuantity().setScale(2, BigDecimal.ROUND_HALF_UP);
+            BigDecimal lossQuantity = materialsUsedBo.getLossQuantity().setScale(2, BigDecimal.ROUND_HALF_UP);
+            BigDecimal surplusQuantity = materialsUsedBo.getSurplusQuantity().setScale(2, BigDecimal.ROUND_HALF_UP);
+
+            materialsUsedBo.setQuantity(quantity);
+            materialsUsedBo.setUsedQuantity(usedQuantity);
+            materialsUsedBo.setLossQuantity(lossQuantity);
+            materialsUsedBo.setSurplusQuantity(surplusQuantity);
+        }
+        productInfoService.attributeAssign(materialsUsedBos, WorkshopReportMaterialsUsedBo::getMaterialId, (item, productInfo) -> {
+            item.setMaterialName(productInfo.getName());
+            item.setMaterialCode(productInfo.getCustomCode());
+
+            item.setMaterialLength(productInfo.getLength());
+            item.setMaterialWidth(productInfo.getWidth());
+            item.setMaterialHeight(productInfo.getHeight());
+            item.setMaterialNetWeight(productInfo.getNetWeight());
+            item.setMaterialUnit(productInfo.getUnit());
+            item.setMaterialColor(productInfo.getColor());
+
+        });
+        Map<Long, List<WorkshopReportMaterialsUsedBo>> materialsUsedMap = materialsUsedBos
+                .stream().collect(Collectors.groupingBy(WorkshopReportMaterialsUsedBo::getProductionOrderDetailId));
+        for (WorkshopReportBo record : records) {
+            record.setMaterialsUsedList(materialsUsedMap.getOrDefault(record.getTaskId(), new ArrayList<>()));
+        }
+
         return workshopReportBoPage;
     }
 }

+ 28 - 0
hx-mes/src/main/resources/mapper/production/ProductionTaskProgressMapper.xml

@@ -69,4 +69,32 @@
             AND ps.processes_id = ptp.processes_id
             ${ew.customSqlSegment}
     </select>
+    <select id="workshopReportMaterialsUsed"
+            resultType="com.fjhx.mes.entity.production.bo.WorkshopReportMaterialsUsedBo">
+        SELECT production_order_detail_id,
+               material_id,
+               material_name,
+               quantity,
+               usedQuantity,
+               lossQuantity,
+               (quantity - usedQuantity - lossQuantity) AS surplusQuantity
+        FROM (SELECT pod.id                                              AS production_order_detail_id,
+                     cpb.material_id,
+                     cpb.product_name                                    as material_name,
+                     (cpb.quantity / pod.quantity)                       as quantity,
+                     (cpb.quantity / pod.quantity * pod.finish_quantity) AS usedQuantity,
+                     ifnull(t1.quantity, 0)                              AS lossQuantity
+              FROM contract_product_bom cpb
+                       JOIN production_order_detail pod ON pod.contract_detail_id = cpb.contract_product_id
+                       LEFT JOIN (SELECT sj.prod_order_id,
+                                         sjd.product_id,
+                                         sum(sjd.quantity) AS quantity
+                                  FROM stock_journal_details sjd
+                                           JOIN stock_journal sj ON sjd.stock_journal_id = sj.id
+                                  WHERE sj.type = 1
+                                  GROUP BY sj.prod_order_id,
+                                           sjd.product_id) t1 ON t1.prod_order_id = pod.produce_order_id
+                  AND t1.product_id = cpb.material_id
+                  ${ew.customSqlSegment}) t2
+    </select>
 </mapper>