From 1e152bbcfb357073d8bcf0b51fe701e3fb81540d Mon Sep 17 00:00:00 2001
From: inleft <inleft@qq.com>
Date: Mon, 22 Aug 2022 23:22:00 +0800
Subject: [PATCH] 修正邮箱拉取条数 添加日志上下篇

---
 snowy-main/src/main/java/vip/xiaonuo/modular/blogarticle/service/impl/BlogArticleServiceImpl.java |   72 +++++++++++++++++-------------------
 1 files changed, 34 insertions(+), 38 deletions(-)

diff --git a/snowy-main/src/main/java/vip/xiaonuo/modular/blogarticle/service/impl/BlogArticleServiceImpl.java b/snowy-main/src/main/java/vip/xiaonuo/modular/blogarticle/service/impl/BlogArticleServiceImpl.java
index b1a14aa..4f0786a 100644
--- a/snowy-main/src/main/java/vip/xiaonuo/modular/blogarticle/service/impl/BlogArticleServiceImpl.java
+++ b/snowy-main/src/main/java/vip/xiaonuo/modular/blogarticle/service/impl/BlogArticleServiceImpl.java
@@ -28,6 +28,7 @@
 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;
@@ -51,6 +52,7 @@
 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;
@@ -185,59 +187,53 @@
     @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);
     }

--
Gitblit v1.9.1