| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.system.mapper.TProjectTeamMapper; |
| | | import com.ruoyi.system.mapper.TQaTestItemMapper; |
| | | import com.ruoyi.system.mapper.TQaTestItemReportMapper; |
| | | import com.ruoyi.system.model.TProjectTeam; |
| | | import com.ruoyi.system.model.TQaTestItem; |
| | | import com.ruoyi.system.model.TQaTestItemReport; |
| | | import com.ruoyi.system.query.TQaTestItemQuery; |
| | | import com.ruoyi.system.service.TQaTestItemService; |
| | | import com.ruoyi.system.vo.TQaTestItemVO; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.List; |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class TQaTestItemServiceImpl extends ServiceImpl<TQaTestItemMapper, TQaTestItem> implements TQaTestItemService { |
| | | |
| | | @Resource |
| | | private TQaTestItemReportMapper tQaTestItemReportMapper; |
| | | @Resource |
| | | private TProjectTeamMapper tProjectTeamMapper; |
| | | |
| | | @Override |
| | | public PageInfo<TQaTestItemVO> pageList(TQaTestItemQuery query) { |
| | | PageInfo<TQaTestItemVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | List<TQaTestItemVO> list = this.baseMapper.pageList(query,pageInfo); |
| | | pageInfo.setRecords(list); |
| | | |
| | | // 1. 先查所有数据(不分页) |
| | | List<TQaTestItemVO> allList = new ArrayList<>(); |
| | | |
| | | List<TQaTestItemVO> list = this.baseMapper.pageList(query,null);//先不分页 |
| | | if (list != null) { |
| | | allList.addAll(list); |
| | | } |
| | | |
| | | if (query.getStatus() != null && query.getStatus() == -1) { |
| | | //增加 在草稿箱的子元素 |
| | | LambdaQueryWrapper<TQaTestItemReport> tQaTestItemReportLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | tQaTestItemReportLambdaQueryWrapper.eq(TQaTestItemReport :: getStatus, -1); |
| | | tQaTestItemReportLambdaQueryWrapper.in(TQaTestItemReport :: getDisabled, false); |
| | | |
| | | List<String> teamIds = query.getTeamIds(); |
| | | if (teamIds != null && !teamIds.isEmpty()) { |
| | | // 使用 inSql 嵌套查询 |
| | | String teamIdsStr = teamIds.stream() |
| | | .map(String::valueOf) |
| | | .collect(Collectors.joining(",")); |
| | | |
| | | tQaTestItemReportLambdaQueryWrapper.inSql(TQaTestItemReport::getItemId, |
| | | "SELECT id FROM t_qa_test_item WHERE team_id IN (" + teamIdsStr + ")"); |
| | | } |
| | | |
| | | List<TQaTestItemReport> tQaTestItemReports = tQaTestItemReportMapper.selectList(tQaTestItemReportLambdaQueryWrapper); |
| | | if (tQaTestItemReports != null && !tQaTestItemReports.isEmpty()) { |
| | | // 提取 itemId 并去重 |
| | | List<String> distinctItemIds = tQaTestItemReports.stream() |
| | | .map(TQaTestItemReport::getItemId) // 假设子表中有 itemId 字段 |
| | | .filter(Objects::nonNull) // 过滤掉 null |
| | | .distinct() // 去重 |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 用去重后的 itemId 查询主表数据 |
| | | if (!distinctItemIds.isEmpty()) { |
| | | LambdaQueryWrapper<TQaTestItem> mainWrapper = new LambdaQueryWrapper<>(); |
| | | mainWrapper.in(TQaTestItem::getId, distinctItemIds); |
| | | // 如果还需要 teamId 过滤,可以再加 |
| | | if (teamIds != null && !teamIds.isEmpty()) { |
| | | mainWrapper.in(TQaTestItem::getTeamId, teamIds); |
| | | } |
| | | mainWrapper.ne(TQaTestItem::getStatus, -1) |
| | | .isNotNull(TQaTestItem::getStatus); // 排除 null 值 |
| | | List<TQaTestItem> mainDataList = this.baseMapper.selectList(mainWrapper); |
| | | |
| | | // TODO: 将 mainDataList 转换为 TQaTestItemVO 并添加到 list 中 |
| | | List<TQaTestItemVO> tQaTestItemVOList = new ArrayList<>(); |
| | | for (TQaTestItem tQaTestItem : mainDataList) { |
| | | TQaTestItemVO tQaTestItemVO = new TQaTestItemVO(); |
| | | |
| | | BeanUtils.copyProperties(tQaTestItem, tQaTestItemVO); |
| | | |
| | | TProjectTeam tProjectTeam = tProjectTeamMapper.selectById(tQaTestItem.getTeamId()); |
| | | if (tProjectTeam != null) { |
| | | tQaTestItemVO.setTeamName(tProjectTeam.getTeamName()); |
| | | } |
| | | tQaTestItemVOList.add(tQaTestItemVO); |
| | | } |
| | | |
| | | allList.addAll(tQaTestItemVOList); |
| | | |
| | | //去重 |
| | | allList = allList.stream() |
| | | .collect(Collectors.collectingAndThen( |
| | | Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(TQaTestItemVO::getId))), |
| | | ArrayList::new |
| | | )); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //统一排序 |
| | | allList.sort(Comparator.comparing(TQaTestItemVO::getCreateTime, Comparator.nullsLast(Comparator.reverseOrder()))); |
| | | |
| | | // 手动分页 |
| | | int total = allList.size(); |
| | | int start = (query.getPageNum() - 1) * query.getPageSize(); |
| | | int end = Math.min(start + query.getPageSize(), total); |
| | | |
| | | List<TQaTestItemVO> pageRecords = new ArrayList<>(); |
| | | if (start < total) { |
| | | pageRecords = allList.subList(start, end); |
| | | } |
| | | |
| | | pageInfo.setTotal(total); |
| | | pageInfo.setRecords(pageRecords); |
| | | return pageInfo; |
| | | } |
| | | |