diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/MesDvMaintenRecordController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/MesDvMaintenRecordController.java new file mode 100644 index 0000000..33fae61 --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/MesDvMaintenRecordController.java @@ -0,0 +1,141 @@ +package cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord; + +import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.MesDvMaintenRecordPageReqVO; +import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.MesDvMaintenRecordRespVO; +import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.MesDvMaintenRecordSaveReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkplan.MesDvCheckPlanDO; +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.machinery.MesDvMachineryDO; +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.maintenrecord.MesDvMaintenRecordDO; +import cn.iocoder.yudao.module.mes.service.dv.checkplan.MesDvCheckPlanService; +import cn.iocoder.yudao.module.mes.service.dv.machinery.MesDvMachineryService; +import cn.iocoder.yudao.module.mes.service.dv.maintenrecord.MesDvMaintenRecordService; +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.Valid; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; + +@Tag(name = "管理后台 - MES 设备保养记录") +@RestController +@RequestMapping("/mes/dv/mainten-record") +@Validated +public class MesDvMaintenRecordController { + + @Resource + private MesDvMaintenRecordService maintenRecordService; + + @Resource + private MesDvCheckPlanService checkPlanService; + + @Resource + private MesDvMachineryService machineryService; + + @Resource + private AdminUserApi adminUserApi; + + @PostMapping("/create") + @Operation(summary = "创建设备保养记录") + @PreAuthorize("@ss.hasPermission('mes:dv-mainten-record:create')") + public CommonResult createMaintenRecord(@Valid @RequestBody MesDvMaintenRecordSaveReqVO createReqVO) { + return success(maintenRecordService.createMaintenRecord(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新设备保养记录") + @PreAuthorize("@ss.hasPermission('mes:dv-mainten-record:update')") + public CommonResult updateMaintenRecord(@Valid @RequestBody MesDvMaintenRecordSaveReqVO updateReqVO) { + maintenRecordService.updateMaintenRecord(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除设备保养记录") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('mes:dv-mainten-record:delete')") + public CommonResult deleteMaintenRecord(@RequestParam("id") Long id) { + maintenRecordService.deleteMaintenRecord(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得设备保养记录") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('mes:dv-mainten-record:query')") + public CommonResult getMaintenRecord(@RequestParam("id") Long id) { + MesDvMaintenRecordDO maintenRecord = maintenRecordService.getMaintenRecord(id); + if (maintenRecord == null) { + return success(null); + } + return success(buildMaintenRecordRespVOList(Collections.singletonList(maintenRecord)).get(0)); + } + + @GetMapping("/page") + @Operation(summary = "获得设备保养记录分页") + @PreAuthorize("@ss.hasPermission('mes:dv-mainten-record:query')") + public CommonResult> getMaintenRecordPage(@Valid MesDvMaintenRecordPageReqVO pageReqVO) { + PageResult pageResult = maintenRecordService.getMaintenRecordPage(pageReqVO); + return success(new PageResult<>(buildMaintenRecordRespVOList(pageResult.getList()), pageResult.getTotal())); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出设备保养记录 Excel") + @PreAuthorize("@ss.hasPermission('mes:dv-mainten-record:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportMaintenRecordExcel(@Valid MesDvMaintenRecordPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = maintenRecordService.getMaintenRecordPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "设备保养记录.xls", "数据", MesDvMaintenRecordRespVO.class, + buildMaintenRecordRespVOList(list)); + } + + // ==================== 拼接 VO ==================== + + private List buildMaintenRecordRespVOList(List list) { + if (CollUtil.isEmpty(list)) { + return Collections.emptyList(); + } + // 1. 批量获取关联数据 + Map planMap = checkPlanService.getCheckPlanMap( + convertSet(list, MesDvMaintenRecordDO::getPlanId)); + Map machineryMap = machineryService.getMachineryMap( + convertSet(list, MesDvMaintenRecordDO::getMachineryId)); + Map userMap = adminUserApi.getUserMap( + convertSet(list, MesDvMaintenRecordDO::getUserId)); + // 2. 拼接 VO + return BeanUtils.toBean(list, MesDvMaintenRecordRespVO.class, vo -> { + MapUtils.findAndThen(planMap, vo.getPlanId(), + plan -> vo.setPlanName(plan.getName())); + MapUtils.findAndThen(machineryMap, vo.getMachineryId(), machinery -> vo + .setMachineryCode(machinery.getCode()).setMachineryName(machinery.getName()) + .setMachineryBrand(machinery.getBrand()).setMachinerySpec(machinery.getSpec())); + MapUtils.findAndThen(userMap, vo.getUserId(), + user -> vo.setNickname(user.getNickname())); + }); + } + +} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/MesDvMaintenRecordLineController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/MesDvMaintenRecordLineController.java new file mode 100644 index 0000000..e3616cb --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/MesDvMaintenRecordLineController.java @@ -0,0 +1,122 @@ +package cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord; + +import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.line.MesDvMaintenRecordLinePageReqVO; +import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.line.MesDvMaintenRecordLineRespVO; +import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.line.MesDvMaintenRecordLineSaveReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.maintenrecord.MesDvMaintenRecordLineDO; +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.subject.MesDvSubjectDO; +import cn.iocoder.yudao.module.mes.service.dv.maintenrecord.MesDvMaintenRecordLineService; +import cn.iocoder.yudao.module.mes.service.dv.subject.MesDvSubjectService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.Valid; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; + +@Tag(name = "管理后台 - MES 设备保养记录明细") +@RestController +@RequestMapping("/mes/dv/mainten-record-line") +@Validated +public class MesDvMaintenRecordLineController { + + @Resource + private MesDvMaintenRecordLineService maintenRecordLineService; + + @Resource + private MesDvSubjectService subjectService; + + @PostMapping("/create") + @Operation(summary = "创建设备保养记录明细") + @PreAuthorize("@ss.hasPermission('mes:dv-mainten-record:create')") + public CommonResult createMaintenRecordLine(@Valid @RequestBody MesDvMaintenRecordLineSaveReqVO createReqVO) { + return success(maintenRecordLineService.createMaintenRecordLine(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新设备保养记录明细") + @PreAuthorize("@ss.hasPermission('mes:dv-mainten-record:update')") + public CommonResult updateMaintenRecordLine(@Valid @RequestBody MesDvMaintenRecordLineSaveReqVO updateReqVO) { + maintenRecordLineService.updateMaintenRecordLine(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除设备保养记录明细") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('mes:dv-mainten-record:delete')") + public CommonResult deleteMaintenRecordLine(@RequestParam("id") Long id) { + maintenRecordLineService.deleteMaintenRecordLine(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得设备保养记录明细") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('mes:dv-mainten-record:query')") + public CommonResult getMaintenRecordLine(@RequestParam("id") Long id) { + MesDvMaintenRecordLineDO maintenRecordLine = maintenRecordLineService.getMaintenRecordLine(id); + if (maintenRecordLine == null) { + return success(null); + } + return success(buildMaintenRecordLineRespVOList(Collections.singletonList(maintenRecordLine)).get(0)); + } + + @GetMapping("/page") + @Operation(summary = "获得设备保养记录明细分页") + @PreAuthorize("@ss.hasPermission('mes:dv-mainten-record:query')") + public CommonResult> getMaintenRecordLinePage(@Valid MesDvMaintenRecordLinePageReqVO pageReqVO) { + PageResult pageResult = maintenRecordLineService.getMaintenRecordLinePage(pageReqVO); + return success(new PageResult<>(buildMaintenRecordLineRespVOList(pageResult.getList()), pageResult.getTotal())); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出设备保养记录明细 Excel") + @PreAuthorize("@ss.hasPermission('mes:dv-mainten-record:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportMaintenRecordLineExcel(@Valid MesDvMaintenRecordLinePageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = maintenRecordLineService.getMaintenRecordLinePage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "设备保养记录明细.xls", "数据", MesDvMaintenRecordLineRespVO.class, + buildMaintenRecordLineRespVOList(list)); + } + + // ==================== 拼接 VO ==================== + + private List buildMaintenRecordLineRespVOList(List list) { + if (CollUtil.isEmpty(list)) { + return Collections.emptyList(); + } + // 1. 批量获取关联数据 + Map subjectMap = subjectService.getSubjectMap( + convertSet(list, MesDvMaintenRecordLineDO::getSubjectId)); + // 2. 拼接 VO + return BeanUtils.toBean(list, MesDvMaintenRecordLineRespVO.class, vo -> + MapUtils.findAndThen(subjectMap, vo.getSubjectId(), subject -> vo + .setSubjectName(subject.getName()).setSubjectContent(subject.getContent()) + .setSubjectStandard(subject.getStandard()))); + } + +} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/MesDvMaintenRecordPageReqVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/MesDvMaintenRecordPageReqVO.java new file mode 100644 index 0000000..6d3108b --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/MesDvMaintenRecordPageReqVO.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - MES 设备保养记录分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MesDvMaintenRecordPageReqVO extends PageParam { + + @Schema(description = "计划名称", example = "计划1") + private String planName; + + @Schema(description = "设备编码", example = "M1") + private String machineryCode; + + @Schema(description = "设备名称", example = "设备1") + private String machineryName; + + @Schema(description = "保养人名称", example = "张三") + private String nickname; + + @Schema(description = "保养时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] maintenTime; + +} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/MesDvMaintenRecordRespVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/MesDvMaintenRecordRespVO.java new file mode 100644 index 0000000..103e85d --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/MesDvMaintenRecordRespVO.java @@ -0,0 +1,72 @@ +package cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo; + +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.mes.enums.DictTypeConstants; +import cn.idev.excel.annotation.ExcelIgnoreUnannotated; +import cn.idev.excel.annotation.ExcelProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - MES 设备保养记录 Response VO") +@Data +@ExcelIgnoreUnannotated +public class MesDvMaintenRecordRespVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("编号") + private Long id; + + @Schema(description = "计划编号", example = "1") + private Long planId; + + @Schema(description = "计划名称", example = "保养计划1") + @ExcelProperty("计划名称") + private String planName; + + @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Long machineryId; + + @Schema(description = "设备编码", example = "M001") + @ExcelProperty("设备编码") + private String machineryCode; + + @Schema(description = "设备名称", example = "机床A") + @ExcelProperty("设备名称") + private String machineryName; + + @Schema(description = "品牌", example = "西门子") + @ExcelProperty("品牌") + private String machineryBrand; + + @Schema(description = "规格型号", example = "X-100") + @ExcelProperty("规格型号") + private String machinerySpec; + + @Schema(description = "保养时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("保养时间") + private LocalDateTime maintenTime; + + @Schema(description = "用户编号", example = "1") + private Long userId; + + @Schema(description = "保养人名称", example = "张三") + @ExcelProperty("保养人") + private String nickname; + + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") + @ExcelProperty(value = "状态", converter = DictConvert.class) + @DictFormat(DictTypeConstants.MES_MAINTEN_RECORD_STATUS) + private Integer status; + + @Schema(description = "备注", example = "测试备注") + @ExcelProperty("备注") + private String remark; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/MesDvMaintenRecordSaveReqVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/MesDvMaintenRecordSaveReqVO.java new file mode 100644 index 0000000..2ffce7e --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/MesDvMaintenRecordSaveReqVO.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import jakarta.validation.constraints.NotNull; +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - MES 设备保养记录新增/修改 Request VO") +@Data +public class MesDvMaintenRecordSaveReqVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "1024") + private Long id; + + @Schema(description = "计划编号", example = "1") + private Long planId; + + @Schema(description = "设备编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "设备不能为空") + private Long machineryId; + + @Schema(description = "保养时间", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "保养时间不能为空") + private LocalDateTime maintenTime; + + @Schema(description = "用户编号", example = "1") + private Long userId; + + @Schema(description = "状态", example = "10") + private Integer status; + + @Schema(description = "备注", example = "测试备注") + private String remark; + +} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/line/MesDvMaintenRecordLinePageReqVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/line/MesDvMaintenRecordLinePageReqVO.java new file mode 100644 index 0000000..047fb32 --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/line/MesDvMaintenRecordLinePageReqVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.line; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +@Schema(description = "管理后台 - MES 设备保养记录明细分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class MesDvMaintenRecordLinePageReqVO extends PageParam { + + @Schema(description = "保养记录ID", example = "1") + private Long recordId; + +} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/line/MesDvMaintenRecordLineRespVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/line/MesDvMaintenRecordLineRespVO.java new file mode 100644 index 0000000..adea3c9 --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/line/MesDvMaintenRecordLineRespVO.java @@ -0,0 +1,57 @@ +package cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.line; + +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; +import cn.iocoder.yudao.module.mes.enums.DictTypeConstants; +import cn.idev.excel.annotation.ExcelIgnoreUnannotated; +import cn.idev.excel.annotation.ExcelProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - MES 设备保养记录明细 Response VO") +@Data +@ExcelIgnoreUnannotated +public class MesDvMaintenRecordLineRespVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @ExcelProperty("编号") + private Long id; + + @Schema(description = "保养记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Long recordId; + + @Schema(description = "项目编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Long subjectId; + + @Schema(description = "项目名称", example = "检查机油") + @ExcelProperty("项目名称") + private String subjectName; + + @Schema(description = "项目内容", example = "检查机油是否充足") + @ExcelProperty("项目内容") + private String subjectContent; + + @Schema(description = "项目标准", example = "无漏油") + @ExcelProperty("标准") + private String subjectStandard; + + @Schema(description = "保养结果", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @ExcelProperty(value = "保养结果", converter = DictConvert.class) + @DictFormat(DictTypeConstants.MES_MAINTEN_STATUS) + private Integer status; + + @Schema(description = "异常描述", example = "发现损坏") + @ExcelProperty("异常描述") + private String result; + + @Schema(description = "备注", example = "测试备注") + @ExcelProperty("备注") + private String remark; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/line/MesDvMaintenRecordLineSaveReqVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/line/MesDvMaintenRecordLineSaveReqVO.java new file mode 100644 index 0000000..b691306 --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/maintenrecord/vo/line/MesDvMaintenRecordLineSaveReqVO.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.line; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import jakarta.validation.constraints.NotNull; + +@Schema(description = "管理后台 - MES 设备保养记录明细新增/修改 Request VO") +@Data +public class MesDvMaintenRecordLineSaveReqVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "1024") + private Long id; + + @Schema(description = "保养记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "保养记录不能为空") + private Long recordId; + + @Schema(description = "项目编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "项目不能为空") + private Long subjectId; + + @Schema(description = "保养结果", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "保养结果不能为空") + private Integer status; + + @Schema(description = "异常描述", example = "发现损坏") + private String result; + + @Schema(description = "备注", example = "测试备注") + private String remark; + +} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/dv/maintenrecord/MesDvMaintenRecordDO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/dv/maintenrecord/MesDvMaintenRecordDO.java new file mode 100644 index 0000000..7f7dee3 --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/dv/maintenrecord/MesDvMaintenRecordDO.java @@ -0,0 +1,66 @@ +package cn.iocoder.yudao.module.mes.dal.dataobject.dv.maintenrecord; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.checkplan.MesDvCheckPlanDO; +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.machinery.MesDvMachineryDO; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; + +import java.time.LocalDateTime; + +/** + * MES 设备保养记录 DO + * + * @author 芋道源码 + */ +@TableName("mes_dv_mainten_record") +@KeySequence("mes_dv_mainten_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class MesDvMaintenRecordDO extends BaseDO { + + /** + * 编号 + */ + @TableId + private Long id; + /** + * 计划编号 + * + * 关联 {@link MesDvCheckPlanDO#getId()} + */ + private Long planId; + /** + * 设备编号 + * + * 关联 {@link MesDvMachineryDO#getId()} + */ + private Long machineryId; + /** + * 保养时间 + */ + private LocalDateTime maintenTime; + /** + * 用户编号 + * + * 关联 AdminUserDO#getId() + */ + private Long userId; + /** + * 状态 + * + * 字典类型 mes_mainten_record_status + */ + private Integer status; + /** + * 备注 + */ + private String remark; + +} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/dv/maintenrecord/MesDvMaintenRecordLineDO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/dv/maintenrecord/MesDvMaintenRecordLineDO.java new file mode 100644 index 0000000..a8df96c --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/dv/maintenrecord/MesDvMaintenRecordLineDO.java @@ -0,0 +1,57 @@ +package cn.iocoder.yudao.module.mes.dal.dataobject.dv.maintenrecord; + +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.subject.MesDvSubjectDO; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; + +/** + * MES 设备保养记录明细 DO + * + * @author 芋道源码 + */ +@TableName("mes_dv_mainten_record_line") +@KeySequence("mes_dv_mainten_record_line_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class MesDvMaintenRecordLineDO extends BaseDO { + + /** + * 编号 + */ + @TableId + private Long id; + /** + * 保养记录编号 + * + * 关联 {@link MesDvMaintenRecordDO#getId()} + */ + private Long recordId; + /** + * 项目编号 + * + * 关联 {@link MesDvSubjectDO#getId()} + */ + private Long subjectId; + /** + * 保养结果 + * + * 字典类型 mes_mainten_status + */ + private Integer status; + /** + * 异常描述 + */ + private String result; + /** + * 备注 + */ + private String remark; + +} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/dv/maintenrecord/MesDvMaintenRecordLineMapper.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/dv/maintenrecord/MesDvMaintenRecordLineMapper.java new file mode 100644 index 0000000..5188258 --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/dv/maintenrecord/MesDvMaintenRecordLineMapper.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.mes.dal.mysql.dv.maintenrecord; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.line.MesDvMaintenRecordLinePageReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.maintenrecord.MesDvMaintenRecordLineDO; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * MES 设备保养记录明细 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface MesDvMaintenRecordLineMapper extends BaseMapperX { + + default PageResult selectPage(MesDvMaintenRecordLinePageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(MesDvMaintenRecordLineDO::getRecordId, reqVO.getRecordId()) + .orderByDesc(MesDvMaintenRecordLineDO::getId)); + } + + default List selectListByRecordId(Long recordId) { + return selectList(MesDvMaintenRecordLineDO::getRecordId, recordId); + } + + default int deleteByRecordId(Long recordId) { + return delete(MesDvMaintenRecordLineDO::getRecordId, recordId); + } + +} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/dv/maintenrecord/MesDvMaintenRecordMapper.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/dv/maintenrecord/MesDvMaintenRecordMapper.java new file mode 100644 index 0000000..56adadc --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/dv/maintenrecord/MesDvMaintenRecordMapper.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.mes.dal.mysql.dv.maintenrecord; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.MesDvMaintenRecordPageReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.maintenrecord.MesDvMaintenRecordDO; +import cn.hutool.core.util.StrUtil; +import org.apache.ibatis.annotations.Mapper; + +/** + * MES 设备保养记录 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface MesDvMaintenRecordMapper extends BaseMapperX { + + default PageResult selectPage(MesDvMaintenRecordPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() +// .apply(StrUtil.isNotBlank(reqVO.getPlanName()), +// "plan_id IN (SELECT id FROM mes_dv_check_plan WHERE name LIKE CONCAT('%', {0}, '%') AND deleted = 0)", +// reqVO.getPlanName()) +// .apply(StrUtil.isNotBlank(reqVO.getMachineryCode()), +// "machinery_id IN (SELECT id FROM mes_dv_machinery WHERE code LIKE CONCAT('%', {0}, '%') AND deleted = 0)", +// reqVO.getMachineryCode()) +// .apply(StrUtil.isNotBlank(reqVO.getMachineryName()), +// "machinery_id IN (SELECT id FROM mes_dv_machinery WHERE name LIKE CONCAT('%', {0}, '%') AND deleted = 0)", +// reqVO.getMachineryName()) +// .apply(StrUtil.isNotBlank(reqVO.getNickname()), +// "user_id IN (SELECT id FROM system_users WHERE nickname LIKE CONCAT('%', {0}, '%') AND deleted = 0)", +// reqVO.getNickname()) + .betweenIfPresent(MesDvMaintenRecordDO::getMaintenTime, reqVO.getMaintenTime()) + .orderByDesc(MesDvMaintenRecordDO::getId)); + } + +} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordLineService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordLineService.java new file mode 100644 index 0000000..11b635e --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordLineService.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.mes.service.dv.maintenrecord; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.line.MesDvMaintenRecordLinePageReqVO; +import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.line.MesDvMaintenRecordLineSaveReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.maintenrecord.MesDvMaintenRecordLineDO; + +import jakarta.validation.Valid; + +/** + * 设备保养记录明细 Service 接口 + * + * @author 芋道源码 + */ +public interface MesDvMaintenRecordLineService { + + /** + * 创建设备保养记录明细 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createMaintenRecordLine(@Valid MesDvMaintenRecordLineSaveReqVO createReqVO); + + /** + * 更新设备保养记录明细 + * + * @param updateReqVO 更新信息 + */ + void updateMaintenRecordLine(@Valid MesDvMaintenRecordLineSaveReqVO updateReqVO); + + /** + * 删除设备保养记录明细 + * + * @param id 编号 + */ + void deleteMaintenRecordLine(Long id); + + /** + * 获得设备保养记录明细 + * + * @param id 编号 + * @return 设备保养记录明细 + */ + MesDvMaintenRecordLineDO getMaintenRecordLine(Long id); + + /** + * 获得设备保养记录明细分页 + * + * @param pageReqVO 分页查询 + * @return 设备保养记录明细分页 + */ + PageResult getMaintenRecordLinePage(MesDvMaintenRecordLinePageReqVO pageReqVO); + +} \ No newline at end of file diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordLineServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordLineServiceImpl.java new file mode 100644 index 0000000..12f24ef --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordLineServiceImpl.java @@ -0,0 +1,67 @@ +package cn.iocoder.yudao.module.mes.service.dv.maintenrecord; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.line.MesDvMaintenRecordLinePageReqVO; +import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.line.MesDvMaintenRecordLineSaveReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.maintenrecord.MesDvMaintenRecordLineDO; +import cn.iocoder.yudao.module.mes.dal.mysql.dv.maintenrecord.MesDvMaintenRecordLineMapper; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; +import jakarta.annotation.Resource; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.MAINTEN_RECORD_LINE_NOT_EXISTS; + +// TODO @AI:注释风格; +/** + * 设备保养记录明细 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class MesDvMaintenRecordLineServiceImpl implements MesDvMaintenRecordLineService { + + @Resource + private MesDvMaintenRecordLineMapper maintenRecordLineMapper; + + @Override + public Long createMaintenRecordLine(MesDvMaintenRecordLineSaveReqVO createReqVO) { + // TODO @AI:必要的校验 + MesDvMaintenRecordLineDO maintenRecordLine = BeanUtils.toBean(createReqVO, MesDvMaintenRecordLineDO.class); + maintenRecordLineMapper.insert(maintenRecordLine); + return maintenRecordLine.getId(); + } + + @Override + public void updateMaintenRecordLine(MesDvMaintenRecordLineSaveReqVO updateReqVO) { + // TODO @AI:必要的校验 + validateMaintenRecordLineExists(updateReqVO.getId()); + MesDvMaintenRecordLineDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMaintenRecordLineDO.class); + maintenRecordLineMapper.updateById(updateObj); + } + + @Override + public void deleteMaintenRecordLine(Long id) { + validateMaintenRecordLineExists(id); + maintenRecordLineMapper.deleteById(id); + } + + private void validateMaintenRecordLineExists(Long id) { + if (maintenRecordLineMapper.selectById(id) == null) { + throw exception(MAINTEN_RECORD_LINE_NOT_EXISTS); + } + } + + @Override + public MesDvMaintenRecordLineDO getMaintenRecordLine(Long id) { + return maintenRecordLineMapper.selectById(id); + } + + @Override + public PageResult getMaintenRecordLinePage(MesDvMaintenRecordLinePageReqVO pageReqVO) { + return maintenRecordLineMapper.selectPage(pageReqVO); + } + +} \ No newline at end of file diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordService.java new file mode 100644 index 0000000..157d386 --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordService.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.mes.service.dv.maintenrecord; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.MesDvMaintenRecordPageReqVO; +import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.MesDvMaintenRecordSaveReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.maintenrecord.MesDvMaintenRecordDO; + +import jakarta.validation.Valid; + +/** + * 设备保养记录 Service 接口 + * + * @author 芋道源码 + */ +public interface MesDvMaintenRecordService { + + /** + * 创建设备保养记录 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createMaintenRecord(@Valid MesDvMaintenRecordSaveReqVO createReqVO); + + /** + * 更新设备保养记录 + * + * @param updateReqVO 更新信息 + */ + void updateMaintenRecord(@Valid MesDvMaintenRecordSaveReqVO updateReqVO); + + /** + * 删除设备保养记录 + * + * @param id 编号 + */ + void deleteMaintenRecord(Long id); + + /** + * 获得设备保养记录 + * + * @param id 编号 + * @return 设备保养记录 + */ + MesDvMaintenRecordDO getMaintenRecord(Long id); + + /** + * 获得设备保养记录分页 + * + * @param pageReqVO 分页查询 + * @return 设备保养记录分页 + */ + PageResult getMaintenRecordPage(MesDvMaintenRecordPageReqVO pageReqVO); + +} diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordServiceImpl.java new file mode 100644 index 0000000..b3734a1 --- /dev/null +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/dv/maintenrecord/MesDvMaintenRecordServiceImpl.java @@ -0,0 +1,82 @@ +package cn.iocoder.yudao.module.mes.service.dv.maintenrecord; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.MesDvMaintenRecordPageReqVO; +import cn.iocoder.yudao.module.mes.controller.admin.dv.maintenrecord.vo.MesDvMaintenRecordSaveReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.dv.maintenrecord.MesDvMaintenRecordDO; +import cn.iocoder.yudao.module.mes.dal.mysql.dv.maintenrecord.MesDvMaintenRecordMapper; +import cn.iocoder.yudao.module.mes.dal.mysql.dv.maintenrecord.MesDvMaintenRecordLineMapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; +import jakarta.annotation.Resource; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.MAINTEN_RECORD_NOT_EXISTS; + +// TODO @AI:注释风格; +/** + * 设备保养记录 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class MesDvMaintenRecordServiceImpl implements MesDvMaintenRecordService { + + @Resource + private MesDvMaintenRecordMapper maintenRecordMapper; + + @Resource + private MesDvMaintenRecordLineMapper maintenRecordLineMapper; + + @Override + public Long createMaintenRecord(MesDvMaintenRecordSaveReqVO createReqVO) { + // TODO @AI:必要的校验 + // 插入 + MesDvMaintenRecordDO maintenRecord = BeanUtils.toBean(createReqVO, MesDvMaintenRecordDO.class); + maintenRecordMapper.insert(maintenRecord); + return maintenRecord.getId(); + } + + @Override + public void updateMaintenRecord(MesDvMaintenRecordSaveReqVO updateReqVO) { + // TODO @AI:必要的校验 + // 校验存在 + validateMaintenRecordExists(updateReqVO.getId()); + + // 更新 + MesDvMaintenRecordDO updateObj = BeanUtils.toBean(updateReqVO, MesDvMaintenRecordDO.class); + maintenRecordMapper.updateById(updateObj); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteMaintenRecord(Long id) { + // 校验存在 + validateMaintenRecordExists(id); + + // 删除 + maintenRecordMapper.deleteById(id); + // 级联删除子表 + maintenRecordLineMapper.deleteByRecordId(id); + } + + private void validateMaintenRecordExists(Long id) { + if (maintenRecordMapper.selectById(id) == null) { + throw exception(MAINTEN_RECORD_NOT_EXISTS); + } + } + + @Override + public MesDvMaintenRecordDO getMaintenRecord(Long id) { + return maintenRecordMapper.selectById(id); + } + + @Override + public PageResult getMaintenRecordPage(MesDvMaintenRecordPageReqVO pageReqVO) { + return maintenRecordMapper.selectPage(pageReqVO); + } + +}