Commit 90a621a87a10f73ae1724ce83e8ca23389e28454
1 parent
59cb4577
✨ feat(mes): 更新设备点检和保养记录的状态处理
实现设备点检和保养记录提交时,自动更新设备台账中的最近点检和保养时间。优化了检查记录行的删除逻辑,确保在删除前进行存在性校验。
Showing
5 changed files
with
44 additions
and
5 deletions
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 |
| 58 | 58 | @Override |
| 59 | 59 | public void deleteCheckRecordLine(Long id) { |
| 60 | 60 | // 1. 校验存在 |
| 61 | - // TODO @AI:复用 validateCheckRecordLineExists 方法; | |
| 62 | - MesDvCheckRecordLineDO line = checkRecordLineMapper.selectById(id); | |
| 63 | - if (line == null) { | |
| 64 | - throw exception(DV_CHECK_RECORD_LINE_NOT_EXISTS); | |
| 65 | - } | |
| 61 | + validateCheckRecordLineExists(id); | |
| 66 | 62 | |
| 67 | 63 | // 2. 校验父记录为草稿状态 |
| 64 | + MesDvCheckRecordLineDO line = checkRecordLineMapper.selectById(id); | |
| 68 | 65 | checkRecordService.validateCheckRecordDraft(line.getRecordId()); |
| 69 | 66 | // 3. 删除 |
| 70 | 67 | checkRecordLineMapper.deleteById(id); | ... | ... |
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 { |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | @Override |
| 102 | + @Transactional(rollbackFor = Exception.class) | |
| 102 | 103 | public void submitCheckRecord(Long id) { |
| 103 | 104 | // 1.1 校验状态为草稿 |
| 104 | 105 | validateCheckRecordDraft(id); |
| ... | ... | @@ -109,9 +110,15 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService { |
| 109 | 110 | } |
| 110 | 111 | |
| 111 | 112 | // 2. 状态改为已完成 |
| 113 | + MesDvCheckRecordDO record = checkRecordMapper.selectById(id); | |
| 112 | 114 | MesDvCheckRecordDO updateObj = new MesDvCheckRecordDO() |
| 113 | 115 | .setId(id).setStatus(MesDvCheckRecordStatusEnum.FINISHED.getStatus()); |
| 114 | 116 | checkRecordMapper.updateById(updateObj); |
| 117 | + | |
| 118 | + // 3. 回写设备台账的【最近点检时间】 | |
| 119 | + if (record.getCheckTime() != null) { | |
| 120 | + machineryService.updateMachineryLastCheckTime(record.getMachineryId(), record.getCheckTime()); | |
| 121 | + } | |
| 115 | 122 | } |
| 116 | 123 | |
| 117 | 124 | @Override | ... | ... |
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 |
| 8 | 8 | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.machinery.MesDvMachineryDO; |
| 9 | 9 | import jakarta.validation.Valid; |
| 10 | 10 | |
| 11 | +import java.time.LocalDateTime; | |
| 11 | 12 | import java.util.Collection; |
| 12 | 13 | import java.util.List; |
| 13 | 14 | import java.util.Map; |
| ... | ... | @@ -107,6 +108,22 @@ public interface MesDvMachineryService { |
| 107 | 108 | } |
| 108 | 109 | |
| 109 | 110 | /** |
| 111 | + * 更新设备的最近点检时间 | |
| 112 | + * | |
| 113 | + * @param machineryId 设备编号 | |
| 114 | + * @param lastCheckTime 最近点检时间 | |
| 115 | + */ | |
| 116 | + void updateMachineryLastCheckTime(Long machineryId, LocalDateTime lastCheckTime); | |
| 117 | + | |
| 118 | + /** | |
| 119 | + * 更新设备的最近保养时间 | |
| 120 | + * | |
| 121 | + * @param machineryId 设备编号 | |
| 122 | + * @param lastMaintenTime 最近保养时间 | |
| 123 | + */ | |
| 124 | + void updateMachineryLastMaintenTime(Long machineryId, LocalDateTime lastMaintenTime); | |
| 125 | + | |
| 126 | + /** | |
| 110 | 127 | * 导入设备列表 |
| 111 | 128 | * |
| 112 | 129 | * @param importMachineryList 导入设备列表 | ... | ... |
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; |
| 27 | 27 | import org.springframework.transaction.annotation.Transactional; |
| 28 | 28 | import org.springframework.validation.annotation.Validated; |
| 29 | 29 | |
| 30 | +import java.time.LocalDateTime; | |
| 30 | 31 | import java.util.*; |
| 31 | 32 | import java.util.concurrent.atomic.AtomicInteger; |
| 32 | 33 | import java.util.stream.Collectors; |
| ... | ... | @@ -180,6 +181,16 @@ public class MesDvMachineryServiceImpl implements MesDvMachineryService { |
| 180 | 181 | } |
| 181 | 182 | |
| 182 | 183 | @Override |
| 184 | + public void updateMachineryLastCheckTime(Long machineryId, LocalDateTime lastCheckTime) { | |
| 185 | + machineryMapper.updateById(new MesDvMachineryDO().setId(machineryId).setLastCheckTime(lastCheckTime)); | |
| 186 | + } | |
| 187 | + | |
| 188 | + @Override | |
| 189 | + public void updateMachineryLastMaintenTime(Long machineryId, LocalDateTime lastMaintenTime) { | |
| 190 | + machineryMapper.updateById(new MesDvMachineryDO().setId(machineryId).setLastMaintenTime(lastMaintenTime)); | |
| 191 | + } | |
| 192 | + | |
| 193 | + @Override | |
| 183 | 194 | public List<MesDvMachineryDO> getMachineryList() { |
| 184 | 195 | return machineryMapper.selectList(); |
| 185 | 196 | } | ... | ... |
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 |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | @Override |
| 72 | + @Transactional(rollbackFor = Exception.class) | |
| 72 | 73 | public void submitMaintenRecord(Long id) { |
| 73 | 74 | // 1.1 校验状态为草稿 |
| 74 | 75 | validateMaintenRecordDraft(id); |
| ... | ... | @@ -79,10 +80,16 @@ public class MesDvMaintenRecordServiceImpl implements MesDvMaintenRecordService |
| 79 | 80 | } |
| 80 | 81 | |
| 81 | 82 | // 2. 状态改为已提交 |
| 83 | + MesDvMaintenRecordDO record = maintenRecordMapper.selectById(id); | |
| 82 | 84 | MesDvMaintenRecordDO updateObj = new MesDvMaintenRecordDO(); |
| 83 | 85 | updateObj.setId(id); |
| 84 | 86 | updateObj.setStatus(MesDvMaintenRecordStatusEnum.SUBMITTED.getStatus()); |
| 85 | 87 | maintenRecordMapper.updateById(updateObj); |
| 88 | + | |
| 89 | + // 3. 回写设备台账的【最近保养时间】 | |
| 90 | + if (record.getMaintenTime() != null) { | |
| 91 | + machineryService.updateMachineryLastMaintenTime(record.getMachineryId(), record.getMaintenTime()); | |
| 92 | + } | |
| 86 | 93 | } |
| 87 | 94 | |
| 88 | 95 | @Override | ... | ... |