Commit d86453bb7e13da05cda51fd645456d4b8270c6ee

Authored by YunaiV
1 parent 2006ce7a

feat(mes): 新增设备点检记录相关功能,包括记录明细接口及表单组件

yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/checkplan/MesDvCheckPlanMachineryController.java
... ... @@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.mes.controller.admin.dv.checkplan;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5   -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
  5 +import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
6 6 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
7 7 import cn.iocoder.yudao.module.mes.controller.admin.dv.checkplan.vo.machinery.MesDvCheckPlanMachineryRespVO;
8 8 import cn.iocoder.yudao.module.mes.controller.admin.dv.checkplan.vo.machinery.MesDvCheckPlanMachinerySaveReqVO;
... ... @@ -19,10 +19,12 @@ import org.springframework.security.access.prepost.PreAuthorize;
19 19 import org.springframework.validation.annotation.Validated;
20 20 import org.springframework.web.bind.annotation.*;
21 21  
  22 +import java.util.Collections;
22 23 import java.util.List;
23 24 import java.util.Map;
24 25  
25 26 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  27 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
26 28  
27 29 @Tag(name = "管理后台 - MES 点检保养方案设备")
28 30 @RestController
... ... @@ -58,27 +60,24 @@ public class MesDvCheckPlanMachineryController {
58 60 public CommonResult<List<MesDvCheckPlanMachineryRespVO>> getCheckPlanMachineryListByPlan(
59 61 @RequestParam("planId") Long planId) {
60 62 List<MesDvCheckPlanMachineryDO> list = checkPlanMachineryService.getCheckPlanMachineryListByPlanId(planId);
61   - List<MesDvCheckPlanMachineryRespVO> respList = BeanUtils.toBean(list, MesDvCheckPlanMachineryRespVO.class);
62   - // TODO @AI:为空,直接 return;
63   - // 拼装设备编码/名称/品牌/规格
64   - // TODO @AI:拆出来,放在 buildVO 那;
65   - if (CollUtil.isNotEmpty(respList)) {
66   - // TODO @AI:convertMap;
67   - List<Long> machineryIds = CollectionUtils.convertList(respList, MesDvCheckPlanMachineryRespVO::getMachineryId);
68   - // TODO @AI:这里暂时没实现;
69   - Map<Long, MesDvMachineryDO> machineryMap = machineryService.getMachineryMap(machineryIds);
70   - respList.forEach(resp -> {
71   - MesDvMachineryDO machinery = machineryMap.get(resp.getMachineryId());
72   - if (machinery != null) {
73   - // TODO @AI:链式调用;
74   - resp.setMachineryCode(machinery.getCode());
75   - resp.setMachineryName(machinery.getName());
76   - resp.setMachineryBrand(machinery.getBrand());
77   - resp.setMachinerySpec(machinery.getSpec());
78   - }
79   - });
  63 + return success(buildCheckPlanMachineryRespVOList(list));
  64 + }
  65 +
  66 + // ==================== 拼接 VO ====================
  67 +
  68 + private List<MesDvCheckPlanMachineryRespVO> buildCheckPlanMachineryRespVOList(
  69 + List<MesDvCheckPlanMachineryDO> list) {
  70 + if (CollUtil.isEmpty(list)) {
  71 + return Collections.emptyList();
80 72 }
81   - return success(respList);
  73 + Map<Long, MesDvMachineryDO> machineryMap = machineryService.getMachineryMap(
  74 + convertSet(list, MesDvCheckPlanMachineryDO::getMachineryId));
  75 + return BeanUtils.toBean(list, MesDvCheckPlanMachineryRespVO.class, vo ->
  76 + MapUtils.findAndThen(machineryMap, vo.getMachineryId(), machinery ->
  77 + vo.setMachineryCode(machinery.getCode()).setMachineryName(machinery.getName())
  78 + .setMachineryBrand(machinery.getBrand()).setMachinerySpec(machinery.getSpec())
  79 + )
  80 + );
82 81 }
83 82  
84 83 }
... ...