| | |
| | | package cn.iocoder.yudao.module.mes.controller.admin.qc.indicator; |
| | | |
| | | 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 org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | |
| | | @PreAuthorize("@ss.hasPermission('mes:qc-indicator:query')") |
| | | public CommonResult<MesQcIndicatorRespVO> getIndicator(@RequestParam("id") Long id) { |
| | | MesQcIndicatorDO indicator = indicatorService.getIndicator(id); |
| | | return success(BeanUtils.toBean(indicator, MesQcIndicatorRespVO.class)); |
| | | return success(buildRespVOList(Collections.singletonList(indicator)).get(0)); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | |
| | | @PreAuthorize("@ss.hasPermission('mes:qc-indicator:query')") |
| | | public CommonResult<PageResult<MesQcIndicatorRespVO>> getIndicatorPage(@Valid MesQcIndicatorPageReqVO pageReqVO) { |
| | | PageResult<MesQcIndicatorDO> pageResult = indicatorService.getIndicatorPage(pageReqVO); |
| | | return success(BeanUtils.toBean(pageResult, MesQcIndicatorRespVO.class)); |
| | | return success(new PageResult<>(buildRespVOList(pageResult.getList()), pageResult.getTotal())); |
| | | } |
| | | |
| | | @GetMapping("/list") |
| | | @Operation(summary = "获得质检指标全量列表(含分组层级,供树表/下拉使用)") |
| | | @PreAuthorize("@ss.hasPermission('mes:qc-indicator:query')") |
| | | public CommonResult<List<MesQcIndicatorRespVO>> getIndicatorList() { |
| | | return success(buildRespVOList(indicatorService.getIndicatorList())); |
| | | } |
| | | |
| | | @GetMapping("/export-excel") |
| | |
| | | BeanUtils.toBean(list, MesQcIndicatorRespVO.class)); |
| | | } |
| | | |
| | | // ==================== 拼接 VO ==================== |
| | | |
| | | private List<MesQcIndicatorRespVO> buildRespVOList(List<MesQcIndicatorDO> list) { |
| | | List<MesQcIndicatorRespVO> voList = BeanUtils.toBean(list, MesQcIndicatorRespVO.class); |
| | | if (CollUtil.isEmpty(list)) { |
| | | return voList; |
| | | } |
| | | // 填充父指标名称 |
| | | Set<Long> parentIds = list.stream().map(MesQcIndicatorDO::getParentId) |
| | | .filter(pid -> pid != null && pid > 0).collect(Collectors.toSet()); |
| | | if (CollUtil.isNotEmpty(parentIds)) { |
| | | Map<Long, String> parentNameMap = indicatorService.getIndicatorList(parentIds).stream() |
| | | .collect(Collectors.toMap(MesQcIndicatorDO::getId, MesQcIndicatorDO::getName)); |
| | | voList.forEach(vo -> { |
| | | if (vo.getParentId() != null && vo.getParentId() > 0) { |
| | | vo.setParentName(parentNameMap.get(vo.getParentId())); |
| | | } |
| | | }); |
| | | } |
| | | return voList; |
| | | } |
| | | |
| | | } |