Commit 278fe45e7f0589b564477f23846a941d3b7b7012

Authored by YunaiV
1 parent d86453bb

feat(mes): 新增设备点检记录及明细相关功能,包括请求和响应 VO 及控制器

Showing 16 changed files with 1128 additions and 0 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/checkrecord/MesDvCheckRecordController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord;
  2 +
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
  5 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  6 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  7 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  8 +import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
  9 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  10 +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
  11 +import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.MesDvCheckRecordPageReqVO;
  12 +import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.MesDvCheckRecordRespVO;
  13 +import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.MesDvCheckRecordSaveReqVO;
  14 +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkplan.MesDvCheckPlanDO;
  15 +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkrecord.MesDvCheckRecordDO;
  16 +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.machinery.MesDvMachineryDO;
  17 +import cn.iocoder.yudao.module.mes.service.dv.checkplan.MesDvCheckPlanService;
  18 +import cn.iocoder.yudao.module.mes.service.dv.checkrecord.MesDvCheckRecordService;
  19 +import cn.iocoder.yudao.module.mes.service.dv.machinery.MesDvMachineryService;
  20 +import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
  21 +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
  22 +import io.swagger.v3.oas.annotations.Operation;
  23 +import io.swagger.v3.oas.annotations.Parameter;
  24 +import io.swagger.v3.oas.annotations.tags.Tag;
  25 +import jakarta.annotation.Resource;
  26 +import jakarta.servlet.http.HttpServletResponse;
  27 +import jakarta.validation.Valid;
  28 +import org.springframework.security.access.prepost.PreAuthorize;
  29 +import org.springframework.validation.annotation.Validated;
  30 +import org.springframework.web.bind.annotation.*;
  31 +
  32 +import java.io.IOException;
  33 +import java.util.Collections;
  34 +import java.util.List;
  35 +import java.util.Map;
  36 +
  37 +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
  38 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  39 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
  40 +
  41 +@Tag(name = "管理后台 - MES 设备点检记录")
  42 +@RestController
  43 +@RequestMapping("/mes/dv/check-record")
  44 +@Validated
  45 +public class MesDvCheckRecordController {
  46 +
  47 + @Resource
  48 + private MesDvCheckRecordService checkRecordService;
  49 +
  50 + @Resource
  51 + private MesDvCheckPlanService checkPlanService;
  52 +
  53 + @Resource
  54 + private MesDvMachineryService machineryService;
  55 +
  56 + @Resource
  57 + private AdminUserApi adminUserApi;
  58 +
  59 + @PostMapping("/create")
  60 + @Operation(summary = "创建设备点检记录")
  61 + @PreAuthorize("@ss.hasPermission('mes:dv-check-record:create')")
  62 + public CommonResult<Long> createCheckRecord(@Valid @RequestBody MesDvCheckRecordSaveReqVO createReqVO) {
  63 + return success(checkRecordService.createCheckRecord(createReqVO));
  64 + }
  65 +
  66 + @PutMapping("/update")
  67 + @Operation(summary = "更新设备点检记录")
  68 + @PreAuthorize("@ss.hasPermission('mes:dv-check-record:update')")
  69 + public CommonResult<Boolean> updateCheckRecord(@Valid @RequestBody MesDvCheckRecordSaveReqVO updateReqVO) {
  70 + checkRecordService.updateCheckRecord(updateReqVO);
  71 + return success(true);
  72 + }
  73 +
  74 + @PutMapping("/submit")
  75 + @Operation(summary = "提交设备点检记录(待点检→已完成)")
  76 + @Parameter(name = "id", description = "编号", required = true)
  77 + @PreAuthorize("@ss.hasPermission('mes:dv-check-record:update')")
  78 + public CommonResult<Boolean> submitCheckRecord(@RequestParam("id") Long id) {
  79 + checkRecordService.submitCheckRecord(id);
  80 + return success(true);
  81 + }
  82 +
  83 + @DeleteMapping("/delete")
  84 + @Operation(summary = "删除设备点检记录")
  85 + @Parameter(name = "id", description = "编号", required = true)
  86 + @PreAuthorize("@ss.hasPermission('mes:dv-check-record:delete')")
  87 + public CommonResult<Boolean> deleteCheckRecord(@RequestParam("id") Long id) {
  88 + checkRecordService.deleteCheckRecord(id);
  89 + return success(true);
  90 + }
  91 +
  92 + @GetMapping("/get")
  93 + @Operation(summary = "获得设备点检记录")
  94 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  95 + @PreAuthorize("@ss.hasPermission('mes:dv-check-record:query')")
  96 + public CommonResult<MesDvCheckRecordRespVO> getCheckRecord(@RequestParam("id") Long id) {
  97 + MesDvCheckRecordDO checkRecord = checkRecordService.getCheckRecord(id);
  98 + if (checkRecord == null) {
  99 + return success(null);
  100 + }
  101 + return success(buildCheckRecordRespVOList(Collections.singletonList(checkRecord)).get(0));
  102 + }
  103 +
  104 + @GetMapping("/page")
  105 + @Operation(summary = "获得设备点检记录分页")
  106 + @PreAuthorize("@ss.hasPermission('mes:dv-check-record:query')")
  107 + public CommonResult<PageResult<MesDvCheckRecordRespVO>> getCheckRecordPage(@Valid MesDvCheckRecordPageReqVO pageReqVO) {
  108 + PageResult<MesDvCheckRecordDO> pageResult = checkRecordService.getCheckRecordPage(pageReqVO);
  109 + return success(new PageResult<>(buildCheckRecordRespVOList(pageResult.getList()), pageResult.getTotal()));
  110 + }
  111 +
  112 + @GetMapping("/export-excel")
  113 + @Operation(summary = "导出设备点检记录 Excel")
  114 + @PreAuthorize("@ss.hasPermission('mes:dv-check-record:export')")
  115 + @ApiAccessLog(operateType = EXPORT)
  116 + public void exportCheckRecordExcel(@Valid MesDvCheckRecordPageReqVO pageReqVO,
  117 + HttpServletResponse response) throws IOException {
  118 + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
  119 + List<MesDvCheckRecordDO> list = checkRecordService.getCheckRecordPage(pageReqVO).getList();
  120 + ExcelUtils.write(response, "设备点检记录.xls", "数据", MesDvCheckRecordRespVO.class,
  121 + buildCheckRecordRespVOList(list));
  122 + }
  123 +
  124 + // ==================== 拼接 VO ====================
  125 +
  126 + @SuppressWarnings("DuplicatedCode")
  127 + private List<MesDvCheckRecordRespVO> buildCheckRecordRespVOList(List<MesDvCheckRecordDO> list) {
  128 + if (CollUtil.isEmpty(list)) {
  129 + return Collections.emptyList();
  130 + }
  131 + // 1. 批量获取关联数据
  132 + Map<Long, MesDvCheckPlanDO> planMap = checkPlanService.getCheckPlanMap(
  133 + convertSet(list, MesDvCheckRecordDO::getPlanId));
  134 + Map<Long, MesDvMachineryDO> machineryMap = machineryService.getMachineryMap(
  135 + convertSet(list, MesDvCheckRecordDO::getMachineryId));
  136 + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
  137 + convertSet(list, MesDvCheckRecordDO::getUserId));
  138 + // 2. 拼接 VO
  139 + return BeanUtils.toBean(list, MesDvCheckRecordRespVO.class, vo -> {
  140 + MapUtils.findAndThen(planMap, vo.getPlanId(),
  141 + plan -> vo.setPlanName(plan.getName()));
  142 + MapUtils.findAndThen(machineryMap, vo.getMachineryId(), machinery -> vo
  143 + .setMachineryCode(machinery.getCode()).setMachineryName(machinery.getName())
  144 + .setMachineryBrand(machinery.getBrand()).setMachinerySpec(machinery.getSpec()));
  145 + MapUtils.findAndThen(userMap, vo.getUserId(),
  146 + user -> vo.setNickname(user.getNickname()));
  147 + });
  148 + }
  149 +
  150 +}
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/checkrecord/MesDvCheckRecordLineController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord;
  2 +
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
  7 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  8 +import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.line.MesDvCheckRecordLinePageReqVO;
  9 +import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.line.MesDvCheckRecordLineRespVO;
  10 +import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.line.MesDvCheckRecordLineSaveReqVO;
  11 +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkrecord.MesDvCheckRecordLineDO;
  12 +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.subject.MesDvSubjectDO;
  13 +import cn.iocoder.yudao.module.mes.service.dv.checkrecord.MesDvCheckRecordLineService;
  14 +import cn.iocoder.yudao.module.mes.service.dv.subject.MesDvSubjectService;
  15 +import io.swagger.v3.oas.annotations.Operation;
  16 +import io.swagger.v3.oas.annotations.Parameter;
  17 +import io.swagger.v3.oas.annotations.tags.Tag;
  18 +import jakarta.annotation.Resource;
  19 +import jakarta.validation.Valid;
  20 +import org.springframework.security.access.prepost.PreAuthorize;
  21 +import org.springframework.validation.annotation.Validated;
  22 +import org.springframework.web.bind.annotation.*;
  23 +
  24 +import java.util.Collections;
  25 +import java.util.List;
  26 +import java.util.Map;
  27 +
  28 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  29 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
  30 +
  31 +@Tag(name = "管理后台 - MES 设备点检记录明细")
  32 +@RestController
  33 +@RequestMapping("/mes/dv/check-record-line")
  34 +@Validated
  35 +public class MesDvCheckRecordLineController {
  36 +
  37 + @Resource
  38 + private MesDvCheckRecordLineService checkRecordLineService;
  39 +
  40 + @Resource
  41 + private MesDvSubjectService subjectService;
  42 +
  43 + @PostMapping("/create")
  44 + @Operation(summary = "创建设备点检记录明细")
  45 + @PreAuthorize("@ss.hasPermission('mes:dv-check-record:create')")
  46 + public CommonResult<Long> createCheckRecordLine(@Valid @RequestBody MesDvCheckRecordLineSaveReqVO createReqVO) {
  47 + return success(checkRecordLineService.createCheckRecordLine(createReqVO));
  48 + }
  49 +
  50 + @PutMapping("/update")
  51 + @Operation(summary = "更新设备点检记录明细")
  52 + @PreAuthorize("@ss.hasPermission('mes:dv-check-record:update')")
  53 + public CommonResult<Boolean> updateCheckRecordLine(@Valid @RequestBody MesDvCheckRecordLineSaveReqVO updateReqVO) {
  54 + checkRecordLineService.updateCheckRecordLine(updateReqVO);
  55 + return success(true);
  56 + }
  57 +
  58 + @DeleteMapping("/delete")
  59 + @Operation(summary = "删除设备点检记录明细")
  60 + @Parameter(name = "id", description = "编号", required = true)
  61 + @PreAuthorize("@ss.hasPermission('mes:dv-check-record:delete')")
  62 + public CommonResult<Boolean> deleteCheckRecordLine(@RequestParam("id") Long id) {
  63 + checkRecordLineService.deleteCheckRecordLine(id);
  64 + return success(true);
  65 + }
  66 +
  67 + @GetMapping("/get")
  68 + @Operation(summary = "获得设备点检记录明细")
  69 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  70 + @PreAuthorize("@ss.hasPermission('mes:dv-check-record:query')")
  71 + public CommonResult<MesDvCheckRecordLineRespVO> getCheckRecordLine(@RequestParam("id") Long id) {
  72 + MesDvCheckRecordLineDO line = checkRecordLineService.getCheckRecordLine(id);
  73 + if (line == null) {
  74 + return success(null);
  75 + }
  76 + return success(buildCheckRecordLineRespVOList(Collections.singletonList(line)).get(0));
  77 + }
  78 +
  79 + @GetMapping("/page")
  80 + @Operation(summary = "获得设备点检记录明细分页")
  81 + @PreAuthorize("@ss.hasPermission('mes:dv-check-record:query')")
  82 + public CommonResult<PageResult<MesDvCheckRecordLineRespVO>> getCheckRecordLinePage(@Valid MesDvCheckRecordLinePageReqVO pageReqVO) {
  83 + PageResult<MesDvCheckRecordLineDO> pageResult = checkRecordLineService.getCheckRecordLinePage(pageReqVO);
  84 + return success(new PageResult<>(buildCheckRecordLineRespVOList(pageResult.getList()), pageResult.getTotal()));
  85 + }
  86 +
  87 + // ==================== 拼接 VO ====================
  88 +
  89 + private List<MesDvCheckRecordLineRespVO> buildCheckRecordLineRespVOList(List<MesDvCheckRecordLineDO> list) {
  90 + if (CollUtil.isEmpty(list)) {
  91 + return Collections.emptyList();
  92 + }
  93 + // 1. 批量获取关联数据
  94 + Map<Long, MesDvSubjectDO> subjectMap = subjectService.getSubjectMap(
  95 + convertSet(list, MesDvCheckRecordLineDO::getSubjectId));
  96 + // 2. 拼接 VO
  97 + return BeanUtils.toBean(list, MesDvCheckRecordLineRespVO.class, 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())));
  103 + }
  104 +
  105 +}
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/checkrecord/vo/MesDvCheckRecordPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +import lombok.Data;
  6 +import lombok.EqualsAndHashCode;
  7 +import lombok.ToString;
  8 +import org.springframework.format.annotation.DateTimeFormat;
  9 +
  10 +import java.time.LocalDateTime;
  11 +
  12 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  13 +
  14 +@Schema(description = "管理后台 - MES 设备点检记录分页 Request VO")
  15 +@Data
  16 +@EqualsAndHashCode(callSuper = true)
  17 +@ToString(callSuper = true)
  18 +public class MesDvCheckRecordPageReqVO extends PageParam {
  19 +
  20 + @Schema(description = "点检计划编号", example = "1")
  21 + private Long planId;
  22 +
  23 + @Schema(description = "设备编号", example = "1")
  24 + private Long machineryId;
  25 +
  26 + @Schema(description = "点检人编号", example = "1")
  27 + private Long userId;
  28 +
  29 + @Schema(description = "状态", example = "10")
  30 + private Integer status;
  31 +
  32 + @Schema(description = "点检时间")
  33 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  34 + private LocalDateTime[] checkTime;
  35 +
  36 +}
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/checkrecord/vo/MesDvCheckRecordRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo;
  2 +
  3 +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
  4 +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
  5 +import cn.iocoder.yudao.module.mes.enums.DictTypeConstants;
  6 +import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
  7 +import cn.idev.excel.annotation.ExcelProperty;
  8 +import io.swagger.v3.oas.annotations.media.Schema;
  9 +import lombok.Data;
  10 +
  11 +import java.time.LocalDateTime;
  12 +
  13 +@Schema(description = "管理后台 - MES 设备点检记录 Response VO")
  14 +@Data
  15 +@ExcelIgnoreUnannotated
  16 +public class MesDvCheckRecordRespVO {
  17 +
  18 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
  19 + @ExcelProperty("编号")
  20 + private Long id;
  21 +
  22 + @Schema(description = "点检计划编号", example = "1")
  23 + private Long planId;
  24 +
  25 + @Schema(description = "计划名称", example = "日常点检计划")
  26 + @ExcelProperty("计划名称")
  27 + private String planName;
  28 +
  29 + @Schema(description = "计划类型", example = "1")
  30 + private Integer planType;
  31 +
  32 + @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  33 + private Long machineryId;
  34 +
  35 + @Schema(description = "设备编码", example = "M001")
  36 + @ExcelProperty("设备编码")
  37 + private String machineryCode;
  38 +
  39 + @Schema(description = "设备名称", example = "机床A")
  40 + @ExcelProperty("设备名称")
  41 + private String machineryName;
  42 +
  43 + @Schema(description = "品牌", example = "西门子")
  44 + @ExcelProperty("品牌")
  45 + private String machineryBrand;
  46 +
  47 + @Schema(description = "规格型号", example = "X-100")
  48 + @ExcelProperty("规格型号")
  49 + private String machinerySpec;
  50 +
  51 + @Schema(description = "点检时间", requiredMode = Schema.RequiredMode.REQUIRED)
  52 + @ExcelProperty("点检时间")
  53 + private LocalDateTime checkTime;
  54 +
  55 + @Schema(description = "点检人编号", example = "1")
  56 + private Long userId;
  57 +
  58 + @Schema(description = "点检人名称", example = "张三")
  59 + @ExcelProperty("点检人")
  60 + private String nickname;
  61 +
  62 + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
  63 + @ExcelProperty(value = "状态", converter = DictConvert.class)
  64 + @DictFormat(DictTypeConstants.MES_DV_CHECK_RECORD_STATUS)
  65 + private Integer status;
  66 +
  67 + @Schema(description = "备注", example = "测试备注")
  68 + @ExcelProperty("备注")
  69 + private String remark;
  70 +
  71 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  72 + @ExcelProperty("创建时间")
  73 + private LocalDateTime createTime;
  74 +
  75 +}
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/checkrecord/vo/MesDvCheckRecordSaveReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +import jakarta.validation.constraints.NotNull;
  7 +import java.time.LocalDateTime;
  8 +
  9 +@Schema(description = "管理后台 - MES 设备点检记录新增/修改 Request VO")
  10 +@Data
  11 +public class MesDvCheckRecordSaveReqVO {
  12 +
  13 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "1024")
  14 + private Long id;
  15 +
  16 + @Schema(description = "点检计划编号", example = "1")
  17 + private Long planId;
  18 +
  19 + @Schema(description = "计划类型", example = "1")
  20 + private Integer planType;
  21 +
  22 + @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  23 + @NotNull(message = "设备不能为空")
  24 + private Long machineryId;
  25 +
  26 + @Schema(description = "点检时间", requiredMode = Schema.RequiredMode.REQUIRED)
  27 + @NotNull(message = "点检时间不能为空")
  28 + private LocalDateTime checkTime;
  29 +
  30 + @Schema(description = "点检人编号", example = "1")
  31 + private Long userId;
  32 +
  33 + @Schema(description = "状态", example = "10")
  34 + private Integer status;
  35 +
  36 + @Schema(description = "备注", example = "测试备注")
  37 + private String remark;
  38 +
  39 +}
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/checkrecord/vo/line/MesDvCheckRecordLinePageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.line;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +import lombok.Data;
  6 +import lombok.EqualsAndHashCode;
  7 +import lombok.ToString;
  8 +
  9 +@Schema(description = "管理后台 - MES 设备点检记录明细分页 Request VO")
  10 +@Data
  11 +@EqualsAndHashCode(callSuper = true)
  12 +@ToString(callSuper = true)
  13 +public class MesDvCheckRecordLinePageReqVO extends PageParam {
  14 +
  15 + @Schema(description = "点检记录编号", example = "1")
  16 + private Long recordId;
  17 +
  18 +}
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/checkrecord/vo/line/MesDvCheckRecordLineRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.line;
  2 +
  3 +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
  4 +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
  5 +import cn.iocoder.yudao.module.mes.enums.DictTypeConstants;
  6 +import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
  7 +import cn.idev.excel.annotation.ExcelProperty;
  8 +import io.swagger.v3.oas.annotations.media.Schema;
  9 +import lombok.Data;
  10 +
  11 +import java.time.LocalDateTime;
  12 +
  13 +@Schema(description = "管理后台 - MES 设备点检记录明细 Response VO")
  14 +@Data
  15 +@ExcelIgnoreUnannotated
  16 +public class MesDvCheckRecordLineRespVO {
  17 +
  18 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
  19 + @ExcelProperty("编号")
  20 + private Long id;
  21 +
  22 + @Schema(description = "点检记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  23 + private Long recordId;
  24 +
  25 + @Schema(description = "点检项目编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  26 + private Long subjectId;
  27 +
  28 + @Schema(description = "项目编码", example = "S001")
  29 + @ExcelProperty("项目编码")
  30 + private String subjectCode;
  31 +
  32 + @Schema(description = "项目名称", example = "润滑油检查")
  33 + @ExcelProperty("项目名称")
  34 + private String subjectName;
  35 +
  36 + @Schema(description = "检查内容", example = "检查润滑油是否充足")
  37 + @ExcelProperty("检查内容")
  38 + private String subjectContent;
  39 +
  40 + @Schema(description = "检查标准", example = "油位不低于最低刻度")
  41 + @ExcelProperty("检查标准")
  42 + private String subjectStandard;
  43 +
  44 + @Schema(description = "点检结果(Y=正常,N=异常)", requiredMode = Schema.RequiredMode.REQUIRED, example = "Y")
  45 + @ExcelProperty(value = "点检结果", converter = DictConvert.class)
  46 + @DictFormat(DictTypeConstants.MES_DV_CHECK_RESULT)
  47 + private String checkStatus;
  48 +
  49 + @Schema(description = "异常描述", example = "设备异响")
  50 + @ExcelProperty("异常描述")
  51 + private String checkResult;
  52 +
  53 + @Schema(description = "备注", example = "测试备注")
  54 + @ExcelProperty("备注")
  55 + private String remark;
  56 +
  57 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  58 + @ExcelProperty("创建时间")
  59 + private LocalDateTime createTime;
  60 +
  61 +}
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/checkrecord/vo/line/MesDvCheckRecordLineSaveReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.line;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +import jakarta.validation.constraints.NotNull;
  7 +
  8 +@Schema(description = "管理后台 - MES 设备点检记录明细新增/修改 Request VO")
  9 +@Data
  10 +public class MesDvCheckRecordLineSaveReqVO {
  11 +
  12 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "1024")
  13 + private Long id;
  14 +
  15 + @Schema(description = "点检记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  16 + @NotNull(message = "点检记录不能为空")
  17 + private Long recordId;
  18 +
  19 + @Schema(description = "点检项目编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  20 + @NotNull(message = "点检项目不能为空")
  21 + private Long subjectId;
  22 +
  23 + @Schema(description = "点检结果(Y=正常,N=异常)", requiredMode = Schema.RequiredMode.REQUIRED, example = "Y")
  24 + @NotNull(message = "点检结果不能为空")
  25 + private String checkStatus;
  26 +
  27 + @Schema(description = "异常描述", example = "设备异响")
  28 + private String checkResult;
  29 +
  30 + @Schema(description = "备注", example = "测试备注")
  31 + private String remark;
  32 +
  33 +}
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/dv/checkrecord/MesDvCheckRecordDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkrecord;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkplan.MesDvCheckPlanDO;
  5 +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.machinery.MesDvMachineryDO;
  6 +import com.baomidou.mybatisplus.annotation.KeySequence;
  7 +import com.baomidou.mybatisplus.annotation.TableId;
  8 +import com.baomidou.mybatisplus.annotation.TableName;
  9 +import lombok.*;
  10 +
  11 +import java.time.LocalDateTime;
  12 +
  13 +/**
  14 + * MES 设备点检记录 DO
  15 + *
  16 + * @author 芋道源码
  17 + */
  18 +@TableName("mes_dv_check_record")
  19 +@KeySequence("mes_dv_check_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  20 +@Data
  21 +@EqualsAndHashCode(callSuper = true)
  22 +@ToString(callSuper = true)
  23 +@Builder
  24 +@NoArgsConstructor
  25 +@AllArgsConstructor
  26 +public class MesDvCheckRecordDO extends BaseDO {
  27 +
  28 + /**
  29 + * 编号
  30 + */
  31 + @TableId
  32 + private Long id;
  33 + /**
  34 + * 点检计划编号
  35 + *
  36 + * 关联 {@link MesDvCheckPlanDO#getId()}
  37 + */
  38 + private Long planId;
  39 + // TODO @AI:这个字段可以移除;
  40 + /**
  41 + * 计划类型
  42 + *
  43 + * 字典类型 mes_dv_check_plan_type(与计划保持冗余,避免 JOIN)
  44 + */
  45 + private Integer planType;
  46 + /**
  47 + * 设备编号
  48 + *
  49 + * 关联 {@link MesDvMachineryDO#getId()}
  50 + */
  51 + private Long machineryId;
  52 + /**
  53 + * 点检时间
  54 + */
  55 + private LocalDateTime checkTime;
  56 + /**
  57 + * 点检人编号
  58 + *
  59 + * 关联 AdminUserDO#getId()
  60 + */
  61 + private Long userId;
  62 + // TODO @AI:枚举、字典;
  63 + /**
  64 + * 状态
  65 + *
  66 + * 字典类型 mes_dv_check_record_status(10=待点检,20=已完成)
  67 + */
  68 + private Integer status;
  69 + /**
  70 + * 备注
  71 + */
  72 + private String remark;
  73 +
  74 +}
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/dv/checkrecord/MesDvCheckRecordLineDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkrecord;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.subject.MesDvSubjectDO;
  5 +import com.baomidou.mybatisplus.annotation.KeySequence;
  6 +import com.baomidou.mybatisplus.annotation.TableId;
  7 +import com.baomidou.mybatisplus.annotation.TableName;
  8 +import lombok.*;
  9 +
  10 +/**
  11 + * MES 设备点检记录明细 DO
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@TableName("mes_dv_check_record_line")
  16 +@KeySequence("mes_dv_check_record_line_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  17 +@Data
  18 +@EqualsAndHashCode(callSuper = true)
  19 +@ToString(callSuper = true)
  20 +@Builder
  21 +@NoArgsConstructor
  22 +@AllArgsConstructor
  23 +public class MesDvCheckRecordLineDO extends BaseDO {
  24 +
  25 + /**
  26 + * 编号
  27 + */
  28 + @TableId
  29 + private Long id;
  30 + /**
  31 + * 点检记录编号
  32 + *
  33 + * 关联 {@link MesDvCheckRecordDO#getId()}
  34 + */
  35 + private Long recordId;
  36 + /**
  37 + * 点检项目编号
  38 + *
  39 + * 关联 {@link MesDvSubjectDO#getId()}
  40 + */
  41 + private Long subjectId;
  42 + // TODO @AI:应该使用 int;
  43 + /**
  44 + * 点检结果
  45 + *
  46 + * 字典类型 mes_dv_check_result(Y=正常,N=异常)
  47 + */
  48 + private String checkStatus;
  49 + // TODO @AI:需要标注下,checkStatus 才有使用;
  50 + /**
  51 + * 异常描述
  52 + */
  53 + private String checkResult;
  54 + /**
  55 + * 备注
  56 + */
  57 + private String remark;
  58 +
  59 +}
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/dv/checkrecord/MesDvCheckRecordLineMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.dal.mysql.dv.checkrecord;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.line.MesDvCheckRecordLinePageReqVO;
  7 +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkrecord.MesDvCheckRecordLineDO;
  8 +import org.apache.ibatis.annotations.Mapper;
  9 +
  10 +import java.util.List;
  11 +
  12 +/**
  13 + * MES 设备点检记录明细 Mapper
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@Mapper
  18 +public interface MesDvCheckRecordLineMapper extends BaseMapperX<MesDvCheckRecordLineDO> {
  19 +
  20 + default PageResult<MesDvCheckRecordLineDO> selectPage(MesDvCheckRecordLinePageReqVO reqVO) {
  21 + return selectPage(reqVO, new LambdaQueryWrapperX<MesDvCheckRecordLineDO>()
  22 + .eqIfPresent(MesDvCheckRecordLineDO::getRecordId, reqVO.getRecordId())
  23 + .orderByDesc(MesDvCheckRecordLineDO::getId));
  24 + }
  25 +
  26 + default List<MesDvCheckRecordLineDO> selectListByRecordId(Long recordId) {
  27 + return selectList(MesDvCheckRecordLineDO::getRecordId, recordId);
  28 + }
  29 +
  30 + default int deleteByRecordId(Long recordId) {
  31 + return delete(MesDvCheckRecordLineDO::getRecordId, recordId);
  32 + }
  33 +
  34 +}
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/dv/checkrecord/MesDvCheckRecordMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.dal.mysql.dv.checkrecord;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.MesDvCheckRecordPageReqVO;
  7 +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkrecord.MesDvCheckRecordDO;
  8 +import org.apache.ibatis.annotations.Mapper;
  9 +
  10 +/**
  11 + * MES 设备点检记录 Mapper
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@Mapper
  16 +public interface MesDvCheckRecordMapper extends BaseMapperX<MesDvCheckRecordDO> {
  17 +
  18 + default PageResult<MesDvCheckRecordDO> selectPage(MesDvCheckRecordPageReqVO reqVO) {
  19 + return selectPage(reqVO, new LambdaQueryWrapperX<MesDvCheckRecordDO>()
  20 + .eqIfPresent(MesDvCheckRecordDO::getPlanId, reqVO.getPlanId())
  21 + .eqIfPresent(MesDvCheckRecordDO::getMachineryId, reqVO.getMachineryId())
  22 + .eqIfPresent(MesDvCheckRecordDO::getUserId, reqVO.getUserId())
  23 + .eqIfPresent(MesDvCheckRecordDO::getStatus, reqVO.getStatus())
  24 + .betweenIfPresent(MesDvCheckRecordDO::getCheckTime, reqVO.getCheckTime())
  25 + .orderByDesc(MesDvCheckRecordDO::getId));
  26 + }
  27 +
  28 +}
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkrecord/MesDvCheckRecordLineService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.service.dv.checkrecord;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.line.MesDvCheckRecordLinePageReqVO;
  5 +import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.line.MesDvCheckRecordLineSaveReqVO;
  6 +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkrecord.MesDvCheckRecordLineDO;
  7 +
  8 +import jakarta.validation.Valid;
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * MES 设备点检记录明细 Service 接口
  13 + *
  14 + * @author 芋道源码
  15 + */
  16 +public interface MesDvCheckRecordLineService {
  17 +
  18 + /**
  19 + * 创建点检记录明细
  20 + *
  21 + * @param createReqVO 创建信息
  22 + * @return 编号
  23 + */
  24 + Long createCheckRecordLine(@Valid MesDvCheckRecordLineSaveReqVO createReqVO);
  25 +
  26 + /**
  27 + * 更新点检记录明细
  28 + *
  29 + * @param updateReqVO 更新信息
  30 + */
  31 + void updateCheckRecordLine(@Valid MesDvCheckRecordLineSaveReqVO updateReqVO);
  32 +
  33 + /**
  34 + * 删除点检记录明细
  35 + *
  36 + * @param id 编号
  37 + */
  38 + void deleteCheckRecordLine(Long id);
  39 +
  40 + /**
  41 + * 根据点检记录编号删除所有明细
  42 + *
  43 + * @param recordId 点检记录编号
  44 + */
  45 + void deleteByRecordId(Long recordId);
  46 +
  47 + /**
  48 + * 校验点检记录明细存在
  49 + *
  50 + * @param id 编号
  51 + */
  52 + void validateCheckRecordLineExists(Long id);
  53 +
  54 + /**
  55 + * 获得点检记录明细
  56 + *
  57 + * @param id 编号
  58 + * @return 点检记录明细
  59 + */
  60 + MesDvCheckRecordLineDO getCheckRecordLine(Long id);
  61 +
  62 + /**
  63 + * 获得点检记录明细分页
  64 + *
  65 + * @param pageReqVO 分页查询
  66 + * @return 点检记录明细分页
  67 + */
  68 + PageResult<MesDvCheckRecordLineDO> getCheckRecordLinePage(MesDvCheckRecordLinePageReqVO pageReqVO);
  69 +
  70 + /**
  71 + * 获得指定点检记录的所有明细
  72 + *
  73 + * @param recordId 点检记录编号
  74 + * @return 明细列表
  75 + */
  76 + List<MesDvCheckRecordLineDO> getCheckRecordLineListByRecordId(Long recordId);
  77 +
  78 +}
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkrecord/MesDvCheckRecordLineServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.service.dv.checkrecord;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  5 +import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.line.MesDvCheckRecordLinePageReqVO;
  6 +import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.line.MesDvCheckRecordLineSaveReqVO;
  7 +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkrecord.MesDvCheckRecordLineDO;
  8 +import cn.iocoder.yudao.module.mes.dal.mysql.dv.checkrecord.MesDvCheckRecordLineMapper;
  9 +import jakarta.annotation.Resource;
  10 +import org.springframework.stereotype.Service;
  11 +import org.springframework.validation.annotation.Validated;
  12 +
  13 +import java.util.List;
  14 +
  15 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  16 +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.DV_CHECK_RECORD_LINE_NOT_EXISTS;
  17 +
  18 +/**
  19 + * MES 设备点检记录明细 Service 实现类
  20 + *
  21 + * @author 芋道源码
  22 + */
  23 +@Service
  24 +@Validated
  25 +public class MesDvCheckRecordLineServiceImpl implements MesDvCheckRecordLineService {
  26 +
  27 + @Resource
  28 + private MesDvCheckRecordLineMapper checkRecordLineMapper;
  29 +
  30 + @Override
  31 + public Long createCheckRecordLine(MesDvCheckRecordLineSaveReqVO createReqVO) {
  32 + // TODO @AI:校验下存在
  33 + MesDvCheckRecordLineDO line = BeanUtils.toBean(createReqVO, MesDvCheckRecordLineDO.class);
  34 + checkRecordLineMapper.insert(line);
  35 + return line.getId();
  36 + }
  37 +
  38 + @Override
  39 + public void updateCheckRecordLine(MesDvCheckRecordLineSaveReqVO updateReqVO) {
  40 + // TODO @AI:校验下存在
  41 + // 校验存在
  42 + validateCheckRecordLineExists(updateReqVO.getId());
  43 +
  44 + // 更新
  45 + MesDvCheckRecordLineDO updateObj = BeanUtils.toBean(updateReqVO, MesDvCheckRecordLineDO.class);
  46 + checkRecordLineMapper.updateById(updateObj);
  47 + }
  48 +
  49 + @Override
  50 + public void deleteCheckRecordLine(Long id) {
  51 + // 校验存在
  52 + validateCheckRecordLineExists(id);
  53 + // 删除
  54 + checkRecordLineMapper.deleteById(id);
  55 + }
  56 +
  57 + @Override
  58 + public void deleteByRecordId(Long recordId) {
  59 + checkRecordLineMapper.deleteByRecordId(recordId);
  60 + }
  61 +
  62 + @Override
  63 + public void validateCheckRecordLineExists(Long id) {
  64 + if (checkRecordLineMapper.selectById(id) == null) {
  65 + throw exception(DV_CHECK_RECORD_LINE_NOT_EXISTS);
  66 + }
  67 + }
  68 +
  69 + @Override
  70 + public MesDvCheckRecordLineDO getCheckRecordLine(Long id) {
  71 + return checkRecordLineMapper.selectById(id);
  72 + }
  73 +
  74 + @Override
  75 + public PageResult<MesDvCheckRecordLineDO> getCheckRecordLinePage(MesDvCheckRecordLinePageReqVO pageReqVO) {
  76 + return checkRecordLineMapper.selectPage(pageReqVO);
  77 + }
  78 +
  79 + @Override
  80 + public List<MesDvCheckRecordLineDO> getCheckRecordLineListByRecordId(Long recordId) {
  81 + return checkRecordLineMapper.selectListByRecordId(recordId);
  82 + }
  83 +
  84 +}
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkrecord/MesDvCheckRecordService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.service.dv.checkrecord;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.MesDvCheckRecordPageReqVO;
  5 +import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.MesDvCheckRecordSaveReqVO;
  6 +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkrecord.MesDvCheckRecordDO;
  7 +
  8 +import jakarta.validation.Valid;
  9 +
  10 +/**
  11 + * MES 设备点检记录 Service 接口
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +public interface MesDvCheckRecordService {
  16 +
  17 + /**
  18 + * 创建设备点检记录
  19 + *
  20 + * @param createReqVO 创建信息
  21 + * @return 编号
  22 + */
  23 + Long createCheckRecord(@Valid MesDvCheckRecordSaveReqVO createReqVO);
  24 +
  25 + /**
  26 + * 更新设备点检记录
  27 + *
  28 + * @param updateReqVO 更新信息
  29 + */
  30 + void updateCheckRecord(@Valid MesDvCheckRecordSaveReqVO updateReqVO);
  31 +
  32 + /**
  33 + * 提交点检记录(状态从待点检变为已完成)
  34 + *
  35 + * @param id 编号
  36 + */
  37 + void submitCheckRecord(Long id);
  38 +
  39 + /**
  40 + * 删除设备点检记录
  41 + *
  42 + * @param id 编号
  43 + */
  44 + void deleteCheckRecord(Long id);
  45 +
  46 + /**
  47 + * 校验设备点检记录存在
  48 + *
  49 + * @param id 编号
  50 + */
  51 + void validateCheckRecordExists(Long id);
  52 +
  53 + /**
  54 + * 获得设备点检记录
  55 + *
  56 + * @param id 编号
  57 + * @return 设备点检记录
  58 + */
  59 + MesDvCheckRecordDO getCheckRecord(Long id);
  60 +
  61 + /**
  62 + * 获得设备点检记录分页
  63 + *
  64 + * @param pageReqVO 分页查询
  65 + * @return 设备点检记录分页
  66 + */
  67 + PageResult<MesDvCheckRecordDO> getCheckRecordPage(MesDvCheckRecordPageReqVO pageReqVO);
  68 +
  69 +}
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/checkrecord/MesDvCheckRecordServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.service.dv.checkrecord;
  2 +
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  5 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  6 +import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.MesDvCheckRecordPageReqVO;
  7 +import cn.iocoder.yudao.module.mes.controller.admin.dv.checkrecord.vo.MesDvCheckRecordSaveReqVO;
  8 +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkplan.MesDvCheckPlanSubjectDO;
  9 +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkrecord.MesDvCheckRecordDO;
  10 +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkrecord.MesDvCheckRecordLineDO;
  11 +import cn.iocoder.yudao.module.mes.dal.mysql.dv.checkrecord.MesDvCheckRecordLineMapper;
  12 +import cn.iocoder.yudao.module.mes.dal.mysql.dv.checkrecord.MesDvCheckRecordMapper;
  13 +import cn.iocoder.yudao.module.mes.service.dv.checkplan.MesDvCheckPlanService;
  14 +import cn.iocoder.yudao.module.mes.service.dv.checkplan.MesDvCheckPlanSubjectService;
  15 +import cn.iocoder.yudao.module.mes.service.dv.machinery.MesDvMachineryService;
  16 +import jakarta.annotation.Resource;
  17 +import org.springframework.stereotype.Service;
  18 +import org.springframework.transaction.annotation.Transactional;
  19 +import org.springframework.validation.annotation.Validated;
  20 +
  21 +import java.util.List;
  22 +
  23 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  24 +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
  25 +
  26 +/**
  27 + * MES 设备点检记录 Service 实现类
  28 + *
  29 + * @author 芋道源码
  30 + */
  31 +@Service
  32 +@Validated
  33 +public class MesDvCheckRecordServiceImpl implements MesDvCheckRecordService {
  34 +
  35 + // TODO @AI:枚举类;
  36 + /**
  37 + * 待点检状态
  38 + */
  39 + private static final int STATUS_PREPARE = 10;
  40 + /**
  41 + * 已完成状态
  42 + */
  43 + private static final int STATUS_FINISHED = 20;
  44 +
  45 + @Resource
  46 + private MesDvCheckRecordMapper checkRecordMapper;
  47 + @Resource
  48 + private MesDvCheckRecordLineMapper checkRecordLineMapper;
  49 + @Resource
  50 + private MesDvMachineryService machineryService;
  51 + @Resource
  52 + private MesDvCheckPlanService checkPlanService;
  53 + @Resource
  54 + private MesDvCheckPlanSubjectService checkPlanSubjectService;
  55 +
  56 + @Override
  57 + @Transactional(rollbackFor = Exception.class)
  58 + public Long createCheckRecord(MesDvCheckRecordSaveReqVO createReqVO) {
  59 + // 1. 校验关联数据
  60 + validateCheckRecordRelation(createReqVO);
  61 +
  62 + // 2. 插入主记录,状态默认为待点检
  63 + MesDvCheckRecordDO checkRecord = BeanUtils.toBean(createReqVO, MesDvCheckRecordDO.class)
  64 + .setStatus(STATUS_PREPARE);
  65 + checkRecordMapper.insert(checkRecord);
  66 +
  67 + // 3. 如果指定了点检计划,自动生成明细行
  68 + if (createReqVO.getPlanId() != null) {
  69 + generateCheckRecordLines(checkRecord.getId(), createReqVO.getPlanId());
  70 + }
  71 + return checkRecord.getId();
  72 + }
  73 +
  74 + @Override
  75 + @Transactional(rollbackFor = Exception.class)
  76 + public void updateCheckRecord(MesDvCheckRecordSaveReqVO updateReqVO) {
  77 + // 1.1 校验存在 + 状态为待点检
  78 + MesDvCheckRecordDO existRecord = validateCheckRecordPrepare(updateReqVO.getId());
  79 + // 1.2 校验关联数据
  80 + validateCheckRecordRelation(updateReqVO);
  81 +
  82 + // 2. 如果计划变更,删除旧明细并重新生成
  83 + Long oldPlanId = existRecord.getPlanId();
  84 + Long newPlanId = updateReqVO.getPlanId();
  85 + boolean planChanged = !java.util.Objects.equals(oldPlanId, newPlanId);
  86 + if (planChanged) {
  87 + checkRecordLineMapper.deleteByRecordId(updateReqVO.getId());
  88 + if (newPlanId != null) {
  89 + generateCheckRecordLines(updateReqVO.getId(), newPlanId);
  90 + }
  91 + }
  92 +
  93 + // 3. 更新主记录
  94 + MesDvCheckRecordDO updateObj = BeanUtils.toBean(updateReqVO, MesDvCheckRecordDO.class);
  95 + checkRecordMapper.updateById(updateObj);
  96 + }
  97 +
  98 + @Override
  99 + public void submitCheckRecord(Long id) {
  100 + // 1.1 校验状态为待点检
  101 + validateCheckRecordPrepare(id);
  102 + // 1.2 校验至少有一条明细
  103 + List<MesDvCheckRecordLineDO> lines = checkRecordLineMapper.selectListByRecordId(id);
  104 + if (CollUtil.isEmpty(lines)) {
  105 + throw exception(DV_CHECK_RECORD_NO_LINE);
  106 + }
  107 +
  108 + // 2. 状态改为已完成
  109 + MesDvCheckRecordDO updateObj = new MesDvCheckRecordDO()
  110 + .setId(id).setStatus(STATUS_FINISHED);
  111 + checkRecordMapper.updateById(updateObj);
  112 + }
  113 +
  114 + @Override
  115 + @Transactional(rollbackFor = Exception.class)
  116 + public void deleteCheckRecord(Long id) {
  117 + // 1. 校验状态为待点检(已完成不可删除)
  118 + validateCheckRecordPrepare(id);
  119 +
  120 + // 2.1 删除主记录
  121 + checkRecordMapper.deleteById(id);
  122 + // 2.2 级联删除明细
  123 + checkRecordLineMapper.deleteByRecordId(id);
  124 + }
  125 +
  126 + @Override
  127 + public void validateCheckRecordExists(Long id) {
  128 + if (checkRecordMapper.selectById(id) == null) {
  129 + throw exception(DV_CHECK_RECORD_NOT_EXISTS);
  130 + }
  131 + }
  132 +
  133 + @Override
  134 + public MesDvCheckRecordDO getCheckRecord(Long id) {
  135 + return checkRecordMapper.selectById(id);
  136 + }
  137 +
  138 + @Override
  139 + public PageResult<MesDvCheckRecordDO> getCheckRecordPage(MesDvCheckRecordPageReqVO pageReqVO) {
  140 + return checkRecordMapper.selectPage(pageReqVO);
  141 + }
  142 +
  143 + // ==================== 私有方法 ====================
  144 +
  145 + /**
  146 + * 校验点检记录为待点检状态
  147 + */
  148 + private MesDvCheckRecordDO validateCheckRecordPrepare(Long id) {
  149 + MesDvCheckRecordDO record = checkRecordMapper.selectById(id);
  150 + if (record == null) {
  151 + throw exception(DV_CHECK_RECORD_NOT_EXISTS);
  152 + }
  153 + // TODO @AI:ObjUtil notEquals
  154 + if (!STATUS_PREPARE.equals(record.getStatus())) {
  155 + throw exception(DV_CHECK_RECORD_NOT_PREPARE);
  156 + }
  157 + return record;
  158 + }
  159 +
  160 + private void validateCheckRecordRelation(MesDvCheckRecordSaveReqVO reqVO) {
  161 + // 校验设备是否存在
  162 + machineryService.validateMachineryExists(reqVO.getMachineryId());
  163 + // 校验点检计划是否存在
  164 + if (reqVO.getPlanId() != null) {
  165 + checkPlanService.validateCheckPlanExists(reqVO.getPlanId());
  166 + }
  167 + }
  168 +
  169 + /**
  170 + * 根据计划自动生成点检项目明细行
  171 + */
  172 + private void generateCheckRecordLines(Long recordId, Long planId) {
  173 + List<MesDvCheckPlanSubjectDO> planSubjects = checkPlanSubjectService.getCheckPlanSubjectListByPlanId(planId);
  174 + if (CollUtil.isEmpty(planSubjects)) {
  175 + return;
  176 + }
  177 + // TODO @AI:批量插入;
  178 + for (MesDvCheckPlanSubjectDO planSubject : planSubjects) {
  179 + MesDvCheckRecordLineDO line = new MesDvCheckRecordLineDO()
  180 + .setRecordId(recordId).setSubjectId(planSubject.getSubjectId()).setCheckStatus("Y");
  181 + checkRecordLineMapper.insert(line);
  182 + }
  183 + }
  184 +
  185 +}