浏览代码

pms 保养工单 填报 删除与保存物料

zhangcl 1 周之前
父节点
当前提交
779c83124b

+ 5 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotmainworkorderbommaterial/IotMainWorkOrderBomMaterialMapper.java

@@ -10,7 +10,9 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.iotmainworkorderbommaterial.Io
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Update;
 
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Set;
 
@@ -93,4 +95,7 @@ public interface IotMainWorkOrderBomMaterialMapper extends BaseMapperX<IotMainWo
                                                                      @Param("stockLocationIds") Set<Long> stockLocationIds,
                                                                      @Param("materialName") String materialName,
                                                                      @Param("materialCode") String materialCode);
+
+    @Update("UPDATE rq_iot_main_work_order_bom_material SET deleted = 1, update_time = #{deletedTime} WHERE work_order_id = #{workOrderId}")
+    void updateToDelete(@Param("workOrderId") Long workOrderId, @Param("deletedTime") LocalDateTime deletedTime);
 }

+ 8 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotdevicematerial/IotDeviceMaterialServiceImpl.java

@@ -1,5 +1,6 @@
 package cn.iocoder.yudao.module.pms.service.iotdevicematerial;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.StrUtil;
@@ -335,7 +336,13 @@ public class IotDeviceMaterialServiceImpl implements IotDeviceMaterialService {
                 }
 
                 // 设置保养项关联的物料列表
