feat(service): 删除分组时更新相关文件
- 在删除分组前,将该分组下的所有文件移动到默认分组(ID为999) - 新增 MarkdownFileMapper 依赖,用于更新文件分组 - 使用 @Transactional 注解确保删除分组和更新文件的操作在一个事务中完成
This commit is contained in:
@@ -1,13 +1,17 @@
|
|||||||
package com.test.bijihoudaun.service.impl;
|
package com.test.bijihoudaun.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.test.bijihoudaun.entity.Grouping;
|
import com.test.bijihoudaun.entity.Grouping;
|
||||||
|
import com.test.bijihoudaun.entity.MarkdownFile;
|
||||||
import com.test.bijihoudaun.mapper.GroupingMapper;
|
import com.test.bijihoudaun.mapper.GroupingMapper;
|
||||||
|
import com.test.bijihoudaun.mapper.MarkdownFileMapper;
|
||||||
import com.test.bijihoudaun.service.GroupingService;
|
import com.test.bijihoudaun.service.GroupingService;
|
||||||
import com.test.bijihoudaun.util.SnowflakeIdGenerator;
|
import com.test.bijihoudaun.util.SnowflakeIdGenerator;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -19,6 +23,8 @@ public class GroupingServiceImpl
|
|||||||
@Resource
|
@Resource
|
||||||
private GroupingMapper groupingMapper;
|
private GroupingMapper groupingMapper;
|
||||||
@Resource
|
@Resource
|
||||||
|
private MarkdownFileMapper markdownFileMapper;
|
||||||
|
@Resource
|
||||||
private SnowflakeIdGenerator snowflakeIdGenerator;
|
private SnowflakeIdGenerator snowflakeIdGenerator;
|
||||||
|
|
||||||
|
|
||||||
@@ -46,7 +52,13 @@ public class GroupingServiceImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void deleteGrouping(Long id) {
|
public void deleteGrouping(Long id) {
|
||||||
|
LambdaUpdateWrapper<MarkdownFile> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.eq(MarkdownFile::getGroupingId, id)
|
||||||
|
.set(MarkdownFile::getGroupingId, 999L);
|
||||||
|
markdownFileMapper.update(null, updateWrapper);
|
||||||
|
|
||||||
this.removeById(id);
|
this.removeById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user