Commit a47ab328005727c501f06eb9f4bda189b4a2a91d

Authored by puhui999
1 parent a4613f0a

营销活动: 新增文章分类管理

Showing 19 changed files with 813 additions and 1 deletions
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/DictTypeConstants.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.enums;
  2 +
  3 +/**
  4 + * promotion 字典类型的枚举类
  5 + *
  6 + * @author HUIHUI
  7 + */
  8 +public class DictTypeConstants {
  9 +
  10 +}
... ...
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java
... ... @@ -110,4 +110,7 @@ public interface ErrorCodeConstants {
110 110 ErrorCode BARGAIN_HELP_CREATE_FAIL_CONFLICT = new ErrorCode(1_013_014_003, "助力失败,请重试");
111 111 ErrorCode BARGAIN_HELP_CREATE_FAIL_HELP_EXISTS = new ErrorCode(1_013_014_004, "助力失败,您已经助力过了");
112 112  
  113 + // ========== 文章分类 1-013-015-000 ==========
  114 + ErrorCode ARTICLE_CATEGORY_NOT_EXISTS = new ErrorCode(1_013_015_000, "分类不存在");
  115 +
113 116 }
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/articlecategory/ArticleCategoryController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.admin.articlecategory;
  2 +
  3 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
  4 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
  7 +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
  8 +import cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.vo.*;
  9 +import cn.iocoder.yudao.module.promotion.convert.articlecategory.ArticleCategoryConvert;
  10 +import cn.iocoder.yudao.module.promotion.dal.dataobject.articlecategory.ArticleCategoryDO;
  11 +import cn.iocoder.yudao.module.promotion.service.articlecategory.ArticleCategoryService;
  12 +import io.swagger.v3.oas.annotations.Operation;
  13 +import io.swagger.v3.oas.annotations.Parameter;
  14 +import io.swagger.v3.oas.annotations.tags.Tag;
  15 +import org.springframework.security.access.prepost.PreAuthorize;
  16 +import org.springframework.validation.annotation.Validated;
  17 +import org.springframework.web.bind.annotation.*;
  18 +
  19 +import javax.annotation.Resource;
  20 +import javax.servlet.http.HttpServletResponse;
  21 +import javax.validation.Valid;
  22 +import java.io.IOException;
  23 +import java.util.Collection;
  24 +import java.util.Comparator;
  25 +import java.util.List;
  26 +
  27 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  28 +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
  29 +
  30 +@Tag(name = "管理后台 - 文章分类")
  31 +@RestController
  32 +@RequestMapping("/promotion/article-category")
  33 +@Validated
  34 +public class ArticleCategoryController {
  35 +
  36 + @Resource
  37 + private ArticleCategoryService articleCategoryService;
  38 +
  39 + @PostMapping("/create")
  40 + @Operation(summary = "创建文章分类")
  41 + @PreAuthorize("@ss.hasPermission('promotion:article-category:create')")
  42 + public CommonResult<Long> createArticleCategory(@Valid @RequestBody ArticleCategoryCreateReqVO createReqVO) {
  43 + return success(articleCategoryService.createArticleCategory(createReqVO));
  44 + }
  45 +
  46 + @PutMapping("/update")
  47 + @Operation(summary = "更新文章分类")
  48 + @PreAuthorize("@ss.hasPermission('promotion:article-category:update')")
  49 + public CommonResult<Boolean> updateArticleCategory(@Valid @RequestBody ArticleCategoryUpdateReqVO updateReqVO) {
  50 + articleCategoryService.updateArticleCategory(updateReqVO);
  51 + return success(true);
  52 + }
  53 +
  54 + @DeleteMapping("/delete")
  55 + @Operation(summary = "删除文章分类")
  56 + @Parameter(name = "id", description = "编号", required = true)
  57 + @PreAuthorize("@ss.hasPermission('promotion:article-category:delete')")
  58 + public CommonResult<Boolean> deleteArticleCategory(@RequestParam("id") Long id) {
  59 + articleCategoryService.deleteArticleCategory(id);
  60 + return success(true);
  61 + }
  62 +
  63 + @GetMapping("/get")
  64 + @Operation(summary = "获得文章分类")
  65 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  66 + @PreAuthorize("@ss.hasPermission('promotion:article-category:query')")
  67 + public CommonResult<ArticleCategoryRespVO> getArticleCategory(@RequestParam("id") Long id) {
  68 + ArticleCategoryDO articleCategory = articleCategoryService.getArticleCategory(id);
  69 + return success(ArticleCategoryConvert.INSTANCE.convert(articleCategory));
  70 + }
  71 +
  72 + @GetMapping("/list")
  73 + @Operation(summary = "获得文章分类列表")
  74 + @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
  75 + @PreAuthorize("@ss.hasPermission('promotion:article-category:query')")
  76 + public CommonResult<List<ArticleCategoryRespVO>> getArticleCategoryList(@RequestParam("ids") Collection<Long> ids) {
  77 + List<ArticleCategoryDO> list = articleCategoryService.getArticleCategoryList(ids);
  78 + return success(ArticleCategoryConvert.INSTANCE.convertList(list));
  79 + }
  80 +
  81 + @GetMapping("/list-all-simple")
  82 + @Operation(summary = "获取文章分类精简信息列表", description = "只包含被开启的文章分类,主要用于前端的下拉选项")
  83 + public CommonResult<List<ArticleCategorySimpleRespVO>> getSimpleDeptList() {
  84 + // 获得部门列表,只要开启状态的
  85 + List<ArticleCategoryDO> list = articleCategoryService.getArticleCategoryListByStatus(CommonStatusEnum.ENABLE.getStatus());
  86 + // 降序排序后,返回给前端
  87 + list.sort(Comparator.comparing(ArticleCategoryDO::getSort).reversed());
  88 + return success(ArticleCategoryConvert.INSTANCE.convertList03(list));
  89 + }
  90 +
  91 + @GetMapping("/page")
  92 + @Operation(summary = "获得文章分类分页")
  93 + @PreAuthorize("@ss.hasPermission('promotion:article-category:query')")
  94 + public CommonResult<PageResult<ArticleCategoryRespVO>> getArticleCategoryPage(@Valid ArticleCategoryPageReqVO pageVO) {
  95 + PageResult<ArticleCategoryDO> pageResult = articleCategoryService.getArticleCategoryPage(pageVO);
  96 + return success(ArticleCategoryConvert.INSTANCE.convertPage(pageResult));
  97 + }
  98 +
  99 + @GetMapping("/export-excel")
  100 + @Operation(summary = "导出文章分类 Excel")
  101 + @PreAuthorize("@ss.hasPermission('promotion:article-category:export')")
  102 + @OperateLog(type = EXPORT)
  103 + public void exportArticleCategoryExcel(@Valid ArticleCategoryExportReqVO exportReqVO,
  104 + HttpServletResponse response) throws IOException {
  105 + List<ArticleCategoryDO> list = articleCategoryService.getArticleCategoryList(exportReqVO);
  106 + // 导出 Excel
  107 + List<ArticleCategoryExcelVO> datas = ArticleCategoryConvert.INSTANCE.convertList02(list);
  108 + ExcelUtils.write(response, "文章分类.xls", "数据", ArticleCategoryExcelVO.class, datas);
  109 + }
  110 +
  111 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/articlecategory/vo/ArticleCategoryBaseVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.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 ArticleCategoryBaseVO {
  14 +
  15 + @Schema(description = "文章分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "秒杀")
  16 + @NotNull(message = "文章分类名称不能为空")
  17 + private String name;
  18 +
  19 + @Schema(description = "图标地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn")
  20 + private String picUrl;
  21 +
  22 + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  23 + @NotNull(message = "状态不能为空")
  24 + private Integer status;
  25 +
  26 + @Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  27 + @NotNull(message = "排序不能为空")
  28 + private Integer sort;
  29 +
  30 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/articlecategory/vo/ArticleCategoryCreateReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.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 ArticleCategoryCreateReqVO extends ArticleCategoryBaseVO {
  13 +
  14 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/articlecategory/vo/ArticleCategoryExcelVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.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 ArticleCategoryExcelVO {
  19 +
  20 + @ExcelProperty("文章分类编号")
  21 + private Long id;
  22 +
  23 + @ExcelProperty("文章分类名称")
  24 + private String name;
  25 +
  26 + @ExcelProperty("图标地址")
  27 + private String picUrl;
  28 +
  29 + @ExcelProperty(value = "状态", converter = DictConvert.class)
  30 + @DictFormat(DictTypeConstants.COMMON_STATUS)
  31 + private Integer status;
  32 +
  33 + @ExcelProperty("排序")
  34 + private Integer sort;
  35 +
  36 + @ExcelProperty("创建时间")
  37 + private LocalDateTime createTime;
  38 +
  39 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/articlecategory/vo/ArticleCategoryExportReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.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,参数和 ArticleCategoryPageReqVO 是一致的")
  12 +@Data
  13 +public class ArticleCategoryExportReqVO {
  14 +
  15 + @Schema(description = "文章分类名称", example = "秒杀")
  16 + private String name;
  17 +
  18 + @Schema(description = "状态", example = "1")
  19 + private Integer status;
  20 +
  21 + @Schema(description = "创建时间")
  22 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  23 + private LocalDateTime[] createTime;
  24 +
  25 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/articlecategory/vo/ArticleCategoryPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.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 ArticleCategoryPageReqVO extends PageParam {
  19 +
  20 + @Schema(description = "文章分类名称", example = "秒杀")
  21 + private String name;
  22 +
  23 + @Schema(description = "状态", example = "1")
  24 + private Integer status;
  25 +
  26 + @Schema(description = "创建时间")
  27 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  28 + private LocalDateTime[] createTime;
  29 +
  30 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/articlecategory/vo/ArticleCategoryRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.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 ArticleCategoryRespVO extends ArticleCategoryBaseVO {
  15 +
  16 + @Schema(description = "文章分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "19490")
  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/articlecategory/vo/ArticleCategorySimpleRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +@Schema(description = "管理后台 - 文章分类精简信息 Response VO")
  7 +@Data
  8 +public class ArticleCategorySimpleRespVO {
  9 +
  10 + @Schema(description = "文章分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "19490")
  11 + private Long id;
  12 +
  13 + @Schema(description = "文章分类名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "秒杀")
  14 + private String name;
  15 +
  16 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/articlecategory/vo/ArticleCategoryUpdateReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.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 ArticleCategoryUpdateReqVO extends ArticleCategoryBaseVO {
  15 +
  16 + @Schema(description = "文章分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "19490")
  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/articlecategory/ArticleCategoryConvert.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.convert.articlecategory;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.vo.*;
  5 +import cn.iocoder.yudao.module.promotion.dal.dataobject.articlecategory.ArticleCategoryDO;
  6 +import org.mapstruct.Mapper;
  7 +import org.mapstruct.factory.Mappers;
  8 +
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * 文章分类 Convert
  13 + *
  14 + * @author HUIHUI
  15 + */
  16 +@Mapper
  17 +public interface ArticleCategoryConvert {
  18 +
  19 + ArticleCategoryConvert INSTANCE = Mappers.getMapper(ArticleCategoryConvert.class);
  20 +
  21 + ArticleCategoryDO convert(ArticleCategoryCreateReqVO bean);
  22 +
  23 + ArticleCategoryDO convert(ArticleCategoryUpdateReqVO bean);
  24 +
  25 + ArticleCategoryRespVO convert(ArticleCategoryDO bean);
  26 +
  27 + List<ArticleCategoryRespVO> convertList(List<ArticleCategoryDO> list);
  28 +
  29 + PageResult<ArticleCategoryRespVO> convertPage(PageResult<ArticleCategoryDO> page);
  30 +
  31 + List<ArticleCategoryExcelVO> convertList02(List<ArticleCategoryDO> list);
  32 +
  33 + List<ArticleCategorySimpleRespVO> convertList03(List<ArticleCategoryDO> list);
  34 +
  35 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/articlecategory/ArticleCategoryDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.dal.dataobject.articlecategory;
  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_category")
  16 +@KeySequence("promotion_article_category_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 ArticleCategoryDO extends BaseDO {
  24 +
  25 + /**
  26 + * 文章分类编号
  27 + */
  28 + @TableId
  29 + private Long id;
  30 + /**
  31 + * 文章分类名称
  32 + */
  33 + private String name;
  34 + /**
  35 + * 图标地址
  36 + */
  37 + private String picUrl;
  38 + /**
  39 + * 状态
  40 + *
  41 + * 枚举 {@link CommonStatusEnum}
  42 + */
  43 + private Integer status;
  44 + /**
  45 + * 排序
  46 + */
  47 + private Integer sort;
  48 +
  49 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/articlecategory/ArticleCategoryMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.dal.mysql.articlecategory;
  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.articlecategory.vo.ArticleCategoryExportReqVO;
  7 +import cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.vo.ArticleCategoryPageReqVO;
  8 +import cn.iocoder.yudao.module.promotion.dal.dataobject.articlecategory.ArticleCategoryDO;
  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 ArticleCategoryMapper extends BaseMapperX<ArticleCategoryDO> {
  20 +
  21 + default PageResult<ArticleCategoryDO> selectPage(ArticleCategoryPageReqVO reqVO) {
  22 + return selectPage(reqVO, new LambdaQueryWrapperX<ArticleCategoryDO>()
  23 + .likeIfPresent(ArticleCategoryDO::getName, reqVO.getName())
  24 + .eqIfPresent(ArticleCategoryDO::getStatus, reqVO.getStatus())
  25 + .betweenIfPresent(ArticleCategoryDO::getCreateTime, reqVO.getCreateTime())
  26 + .orderByDesc(ArticleCategoryDO::getSort));
  27 + }
  28 +
  29 + default List<ArticleCategoryDO> selectList(ArticleCategoryExportReqVO reqVO) {
  30 + return selectList(new LambdaQueryWrapperX<ArticleCategoryDO>()
  31 + .likeIfPresent(ArticleCategoryDO::getName, reqVO.getName())
  32 + .eqIfPresent(ArticleCategoryDO::getStatus, reqVO.getStatus())
  33 + .betweenIfPresent(ArticleCategoryDO::getCreateTime, reqVO.getCreateTime())
  34 + .orderByDesc(ArticleCategoryDO::getSort));
  35 + }
  36 +
  37 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/articlecategory/ArticleCategoryService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.service.articlecategory;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.vo.ArticleCategoryCreateReqVO;
  5 +import cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.vo.ArticleCategoryExportReqVO;
  6 +import cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.vo.ArticleCategoryPageReqVO;
  7 +import cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.vo.ArticleCategoryUpdateReqVO;
  8 +import cn.iocoder.yudao.module.promotion.dal.dataobject.articlecategory.ArticleCategoryDO;
  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 ArticleCategoryService {
  20 +
  21 + /**
  22 + * 创建文章分类
  23 + *
  24 + * @param createReqVO 创建信息
  25 + * @return 编号
  26 + */
  27 + Long createArticleCategory(@Valid ArticleCategoryCreateReqVO createReqVO);
  28 +
  29 + /**
  30 + * 更新文章分类
  31 + *
  32 + * @param updateReqVO 更新信息
  33 + */
  34 + void updateArticleCategory(@Valid ArticleCategoryUpdateReqVO updateReqVO);
  35 +
  36 + /**
  37 + * 删除文章分类
  38 + *
  39 + * @param id 编号
  40 + */
  41 + void deleteArticleCategory(Long id);
  42 +
  43 + /**
  44 + * 获得文章分类
  45 + *
  46 + * @param id 编号
  47 + * @return 文章分类
  48 + */
  49 + ArticleCategoryDO getArticleCategory(Long id);
  50 +
  51 + /**
  52 + * 获得文章分类列表
  53 + *
  54 + * @param ids 编号
  55 + * @return 文章分类列表
  56 + */
  57 + List<ArticleCategoryDO> getArticleCategoryList(Collection<Long> ids);
  58 +
  59 + /**
  60 + * 获得文章分类分页
  61 + *
  62 + * @param pageReqVO 分页查询
  63 + * @return 文章分类分页
  64 + */
  65 + PageResult<ArticleCategoryDO> getArticleCategoryPage(ArticleCategoryPageReqVO pageReqVO);
  66 +
  67 + /**
  68 + * 获得文章分类列表, 用于 Excel 导出
  69 + *
  70 + * @param exportReqVO 查询条件
  71 + * @return 文章分类列表
  72 + */
  73 + List<ArticleCategoryDO> getArticleCategoryList(ArticleCategoryExportReqVO exportReqVO);
  74 +
  75 + /**
  76 + * 获得指定状态的文章分类列表
  77 + *
  78 + * @param status 状态
  79 + * @return 文章分类列表
  80 + */
  81 + List<ArticleCategoryDO> getArticleCategoryListByStatus(Integer status);
  82 +
  83 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/articlecategory/ArticleCategoryServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.service.articlecategory;
  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.articlecategory.vo.ArticleCategoryCreateReqVO;
  7 +import cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.vo.ArticleCategoryExportReqVO;
  8 +import cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.vo.ArticleCategoryPageReqVO;
  9 +import cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.vo.ArticleCategoryUpdateReqVO;
  10 +import cn.iocoder.yudao.module.promotion.convert.articlecategory.ArticleCategoryConvert;
  11 +import cn.iocoder.yudao.module.promotion.dal.dataobject.articlecategory.ArticleCategoryDO;
  12 +import cn.iocoder.yudao.module.promotion.dal.mysql.articlecategory.ArticleCategoryMapper;
  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_CATEGORY_NOT_EXISTS;
  22 +
  23 +/**
  24 + * 文章分类 Service 实现类
  25 + *
  26 + * @author HUIHUI
  27 + */
  28 +@Service
  29 +@Validated
  30 +public class ArticleCategoryServiceImpl implements ArticleCategoryService {
  31 +
  32 + @Resource
  33 + private ArticleCategoryMapper articleCategoryMapper;
  34 +
  35 + @Override
  36 + public Long createArticleCategory(ArticleCategoryCreateReqVO createReqVO) {
  37 + // 插入
  38 + ArticleCategoryDO articleCategory = ArticleCategoryConvert.INSTANCE.convert(createReqVO);
  39 + articleCategoryMapper.insert(articleCategory);
  40 + // 返回
  41 + return articleCategory.getId();
  42 + }
  43 +
  44 + @Override
  45 + public void updateArticleCategory(ArticleCategoryUpdateReqVO updateReqVO) {
  46 + // 校验存在
  47 + validateArticleCategoryExists(updateReqVO.getId());
  48 + // 更新
  49 + ArticleCategoryDO updateObj = ArticleCategoryConvert.INSTANCE.convert(updateReqVO);
  50 + articleCategoryMapper.updateById(updateObj);
  51 + }
  52 +
  53 + @Override
  54 + public void deleteArticleCategory(Long id) {
  55 + // 校验存在
  56 + validateArticleCategoryExists(id);
  57 + // 删除
  58 + articleCategoryMapper.deleteById(id);
  59 + }
  60 +
  61 + private void validateArticleCategoryExists(Long id) {
  62 + if (articleCategoryMapper.selectById(id) == null) {
  63 + throw exception(ARTICLE_CATEGORY_NOT_EXISTS);
  64 + }
  65 + }
  66 +
  67 + @Override
  68 + public ArticleCategoryDO getArticleCategory(Long id) {
  69 + return articleCategoryMapper.selectById(id);
  70 + }
  71 +
  72 + @Override
  73 + public List<ArticleCategoryDO> getArticleCategoryList(Collection<Long> ids) {
  74 + if (CollUtil.isEmpty(ids)) {
  75 + return ListUtil.empty();
  76 + }
  77 + return articleCategoryMapper.selectBatchIds(ids);
  78 + }
  79 +
  80 + @Override
  81 + public PageResult<ArticleCategoryDO> getArticleCategoryPage(ArticleCategoryPageReqVO pageReqVO) {
  82 + return articleCategoryMapper.selectPage(pageReqVO);
  83 + }
  84 +
  85 + @Override
  86 + public List<ArticleCategoryDO> getArticleCategoryList(ArticleCategoryExportReqVO exportReqVO) {
  87 + return articleCategoryMapper.selectList(exportReqVO);
  88 + }
  89 +
  90 + @Override
  91 + public List<ArticleCategoryDO> getArticleCategoryListByStatus(Integer status) {
  92 + return articleCategoryMapper.selectList(ArticleCategoryDO::getStatus, status);
  93 + }
  94 +
  95 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/articlecategory/ArticleCategoryServiceImplTest.java 0 → 100644
  1 +package cn.iocoder.yudao.module.promotion.service.articlecategory;
  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.articlecategory.vo.ArticleCategoryCreateReqVO;
  6 +import cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.vo.ArticleCategoryExportReqVO;
  7 +import cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.vo.ArticleCategoryPageReqVO;
  8 +import cn.iocoder.yudao.module.promotion.controller.admin.articlecategory.vo.ArticleCategoryUpdateReqVO;
  9 +import cn.iocoder.yudao.module.promotion.dal.dataobject.articlecategory.ArticleCategoryDO;
  10 +import cn.iocoder.yudao.module.promotion.dal.mysql.articlecategory.ArticleCategoryMapper;
  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_CATEGORY_NOT_EXISTS;
  25 +import static org.junit.jupiter.api.Assertions.*;
  26 +
  27 +/**
  28 + * {@link ArticleCategoryServiceImpl} 的单元测试类
  29 + *
  30 + * @author HUIHUI
  31 + */
  32 +@Import(ArticleCategoryServiceImpl.class)
  33 +public class ArticleCategoryServiceImplTest extends BaseDbUnitTest {
  34 +
  35 + @Resource
  36 + private ArticleCategoryServiceImpl articleCategoryService;
  37 +
  38 + @Resource
  39 + private ArticleCategoryMapper articleCategoryMapper;
  40 +
  41 + @Test
  42 + public void testCreateArticleCategory_success() {
  43 + // 准备参数
  44 + ArticleCategoryCreateReqVO reqVO = randomPojo(ArticleCategoryCreateReqVO.class);
  45 +
  46 + // 调用
  47 + Long articleCategoryId = articleCategoryService.createArticleCategory(reqVO);
  48 + // 断言
  49 + assertNotNull(articleCategoryId);
  50 + // 校验记录的属性是否正确
  51 + ArticleCategoryDO articleCategory = articleCategoryMapper.selectById(articleCategoryId);
  52 + assertPojoEquals(reqVO, articleCategory);
  53 + }
  54 +
  55 + @Test
  56 + public void testUpdateArticleCategory_success() {
  57 + // mock 数据
  58 + ArticleCategoryDO dbArticleCategory = randomPojo(ArticleCategoryDO.class);
  59 + articleCategoryMapper.insert(dbArticleCategory);// @Sql: 先插入出一条存在的数据
  60 + // 准备参数
  61 + ArticleCategoryUpdateReqVO reqVO = randomPojo(ArticleCategoryUpdateReqVO.class, o -> {
  62 + o.setId(dbArticleCategory.getId()); // 设置更新的 ID
  63 + });
  64 +
  65 + // 调用
  66 + articleCategoryService.updateArticleCategory(reqVO);
  67 + // 校验是否更新正确
  68 + ArticleCategoryDO articleCategory = articleCategoryMapper.selectById(reqVO.getId()); // 获取最新的
  69 + assertPojoEquals(reqVO, articleCategory);
  70 + }
  71 +
  72 + @Test
  73 + public void testUpdateArticleCategory_notExists() {
  74 + // 准备参数
  75 + ArticleCategoryUpdateReqVO reqVO = randomPojo(ArticleCategoryUpdateReqVO.class);
  76 +
  77 + // 调用, 并断言异常
  78 + assertServiceException(() -> articleCategoryService.updateArticleCategory(reqVO), ARTICLE_CATEGORY_NOT_EXISTS);
  79 + }
  80 +
  81 + @Test
  82 + public void testDeleteArticleCategory_success() {
  83 + // mock 数据
  84 + ArticleCategoryDO dbArticleCategory = randomPojo(ArticleCategoryDO.class);
  85 + articleCategoryMapper.insert(dbArticleCategory);// @Sql: 先插入出一条存在的数据
  86 + // 准备参数
  87 + Long id = dbArticleCategory.getId();
  88 +
  89 + // 调用
  90 + articleCategoryService.deleteArticleCategory(id);
  91 + // 校验数据不存在了
  92 + assertNull(articleCategoryMapper.selectById(id));
  93 + }
  94 +
  95 + @Test
  96 + public void testDeleteArticleCategory_notExists() {
  97 + // 准备参数
  98 + Long id = randomLongId();
  99 +
  100 + // 调用, 并断言异常
  101 + assertServiceException(() -> articleCategoryService.deleteArticleCategory(id), ARTICLE_CATEGORY_NOT_EXISTS);
  102 + }
  103 +
  104 + @Test
  105 + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
  106 + public void testGetArticleCategoryPage() {
  107 + // mock 数据
  108 + ArticleCategoryDO dbArticleCategory = randomPojo(ArticleCategoryDO.class, o -> { // 等会查询到
  109 + o.setName(null);
  110 + o.setPicUrl(null);
  111 + o.setStatus(null);
  112 + o.setSort(null);
  113 + o.setCreateTime(null);
  114 + });
  115 + articleCategoryMapper.insert(dbArticleCategory);
  116 + // 测试 name 不匹配
  117 + articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setName(null)));
  118 + // 测试 picUrl 不匹配
  119 + articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setPicUrl(null)));
  120 + // 测试 status 不匹配
  121 + articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setStatus(null)));
  122 + // 测试 sort 不匹配
  123 + articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setSort(null)));
  124 + // 测试 createTime 不匹配
  125 + articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setCreateTime(null)));
  126 + // 准备参数
  127 + ArticleCategoryPageReqVO reqVO = new ArticleCategoryPageReqVO();
  128 + reqVO.setName(null);
  129 + reqVO.setStatus(null);
  130 + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
  131 +
  132 + // 调用
  133 + PageResult<ArticleCategoryDO> pageResult = articleCategoryService.getArticleCategoryPage(reqVO);
  134 + // 断言
  135 + assertEquals(1, pageResult.getTotal());
  136 + assertEquals(1, pageResult.getList().size());
  137 + assertPojoEquals(dbArticleCategory, pageResult.getList().get(0));
  138 + }
  139 +
  140 + @Test
  141 + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
  142 + public void testGetArticleCategoryList() {
  143 + // mock 数据
  144 + ArticleCategoryDO dbArticleCategory = randomPojo(ArticleCategoryDO.class, o -> { // 等会查询到
  145 + o.setName(null);
  146 + o.setPicUrl(null);
  147 + o.setStatus(null);
  148 + o.setSort(null);
  149 + o.setCreateTime(null);
  150 + });
  151 + articleCategoryMapper.insert(dbArticleCategory);
  152 + // 测试 name 不匹配
  153 + articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setName(null)));
  154 + // 测试 picUrl 不匹配
  155 + articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setPicUrl(null)));
  156 + // 测试 status 不匹配
  157 + articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setStatus(null)));
  158 + // 测试 sort 不匹配
  159 + articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setSort(null)));
  160 + // 测试 createTime 不匹配
  161 + articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setCreateTime(null)));
  162 + // 准备参数
  163 + ArticleCategoryExportReqVO reqVO = new ArticleCategoryExportReqVO();
  164 + reqVO.setName(null);
  165 + reqVO.setStatus(null);
  166 + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
  167 +
  168 + // 调用
  169 + List<ArticleCategoryDO> list = articleCategoryService.getArticleCategoryList(reqVO);
  170 + // 断言
  171 + assertEquals(1, list.size());
  172 + assertPojoEquals(dbArticleCategory, list.get(0));
  173 + }
  174 +
  175 +}
