云
14 小时以前 fec1341c1cb8e11cfbe3fa7dfabe447edb72b630
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/dv/machinery/MesDvMachineryController.java
@@ -52,6 +52,8 @@
    private MesDvMachineryTypeService machineryTypeService;
    @Resource
    private MesMdWorkshopService workshopService;
    @Resource
    private cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationService workstationService;
    @PostMapping("/create")
    @Operation(summary = "创建设备")
@@ -80,7 +82,6 @@
    @GetMapping("/get")
    @Operation(summary = "获得设备")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:dv-machinery:query')")
    public CommonResult<MesDvMachineryRespVO> getMachinery(@RequestParam("id") Long id) {
        MesDvMachineryDO machinery = machineryService.getMachinery(id);
        if (machinery == null) {
@@ -91,7 +92,6 @@
    @GetMapping("/page")
    @Operation(summary = "获得设备分页")
    @PreAuthorize("@ss.hasPermission('mes:dv-machinery:query')")
    public CommonResult<PageResult<MesDvMachineryRespVO>> getMachineryPage(@Valid MesDvMachineryPageReqVO pageReqVO) {
        PageResult<MesDvMachineryDO> pageResult = machineryService.getMachineryPage(pageReqVO);
        return success(new PageResult<>(buildMachineryRespVOList(pageResult.getList()), pageResult.getTotal()));
@@ -112,7 +112,6 @@
    @GetMapping("/simple-list")
    @Operation(summary = "获得设备精简列表", description = "主要用于前端的下拉选项")
    @PreAuthorize("@ss.hasPermission('mes:dv-machinery:query')")
    public CommonResult<List<MesDvMachineryRespVO>> getMachinerySimpleList() {
        List<MesDvMachineryDO> list = machineryService.getMachineryList();
        return success(BeanUtils.toBean(list, MesDvMachineryRespVO.class));
@@ -151,17 +150,21 @@
        if (CollUtil.isEmpty(list)) {
            return Collections.emptyList();
        }
        // 1. 批量获取设备类型和车间信息
        // 1. 批量获取设备类型、车间和工作站信息
        Map<Long, MesDvMachineryTypeDO> machineryTypeMap = machineryTypeService.getMachineryTypeMap(
                convertSet(list, MesDvMachineryDO::getMachineryTypeId));
        Map<Long, MesMdWorkshopDO> workshopMap = workshopService.getWorkshopMap(
                convertSet(list, MesDvMachineryDO::getWorkshopId));
        Map<Long, cn.iocoder.yudao.module.mes.dal.dataobject.md.workstation.MesMdWorkstationDO> workstationMap =
                workstationService.getWorkstationMap(convertSet(list, MesDvMachineryDO::getWorkstationId));
        // 2. 拼接 VO
        return BeanUtils.toBean(list, MesDvMachineryRespVO.class, vo -> {
            MapUtils.findAndThen(machineryTypeMap, vo.getMachineryTypeId(),
                    machineryType -> vo.setMachineryTypeName(machineryType.getName()));
            MapUtils.findAndThen(workshopMap, vo.getWorkshopId(),
                    workshop -> vo.setWorkshopName(workshop.getName()));
            MapUtils.findAndThen(workstationMap, vo.getWorkstationId(),
                    workstation -> vo.setWorkstationName(workstation.getName()));
        });
    }