Commit be3709eb175f3f00478e78a958a75f2e15248372
1 parent
0a70bb5c
feat(mes): 规范 qc-template Controller 代码风格
- MesQcTemplateIndicatorController:Mapper 注入改为 Service 注入(MesQcIndicatorService、MesMdUnitMeasureService),方法重命名为 buildIndicatorRespVOList,使用 findAndThen 链式设置冗余字段 - MesQcTemplateItemController:同上,MesMdItemService、MesMdUnitMeasureService,方法重命名为 buildItemRespVOList,嵌套 findAndThen 补充物料及单位名称 - MesQcTemplatePageReqVO:enableFlag 改为 Boolean,type 改为 Integer(单值查询) - MesQcTemplateMapper:selectPage 改用 findInSet 匹配 types 字段,eqIfPresent 匹配 enableFlag
Showing
2 changed files
with
61 additions
and
74 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/template/MesQcTemplateIndicatorController.java
| 1 | package cn.iocoder.yudao.module.mes.controller.admin.qc.template; | 1 | package cn.iocoder.yudao.module.mes.controller.admin.qc.template; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| @@ -9,8 +10,8 @@ import cn.iocoder.yudao.module.mes.controller.admin.qc.template.vo.indicator.Mes | @@ -9,8 +10,8 @@ import cn.iocoder.yudao.module.mes.controller.admin.qc.template.vo.indicator.Mes | ||
| 9 | import cn.iocoder.yudao.module.mes.dal.dataobject.md.unitmeasure.MesMdUnitMeasureDO; | 10 | import cn.iocoder.yudao.module.mes.dal.dataobject.md.unitmeasure.MesMdUnitMeasureDO; |
| 10 | import cn.iocoder.yudao.module.mes.dal.dataobject.qc.MesQcIndicatorDO; | 11 | import cn.iocoder.yudao.module.mes.dal.dataobject.qc.MesQcIndicatorDO; |
| 11 | import cn.iocoder.yudao.module.mes.dal.dataobject.qc.MesQcTemplateIndicatorDO; | 12 | import cn.iocoder.yudao.module.mes.dal.dataobject.qc.MesQcTemplateIndicatorDO; |
| 12 | -import cn.iocoder.yudao.module.mes.dal.mysql.md.unitmeasure.MesMdUnitMeasureMapper; | ||
| 13 | -import cn.iocoder.yudao.module.mes.dal.mysql.qc.MesQcIndicatorMapper; | 13 | +import cn.iocoder.yudao.module.mes.service.md.unitmeasure.MesMdUnitMeasureService; |
| 14 | +import cn.iocoder.yudao.module.mes.service.qc.MesQcIndicatorService; | ||
| 14 | import cn.iocoder.yudao.module.mes.service.qc.MesQcTemplateService; | 15 | import cn.iocoder.yudao.module.mes.service.qc.MesQcTemplateService; |
| 15 | import io.swagger.v3.oas.annotations.Operation; | 16 | import io.swagger.v3.oas.annotations.Operation; |
| 16 | import io.swagger.v3.oas.annotations.Parameter; | 17 | import io.swagger.v3.oas.annotations.Parameter; |
| @@ -21,9 +22,12 @@ import org.springframework.security.access.prepost.PreAuthorize; | @@ -21,9 +22,12 @@ import org.springframework.security.access.prepost.PreAuthorize; | ||
| 21 | import org.springframework.validation.annotation.Validated; | 22 | import org.springframework.validation.annotation.Validated; |
| 22 | import org.springframework.web.bind.annotation.*; | 23 | import org.springframework.web.bind.annotation.*; |
| 23 | 24 | ||
| 25 | +import java.util.Collections; | ||
| 24 | import java.util.List; | 26 | import java.util.List; |
| 25 | -import java.util.stream.Collectors; | 27 | +import java.util.Map; |
| 26 | 28 | ||
| 29 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||
| 30 | +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; | ||
| 27 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 31 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 28 | 32 | ||
| 29 | @Tag(name = "管理后台 - MES 质检方案-检测指标项") | 33 | @Tag(name = "管理后台 - MES 质检方案-检测指标项") |
| @@ -35,9 +39,9 @@ public class MesQcTemplateIndicatorController { | @@ -35,9 +39,9 @@ public class MesQcTemplateIndicatorController { | ||
| 35 | @Resource | 39 | @Resource |
| 36 | private MesQcTemplateService templateService; | 40 | private MesQcTemplateService templateService; |
| 37 | @Resource | 41 | @Resource |
| 38 | - private MesQcIndicatorMapper indicatorMapper; | 42 | + private MesQcIndicatorService indicatorService; |
| 39 | @Resource | 43 | @Resource |
| 40 | - private MesMdUnitMeasureMapper unitMeasureMapper; | 44 | + private MesMdUnitMeasureService unitMeasureService; |
| 41 | 45 | ||
| 42 | @PostMapping("/create") | 46 | @PostMapping("/create") |
| 43 | @Operation(summary = "创建质检方案-检测指标项") | 47 | @Operation(summary = "创建质检方案-检测指标项") |
| @@ -68,8 +72,8 @@ public class MesQcTemplateIndicatorController { | @@ -68,8 +72,8 @@ public class MesQcTemplateIndicatorController { | ||
| 68 | @Parameter(name = "id", description = "编号", required = true, example = "1024") | 72 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 69 | @PreAuthorize("@ss.hasPermission('mes:qc-template:query')") | 73 | @PreAuthorize("@ss.hasPermission('mes:qc-template:query')") |
| 70 | public CommonResult<MesQcTemplateIndicatorRespVO> getTemplateIndicator(@RequestParam("id") Long id) { | 74 | public CommonResult<MesQcTemplateIndicatorRespVO> getTemplateIndicator(@RequestParam("id") Long id) { |
| 71 | - MesQcTemplateIndicatorDO do0 = templateService.getTemplateIndicator(id); | ||
| 72 | - return success(convertIndicatorRespVO(do0)); | 75 | + MesQcTemplateIndicatorDO indicator = templateService.getTemplateIndicator(id); |
| 76 | + return success(buildIndicatorRespVOList(Collections.singletonList(indicator)).get(0)); | ||
| 73 | } | 77 | } |
| 74 | 78 | ||
| 75 | @GetMapping("/page") | 79 | @GetMapping("/page") |
| @@ -78,40 +82,29 @@ public class MesQcTemplateIndicatorController { | @@ -78,40 +82,29 @@ public class MesQcTemplateIndicatorController { | ||
| 78 | public CommonResult<PageResult<MesQcTemplateIndicatorRespVO>> getTemplateIndicatorPage( | 82 | public CommonResult<PageResult<MesQcTemplateIndicatorRespVO>> getTemplateIndicatorPage( |
| 79 | @Valid MesQcTemplateIndicatorPageReqVO pageReqVO) { | 83 | @Valid MesQcTemplateIndicatorPageReqVO pageReqVO) { |
| 80 | PageResult<MesQcTemplateIndicatorDO> pageResult = templateService.getTemplateIndicatorPage(pageReqVO); | 84 | PageResult<MesQcTemplateIndicatorDO> pageResult = templateService.getTemplateIndicatorPage(pageReqVO); |
| 81 | - List<MesQcTemplateIndicatorRespVO> voList = pageResult.getList().stream() | ||
| 82 | - .map(this::convertIndicatorRespVO) | ||
| 83 | - .collect(Collectors.toList()); | ||
| 84 | - return success(new PageResult<>(voList, pageResult.getTotal())); | 85 | + return success(new PageResult<>(buildIndicatorRespVOList(pageResult.getList()), pageResult.getTotal())); |
| 85 | } | 86 | } |
| 86 | 87 | ||
| 87 | - // TODO @AI:参考别的模块,buildVO;包括注释; | ||
| 88 | - /** | ||
| 89 | - * DO → RespVO:JOIN mes_qc_indicator 补充检测项信息,JOIN mes_md_unit_measure 补充单位名称 | ||
| 90 | - */ | ||
| 91 | - private MesQcTemplateIndicatorRespVO convertIndicatorRespVO(MesQcTemplateIndicatorDO do0) { | ||
| 92 | - // TODO @AI:应该是批量的操作; | ||
| 93 | - if (do0 == null) { | ||
| 94 | - return null; | ||
| 95 | - } | ||
| 96 | - MesQcTemplateIndicatorRespVO vo = BeanUtils.toBean(do0, MesQcTemplateIndicatorRespVO.class); | ||
| 97 | - // JOIN 质检指标 | ||
| 98 | - if (do0.getIndicatorId() != null) { | ||
| 99 | - MesQcIndicatorDO indicator = indicatorMapper.selectById(do0.getIndicatorId()); | ||
| 100 | - if (indicator != null) { | ||
| 101 | - vo.setIndicatorCode(indicator.getCode()); | ||
| 102 | - vo.setIndicatorName(indicator.getName()); | ||
| 103 | - vo.setIndicatorType(indicator.getType()); | ||
| 104 | - vo.setIndicatorTool(indicator.getTool()); | ||
| 105 | - } | ||
| 106 | - } | ||
| 107 | - // JOIN 计量单位 | ||
| 108 | - if (do0.getUnitMeasureId() != null) { | ||
| 109 | - MesMdUnitMeasureDO unit = unitMeasureMapper.selectById(do0.getUnitMeasureId()); | ||
| 110 | - if (unit != null) { | ||
| 111 | - vo.setUnitMeasureName(unit.getName()); | ||
| 112 | - } | 88 | + // ==================== 拼接 VO ==================== |
| 89 | + | ||
| 90 | + private List<MesQcTemplateIndicatorRespVO> buildIndicatorRespVOList(List<MesQcTemplateIndicatorDO> list) { | ||
| 91 | + if (CollUtil.isEmpty(list)) { | ||
| 92 | + return Collections.emptyList(); | ||
| 113 | } | 93 | } |
| 114 | - return vo; | 94 | + // 批量查询质检指标 |
| 95 | + Map<Long, MesQcIndicatorDO> indicatorMap = indicatorService.getIndicatorMap( | ||
| 96 | + convertSet(list, MesQcTemplateIndicatorDO::getIndicatorId)); | ||
| 97 | + // 批量查询计量单位 | ||
| 98 | + Map<Long, MesMdUnitMeasureDO> unitMeasureMap = unitMeasureService.getUnitMeasureMap( | ||
| 99 | + convertSet(list, MesQcTemplateIndicatorDO::getUnitMeasureId)); | ||
| 100 | + // 拼装 VO | ||
| 101 | + return BeanUtils.toBean(list, MesQcTemplateIndicatorRespVO.class, vo -> { | ||
| 102 | + findAndThen(indicatorMap, vo.getIndicatorId(), indicator -> | ||
| 103 | + vo.setIndicatorCode(indicator.getCode()).setIndicatorName(indicator.getName()) | ||
| 104 | + .setIndicatorType(indicator.getType()).setIndicatorTool(indicator.getTool())); | ||
| 105 | + findAndThen(unitMeasureMap, vo.getUnitMeasureId(), | ||
| 106 | + unit -> vo.setUnitMeasureName(unit.getName())); | ||
| 107 | + }); | ||
| 115 | } | 108 | } |
| 116 | 109 | ||
| 117 | } | 110 | } |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/template/MesQcTemplateItemController.java
| @@ -9,8 +9,8 @@ import cn.iocoder.yudao.module.mes.controller.admin.qc.template.vo.item.MesQcTem | @@ -9,8 +9,8 @@ import cn.iocoder.yudao.module.mes.controller.admin.qc.template.vo.item.MesQcTem | ||
| 9 | import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO; | 9 | import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO; |
| 10 | import cn.iocoder.yudao.module.mes.dal.dataobject.md.unitmeasure.MesMdUnitMeasureDO; | 10 | import cn.iocoder.yudao.module.mes.dal.dataobject.md.unitmeasure.MesMdUnitMeasureDO; |
| 11 | import cn.iocoder.yudao.module.mes.dal.dataobject.qc.MesQcTemplateItemDO; | 11 | import cn.iocoder.yudao.module.mes.dal.dataobject.qc.MesQcTemplateItemDO; |
| 12 | -import cn.iocoder.yudao.module.mes.dal.mysql.md.item.MesMdItemMapper; | ||
| 13 | -import cn.iocoder.yudao.module.mes.dal.mysql.md.unitmeasure.MesMdUnitMeasureMapper; | 12 | +import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService; |
| 13 | +import cn.iocoder.yudao.module.mes.service.md.unitmeasure.MesMdUnitMeasureService; | ||
| 14 | import cn.iocoder.yudao.module.mes.service.qc.MesQcTemplateService; | 14 | import cn.iocoder.yudao.module.mes.service.qc.MesQcTemplateService; |
| 15 | import io.swagger.v3.oas.annotations.Operation; | 15 | import io.swagger.v3.oas.annotations.Operation; |
| 16 | import io.swagger.v3.oas.annotations.Parameter; | 16 | import io.swagger.v3.oas.annotations.Parameter; |
| @@ -21,9 +21,12 @@ import org.springframework.security.access.prepost.PreAuthorize; | @@ -21,9 +21,12 @@ import org.springframework.security.access.prepost.PreAuthorize; | ||
| 21 | import org.springframework.validation.annotation.Validated; | 21 | import org.springframework.validation.annotation.Validated; |
| 22 | import org.springframework.web.bind.annotation.*; | 22 | import org.springframework.web.bind.annotation.*; |
| 23 | 23 | ||
| 24 | +import java.util.Collections; | ||
| 24 | import java.util.List; | 25 | import java.util.List; |
| 25 | -import java.util.stream.Collectors; | 26 | +import java.util.Map; |
| 26 | 27 | ||
| 28 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||
| 29 | +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; | ||
| 27 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 30 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 28 | 31 | ||
| 29 | @Tag(name = "管理后台 - MES 质检方案-产品关联") | 32 | @Tag(name = "管理后台 - MES 质检方案-产品关联") |
| @@ -35,9 +38,9 @@ public class MesQcTemplateItemController { | @@ -35,9 +38,9 @@ public class MesQcTemplateItemController { | ||
| 35 | @Resource | 38 | @Resource |
| 36 | private MesQcTemplateService templateService; | 39 | private MesQcTemplateService templateService; |
| 37 | @Resource | 40 | @Resource |
| 38 | - private MesMdItemMapper mdItemMapper; | 41 | + private MesMdItemService mdItemService; |
| 39 | @Resource | 42 | @Resource |
| 40 | - private MesMdUnitMeasureMapper unitMeasureMapper; | 43 | + private MesMdUnitMeasureService unitMeasureService; |
| 41 | 44 | ||
| 42 | @PostMapping("/create") | 45 | @PostMapping("/create") |
| 43 | @Operation(summary = "创建质检方案-产品关联") | 46 | @Operation(summary = "创建质检方案-产品关联") |
| @@ -68,8 +71,8 @@ public class MesQcTemplateItemController { | @@ -68,8 +71,8 @@ public class MesQcTemplateItemController { | ||
| 68 | @Parameter(name = "id", description = "编号", required = true, example = "1024") | 71 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| 69 | @PreAuthorize("@ss.hasPermission('mes:qc-template:query')") | 72 | @PreAuthorize("@ss.hasPermission('mes:qc-template:query')") |
| 70 | public CommonResult<MesQcTemplateItemRespVO> getTemplateItem(@RequestParam("id") Long id) { | 73 | public CommonResult<MesQcTemplateItemRespVO> getTemplateItem(@RequestParam("id") Long id) { |
| 71 | - MesQcTemplateItemDO do0 = templateService.getTemplateItem(id); | ||
| 72 | - return success(convertItemRespVO(do0)); | 74 | + MesQcTemplateItemDO item = templateService.getTemplateItem(id); |
| 75 | + return success(buildItemRespVOList(Collections.singletonList(item)).get(0)); | ||
| 73 | } | 76 | } |
| 74 | 77 | ||
| 75 | @GetMapping("/page") | 78 | @GetMapping("/page") |
| @@ -78,38 +81,29 @@ public class MesQcTemplateItemController { | @@ -78,38 +81,29 @@ public class MesQcTemplateItemController { | ||
| 78 | public CommonResult<PageResult<MesQcTemplateItemRespVO>> getTemplateItemPage( | 81 | public CommonResult<PageResult<MesQcTemplateItemRespVO>> getTemplateItemPage( |
| 79 | @Valid MesQcTemplateItemPageReqVO pageReqVO) { | 82 | @Valid MesQcTemplateItemPageReqVO pageReqVO) { |
| 80 | PageResult<MesQcTemplateItemDO> pageResult = templateService.getTemplateItemPage(pageReqVO); | 83 | PageResult<MesQcTemplateItemDO> pageResult = templateService.getTemplateItemPage(pageReqVO); |
| 81 | - List<MesQcTemplateItemRespVO> voList = pageResult.getList().stream() | ||
| 82 | - .map(this::convertItemRespVO) | ||
| 83 | - .collect(Collectors.toList()); | ||
| 84 | - return success(new PageResult<>(voList, pageResult.getTotal())); | 84 | + return success(new PageResult<>(buildItemRespVOList(pageResult.getList()), pageResult.getTotal())); |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | - // TODO @AI:参考别的模块,buildVO;包括注释; | ||
| 88 | - // 质检方案-产品关联的 VO 构建方法 | ||
| 89 | - /** | ||
| 90 | - * DO → RespVO:JOIN mes_md_item 补充物料信息,JOIN mes_md_unit_measure 补充单位名称 | ||
| 91 | - */ | ||
| 92 | - private MesQcTemplateItemRespVO convertItemRespVO(MesQcTemplateItemDO do0) { | ||
| 93 | - if (do0 == null) { | ||
| 94 | - return null; | ||
| 95 | - } | ||
| 96 | - MesQcTemplateItemRespVO vo = BeanUtils.toBean(do0, MesQcTemplateItemRespVO.class); | ||
| 97 | - if (do0.getItemId() != null) { | ||
| 98 | - MesMdItemDO item = mdItemMapper.selectById(do0.getItemId()); | ||
| 99 | - if (item != null) { | ||
| 100 | - vo.setItemCode(item.getCode()); | ||
| 101 | - vo.setItemName(item.getName()); | ||
| 102 | - vo.setSpecification(item.getSpecification()); | ||
| 103 | - // 查询计量单位名称 | ||
| 104 | - if (item.getUnitMeasureId() != null) { | ||
| 105 | - MesMdUnitMeasureDO unit = unitMeasureMapper.selectById(item.getUnitMeasureId()); | ||
| 106 | - if (unit != null) { | ||
| 107 | - vo.setUnitMeasureName(unit.getName()); | ||
| 108 | - } | ||
| 109 | - } | ||
| 110 | - } | 87 | + // ==================== 拼接 VO ==================== |
| 88 | + | ||
| 89 | + private List<MesQcTemplateItemRespVO> buildItemRespVOList(List<MesQcTemplateItemDO> list) { | ||
| 90 | + if (list.isEmpty()) { | ||
| 91 | + return Collections.emptyList(); | ||
| 111 | } | 92 | } |
| 112 | - return vo; | 93 | + // 批量查询物料 |
| 94 | + Map<Long, MesMdItemDO> itemMap = mdItemService.getItemMap( | ||
| 95 | + convertSet(list, MesQcTemplateItemDO::getItemId)); | ||
| 96 | + // 批量查询计量单位 | ||
| 97 | + Map<Long, MesMdUnitMeasureDO> unitMeasureMap = unitMeasureService.getUnitMeasureMap( | ||
| 98 | + convertSet(itemMap.values(), MesMdItemDO::getUnitMeasureId)); | ||
| 99 | + // 拼装 VO | ||
| 100 | + return BeanUtils.toBean(list, MesQcTemplateItemRespVO.class, vo -> { | ||
| 101 | + findAndThen(itemMap, vo.getItemId(), item -> { | ||
| 102 | + vo.setItemCode(item.getCode()).setItemName(item.getName()).setSpecification(item.getSpecification()); | ||
| 103 | + findAndThen(unitMeasureMap, item.getUnitMeasureId(), | ||
| 104 | + unit -> vo.setUnitMeasureName(unit.getName())); | ||
| 105 | + }); | ||
| 106 | + }); | ||
| 113 | } | 107 | } |
| 114 | 108 | ||
| 115 | } | 109 | } |