| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.system.mapper.TTrainLibraryMapper; |
| | | import com.ruoyi.system.model.TProjectTeam; |
| | | import com.ruoyi.system.model.TTrainLibrary; |
| | | import com.ruoyi.system.model.TTrainLibraryWarehousing; |
| | | import com.ruoyi.system.query.TTrainLibraryDetailQuery; |
| | | import com.ruoyi.system.query.TTrainLibraryQuery; |
| | | import com.ruoyi.system.service.TProjectTeamService; |
| | | import com.ruoyi.system.service.TTrainLibraryService; |
| | | import com.ruoyi.system.vo.TProjectTeamVO; |
| | | import com.ruoyi.system.vo.TTrainLibraryDetailVO; |
| | | import com.ruoyi.system.vo.TTrainLibraryVO; |
| | | import com.ruoyi.system.vo.TTrainLibraryWarehousingVO; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Service |
| | | public class TTrainLibraryServiceImpl extends ServiceImpl<TTrainLibraryMapper, TTrainLibrary> implements TTrainLibraryService { |
| | | @Resource |
| | | private TProjectTeamService projectTeamService; |
| | | |
| | | @Override |
| | | public PageInfo<TTrainLibraryVO> pageList(TTrainLibraryQuery query) { |
| | | PageInfo<TTrainLibraryVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | List<TTrainLibraryVO> list = this.baseMapper.pageList(query,pageInfo); |
| | | pageInfo.setRecords(list); |
| | | public PageInfo<TTrainLibraryVO> pageList(TTrainLibraryQuery query, String roleType) { |
| | | // 1. 查询所有符合条件的数据(不分页) |
| | | List<TTrainLibraryVO> allList = this.baseMapper.listAll(query); |
| | | |
| | | // 2. 在内存中过滤 + 补充 projectName |
| | | List<TTrainLibraryVO> filteredList = new ArrayList<>(); |
| | | for (TTrainLibraryVO vo : allList) { |
| | | if (StringUtils.isNotEmpty(vo.getProjectId())) { |
| | | TProjectTeam byId = projectTeamService.getById(vo.getProjectId()); |
| | | // 未封存的数据:roleType=2 或 status=1 |
| | | if (byId != null && ("2".equals(roleType) || byId.getStatus() == 1)) { |
| | | vo.setProjectName(byId.getTeamName()); |
| | | filteredList.add(vo); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 3. 手动分页(在内存中截取) |
| | | int total = filteredList.size(); |
| | | int pageNum = query.getPageNum(); |
| | | int pageSize = query.getPageSize(); |
| | | int start = (pageNum - 1) * pageSize; |
| | | int end = Math.min(start + pageSize, total); |
| | | |
| | | // 处理边界情况 |
| | | List<TTrainLibraryVO> pageList = new ArrayList<>(); |
| | | if (start < total) { |
| | | pageList = filteredList.subList(start, end); |
| | | } |
| | | |
| | | // 4. 构建 PageInfo 返回 |
| | | PageInfo<TTrainLibraryVO> pageInfo = new PageInfo<>(); |
| | | pageInfo.setRecords(pageList); |
| | | pageInfo.setTotal(total); |
| | | pageInfo.setPages((int) Math.ceil((double) total / pageSize)); |
| | | pageInfo.setHasNextPage(pageNum < (int) Math.ceil((double) total / pageSize)); |
| | | |
| | | return pageInfo; |
| | | } |
| | | |