From a7ec38e78bfe17bc7b454cadee5d72b6fb035ca0 Mon Sep 17 00:00:00 2001 From: huangge1199 Date: Tue, 27 Aug 2024 16:03:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=9A=E5=AE=A2=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD=EF=BC=88=E6=9C=AA?= =?UTF-8?q?=E5=AE=8C=E6=88=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blog/controller/BlogPostsController.java | 116 ++++++++++++ .../com/ruoyi/blog/domain/BlogContents.java | 39 ++++ .../java/com/ruoyi/blog/domain/BlogPosts.java | 62 ++++++ .../com/ruoyi/blog/domain/bo/BlogPostsBo.java | 81 ++++++++ .../com/ruoyi/blog/domain/vo/BlogPostsVo.java | 90 +++++++++ .../ruoyi/blog/mapper/BlogContentsMapper.java | 17 ++ .../ruoyi/blog/mapper/BlogPostsMapper.java | 18 ++ .../ruoyi/blog/service/IBlogPostsService.java | 66 +++++++ .../service/impl/BlogPostsServiceImpl.java | 176 ++++++++++++++++++ .../mapper/blog/BlogContentsMapper.xml | 7 + .../resources/mapper/blog/BlogPostsMapper.xml | 7 + 11 files changed, 679 insertions(+) create mode 100644 ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/controller/BlogPostsController.java create mode 100644 ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/domain/BlogContents.java create mode 100644 ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/domain/BlogPosts.java create mode 100644 ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/domain/bo/BlogPostsBo.java create mode 100644 ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/domain/vo/BlogPostsVo.java create mode 100644 ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/mapper/BlogContentsMapper.java create mode 100644 ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/mapper/BlogPostsMapper.java create mode 100644 ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/service/IBlogPostsService.java create mode 100644 ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/service/impl/BlogPostsServiceImpl.java create mode 100644 ruoyi-modules/ruoyi-blog/src/main/resources/mapper/blog/BlogContentsMapper.xml create mode 100644 ruoyi-modules/ruoyi-blog/src/main/resources/mapper/blog/BlogPostsMapper.xml diff --git a/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/controller/BlogPostsController.java b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/controller/BlogPostsController.java new file mode 100644 index 0000000..1bed627 --- /dev/null +++ b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/controller/BlogPostsController.java @@ -0,0 +1,116 @@ +package com.ruoyi.blog.controller; + +import java.util.List; +import lombok.RequiredArgsConstructor; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.constraints.*; +import cn.dev33.satoken.annotation.SaCheckPermission; +import org.springframework.web.bind.annotation.*; +import org.springframework.validation.annotation.Validated; +import com.ruoyi.common.core.core.domain.R; +import com.ruoyi.common.excel.utils.ExcelUtil; +import com.ruoyi.common.log.annotation.Log; +import com.ruoyi.common.log.enums.BusinessType; +import com.ruoyi.common.web.annotation.RepeatSubmit; +import com.ruoyi.common.web.core.BaseController; +import jakarta.annotation.Resource; +import com.ruoyi.blog.domain.vo.BlogPostsVo; +import com.ruoyi.blog.domain.bo.BlogPostsBo; +import com.ruoyi.blog.service.IBlogPostsService; + +import com.ruoyi.common.orm.core.page.TableDataInfo; + +/** + * 博客文章Controller + * + * @author huangge1199 + * 2024-08-27 + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/blog/posts") +public class BlogPostsController extends BaseController +{ + @Resource + private IBlogPostsService blogPostsService; + + /** + * 查询博客文章列表 + */ + @SaCheckPermission("blog:posts:list") + @GetMapping("/list") + public TableDataInfo list(BlogPostsBo blogPostsBo) + { + return blogPostsService.selectPage(blogPostsBo); + } + + /** + * 导出博客文章列表 + */ + @SaCheckPermission("blog:posts:export") + @Log(title = "博客文章", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, BlogPostsBo blogPostsBo) + { + List list = blogPostsService.selectList(blogPostsBo); + ExcelUtil.exportExcel(list, "博客文章", BlogPostsVo.class, response); + } + + /** + * 获取博客文章详细信息 + */ + @SaCheckPermission("blog:posts:query") + @GetMapping(value = "/{id}") + public R getInfo(@PathVariable Long id) + { + return R.ok(blogPostsService.selectById(id)); + } + + /** + * 新增博客文章 + */ + @SaCheckPermission("blog:posts:add") + @Log(title = "博客文章", businessType = BusinessType.INSERT) + @RepeatSubmit() + @PostMapping + public R add(@Validated @RequestBody BlogPostsBo blogPostsBo) + { + boolean inserted = blogPostsService.insert(blogPostsBo); + if (!inserted) { + return R.fail("新增博客文章记录失败!"); + } + return R.ok(); + } + + /** + * 修改博客文章 + */ + @SaCheckPermission("blog:posts:edit") + @Log(title = "博客文章", businessType = BusinessType.UPDATE) + @RepeatSubmit() + @PutMapping + public R edit(@Validated @RequestBody BlogPostsBo blogPostsBo) + { + boolean updated = blogPostsService.update(blogPostsBo); + if (!updated) { + R.fail("修改博客文章记录失败!"); + } + return R.ok(); + } + + /** + * 删除博客文章 + */ + @SaCheckPermission("blog:posts:remove") + @Log(title = "博客文章", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public R remove(@PathVariable Long[] ids) + { + boolean deleted = blogPostsService.deleteByIds(ids); + if (!deleted) { + R.fail("删除博客文章记录失败!"); + } + return R.ok(); + } +} diff --git a/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/domain/BlogContents.java b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/domain/BlogContents.java new file mode 100644 index 0000000..86ffe90 --- /dev/null +++ b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/domain/BlogContents.java @@ -0,0 +1,39 @@ +package com.ruoyi.blog.domain; + +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; +import java.io.Serial; +import java.io.Serializable; +import com.ruoyi.common.orm.core.domain.BaseEntity; + +/** + * 博客文章内容对象 blog_contents + * + * @author huangge1199 + * 2024-08-27 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Table(value = "blog_contents") +public class BlogContents extends BaseEntity +{ + @Serial + private static final long serialVersionUID = 1L; + + /** */ + @Id + private Long id; + + /** 文章ID */ + private Long postId; + + /** html */ + private String content; + + /** md */ + private String originalContent; + + +} diff --git a/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/domain/BlogPosts.java b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/domain/BlogPosts.java new file mode 100644 index 0000000..e32133b --- /dev/null +++ b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/domain/BlogPosts.java @@ -0,0 +1,62 @@ +package com.ruoyi.blog.domain; + +import java.util.List; +import com.ruoyi.blog.domain.BlogContents; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; +import com.ruoyi.common.orm.core.domain.BaseEntity; + +/** + * 博客文章对象 blog_posts + * + * @author huangge1199 + * 2024-08-27 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Table(value = "blog_posts") +public class BlogPosts extends BaseEntity +{ + /** 主键 */ + @Id + private Long id; + + /** 是否可评论,0:能,1:不能 */ + private Integer disallowComment; + + /** 关键字 */ + private String keywords; + + /** 密码 */ + private String password; + + /** 固定链接地址 */ + private String slug; + + /** 类型,0:文章,1:自定义页面 */ + private Long type; + + /** 状态,0:已发布,1:草稿,2:已删除,3:私密 */ + private Long status; + + /** 总览 */ + private String summary; + + /** 标题 */ + private String title; + + /** 置顶 */ + private Long topPriority; + + /** 拜访数量 */ + private Long visits; + + /** 字数 */ + private Long wordCount; + + /** 博客文章内容信息 */ + private BlogContents blogContents; + +} diff --git a/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/domain/bo/BlogPostsBo.java b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/domain/bo/BlogPostsBo.java new file mode 100644 index 0000000..1dcde6d --- /dev/null +++ b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/domain/bo/BlogPostsBo.java @@ -0,0 +1,81 @@ +package com.ruoyi.blog.domain.bo; + +import com.ruoyi.blog.domain.BlogPosts; +import com.ruoyi.blog.domain.BlogContents; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; +import lombok.EqualsAndHashCode; +import jakarta.validation.constraints.*; +import java.util.List; +import com.ruoyi.common.orm.core.domain.BaseEntity; + +/** + * 博客文章业务对象 blog_posts + * + * @author huangge1199 + * @date 2024-08-27 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = BlogPosts.class, reverseConvertGenerate = false) +public class BlogPostsBo extends BaseEntity +{ + + /** + * 主键 + */ + @NotNull(message = "主键不能为空") + private Long id; + + /** + * 是否可评论,0:能,1:不能 + */ + private Integer disallowComment; + + /** + * 关键字 + */ + private String keywords; + + /** + * 密码 + */ + private String password; + + /** + * 固定链接地址 + */ + @NotBlank(message = "固定链接地址不能为空") + private String slug; + + /** + * 类型,0:文章,1:自定义页面 + */ + @NotNull(message = "类型,0:文章,1:自定义页面不能为空") + private Long type; + + /** + * 状态,0:已发布,1:草稿,2:已删除,3:私密 + */ + private Long status; + + /** + * 总览 + */ + private String summary; + + /** + * 标题 + */ + @NotBlank(message = "标题不能为空") + private String title; + + /** + * 置顶 + */ + private Long topPriority; + + + /** 博客文章内容信息 */ + private BlogContents blogContents; +} diff --git a/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/domain/vo/BlogPostsVo.java b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/domain/vo/BlogPostsVo.java new file mode 100644 index 0000000..b3979f8 --- /dev/null +++ b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/domain/vo/BlogPostsVo.java @@ -0,0 +1,90 @@ +package com.ruoyi.blog.domain.vo; + +import java.util.List; + +import com.mybatisflex.annotation.RelationOneToOne; +import com.ruoyi.blog.domain.BlogPosts; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import com.ruoyi.common.excel.annotation.ExcelDictFormat; +import com.ruoyi.common.excel.convert.ExcelDictConvert; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; +import lombok.EqualsAndHashCode; +import com.mybatisflex.annotation.RelationOneToMany; +import com.ruoyi.blog.domain.BlogContents; +import java.io.Serial; +import java.io.Serializable; +import java.util.Date; +import com.ruoyi.common.orm.core.domain.BaseEntity; + +/** + * 博客文章视图对象 blog_posts + * + * @author huangge1199 + * @date 2024-08-27 + */ +@Data +@ExcelIgnoreUnannotated +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = BlogPosts.class) +public class BlogPostsVo extends BaseEntity implements Serializable +{ + + @Serial + private static final long serialVersionUID = 1L; + + /** 主键 */ + @ExcelProperty(value = "主键") + private Long id; + + /** 是否可评论,0:能,1:不能 */ + @ExcelProperty(value = "是否可评论,0:能,1:不能") + private Integer disallowComment; + + /** 关键字 */ + @ExcelProperty(value = "关键字") + private String keywords; + + /** 密码 */ + @ExcelProperty(value = "密码") + private String password; + + /** 固定链接地址 */ + @ExcelProperty(value = "固定链接地址") + private String slug; + + /** 类型,0:文章,1:自定义页面 */ + @ExcelProperty(value = "类型,0:文章,1:自定义页面") + private Long type; + + /** 状态,0:已发布,1:草稿,2:已删除,3:私密 */ + @ExcelProperty(value = "状态,0:已发布,1:草稿,2:已删除,3:私密") + private Long status; + + /** 总览 */ + @ExcelProperty(value = "总览") + private String summary; + + /** 标题 */ + @ExcelProperty(value = "标题") + private String title; + + /** 置顶 */ + @ExcelProperty(value = "置顶") + private Long topPriority; + + /** 拜访数量 */ + @ExcelProperty(value = "拜访数量") + private Long visits; + + /** 字数 */ + @ExcelProperty(value = "字数") + private Long wordCount; + + + /** 博客文章内容信息 */ + @RelationOneToOne(selfField = "id", targetField = "postId") + private BlogContents blogContents; + +} diff --git a/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/mapper/BlogContentsMapper.java b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/mapper/BlogContentsMapper.java new file mode 100644 index 0000000..f0def2f --- /dev/null +++ b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/mapper/BlogContentsMapper.java @@ -0,0 +1,17 @@ +package com.ruoyi.blog.mapper; + +import com.mybatisflex.core.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import com.ruoyi.blog.domain.BlogContents; + +/** + * 博客文章内容Mapper接口 + * + * @author huangge1199 + * 2024-08-27 + */ +@Mapper +public interface BlogContentsMapper extends BaseMapper +{ + +} diff --git a/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/mapper/BlogPostsMapper.java b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/mapper/BlogPostsMapper.java new file mode 100644 index 0000000..fb8f1dc --- /dev/null +++ b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/mapper/BlogPostsMapper.java @@ -0,0 +1,18 @@ +package com.ruoyi.blog.mapper; + +import com.mybatisflex.core.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import com.ruoyi.blog.domain.BlogPosts; +import com.ruoyi.blog.domain.BlogContents; + +/** + * 博客文章Mapper接口 + * + * @author huangge1199 + * 2024-08-27 + */ +@Mapper +public interface BlogPostsMapper extends BaseMapper +{ + +} diff --git a/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/service/IBlogPostsService.java b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/service/IBlogPostsService.java new file mode 100644 index 0000000..5ce9f97 --- /dev/null +++ b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/service/IBlogPostsService.java @@ -0,0 +1,66 @@ +package com.ruoyi.blog.service; + +import java.util.List; +import com.ruoyi.blog.domain.BlogPosts; +import com.ruoyi.blog.domain.vo.BlogPostsVo; +import com.ruoyi.blog.domain.bo.BlogPostsBo; +import com.ruoyi.common.orm.core.service.IBaseService; +import com.ruoyi.common.orm.core.page.TableDataInfo; + +/** + * 博客文章Service接口 + * + * @author huangge1199 + * 2024-08-27 + */ +public interface IBlogPostsService extends IBaseService +{ + /** + * 查询博客文章 + * + * @param id 博客文章主键 + * @return 博客文章 + */ + BlogPostsVo selectById(Long id); + + /** + * 查询博客文章列表 + * + * @param blogPostsBo 博客文章Bo + * @return 博客文章集合 + */ + List selectList(BlogPostsBo blogPostsBo); + + /** + * 分页查询博客文章列表 + * + * @param blogPostsBo 博客文章Bo + * @return 分页博客文章集合 + */ + TableDataInfo selectPage(BlogPostsBo blogPostsBo); + + /** + * 新增博客文章 + * + * @param blogPostsBo 博客文章Bo + * @return 结果:true 操作成功,false 操作失败 + */ + boolean insert(BlogPostsBo blogPostsBo); + + /** + * 修改博客文章 + * + * @param blogPostsBo 博客文章Bo + * @return 结果:true 更新成功,false 更新失败 + */ + boolean update(BlogPostsBo blogPostsBo); + + /** + * 批量删除博客文章 + * + * @param ids 需要删除的博客文章主键集合 + * @return 结果:true 删除成功,false 删除失败 + */ + boolean deleteByIds(Long[] ids); + +} diff --git a/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/service/impl/BlogPostsServiceImpl.java b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/service/impl/BlogPostsServiceImpl.java new file mode 100644 index 0000000..308e276 --- /dev/null +++ b/ruoyi-modules/ruoyi-blog/src/main/java/com/ruoyi/blog/service/impl/BlogPostsServiceImpl.java @@ -0,0 +1,176 @@ +package com.ruoyi.blog.service.impl; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import cn.hutool.core.util.ObjectUtil; +import com.mybatisflex.core.paginate.Page; +import com.mybatisflex.core.query.QueryWrapper; +import com.ruoyi.common.core.utils.MapstructUtils; +import com.ruoyi.common.core.utils.StringUtils; +import com.ruoyi.common.orm.core.page.PageQuery; +import com.ruoyi.common.orm.core.page.TableDataInfo; +import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl; +import com.ruoyi.common.core.utils.DateUtils; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.Arrays; +import com.ruoyi.blog.domain.BlogContents; +import com.ruoyi.blog.mapper.BlogContentsMapper; +import static com.ruoyi.blog.domain.table.BlogContentsTableDef.BLOG_CONTENTS; +import com.ruoyi.blog.mapper.BlogPostsMapper; +import com.ruoyi.blog.domain.BlogPosts; +import com.ruoyi.blog.domain.bo.BlogPostsBo; +import com.ruoyi.blog.domain.vo.BlogPostsVo; +import com.ruoyi.blog.service.IBlogPostsService; +import static com.ruoyi.blog.domain.table.BlogPostsTableDef.BLOG_POSTS; + +/** + * 博客文章Service业务层处理 + * + * @author huangge1199 + * 2024-08-27 + */ +@Service +public class BlogPostsServiceImpl extends BaseServiceImpl implements IBlogPostsService +{ + @Resource + private BlogPostsMapper blogPostsMapper; + @Resource + private BlogContentsMapper blogContentsMapper; + + @Override + public QueryWrapper query() { + return super.query().from(BLOG_POSTS); + } + + private QueryWrapper buildQueryWrapper(BlogPostsBo blogPostsBo) { + QueryWrapper queryWrapper = super.buildBaseQueryWrapper(); + + if (StringUtils.isNotBlank(blogPostsBo.getSlug())) { + queryWrapper.and(BLOG_POSTS.SLUG.eq(blogPostsBo.getSlug())); + } + if (blogPostsBo.getType() != null) { + queryWrapper.and(BLOG_POSTS.TYPE.eq(blogPostsBo.getType())); + } + if (blogPostsBo.getStatus() != null) { + queryWrapper.and(BLOG_POSTS.STATUS.eq(blogPostsBo.getStatus())); + } + if (StringUtils.isNotBlank(blogPostsBo.getTitle())) { + queryWrapper.and(BLOG_POSTS.TITLE.eq(blogPostsBo.getTitle())); + } + + return queryWrapper; + } + + /** + * 查询博客文章 + * + * @param id 博客文章主键 + * @return 博客文章 + */ + @Override + public BlogPostsVo selectById(Long id) + { + return blogPostsMapper.selectOneWithRelationsByQueryAs(query().where(BLOG_POSTS.ID.eq(id)), BlogPostsVo.class); + + } + + /** + * 查询博客文章列表 + * + * @param blogPostsBo 博客文章Bo + * @return 博客文章集合 + */ + @Override + public List selectList(BlogPostsBo blogPostsBo) + { + QueryWrapper queryWrapper = buildQueryWrapper(blogPostsBo); + return blogPostsMapper.selectListWithRelationsByQueryAs(queryWrapper, BlogPostsVo.class); + } + + /** + * 分页查询博客文章列表 + * + * @param blogPostsBo 博客文章Bo + * @return 分页博客文章集合 + */ + @Override + public TableDataInfo selectPage(BlogPostsBo blogPostsBo) + { + QueryWrapper queryWrapper = buildQueryWrapper(blogPostsBo); + Page page = blogPostsMapper.paginateWithRelationsAs(PageQuery.build(), queryWrapper, BlogPostsVo.class); + return TableDataInfo.build(page); + } + + /** + * 新增博客文章 + * + * @param blogPostsBo 博客文章Bo + * @return 结果:true 操作成功,false 操作失败 + */ + @Transactional + @Override + public boolean insert(BlogPostsBo blogPostsBo) + { + BlogPosts blogPosts = MapstructUtils.convert(blogPostsBo, BlogPosts.class); + + boolean inserted = this.save(blogPosts); + if (inserted && ObjectUtil.isNotNull(blogPosts)) { + return insertBlogContents(blogPosts); + } + return false; + } + + /** + * 修改博客文章 + * + * @param blogPostsBo 博客文章Bo + * @return 结果:true 更新成功,false 更新失败 + */ + @Transactional + @Override + public boolean update(BlogPostsBo blogPostsBo) + { + BlogPosts blogPosts = MapstructUtils.convert(blogPostsBo, BlogPosts.class); + if(ObjectUtil.isNotNull(blogPosts) && ObjectUtil.isNotNull(blogPosts.getId())) { + boolean updated = this.updateById(blogPosts); + if (updated) { + QueryWrapper queryWrapper = QueryWrapper.create().from(BLOG_CONTENTS).where(BLOG_CONTENTS.POST_ID.eq(blogPosts.getId())); + blogContentsMapper.deleteByQuery(queryWrapper); + return insertBlogContents(blogPosts); + } + } + return false; + } + + /** + * 批量删除博客文章 + * + * @param ids 需要删除的博客文章主键集合 + * @return 结果:true 删除成功,false 删除失败 + */ + @Transactional + @Override + public boolean deleteByIds(Long[] ids) + { + QueryWrapper queryWrapper = QueryWrapper.create().from(BLOG_CONTENTS).where(BLOG_CONTENTS.POST_ID.in(Arrays.asList(ids))); + blogContentsMapper.deleteByQuery(queryWrapper); + return this.removeByIds(Arrays.asList(ids)); + } + + /** + * 新增博客文章内容信息 + * + * @param blogPosts 博客文章对象 + */ + private boolean insertBlogContents(BlogPosts blogPosts) + { + BlogContents blogContents = blogPosts.getBlogContents(); + Long id = blogPosts.getId(); + blogContents.setPostId(id); + return blogContentsMapper.insert(blogContents) > 0; + } +} diff --git a/ruoyi-modules/ruoyi-blog/src/main/resources/mapper/blog/BlogContentsMapper.xml b/ruoyi-modules/ruoyi-blog/src/main/resources/mapper/blog/BlogContentsMapper.xml new file mode 100644 index 0000000..0700b81 --- /dev/null +++ b/ruoyi-modules/ruoyi-blog/src/main/resources/mapper/blog/BlogContentsMapper.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/ruoyi-modules/ruoyi-blog/src/main/resources/mapper/blog/BlogPostsMapper.xml b/ruoyi-modules/ruoyi-blog/src/main/resources/mapper/blog/BlogPostsMapper.xml new file mode 100644 index 0000000..9e1f02e --- /dev/null +++ b/ruoyi-modules/ruoyi-blog/src/main/resources/mapper/blog/BlogPostsMapper.xml @@ -0,0 +1,7 @@ + + + + +