code review:文章管理

This commit is contained in:
YunaiV 2023-10-16 09:57:57 +08:00
parent 69268b525a
commit 7345933d6b
21 changed files with 35 additions and 388 deletions

View File

@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.promotion.controller.admin.article;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.*;
import cn.iocoder.yudao.module.promotion.convert.article.ArticleCategoryConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleCategoryDO;
@ -17,15 +15,11 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@Tag(name = "管理后台 - 文章分类")
@RestController
@ -65,23 +59,14 @@ public class ArticleCategoryController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('promotion:article-category:query')")
public CommonResult<ArticleCategoryRespVO> getArticleCategory(@RequestParam("id") Long id) {
ArticleCategoryDO articleCategory = articleCategoryService.getArticleCategory(id);
return success(ArticleCategoryConvert.INSTANCE.convert(articleCategory));
}
@GetMapping("/list")
@Operation(summary = "获得文章分类列表")
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
@PreAuthorize("@ss.hasPermission('promotion:article-category:query')")
public CommonResult<List<ArticleCategoryRespVO>> getArticleCategoryList(@RequestParam("ids") Collection<Long> ids) {
List<ArticleCategoryDO> list = articleCategoryService.getArticleCategoryList(ids);
return success(ArticleCategoryConvert.INSTANCE.convertList(list));
ArticleCategoryDO category = articleCategoryService.getArticleCategory(id);
return success(ArticleCategoryConvert.INSTANCE.convert(category));
}
@GetMapping("/list-all-simple")
@Operation(summary = "获取文章分类精简信息列表", description = "只包含被开启的文章分类,主要用于前端的下拉选项")
public CommonResult<List<ArticleCategorySimpleRespVO>> getSimpleDeptList() {
// 获得部门列表只要开启状态的
// 获得分类列表只要开启状态的
List<ArticleCategoryDO> list = articleCategoryService.getArticleCategoryListByStatus(CommonStatusEnum.ENABLE.getStatus());
// 降序排序后返回给前端
list.sort(Comparator.comparing(ArticleCategoryDO::getSort).reversed());
@ -96,16 +81,4 @@ public class ArticleCategoryController {
return success(ArticleCategoryConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/export-excel")
@Operation(summary = "导出文章分类 Excel")
@PreAuthorize("@ss.hasPermission('promotion:article-category:export')")
@OperateLog(type = EXPORT)
public void exportArticleCategoryExcel(@Valid ArticleCategoryExportReqVO exportReqVO,
HttpServletResponse response) throws IOException {
List<ArticleCategoryDO> list = articleCategoryService.getArticleCategoryList(exportReqVO);
// 导出 Excel
List<ArticleCategoryExcelVO> datas = ArticleCategoryConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "文章分类.xls", "数据", ArticleCategoryExcelVO.class, datas);
}
}

View File

@ -2,9 +2,10 @@ package cn.iocoder.yudao.module.promotion.controller.admin.article;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.*;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.convert.article.ArticleConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO;
import cn.iocoder.yudao.module.promotion.service.article.ArticleService;
@ -16,14 +17,9 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@Tag(name = "管理后台 - 文章管理")
@RestController
@ -67,15 +63,6 @@ public class ArticleController {
return success(ArticleConvert.INSTANCE.convert(article));
}
@GetMapping("/list")
@Operation(summary = "获得文章管理列表")
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
@PreAuthorize("@ss.hasPermission('promotion:article:query')")
public CommonResult<List<ArticleRespVO>> getArticleList(@RequestParam("ids") Collection<Long> ids) {
List<ArticleDO> list = articleService.getArticleList(ids);
return success(ArticleConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@Operation(summary = "获得文章管理分页")
@PreAuthorize("@ss.hasPermission('promotion:article:query')")
@ -84,16 +71,4 @@ public class ArticleController {
return success(ArticleConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/export-excel")
@Operation(summary = "导出文章管理 Excel")
@PreAuthorize("@ss.hasPermission('promotion:article:export')")
@OperateLog(type = EXPORT)
public void exportArticleExcel(@Valid ArticleExportReqVO exportReqVO,
HttpServletResponse response) throws IOException {
List<ArticleDO> list = articleService.getArticleList(exportReqVO);
// 导出 Excel
List<ArticleExcelVO> datas = ArticleConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "文章管理.xls", "数据", ArticleExcelVO.class, datas);
}
}

View File

@ -1,63 +0,0 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 文章管理 Excel VO
*
* @author HUIHUI
*/
@Data
public class ArticleExcelVO {
@ExcelProperty("文章编号")
private Long id;
@ExcelProperty("文章分类编号")
private Long categoryId;
@ExcelProperty("关联商品编号")
private Long spuId;
@ExcelProperty("文章标题")
private String title;
@ExcelProperty("文章作者")
private String author;
@ExcelProperty("文章封面图片地址")
private String picUrl;
@ExcelProperty("文章简介")
private String introduction;
@ExcelProperty("浏览次数")
private String browseCount;
@ExcelProperty("排序")
private Integer sort;
@ExcelProperty(value = "状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.COMMON_STATUS)
private Integer status;
@ExcelProperty("是否热门(小程序)")
private Boolean recommendHot;
@ExcelProperty("是否轮播图(小程序)")
private Boolean recommendBanner;
@ExcelProperty("文章内容")
private String content;
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -1,40 +0,0 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 文章管理 Excel 导出 Request VO参数和 ArticlePageReqVO 是一致的")
@Data
public class ArticleExportReqVO {
@Schema(description = "文章分类编号", example = "15458")
private Long categoryId;
@Schema(description = "关联商品编号", example = "22378")
private Long spuId;
@Schema(description = "文章标题")
private String title;
@Schema(description = "文章作者")
private String author;
@Schema(description = "状态", example = "2")
private Integer status;
@Schema(description = "是否热门(小程序)")
private Boolean recommendHot;
@Schema(description = "是否轮播图(小程序)")
private Boolean recommendBanner;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo;
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -34,6 +34,7 @@ public class ArticleBaseVO {
@Schema(description = "文章简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "这是一个简介")
private String introduction;
// TODO @puhui999浏览量的字段应该不是后端新增设置的哈
@Schema(description = "浏览次数", requiredMode = Schema.RequiredMode.REQUIRED, example = "111")
private String browseCount;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo;
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo;
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo;
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo;
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

View File

@ -1,39 +0,0 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 文章分类 Excel VO
*
* @author HUIHUI
*/
@Data
public class ArticleCategoryExcelVO {
@ExcelProperty("文章分类编号")
private Long id;
@ExcelProperty("文章分类名称")
private String name;
@ExcelProperty("图标地址")
private String picUrl;
@ExcelProperty(value = "状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.COMMON_STATUS)
private Integer status;
@ExcelProperty("排序")
private Integer sort;
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -1,25 +0,0 @@
package cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 文章分类 Excel 导出 Request VO参数和 ArticleCategoryPageReqVO 是一致的")
@Data
public class ArticleCategoryExportReqVO {
@Schema(description = "文章分类名称", example = "秒杀")
private String name;
@Schema(description = "状态", example = "1")
private Integer status;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -28,8 +28,6 @@ public interface ArticleCategoryConvert {
PageResult<ArticleCategoryRespVO> convertPage(PageResult<ArticleCategoryDO> page);
List<ArticleCategoryExcelVO> convertList02(List<ArticleCategoryDO> list);
List<ArticleCategorySimpleRespVO> convertList03(List<ArticleCategoryDO> list);
}

View File

@ -1,10 +1,9 @@
package cn.iocoder.yudao.module.promotion.convert.article;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleExcelVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@ -31,6 +30,4 @@ public interface ArticleConvert {
PageResult<ArticleRespVO> convertPage(PageResult<ArticleDO> page);
List<ArticleExcelVO> convertList02(List<ArticleDO> list);
}

View File

@ -3,13 +3,10 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.article;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryPageReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleCategoryDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 文章分类 Mapper
*
@ -26,12 +23,4 @@ public interface ArticleCategoryMapper extends BaseMapperX<ArticleCategoryDO> {
.orderByDesc(ArticleCategoryDO::getSort));
}
default List<ArticleCategoryDO> selectList(ArticleCategoryExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<ArticleCategoryDO>()
.likeIfPresent(ArticleCategoryDO::getName, reqVO.getName())
.eqIfPresent(ArticleCategoryDO::getStatus, reqVO.getStatus())
.betweenIfPresent(ArticleCategoryDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(ArticleCategoryDO::getSort));
}
}

View File

@ -3,13 +3,10 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.article;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 文章管理 Mapper
*
@ -31,17 +28,4 @@ public interface ArticleMapper extends BaseMapperX<ArticleDO> {
.orderByDesc(ArticleDO::getId));
}
default List<ArticleDO> selectList(ArticleExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<ArticleDO>()
.eqIfPresent(ArticleDO::getCategoryId, reqVO.getCategoryId())
.eqIfPresent(ArticleDO::getTitle, reqVO.getTitle())
.eqIfPresent(ArticleDO::getAuthor, reqVO.getAuthor())
.eqIfPresent(ArticleDO::getStatus, reqVO.getStatus())
.eqIfPresent(ArticleDO::getSpuId, reqVO.getSpuId())
.eqIfPresent(ArticleDO::getRecommendHot, reqVO.getRecommendHot())
.eqIfPresent(ArticleDO::getRecommendBanner, reqVO.getRecommendBanner())
.betweenIfPresent(ArticleDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(ArticleDO::getId));
}
}

View File

@ -2,13 +2,11 @@ package cn.iocoder.yudao.module.promotion.service.article;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryUpdateReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleCategoryDO;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/**
@ -48,14 +46,6 @@ public interface ArticleCategoryService {
*/
ArticleCategoryDO getArticleCategory(Long id);
/**
* 获得文章分类列表
*
* @param ids 编号
* @return 文章分类列表
*/
List<ArticleCategoryDO> getArticleCategoryList(Collection<Long> ids);
/**
* 获得文章分类分页
*
@ -64,14 +54,6 @@ public interface ArticleCategoryService {
*/
PageResult<ArticleCategoryDO> getArticleCategoryPage(ArticleCategoryPageReqVO pageReqVO);
/**
* 获得文章分类列表, 用于 Excel 导出
*
* @param exportReqVO 查询条件
* @return 文章分类列表
*/
List<ArticleCategoryDO> getArticleCategoryList(ArticleCategoryExportReqVO exportReqVO);
/**
* 获得指定状态的文章分类列表
*

View File

@ -1,10 +1,7 @@
package cn.iocoder.yudao.module.promotion.service.article;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryUpdateReqVO;
import cn.iocoder.yudao.module.promotion.convert.article.ArticleCategoryConvert;
@ -14,7 +11,6 @@ import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -35,10 +31,10 @@ public class ArticleCategoryServiceImpl implements ArticleCategoryService {
@Override
public Long createArticleCategory(ArticleCategoryCreateReqVO createReqVO) {
// 插入
ArticleCategoryDO articleCategory = ArticleCategoryConvert.INSTANCE.convert(createReqVO);
articleCategoryMapper.insert(articleCategory);
ArticleCategoryDO category = ArticleCategoryConvert.INSTANCE.convert(createReqVO);
articleCategoryMapper.insert(category);
// 返回
return articleCategory.getId();
return category.getId();
}
@Override
@ -54,6 +50,8 @@ public class ArticleCategoryServiceImpl implements ArticleCategoryService {
public void deleteArticleCategory(Long id) {
// 校验存在
validateArticleCategoryExists(id);
// TODO @puhui999需要校验下是不是存在文章
// 删除
articleCategoryMapper.deleteById(id);
}
@ -69,24 +67,11 @@ public class ArticleCategoryServiceImpl implements ArticleCategoryService {
return articleCategoryMapper.selectById(id);
}
@Override
public List<ArticleCategoryDO> getArticleCategoryList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return ListUtil.empty();
}
return articleCategoryMapper.selectBatchIds(ids);
}
@Override
public PageResult<ArticleCategoryDO> getArticleCategoryPage(ArticleCategoryPageReqVO pageReqVO) {
return articleCategoryMapper.selectPage(pageReqVO);
}
@Override
public List<ArticleCategoryDO> getArticleCategoryList(ArticleCategoryExportReqVO exportReqVO) {
return articleCategoryMapper.selectList(exportReqVO);
}
@Override
public List<ArticleCategoryDO> getArticleCategoryListByStatus(Integer status) {
return articleCategoryMapper.selectList(ArticleCategoryDO::getStatus, status);

View File

@ -1,15 +1,12 @@
package cn.iocoder.yudao.module.promotion.service.article;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/**
* 文章管理 Service 接口
@ -48,14 +45,6 @@ public interface ArticleService {
*/
ArticleDO getArticle(Long id);
/**
* 获得文章管理列表
*
* @param ids 编号
* @return 文章管理列表
*/
List<ArticleDO> getArticleList(Collection<Long> ids);
/**
* 获得文章管理分页
*
@ -64,12 +53,4 @@ public interface ArticleService {
*/
PageResult<ArticleDO> getArticlePage(ArticlePageReqVO pageReqVO);
/**
* 获得文章管理列表, 用于 Excel 导出
*
* @param exportReqVO 查询条件
* @return 文章管理列表
*/
List<ArticleDO> getArticleList(ArticleExportReqVO exportReqVO);
}

View File

@ -1,12 +1,9 @@
package cn.iocoder.yudao.module.promotion.service.article;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.convert.article.ArticleConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.article.ArticleMapper;
@ -14,8 +11,6 @@ import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.ARTICLE_NOT_EXISTS;
@ -34,6 +29,7 @@ public class ArticleServiceImpl implements ArticleService {
@Override
public Long createArticle(ArticleCreateReqVO createReqVO) {
// TODO @puhui999需要校验分类存在
// 插入
ArticleDO article = ArticleConvert.INSTANCE.convert(createReqVO);
articleMapper.insert(article);
@ -45,6 +41,8 @@ public class ArticleServiceImpl implements ArticleService {
public void updateArticle(ArticleUpdateReqVO updateReqVO) {
// 校验存在
validateArticleExists(updateReqVO.getId());
// TODO @puhui999需要校验分类存在
// 更新
ArticleDO updateObj = ArticleConvert.INSTANCE.convert(updateReqVO);
articleMapper.updateById(updateObj);
@ -69,22 +67,9 @@ public class ArticleServiceImpl implements ArticleService {
return articleMapper.selectById(id);
}
@Override
public List<ArticleDO> getArticleList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return ListUtil.empty();
}
return articleMapper.selectBatchIds(ids);
}
@Override
public PageResult<ArticleDO> getArticlePage(ArticlePageReqVO pageReqVO) {
return articleMapper.selectPage(pageReqVO);
}
@Override
public List<ArticleDO> getArticleList(ArticleExportReqVO exportReqVO) {
return articleMapper.selectList(exportReqVO);
}
}

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.promotion.service.article;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.category.ArticleCategoryUpdateReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleCategoryDO;
@ -13,7 +12,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
@ -24,6 +22,7 @@ import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.ARTICLE_CATEGORY_NOT_EXISTS;
import static org.junit.jupiter.api.Assertions.*;
// TODO 芋艿review 单测
/**
* {@link ArticleCategoryServiceImpl} 的单元测试类
*
@ -137,39 +136,4 @@ public class ArticleCategoryServiceImplTest extends BaseDbUnitTest {
assertPojoEquals(dbArticleCategory, pageResult.getList().get(0));
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetArticleCategoryList() {
// mock 数据
ArticleCategoryDO dbArticleCategory = randomPojo(ArticleCategoryDO.class, o -> { // 等会查询到
o.setName(null);
o.setPicUrl(null);
o.setStatus(null);
o.setSort(null);
o.setCreateTime(null);
});
articleCategoryMapper.insert(dbArticleCategory);
// 测试 name 不匹配
articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setName(null)));
// 测试 picUrl 不匹配
articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setPicUrl(null)));
// 测试 status 不匹配
articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setStatus(null)));
// 测试 sort 不匹配
articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setSort(null)));
// 测试 createTime 不匹配
articleCategoryMapper.insert(cloneIgnoreId(dbArticleCategory, o -> o.setCreateTime(null)));
// 准备参数
ArticleCategoryExportReqVO reqVO = new ArticleCategoryExportReqVO();
reqVO.setName(null);
reqVO.setStatus(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
List<ArticleCategoryDO> list = articleCategoryService.getArticleCategoryList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbArticleCategory, list.get(0));
}
}

View File

@ -2,10 +2,10 @@ package cn.iocoder.yudao.module.promotion.service.article;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleExportReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticlePageReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.article.vo.article.ArticleUpdateReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.article.ArticleDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.article.ArticleMapper;
import org.junit.jupiter.api.Disabled;