fix: 目标积分只设置二级部门,三级部门自动继承二级部门配置
This commit is contained in:
parent
40d7633e6f
commit
1380ef401a
@ -1122,7 +1122,7 @@ public class AnalyticsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取延误扣分比例
|
* 获取延误扣分比例(三级部门继承二级部门的配置)
|
||||||
* @param deptId 部门ID
|
* @param deptId 部门ID
|
||||||
* @param month 月份 yyyy-MM
|
* @param month 月份 yyyy-MM
|
||||||
* @return 扣分比例(默认1%)
|
* @return 扣分比例(默认1%)
|
||||||
@ -1133,28 +1133,9 @@ public class AnalyticsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 先查找指定月份的配置
|
BigDecimal rate = findDeptDeductionRate(deptId, month);
|
||||||
DesignerTargetScore config = designerTargetScoreMapper.selectOne(
|
if (rate != null) {
|
||||||
new LambdaQueryWrapper<DesignerTargetScore>()
|
return rate;
|
||||||
.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<DesignerTargetScore>()
|
|
||||||
.eq(DesignerTargetScore::getDeptId, deptId)
|
|
||||||
.isNull(DesignerTargetScore::getUserId)
|
|
||||||
.isNull(DesignerTargetScore::getEffectiveMonth)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (config != null && config.getDeductionRate() != null) {
|
|
||||||
return config.getDeductionRate();
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("获取扣分比例配置失败: deptId={}, month={}", deptId, month, 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<DesignerTargetScore>()
|
||||||
|
.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<DesignerTargetScore>()
|
||||||
|
.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 userId 用户ID
|
||||||
* @param deptId 部门ID
|
* @param deptId 部门ID
|
||||||
* @param month 月份 yyyy-MM
|
* @param month 月份 yyyy-MM
|
||||||
@ -1185,29 +1207,11 @@ public class AnalyticsService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找部门通用配置
|
// 查找部门通用配置(支持向上继承:三级部门继承二级部门的配置)
|
||||||
if (deptId != null) {
|
if (deptId != null) {
|
||||||
DesignerTargetScore config = designerTargetScoreMapper.selectOne(
|
BigDecimal targetScore = findDeptTargetScore(deptId, month);
|
||||||
new LambdaQueryWrapper<DesignerTargetScore>()
|
if (targetScore != null && targetScore.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
.eq(DesignerTargetScore::getDeptId, deptId)
|
return targetScore;
|
||||||
.isNull(DesignerTargetScore::getUserId)
|
|
||||||
.eq(DesignerTargetScore::getEffectiveMonth, month)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (config != null && config.getTargetScore() != null) {
|
|
||||||
return config.getTargetScore();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查找部门默认配置(没有指定月份)
|
|
||||||
config = designerTargetScoreMapper.selectOne(
|
|
||||||
new LambdaQueryWrapper<DesignerTargetScore>()
|
|
||||||
.eq(DesignerTargetScore::getDeptId, deptId)
|
|
||||||
.isNull(DesignerTargetScore::getUserId)
|
|
||||||
.isNull(DesignerTargetScore::getEffectiveMonth)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (config != null && config.getTargetScore() != null) {
|
|
||||||
return config.getTargetScore();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -1216,5 +1220,46 @@ public class AnalyticsService {
|
|||||||
|
|
||||||
return BigDecimal.ZERO; // 默认0
|
return BigDecimal.ZERO; // 默认0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归查找部门目标积分(向上查找父部门配置)
|
||||||
|
*/
|
||||||
|
private BigDecimal findDeptTargetScore(Long deptId, String month) {
|
||||||
|
if (deptId == null || deptId == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 先查找当前部门的配置(指定月份)
|
||||||
|
DesignerTargetScore config = designerTargetScoreMapper.selectOne(
|
||||||
|
new LambdaQueryWrapper<DesignerTargetScore>()
|
||||||
|
.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<DesignerTargetScore>()
|
||||||
|
.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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -144,15 +144,39 @@ public class DesignerTargetScoreService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有接单部门
|
* 获取二级接单部门(用于目标积分配置,三级部门自动继承二级部门的目标)
|
||||||
*/
|
*/
|
||||||
public List<Department> getReceivingDepartments() {
|
public List<Department> getReceivingDepartments() {
|
||||||
return departmentMapper.selectList(
|
// 获取所有接单部门
|
||||||
|
List<Department> allDepts = departmentMapper.selectList(
|
||||||
new LambdaQueryWrapper<Department>()
|
new LambdaQueryWrapper<Department>()
|
||||||
.eq(Department::getDeptType, "receiving")
|
.eq(Department::getDeptType, "receiving")
|
||||||
.eq(Department::getStatus, 1)
|
.eq(Department::getStatus, 1)
|
||||||
.orderByAsc(Department::getSortOrder)
|
.orderByAsc(Department::getSortOrder)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 构建部门ID到部门的映射
|
||||||
|
Map<Long, Department> 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user