From 1380ef401ab5ddecdb1a86ab8bb10f229ceeb623 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 8 Jan 2026 13:37:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=9B=AE=E6=A0=87=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E5=8F=AA=E8=AE=BE=E7=BD=AE=E4=BA=8C=E7=BA=A7=E9=83=A8=E9=97=A8?= =?UTF-8?q?=EF=BC=8C=E4=B8=89=E7=BA=A7=E9=83=A8=E9=97=A8=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E7=BB=A7=E6=89=BF=E4=BA=8C=E7=BA=A7=E9=83=A8=E9=97=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designhub/service/AnalyticsService.java | 137 ++++++++++++------ .../service/DesignerTargetScoreService.java | 28 +++- 2 files changed, 117 insertions(+), 48 deletions(-) diff --git a/backend/src/main/java/com/designhub/service/AnalyticsService.java b/backend/src/main/java/com/designhub/service/AnalyticsService.java index bf167fe..f42d2f2 100644 --- a/backend/src/main/java/com/designhub/service/AnalyticsService.java +++ b/backend/src/main/java/com/designhub/service/AnalyticsService.java @@ -1122,7 +1122,7 @@ public class AnalyticsService { } /** - * 获取延误扣分比例 + * 获取延误扣分比例(三级部门继承二级部门的配置) * @param deptId 部门ID * @param month 月份 yyyy-MM * @return 扣分比例(默认1%) @@ -1133,28 +1133,9 @@ public class AnalyticsService { } try { - // 先查找指定月份的配置 - DesignerTargetScore config = designerTargetScoreMapper.selectOne( - new LambdaQueryWrapper() - .eq(DesignerTargetScore::getDeptId, deptId) - .isNull(DesignerTargetScore::getUserId) // 部门通用配置 - .eq(DesignerTargetScore::getEffectiveMonth, month) - ); - - if (config != null && config.getDeductionRate() != null) { - return config.getDeductionRate(); - } - - // 查找通用配置(没有指定月份的) - config = designerTargetScoreMapper.selectOne( - new LambdaQueryWrapper() - .eq(DesignerTargetScore::getDeptId, deptId) - .isNull(DesignerTargetScore::getUserId) - .isNull(DesignerTargetScore::getEffectiveMonth) - ); - - if (config != null && config.getDeductionRate() != null) { - return config.getDeductionRate(); + BigDecimal rate = findDeptDeductionRate(deptId, month); + if (rate != null) { + return rate; } } catch (Exception e) { log.warn("获取扣分比例配置失败: deptId={}, month={}", deptId, month, e); @@ -1164,7 +1145,48 @@ public class AnalyticsService { } /** - * 获取设计师目标积分 + * 递归查找部门扣分比例(向上查找父部门配置) + */ + private BigDecimal findDeptDeductionRate(Long deptId, String month) { + if (deptId == null || deptId == 0) { + return null; + } + + // 先查找指定月份的配置 + DesignerTargetScore config = designerTargetScoreMapper.selectOne( + new LambdaQueryWrapper() + .eq(DesignerTargetScore::getDeptId, deptId) + .isNull(DesignerTargetScore::getUserId) + .eq(DesignerTargetScore::getEffectiveMonth, month) + ); + + if (config != null && config.getDeductionRate() != null) { + return config.getDeductionRate(); + } + + // 查找通用配置(没有指定月份的) + config = designerTargetScoreMapper.selectOne( + new LambdaQueryWrapper() + .eq(DesignerTargetScore::getDeptId, deptId) + .isNull(DesignerTargetScore::getUserId) + .isNull(DesignerTargetScore::getEffectiveMonth) + ); + + if (config != null && config.getDeductionRate() != null) { + return config.getDeductionRate(); + } + + // 当前部门没有配置,向上查找父部门 + Department dept = departmentMapper.selectById(deptId); + if (dept != null && dept.getParentId() != null && dept.getParentId() > 0) { + return findDeptDeductionRate(dept.getParentId(), month); + } + + return null; + } + + /** + * 获取设计师目标积分(三级部门继承二级部门的目标积分) * @param userId 用户ID * @param deptId 部门ID * @param month 月份 yyyy-MM @@ -1185,29 +1207,11 @@ public class AnalyticsService { } } - // 查找部门通用配置 + // 查找部门通用配置(支持向上继承:三级部门继承二级部门的配置) if (deptId != null) { - DesignerTargetScore config = designerTargetScoreMapper.selectOne( - new LambdaQueryWrapper() - .eq(DesignerTargetScore::getDeptId, deptId) - .isNull(DesignerTargetScore::getUserId) - .eq(DesignerTargetScore::getEffectiveMonth, month) - ); - - if (config != null && config.getTargetScore() != null) { - return config.getTargetScore(); - } - - // 查找部门默认配置(没有指定月份) - config = designerTargetScoreMapper.selectOne( - new LambdaQueryWrapper() - .eq(DesignerTargetScore::getDeptId, deptId) - .isNull(DesignerTargetScore::getUserId) - .isNull(DesignerTargetScore::getEffectiveMonth) - ); - - if (config != null && config.getTargetScore() != null) { - return config.getTargetScore(); + BigDecimal targetScore = findDeptTargetScore(deptId, month); + if (targetScore != null && targetScore.compareTo(BigDecimal.ZERO) > 0) { + return targetScore; } } } catch (Exception e) { @@ -1216,5 +1220,46 @@ public class AnalyticsService { return BigDecimal.ZERO; // 默认0 } + + /** + * 递归查找部门目标积分(向上查找父部门配置) + */ + private BigDecimal findDeptTargetScore(Long deptId, String month) { + if (deptId == null || deptId == 0) { + return null; + } + + // 先查找当前部门的配置(指定月份) + DesignerTargetScore config = designerTargetScoreMapper.selectOne( + new LambdaQueryWrapper() + .eq(DesignerTargetScore::getDeptId, deptId) + .isNull(DesignerTargetScore::getUserId) + .eq(DesignerTargetScore::getEffectiveMonth, month) + ); + + if (config != null && config.getTargetScore() != null) { + return config.getTargetScore(); + } + + // 查找当前部门的默认配置(没有指定月份) + config = designerTargetScoreMapper.selectOne( + new LambdaQueryWrapper() + .eq(DesignerTargetScore::getDeptId, deptId) + .isNull(DesignerTargetScore::getUserId) + .isNull(DesignerTargetScore::getEffectiveMonth) + ); + + if (config != null && config.getTargetScore() != null) { + return config.getTargetScore(); + } + + // 当前部门没有配置,向上查找父部门 + Department dept = departmentMapper.selectById(deptId); + if (dept != null && dept.getParentId() != null && dept.getParentId() > 0) { + return findDeptTargetScore(dept.getParentId(), month); + } + + return null; + } } diff --git a/backend/src/main/java/com/designhub/service/DesignerTargetScoreService.java b/backend/src/main/java/com/designhub/service/DesignerTargetScoreService.java index 7ef9dc0..3141611 100644 --- a/backend/src/main/java/com/designhub/service/DesignerTargetScoreService.java +++ b/backend/src/main/java/com/designhub/service/DesignerTargetScoreService.java @@ -144,15 +144,39 @@ public class DesignerTargetScoreService { } /** - * 获取所有接单部门 + * 获取二级接单部门(用于目标积分配置,三级部门自动继承二级部门的目标) */ public List getReceivingDepartments() { - return departmentMapper.selectList( + // 获取所有接单部门 + List allDepts = departmentMapper.selectList( new LambdaQueryWrapper() .eq(Department::getDeptType, "receiving") .eq(Department::getStatus, 1) .orderByAsc(Department::getSortOrder) ); + + // 构建部门ID到部门的映射 + Map deptMap = allDepts.stream() + .collect(Collectors.toMap(Department::getId, d -> d)); + + // 过滤出二级部门:有父部门,且父部门是一级部门(父部门的parentId为0或null) + return allDepts.stream() + .filter(dept -> { + Long parentId = dept.getParentId(); + if (parentId == null || parentId == 0) { + // 一级部门,不选 + return false; + } + Department parent = deptMap.get(parentId); + if (parent == null) { + // 父部门不存在,可能是二级部门(父部门可能是其他类型) + // 尝试从数据库查询父部门 + parent = departmentMapper.selectById(parentId); + } + // 如果父部门存在且父部门是一级部门(parentId为0或null),则当前是二级部门 + return parent != null && (parent.getParentId() == null || parent.getParentId() == 0); + }) + .collect(Collectors.toList()); } }