fix: ensure department score pool uses own record and auto-create

This commit is contained in:
Your Name 2026-02-24 13:39:09 +08:00
parent c902f475c8
commit 52062b0d83
2 changed files with 20 additions and 13 deletions

View File

@ -112,7 +112,15 @@ public class DepartmentController {
@Operation(summary = "获取部门积分池详情")
@GetMapping("/{deptId}/score-pool")
public Result<TeamScorePool> getScorePool(@PathVariable Long deptId) {
return Result.success(teamScorePoolService.getByDeptId(deptId));
TeamScorePool pool = teamScorePoolService.getOwnPoolByDeptId(deptId);
if (pool == null) {
Department department = departmentService.getDepartmentById(deptId);
if (department == null) {
return Result.error("部门不存在");
}
pool = teamScorePoolService.upsertPoolForSelf(deptId, department.getDeptName());
}
return Result.success(pool);
}
@Operation(summary = "更新部门积分池自动发放配置")
@ -186,4 +194,3 @@ public class DepartmentController {
}
}

View File

@ -49,15 +49,16 @@ public class TeamScorePoolService {
// 判断是否需要向上查找父部门积分池
boolean shouldFindParent = false;
if (pool == null) {
// 情况1:当前部门没有积分池记录
shouldFindParent = true;
log.debug("部门{}没有积分池记录,尝试查找父部门积分池", deptId);
} else if (allowShareParent && isPoolEmptyAndNeverRecharged(pool)) {
// 情况2:当前部门有积分池但余额为0且从未充值(说明是系统自动创建的空记录)
shouldFindParent = true;
log.debug("部门{}的积分池余额为0且从未充值,尝试查找父部门共享积分池", deptId);
if (allowShareParent) {
if (pool == null) {
// 情况1:当前部门没有积分池记录
shouldFindParent = true;
log.debug("部门{}没有积分池记录,尝试查找父部门积分池", deptId);
} else if (isPoolEmptyAndNeverRecharged(pool)) {
// 情况2:当前部门有积分池但余额为0且从未充值(说明是系统自动创建的空记录)
shouldFindParent = true;
log.debug("部门{}的积分池余额为0且从未充值,尝试查找父部门共享积分池", deptId);
}
}
if (shouldFindParent) {
@ -292,7 +293,7 @@ public class TeamScorePoolService {
*/
@Transactional(rollbackFor = Exception.class)
public TeamScorePool upsertPool(Long deptId, String deptName) {
TeamScorePool pool = getByDeptId(deptId);
TeamScorePool pool = getOwnPoolByDeptId(deptId);
if (pool == null) {
pool = new TeamScorePool();
pool.setDeptId(deptId);
@ -472,4 +473,3 @@ public class TeamScorePoolService {
return usageRate >= threshold;
}
}