feat: 规则批量删除与多选操作

后端新增 DELETE /rule/batch,按 userId 校验规则归属,先清理标签关联再批量删除并返回实际删除数;前端规则管理表格增加多选列与批量删除按钮,补充三语文案;同步更新 README 中 AI 渠道推荐与图片记账说明。
This commit is contained in:
2026-09-21 20:30:45 +08:00
parent 2ade60da42
commit 09ca5b43fb
7 changed files with 100 additions and 2 deletions
@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
import cn.rosercode.finance.common.PageResult;
import cn.rosercode.finance.common.Result;
import cn.rosercode.finance.dto.BatchDeleteRequest;
import cn.rosercode.finance.dto.RuleQuery;
import cn.rosercode.finance.dto.RuleRequest;
import cn.rosercode.finance.service.RuleService;
@@ -111,6 +112,19 @@ public class RuleController {
return Result.success();
}
/**
* 批量删除规则
*
* @param body 批量删除请求(规则ID列表)
* @return 实际删除的规则数
*/
@DeleteMapping("/batch")
@Operation(summary = "批量删除规则", description = "根据规则ID列表批量删除当前用户的规则及其标签关联")
public Result<Integer> batchDelete(@RequestBody @Valid BatchDeleteRequest body) {
Long userId = UserContext.getUserId();
return Result.success(ruleService.batchDelete(userId, body.getIds()));
}
/**
* 启用或停用规则
*
@@ -56,6 +56,17 @@ public interface RuleService {
*/
void delete(Long userId, Long id);
/**
* 批量删除规则及其标签关联。
*
* <p>仅删除归属当前用户的规则,先清理标签关联再批量删除,返回实际删除数。</p>
*
* @param userId 当前用户ID
* @param ids 待删除的规则ID列表
* @return 实际删除的规则数
*/
int batchDelete(Long userId, List<Long> ids);
/**
* 启用或停用规则。
*
@@ -195,6 +195,36 @@ public class RuleServiceImpl implements RuleService {
log.info("删除规则: userId={}, id={}", userId, id);
}
/**
* {@inheritDoc}
*
* 仅删除归属当前用户的规则,先清理标签关联再批量删除,返回实际删除数。
*/
@Override
@Transactional
public int batchDelete(Long userId, List<Long> ids) {
if (ids == null || ids.isEmpty()) {
return 0;
}
// 仅保留属于当前用户的规则ID
List<Long> ownedIds = ruleMapper.selectList(new LambdaQueryWrapper<Rule>()
.select(Rule::getId)
.eq(Rule::getUserId, userId)
.in(Rule::getId, ids))
.stream()
.map(Rule::getId)
.collect(Collectors.toList());
if (ownedIds.isEmpty()) {
return 0;
}
// 先清理标签关联,再批量删除规则
ruleTagMapper.delete(new LambdaQueryWrapper<RuleTag>()
.in(RuleTag::getRuleId, ownedIds));
int deleted = ruleMapper.deleteByIds(ownedIds);
log.info("批量删除规则: userId={}, 请求={}, 实际={}", userId, ids.size(), deleted);
return deleted;
}
/**
* {@inheritDoc}
*/