Browse Source

✨ feat(mes): 更新设备点检和保养记录的状态处理

实现设备点检和保养记录提交时,自动更新设备台账中的最近点检和保养时间。优化了检查记录行的删除逻辑,确保在删除前进行存在性校验。
YunaiV 2 months ago
parent
commit
90a621a87a

+ 2 - 5
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkrecord/MesDvCheckRecordLineServiceImpl.java

@@ -58,13 +58,10 @@ public class MesDvCheckRecordLineServiceImpl implements MesDvCheckRecordLineServ
     @Override
     public void deleteCheckRecordLine(Long id) {
         // 1. 校验存在
-        // TODO @AI:复用 validateCheckRecordLineExists 方法;
-        MesDvCheckRecordLineDO line = checkRecordLineMapper.selectById(id);
-        if (line == null) {
-            throw exception(DV_CHECK_RECORD_LINE_NOT_EXISTS);
-        }
+        validateCheckRecordLineExists(id);
 
         // 2. 校验父记录为草稿状态
+        MesDvCheckRecordLineDO line = checkRecordLineMapper.selectById(id);
         checkRecordService.validateCheckRecordDraft(line.getRecordId());
         // 3. 删除
         checkRecordLineMapper.deleteById(id);

+ 7 - 0
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkrecord/MesDvCheckRecordServiceImpl.java

@@ -99,6 +99,7 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService {
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void submitCheckRecord(Long id) {
         // 1.1 校验状态为草稿
         validateCheckRecordDraft(id);
@@ -109,9 +110,15 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService {
         }
 
         // 2. 状态改为已完成
+        MesDvCheckRecordDO record = checkRecordMapper.selectById(id);
         MesDvCheckRecordDO updateObj = new MesDvCheckRecordDO()
                 .setId(id).setStatus(MesDvCheckRecordStatusEnum.FINISHED.getStatus());
         checkRecordMapper.updateById(updateObj);
+
+        // 3. 回写设备台账的【最近点检时间】
+        if (record.getCheckTime() != null) {
+            machineryService.updateMachineryLastCheckTime(record.getMachineryId(), record.getCheckTime());
+        }
     }
 
     @Override

+ 17 - 0
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/machinery/MesDvMachineryService.java

@@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.mes.controller.admin.dv.machinery.vo.MesDvMachine
 import cn.iocoder.yudao.module.mes.dal.dataobject.dv.machinery.MesDvMachineryDO;
 import jakarta.validation.Valid;
 
+import java.time.LocalDateTime;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -106,6 +107,22 @@ public interface MesDvMachineryService {
         return convertMap(getMachineryList(ids), MesDvMachineryDO::getId);
     }
 
+    /**
+     * 更新设备的最近点检时间
+     *
+     * @param machineryId 设备编号
+     * @param lastCheckTime 最近点检时间
+     */
+    void updateMachineryLastCheckTime(Long machineryId, LocalDateTime lastCheckTime);
+
+    /**
+     * 更新设备的最近保养时间
+     *
+     * @param machineryId 设备编号
+     * @param lastMaintenTime 最近保养时间
+     */
+    void updateMachineryLastMaintenTime(Long machineryId, LocalDateTime lastMaintenTime);
+
     /**
      * 导入设备列表
      *

+ 11 - 0
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/machinery/MesDvMachineryServiceImpl.java

@@ -27,6 +27,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
@@ -179,6 +180,16 @@ public class MesDvMachineryServiceImpl implements MesDvMachineryService {
         return machineryMapper.selectCountByMachineryTypeId(machineryTypeId);
     }
 
+    @Override
+    public void updateMachineryLastCheckTime(Long machineryId, LocalDateTime lastCheckTime) {
+        machineryMapper.updateById(new MesDvMachineryDO().setId(machineryId).setLastCheckTime(lastCheckTime));
+    }
+
+    @Override
+    public void updateMachineryLastMaintenTime(Long machineryId, LocalDateTime lastMaintenTime) {
+        machineryMapper.updateById(new MesDvMachineryDO().setId(machineryId).setLastMaintenTime(lastMaintenTime));
+    }
+
     @Override
     public List<MesDvMachineryDO> getMachineryList() {
         return machineryMapper.selectList();

+ 7 - 0
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordServiceImpl.java

@@ -69,6 +69,7 @@ public class MesDvMaintenRecordServiceImpl implements MesDvMaintenRecordService
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void submitMaintenRecord(Long id) {
         // 1.1 校验状态为草稿
         validateMaintenRecordDraft(id);
@@ -79,10 +80,16 @@ public class MesDvMaintenRecordServiceImpl implements MesDvMaintenRecordService
         }
 
         // 2. 状态改为已提交
+        MesDvMaintenRecordDO record = maintenRecordMapper.selectById(id);
         MesDvMaintenRecordDO updateObj = new MesDvMaintenRecordDO();
         updateObj.setId(id);
         updateObj.setStatus(MesDvMaintenRecordStatusEnum.SUBMITTED.getStatus());
         maintenRecordMapper.updateById(updateObj);
+
+        // 3. 回写设备台账的【最近保养时间】
+        if (record.getMaintenTime() != null) {
+            machineryService.updateMachineryLastMaintenTime(record.getMachineryId(), record.getMaintenTime());
+        }
     }
 
     @Override