Commit d7b33f00ed91f14b21fa6d63f533f056f460cff3
1 parent
1ed449c8
✨ feat(mes): 新增点检记录明细的项目类型字段及批量创建功能
新增项目类型字段到点检记录明细响应对象,并在控制器和服务层中实现批量创建点检记录明细的功能。此变更提升了点检记录的灵活性和可扩展性。
Showing
6 changed files
with
62 additions
and
28 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/checkrecord/MesDvCheckRecordLineController.java
| @@ -96,10 +96,8 @@ public class MesDvCheckRecordLineController { | @@ -96,10 +96,8 @@ public class MesDvCheckRecordLineController { | ||
| 96 | // 2. 拼接 VO | 96 | // 2. 拼接 VO |
| 97 | return BeanUtils.toBean(list, MesDvCheckRecordLineRespVO.class, vo -> | 97 | return BeanUtils.toBean(list, MesDvCheckRecordLineRespVO.class, vo -> |
| 98 | MapUtils.findAndThen(subjectMap, vo.getSubjectId(), subject -> vo | 98 | MapUtils.findAndThen(subjectMap, vo.getSubjectId(), subject -> vo |
| 99 | - .setSubjectCode(subject.getCode()) | ||
| 100 | - .setSubjectName(subject.getName()) | ||
| 101 | - .setSubjectContent(subject.getContent()) | ||
| 102 | - .setSubjectStandard(subject.getStandard()))); | 99 | + .setSubjectCode(subject.getCode()).setSubjectName(subject.getName()) |
| 100 | + .setSubjectType(subject.getType()).setSubjectContent(subject.getContent()).setSubjectStandard(subject.getStandard()))); | ||
| 103 | } | 101 | } |
| 104 | 102 | ||
| 105 | } | 103 | } |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/checkrecord/vo/line/MesDvCheckRecordLineRespVO.java
| @@ -33,6 +33,10 @@ public class MesDvCheckRecordLineRespVO { | @@ -33,6 +33,10 @@ public class MesDvCheckRecordLineRespVO { | ||
| 33 | @ExcelProperty("项目名称") | 33 | @ExcelProperty("项目名称") |
| 34 | private String subjectName; | 34 | private String subjectName; |
| 35 | 35 | ||
| 36 | + @Schema(description = "项目类型", example = "1") | ||
| 37 | + @ExcelProperty("项目类型") | ||
| 38 | + private Integer subjectType; | ||
| 39 | + | ||
| 36 | @Schema(description = "检查内容", example = "检查润滑油是否充足") | 40 | @Schema(description = "检查内容", example = "检查润滑油是否充足") |
| 37 | @ExcelProperty("检查内容") | 41 | @ExcelProperty("检查内容") |
| 38 | private String subjectContent; | 42 | private String subjectContent; |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkrecord/MesDvCheckRecordLineService.java
| @@ -45,6 +45,13 @@ public interface MesDvCheckRecordLineService { | @@ -45,6 +45,13 @@ public interface MesDvCheckRecordLineService { | ||
| 45 | void deleteByRecordId(Long recordId); | 45 | void deleteByRecordId(Long recordId); |
| 46 | 46 | ||
| 47 | /** | 47 | /** |
| 48 | + * 批量创建点检记录明细 | ||
| 49 | + * | ||
| 50 | + * @param lines 明细列表 | ||
| 51 | + */ | ||
| 52 | + void createCheckRecordLineList(List<MesDvCheckRecordLineDO> lines); | ||
| 53 | + | ||
| 54 | + /** | ||
| 48 | * 校验点检记录明细存在 | 55 | * 校验点检记录明细存在 |
| 49 | * | 56 | * |
| 50 | * @param id 编号 | 57 | * @param id 编号 |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkrecord/MesDvCheckRecordLineServiceImpl.java
| @@ -34,8 +34,8 @@ public class MesDvCheckRecordLineServiceImpl implements MesDvCheckRecordLineServ | @@ -34,8 +34,8 @@ public class MesDvCheckRecordLineServiceImpl implements MesDvCheckRecordLineServ | ||
| 34 | 34 | ||
| 35 | @Override | 35 | @Override |
| 36 | public Long createCheckRecordLine(MesDvCheckRecordLineSaveReqVO createReqVO) { | 36 | public Long createCheckRecordLine(MesDvCheckRecordLineSaveReqVO createReqVO) { |
| 37 | - // 1. 校验点检记录存在 | ||
| 38 | - checkRecordService.validateCheckRecordExists(createReqVO.getRecordId()); | 37 | + // 1. 校验点检记录存在且为草稿状态 |
| 38 | + checkRecordService.validateCheckRecordDraft(createReqVO.getRecordId()); | ||
| 39 | 39 | ||
| 40 | // 2. 插入 | 40 | // 2. 插入 |
| 41 | MesDvCheckRecordLineDO line = BeanUtils.toBean(createReqVO, MesDvCheckRecordLineDO.class); | 41 | MesDvCheckRecordLineDO line = BeanUtils.toBean(createReqVO, MesDvCheckRecordLineDO.class); |
| @@ -47,8 +47,8 @@ public class MesDvCheckRecordLineServiceImpl implements MesDvCheckRecordLineServ | @@ -47,8 +47,8 @@ public class MesDvCheckRecordLineServiceImpl implements MesDvCheckRecordLineServ | ||
| 47 | public void updateCheckRecordLine(MesDvCheckRecordLineSaveReqVO updateReqVO) { | 47 | public void updateCheckRecordLine(MesDvCheckRecordLineSaveReqVO updateReqVO) { |
| 48 | // 1.1 校验行存在 | 48 | // 1.1 校验行存在 |
| 49 | validateCheckRecordLineExists(updateReqVO.getId()); | 49 | validateCheckRecordLineExists(updateReqVO.getId()); |
| 50 | - // 1.2 校验点检记录存在 | ||
| 51 | - checkRecordService.validateCheckRecordExists(updateReqVO.getRecordId()); | 50 | + // 1.2 校验点检记录存在且为草稿状态 |
| 51 | + checkRecordService.validateCheckRecordDraft(updateReqVO.getRecordId()); | ||
| 52 | 52 | ||
| 53 | // 2. 更新 | 53 | // 2. 更新 |
| 54 | MesDvCheckRecordLineDO updateObj = BeanUtils.toBean(updateReqVO, MesDvCheckRecordLineDO.class); | 54 | MesDvCheckRecordLineDO updateObj = BeanUtils.toBean(updateReqVO, MesDvCheckRecordLineDO.class); |
| @@ -57,9 +57,16 @@ public class MesDvCheckRecordLineServiceImpl implements MesDvCheckRecordLineServ | @@ -57,9 +57,16 @@ public class MesDvCheckRecordLineServiceImpl implements MesDvCheckRecordLineServ | ||
| 57 | 57 | ||
| 58 | @Override | 58 | @Override |
| 59 | public void deleteCheckRecordLine(Long id) { | 59 | public void deleteCheckRecordLine(Long id) { |
| 60 | - // 校验存在 | ||
| 61 | - validateCheckRecordLineExists(id); | ||
| 62 | - // 删除 | 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 | + } | ||
| 66 | + | ||
| 67 | + // 2. 校验父记录为草稿状态 | ||
| 68 | + checkRecordService.validateCheckRecordDraft(line.getRecordId()); | ||
| 69 | + // 3. 删除 | ||
| 63 | checkRecordLineMapper.deleteById(id); | 70 | checkRecordLineMapper.deleteById(id); |
| 64 | } | 71 | } |
| 65 | 72 | ||
| @@ -69,6 +76,11 @@ public class MesDvCheckRecordLineServiceImpl implements MesDvCheckRecordLineServ | @@ -69,6 +76,11 @@ public class MesDvCheckRecordLineServiceImpl implements MesDvCheckRecordLineServ | ||
| 69 | } | 76 | } |
| 70 | 77 | ||
| 71 | @Override | 78 | @Override |
| 79 | + public void createCheckRecordLineList(List<MesDvCheckRecordLineDO> lines) { | ||
| 80 | + checkRecordLineMapper.insertBatch(lines); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + @Override | ||
| 72 | public void validateCheckRecordLineExists(Long id) { | 84 | public void validateCheckRecordLineExists(Long id) { |
| 73 | if (checkRecordLineMapper.selectById(id) == null) { | 85 | if (checkRecordLineMapper.selectById(id) == null) { |
| 74 | throw exception(DV_CHECK_RECORD_LINE_NOT_EXISTS); | 86 | throw exception(DV_CHECK_RECORD_LINE_NOT_EXISTS); |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkrecord/MesDvCheckRecordService.java
| @@ -51,6 +51,13 @@ public interface MesDvCheckRecordService { | @@ -51,6 +51,13 @@ public interface MesDvCheckRecordService { | ||
| 51 | void validateCheckRecordExists(Long id); | 51 | void validateCheckRecordExists(Long id); |
| 52 | 52 | ||
| 53 | /** | 53 | /** |
| 54 | + * 校验点检记录为草稿状态 | ||
| 55 | + * | ||
| 56 | + * @param id 编号 | ||
| 57 | + */ | ||
| 58 | + void validateCheckRecordDraft(Long id); | ||
| 59 | + | ||
| 60 | + /** | ||
| 54 | * 获得指定设备的点检记录数量 | 61 | * 获得指定设备的点检记录数量 |
| 55 | * | 62 | * |
| 56 | * @param machineryId 设备编号 | 63 | * @param machineryId 设备编号 |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkrecord/MesDvCheckRecordServiceImpl.java
| @@ -11,12 +11,13 @@ import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkrecord.MesDvCheckRecor | @@ -11,12 +11,13 @@ import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkrecord.MesDvCheckRecor | ||
| 11 | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkrecord.MesDvCheckRecordLineDO; | 11 | import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkrecord.MesDvCheckRecordLineDO; |
| 12 | import cn.iocoder.yudao.module.mes.enums.dv.MesDvCheckRecordStatusEnum; | 12 | import cn.iocoder.yudao.module.mes.enums.dv.MesDvCheckRecordStatusEnum; |
| 13 | import cn.iocoder.yudao.module.mes.enums.dv.MesDvCheckResultEnum; | 13 | import cn.iocoder.yudao.module.mes.enums.dv.MesDvCheckResultEnum; |
| 14 | -import cn.iocoder.yudao.module.mes.dal.mysql.dv.checkrecord.MesDvCheckRecordLineMapper; | ||
| 15 | import cn.iocoder.yudao.module.mes.dal.mysql.dv.checkrecord.MesDvCheckRecordMapper; | 14 | import cn.iocoder.yudao.module.mes.dal.mysql.dv.checkrecord.MesDvCheckRecordMapper; |
| 16 | import cn.iocoder.yudao.module.mes.service.dv.checkplan.MesDvCheckPlanService; | 15 | import cn.iocoder.yudao.module.mes.service.dv.checkplan.MesDvCheckPlanService; |
| 17 | import cn.iocoder.yudao.module.mes.service.dv.checkplan.MesDvCheckPlanSubjectService; | 16 | import cn.iocoder.yudao.module.mes.service.dv.checkplan.MesDvCheckPlanSubjectService; |
| 18 | import cn.iocoder.yudao.module.mes.service.dv.machinery.MesDvMachineryService; | 17 | import cn.iocoder.yudao.module.mes.service.dv.machinery.MesDvMachineryService; |
| 18 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 19 | import jakarta.annotation.Resource; | 19 | import jakarta.annotation.Resource; |
| 20 | +import org.springframework.context.annotation.Lazy; | ||
| 20 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
| 21 | import org.springframework.transaction.annotation.Transactional; | 22 | import org.springframework.transaction.annotation.Transactional; |
| 22 | import org.springframework.validation.annotation.Validated; | 23 | import org.springframework.validation.annotation.Validated; |
| @@ -39,19 +40,22 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService { | @@ -39,19 +40,22 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService { | ||
| 39 | @Resource | 40 | @Resource |
| 40 | private MesDvCheckRecordMapper checkRecordMapper; | 41 | private MesDvCheckRecordMapper checkRecordMapper; |
| 41 | @Resource | 42 | @Resource |
| 42 | - private MesDvCheckRecordLineMapper checkRecordLineMapper; | 43 | + @Lazy |
| 44 | + private MesDvCheckRecordLineService checkRecordLineService; | ||
| 43 | @Resource | 45 | @Resource |
| 44 | private MesDvMachineryService machineryService; | 46 | private MesDvMachineryService machineryService; |
| 45 | @Resource | 47 | @Resource |
| 46 | private MesDvCheckPlanService checkPlanService; | 48 | private MesDvCheckPlanService checkPlanService; |
| 47 | @Resource | 49 | @Resource |
| 48 | private MesDvCheckPlanSubjectService checkPlanSubjectService; | 50 | private MesDvCheckPlanSubjectService checkPlanSubjectService; |
| 51 | + @Resource | ||
| 52 | + private AdminUserApi adminUserApi; | ||
| 49 | 53 | ||
| 50 | @Override | 54 | @Override |
| 51 | @Transactional(rollbackFor = Exception.class) | 55 | @Transactional(rollbackFor = Exception.class) |
| 52 | public Long createCheckRecord(MesDvCheckRecordSaveReqVO createReqVO) { | 56 | public Long createCheckRecord(MesDvCheckRecordSaveReqVO createReqVO) { |
| 53 | // 1. 校验关联数据 | 57 | // 1. 校验关联数据 |
| 54 | - validateCheckRecordRelation(createReqVO); | 58 | + validateCheckRecordSave(createReqVO); |
| 55 | 59 | ||
| 56 | // 2. 插入主记录,状态默认为草稿 | 60 | // 2. 插入主记录,状态默认为草稿 |
| 57 | MesDvCheckRecordDO checkRecord = BeanUtils.toBean(createReqVO, MesDvCheckRecordDO.class) | 61 | MesDvCheckRecordDO checkRecord = BeanUtils.toBean(createReqVO, MesDvCheckRecordDO.class) |
| @@ -69,16 +73,17 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService { | @@ -69,16 +73,17 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService { | ||
| 69 | @Transactional(rollbackFor = Exception.class) | 73 | @Transactional(rollbackFor = Exception.class) |
| 70 | public void updateCheckRecord(MesDvCheckRecordSaveReqVO updateReqVO) { | 74 | public void updateCheckRecord(MesDvCheckRecordSaveReqVO updateReqVO) { |
| 71 | // 1.1 校验存在 + 状态为草稿 | 75 | // 1.1 校验存在 + 状态为草稿 |
| 72 | - MesDvCheckRecordDO existRecord = validateCheckRecordDraft(updateReqVO.getId()); | 76 | + validateCheckRecordDraft(updateReqVO.getId()); |
| 73 | // 1.2 校验关联数据 | 77 | // 1.2 校验关联数据 |
| 74 | - validateCheckRecordRelation(updateReqVO); | 78 | + validateCheckRecordSave(updateReqVO); |
| 75 | 79 | ||
| 76 | // 2. 如果计划变更,删除旧明细并重新生成 | 80 | // 2. 如果计划变更,删除旧明细并重新生成 |
| 81 | + MesDvCheckRecordDO existRecord = checkRecordMapper.selectById(updateReqVO.getId()); | ||
| 77 | Long oldPlanId = existRecord.getPlanId(); | 82 | Long oldPlanId = existRecord.getPlanId(); |
| 78 | Long newPlanId = updateReqVO.getPlanId(); | 83 | Long newPlanId = updateReqVO.getPlanId(); |
| 79 | - boolean planChanged = !java.util.Objects.equals(oldPlanId, newPlanId); | 84 | + boolean planChanged = ObjUtil.notEqual(oldPlanId, newPlanId); |
| 80 | if (planChanged) { | 85 | if (planChanged) { |
| 81 | - checkRecordLineMapper.deleteByRecordId(updateReqVO.getId()); | 86 | + checkRecordLineService.deleteByRecordId(updateReqVO.getId()); |
| 82 | if (newPlanId != null) { | 87 | if (newPlanId != null) { |
| 83 | generateCheckRecordLines(updateReqVO.getId(), newPlanId); | 88 | generateCheckRecordLines(updateReqVO.getId(), newPlanId); |
| 84 | } | 89 | } |
| @@ -94,7 +99,7 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService { | @@ -94,7 +99,7 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService { | ||
| 94 | // 1.1 校验状态为草稿 | 99 | // 1.1 校验状态为草稿 |
| 95 | validateCheckRecordDraft(id); | 100 | validateCheckRecordDraft(id); |
| 96 | // 1.2 校验至少有一条明细 | 101 | // 1.2 校验至少有一条明细 |
| 97 | - List<MesDvCheckRecordLineDO> lines = checkRecordLineMapper.selectListByRecordId(id); | 102 | + List<MesDvCheckRecordLineDO> lines = checkRecordLineService.getCheckRecordLineListByRecordId(id); |
| 98 | if (CollUtil.isEmpty(lines)) { | 103 | if (CollUtil.isEmpty(lines)) { |
| 99 | throw exception(DV_CHECK_RECORD_NO_LINE); | 104 | throw exception(DV_CHECK_RECORD_NO_LINE); |
| 100 | } | 105 | } |
| @@ -114,7 +119,7 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService { | @@ -114,7 +119,7 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService { | ||
| 114 | // 2.1 删除主记录 | 119 | // 2.1 删除主记录 |
| 115 | checkRecordMapper.deleteById(id); | 120 | checkRecordMapper.deleteById(id); |
| 116 | // 2.2 级联删除明细 | 121 | // 2.2 级联删除明细 |
| 117 | - checkRecordLineMapper.deleteByRecordId(id); | 122 | + checkRecordLineService.deleteByRecordId(id); |
| 118 | } | 123 | } |
| 119 | 124 | ||
| 120 | @Override | 125 | @Override |
| @@ -139,12 +144,10 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService { | @@ -139,12 +144,10 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService { | ||
| 139 | return checkRecordMapper.selectPage(pageReqVO); | 144 | return checkRecordMapper.selectPage(pageReqVO); |
| 140 | } | 145 | } |
| 141 | 146 | ||
| 142 | - // ==================== 私有方法 ==================== | 147 | + // ==================== 校验方法 ==================== |
| 143 | 148 | ||
| 144 | - /** | ||
| 145 | - * 校验点检记录为草稿状态 | ||
| 146 | - */ | ||
| 147 | - private MesDvCheckRecordDO validateCheckRecordDraft(Long id) { | 149 | + @Override |
| 150 | + public void validateCheckRecordDraft(Long id) { | ||
| 148 | MesDvCheckRecordDO record = checkRecordMapper.selectById(id); | 151 | MesDvCheckRecordDO record = checkRecordMapper.selectById(id); |
| 149 | if (record == null) { | 152 | if (record == null) { |
| 150 | throw exception(DV_CHECK_RECORD_NOT_EXISTS); | 153 | throw exception(DV_CHECK_RECORD_NOT_EXISTS); |
| @@ -152,16 +155,19 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService { | @@ -152,16 +155,19 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService { | ||
| 152 | if (ObjUtil.notEqual(MesDvCheckRecordStatusEnum.DRAFT.getStatus(), record.getStatus())) { | 155 | if (ObjUtil.notEqual(MesDvCheckRecordStatusEnum.DRAFT.getStatus(), record.getStatus())) { |
| 153 | throw exception(DV_CHECK_RECORD_NOT_DRAFT); | 156 | throw exception(DV_CHECK_RECORD_NOT_DRAFT); |
| 154 | } | 157 | } |
| 155 | - return record; | ||
| 156 | } | 158 | } |
| 157 | 159 | ||
| 158 | - private void validateCheckRecordRelation(MesDvCheckRecordSaveReqVO reqVO) { | 160 | + private void validateCheckRecordSave(MesDvCheckRecordSaveReqVO reqVO) { |
| 159 | // 校验设备是否存在 | 161 | // 校验设备是否存在 |
| 160 | machineryService.validateMachineryExists(reqVO.getMachineryId()); | 162 | machineryService.validateMachineryExists(reqVO.getMachineryId()); |
| 161 | // 校验点检计划是否存在 | 163 | // 校验点检计划是否存在 |
| 162 | if (reqVO.getPlanId() != null) { | 164 | if (reqVO.getPlanId() != null) { |
| 163 | checkPlanService.validateCheckPlanExists(reqVO.getPlanId()); | 165 | checkPlanService.validateCheckPlanExists(reqVO.getPlanId()); |
| 164 | } | 166 | } |
| 167 | + // 校验点检人是否存在 | ||
| 168 | + if (reqVO.getUserId() != null) { | ||
| 169 | + adminUserApi.validateUser(reqVO.getUserId()); | ||
| 170 | + } | ||
| 165 | } | 171 | } |
| 166 | 172 | ||
| 167 | /** | 173 | /** |
| @@ -178,7 +184,7 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService { | @@ -178,7 +184,7 @@ public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService { | ||
| 178 | .setRecordId(recordId).setSubjectId(planSubject.getSubjectId()) | 184 | .setRecordId(recordId).setSubjectId(planSubject.getSubjectId()) |
| 179 | .setCheckStatus(MesDvCheckResultEnum.NORMAL.getResult())); | 185 | .setCheckStatus(MesDvCheckResultEnum.NORMAL.getResult())); |
| 180 | } | 186 | } |
| 181 | - checkRecordLineMapper.insertBatch(lines); | 187 | + checkRecordLineService.createCheckRecordLineList(lines); |
| 182 | } | 188 | } |
| 183 | 189 | ||
| 184 | } | 190 | } |