From d6d3401bb04f29d5b0c0e6ea17b3de7fa9021c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=AD=9F?= <3111696955@qq.com> Date: Thu, 31 Jul 2025 15:41:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(service):=20=E5=88=A0=E9=99=A4=E5=88=86?= =?UTF-8?q?=E7=BB=84=E6=97=B6=E6=9B=B4=E6=96=B0=E7=9B=B8=E5=85=B3=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在删除分组前,将该分组下的所有文件移动到默认分组(ID为999) - 新增 MarkdownFileMapper 依赖,用于更新文件分组 - 使用 @Transactional 注解确保删除分组和更新文件的操作在一个事务中完成 --- .../service/impl/GroupingServiceImpl.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/biji-houdaun/src/main/java/com/test/bijihoudaun/service/impl/GroupingServiceImpl.java b/biji-houdaun/src/main/java/com/test/bijihoudaun/service/impl/GroupingServiceImpl.java index 1b7b9e1..e52f470 100644 --- a/biji-houdaun/src/main/java/com/test/bijihoudaun/service/impl/GroupingServiceImpl.java +++ b/biji-houdaun/src/main/java/com/test/bijihoudaun/service/impl/GroupingServiceImpl.java @@ -1,13 +1,17 @@ package com.test.bijihoudaun.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.test.bijihoudaun.entity.Grouping; +import com.test.bijihoudaun.entity.MarkdownFile; import com.test.bijihoudaun.mapper.GroupingMapper; +import com.test.bijihoudaun.mapper.MarkdownFileMapper; import com.test.bijihoudaun.service.GroupingService; import com.test.bijihoudaun.util.SnowflakeIdGenerator; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -19,6 +23,8 @@ public class GroupingServiceImpl @Resource private GroupingMapper groupingMapper; @Resource + private MarkdownFileMapper markdownFileMapper; + @Resource private SnowflakeIdGenerator snowflakeIdGenerator; @@ -46,7 +52,13 @@ public class GroupingServiceImpl } @Override + @Transactional public void deleteGrouping(Long id) { + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(MarkdownFile::getGroupingId, id) + .set(MarkdownFile::getGroupingId, 999L); + markdownFileMapper.update(null, updateWrapper); + this.removeById(id); }