From 2ddbd99aa5b2e396f96c6daba60fe1ac2573d9fb Mon Sep 17 00:00:00 2001 From: inleft <inleft@qq.com> Date: Sat, 18 May 2024 11:53:54 +0800 Subject: [PATCH] 新增RSS 订阅链接 --- snowy-main/src/main/java/vip/xiaonuo/modular/blogarticle/service/impl/BlogArticleServiceImpl.java | 80 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 80 insertions(+), 0 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 41b8f64..011859d 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 @@ -25,24 +25,37 @@ package vip.xiaonuo.modular.blogarticle.service.impl; import cn.hutool.core.bean.BeanUtil; +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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.AsyncResult; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import vip.xiaonuo.core.consts.MyConstant; import vip.xiaonuo.core.exception.ServiceException; import vip.xiaonuo.core.factory.PageFactory; import vip.xiaonuo.core.pojo.page.PageResult; import vip.xiaonuo.core.util.PoiUtil; import vip.xiaonuo.modular.blogStatistics.vo.BlogArchiveDetailVo; import vip.xiaonuo.modular.blogarticle.entity.BlogArticle; +import vip.xiaonuo.modular.blogarticle.entity.BlogArticleVo; import vip.xiaonuo.modular.blogarticle.enums.BlogArticleExceptionEnum; import vip.xiaonuo.modular.blogarticle.mapper.BlogArticleMapper; import vip.xiaonuo.modular.blogarticle.param.BlogArticleParam; +import vip.xiaonuo.modular.blogarticle.param.BlogArticleQueryDto; 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; /** * blog文章service接口实现类 @@ -167,4 +180,71 @@ return this.baseMapper.searchMonthCount(separateYear); } + + /** + * 异步获取上下相邻日志id + */ + @Async + @Override + public Future<List<BlogArticleVo>> getAdjoiningRecord(BlogArticleQueryDto queryDto) { + 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()); + + List<BlogArticleVo> result = new ArrayList(2) {{ + add(null); + add(null); + }}; + + List<BlogArticleVo> tempRecordList; + while (true) { + 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).getId())) { + //防止边界 + 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); + } + + //记录此页最后一条作为下一页起始记录(记录恰好在队头) + result.set(0, tempRecordList.get(i)); + } + + //下一页 + param.put("pageNo", PageUtil.getStart(++pageNo, pageSize)); + } + + + 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); + } } -- Gitblit v1.9.1