| | |
| | | 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 java.io.IOException; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| | | |
| | | @Tag(name = "管理后台 - MES 质检指标") |
| | | @RestController |
| | |
| | | @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)); |
| | | PageResult<MesQcIndicatorRespVO> voPageResult = BeanUtils.toBean(pageResult, MesQcIndicatorRespVO.class); |
| | | fillParentName(voPageResult.getList()); |
| | | return success(voPageResult); |
| | | } |
| | | |
| | | @GetMapping("/group-list") |
| | | @Operation(summary = "获得分组项精简列表", description = "只包含分组项,主要用于「所属分组」的下拉选项") |
| | | @PreAuthorize("@ss.hasPermission('mes:qc-indicator:query')") |
| | | public CommonResult<List<MesQcIndicatorRespVO>> getIndicatorGroupList() { |
| | | List<MesQcIndicatorDO> list = indicatorService.getIndicatorGroupList(); |
| | | return success(BeanUtils.toBean(list, MesQcIndicatorRespVO.class)); |
| | | } |
| | | |
| | | @GetMapping("/export-excel") |
| | |
| | | HttpServletResponse response) throws IOException { |
| | | pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
| | | List<MesQcIndicatorDO> list = indicatorService.getIndicatorPage(pageReqVO).getList(); |
| | | // 组装导出 VO(补齐所属分组名称) |
| | | List<MesQcIndicatorRespVO> excelList = BeanUtils.toBean(list, MesQcIndicatorRespVO.class); |
| | | fillParentName(excelList); |
| | | // 导出 Excel |
| | | ExcelUtils.write(response, "质检指标.xls", "数据", MesQcIndicatorRespVO.class, |
| | | BeanUtils.toBean(list, MesQcIndicatorRespVO.class)); |
| | | ExcelUtils.write(response, "质检指标.xls", "数据", MesQcIndicatorRespVO.class, excelList); |
| | | } |
| | | |
| | | /** |
| | | * 回填「所属分组」名称。父指标可能不在当前页(甚至不在筛选结果内),所以单独按 id 批量取一次 |
| | | */ |
| | | private void fillParentName(List<MesQcIndicatorRespVO> list) { |
| | | Set<Long> parentIds = convertSet(list, MesQcIndicatorRespVO::getParentId, |
| | | vo -> vo.getParentId() != null && !MesQcIndicatorDO.PARENT_ID_ROOT.equals(vo.getParentId())); |
| | | if (CollUtil.isEmpty(parentIds)) { |
| | | return; |
| | | } |
| | | Map<Long, String> parentNameMap = convertMap(indicatorService.getIndicatorList(parentIds), |
| | | MesQcIndicatorDO::getId, MesQcIndicatorDO::getName); |
| | | list.forEach(vo -> vo.setParentName(parentNameMap.get(vo.getParentId()))); |
| | | } |
| | | |
| | | } |