From 1f3f3d789b751a3f585b61f2bd9ed7299c5e2134 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 27 Dec 2023 22:07:54 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20MALL=EF=BC=9A=E8=90=A5=E9=94=80?= =?UTF-8?q?=E6=96=87=E7=AB=A0=E5=A2=9E=E5=8A=A0=20title=20=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=EF=BC=8C=E7=AE=80=E6=98=93=E8=A7=A3=E5=86=B3=E5=B8=B8?= =?UTF-8?q?=E8=A7=81=E9=97=AE=E9=A2=98=E3=80=81=E7=94=A8=E6=88=B7=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE=E7=9A=84=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/article/AppArticleController.java | 16 +++++-- .../article/vo/article/AppArticleRespVO.java | 2 +- .../dal/mysql/article/ArticleMapper.java | 4 ++ .../service/article/ArticleService.java | 42 ++++++++++--------- .../service/article/ArticleServiceImpl.java | 12 +++--- 5 files changed, 46 insertions(+), 30 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/article/AppArticleController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/article/AppArticleController.java index ee3a13357..bf33a2be2 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/article/AppArticleController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/article/AppArticleController.java @@ -2,9 +2,11 @@ package cn.iocoder.yudao.module.promotion.controller.app.article; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.promotion.controller.app.article.vo.article.AppArticlePageReqVO; import cn.iocoder.yudao.module.promotion.controller.app.article.vo.article.AppArticleRespVO; import cn.iocoder.yudao.module.promotion.convert.article.ArticleConvert; +import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO; import cn.iocoder.yudao.module.promotion.service.article.ArticleService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -51,9 +53,15 @@ public class AppArticleController { @RequestMapping("/get") @Operation(summary = "获得文章详情") - @Parameter(name = "id", description = "文章编号", example = "1024") - public CommonResult getArticlePage(@RequestParam("id") Long id) { - return success(ArticleConvert.INSTANCE.convert01(articleService.getArticle(id))); + @Parameters({ + @Parameter(name = "id", description = "文章编号", example = "1024"), + @Parameter(name = "title", description = "文章标题", example = "1024"), + }) + public CommonResult getArticle(@RequestParam(value = "id", required = false) Long id, + @RequestParam(value = "title", required = false) String title) { + ArticleDO article = id != null ? articleService.getArticle(id) + : articleService.getLastArticleByTitle(title); + return success(BeanUtils.toBean(article, AppArticleRespVO.class)); } @PutMapping("/add-browse-count") @@ -64,4 +72,4 @@ public class AppArticleController { return success(true); } -} +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/article/vo/article/AppArticleRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/article/vo/article/AppArticleRespVO.java index 8f74776c4..2c77fdc34 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/article/vo/article/AppArticleRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/article/vo/article/AppArticleRespVO.java @@ -28,7 +28,7 @@ public class AppArticleRespVO { private String introduction; @Schema(description = "文章内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是详细") - private String description; + private String content; @Schema(description = "发布时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/article/ArticleMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/article/ArticleMapper.java index 6f05b9a9b..4ee82471e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/article/ArticleMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/article/ArticleMapper.java @@ -38,6 +38,10 @@ public interface ArticleMapper extends BaseMapperX { .eqIfPresent(ArticleDO::getRecommendBanner, recommendBanner)); } + default List selectListByTitle(String title) { + return selectList(ArticleDO::getTitle, title); + } + default PageResult selectPage(AppArticlePageReqVO pageReqVO) { return selectPage(pageReqVO, new LambdaQueryWrapperX() .eqIfPresent(ArticleDO::getCategoryId, pageReqVO.getCategoryId())); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/article/ArticleService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/article/ArticleService.java index 7af9153f4..79b09c353 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/article/ArticleService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/article/ArticleService.java @@ -11,14 +11,14 @@ import jakarta.validation.Valid; import java.util.List; /** - * 文章详情 Service 接口 + * 文章 Service 接口 * * @author HUIHUI */ public interface ArticleService { /** - * 创建文章详情 + * 创建文章 * * @param createReqVO 创建信息 * @return 编号 @@ -26,60 +26,62 @@ public interface ArticleService { Long createArticle(@Valid ArticleCreateReqVO createReqVO); /** - * 更新文章详情 + * 更新文章 * * @param updateReqVO 更新信息 */ void updateArticle(@Valid ArticleUpdateReqVO updateReqVO); /** - * 删除文章详情 + * 删除文章 * * @param id 编号 */ void deleteArticle(Long id); /** - * 获得文章详情 + * 获得文章 * * @param id 编号 - * @return 文章详情 + * @return 文章 */ ArticleDO getArticle(Long id); /** - * 获得文章详情分页 + * 基于标题,获得文章 + * + * 如果有重名的文章,获取最后发布的 + * + * @param title 标题 + * @return 文章 + */ + ArticleDO getLastArticleByTitle(String title); + + /** + * 获得文章分页 * * @param pageReqVO 分页查询 - * @return 文章详情分页 + * @return 文章分页 */ PageResult getArticlePage(ArticlePageReqVO pageReqVO); /** - * 获得文章详情列表 + * 获得文章列表 * * @param recommendHot 是否热门 * @param recommendBanner 是否轮播图 - * @return 文章详情列表 + * @return 文章列表 */ List getArticleCategoryListByRecommend(Boolean recommendHot, Boolean recommendBanner); /** - * 获得文章详情分页 + * 获得文章分页 * * @param pageReqVO 分页查询 - * @return 文章详情分页 + * @return 文章分页 */ PageResult getArticlePage(AppArticlePageReqVO pageReqVO); - /** - * 获得指定分类的文章列表 - * - * @param categoryId 文章分类编号 - * @return 文章列表 - */ - List getArticleByCategoryId(Long categoryId); - /** * 获得指定分类的文章数量 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/article/ArticleServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/article/ArticleServiceImpl.java index 76e05f906..3c3dc8ccb 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/article/ArticleServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/article/ArticleServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.service.article; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticlePageReqVO; @@ -85,6 +86,12 @@ public class ArticleServiceImpl implements ArticleService { return articleMapper.selectById(id); } + @Override + public ArticleDO getLastArticleByTitle(String title) { + List articles = articleMapper.selectListByTitle(title); + return CollUtil.getLast(articles); + } + @Override public PageResult getArticlePage(ArticlePageReqVO pageReqVO) { return articleMapper.selectPage(pageReqVO); @@ -100,11 +107,6 @@ public class ArticleServiceImpl implements ArticleService { return articleMapper.selectPage(pageReqVO); } - @Override - public List getArticleByCategoryId(Long categoryId) { - return articleMapper.selectList(ArticleDO::getCategoryId, categoryId); - } - @Override public Long getArticleCountByCategoryId(Long categoryId) { return articleMapper.selectCount(ArticleDO::getCategoryId, categoryId);