From 1f005aa1b03d7671276bfe108fc7147476079059 Mon Sep 17 00:00:00 2001 From: gxwebsoft Date: Wed, 13 Mar 2024 20:40:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=96=87=E7=AB=A0=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ArticleContentController.java | 109 ++++++++++++++++++ .../cms/controller/ArticleController.java | 15 +++ .../com/gxwebsoft/cms/entity/Article.java | 1 + .../gxwebsoft/cms/entity/ArticleContent.java | 37 ++++++ .../cms/mapper/ArticleContentMapper.java | 37 ++++++ .../cms/mapper/xml/ArticleContentMapper.xml | 35 ++++++ .../cms/param/ArticleContentParam.java | 32 +++++ .../cms/service/ArticleContentService.java | 42 +++++++ .../impl/ArticleContentServiceImpl.java | 47 ++++++++ .../cms/service/impl/ArticleServiceImpl.java | 4 +- .../oa/controller/LinkController.java | 3 +- .../com/gxwebsoft/generator/CmsGenerator.java | 3 +- 12 files changed, 360 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/gxwebsoft/cms/controller/ArticleContentController.java create mode 100644 src/main/java/com/gxwebsoft/cms/entity/ArticleContent.java create mode 100644 src/main/java/com/gxwebsoft/cms/mapper/ArticleContentMapper.java create mode 100644 src/main/java/com/gxwebsoft/cms/mapper/xml/ArticleContentMapper.xml create mode 100644 src/main/java/com/gxwebsoft/cms/param/ArticleContentParam.java create mode 100644 src/main/java/com/gxwebsoft/cms/service/ArticleContentService.java create mode 100644 src/main/java/com/gxwebsoft/cms/service/impl/ArticleContentServiceImpl.java diff --git a/src/main/java/com/gxwebsoft/cms/controller/ArticleContentController.java b/src/main/java/com/gxwebsoft/cms/controller/ArticleContentController.java new file mode 100644 index 0000000..b935dc6 --- /dev/null +++ b/src/main/java/com/gxwebsoft/cms/controller/ArticleContentController.java @@ -0,0 +1,109 @@ +package com.gxwebsoft.cms.controller; + +import com.gxwebsoft.cms.entity.ArticleContent; +import com.gxwebsoft.cms.param.ArticleContentParam; +import com.gxwebsoft.cms.service.ArticleContentService; +import com.gxwebsoft.common.core.web.*; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 文章记录表控制器 + * + * @author 科技小王子 + * @since 2024-03-13 20:28:29 + */ +@Api(tags = "文章记录表管理") +@RestController +@RequestMapping("/api/cms/article-content") +public class ArticleContentController extends BaseController { + @Resource + private ArticleContentService articleContentService; + + @ApiOperation("分页查询文章记录表") + @GetMapping("/page") + public ApiResult> page(ArticleContentParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("create_time desc"); + return success(articleContentService.page(page, page.getWrapper())); + // 使用关联查询 + //return success(articleContentService.pageRel(param)); + } + + @ApiOperation("查询全部文章记录表") + @GetMapping() + public ApiResult> list(ArticleContentParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("create_time desc"); + return success(articleContentService.list(page.getOrderWrapper())); + // 使用关联查询 + //return success(articleContentService.listRel(param)); + } + + @ApiOperation("根据id查询文章记录表") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + return success(articleContentService.getById(id)); + // 使用关联查询 + //return success(articleContentService.getByIdRel(id)); + } + + @ApiOperation("添加文章记录表") + @PostMapping() + public ApiResult save(@RequestBody ArticleContent articleContent) { + if (articleContentService.save(articleContent)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @ApiOperation("修改文章记录表") + @PutMapping() + public ApiResult update(@RequestBody ArticleContent articleContent) { + if (articleContentService.updateById(articleContent)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @ApiOperation("删除文章记录表") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (articleContentService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @ApiOperation("批量添加文章记录表") + @PostMapping("/batch") + public ApiResult saveBatch(@RequestBody List list) { + if (articleContentService.saveBatch(list)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @ApiOperation("批量修改文章记录表") + @PutMapping("/batch") + public ApiResult removeBatch(@RequestBody BatchParam batchParam) { + if (batchParam.update(articleContentService, "")) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @ApiOperation("批量删除文章记录表") + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (articleContentService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } + +} diff --git a/src/main/java/com/gxwebsoft/cms/controller/ArticleController.java b/src/main/java/com/gxwebsoft/cms/controller/ArticleController.java index 7ecf56b..cfb2c05 100644 --- a/src/main/java/com/gxwebsoft/cms/controller/ArticleController.java +++ b/src/main/java/com/gxwebsoft/cms/controller/ArticleController.java @@ -4,8 +4,10 @@ import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.gxwebsoft.cms.entity.Article; import com.gxwebsoft.cms.entity.ArticleCategory; +import com.gxwebsoft.cms.entity.ArticleContent; import com.gxwebsoft.cms.param.ArticleParam; import com.gxwebsoft.cms.service.ArticleCategoryService; +import com.gxwebsoft.cms.service.ArticleContentService; import com.gxwebsoft.cms.service.ArticleService; import com.gxwebsoft.common.core.web.*; import com.gxwebsoft.common.system.entity.User; @@ -30,6 +32,8 @@ public class ArticleController extends BaseController { private ArticleService articleService; @Resource private ArticleCategoryService articleCategoryService; + @Resource + private ArticleContentService articleContentService; @ApiOperation("分页查询文章记录表") @GetMapping("/page") @@ -53,6 +57,9 @@ public class ArticleController extends BaseController { // 更新阅读数量 article.setActualViews(article.getActualViews() + 1); articleService.updateById(article); + // 附加文字内容 + final ArticleContent content = articleContentService.getById(article.getArticleId()); + article.setContent(content.getContent()); return success(article); } @@ -94,6 +101,11 @@ public class ArticleController extends BaseController { final ArticleCategory category = articleCategoryService.getById(article.getCategoryId()); article.setType(category.getType()); if (articleService.save(article)) { + // 保存文章内容 + final ArticleContent content = new ArticleContent(); + content.setArticleId(article.getArticleId()); + content.setContent(article.getContent()); + articleContentService.save(content); return success("添加成功"); } return fail("添加失败"); @@ -105,6 +117,9 @@ public class ArticleController extends BaseController { if (articleService.updateById(article)) { article.setUpdateTime(DateUtil.date()); articleService.updateById(article); + // 更新文章内容 + ArticleContent content = articleContentService.getById(article.getArticleId()); + content.setContent(article.getContent()); return success("修改成功"); } return fail("修改失败"); diff --git a/src/main/java/com/gxwebsoft/cms/entity/Article.java b/src/main/java/com/gxwebsoft/cms/entity/Article.java index 308beeb..2e0af19 100644 --- a/src/main/java/com/gxwebsoft/cms/entity/Article.java +++ b/src/main/java/com/gxwebsoft/cms/entity/Article.java @@ -48,6 +48,7 @@ public class Article implements Serializable { private String source; @ApiModelProperty(value = "文章内容") + @TableField(exist = false) private String content; @ApiModelProperty(value = "虚拟阅读量(仅用作展示)") diff --git a/src/main/java/com/gxwebsoft/cms/entity/ArticleContent.java b/src/main/java/com/gxwebsoft/cms/entity/ArticleContent.java new file mode 100644 index 0000000..03d3a96 --- /dev/null +++ b/src/main/java/com/gxwebsoft/cms/entity/ArticleContent.java @@ -0,0 +1,37 @@ +package com.gxwebsoft.cms.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; + +/** + * 文章记录表 + * + * @author 科技小王子 + * @since 2024-03-13 20:28:29 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "ArticleContent对象", description = "文章记录表") +@TableName("cms_article_content") +public class ArticleContent implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "文章ID") + private Integer articleId; + + @ApiModelProperty(value = "文章内容") + private String content; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + + @ApiModelProperty(value = "注册时间") + private Date createTime; + +} diff --git a/src/main/java/com/gxwebsoft/cms/mapper/ArticleContentMapper.java b/src/main/java/com/gxwebsoft/cms/mapper/ArticleContentMapper.java new file mode 100644 index 0000000..448d141 --- /dev/null +++ b/src/main/java/com/gxwebsoft/cms/mapper/ArticleContentMapper.java @@ -0,0 +1,37 @@ +package com.gxwebsoft.cms.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.gxwebsoft.cms.entity.ArticleContent; +import com.gxwebsoft.cms.param.ArticleContentParam; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 文章记录表Mapper + * + * @author 科技小王子 + * @since 2024-03-13 20:28:29 + */ +public interface ArticleContentMapper extends BaseMapper { + + /** + * 分页查询 + * + * @param page 分页对象 + * @param param 查询参数 + * @return List + */ + List selectPageRel(@Param("page") IPage page, + @Param("param") ArticleContentParam param); + + /** + * 查询全部 + * + * @param param 查询参数 + * @return List + */ + List selectListRel(@Param("param") ArticleContentParam param); + +} diff --git a/src/main/java/com/gxwebsoft/cms/mapper/xml/ArticleContentMapper.xml b/src/main/java/com/gxwebsoft/cms/mapper/xml/ArticleContentMapper.xml new file mode 100644 index 0000000..3e35a2c --- /dev/null +++ b/src/main/java/com/gxwebsoft/cms/mapper/xml/ArticleContentMapper.xml @@ -0,0 +1,35 @@ + + + + + + + SELECT a.* + FROM cms_article_content a + + + AND a.article_id = #{param.articleId} + + + AND a.content LIKE CONCAT('%', #{param.content}, '%') + + + AND a.create_time >= #{param.createTimeStart} + + + AND a.create_time <= #{param.createTimeEnd} + + + + + + + + + + + diff --git a/src/main/java/com/gxwebsoft/cms/param/ArticleContentParam.java b/src/main/java/com/gxwebsoft/cms/param/ArticleContentParam.java new file mode 100644 index 0000000..80eb32d --- /dev/null +++ b/src/main/java/com/gxwebsoft/cms/param/ArticleContentParam.java @@ -0,0 +1,32 @@ +package com.gxwebsoft.cms.param; + +import com.gxwebsoft.common.core.annotation.QueryField; +import com.gxwebsoft.common.core.annotation.QueryType; +import com.gxwebsoft.common.core.web.BaseParam; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 文章记录表查询参数 + * + * @author 科技小王子 + * @since 2024-03-13 20:28:29 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(value = "ArticleContentParam对象", description = "文章记录表查询参数") +public class ArticleContentParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "文章ID") + @QueryField(type = QueryType.EQ) + private Integer articleId; + + @ApiModelProperty(value = "文章内容") + private String content; + +} diff --git a/src/main/java/com/gxwebsoft/cms/service/ArticleContentService.java b/src/main/java/com/gxwebsoft/cms/service/ArticleContentService.java new file mode 100644 index 0000000..278b0b1 --- /dev/null +++ b/src/main/java/com/gxwebsoft/cms/service/ArticleContentService.java @@ -0,0 +1,42 @@ +package com.gxwebsoft.cms.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.cms.entity.ArticleContent; +import com.gxwebsoft.cms.param.ArticleContentParam; + +import java.util.List; + +/** + * 文章记录表Service + * + * @author 科技小王子 + * @since 2024-03-13 20:28:29 + */ +public interface ArticleContentService extends IService { + + /** + * 分页关联查询 + * + * @param param 查询参数 + * @return PageResult + */ + PageResult pageRel(ArticleContentParam param); + + /** + * 关联查询全部 + * + * @param param 查询参数 + * @return List + */ + List listRel(ArticleContentParam param); + + /** + * 根据id查询 + * + * @param + * @return ArticleContent + */ + ArticleContent getByIdRel(Integer id); + +} diff --git a/src/main/java/com/gxwebsoft/cms/service/impl/ArticleContentServiceImpl.java b/src/main/java/com/gxwebsoft/cms/service/impl/ArticleContentServiceImpl.java new file mode 100644 index 0000000..58bcf09 --- /dev/null +++ b/src/main/java/com/gxwebsoft/cms/service/impl/ArticleContentServiceImpl.java @@ -0,0 +1,47 @@ +package com.gxwebsoft.cms.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gxwebsoft.cms.mapper.ArticleContentMapper; +import com.gxwebsoft.cms.service.ArticleContentService; +import com.gxwebsoft.cms.entity.ArticleContent; +import com.gxwebsoft.cms.param.ArticleContentParam; +import com.gxwebsoft.common.core.web.PageParam; +import com.gxwebsoft.common.core.web.PageResult; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 文章记录表Service实现 + * + * @author 科技小王子 + * @since 2024-03-13 20:28:29 + */ +@Service +public class ArticleContentServiceImpl extends ServiceImpl implements ArticleContentService { + + @Override + public PageResult pageRel(ArticleContentParam param) { + PageParam page = new PageParam<>(param); + //page.setDefaultOrder("create_time desc"); + List list = baseMapper.selectPageRel(page, param); + return new PageResult<>(list, page.getTotal()); + } + + @Override + public List listRel(ArticleContentParam param) { + List list = baseMapper.selectListRel(param); + // 排序 + PageParam page = new PageParam<>(); + //page.setDefaultOrder("create_time desc"); + return page.sortRecords(list); + } + + @Override + public ArticleContent getByIdRel(Integer id) { + ArticleContentParam param = new ArticleContentParam(); + param.setArticleId(id); + return param.getOne(baseMapper.selectListRel(param)); + } + +} diff --git a/src/main/java/com/gxwebsoft/cms/service/impl/ArticleServiceImpl.java b/src/main/java/com/gxwebsoft/cms/service/impl/ArticleServiceImpl.java index 9a5ec4a..fe3bf33 100644 --- a/src/main/java/com/gxwebsoft/cms/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/gxwebsoft/cms/service/impl/ArticleServiceImpl.java @@ -23,7 +23,7 @@ public class ArticleServiceImpl extends ServiceImpl impl @Override public PageResult
pageRel(ArticleParam param) { PageParam page = new PageParam<>(param); - //page.setDefaultOrder("create_time desc"); + page.setDefaultOrder("create_time desc"); List
list = baseMapper.selectPageRel(page, param); return new PageResult<>(list, page.getTotal()); } @@ -33,7 +33,7 @@ public class ArticleServiceImpl extends ServiceImpl impl List
list = baseMapper.selectListRel(param); // 排序 PageParam page = new PageParam<>(); - //page.setDefaultOrder("create_time desc"); + page.setDefaultOrder("create_time desc"); return page.sortRecords(list); } diff --git a/src/main/java/com/gxwebsoft/oa/controller/LinkController.java b/src/main/java/com/gxwebsoft/oa/controller/LinkController.java index bc37de3..fe658b0 100644 --- a/src/main/java/com/gxwebsoft/oa/controller/LinkController.java +++ b/src/main/java/com/gxwebsoft/oa/controller/LinkController.java @@ -42,9 +42,8 @@ public class LinkController extends BaseController { @ApiOperation("根据id查询常用链接") @GetMapping("/{id}") public ApiResult get(@PathVariable("id") Integer id) { - return success(linkService.getById(id)); // 使用关联查询 - //return success(linkService.getByIdRel(id)); + return success(linkService.getByIdRel(id)); } @ApiOperation("添加常用链接") diff --git a/src/test/java/com/gxwebsoft/generator/CmsGenerator.java b/src/test/java/com/gxwebsoft/generator/CmsGenerator.java index 078cf4c..fb37bbb 100644 --- a/src/test/java/com/gxwebsoft/generator/CmsGenerator.java +++ b/src/test/java/com/gxwebsoft/generator/CmsGenerator.java @@ -45,6 +45,7 @@ public class CmsGenerator { // "cms_article_category", // "cms_article_like", // "cms_article_comment", +// "cms_article_content", // "cms_docs", // "cms_ad", // "cms_ad_record", @@ -52,7 +53,7 @@ public class CmsGenerator { // "cms_design", // "cms_design_record", // "cms_website", - "cms_website_field" +// "cms_website_field", }; // 需要去除的表前缀 private static final String[] TABLE_PREFIX = new String[]{