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 | 172 +++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 113 insertions(+), 59 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 d55be1c..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,32 +25,43 @@ 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.StrUtil; +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 vip.xiaonuo.core.consts.CommonConstant; -import vip.xiaonuo.core.enums.CommonStatusEnum; +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 org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; + +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.concurrent.Future; /** - * blog文章主体service接口实现类 + * blog文章service接口实现类 * * @author inleft - * @date 2022-01-22 16:53:06 + * @date 2022-02-09 18:20:46 */ @Service public class BlogArticleServiceImpl extends ServiceImpl<BlogArticleMapper, BlogArticle> implements BlogArticleService { @@ -62,79 +73,39 @@ // 根据文章标题 查询 if (ObjectUtil.isNotEmpty(blogArticleParam.getTitle())) { - queryWrapper.lambda().eq(BlogArticle::getTitle, blogArticleParam.getTitle()); + queryWrapper.lambda().like(BlogArticle::getTitle, blogArticleParam.getTitle()); } - // 根据文章文件id 查询 - if (ObjectUtil.isNotEmpty(blogArticleParam.getArticleFileId())) { - queryWrapper.lambda().eq(BlogArticle::getArticleFileId, blogArticleParam.getArticleFileId()); - } - // 根据文件类型 1:markdown 2:html 查询 + // 根据文件类型 查询 if (ObjectUtil.isNotEmpty(blogArticleParam.getArticleFileType())) { queryWrapper.lambda().eq(BlogArticle::getArticleFileType, blogArticleParam.getArticleFileType()); } - // 根据文章分类id 0:没有分类 查询 + // 根据文章分类 查询 if (ObjectUtil.isNotEmpty(blogArticleParam.getArticleTypeId())) { queryWrapper.lambda().eq(BlogArticle::getArticleTypeId, blogArticleParam.getArticleTypeId()); } // 根据文章引言 查询 if (ObjectUtil.isNotEmpty(blogArticleParam.getIntroduce())) { - queryWrapper.lambda().eq(BlogArticle::getIntroduce, blogArticleParam.getIntroduce()); - } - // 根据封面文件地址(id) 查询 - if (ObjectUtil.isNotEmpty(blogArticleParam.getCoverFileId())) { - queryWrapper.lambda().eq(BlogArticle::getCoverFileId, blogArticleParam.getCoverFileId()); - } - // 根据上次编辑时间 查询 - if (ObjectUtil.isNotEmpty(blogArticleParam.getLastEditorDate())) { - queryWrapper.lambda().eq(BlogArticle::getLastEditorDate, blogArticleParam.getLastEditorDate()); + queryWrapper.lambda().like(BlogArticle::getIntroduce, blogArticleParam.getIntroduce()); } // 根据发布时间 查询 if (ObjectUtil.isNotEmpty(blogArticleParam.getPublishDate())) { - queryWrapper.lambda().eq(BlogArticle::getPublishDate, blogArticleParam.getPublishDate()); + queryWrapper.lambda().ge(BlogArticle::getPublishDate, blogArticleParam.getPublishDate()); } - // 根据是否置顶 0:否 1:是 查询 + // 根据是否置顶 查询 if (ObjectUtil.isNotEmpty(blogArticleParam.getIsTop())) { queryWrapper.lambda().eq(BlogArticle::getIsTop, blogArticleParam.getIsTop()); } - // 根据置顶值(越小越靠前) 查询 - if (ObjectUtil.isNotEmpty(blogArticleParam.getTopValue())) { - queryWrapper.lambda().eq(BlogArticle::getTopValue, blogArticleParam.getTopValue()); - } - // 根据公开状态 1:公开 2:私密 3:密码授权 查询 + // 根据公开状态 查询 if (ObjectUtil.isNotEmpty(blogArticleParam.getAuthStatus())) { queryWrapper.lambda().eq(BlogArticle::getAuthStatus, blogArticleParam.getAuthStatus()); } - // 根据授权密码(在密码授权状态时) 查询 - if (ObjectUtil.isNotEmpty(blogArticleParam.getAuthPassword())) { - queryWrapper.lambda().eq(BlogArticle::getAuthPassword, blogArticleParam.getAuthPassword()); - } - // 根据编辑状态 0:草稿 1:发布 查询 + // 根据编辑状态 查询 if (ObjectUtil.isNotEmpty(blogArticleParam.getEditorStatus())) { queryWrapper.lambda().eq(BlogArticle::getEditorStatus, blogArticleParam.getEditorStatus()); } - // 根据归档年份(以初次发布时间为准) 查询 - if (ObjectUtil.isNotEmpty(blogArticleParam.getSeparateYear())) { - queryWrapper.lambda().eq(BlogArticle::getSeparateYear, blogArticleParam.getSeparateYear()); - } - // 根据归档月份 查询 - if (ObjectUtil.isNotEmpty(blogArticleParam.getSeparateMonth())) { - queryWrapper.lambda().eq(BlogArticle::getSeparateMonth, blogArticleParam.getSeparateMonth()); - } - // 根据归档日 查询 - if (ObjectUtil.isNotEmpty(blogArticleParam.getSeparateDay())) { - queryWrapper.lambda().eq(BlogArticle::getSeparateDay, blogArticleParam.getSeparateDay()); - } - // 根据是否启用 0:否 1:是 查询 - if (ObjectUtil.isNotEmpty(blogArticleParam.getIsEnable())) { - queryWrapper.lambda().eq(BlogArticle::getIsEnable, blogArticleParam.getIsEnable()); - } - // 根据更新时间 查询 - if (ObjectUtil.isNotEmpty(blogArticleParam.getUpdateDate())) { - queryWrapper.lambda().eq(BlogArticle::getUpdateDate, blogArticleParam.getUpdateDate()); - } // 根据创建时间 查询 if (ObjectUtil.isNotEmpty(blogArticleParam.getCreateDate())) { - queryWrapper.lambda().eq(BlogArticle::getCreateDate, blogArticleParam.getCreateDate()); + queryWrapper.lambda().ge(BlogArticle::getCreateDate, blogArticleParam.getCreateDate()); } } return new PageResult<>(this.page(PageFactory.defaultPage(), queryWrapper)); @@ -174,10 +145,10 @@ } /** - * 获取blog文章主体 + * 获取blog文章 * * @author inleft - * @date 2022-01-22 16:53:06 + * @date 2022-02-09 18:20:46 */ private BlogArticle queryBlogArticle(BlogArticleParam blogArticleParam) { BlogArticle blogArticle = this.getById(blogArticleParam.getId()); @@ -193,4 +164,87 @@ PoiUtil.exportExcelWithStream("SnowyBlogArticle.xls", BlogArticle.class, list); } + + @Override + public List searchList(Map<String, Object> param) { + return this.baseMapper.searchList(param); + } + + @Override + public long searchListCount(Map<String, Object> param) { + return this.baseMapper.searchListCount(param); + } + + @Override + public List<BlogArchiveDetailVo> searchMonthCount(Integer separateYear) { + 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