... ...
yudao-module-mall/yudao-module-promotion-biz/src/test/resources/sql/clean.sql
... ... @@ -6,3 +6,5 @@ DELETE FROM &quot;promotion_discount_activity&quot;;
6 6 DELETE FROM "promotion_discount_product";
7 7 DELETE FROM "promotion_seckill_config";
8 8 DELETE FROM "promotion_combination_activity";
  9 +DELETE
  10 +FROM "promotion_article_category";
... ...
yudao-module-mall/yudao-module-promotion-biz/src/test/resources/sql/create_tables.sql
... ... @@ -180,4 +180,20 @@ CREATE TABLE IF NOT EXISTS &quot;promotion_combination_activity&quot;
180 180 "deleted" bit NOT NULL DEFAULT FALSE,
181 181 "tenant_id" bigint NOT NULL,
182 182 PRIMARY KEY ("id")
183   -) COMMENT '拼团活动';
184 183 \ No newline at end of file
  184 +) COMMENT '拼团活动';
  185 +
  186 +CREATE TABLE IF NOT EXISTS "promotion_article_category"
  187 +(
  188 + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
  189 + "name" varchar NOT NULL,
  190 + "pic_url" varchar,
  191 + "status" int NOT NULL,
  192 + "sort" int NOT NULL,
  193 + "creator" varchar DEFAULT '',
  194 + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  195 + "updater" varchar DEFAULT '',
  196 + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  197 + "deleted" bit NOT NULL DEFAULT FALSE,
  198 + "tenant_id" bigint NOT NULL,
  199 + PRIMARY KEY ("id")
  200 +) COMMENT '文章分类表';
185 201 \ No newline at end of file
... ...