diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/repair/MesDvRepairController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/repair/MesDvRepairController.java index 127e618..16a987e 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/repair/MesDvRepairController.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/repair/MesDvRepairController.java @@ -31,7 +31,6 @@ import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.stream.Stream; import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; @@ -111,8 +110,28 @@ public class MesDvRepairController { buildRepairRespVOList(list)); } + @PutMapping("/submit") + @Operation(summary = "提交维修工单(草稿→维修中)") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('mes:dv-repair:update')") + public CommonResult submitRepair(@RequestParam("id") Long id) { + repairService.submitRepair(id); + return success(true); + } + + // TODO @AI:submit=>confirm=>finish(然后里面有是 resultstatus 这样的字段【对齐实体?】) + + @PutMapping("/finish") + @Operation(summary = "完成维修(维修中→待验收)") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('mes:dv-repair:update')") + public CommonResult finishRepair(@RequestParam("id") Long id) { + repairService.finishRepair(id); + return success(true); + } + @PutMapping("/confirm") - @Operation(summary = "通过维修工单(草稿→已确认,结果=通过)") + @Operation(summary = "验收通过(待验收→已确认,结果=通过)") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('mes:dv-repair:update')") public CommonResult confirmRepair(@RequestParam("id") Long id) { @@ -121,7 +140,7 @@ public class MesDvRepairController { } @PutMapping("/reject") - @Operation(summary = "不通过维修工单(草稿→已确认,结果=不通过)") + @Operation(summary = "验收不通过(待验收→已确认,结果=不通过)") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('mes:dv-repair:update')") public CommonResult rejectRepair(@RequestParam("id") Long id) { diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/dv/repair/MesDvRepairDO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/dv/repair/MesDvRepairDO.java index 43919c1..2a1a8f1 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/dv/repair/MesDvRepairDO.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/dv/repair/MesDvRepairDO.java @@ -76,7 +76,7 @@ public class MesDvRepairDO extends BaseDO { * 关联 AdminUserDO#getId() */ private Long confirmUserId; - // TODO @芋艿:sourceDocType、sourceDocId、sourceDocCode 需要哪里处理; + // DONE @芋艿:sourceDocType、sourceDocId、sourceDocCode 为预留字段,对齐:暂未使用 /** * 来源单据类型 */ @@ -93,7 +93,6 @@ public class MesDvRepairDO extends BaseDO { * 状态 * * 枚举 {@link MesDvRepairStatusEnum} - * 字典类型 mes_dv_repair_status */ private Integer status; /** diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java index b9053f3..4319c09 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java @@ -177,8 +177,10 @@ public interface ErrorCodeConstants { // ========== MES 设备管理-维修工单(1-040-303-000) ========== ErrorCode DV_REPAIR_NOT_EXISTS = new ErrorCode(1_040_303_000, "维修工单不存在"); - ErrorCode DV_REPAIR_NOT_DRAFT = new ErrorCode(1_040_303_001, "维修工单已确认,不允许修改或删除"); + ErrorCode DV_REPAIR_NOT_PREPARE = new ErrorCode(1_040_303_001, "维修工单不是草稿状态,不允许修改或删除"); ErrorCode DV_REPAIR_CODE_DUPLICATE = new ErrorCode(1_040_303_002, "维修工单编码已存在"); + ErrorCode DV_REPAIR_NOT_CONFIRMED = new ErrorCode(1_040_303_003, "只有维修中状态的维修工单才能完成维修"); + ErrorCode DV_REPAIR_NOT_APPROVING = new ErrorCode(1_040_303_004, "只有待验收状态的维修工单才能验收"); // ========== MES 设备管理-维修工单行(1-040-303-100) ========== ErrorCode DV_REPAIR_LINE_NOT_EXISTS = new ErrorCode(1_040_303_100, "维修工单行不存在"); diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/dv/MesDvRepairStatusEnum.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/dv/MesDvRepairStatusEnum.java index b962070..87f150e 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/dv/MesDvRepairStatusEnum.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/dv/MesDvRepairStatusEnum.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.mes.enums.dv; import cn.iocoder.yudao.framework.common.core.ArrayValuable; +import cn.iocoder.yudao.module.mes.enums.MesOrderStatusConstants; import lombok.AllArgsConstructor; import lombok.Getter; @@ -9,14 +10,35 @@ import java.util.Arrays; /** * MES 维修工单状态枚举 * + * 状态流转:草稿 → 维修中 → 待验收 → 已确认 + * * @author 芋道源码 */ @Getter @AllArgsConstructor public enum MesDvRepairStatusEnum implements ArrayValuable { - DRAFT(10, "草稿"), - CONFIRMED(20, "已确认"); + // TODO @AI:不用 ktg 的注释,里面需要 @ 对应方法,对齐现有项目的规范; + /** + * 草稿 + */ + PREPARE(MesOrderStatusConstants.PREPARE, "草稿"), + /** + * 维修中(提交后,维修人接单) + */ + CONFIRMED(MesOrderStatusConstants.CONFIRMED, "维修中"), + /** + * 待验收(维修完成,等待验收) + * + * 对应 KTG: FINISHED + */ + APPROVING(MesOrderStatusConstants.APPROVING, "待验收"), + /** + * 已确认(验收通过或不通过,终态) + * + * 对应 KTG: CONFIRMED + */ + FINISHED(MesOrderStatusConstants.FINISHED, "已确认"); public static final Integer[] ARRAYS = Arrays.stream(values()).map(MesDvRepairStatusEnum::getStatus).toArray(Integer[]::new); diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/repair/MesDvRepairLineServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/repair/MesDvRepairLineServiceImpl.java index 05201cd..09ee904 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/repair/MesDvRepairLineServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/repair/MesDvRepairLineServiceImpl.java @@ -38,7 +38,7 @@ public class MesDvRepairLineServiceImpl implements MesDvRepairLineService { // 1.1 校验关联数据 validateRepairLineRelation(createReqVO); // 1.2 校验维修工单为草稿状态 - repairService.validateRepairDraft(createReqVO.getRepairId()); + repairService.validateRepairPrepare(createReqVO.getRepairId()); // 2. 插入 MesDvRepairLineDO repairLine = BeanUtils.toBean(createReqVO, MesDvRepairLineDO.class); @@ -53,7 +53,7 @@ public class MesDvRepairLineServiceImpl implements MesDvRepairLineService { // 1.2 校验关联数据 validateRepairLineRelation(updateReqVO); // 1.3 校验维修工单为草稿状态 - repairService.validateRepairDraft(updateReqVO.getRepairId()); + repairService.validateRepairPrepare(updateReqVO.getRepairId()); // 2. 更新 MesDvRepairLineDO updateObj = BeanUtils.toBean(updateReqVO, MesDvRepairLineDO.class); @@ -68,7 +68,7 @@ public class MesDvRepairLineServiceImpl implements MesDvRepairLineService { throw exception(DV_REPAIR_LINE_NOT_EXISTS); } // 1.2 校验维修工单为草稿状态 - repairService.validateRepairDraft(line.getRepairId()); + repairService.validateRepairPrepare(line.getRepairId()); // 2. 删除 repairLineMapper.deleteById(id); diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/repair/MesDvRepairService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/repair/MesDvRepairService.java index 5a7717c..64eb889 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/repair/MesDvRepairService.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/repair/MesDvRepairService.java @@ -40,8 +40,9 @@ public interface MesDvRepairService { * 校验维修工单是否存在 * * @param id 编号 + * @return 维修工单 */ - void validateRepairExists(Long id); + MesDvRepairDO validateRepairExists(Long id); /** * 获得指定设备的维修工单数量 @@ -68,14 +69,28 @@ public interface MesDvRepairService { PageResult getRepairPage(MesDvRepairPageReqVO pageReqVO); /** - * 通过维修工单(草稿→已确认,结果=通过) + * 提交维修工单(草稿→维修中) + * + * @param id 编号 + */ + void submitRepair(Long id); + + /** + * 完成维修(维修中→待验收) + * + * @param id 编号 + */ + void finishRepair(Long id); + + /** + * 验收通过(待验收→已确认,结果=通过) * * @param id 编号 */ void confirmRepair(Long id); /** - * 不通过维修工单(草稿→已确认,结果=不通过) + * 验收不通过(待验收→已确认,结果=不通过) * * @param id 编号 */ diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/repair/MesDvRepairServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/repair/MesDvRepairServiceImpl.java index c9cabdf..e4a0996 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/repair/MesDvRepairServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/repair/MesDvRepairServiceImpl.java @@ -18,6 +18,7 @@ import org.springframework.validation.annotation.Validated; import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; /** @@ -39,15 +40,12 @@ public class MesDvRepairServiceImpl implements MesDvRepairService { @Override public Long createRepair(MesDvRepairSaveReqVO createReqVO) { - // TODO @AI:抽成 validateXXSaveData(vo); - // 1.1 校验关联数据 - validateRepairRelation(createReqVO); - // 1.2 校验编码唯一 - validateCodeUnique(null, createReqVO.getCode()); + // 1. 校验保存数据 + validateSaveData(createReqVO); // 2. 插入 MesDvRepairDO repair = BeanUtils.toBean(createReqVO, MesDvRepairDO.class); - repair.setStatus(MesDvRepairStatusEnum.DRAFT.getStatus()); + repair.setStatus(MesDvRepairStatusEnum.PREPARE.getStatus()); repairMapper.insert(repair); return repair.getId(); } @@ -55,12 +53,9 @@ public class MesDvRepairServiceImpl implements MesDvRepairService { @Override public void updateRepair(MesDvRepairSaveReqVO updateReqVO) { // 1.1 校验存在,且状态为草稿 - validateRepairDraft(updateReqVO.getId()); - // TODO @AI:抽成 validateXXSaveData(vo); - // 1.2 校验关联数据 - validateRepairRelation(updateReqVO); - // 1.3 校验编码唯一 - validateCodeUnique(updateReqVO.getId(), updateReqVO.getCode()); + validateRepairPrepare(updateReqVO.getId()); + // 1.2 校验保存数据 + validateSaveData(updateReqVO); // 2. 更新 MesDvRepairDO updateObj = BeanUtils.toBean(updateReqVO, MesDvRepairDO.class); @@ -71,7 +66,7 @@ public class MesDvRepairServiceImpl implements MesDvRepairService { @Transactional(rollbackFor = Exception.class) public void deleteRepair(Long id) { // 校验存在,且状态为草稿 - validateRepairDraft(id); + validateRepairPrepare(id); // 删除 repairMapper.deleteById(id); @@ -79,8 +74,13 @@ public class MesDvRepairServiceImpl implements MesDvRepairService { repairLineService.deleteByRepairId(id); } - private void validateRepairRelation(MesDvRepairSaveReqVO reqVO) { - // 校验设备是否存在 + /** + * 校验保存时的关联数据 + */ + private void validateSaveData(MesDvRepairSaveReqVO reqVO) { + // 校验编码唯一 + validateCodeUnique(reqVO.getId(), reqVO.getCode()); + // 校验设备存在 machineryService.validateMachineryExists(reqVO.getMachineryId()); } @@ -89,20 +89,21 @@ public class MesDvRepairServiceImpl implements MesDvRepairService { return; } MesDvRepairDO repair = repairMapper.selectByCode(code); - // TODO @AI:参考别的模块,notEquals if (repair == null) { return; } - if (id == null || !id.equals(repair.getId())) { + if (ObjUtil.notEqual(id, repair.getId())) { throw exception(DV_REPAIR_CODE_DUPLICATE); } } @Override - public void validateRepairExists(Long id) { - if (repairMapper.selectById(id) == null) { + public MesDvRepairDO validateRepairExists(Long id) { + MesDvRepairDO repair = repairMapper.selectById(id); + if (repair == null) { throw exception(DV_REPAIR_NOT_EXISTS); } + return repair; } @Override @@ -116,14 +117,10 @@ public class MesDvRepairServiceImpl implements MesDvRepairService { * @param id 编号 * @return 维修工单 */ - public MesDvRepairDO validateRepairDraft(Long id) { - // TODO @AI:复用 validateRepairExists 方法 - MesDvRepairDO repair = repairMapper.selectById(id); - if (repair == null) { - throw exception(DV_REPAIR_NOT_EXISTS); - } - if (ObjUtil.notEqual(MesDvRepairStatusEnum.DRAFT.getStatus(), repair.getStatus())) { - throw exception(DV_REPAIR_NOT_DRAFT); + public MesDvRepairDO validateRepairPrepare(Long id) { + MesDvRepairDO repair = validateRepairExists(id); + if (ObjUtil.notEqual(MesDvRepairStatusEnum.PREPARE.getStatus(), repair.getStatus())) { + throw exception(DV_REPAIR_NOT_PREPARE); } return repair; } @@ -139,26 +136,59 @@ public class MesDvRepairServiceImpl implements MesDvRepairService { } @Override - public void confirmRepair(Long id) { + public void submitRepair(Long id) { // 1. 校验存在,且状态为草稿 - validateRepairDraft(id); + validateRepairPrepare(id); - // 2. 更新状态为已确认,结果为通过,自动设置验收日期 + // 2. 更新状态为维修中,自动设置维修人为当前用户 repairMapper.updateById(new MesDvRepairDO().setId(id) .setStatus(MesDvRepairStatusEnum.CONFIRMED.getStatus()) + .setAcceptedUserId(getLoginUserId())); + } + + @Override + public void finishRepair(Long id) { + // 1. 校验存在,且状态为维修中 + MesDvRepairDO repair = validateRepairExists(id); + if (ObjUtil.notEqual(MesDvRepairStatusEnum.CONFIRMED.getStatus(), repair.getStatus())) { + throw exception(DV_REPAIR_NOT_CONFIRMED); + } + + // 2. 更新状态为待验收,自动设置维修完成日期 + repairMapper.updateById(new MesDvRepairDO().setId(id) + .setStatus(MesDvRepairStatusEnum.APPROVING.getStatus()) + .setFinishDate(LocalDateTime.now())); + } + + @Override + public void confirmRepair(Long id) { + // 1. 校验存在,且状态为待验收 + MesDvRepairDO repair = validateRepairExists(id); + if (ObjUtil.notEqual(MesDvRepairStatusEnum.APPROVING.getStatus(), repair.getStatus())) { + throw exception(DV_REPAIR_NOT_APPROVING); + } + + // 2. 更新状态为已确认,结果为通过,自动设置验收人和验收日期 + repairMapper.updateById(new MesDvRepairDO().setId(id) + .setStatus(MesDvRepairStatusEnum.FINISHED.getStatus()) .setResult(MesDvRepairResultEnum.PASS.getResult()) + .setConfirmUserId(getLoginUserId()) .setConfirmDate(LocalDateTime.now())); } @Override public void rejectRepair(Long id) { - // 1. 校验存在,且状态为草稿 - validateRepairDraft(id); + // 1. 校验存在,且状态为待验收 + MesDvRepairDO repair = validateRepairExists(id); + if (ObjUtil.notEqual(MesDvRepairStatusEnum.APPROVING.getStatus(), repair.getStatus())) { + throw exception(DV_REPAIR_NOT_APPROVING); + } - // 2. 更新状态为已确认,结果为不通过,自动设置验收日期 + // 2. 更新状态为已确认,结果为不通过,自动设置验收人和验收日期 repairMapper.updateById(new MesDvRepairDO().setId(id) - .setStatus(MesDvRepairStatusEnum.CONFIRMED.getStatus()) + .setStatus(MesDvRepairStatusEnum.FINISHED.getStatus()) .setResult(MesDvRepairResultEnum.FAIL.getResult()) + .setConfirmUserId(getLoginUserId()) .setConfirmDate(LocalDateTime.now())); }