Commit 55eed1377af431143be12dd0de0bc7a1577cde78
1 parent
a47ab328
营销活动: 新增文章管理
Showing
21 changed files
with
971 additions
and
11 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/ProductSpuController.java
| ... | ... | @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.product.controller.admin.spu.vo.*; |
| 8 | 8 | import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; |
| 9 | 9 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| 10 | 10 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| 11 | +import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; | |
| 11 | 12 | import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; |
| 12 | 13 | import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; |
| 13 | 14 | import io.swagger.v3.oas.annotations.Operation; |
| ... | ... | @@ -22,6 +23,7 @@ import javax.servlet.http.HttpServletResponse; |
| 22 | 23 | import javax.validation.Valid; |
| 23 | 24 | import java.io.IOException; |
| 24 | 25 | import java.util.Collection; |
| 26 | +import java.util.Comparator; | |
| 25 | 27 | import java.util.List; |
| 26 | 28 | import java.util.Map; |
| 27 | 29 | |
| ... | ... | @@ -88,11 +90,13 @@ public class ProductSpuController { |
| 88 | 90 | return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespVO(spu, skus)); |
| 89 | 91 | } |
| 90 | 92 | |
| 91 | - @GetMapping("/get-simple-list") | |
| 93 | + @GetMapping("/list-all-simple") | |
| 92 | 94 | @Operation(summary = "获得商品 SPU 精简列表") |
| 93 | 95 | @PreAuthorize("@ss.hasPermission('product:spu:query')") |
| 94 | 96 | public CommonResult<List<ProductSpuSimpleRespVO>> getSpuSimpleList() { |
| 95 | - List<ProductSpuDO> list = productSpuService.getSpuList(); | |
| 97 | + List<ProductSpuDO> list = productSpuService.getSpuListByStatus(ProductSpuStatusEnum.ENABLE.getStatus()); | |
| 98 | + // 降序排序后,返回给前端 | |
| 99 | + list.sort(Comparator.comparing(ProductSpuDO::getSort).reversed()); | |
| 96 | 100 | return success(ProductSpuConvert.INSTANCE.convertList02(list)); |
| 97 | 101 | } |
| 98 | 102 | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java
| ... | ... | @@ -68,11 +68,12 @@ public interface ProductSpuService { |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | - * 获得所有商品 SPU 列表 | |
| 71 | + * 获得指定状态的商品 SPU 列表 | |
| 72 | 72 | * |
| 73 | + * @param status 状态 | |
| 73 | 74 | * @return 商品 SPU 列表 |
| 74 | 75 | */ |
| 75 | - List<ProductSpuDO> getSpuList(); | |
| 76 | + List<ProductSpuDO> getSpuListByStatus(Integer status); | |
| 76 | 77 | |
| 77 | 78 | /** |
| 78 | 79 | * 获得所有商品 SPU 列表 |
| ... | ... | @@ -146,4 +147,5 @@ public interface ProductSpuService { |
| 146 | 147 | * @return 商品 SPU 列表 |
| 147 | 148 | */ |
| 148 | 149 | List<ProductSpuDO> validateSpuList(Collection<Long> ids); |
| 150 | + | |
| 149 | 151 | } | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java
| ... | ... | @@ -196,8 +196,8 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | @Override |
| 199 | - public List<ProductSpuDO> getSpuList() { | |
| 200 | - return productSpuMapper.selectList(); | |
| 199 | + public List<ProductSpuDO> getSpuListByStatus(Integer status) { | |
| 200 | + return productSpuMapper.selectList(ProductSpuDO::getStatus, status); | |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | @Override | ... | ... |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java
| ... | ... | @@ -113,4 +113,7 @@ public interface ErrorCodeConstants { |
| 113 | 113 | // ========== 文章分类 1-013-015-000 ========== |
| 114 | 114 | ErrorCode ARTICLE_CATEGORY_NOT_EXISTS = new ErrorCode(1_013_015_000, "分类不存在"); |
| 115 | 115 | |
| 116 | + // ========== 文章管理 1-013-016-000 ========== | |
| 117 | + ErrorCode ARTICLE_NOT_EXISTS = new ErrorCode(1_013_016_000, "文章管理不存在"); | |
| 118 | + | |
| 116 | 119 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/article/ArticleController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.article; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 6 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 7 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.*; | |
| 8 | +import cn.iocoder.yudao.module.promotion.convert.article.ArticleConvert; | |
| 9 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO; | |
| 10 | +import cn.iocoder.yudao.module.promotion.service.article.ArticleService; | |
| 11 | +import io.swagger.v3.oas.annotations.Operation; | |
| 12 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 13 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 14 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 15 | +import org.springframework.validation.annotation.Validated; | |
| 16 | +import org.springframework.web.bind.annotation.*; | |
| 17 | + | |
| 18 | +import javax.annotation.Resource; | |
| 19 | +import javax.servlet.http.HttpServletResponse; | |
| 20 | +import javax.validation.Valid; | |
| 21 | +import java.io.IOException; | |
| 22 | +import java.util.Collection; | |
| 23 | +import java.util.List; | |
| 24 | + | |
| 25 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 26 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | |
| 27 | + | |
| 28 | +@Tag(name = "管理后台 - 文章管理") | |
| 29 | +@RestController | |
| 30 | +@RequestMapping("/promotion/article") | |
| 31 | +@Validated | |
| 32 | +public class ArticleController { | |
| 33 | + | |
| 34 | + @Resource | |
| 35 | + private ArticleService articleService; | |
| 36 | + | |
| 37 | + @PostMapping("/create") | |
| 38 | + @Operation(summary = "创建文章管理") | |
| 39 | + @PreAuthorize("@ss.hasPermission('promotion:article:create')") | |
| 40 | + public CommonResult<Long> createArticle(@Valid @RequestBody ArticleCreateReqVO createReqVO) { | |
| 41 | + return success(articleService.createArticle(createReqVO)); | |
| 42 | + } | |
| 43 | + | |
| 44 | + @PutMapping("/update") | |
| 45 | + @Operation(summary = "更新文章管理") | |
| 46 | + @PreAuthorize("@ss.hasPermission('promotion:article:update')") | |
| 47 | + public CommonResult<Boolean> updateArticle(@Valid @RequestBody ArticleUpdateReqVO updateReqVO) { | |
| 48 | + articleService.updateArticle(updateReqVO); | |
| 49 | + return success(true); | |
| 50 | + } | |
| 51 | + | |
| 52 | + @DeleteMapping("/delete") | |
| 53 | + @Operation(summary = "删除文章管理") | |
| 54 | + @Parameter(name = "id", description = "编号", required = true) | |
| 55 | + @PreAuthorize("@ss.hasPermission('promotion:article:delete')") | |
| 56 | + public CommonResult<Boolean> deleteArticle(@RequestParam("id") Long id) { | |
| 57 | + articleService.deleteArticle(id); | |
| 58 | + return success(true); | |
| 59 | + } | |
| 60 | + | |
| 61 | + @GetMapping("/get") | |
| 62 | + @Operation(summary = "获得文章管理") | |
| 63 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 64 | + @PreAuthorize("@ss.hasPermission('promotion:article:query')") | |
| 65 | + public CommonResult<ArticleRespVO> getArticle(@RequestParam("id") Long id) { | |
| 66 | + ArticleDO article = articleService.getArticle(id); | |
| 67 | + return success(ArticleConvert.INSTANCE.convert(article)); | |
| 68 | + } | |
| 69 | + | |
| 70 | + @GetMapping("/list") | |
| 71 | + @Operation(summary = "获得文章管理列表") | |
| 72 | + @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048") | |
| 73 | + @PreAuthorize("@ss.hasPermission('promotion:article:query')") | |
| 74 | + public CommonResult<List<ArticleRespVO>> getArticleList(@RequestParam("ids") Collection<Long> ids) { | |
| 75 | + List<ArticleDO> list = articleService.getArticleList(ids); | |
| 76 | + return success(ArticleConvert.INSTANCE.convertList(list)); | |
| 77 | + } | |
| 78 | + | |
| 79 | + @GetMapping("/page") | |
| 80 | + @Operation(summary = "获得文章管理分页") | |
| 81 | + @PreAuthorize("@ss.hasPermission('promotion:article:query')") | |
| 82 | + public CommonResult<PageResult<ArticleRespVO>> getArticlePage(@Valid ArticlePageReqVO pageVO) { | |
| 83 | + PageResult<ArticleDO> pageResult = articleService.getArticlePage(pageVO); | |
| 84 | + return success(ArticleConvert.INSTANCE.convertPage(pageResult)); | |
| 85 | + } | |
| 86 | + | |
| 87 | + @GetMapping("/export-excel") | |
| 88 | + @Operation(summary = "导出文章管理 Excel") | |
| 89 | + @PreAuthorize("@ss.hasPermission('promotion:article:export')") | |
| 90 | + @OperateLog(type = EXPORT) | |
| 91 | + public void exportArticleExcel(@Valid ArticleExportReqVO exportReqVO, | |
| 92 | + HttpServletResponse response) throws IOException { | |
| 93 | + List<ArticleDO> list = articleService.getArticleList(exportReqVO); | |
| 94 | + // 导出 Excel | |
| 95 | + List<ArticleExcelVO> datas = ArticleConvert.INSTANCE.convertList02(list); | |
| 96 | + ExcelUtils.write(response, "文章管理.xls", "数据", ArticleExcelVO.class, datas); | |
| 97 | + } | |
| 98 | + | |
| 99 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/article/vo/ArticleBaseVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.article.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +import javax.validation.constraints.NotNull; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * 文章管理 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 10 | + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | |
| 11 | + */ | |
| 12 | +@Data | |
| 13 | +public class ArticleBaseVO { | |
| 14 | + | |
| 15 | + @Schema(description = "文章分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15458") | |
| 16 | + @NotNull(message = "文章分类编号不能为空") | |
| 17 | + private Long categoryId; | |
| 18 | + | |
| 19 | + @Schema(description = "关联商品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22378") | |
| 20 | + @NotNull(message = "关联商品不能为空") | |
| 21 | + private Long spuId; | |
| 22 | + | |
| 23 | + @Schema(description = "文章标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "这是一个标题") | |
| 24 | + @NotNull(message = "文章标题不能为空") | |
| 25 | + private String title; | |
| 26 | + | |
| 27 | + @Schema(description = "文章作者", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") | |
| 28 | + private String author; | |
| 29 | + | |
| 30 | + @Schema(description = "文章封面图片地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn") | |
| 31 | + @NotNull(message = "文章封面图片地址不能为空") | |
| 32 | + private String picUrl; | |
| 33 | + | |
| 34 | + @Schema(description = "文章简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "这是一个简介") | |
| 35 | + private String introduction; | |
| 36 | + | |
| 37 | + @Schema(description = "浏览次数", requiredMode = Schema.RequiredMode.REQUIRED, example = "111") | |
| 38 | + private String browseCount; | |
| 39 | + | |
| 40 | + @Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 41 | + @NotNull(message = "排序不能为空") | |
| 42 | + private Integer sort; | |
| 43 | + | |
| 44 | + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | |
| 45 | + @NotNull(message = "状态不能为空") | |
| 46 | + private Integer status; | |
| 47 | + | |
| 48 | + @Schema(description = "是否热门(小程序)", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 49 | + @NotNull(message = "是否热门(小程序)不能为空") | |
| 50 | + private Boolean recommendHot; | |
| 51 | + | |
| 52 | + @Schema(description = "是否轮播图(小程序)", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 53 | + @NotNull(message = "是否轮播图(小程序)不能为空") | |
| 54 | + private Boolean recommendBanner; | |
| 55 | + | |
| 56 | + @Schema(description = "文章内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "这是文章内容") | |
| 57 | + @NotNull(message = "文章内容不能为空") | |
| 58 | + private String content; | |
| 59 | + | |
| 60 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/article/vo/ArticleCreateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.article.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | +import lombok.EqualsAndHashCode; | |
| 6 | +import lombok.ToString; | |
| 7 | + | |
| 8 | +@Schema(description = "管理后台 - 文章管理创建 Request VO") | |
| 9 | +@Data | |
| 10 | +@EqualsAndHashCode(callSuper = true) | |
| 11 | +@ToString(callSuper = true) | |
| 12 | +public class ArticleCreateReqVO extends ArticleBaseVO { | |
| 13 | + | |
| 14 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/article/vo/ArticleExcelVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.article.vo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | +import cn.iocoder.yudao.module.system.enums.DictTypeConstants; | |
| 6 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 7 | +import lombok.Data; | |
| 8 | + | |
| 9 | +import java.time.LocalDateTime; | |
| 10 | + | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 文章管理 Excel VO | |
| 14 | + * | |
| 15 | + * @author HUIHUI | |
| 16 | + */ | |
| 17 | +@Data | |
| 18 | +public class ArticleExcelVO { | |
| 19 | + | |
| 20 | + @ExcelProperty("文章编号") | |
| 21 | + private Long id; | |
| 22 | + | |
| 23 | + @ExcelProperty("文章分类编号") | |
| 24 | + private Long categoryId; | |
| 25 | + | |
| 26 | + @ExcelProperty("关联商品编号") | |
| 27 | + private Long spuId; | |
| 28 | + | |
| 29 | + @ExcelProperty("文章标题") | |
| 30 | + private String title; | |
| 31 | + | |
| 32 | + @ExcelProperty("文章作者") | |
| 33 | + private String author; | |
| 34 | + | |
| 35 | + @ExcelProperty("文章封面图片地址") | |
| 36 | + private String picUrl; | |
| 37 | + | |
| 38 | + @ExcelProperty("文章简介") | |
| 39 | + private String introduction; | |
| 40 | + | |
| 41 | + @ExcelProperty("浏览次数") | |
| 42 | + private String browseCount; | |
| 43 | + | |
| 44 | + @ExcelProperty("排序") | |
| 45 | + private Integer sort; | |
| 46 | + | |
| 47 | + @ExcelProperty(value = "状态", converter = DictConvert.class) | |
| 48 | + @DictFormat(DictTypeConstants.COMMON_STATUS) | |
| 49 | + private Integer status; | |
| 50 | + | |
| 51 | + @ExcelProperty("是否热门(小程序)") | |
| 52 | + private Boolean recommendHot; | |
| 53 | + | |
| 54 | + @ExcelProperty("是否轮播图(小程序)") | |
| 55 | + private Boolean recommendBanner; | |
| 56 | + | |
| 57 | + @ExcelProperty("文章内容") | |
| 58 | + private String content; | |
| 59 | + | |
| 60 | + @ExcelProperty("创建时间") | |
| 61 | + private LocalDateTime createTime; | |
| 62 | + | |
| 63 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/article/vo/ArticleExportReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.article.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 6 | + | |
| 7 | +import java.time.LocalDateTime; | |
| 8 | + | |
| 9 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 10 | + | |
| 11 | +@Schema(description = "管理后台 - 文章管理 Excel 导出 Request VO,参数和 ArticlePageReqVO 是一致的") | |
| 12 | +@Data | |
| 13 | +public class ArticleExportReqVO { | |
| 14 | + | |
| 15 | + @Schema(description = "文章分类编号", example = "15458") | |
| 16 | + private Long categoryId; | |
| 17 | + | |
| 18 | + @Schema(description = "关联商品编号", example = "22378") | |
| 19 | + private Long spuId; | |
| 20 | + | |
| 21 | + @Schema(description = "文章标题") | |
| 22 | + private String title; | |
| 23 | + | |
| 24 | + @Schema(description = "文章作者") | |
| 25 | + private String author; | |
| 26 | + | |
| 27 | + @Schema(description = "状态", example = "2") | |
| 28 | + private Integer status; | |
| 29 | + | |
| 30 | + @Schema(description = "是否热门(小程序)") | |
| 31 | + private Boolean recommendHot; | |
| 32 | + | |
| 33 | + @Schema(description = "是否轮播图(小程序)") | |
| 34 | + private Boolean recommendBanner; | |
| 35 | + | |
| 36 | + @Schema(description = "创建时间") | |
| 37 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 38 | + private LocalDateTime[] createTime; | |
| 39 | + | |
| 40 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/article/vo/ArticlePageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.article.vo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | + | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 13 | + | |
| 14 | +@Schema(description = "管理后台 - 文章管理分页 Request VO") | |
| 15 | +@Data | |
| 16 | +@EqualsAndHashCode(callSuper = true) | |
| 17 | +@ToString(callSuper = true) | |
| 18 | +public class ArticlePageReqVO extends PageParam { | |
| 19 | + | |
| 20 | + @Schema(description = "文章分类编号", example = "15458") | |
| 21 | + private Long categoryId; | |
| 22 | + | |
| 23 | + @Schema(description = "关联商品编号", example = "22378") | |
| 24 | + private Long spuId; | |
| 25 | + | |
| 26 | + @Schema(description = "文章标题") | |
| 27 | + private String title; | |
| 28 | + | |
| 29 | + @Schema(description = "文章作者") | |
| 30 | + private String author; | |
| 31 | + | |
| 32 | + @Schema(description = "状态", example = "2") | |
| 33 | + private Integer status; | |
| 34 | + | |
| 35 | + @Schema(description = "是否热门(小程序)") | |
| 36 | + private Boolean recommendHot; | |
| 37 | + | |
| 38 | + @Schema(description = "是否轮播图(小程序)") | |
| 39 | + private Boolean recommendBanner; | |
| 40 | + | |
| 41 | + @Schema(description = "创建时间") | |
| 42 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 43 | + private LocalDateTime[] createTime; | |
| 44 | + | |
| 45 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/article/vo/ArticleRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.article.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | +import lombok.EqualsAndHashCode; | |
| 6 | +import lombok.ToString; | |
| 7 | + | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +@Schema(description = "管理后台 - 文章管理 Response VO") | |
| 11 | +@Data | |
| 12 | +@EqualsAndHashCode(callSuper = true) | |
| 13 | +@ToString(callSuper = true) | |
| 14 | +public class ArticleRespVO extends ArticleBaseVO { | |
| 15 | + | |
| 16 | + @Schema(description = "文章编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8606") | |
| 17 | + private Long id; | |
| 18 | + | |
| 19 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 20 | + private LocalDateTime createTime; | |
| 21 | + | |
| 22 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/article/vo/ArticleUpdateReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.article.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | +import lombok.EqualsAndHashCode; | |
| 6 | +import lombok.ToString; | |
| 7 | + | |
| 8 | +import javax.validation.constraints.NotNull; | |
| 9 | + | |
| 10 | +@Schema(description = "管理后台 - 文章管理更新 Request VO") | |
| 11 | +@Data | |
| 12 | +@EqualsAndHashCode(callSuper = true) | |
| 13 | +@ToString(callSuper = true) | |
| 14 | +public class ArticleUpdateReqVO extends ArticleBaseVO { | |
| 15 | + | |
| 16 | + @Schema(description = "文章编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8606") | |
| 17 | + @NotNull(message = "文章编号不能为空") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/article/ArticleConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.convert.article; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleCreateReqVO; | |
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleExcelVO; | |
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleRespVO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleUpdateReqVO; | |
| 8 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO; | |
| 9 | +import org.mapstruct.Mapper; | |
| 10 | +import org.mapstruct.factory.Mappers; | |
| 11 | + | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * 文章管理 Convert | |
| 16 | + * | |
| 17 | + * @author HUIHUI | |
| 18 | + */ | |
| 19 | +@Mapper | |
| 20 | +public interface ArticleConvert { | |
| 21 | + | |
| 22 | + ArticleConvert INSTANCE = Mappers.getMapper(ArticleConvert.class); | |
| 23 | + | |
| 24 | + ArticleDO convert(ArticleCreateReqVO bean); | |
| 25 | + | |
| 26 | + ArticleDO convert(ArticleUpdateReqVO bean); | |
| 27 | + | |
| 28 | + ArticleRespVO convert(ArticleDO bean); | |
| 29 | + | |
| 30 | + List<ArticleRespVO> convertList(List<ArticleDO> list); | |
| 31 | + | |
| 32 | + PageResult<ArticleRespVO> convertPage(PageResult<ArticleDO> page); | |
| 33 | + | |
| 34 | + List<ArticleExcelVO> convertList02(List<ArticleDO> list); | |
| 35 | + | |
| 36 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/article/ArticleDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.dal.dataobject.article; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 5 | +import com.baomidou.mybatisplus.annotation.KeySequence; | |
| 6 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 7 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 8 | +import lombok.*; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 文章管理 DO | |
| 12 | + * | |
| 13 | + * @author HUIHUI | |
| 14 | + */ | |
| 15 | +@TableName("promotion_article") | |
| 16 | +@KeySequence("promotion_article_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class ArticleDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 文章管理编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 分类编号 ArticleCategoryDO#id | |
| 32 | + */ | |
| 33 | + private Long categoryId; | |
| 34 | + /** | |
| 35 | + * 关联商品编号 ProductSpuDO#id | |
| 36 | + */ | |
| 37 | + private Long spuId; | |
| 38 | + /** | |
| 39 | + * 文章标题 | |
| 40 | + */ | |
| 41 | + private String title; | |
| 42 | + /** | |
| 43 | + * 文章作者 | |
| 44 | + */ | |
| 45 | + private String author; | |
| 46 | + /** | |
| 47 | + * 文章封面图片地址 | |
| 48 | + */ | |
| 49 | + private String picUrl; | |
| 50 | + /** | |
| 51 | + * 文章简介 | |
| 52 | + */ | |
| 53 | + private String introduction; | |
| 54 | + /** | |
| 55 | + * 浏览次数 | |
| 56 | + */ | |
| 57 | + private String browseCount; | |
| 58 | + /** | |
| 59 | + * 排序 | |
| 60 | + */ | |
| 61 | + private Integer sort; | |
| 62 | + /** | |
| 63 | + * 状态 | |
| 64 | + * | |
| 65 | + * 枚举 {@link CommonStatusEnum} | |
| 66 | + */ | |
| 67 | + private Integer status; | |
| 68 | + /** | |
| 69 | + * 是否热门(小程序) | |
| 70 | + */ | |
| 71 | + private Boolean recommendHot; | |
| 72 | + /** | |
| 73 | + * 是否轮播图(小程序) | |
| 74 | + */ | |
| 75 | + private Boolean recommendBanner; | |
| 76 | + /** | |
| 77 | + * 文章内容 | |
| 78 | + */ | |
| 79 | + private String content; | |
| 80 | + | |
| 81 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/article/ArticleMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.dal.mysql.article; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleExportReqVO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticlePageReqVO; | |
| 8 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | + | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * 文章管理 Mapper | |
| 15 | + * | |
| 16 | + * @author HUIHUI | |
| 17 | + */ | |
| 18 | +@Mapper | |
| 19 | +public interface ArticleMapper extends BaseMapperX<ArticleDO> { | |
| 20 | + | |
| 21 | + default PageResult<ArticleDO> selectPage(ArticlePageReqVO reqVO) { | |
| 22 | + return selectPage(reqVO, new LambdaQueryWrapperX<ArticleDO>() | |
| 23 | + .eqIfPresent(ArticleDO::getCategoryId, reqVO.getCategoryId()) | |
| 24 | + .eqIfPresent(ArticleDO::getTitle, reqVO.getTitle()) | |
| 25 | + .eqIfPresent(ArticleDO::getAuthor, reqVO.getAuthor()) | |
| 26 | + .eqIfPresent(ArticleDO::getStatus, reqVO.getStatus()) | |
| 27 | + .eqIfPresent(ArticleDO::getSpuId, reqVO.getSpuId()) | |
| 28 | + .eqIfPresent(ArticleDO::getRecommendHot, reqVO.getRecommendHot()) | |
| 29 | + .eqIfPresent(ArticleDO::getRecommendBanner, reqVO.getRecommendBanner()) | |
| 30 | + .betweenIfPresent(ArticleDO::getCreateTime, reqVO.getCreateTime()) | |
| 31 | + .orderByDesc(ArticleDO::getId)); | |
| 32 | + } | |
| 33 | + | |
| 34 | + default List<ArticleDO> selectList(ArticleExportReqVO reqVO) { | |
| 35 | + return selectList(new LambdaQueryWrapperX<ArticleDO>() | |
| 36 | + .eqIfPresent(ArticleDO::getCategoryId, reqVO.getCategoryId()) | |
| 37 | + .eqIfPresent(ArticleDO::getTitle, reqVO.getTitle()) | |
| 38 | + .eqIfPresent(ArticleDO::getAuthor, reqVO.getAuthor()) | |
| 39 | + .eqIfPresent(ArticleDO::getStatus, reqVO.getStatus()) | |
| 40 | + .eqIfPresent(ArticleDO::getSpuId, reqVO.getSpuId()) | |
| 41 | + .eqIfPresent(ArticleDO::getRecommendHot, reqVO.getRecommendHot()) | |
| 42 | + .eqIfPresent(ArticleDO::getRecommendBanner, reqVO.getRecommendBanner()) | |
| 43 | + .betweenIfPresent(ArticleDO::getCreateTime, reqVO.getCreateTime()) | |
| 44 | + .orderByDesc(ArticleDO::getId)); | |
| 45 | + } | |
| 46 | + | |
| 47 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/article/ArticleService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.service.article; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleCreateReqVO; | |
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleExportReqVO; | |
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticlePageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleUpdateReqVO; | |
| 8 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO; | |
| 9 | + | |
| 10 | +import javax.validation.Valid; | |
| 11 | +import java.util.Collection; | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * 文章管理 Service 接口 | |
| 16 | + * | |
| 17 | + * @author HUIHUI | |
| 18 | + */ | |
| 19 | +public interface ArticleService { | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 创建文章管理 | |
| 23 | + * | |
| 24 | + * @param createReqVO 创建信息 | |
| 25 | + * @return 编号 | |
| 26 | + */ | |
| 27 | + Long createArticle(@Valid ArticleCreateReqVO createReqVO); | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * 更新文章管理 | |
| 31 | + * | |
| 32 | + * @param updateReqVO 更新信息 | |
| 33 | + */ | |
| 34 | + void updateArticle(@Valid ArticleUpdateReqVO updateReqVO); | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * 删除文章管理 | |
| 38 | + * | |
| 39 | + * @param id 编号 | |
| 40 | + */ | |
| 41 | + void deleteArticle(Long id); | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * 获得文章管理 | |
| 45 | + * | |
| 46 | + * @param id 编号 | |
| 47 | + * @return 文章管理 | |
| 48 | + */ | |
| 49 | + ArticleDO getArticle(Long id); | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * 获得文章管理列表 | |
| 53 | + * | |
| 54 | + * @param ids 编号 | |
| 55 | + * @return 文章管理列表 | |
| 56 | + */ | |
| 57 | + List<ArticleDO> getArticleList(Collection<Long> ids); | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * 获得文章管理分页 | |
| 61 | + * | |
| 62 | + * @param pageReqVO 分页查询 | |
| 63 | + * @return 文章管理分页 | |
| 64 | + */ | |
| 65 | + PageResult<ArticleDO> getArticlePage(ArticlePageReqVO pageReqVO); | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * 获得文章管理列表, 用于 Excel 导出 | |
| 69 | + * | |
| 70 | + * @param exportReqVO 查询条件 | |
| 71 | + * @return 文章管理列表 | |
| 72 | + */ | |
| 73 | + List<ArticleDO> getArticleList(ArticleExportReqVO exportReqVO); | |
| 74 | + | |
| 75 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/article/ArticleServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.service.article; | |
| 2 | + | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.hutool.core.collection.ListUtil; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleCreateReqVO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleExportReqVO; | |
| 8 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticlePageReqVO; | |
| 9 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleUpdateReqVO; | |
| 10 | +import cn.iocoder.yudao.module.promotion.convert.article.ArticleConvert; | |
| 11 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO; | |
| 12 | +import cn.iocoder.yudao.module.promotion.dal.mysql.article.ArticleMapper; | |
| 13 | +import org.springframework.stereotype.Service; | |
| 14 | +import org.springframework.validation.annotation.Validated; | |
| 15 | + | |
| 16 | +import javax.annotation.Resource; | |
| 17 | +import java.util.Collection; | |
| 18 | +import java.util.List; | |
| 19 | + | |
| 20 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 21 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.ARTICLE_NOT_EXISTS; | |
| 22 | + | |
| 23 | +/** | |
| 24 | + * 文章管理 Service 实现类 | |
| 25 | + * | |
| 26 | + * @author HUIHUI | |
| 27 | + */ | |
| 28 | +@Service | |
| 29 | +@Validated | |
| 30 | +public class ArticleServiceImpl implements ArticleService { | |
| 31 | + | |
| 32 | + @Resource | |
| 33 | + private ArticleMapper articleMapper; | |
| 34 | + | |
| 35 | + @Override | |
| 36 | + public Long createArticle(ArticleCreateReqVO createReqVO) { | |
| 37 | + // 插入 | |
| 38 | + ArticleDO article = ArticleConvert.INSTANCE.convert(createReqVO); | |
| 39 | + articleMapper.insert(article); | |
| 40 | + // 返回 | |
| 41 | + return article.getId(); | |
| 42 | + } | |
| 43 | + | |
| 44 | + @Override | |
| 45 | + public void updateArticle(ArticleUpdateReqVO updateReqVO) { | |
| 46 | + // 校验存在 | |
| 47 | + validateArticleExists(updateReqVO.getId()); | |
| 48 | + // 更新 | |
| 49 | + ArticleDO updateObj = ArticleConvert.INSTANCE.convert(updateReqVO); | |
| 50 | + articleMapper.updateById(updateObj); | |
| 51 | + } | |
| 52 | + | |
| 53 | + @Override | |
| 54 | + public void deleteArticle(Long id) { | |
| 55 | + // 校验存在 | |
| 56 | + validateArticleExists(id); | |
| 57 | + // 删除 | |
| 58 | + articleMapper.deleteById(id); | |
| 59 | + } | |
| 60 | + | |
| 61 | + private void validateArticleExists(Long id) { | |
| 62 | + if (articleMapper.selectById(id) == null) { | |
| 63 | + throw exception(ARTICLE_NOT_EXISTS); | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + @Override | |
| 68 | + public ArticleDO getArticle(Long id) { | |
| 69 | + return articleMapper.selectById(id); | |
| 70 | + } | |
| 71 | + | |
| 72 | + @Override | |
| 73 | + public List<ArticleDO> getArticleList(Collection<Long> ids) { | |
| 74 | + if (CollUtil.isEmpty(ids)) { | |
| 75 | + return ListUtil.empty(); | |
| 76 | + } | |
| 77 | + return articleMapper.selectBatchIds(ids); | |
| 78 | + } | |
| 79 | + | |
| 80 | + @Override | |
| 81 | + public PageResult<ArticleDO> getArticlePage(ArticlePageReqVO pageReqVO) { | |
| 82 | + return articleMapper.selectPage(pageReqVO); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Override | |
| 86 | + public List<ArticleDO> getArticleList(ArticleExportReqVO exportReqVO) { | |
| 87 | + return articleMapper.selectList(exportReqVO); | |
| 88 | + } | |
| 89 | + | |
| 90 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/article/ArticleServiceImplTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.service.article; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleCreateReqVO; | |
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleExportReqVO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticlePageReqVO; | |
| 8 | +import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleUpdateReqVO; | |
| 9 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO; | |
| 10 | +import cn.iocoder.yudao.module.promotion.dal.mysql.article.ArticleMapper; | |
| 11 | +import org.junit.jupiter.api.Disabled; | |
| 12 | +import org.junit.jupiter.api.Test; | |
| 13 | +import org.springframework.context.annotation.Import; | |
| 14 | + | |
| 15 | +import javax.annotation.Resource; | |
| 16 | +import java.util.List; | |
| 17 | + | |
| 18 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; | |
| 19 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | |
| 20 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | |
| 21 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | |
| 22 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; | |
| 23 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | |
| 24 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.ARTICLE_NOT_EXISTS; | |
| 25 | +import static org.junit.jupiter.api.Assertions.*; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * {@link ArticleServiceImpl} 的单元测试类 | |
| 29 | + * | |
| 30 | + * @author HUIHUI | |
| 31 | + */ | |
| 32 | +@Import(ArticleServiceImpl.class) | |
| 33 | +public class ArticleServiceImplTest extends BaseDbUnitTest { | |
| 34 | + | |
| 35 | + @Resource | |
| 36 | + private ArticleServiceImpl articleService; | |
| 37 | + | |
| 38 | + @Resource | |
| 39 | + private ArticleMapper articleMapper; | |
| 40 | + | |
| 41 | + @Test | |
| 42 | + public void testCreateArticle_success() { | |
| 43 | + // 准备参数 | |
| 44 | + ArticleCreateReqVO reqVO = randomPojo(ArticleCreateReqVO.class); | |
| 45 | + | |
| 46 | + // 调用 | |
| 47 | + Long articleId = articleService.createArticle(reqVO); | |
| 48 | + // 断言 | |
| 49 | + assertNotNull(articleId); | |
| 50 | + // 校验记录的属性是否正确 | |
| 51 | + ArticleDO article = articleMapper.selectById(articleId); | |
| 52 | + assertPojoEquals(reqVO, article); | |
| 53 | + } | |
| 54 | + | |
| 55 | + @Test | |
| 56 | + public void testUpdateArticle_success() { | |
| 57 | + // mock 数据 | |
| 58 | + ArticleDO dbArticle = randomPojo(ArticleDO.class); | |
| 59 | + articleMapper.insert(dbArticle);// @Sql: 先插入出一条存在的数据 | |
| 60 | + // 准备参数 | |
| 61 | + ArticleUpdateReqVO reqVO = randomPojo(ArticleUpdateReqVO.class, o -> { | |
| 62 | + o.setId(dbArticle.getId()); // 设置更新的 ID | |
| 63 | + }); | |
| 64 | + | |
| 65 | + // 调用 | |
| 66 | + articleService.updateArticle(reqVO); | |
| 67 | + // 校验是否更新正确 | |
| 68 | + ArticleDO article = articleMapper.selectById(reqVO.getId()); // 获取最新的 | |
| 69 | + assertPojoEquals(reqVO, article); | |
| 70 | + } | |
| 71 | + | |
| 72 | + @Test | |
| 73 | + public void testUpdateArticle_notExists() { | |
| 74 | + // 准备参数 | |
| 75 | + ArticleUpdateReqVO reqVO = randomPojo(ArticleUpdateReqVO.class); | |
| 76 | + | |
| 77 | + // 调用, 并断言异常 | |
| 78 | + assertServiceException(() -> articleService.updateArticle(reqVO), ARTICLE_NOT_EXISTS); | |
| 79 | + } | |
| 80 | + | |
| 81 | + @Test | |
| 82 | + public void testDeleteArticle_success() { | |
| 83 | + // mock 数据 | |
| 84 | + ArticleDO dbArticle = randomPojo(ArticleDO.class); | |
| 85 | + articleMapper.insert(dbArticle);// @Sql: 先插入出一条存在的数据 | |
| 86 | + // 准备参数 | |
| 87 | + Long id = dbArticle.getId(); | |
| 88 | + | |
| 89 | + // 调用 | |
| 90 | + articleService.deleteArticle(id); | |
| 91 | + // 校验数据不存在了 | |
| 92 | + assertNull(articleMapper.selectById(id)); | |
| 93 | + } | |
| 94 | + | |
| 95 | + @Test | |
| 96 | + public void testDeleteArticle_notExists() { | |
| 97 | + // 准备参数 | |
| 98 | + Long id = randomLongId(); | |
| 99 | + | |
| 100 | + // 调用, 并断言异常 | |
| 101 | + assertServiceException(() -> articleService.deleteArticle(id), ARTICLE_NOT_EXISTS); | |
| 102 | + } | |
| 103 | + | |
| 104 | + @Test | |
| 105 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 106 | + public void testGetArticlePage() { | |
| 107 | + // mock 数据 | |
| 108 | + ArticleDO dbArticle = randomPojo(ArticleDO.class, o -> { // 等会查询到 | |
| 109 | + o.setCategoryId(null); | |
| 110 | + o.setTitle(null); | |
| 111 | + o.setAuthor(null); | |
| 112 | + o.setPicUrl(null); | |
| 113 | + o.setIntroduction(null); | |
| 114 | + o.setBrowseCount(null); | |
| 115 | + o.setSort(null); | |
| 116 | + o.setStatus(null); | |
| 117 | + o.setSpuId(null); | |
| 118 | + o.setRecommendHot(null); | |
| 119 | + o.setRecommendBanner(null); | |
| 120 | + o.setContent(null); | |
| 121 | + o.setCreateTime(null); | |
| 122 | + }); | |
| 123 | + articleMapper.insert(dbArticle); | |
| 124 | + // 测试 categoryId 不匹配 | |
| 125 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setCategoryId(null))); | |
| 126 | + // 测试 title 不匹配 | |
| 127 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setTitle(null))); | |
| 128 | + // 测试 author 不匹配 | |
| 129 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setAuthor(null))); | |
| 130 | + // 测试 picUrl 不匹配 | |
| 131 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setPicUrl(null))); | |
| 132 | + // 测试 introduction 不匹配 | |
| 133 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setIntroduction(null))); | |
| 134 | + // 测试 browseCount 不匹配 | |
| 135 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setBrowseCount(null))); | |
| 136 | + // 测试 sort 不匹配 | |
| 137 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setSort(null))); | |
| 138 | + // 测试 status 不匹配 | |
| 139 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setStatus(null))); | |
| 140 | + // 测试 spuId 不匹配 | |
| 141 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setSpuId(null))); | |
| 142 | + // 测试 recommendHot 不匹配 | |
| 143 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setRecommendHot(null))); | |
| 144 | + // 测试 recommendBanner 不匹配 | |
| 145 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setRecommendBanner(null))); | |
| 146 | + // 测试 content 不匹配 | |
| 147 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setContent(null))); | |
| 148 | + // 测试 createTime 不匹配 | |
| 149 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setCreateTime(null))); | |
| 150 | + // 准备参数 | |
| 151 | + ArticlePageReqVO reqVO = new ArticlePageReqVO(); | |
| 152 | + reqVO.setCategoryId(null); | |
| 153 | + reqVO.setTitle(null); | |
| 154 | + reqVO.setAuthor(null); | |
| 155 | + reqVO.setStatus(null); | |
| 156 | + reqVO.setSpuId(null); | |
| 157 | + reqVO.setRecommendHot(null); | |
| 158 | + reqVO.setRecommendBanner(null); | |
| 159 | + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 160 | + | |
| 161 | + // 调用 | |
| 162 | + PageResult<ArticleDO> pageResult = articleService.getArticlePage(reqVO); | |
| 163 | + // 断言 | |
| 164 | + assertEquals(1, pageResult.getTotal()); | |
| 165 | + assertEquals(1, pageResult.getList().size()); | |
| 166 | + assertPojoEquals(dbArticle, pageResult.getList().get(0)); | |
| 167 | + } | |
| 168 | + | |
| 169 | + @Test | |
| 170 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 171 | + public void testGetArticleList() { | |
| 172 | + // mock 数据 | |
| 173 | + ArticleDO dbArticle = randomPojo(ArticleDO.class, o -> { // 等会查询到 | |
| 174 | + o.setCategoryId(null); | |
| 175 | + o.setTitle(null); | |
| 176 | + o.setAuthor(null); | |
| 177 | + o.setPicUrl(null); | |
| 178 | + o.setIntroduction(null); | |
| 179 | + o.setBrowseCount(null); | |
| 180 | + o.setSort(null); | |
| 181 | + o.setStatus(null); | |
| 182 | + o.setSpuId(null); | |
| 183 | + o.setRecommendHot(null); | |
| 184 | + o.setRecommendBanner(null); | |
| 185 | + o.setContent(null); | |
| 186 | + o.setCreateTime(null); | |
| 187 | + }); | |
| 188 | + articleMapper.insert(dbArticle); | |
| 189 | + // 测试 categoryId 不匹配 | |
| 190 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setCategoryId(null))); | |
| 191 | + // 测试 title 不匹配 | |
| 192 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setTitle(null))); | |
| 193 | + // 测试 author 不匹配 | |
| 194 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setAuthor(null))); | |
| 195 | + // 测试 picUrl 不匹配 | |
| 196 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setPicUrl(null))); | |
| 197 | + // 测试 introduction 不匹配 | |
| 198 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setIntroduction(null))); | |
| 199 | + // 测试 browseCount 不匹配 | |
| 200 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setBrowseCount(null))); | |
| 201 | + // 测试 sort 不匹配 | |
| 202 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setSort(null))); | |
| 203 | + // 测试 status 不匹配 | |
| 204 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setStatus(null))); | |
| 205 | + // 测试 spuId 不匹配 | |
| 206 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setSpuId(null))); | |
| 207 | + // 测试 recommendHot 不匹配 | |
| 208 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setRecommendHot(null))); | |
| 209 | + // 测试 recommendBanner 不匹配 | |
| 210 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setRecommendBanner(null))); | |
| 211 | + // 测试 content 不匹配 | |
| 212 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setContent(null))); | |
| 213 | + // 测试 createTime 不匹配 | |
| 214 | + articleMapper.insert(cloneIgnoreId(dbArticle, o -> o.setCreateTime(null))); | |
| 215 | + // 准备参数 | |
| 216 | + ArticleExportReqVO reqVO = new ArticleExportReqVO(); | |
| 217 | + reqVO.setCategoryId(null); | |
| 218 | + reqVO.setTitle(null); | |
| 219 | + reqVO.setAuthor(null); | |
| 220 | + reqVO.setStatus(null); | |
| 221 | + reqVO.setSpuId(null); | |
| 222 | + reqVO.setRecommendHot(null); | |
| 223 | + reqVO.setRecommendBanner(null); | |
| 224 | + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 225 | + | |
| 226 | + // 调用 | |
| 227 | + List<ArticleDO> list = articleService.getArticleList(reqVO); | |
| 228 | + // 断言 | |
| 229 | + assertEquals(1, list.size()); | |
| 230 | + assertPojoEquals(dbArticle, list.get(0)); | |
| 231 | + } | |
| 232 | + | |
| 233 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/test/resources/sql/clean.sql
yudao-module-mall/yudao-module-promotion-biz/src/test/resources/sql/create_tables.sql
| ... | ... | @@ -196,4 +196,28 @@ CREATE TABLE IF NOT EXISTS "promotion_article_category" |
| 196 | 196 | "deleted" bit NOT NULL DEFAULT FALSE, |
| 197 | 197 | "tenant_id" bigint NOT NULL, |
| 198 | 198 | PRIMARY KEY ("id") |
| 199 | -) COMMENT '文章分类表'; | |
| 200 | 199 | \ No newline at end of file |
| 200 | +) COMMENT '文章分类表'; | |
| 201 | + | |
| 202 | +CREATE TABLE IF NOT EXISTS "promotion_article" | |
| 203 | +( | |
| 204 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 205 | + "category_id" bigint NOT NULL, | |
| 206 | + "title" varchar NOT NULL, | |
| 207 | + "author" varchar, | |
| 208 | + "pic_url" varchar NOT NULL, | |
| 209 | + "introduction" varchar, | |
| 210 | + "browse_count" varchar, | |
| 211 | + "sort" int NOT NULL, | |
| 212 | + "status" int NOT NULL, | |
| 213 | + "spu_id" bigint NOT NULL, | |
| 214 | + "recommend_hot" bit NOT NULL, | |
| 215 | + "recommend_banner" bit NOT NULL, | |
| 216 | + "content" varchar NOT NULL, | |
| 217 | + "creator" varchar DEFAULT '', | |
| 218 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 219 | + "updater" varchar DEFAULT '', | |
| 220 | + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
| 221 | + "deleted" bit NOT NULL DEFAULT FALSE, | |
| 222 | + "tenant_id" bigint NOT NULL, | |
| 223 | + PRIMARY KEY ("id") | |
| 224 | +) COMMENT '文章管理表'; | |
| 201 | 225 | \ No newline at end of file | ... | ... |
yudao-server/src/main/resources/application-local.yaml
| ... | ... | @@ -48,7 +48,7 @@ spring: |
| 48 | 48 | primary: master |
| 49 | 49 | datasource: |
| 50 | 50 | master: |
| 51 | - name: ruoyi-vue-pro | |
| 51 | + name: ruoyi-vue-pro2 | |
| 52 | 52 | url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 |
| 53 | 53 | # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 |
| 54 | 54 | # url: jdbc:postgresql://127.0.0.1:5432/${spring.datasource.dynamic.datasource.master.name} # PostgreSQL 连接的示例 |
| ... | ... | @@ -59,7 +59,7 @@ spring: |
| 59 | 59 | # username: sa |
| 60 | 60 | # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W |
| 61 | 61 | slave: # 模拟从库,可根据自己需要修改 |
| 62 | - name: ruoyi-vue-pro | |
| 62 | + name: ruoyi-vue-pro2 | |
| 63 | 63 | lazy: true # 开启懒加载,保证启动速度 |
| 64 | 64 | url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例 |
| 65 | 65 | # url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT # MySQL Connector/J 5.X 连接的示例 |
| ... | ... | @@ -75,8 +75,8 @@ spring: |
| 75 | 75 | redis: |
| 76 | 76 | host: 127.0.0.1 # 地址 |
| 77 | 77 | port: 6379 # 端口 |
| 78 | - database: 0 # 数据库索引 | |
| 79 | -# password: dev # 密码,建议生产环境开启 | |
| 78 | + database: 5 # 数据库索引 | |
| 79 | + password: 123456 # 密码,建议生产环境开启 | |
| 80 | 80 | |
| 81 | 81 | --- #################### 定时任务相关配置 #################### |
| 82 | 82 | ... | ... |