Commit 366602291064201a8a51541d5bde2aa063829f7a
1 parent
d843c5d0
feat(mes):新增 defect 缺陷类型
Showing
8 changed files
with
547 additions
and
0 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/MesQcDefectController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.controller.admin.qc; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; | ||
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 8 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||
| 9 | +import cn.iocoder.yudao.module.mes.controller.admin.qc.vo.MesQcDefectPageReqVO; | ||
| 10 | +import cn.iocoder.yudao.module.mes.controller.admin.qc.vo.MesQcDefectRespVO; | ||
| 11 | +import cn.iocoder.yudao.module.mes.controller.admin.qc.vo.MesQcDefectSaveReqVO; | ||
| 12 | +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.MesQcDefectDO; | ||
| 13 | +import cn.iocoder.yudao.module.mes.service.qc.MesQcDefectService; | ||
| 14 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 15 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 16 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 17 | +import jakarta.annotation.Resource; | ||
| 18 | +import jakarta.servlet.http.HttpServletResponse; | ||
| 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.io.IOException; | ||
| 25 | +import java.util.List; | ||
| 26 | + | ||
| 27 | +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; | ||
| 28 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 29 | + | ||
| 30 | +@Tag(name = "管理后台 - MES 缺陷类型") | ||
| 31 | +@RestController | ||
| 32 | +@RequestMapping("/mes/qc/defect") | ||
| 33 | +@Validated | ||
| 34 | +public class MesQcDefectController { | ||
| 35 | + | ||
| 36 | + @Resource | ||
| 37 | + private MesQcDefectService defectService; | ||
| 38 | + | ||
| 39 | + @PostMapping("/create") | ||
| 40 | + @Operation(summary = "创建缺陷类型") | ||
| 41 | + @PreAuthorize("@ss.hasPermission('mes:qc-defect:create')") | ||
| 42 | + public CommonResult<Long> createDefect(@Valid @RequestBody MesQcDefectSaveReqVO createReqVO) { | ||
| 43 | + return success(defectService.createDefect(createReqVO)); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + @PutMapping("/update") | ||
| 47 | + @Operation(summary = "更新缺陷类型") | ||
| 48 | + @PreAuthorize("@ss.hasPermission('mes:qc-defect:update')") | ||
| 49 | + public CommonResult<Boolean> updateDefect(@Valid @RequestBody MesQcDefectSaveReqVO updateReqVO) { | ||
| 50 | + defectService.updateDefect(updateReqVO); | ||
| 51 | + return success(true); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + @DeleteMapping("/delete") | ||
| 55 | + @Operation(summary = "删除缺陷类型") | ||
| 56 | + @Parameter(name = "id", description = "编号", required = true) | ||
| 57 | + @PreAuthorize("@ss.hasPermission('mes:qc-defect:delete')") | ||
| 58 | + public CommonResult<Boolean> deleteDefect(@RequestParam("id") Long id) { | ||
| 59 | + defectService.deleteDefect(id); | ||
| 60 | + return success(true); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + @GetMapping("/get") | ||
| 64 | + @Operation(summary = "获得缺陷类型") | ||
| 65 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | ||
| 66 | + @PreAuthorize("@ss.hasPermission('mes:qc-defect:query')") | ||
| 67 | + public CommonResult<MesQcDefectRespVO> getDefect(@RequestParam("id") Long id) { | ||
| 68 | + MesQcDefectDO defect = defectService.getDefect(id); | ||
| 69 | + return success(BeanUtils.toBean(defect, MesQcDefectRespVO.class)); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + @GetMapping("/page") | ||
| 73 | + @Operation(summary = "获得缺陷类型分页") | ||
| 74 | + @PreAuthorize("@ss.hasPermission('mes:qc-defect:query')") | ||
| 75 | + public CommonResult<PageResult<MesQcDefectRespVO>> getDefectPage(@Valid MesQcDefectPageReqVO pageReqVO) { | ||
| 76 | + PageResult<MesQcDefectDO> pageResult = defectService.getDefectPage(pageReqVO); | ||
| 77 | + return success(BeanUtils.toBean(pageResult, MesQcDefectRespVO.class)); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + @GetMapping("/simple-list") | ||
| 81 | + @Operation(summary = "获得缺陷类型精简列表", description = "主要用于前端的下拉选项") | ||
| 82 | + public CommonResult<List<MesQcDefectRespVO>> getDefectSimpleList() { | ||
| 83 | + List<MesQcDefectDO> list = defectService.getDefectList(); | ||
| 84 | + return success(BeanUtils.toBean(list, MesQcDefectRespVO.class)); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + @GetMapping("/export-excel") | ||
| 88 | + @Operation(summary = "导出缺陷类型 Excel") | ||
| 89 | + @PreAuthorize("@ss.hasPermission('mes:qc-defect:export')") | ||
| 90 | + @ApiAccessLog(operateType = EXPORT) | ||
| 91 | + public void exportDefectExcel(@Valid MesQcDefectPageReqVO pageReqVO, | ||
| 92 | + HttpServletResponse response) throws IOException { | ||
| 93 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | ||
| 94 | + List<MesQcDefectDO> list = defectService.getDefectPage(pageReqVO).getList(); | ||
| 95 | + // 导出 Excel | ||
| 96 | + ExcelUtils.write(response, "缺陷类型.xls", "数据", MesQcDefectRespVO.class, | ||
| 97 | + BeanUtils.toBean(list, MesQcDefectRespVO.class)); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/vo/MesQcDefectPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.controller.admin.qc.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 | + | ||
| 9 | +@Schema(description = "管理后台 - MES 缺陷类型分页 Request VO") | ||
| 10 | +@Data | ||
| 11 | +@EqualsAndHashCode(callSuper = true) | ||
| 12 | +@ToString(callSuper = true) | ||
| 13 | +public class MesQcDefectPageReqVO extends PageParam { | ||
| 14 | + | ||
| 15 | + @Schema(description = "缺陷编码", example = "DF001") | ||
| 16 | + private String code; | ||
| 17 | + | ||
| 18 | + @Schema(description = "缺陷描述", example = "外观缺陷") | ||
| 19 | + private String name; | ||
| 20 | + | ||
| 21 | + @Schema(description = "检测项类型", example = "APPEARANCE") | ||
| 22 | + private String type; | ||
| 23 | + | ||
| 24 | + @Schema(description = "缺陷等级", example = "MIN") | ||
| 25 | + private String level; | ||
| 26 | + | ||
| 27 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/vo/MesQcDefectRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.controller.admin.qc.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 MesQcDefectRespVO { | ||
| 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 = "DF001") | ||
| 23 | + @ExcelProperty("缺陷编码") | ||
| 24 | + private String code; | ||
| 25 | + | ||
| 26 | + @Schema(description = "缺陷描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "外观缺陷") | ||
| 27 | + @ExcelProperty("缺陷描述") | ||
| 28 | + private String name; | ||
| 29 | + | ||
| 30 | + @Schema(description = "检测项类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "APPEARANCE") | ||
| 31 | + @ExcelProperty(value = "检测项类型", converter = DictConvert.class) | ||
| 32 | + @DictFormat(DictTypeConstants.MES_INDEX_TYPE) | ||
| 33 | + private String type; | ||
| 34 | + | ||
| 35 | + @Schema(description = "缺陷等级", requiredMode = Schema.RequiredMode.REQUIRED, example = "MIN") | ||
| 36 | + @ExcelProperty(value = "缺陷等级", converter = DictConvert.class) | ||
| 37 | + @DictFormat(DictTypeConstants.MES_DEFECT_LEVEL) | ||
| 38 | + private String level; | ||
| 39 | + | ||
| 40 | + @Schema(description = "备注", example = "备注") | ||
| 41 | + @ExcelProperty("备注") | ||
| 42 | + private String remark; | ||
| 43 | + | ||
| 44 | + @Schema(description = "预留字段1") | ||
| 45 | + private String attribute1; | ||
| 46 | + | ||
| 47 | + @Schema(description = "预留字段2") | ||
| 48 | + private String attribute2; | ||
| 49 | + | ||
| 50 | + @Schema(description = "预留字段3") | ||
| 51 | + private Integer attribute3; | ||
| 52 | + | ||
| 53 | + @Schema(description = "预留字段4") | ||
| 54 | + private Integer attribute4; | ||
| 55 | + | ||
| 56 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 57 | + @ExcelProperty("创建时间") | ||
| 58 | + private LocalDateTime createTime; | ||
| 59 | + | ||
| 60 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/vo/MesQcDefectSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.controller.admin.qc.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import jakarta.validation.constraints.NotEmpty; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +@Schema(description = "管理后台 - MES 缺陷类型新增/修改 Request VO") | ||
| 8 | +@Data | ||
| 9 | +public class MesQcDefectSaveReqVO { | ||
| 10 | + | ||
| 11 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 12 | + private Long id; | ||
| 13 | + | ||
| 14 | + @Schema(description = "缺陷编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "DF001") | ||
| 15 | + @NotEmpty(message = "缺陷编码不能为空") | ||
| 16 | + private String code; | ||
| 17 | + | ||
| 18 | + @Schema(description = "缺陷描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "外观缺陷") | ||
| 19 | + @NotEmpty(message = "缺陷描述不能为空") | ||
| 20 | + private String name; | ||
| 21 | + | ||
| 22 | + @Schema(description = "检测项类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "APPEARANCE") | ||
| 23 | + @NotEmpty(message = "检测项类型不能为空") | ||
| 24 | + private String type; | ||
| 25 | + | ||
| 26 | + @Schema(description = "缺陷等级", requiredMode = Schema.RequiredMode.REQUIRED, example = "MIN") | ||
| 27 | + @NotEmpty(message = "缺陷等级不能为空") | ||
| 28 | + private String level; | ||
| 29 | + | ||
| 30 | + @Schema(description = "备注", example = "备注") | ||
| 31 | + private String remark; | ||
| 32 | + | ||
| 33 | + @Schema(description = "预留字段1") | ||
| 34 | + private String attribute1; | ||
| 35 | + | ||
| 36 | + @Schema(description = "预留字段2") | ||
| 37 | + private String attribute2; | ||
| 38 | + | ||
| 39 | + @Schema(description = "预留字段3") | ||
| 40 | + private Integer attribute3; | ||
| 41 | + | ||
| 42 | + @Schema(description = "预留字段4") | ||
| 43 | + private Integer attribute4; | ||
| 44 | + | ||
| 45 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/qc/MesQcDefectDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.dal.dataobject.qc; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 4 | +import com.baomidou.mybatisplus.annotation.KeySequence; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.TableId; | ||
| 6 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 7 | +import lombok.*; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * MES 缺陷类型 DO | ||
| 11 | + * | ||
| 12 | + * @author 芋道源码 | ||
| 13 | + */ | ||
| 14 | +@TableName("mes_qc_defect") | ||
| 15 | +@KeySequence("mes_qc_defect_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||
| 16 | +@Data | ||
| 17 | +@EqualsAndHashCode(callSuper = true) | ||
| 18 | +@ToString(callSuper = true) | ||
| 19 | +@Builder | ||
| 20 | +@NoArgsConstructor | ||
| 21 | +@AllArgsConstructor | ||
| 22 | +public class MesQcDefectDO extends BaseDO { | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 编号 | ||
| 26 | + */ | ||
| 27 | + @TableId | ||
| 28 | + private Long id; | ||
| 29 | + /** | ||
| 30 | + * 缺陷编码 | ||
| 31 | + */ | ||
| 32 | + private String code; | ||
| 33 | + /** | ||
| 34 | + * 缺陷描述 | ||
| 35 | + */ | ||
| 36 | + private String name; | ||
| 37 | + /** | ||
| 38 | + * 检测项类型 | ||
| 39 | + * | ||
| 40 | + * 字典类型 mes_index_type | ||
| 41 | + */ | ||
| 42 | + private String type; | ||
| 43 | + /** | ||
| 44 | + * 缺陷等级 | ||
| 45 | + * | ||
| 46 | + * 字典类型 mes_defect_level | ||
| 47 | + */ | ||
| 48 | + private String level; | ||
| 49 | + /** | ||
| 50 | + * 备注 | ||
| 51 | + */ | ||
| 52 | + private String remark; | ||
| 53 | + /** | ||
| 54 | + * 预留字段1 | ||
| 55 | + */ | ||
| 56 | + private String attribute1; | ||
| 57 | + /** | ||
| 58 | + * 预留字段2 | ||
| 59 | + */ | ||
| 60 | + private String attribute2; | ||
| 61 | + /** | ||
| 62 | + * 预留字段3 | ||
| 63 | + */ | ||
| 64 | + private Integer attribute3; | ||
| 65 | + /** | ||
| 66 | + * 预留字段4 | ||
| 67 | + */ | ||
| 68 | + private Integer attribute4; | ||
| 69 | + | ||
| 70 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/qc/MesQcDefectMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.dal.mysql.qc; | ||
| 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.qc.vo.MesQcDefectPageReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.MesQcDefectDO; | ||
| 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 MesQcDefectMapper extends BaseMapperX<MesQcDefectDO> { | ||
| 19 | + | ||
| 20 | + default PageResult<MesQcDefectDO> selectPage(MesQcDefectPageReqVO reqVO) { | ||
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<MesQcDefectDO>() | ||
| 22 | + .likeIfPresent(MesQcDefectDO::getCode, reqVO.getCode()) | ||
| 23 | + .likeIfPresent(MesQcDefectDO::getName, reqVO.getName()) | ||
| 24 | + .eqIfPresent(MesQcDefectDO::getType, reqVO.getType()) | ||
| 25 | + .eqIfPresent(MesQcDefectDO::getLevel, reqVO.getLevel()) | ||
| 26 | + .orderByDesc(MesQcDefectDO::getId)); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + default MesQcDefectDO selectByCode(String code) { | ||
| 30 | + return selectOne(MesQcDefectDO::getCode, code); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + default MesQcDefectDO selectByName(String name) { | ||
| 34 | + return selectOne(MesQcDefectDO::getName, name); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + default List<MesQcDefectDO> selectList() { | ||
| 38 | + return selectList(new LambdaQueryWrapperX<MesQcDefectDO>() | ||
| 39 | + .orderByDesc(MesQcDefectDO::getId)); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/MesQcDefectService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.service.qc; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.module.mes.controller.admin.qc.vo.MesQcDefectPageReqVO; | ||
| 5 | +import cn.iocoder.yudao.module.mes.controller.admin.qc.vo.MesQcDefectSaveReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.MesQcDefectDO; | ||
| 7 | +import jakarta.validation.Valid; | ||
| 8 | + | ||
| 9 | +import java.util.Collection; | ||
| 10 | +import java.util.List; | ||
| 11 | +import java.util.Map; | ||
| 12 | + | ||
| 13 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * MES 缺陷类型 Service 接口 | ||
| 17 | + * | ||
| 18 | + * @author 芋道源码 | ||
| 19 | + */ | ||
| 20 | +public interface MesQcDefectService { | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 创建缺陷类型 | ||
| 24 | + * | ||
| 25 | + * @param createReqVO 创建信息 | ||
| 26 | + * @return 编号 | ||
| 27 | + */ | ||
| 28 | + Long createDefect(@Valid MesQcDefectSaveReqVO createReqVO); | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 更新缺陷类型 | ||
| 32 | + * | ||
| 33 | + * @param updateReqVO 更新信息 | ||
| 34 | + */ | ||
| 35 | + void updateDefect(@Valid MesQcDefectSaveReqVO updateReqVO); | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 删除缺陷类型 | ||
| 39 | + * | ||
| 40 | + * @param id 编号 | ||
| 41 | + */ | ||
| 42 | + void deleteDefect(Long id); | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 获得缺陷类型 | ||
| 46 | + * | ||
| 47 | + * @param id 编号 | ||
| 48 | + * @return 缺陷类型 | ||
| 49 | + */ | ||
| 50 | + MesQcDefectDO getDefect(Long id); | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 获得缺陷类型分页 | ||
| 54 | + * | ||
| 55 | + * @param pageReqVO 分页查询 | ||
| 56 | + * @return 缺陷类型分页 | ||
| 57 | + */ | ||
| 58 | + PageResult<MesQcDefectDO> getDefectPage(MesQcDefectPageReqVO pageReqVO); | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 获得缺陷类型列表 | ||
| 62 | + * | ||
| 63 | + * @return 缺陷类型列表 | ||
| 64 | + */ | ||
| 65 | + List<MesQcDefectDO> getDefectList(); | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * 获得缺陷类型列表 | ||
| 69 | + * | ||
| 70 | + * @param ids 编号数组 | ||
| 71 | + * @return 缺陷类型列表 | ||
| 72 | + */ | ||
| 73 | + List<MesQcDefectDO> getDefectList(Collection<Long> ids); | ||
| 74 | + | ||
| 75 | + /** | ||
| 76 | + * 获得缺陷类型 Map | ||
| 77 | + * | ||
| 78 | + * @param ids 编号数组 | ||
| 79 | + * @return 缺陷类型 Map | ||
| 80 | + */ | ||
| 81 | + default Map<Long, MesQcDefectDO> getDefectMap(Collection<Long> ids) { | ||
| 82 | + return convertMap(getDefectList(ids), MesQcDefectDO::getId); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/MesQcDefectServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.service.qc; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 4 | +import cn.hutool.core.util.ObjUtil; | ||
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 7 | +import cn.iocoder.yudao.module.mes.controller.admin.qc.vo.MesQcDefectPageReqVO; | ||
| 8 | +import cn.iocoder.yudao.module.mes.controller.admin.qc.vo.MesQcDefectSaveReqVO; | ||
| 9 | +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.MesQcDefectDO; | ||
| 10 | +import cn.iocoder.yudao.module.mes.dal.mysql.qc.MesQcDefectMapper; | ||
| 11 | +import jakarta.annotation.Resource; | ||
| 12 | +import org.springframework.stereotype.Service; | ||
| 13 | +import org.springframework.validation.annotation.Validated; | ||
| 14 | + | ||
| 15 | +import java.util.Collection; | ||
| 16 | +import java.util.Collections; | ||
| 17 | +import java.util.List; | ||
| 18 | + | ||
| 19 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 20 | +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * MES 缺陷类型 Service 实现类 | ||
| 24 | + * | ||
| 25 | + * @author 芋道源码 | ||
| 26 | + */ | ||
| 27 | +@Service | ||
| 28 | +@Validated | ||
| 29 | +public class MesQcDefectServiceImpl implements MesQcDefectService { | ||
| 30 | + | ||
| 31 | + @Resource | ||
| 32 | + private MesQcDefectMapper defectMapper; | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public Long createDefect(MesQcDefectSaveReqVO createReqVO) { | ||
| 36 | + // 校验编码唯一 | ||
| 37 | + validateDefectCodeUnique(null, createReqVO.getCode()); | ||
| 38 | + // 校验名称唯一 | ||
| 39 | + validateDefectNameUnique(null, createReqVO.getName()); | ||
| 40 | + | ||
| 41 | + // 插入 | ||
| 42 | + MesQcDefectDO defect = BeanUtils.toBean(createReqVO, MesQcDefectDO.class); | ||
| 43 | + defectMapper.insert(defect); | ||
| 44 | + return defect.getId(); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public void updateDefect(MesQcDefectSaveReqVO updateReqVO) { | ||
| 49 | + // 校验存在 | ||
| 50 | + validateDefectExists(updateReqVO.getId()); | ||
| 51 | + // 校验编码唯一 | ||
| 52 | + validateDefectCodeUnique(updateReqVO.getId(), updateReqVO.getCode()); | ||
| 53 | + // 校验名称唯一 | ||
| 54 | + validateDefectNameUnique(updateReqVO.getId(), updateReqVO.getName()); | ||
| 55 | + | ||
| 56 | + // 更新 | ||
| 57 | + MesQcDefectDO updateObj = BeanUtils.toBean(updateReqVO, MesQcDefectDO.class); | ||
| 58 | + defectMapper.updateById(updateObj); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + @Override | ||
| 62 | + public void deleteDefect(Long id) { | ||
| 63 | + // 校验存在 | ||
| 64 | + validateDefectExists(id); | ||
| 65 | + // 删除 | ||
| 66 | + defectMapper.deleteById(id); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + private void validateDefectExists(Long id) { | ||
| 70 | + if (defectMapper.selectById(id) == null) { | ||
| 71 | + throw exception(QC_DEFECT_NOT_EXISTS); | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + private void validateDefectCodeUnique(Long id, String code) { | ||
| 76 | + MesQcDefectDO defect = defectMapper.selectByCode(code); | ||
| 77 | + if (defect == null) { | ||
| 78 | + return; | ||
| 79 | + } | ||
| 80 | + if (ObjUtil.notEqual(defect.getId(), id)) { | ||
| 81 | + throw exception(QC_DEFECT_CODE_DUPLICATE); | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + private void validateDefectNameUnique(Long id, String name) { | ||
| 86 | + MesQcDefectDO defect = defectMapper.selectByName(name); | ||
| 87 | + if (defect == null) { | ||
| 88 | + return; | ||
| 89 | + } | ||
| 90 | + if (ObjUtil.notEqual(defect.getId(), id)) { | ||
| 91 | + throw exception(QC_DEFECT_NAME_DUPLICATE); | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + @Override | ||
| 96 | + public MesQcDefectDO getDefect(Long id) { | ||
| 97 | + return defectMapper.selectById(id); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + @Override | ||
| 101 | + public PageResult<MesQcDefectDO> getDefectPage(MesQcDefectPageReqVO pageReqVO) { | ||
| 102 | + return defectMapper.selectPage(pageReqVO); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + @Override | ||
| 106 | + public List<MesQcDefectDO> getDefectList() { | ||
| 107 | + return defectMapper.selectList(); | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + @Override | ||
| 111 | + public List<MesQcDefectDO> getDefectList(Collection<Long> ids) { | ||
| 112 | + if (CollUtil.isEmpty(ids)) { | ||
| 113 | + return Collections.emptyList(); | ||
| 114 | + } | ||
| 115 | + return defectMapper.selectByIds(ids); | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | +} |