| | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.PageUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | import vip.xiaonuo.modular.blogarticle.service.BlogArticleService; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.Future; |
| | |
| | | @Async |
| | | @Override |
| | | public Future<List<BlogArticleVo>> getAdjoiningRecord(BlogArticleQueryDto queryDto) { |
| | | int pageNum = 1; |
| | | Page<BlogArticle> queryPage = new Page<>(pageNum, 10); |
| | | int pageNo = 0; |
| | | int pageSize = 100; |
| | | Map<String, Object> param = new HashMap<>(16); |
| | | param.put("pageNo", PageUtil.getStart(pageNo, pageSize)); |
| | | param.put("pageSize", pageSize); |
| | | param.put("typeId", queryDto.getTypeId()); |
| | | param.put("fileType", queryDto.getFileType()); |
| | | |
| | | LambdaQueryWrapper<BlogArticle> queryWrapper = new LambdaQueryWrapper(); |
| | | List<BlogArticleVo> result = new ArrayList(2) {{ |
| | | add(null); |
| | | add(null); |
| | | }}; |
| | | |
| | | queryWrapper.eq(BlogArticle::getIsEnable, MyConstant.Yes) |
| | | .eq(BlogArticle::getEditorStatus, MyConstant.EditorStatus.status_1) |
| | | .le(BlogArticle::getPublishDate, DateUtil.date()) |
| | | .eq(queryDto.getTypeId() != null, BlogArticle::getArticleTypeId, queryDto.getTypeId()) |
| | | .eq(queryDto.getFileType() != null, BlogArticle::getArticleFileType, queryDto.getFileType()) |
| | | .notIn(queryDto.getFileType() == null && queryDto.getTypeId() == null, BlogArticle::getArticleFileType, new Integer[]{3, 4}) |
| | | .orderByDesc(BlogArticle::getIsTop) |
| | | .orderByAsc(BlogArticle::getTopValue) |
| | | .orderByAsc(queryDto.getTypeId() != null, BlogArticle::getPublishDate) |
| | | .orderByAsc(queryDto.getTypeId() == null, BlogArticle::getUpdateDate) |
| | | .select(BlogArticle::getId); |
| | | |
| | | Long[] recordId = new Long[]{null, null}; |
| | | List<BlogArticle> tempRecordList; |
| | | List<BlogArticleVo> tempRecordList; |
| | | while (true) { |
| | | tempRecordList = this.page(queryPage, queryWrapper).getRecords(); |
| | | tempRecordList = this.baseMapper.getAdjoiningRecord(param); |
| | | if (CollUtil.isEmpty(tempRecordList)) { |
| | | break; |
| | | } |
| | | |
| | | for (int i = 0; i < tempRecordList.size(); i++) { |
| | | if (queryDto.getId().equals(tempRecordList.get(i))) { |
| | | if (queryDto.getId().equals(tempRecordList.get(i).getId())) { |
| | | //防止边界 |
| | | recordId[0] = i - 1 >= 0 ? tempRecordList.get(i - 1).getId() : recordId[0]; |
| | | recordId[1] = i + 1 < tempRecordList.size() ? tempRecordList.get(i + 1).getId() : recordId[1]; |
| | | if (i - 1 >= 0) { |
| | | result.set(0, tempRecordList.get(i - 1)); |
| | | } |
| | | if (i + 1 < tempRecordList.size()) { |
| | | result.set(1, tempRecordList.get(i + 1)); |
| | | } else { |
| | | //记录恰好在队尾 |
| | | param.put("pageNo", PageUtil.getStart(++pageNo, pageSize)); |
| | | tempRecordList = this.baseMapper.getAdjoiningRecord(param); |
| | | if (CollUtil.isNotEmpty(tempRecordList)) { |
| | | result.set(1, tempRecordList.get(0)); |
| | | } |
| | | } |
| | | return new AsyncResult<>(result); |
| | | } |
| | | |
| | | //记录此页最后一条作为下一页起始记录 |
| | | recordId[0] = tempRecordList.get(i).getId(); |
| | | //记录此页最后一条作为下一页起始记录(记录恰好在队头) |
| | | result.set(0, tempRecordList.get(i)); |
| | | } |
| | | |
| | | queryPage = new Page<>(++pageNum, 10); |
| | | //下一页 |
| | | param.put("pageNo", PageUtil.getStart(++pageNo, pageSize)); |
| | | } |
| | | |
| | | List<BlogArticleVo> result = new ArrayList<>(2); |
| | | for (int i = 0; i < recordId.length; i++) { |
| | | if (recordId[i] != null) { |
| | | result.add(this.lambdaQuery() |
| | | .eq(BlogArticle::getId, recordId[i]) |
| | | .oneOpt().map(e -> { |
| | | BlogArticleVo vo = new BlogArticleVo(); |
| | | BeanUtil.copyProperties(e, vo); |
| | | return vo; |
| | | }).orElse(null)); |
| | | } else { |
| | | result.add(null); |
| | | } |
| | | } |
| | | |
| | | return new AsyncResult<>(result); |
| | | } |
| | | |
| | | @Override |
| | | public List<BlogArticleVo> searchPlatformList(Map<String, Object> param) { |
| | | return this.baseMapper.searchPlatformList(param); |
| | | } |
| | | |
| | | @Override |
| | | public long searchPlatformListCount(Map<String, Object> param) { |
| | | return this.baseMapper.searchPlatformListCount(param); |
| | | } |
| | | } |