fix: 子任务完成时立即发放积分到接单部门

问题:子任务完成后用户反馈没有结算积分
原因:submitCompletion方法中积分发放代码被注释掉了
修复:
- TaskItemService注入DeptMonthlyScoreService
- 子任务完成时调用addEarnedScore发放积分
- 同时判断是否延误并记录
This commit is contained in:
Your Name 2026-02-02 14:14:28 +08:00
parent 22169c73ed
commit 47f028513f

View File

@ -49,6 +49,10 @@ public class TaskItemService {
// 排队解锁服务(延迟注入避免循环依赖)
@org.springframework.beans.factory.annotation.Autowired
private TaskUnlockService taskUnlockService;
// 部门月度积分服务(用于子任务完成时发放积分)
@org.springframework.beans.factory.annotation.Autowired
private DeptMonthlyScoreService deptMonthlyScoreService;
/**
* 获取可接单的子任务列表
@ -795,8 +799,34 @@ public class TaskItemService {
log.info("子任务 {} 已完成", itemId);
// 5. 设计师立即获得积分(如果需要,可以调用积分服务)
// scoreService.addScore(userId, item.getTotalScore());
// 5. 🔥 子任务完成时立即发放积分到接单部门
if (item.getReceiverDeptId() != null && item.getTotalScore() != null
&& item.getTotalScore().compareTo(java.math.BigDecimal.ZERO) > 0) {
try {
// 计算是否延误
boolean isDelayed = false;
java.math.BigDecimal delayHours = java.math.BigDecimal.ZERO;
if (item.getDeadline() != null && item.getCompleteTime() != null
&& item.getCompleteTime().isAfter(item.getDeadline())) {
isDelayed = true;
long delayMinutes = java.time.Duration.between(item.getDeadline(), item.getCompleteTime()).toMinutes();
delayHours = java.math.BigDecimal.valueOf(delayMinutes).divide(java.math.BigDecimal.valueOf(60), 2, java.math.RoundingMode.HALF_UP);
}
// 发放积分到部门月度统计
deptMonthlyScoreService.addEarnedScore(
item.getReceiverDeptId(),
item.getTotalScore(),
isDelayed,
delayHours
);
log.info("🎉 子任务 {} 积分已发放: deptId={}, score={}, isDelayed={}, delayHours={}",
item.getItemNo(), item.getReceiverDeptId(), item.getTotalScore(), isDelayed, delayHours);
} catch (Exception e) {
log.error("子任务积分发放失败: itemId={}, error={}", itemId, e.getMessage(), e);
}
}
Map<String, Object> result = new HashMap<>();
result.put("completedItem", item);