Commit 1f3f3d789b751a3f585b61f2bd9ed7299c5e2134
1 parent
c019136f
✨ MALL:营销文章增加 title 查询,简易解决常见问题、用户协议的编辑
Showing
5 changed files
with
46 additions
and
30 deletions
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; | @@ -2,9 +2,11 @@ package cn.iocoder.yudao.module.promotion.controller.app.article; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 5 | import cn.iocoder.yudao.module.promotion.controller.app.article.vo.article.AppArticlePageReqVO; | 6 | import cn.iocoder.yudao.module.promotion.controller.app.article.vo.article.AppArticlePageReqVO; |
| 6 | import cn.iocoder.yudao.module.promotion.controller.app.article.vo.article.AppArticleRespVO; | 7 | import cn.iocoder.yudao.module.promotion.controller.app.article.vo.article.AppArticleRespVO; |
| 7 | import cn.iocoder.yudao.module.promotion.convert.article.ArticleConvert; | 8 | import cn.iocoder.yudao.module.promotion.convert.article.ArticleConvert; |
| 9 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO; | ||
| 8 | import cn.iocoder.yudao.module.promotion.service.article.ArticleService; | 10 | import cn.iocoder.yudao.module.promotion.service.article.ArticleService; |
| 9 | import io.swagger.v3.oas.annotations.Operation; | 11 | import io.swagger.v3.oas.annotations.Operation; |
| 10 | import io.swagger.v3.oas.annotations.Parameter; | 12 | import io.swagger.v3.oas.annotations.Parameter; |
| @@ -51,9 +53,15 @@ public class AppArticleController { | @@ -51,9 +53,15 @@ public class AppArticleController { | ||
| 51 | 53 | ||
| 52 | @RequestMapping("/get") | 54 | @RequestMapping("/get") |
| 53 | @Operation(summary = "获得文章详情") | 55 | @Operation(summary = "获得文章详情") |
| 54 | - @Parameter(name = "id", description = "文章编号", example = "1024") | ||
| 55 | - public CommonResult<AppArticleRespVO> getArticlePage(@RequestParam("id") Long id) { | ||
| 56 | - return success(ArticleConvert.INSTANCE.convert01(articleService.getArticle(id))); | 56 | + @Parameters({ |
| 57 | + @Parameter(name = "id", description = "文章编号", example = "1024"), | ||
| 58 | + @Parameter(name = "title", description = "文章标题", example = "1024"), | ||
| 59 | + }) | ||
| 60 | + public CommonResult<AppArticleRespVO> getArticle(@RequestParam(value = "id", required = false) Long id, | ||
| 61 | + @RequestParam(value = "title", required = false) String title) { | ||
| 62 | + ArticleDO article = id != null ? articleService.getArticle(id) | ||
| 63 | + : articleService.getLastArticleByTitle(title); | ||
| 64 | + return success(BeanUtils.toBean(article, AppArticleRespVO.class)); | ||
| 57 | } | 65 | } |
| 58 | 66 | ||
| 59 | @PutMapping("/add-browse-count") | 67 | @PutMapping("/add-browse-count") |
| @@ -64,4 +72,4 @@ public class AppArticleController { | @@ -64,4 +72,4 @@ public class AppArticleController { | ||
| 64 | return success(true); | 72 | return success(true); |
| 65 | } | 73 | } |
| 66 | 74 | ||
| 67 | -} | 75 | -} |
| 76 | +} | ||
| 68 | \ No newline at end of file | 77 | \ No newline at end of file |
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 { | @@ -28,7 +28,7 @@ public class AppArticleRespVO { | ||
| 28 | private String introduction; | 28 | private String introduction; |
| 29 | 29 | ||
| 30 | @Schema(description = "文章内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是详细") | 30 | @Schema(description = "文章内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是详细") |
| 31 | - private String description; | 31 | + private String content; |
| 32 | 32 | ||
| 33 | @Schema(description = "发布时间", requiredMode = Schema.RequiredMode.REQUIRED) | 33 | @Schema(description = "发布时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 34 | private LocalDateTime createTime; | 34 | private LocalDateTime createTime; |
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<ArticleDO> { | @@ -38,6 +38,10 @@ public interface ArticleMapper extends BaseMapperX<ArticleDO> { | ||
| 38 | .eqIfPresent(ArticleDO::getRecommendBanner, recommendBanner)); | 38 | .eqIfPresent(ArticleDO::getRecommendBanner, recommendBanner)); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | + default List<ArticleDO> selectListByTitle(String title) { | ||
| 42 | + return selectList(ArticleDO::getTitle, title); | ||
| 43 | + } | ||
| 44 | + | ||
| 41 | default PageResult<ArticleDO> selectPage(AppArticlePageReqVO pageReqVO) { | 45 | default PageResult<ArticleDO> selectPage(AppArticlePageReqVO pageReqVO) { |
| 42 | return selectPage(pageReqVO, new LambdaQueryWrapperX<ArticleDO>() | 46 | return selectPage(pageReqVO, new LambdaQueryWrapperX<ArticleDO>() |
| 43 | .eqIfPresent(ArticleDO::getCategoryId, pageReqVO.getCategoryId())); | 47 | .eqIfPresent(ArticleDO::getCategoryId, pageReqVO.getCategoryId())); |
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; | @@ -11,14 +11,14 @@ import jakarta.validation.Valid; | ||
| 11 | import java.util.List; | 11 | import java.util.List; |
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| 14 | - * 文章详情 Service 接口 | 14 | + * 文章 Service 接口 |
| 15 | * | 15 | * |
| 16 | * @author HUIHUI | 16 | * @author HUIHUI |
| 17 | */ | 17 | */ |
| 18 | public interface ArticleService { | 18 | public interface ArticleService { |
| 19 | 19 | ||
| 20 | /** | 20 | /** |
| 21 | - * 创建文章详情 | 21 | + * 创建文章 |
| 22 | * | 22 | * |
| 23 | * @param createReqVO 创建信息 | 23 | * @param createReqVO 创建信息 |
| 24 | * @return 编号 | 24 | * @return 编号 |
| @@ -26,61 +26,63 @@ public interface ArticleService { | @@ -26,61 +26,63 @@ public interface ArticleService { | ||
| 26 | Long createArticle(@Valid ArticleCreateReqVO createReqVO); | 26 | Long createArticle(@Valid ArticleCreateReqVO createReqVO); |
| 27 | 27 | ||
| 28 | /** | 28 | /** |
| 29 | - * 更新文章详情 | 29 | + * 更新文章 |
| 30 | * | 30 | * |
| 31 | * @param updateReqVO 更新信息 | 31 | * @param updateReqVO 更新信息 |
| 32 | */ | 32 | */ |
| 33 | void updateArticle(@Valid ArticleUpdateReqVO updateReqVO); | 33 | void updateArticle(@Valid ArticleUpdateReqVO updateReqVO); |
| 34 | 34 | ||
| 35 | /** | 35 | /** |
| 36 | - * 删除文章详情 | 36 | + * 删除文章 |
| 37 | * | 37 | * |
| 38 | * @param id 编号 | 38 | * @param id 编号 |
| 39 | */ | 39 | */ |
| 40 | void deleteArticle(Long id); | 40 | void deleteArticle(Long id); |
| 41 | 41 | ||
| 42 | /** | 42 | /** |
| 43 | - * 获得文章详情 | 43 | + * 获得文章 |
| 44 | * | 44 | * |
| 45 | * @param id 编号 | 45 | * @param id 编号 |
| 46 | - * @return 文章详情 | 46 | + * @return 文章 |
| 47 | */ | 47 | */ |
| 48 | ArticleDO getArticle(Long id); | 48 | ArticleDO getArticle(Long id); |
| 49 | 49 | ||
| 50 | /** | 50 | /** |
| 51 | - * 获得文章详情分页 | 51 | + * 基于标题,获得文章 |
| 52 | + * | ||
| 53 | + * 如果有重名的文章,获取最后发布的 | ||
| 54 | + * | ||
| 55 | + * @param title 标题 | ||
| 56 | + * @return 文章 | ||
| 57 | + */ | ||
| 58 | + ArticleDO getLastArticleByTitle(String title); | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 获得文章分页 | ||
| 52 | * | 62 | * |
| 53 | * @param pageReqVO 分页查询 | 63 | * @param pageReqVO 分页查询 |
| 54 | - * @return 文章详情分页 | 64 | + * @return 文章分页 |
| 55 | */ | 65 | */ |
| 56 | PageResult<ArticleDO> getArticlePage(ArticlePageReqVO pageReqVO); | 66 | PageResult<ArticleDO> getArticlePage(ArticlePageReqVO pageReqVO); |
| 57 | 67 | ||
| 58 | /** | 68 | /** |
| 59 | - * 获得文章详情列表 | 69 | + * 获得文章列表 |
| 60 | * | 70 | * |
| 61 | * @param recommendHot 是否热门 | 71 | * @param recommendHot 是否热门 |
| 62 | * @param recommendBanner 是否轮播图 | 72 | * @param recommendBanner 是否轮播图 |
| 63 | - * @return 文章详情列表 | 73 | + * @return 文章列表 |
| 64 | */ | 74 | */ |
| 65 | List<ArticleDO> getArticleCategoryListByRecommend(Boolean recommendHot, Boolean recommendBanner); | 75 | List<ArticleDO> getArticleCategoryListByRecommend(Boolean recommendHot, Boolean recommendBanner); |
| 66 | 76 | ||
| 67 | /** | 77 | /** |
| 68 | - * 获得文章详情分页 | 78 | + * 获得文章分页 |
| 69 | * | 79 | * |
| 70 | * @param pageReqVO 分页查询 | 80 | * @param pageReqVO 分页查询 |
| 71 | - * @return 文章详情分页 | 81 | + * @return 文章分页 |
| 72 | */ | 82 | */ |
| 73 | PageResult<ArticleDO> getArticlePage(AppArticlePageReqVO pageReqVO); | 83 | PageResult<ArticleDO> getArticlePage(AppArticlePageReqVO pageReqVO); |
| 74 | 84 | ||
| 75 | /** | 85 | /** |
| 76 | - * 获得指定分类的文章列表 | ||
| 77 | - * | ||
| 78 | - * @param categoryId 文章分类编号 | ||
| 79 | - * @return 文章列表 | ||
| 80 | - */ | ||
| 81 | - List<ArticleDO> getArticleByCategoryId(Long categoryId); | ||
| 82 | - | ||
| 83 | - /** | ||
| 84 | * 获得指定分类的文章数量 | 86 | * 获得指定分类的文章数量 |
| 85 | * | 87 | * |
| 86 | * @param categoryId 文章分类编号 | 88 | * @param categoryId 文章分类编号 |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/article/ArticleServiceImpl.java
| 1 | package cn.iocoder.yudao.module.promotion.service.article; | 1 | package cn.iocoder.yudao.module.promotion.service.article; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleCreateReqVO; | 5 | import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleCreateReqVO; |
| 5 | import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticlePageReqVO; | 6 | import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticlePageReqVO; |
| @@ -86,6 +87,12 @@ public class ArticleServiceImpl implements ArticleService { | @@ -86,6 +87,12 @@ public class ArticleServiceImpl implements ArticleService { | ||
| 86 | } | 87 | } |
| 87 | 88 | ||
| 88 | @Override | 89 | @Override |
| 90 | + public ArticleDO getLastArticleByTitle(String title) { | ||
| 91 | + List<ArticleDO> articles = articleMapper.selectListByTitle(title); | ||
| 92 | + return CollUtil.getLast(articles); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + @Override | ||
| 89 | public PageResult<ArticleDO> getArticlePage(ArticlePageReqVO pageReqVO) { | 96 | public PageResult<ArticleDO> getArticlePage(ArticlePageReqVO pageReqVO) { |
| 90 | return articleMapper.selectPage(pageReqVO); | 97 | return articleMapper.selectPage(pageReqVO); |
| 91 | } | 98 | } |
| @@ -101,11 +108,6 @@ public class ArticleServiceImpl implements ArticleService { | @@ -101,11 +108,6 @@ public class ArticleServiceImpl implements ArticleService { | ||
| 101 | } | 108 | } |
| 102 | 109 | ||
| 103 | @Override | 110 | @Override |
| 104 | - public List<ArticleDO> getArticleByCategoryId(Long categoryId) { | ||
| 105 | - return articleMapper.selectList(ArticleDO::getCategoryId, categoryId); | ||
| 106 | - } | ||
| 107 | - | ||
| 108 | - @Override | ||
| 109 | public Long getArticleCountByCategoryId(Long categoryId) { | 111 | public Long getArticleCountByCategoryId(Long categoryId) { |
| 110 | return articleMapper.selectCount(ArticleDO::getCategoryId, categoryId); | 112 | return articleMapper.selectCount(ArticleDO::getCategoryId, categoryId); |
| 111 | } | 113 | } |