-                List<IotDeviceMaterialRespVO> deviceMaterials = BeanUtils.toBean(deviceBomMaterials, IotDeviceMaterialRespVO.class);
+                List<IotDeviceMaterialRespVO> deviceMaterials = deviceBomMaterials.stream()
+                        .map(source -> {
+                            IotDeviceMaterialRespVO target = new IotDeviceMaterialRespVO();
+                            BeanUtil.copyProperties(source, target, "id");
+                            return target;
+                        })
+                        .collect(Collectors.toList());
                 // 绑定保养项关联的物料 优先级 本地库存 > sap库存 > sap主数据
                 deviceMaterials.forEach(material -> {
                     if (lockStockPair.containsKey(material.getCode())) {

+ 51 - 30
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotmainworkorder/IotMainWorkOrderServiceImpl.java

@@ -1,5 +1,6 @@
 package cn.iocoder.yudao.module.pms.service.iotmainworkorder;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.LocalDateTimeUtil;
 import cn.hutool.core.util.ObjUtil;
@@ -1298,43 +1299,63 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
         Set<Long> mctDeviceIds = new HashSet<>();
         // 需要更新 运行时长周期 的保养项id 集合
         Set<Long> mctBomNodeIds = new HashSet<>();
+        // 需要消耗物料的保养项id集合
+        Set<Long> materialBomNodeIds = new HashSet<>();
+        // 保养完成的保养项id集合
+        Set<Long> completedBomNodeIds = new HashSet<>();
+        // 统计保养项信息 是否保养完成 是否需要消耗物料
+        workOrderBOMs.forEach(bom -> {
+            if ("0".equals(bom.getRule())) {
+                // 需要消耗物料
+                materialBomNodeIds.add(bom.getBomNodeId());
+            }
+            if (1 == bom.getStatus()) {
+                // 保养完成
+                completedBomNodeIds.add(bom.getBomNodeId());
+            }
+        });
+        // 只有保养完成的保养项关联的物料才会被统计出库(如果物料来源是 本地库存)
         workOrderMaterials.forEach(material -> {
-            if (ObjUtil.isEmpty(material.getId())) {
-                // 兼容保养工单中部分保养项保养完成 部分保养项延期保养的情况 这里只新增延期保养 或 正常保养的物料
-                IotMainWorkOrderBomMaterialDO tempMaterial = BeanUtils.toBean(material, IotMainWorkOrderBomMaterialDO.class);
+            // 兼容保养工单中部分保养项保养完成 部分保养项延期保养的情况 这里只新增延期保养 或 正常保养的物料
+            if (materialBomNodeIds.contains(material.getBomNodeId())) {
+                IotMainWorkOrderBomMaterialDO tempMaterial = BeanUtil.copyProperties(material, IotMainWorkOrderBomMaterialDO.class, "id");
                 tempMaterial.setWorkOrderId(mainWorkOrder.getId());
                 workOrderBomMaterialDOS.add(tempMaterial);
+            }
 
-                if ("本地库存".equals(material.getMaterialSource())) {
-                    if (ObjUtil.isNotEmpty(material.getFactoryId())) {
-                        factoryIds.add(material.getFactoryId());
-                    }
-                    if (ObjUtil.isNotEmpty(material.getCostCenterId())) {
-                        costCenterIds.add(material.getCostCenterId());
-                    }
-                    if (ObjUtil.isNotEmpty(material.getStorageLocationId())) {
-                        storageLocationIds.add(material.getStorageLocationId());
-                    }
-                    if (ObjUtil.isNotEmpty(material.getMaterialCode())) {
-                        materialCodes.add(material.getMaterialCode());
-                    }
-                    String uniqueKey = StrUtil.join("-", material.getFactoryId(),
-                            material.getCostCenterId(), material.getMaterialCode(), material.getBomNodeId());
-                    String tempKey = material.getFactoryId() + String.valueOf(material.getCostCenterId())
-                            + material.getMaterialCode();
-                    // 扣减库存使用 合并不同保养项下的相同物料
-                    if (lockStockPair.containsKey(tempKey)) {
-                        BigDecimal tempQuantity = lockStockPair.get(tempKey);
-                        BigDecimal totalQuantity = tempQuantity.add(material.getQuantity());
-                        lockStockPair.put(tempKey, totalQuantity);
-                    } else {
-                        lockStockPair.put(tempKey, material.getQuantity());
-                    }
-                    // 记录出库使用 记录保养项id
-                    bomMaterialPair.put(uniqueKey, material);
+            if (completedBomNodeIds.contains(material.getBomNodeId()) && "本地库存".equals(material.getMaterialSource())) {
+                if (ObjUtil.isNotEmpty(material.getFactoryId())) {
+                    factoryIds.add(material.getFactoryId());
+                }
+                if (ObjUtil.isNotEmpty(material.getCostCenterId())) {
+                    costCenterIds.add(material.getCostCenterId());
+                }
+                if (ObjUtil.isNotEmpty(material.getStorageLocationId())) {
+                    storageLocationIds.add(material.getStorageLocationId());
+                }
+                if (ObjUtil.isNotEmpty(material.getMaterialCode())) {
+                    materialCodes.add(material.getMaterialCode());
                 }
+                String uniqueKey = StrUtil.join("-", material.getFactoryId(),
+                        material.getCostCenterId(), material.getMaterialCode(), material.getBomNodeId());
+                String tempKey = material.getFactoryId() + String.valueOf(material.getCostCenterId())
+                        + material.getMaterialCode();
+                // 扣减库存使用 合并不同保养项下的相同物料
+                if (lockStockPair.containsKey(tempKey)) {
+                    BigDecimal tempQuantity = lockStockPair.get(tempKey);
+                    BigDecimal totalQuantity = tempQuantity.add(material.getQuantity());
+                    lockStockPair.put(tempKey, totalQuantity);
+                } else {
+                    lockStockPair.put(tempKey, material.getQuantity());
+                }
+                // 记录出库使用 记录保养项id
+                bomMaterialPair.put(uniqueKey, material);
             }
         });
+        // 删除当前工单已有的保养项物料 再新增
+        if (ObjUtil.isNotEmpty(updateObj.getId())) {
+            iotMainWorkOrderBomMaterialMapper.updateToDelete(updateObj.getId(), LocalDateTime.now());
+        }
         // 添加 工单消耗的物料记录
         iotMainWorkOrderBomMaterialMapper.insertBatch(workOrderBomMaterialDOS);
         // key设备id-保养项BOM节点id   value保养工单明细对象   用于更新关联的保养计划保养项