fix: 修复删除任务时部门积分池不存在导致事务回滚的问题

This commit is contained in:
Your Name 2026-01-16 10:38:07 +08:00
parent c46f35cfd4
commit c1d3e72e4e

View File

@ -3388,19 +3388,24 @@ public class TaskService {
Long taskId = task.getId();
// 1. 如果任务已完成,需要回退积分
// 1. 如果任务已完成,需要回退积分(积分回退失败不影响删除)
if ("completed".equals(task.getStatus())) {
// 回退主任务积分
if (task.getReceiverDeptId() != null && task.getScoreReward() != null
&& task.getScoreReward().compareTo(BigDecimal.ZERO) > 0) {
try {
// 从团队积分池扣除已奖励的积分
teamScorePoolService.deductScore(task.getReceiverDeptId(), task.getScoreReward().intValue());
log.info("已回退主任务积分: deptId={}, score={}", task.getReceiverDeptId(), task.getScoreReward());
// 回退部门月度积分统计
deptMonthlyScoreService.deductEarnedScore(task.getReceiverDeptId(), task.getScoreReward());
log.info("已回退部门月度积分: deptId={}, score={}", task.getReceiverDeptId(), task.getScoreReward());
// 检查积分池是否存在
if (teamScorePoolService.getByDeptId(task.getReceiverDeptId()) != null) {
// 从团队积分池扣除已奖励的积分
teamScorePoolService.deductScore(task.getReceiverDeptId(), task.getScoreReward().intValue());
log.info("已回退主任务积分: deptId={}, score={}", task.getReceiverDeptId(), task.getScoreReward());
// 回退部门月度积分统计
deptMonthlyScoreService.deductEarnedScore(task.getReceiverDeptId(), task.getScoreReward());
log.info("已回退部门月度积分: deptId={}, score={}", task.getReceiverDeptId(), task.getScoreReward());
} else {
log.warn("部门积分池不存在,跳过主任务积分回退: deptId={}", task.getReceiverDeptId());
}
} catch (Exception e) {
log.warn("回退主任务积分失败: {}", e.getMessage());
}
@ -3417,13 +3422,18 @@ public class TaskService {
if ("completed".equals(item.getStatus()) && item.getReceiverDeptId() != null
&& item.getTotalScore() != null && item.getTotalScore().compareTo(BigDecimal.ZERO) > 0) {
try {
// 从团队积分池扣除已奖励的积分
teamScorePoolService.deductScore(item.getReceiverDeptId(), item.getTotalScore().intValue());
log.info("已回退子任务积分: itemNo={}, deptId={}, score={}",
item.getItemNo(), item.getReceiverDeptId(), item.getTotalScore());
// 回退部门月度积分统计
deptMonthlyScoreService.deductEarnedScore(item.getReceiverDeptId(), item.getTotalScore());
// 检查积分池是否存在
if (teamScorePoolService.getByDeptId(item.getReceiverDeptId()) != null) {
// 从团队积分池扣除已奖励的积分
teamScorePoolService.deductScore(item.getReceiverDeptId(), item.getTotalScore().intValue());
log.info("已回退子任务积分: itemNo={}, deptId={}, score={}",
item.getItemNo(), item.getReceiverDeptId(), item.getTotalScore());
// 回退部门月度积分统计
deptMonthlyScoreService.deductEarnedScore(item.getReceiverDeptId(), item.getTotalScore());
} else {
log.warn("部门积分池不存在,跳过子任务积分回退: itemNo={}, deptId={}", item.getItemNo(), item.getReceiverDeptId());
}
} catch (Exception e) {
log.warn("回退子任务积分失败: itemNo={}, error={}", item.getItemNo(), e.getMessage());
}