Commit 12f7b3902ffbbe17134ce4895213df624b707d06
1 parent
82284f2e
feature(*): 通过角色授权计算绩效
通过角色授权计算绩效
Showing
16 changed files
with
369 additions
and
21 deletions
doc/2023-05-18_update.sql
... | ... | @@ -2,6 +2,9 @@ |
2 | 2 | ALTER TABLE `fw_morax`.`indicators` |
3 | 3 | ADD COLUMN `business_unit` varchar(255) NULL DEFAULT "%" COMMENT '业务报表单位' AFTER `report_path`; |
4 | 4 | |
5 | +ALTER TABLE `fw_morax`.`kpi_pool` | |
6 | + ADD COLUMN `calc_kpi_group_indicator_ids` varchar(4048) NULL COMMENT '计算的绩效指标id' AFTER `star_attachment`; | |
7 | + | |
5 | 8 | -- 2024年3月18日 |
6 | 9 | ALTER TABLE `fw_morax`.`indicator_user_target_value` |
7 | 10 | MODIFY COLUMN `origin_value` decimal(14, 4) NULL DEFAULT NULL COMMENT '原始数据' AFTER `target_type`, | ... | ... |
fw-morax-common/src/main/java/cn/fw/morax/common/constant/Constant.java
... | ... | @@ -3,6 +3,7 @@ package cn.fw.morax.common.constant; |
3 | 3 | import org.apache.commons.collections4.map.LinkedMap; |
4 | 4 | |
5 | 5 | import java.math.BigDecimal; |
6 | +import java.time.YearMonth; | |
6 | 7 | import java.util.LinkedList; |
7 | 8 | |
8 | 9 | public class Constant { |
... | ... | @@ -186,4 +187,9 @@ public class Constant { |
186 | 187 | * 整月天数 |
187 | 188 | */ |
188 | 189 | public final static Integer WHOLE_MONTH_DAY = 31; |
190 | + | |
191 | + /** | |
192 | + * 检查是否有指标角色开始月份 | |
193 | + */ | |
194 | + public final static YearMonth CHECK_HAS_INDICATOR_ROLE_START_MONTH = YearMonth.of(2024, 3); | |
189 | 195 | } | ... | ... |
fw-morax-dao/src/main/java/cn/fw/morax/dao/UserRoleAuthLogDao.java
0 → 100644
1 | +package cn.fw.morax.dao; | |
2 | + | |
3 | +import cn.fw.morax.dao.orm.LocalMapper; | |
4 | +import cn.fw.morax.domain.db.UserRoleAuthLog; | |
5 | +import org.springframework.stereotype.Repository; | |
6 | + | |
7 | +/** | |
8 | + * 用户角色授权记录 | |
9 | + */ | |
10 | +@Repository | |
11 | +public interface UserRoleAuthLogDao extends LocalMapper<UserRoleAuthLog> { | |
12 | + | |
13 | + | |
14 | +} | ... | ... |
fw-morax-domain/src/main/java/cn/fw/morax/domain/bo/kpi/KpiIndicatorBO.java
... | ... | @@ -6,6 +6,7 @@ import cn.fw.morax.domain.enums.ScoreWayEnum; |
6 | 6 | import lombok.*; |
7 | 7 | |
8 | 8 | import java.util.List; |
9 | +import java.util.Set; | |
9 | 10 | |
10 | 11 | /** |
11 | 12 | * @author : kurisu |
... | ... | @@ -63,4 +64,19 @@ public class KpiIndicatorBO { |
63 | 64 | * 参数(绩效台阶参数,提成参数 目前只能设置一个,所以不区分 提成参数、台阶参数) |
64 | 65 | */ |
65 | 66 | private List<KpiGroupIndicatorParam> params; |
67 | + | |
68 | + /** | |
69 | + * 指标角色编码 | |
70 | + */ | |
71 | + private Set<String> indicatorRoleCodes; | |
72 | + | |
73 | + /** | |
74 | + * 是否检查角色编码 | |
75 | + */ | |
76 | + private Boolean checkHasIndicatorRole; | |
77 | + | |
78 | + /** | |
79 | + * 角色授权人员 | |
80 | + */ | |
81 | + private Set<Long> roleAuthUserIds; | |
66 | 82 | } | ... | ... |
fw-morax-domain/src/main/java/cn/fw/morax/domain/db/UserRoleAuthLog.java
0 → 100644
1 | +package cn.fw.morax.domain.db; | |
2 | + | |
3 | +import cn.fw.common.data.entity.BaseAuditableTimeEntity; | |
4 | +import com.baomidou.mybatisplus.annotation.TableLogic; | |
5 | +import com.baomidou.mybatisplus.annotation.TableName; | |
6 | +import lombok.Data; | |
7 | +import lombok.EqualsAndHashCode; | |
8 | +import lombok.experimental.Accessors; | |
9 | + | |
10 | +import java.io.Serializable; | |
11 | +import java.time.LocalDate; | |
12 | +import java.time.LocalDateTime; | |
13 | + | |
14 | +/** | |
15 | + * <p> | |
16 | + * 用户角色授权记录 | |
17 | + * </p> | |
18 | + * | |
19 | + * @author jiangchao | |
20 | + * @since 2024-03-20 | |
21 | + */ | |
22 | +@Data | |
23 | +@EqualsAndHashCode(callSuper = false) | |
24 | +@Accessors(chain = true) | |
25 | +@TableName(autoResultMap = true) | |
26 | +public class UserRoleAuthLog extends BaseAuditableTimeEntity<UserRoleAuthLog, Long> { | |
27 | + | |
28 | + private static final long serialVersionUID = 1L; | |
29 | + | |
30 | + /** | |
31 | + * 用户id | |
32 | + */ | |
33 | + private Long userId; | |
34 | + | |
35 | + /** | |
36 | + * 用户名称 | |
37 | + */ | |
38 | + private String userName; | |
39 | + | |
40 | + /** | |
41 | + * 在职门店 | |
42 | + */ | |
43 | + private Long shopId; | |
44 | + | |
45 | + /** | |
46 | + * 在职门店名称 | |
47 | + */ | |
48 | + private String shopName; | |
49 | + | |
50 | + /** | |
51 | + * 数据开始日期 | |
52 | + */ | |
53 | + private LocalDate beginDate; | |
54 | + | |
55 | + /** | |
56 | + * 数据结束日期 | |
57 | + */ | |
58 | + private LocalDate endDate; | |
59 | + | |
60 | + /** | |
61 | + * 适用角色码 | |
62 | + */ | |
63 | + private String roleCode; | |
64 | + | |
65 | + /** | |
66 | + * 适用角色名称 | |
67 | + */ | |
68 | + private String roleName; | |
69 | + | |
70 | + /** | |
71 | + * 集团id | |
72 | + */ | |
73 | + private Long groupId; | |
74 | + | |
75 | + /** | |
76 | + * 逻辑删除 | |
77 | + */ | |
78 | + @TableLogic | |
79 | + private Boolean yn; | |
80 | + | |
81 | + | |
82 | +} | ... | ... |
fw-morax-domain/src/main/java/cn/fw/morax/domain/db/kpi/KpiPool.java
1 | 1 | package cn.fw.morax.domain.db.kpi; |
2 | 2 | |
3 | 3 | import cn.fw.common.data.entity.BaseAuditableTimeEntity; |
4 | +import cn.fw.common.data.mybatis.handler.LongListTypeHandler; | |
4 | 5 | import cn.fw.morax.domain.enums.KpiPoolChargeRecordEnum; |
5 | 6 | import cn.fw.morax.domain.enums.KpiPoolStatusEnum; |
6 | 7 | import cn.fw.morax.domain.enums.SalaryStaffStatusEnum; |
... | ... | @@ -14,6 +15,7 @@ import java.math.BigDecimal; |
14 | 15 | import java.time.LocalDate; |
15 | 16 | import java.time.YearMonth; |
16 | 17 | import java.util.LinkedHashMap; |
18 | +import java.util.List; | |
17 | 19 | |
18 | 20 | /** |
19 | 21 | * @author : kurisu |
... | ... | @@ -144,6 +146,13 @@ public class KpiPool extends BaseAuditableTimeEntity<KpiPool, Long> { |
144 | 146 | * 绩效平均得分率版本号(相同版号的绩效池一起计算平均得分率) |
145 | 147 | */ |
146 | 148 | private Integer ratioVersion; |
149 | + | |
150 | + /** | |
151 | + * 计算的绩效指标id | |
152 | + */ | |
153 | + @TableField(typeHandler = LongListTypeHandler.class) | |
154 | + private List<Long> calcKpiGroupIndicatorIds; | |
155 | + | |
147 | 156 | /** |
148 | 157 | * 排名-周期-根据 平均绩效得分率averageKpiScoreRatio算的 |
149 | 158 | */ | ... | ... |
fw-morax-rpc/src/main/java/cn/fw/morax/rpc/erp/ErpRpcService.java
... | ... | @@ -377,7 +377,7 @@ public class ErpRpcService { |
377 | 377 | } |
378 | 378 | try { |
379 | 379 | Message<List<ManagerVo>> message = managerApi.getRealTimeShopManager(shopIdList, needManageScope); |
380 | - log.info("实时获取管理层 managerApi.getRealTimeShopManager 传入参数:{}", shopIdList); | |
380 | + log.info("实时获取管理层 managerApi.getRealTimeShopManager 传入参数:{} 返回结果:{}", shopIdList, JSON.toJSONString(message)); | |
381 | 381 | if (message.isSuccess() && !Objects.isNull(message.getData())) { |
382 | 382 | return message.getData(); |
383 | 383 | } |
... | ... | @@ -483,8 +483,9 @@ public class ErpRpcService { |
483 | 483 | roleRangeDto.setStartTime(startTime); |
484 | 484 | roleRangeDto.setEndTime(endTime); |
485 | 485 | |
486 | + //授权结束时间是 2099年 | |
486 | 487 | Message<List<HAuthRange>> message = hUserRoleApi.queryRBatchRangeUserRoleList(roleRangeDto); |
487 | - log.info("查询角色历史授权 hUserRoleApi.queryRBatchRangeUserRoleList 传入参数:{}", JSON.toJSONString(roleRangeDto)); | |
488 | + log.info("查询角色历史授权 hUserRoleApi.queryRBatchRangeUserRoleList 传入参数:{} 返回结果:{}", JSON.toJSONString(roleRangeDto), JSON.toJSONString(message)); | |
488 | 489 | if (message.isSuccess() && !Objects.isNull(message.getData())) { |
489 | 490 | return PublicUtil.copyList(message.getData(), HRoleAuthRangeVO.class); |
490 | 491 | } | ... | ... |
fw-morax-server/src/main/java/cn/fw/morax/server/controller/erp/KpiTaskController.java
... | ... | @@ -190,6 +190,17 @@ public class KpiTaskController { |
190 | 190 | return success(); |
191 | 191 | } |
192 | 192 | |
193 | + @GetMapping("/extract/user-role-auth") | |
194 | + @ControllerMethod("保存绩效排名组下员工角色授权信息") | |
195 | + public Message<Void> extractKpiUser(Long kpiGroupRankId, Date date) { | |
196 | + if (PublicUtil.isEmpty(date)) { | |
197 | + kpiGroupUserTaskService.saveUserRoleAuthLogsForDebug(kpiGroupRankId, LocalDate.now().minusDays(1L)); | |
198 | + } else { | |
199 | + kpiGroupUserTaskService.saveUserRoleAuthLogsForDebug(kpiGroupRankId, DateUtil.date2LocalDate(date)); | |
200 | + } | |
201 | + return success(); | |
202 | + } | |
203 | + | |
193 | 204 | @GetMapping("/calculate-kpi") |
194 | 205 | @ControllerMethod("计算绩效得分") |
195 | 206 | public Message<Void> calculateKpi() { | ... | ... |
fw-morax-service/src/main/java/cn/fw/morax/service/biz/CommonService.java
... | ... | @@ -1854,6 +1854,39 @@ public class CommonService { |
1854 | 1854 | return shopIds; |
1855 | 1855 | } |
1856 | 1856 | |
1857 | + public Set<String> getIndicatorRoleCodes(Set<String> indicatorCodes) { | |
1858 | + if (PublicUtil.isEmpty(indicatorCodes)) { | |
1859 | + return new HashSet<>(); | |
1860 | + } | |
1861 | + //指标角色编码(指标自定义角色) | |
1862 | + List<Indicators> indicators = indicatorsService.list(Wrappers.<Indicators>lambdaQuery() | |
1863 | + .in(Indicators::getIndicatorCode, indicatorCodes) | |
1864 | + .eq(Indicators::getRoleType, ApplicableRoleEnum.PORTION) | |
1865 | + .eq(Indicators::getYn, Boolean.TRUE) | |
1866 | + ); | |
1867 | + if (PublicUtil.isEmpty(indicators)) { | |
1868 | + return new HashSet<>(); | |
1869 | + } | |
1870 | + Set<String> indicatorRoleCodes = indicators.stream().flatMap(data -> data.getRoleCodes().stream()).collect(Collectors.toSet()); | |
1871 | + //添加原始指标角色 | |
1872 | + Set<String> originIndicatorCodes = indicators.stream() | |
1873 | + .filter(indicator -> PublicUtil.isNotEmpty(indicator.getOriginIndicatorCode())) | |
1874 | + .map(Indicators::getOriginIndicatorCode).collect(Collectors.toSet()); | |
1875 | + if (PublicUtil.isNotEmpty(originIndicatorCodes)) { | |
1876 | + List<Indicators> originIndicators = indicatorsService.list(Wrappers.<Indicators>lambdaQuery() | |
1877 | + .in(Indicators::getIndicatorCode, originIndicatorCodes) | |
1878 | + .eq(Indicators::getRoleType, ApplicableRoleEnum.PORTION) | |
1879 | + .eq(Indicators::getYn, Boolean.TRUE) | |
1880 | + ); | |
1881 | + for (Indicators originIndicator : Optional.ofNullable(originIndicators).orElse(new ArrayList<>())) { | |
1882 | + if (PublicUtil.isNotEmpty(originIndicator.getRoleCodes())) { | |
1883 | + indicatorRoleCodes.addAll(originIndicator.getRoleCodes()); | |
1884 | + } | |
1885 | + } | |
1886 | + } | |
1887 | + return indicatorRoleCodes; | |
1888 | + } | |
1889 | + | |
1857 | 1890 | /** |
1858 | 1891 | * 查询指标值 不包含绩效得分率、考评得分率 |
1859 | 1892 | * | ... | ... |
fw-morax-service/src/main/java/cn/fw/morax/service/biz/kpi/KpiCalculateAssessService.java
... | ... | @@ -846,6 +846,9 @@ public class KpiCalculateAssessService { |
846 | 846 | } |
847 | 847 | } |
848 | 848 | } |
849 | + if (PublicUtil.isEmpty(calKpiGroupIds)) { | |
850 | + return null; | |
851 | + } | |
849 | 852 | List<KpiGroup> kpiGroups = kpiGroupService.listByIds(calKpiGroupIds); |
850 | 853 | //根据排名组对应绩效组ids 获取参与排名数据人数 |
851 | 854 | BigDecimal rateRank = kpiAssess.getRank().divide(BigDecimal.valueOf(100)); | ... | ... |
fw-morax-service/src/main/java/cn/fw/morax/service/biz/kpi/KpiCalculateService.java
... | ... | @@ -8,10 +8,13 @@ import cn.fw.morax.common.utils.PublicUtil; |
8 | 8 | import cn.fw.morax.common.utils.ThreadPoolUtil; |
9 | 9 | import cn.fw.morax.domain.bo.kpi.KpiGroupCalculableBO; |
10 | 10 | import cn.fw.morax.domain.bo.kpi.KpiIndicatorBO; |
11 | +import cn.fw.morax.domain.db.UserRoleAuthLog; | |
11 | 12 | import cn.fw.morax.domain.db.kpi.*; |
12 | 13 | import cn.fw.morax.domain.enums.*; |
14 | +import cn.fw.morax.service.biz.CommonService; | |
13 | 15 | import cn.fw.morax.service.biz.calculator.kpi.KpiAbsBaseCalculator; |
14 | 16 | import cn.fw.morax.service.data.CombineIndicatorParamService; |
17 | +import cn.fw.morax.service.data.UserRoleAuthLogService; | |
15 | 18 | import cn.fw.morax.service.data.kpi.*; |
16 | 19 | import com.alibaba.fastjson.JSON; |
17 | 20 | import com.alibaba.fastjson.JSONObject; |
... | ... | @@ -58,18 +61,21 @@ public class KpiCalculateService { |
58 | 61 | private final CombineIndicatorParamService combineIndicatorParamService; |
59 | 62 | private final PlatformTransactionManager platformTransactionManager; |
60 | 63 | private final KpiGroupIndicatorService kpiGroupIndicatorService; |
64 | + private final UserRoleAuthLogService userRoleAuthLogService; | |
61 | 65 | private final TransactionDefinition transactionDefinition; |
62 | 66 | private final KpiRewardPointService kpiRewardPointService; |
63 | 67 | private final KpiPoolCommonService kpiPoolCommonService; |
64 | 68 | private final KpiGroupUserService kpiGroupUserService; |
65 | 69 | private final StringRedisTemplate stringRedisTemplate; |
66 | 70 | private final KpiStarRuleService kpiStarRuleService; |
71 | + private final IndicatorsService indicatorsService; | |
67 | 72 | private final KpiGroupRankService kpiGroupRankService; |
68 | 73 | private final KpiAssessService kpiAssessService; |
69 | 74 | private final KpiGroupService kpiGroupService; |
70 | 75 | private final KpiCacheService kpiCacheService; |
71 | 76 | private final KpiCalcService kpiCalcService; |
72 | 77 | private final KpiPoolService kpiPoolService; |
78 | + private final CommonService commonService; | |
73 | 79 | private final KpiVal kpiVal; |
74 | 80 | @Autowired |
75 | 81 | public KpiCalculateService(final KpiGroupService kpiGroupService, |
... | ... | @@ -86,11 +92,14 @@ public class KpiCalculateService { |
86 | 92 | final KpiStarRuleService kpiStarRuleService, |
87 | 93 | final KpiCacheService kpiCacheService, |
88 | 94 | final KpiVal kpiVal, |
95 | + final CommonService commonService, | |
89 | 96 | final List<KpiAbsBaseCalculator> kpiCalculatorList, |
90 | 97 | final CombineIndicatorParamService combineIndicatorParamService, |
91 | 98 | final TransactionDefinition transactionDefinition, |
92 | 99 | final PlatformTransactionManager platformTransactionManager, |
93 | 100 | final KpiGroupIndicatorPreconditionService kpiGroupIndicatorPreconditionService, |
101 | + final IndicatorsService indicatorsService, | |
102 | + final UserRoleAuthLogService userRoleAuthLogService, | |
94 | 103 | final KpiGroupIndicatorParamService kpiGroupIndicatorParamService |
95 | 104 | ) { |
96 | 105 | this.kpiGroupService = kpiGroupService; |
... | ... | @@ -110,6 +119,9 @@ public class KpiCalculateService { |
110 | 119 | this.kpiCacheService = kpiCacheService; |
111 | 120 | this.kpiCalcService = kpiCalcService; |
112 | 121 | this.kpiVal = kpiVal; |
122 | + this.commonService = commonService; | |
123 | + this.indicatorsService = indicatorsService; | |
124 | + this.userRoleAuthLogService = userRoleAuthLogService; | |
113 | 125 | this.platformTransactionManager = platformTransactionManager; |
114 | 126 | this.kpiGroupIndicatorPreconditionService = kpiGroupIndicatorPreconditionService; |
115 | 127 | this.kpiGroupIndicatorParamService = kpiGroupIndicatorParamService; |
... | ... | @@ -196,7 +208,7 @@ public class KpiCalculateService { |
196 | 208 | log.error("绩效组[{}]人员为空,终止计算!", kpiGroupId); |
197 | 209 | return; |
198 | 210 | } |
199 | - final Set<KpiIndicatorBO> kpiIndicatorBos = this.getKpiCalcIndicator(kpiGroupId, calcDate); | |
211 | + final Set<KpiIndicatorBO> kpiIndicatorBos = this.getKpiCalcIndicator(kpiGroupId, calcDate, users); | |
200 | 212 | for (KpiGroupUser user : users) { |
201 | 213 | this.calcUserKpi(user, kpiIndicatorBos); |
202 | 214 | } |
... | ... | @@ -224,8 +236,18 @@ public class KpiCalculateService { |
224 | 236 | // if (CollectionUtils.isEmpty(indicatorSet)) { |
225 | 237 | // return; |
226 | 238 | // } |
239 | + List<Long> calcKpiGroupIndicatorIds = new ArrayList<>(); | |
227 | 240 | List<KpiPoolIndicatorValue> poolIndicatorValueList = new ArrayList<>(); |
228 | 241 | for (KpiIndicatorBO kpiIndicatorBO : kpiIndicatorBos) { |
242 | + //2024年3月开始检查 指标是否需要判断授权 | |
243 | + if (kpiPool.getMonthly().compareTo(Constant.CHECK_HAS_INDICATOR_ROLE_START_MONTH) >= 0 && Boolean.TRUE.equals(kpiIndicatorBO.getCheckHasIndicatorRole())) { | |
244 | + //员工是否有指标角色授权,有才进行考核,没有跳过不考核 | |
245 | + if (! kpiIndicatorBO.getRoleAuthUserIds().contains(user.getUserId())) { | |
246 | + log.info("用户没有角色授权记录:{}", JSON.toJSONString(user)); | |
247 | + continue; | |
248 | + } | |
249 | + } | |
250 | + calcKpiGroupIndicatorIds.add(kpiIndicatorBO.getKpiGroupIndicatorId()); | |
229 | 251 | KpiAbsBaseCalculator calculator = calculatorMap.get(kpiIndicatorBO.getScoreWay()); |
230 | 252 | if (calculator == null) { |
231 | 253 | continue; |
... | ... | @@ -256,6 +278,7 @@ public class KpiCalculateService { |
256 | 278 | totalScore = totalScore.add(indicatorValue.getIndicatorScore()); |
257 | 279 | } |
258 | 280 | calcTotalScore(totalScore, kpiPool, user.getDataDate()); |
281 | + kpiPool.setCalcKpiGroupIndicatorIds(calcKpiGroupIndicatorIds); | |
259 | 282 | kpiPoolService.updateById(kpiPool); |
260 | 283 | } |
261 | 284 | |
... | ... | @@ -461,7 +484,7 @@ public class KpiCalculateService { |
461 | 484 | /** |
462 | 485 | * 获取绩效计算的指标 |
463 | 486 | */ |
464 | - public Set<KpiIndicatorBO> getKpiCalcIndicator(Long kpiGroupId, LocalDate calcDate) { | |
487 | + public Set<KpiIndicatorBO> getKpiCalcIndicator(Long kpiGroupId, LocalDate calcDate, List<KpiGroupUser> users) { | |
465 | 488 | final Set<KpiIndicatorBO> kpiIndicatorBos = kpiGroupIndicatorService.allIndicators(DateUtil.localDate2Date(calcDate), kpiGroupId); |
466 | 489 | for (KpiIndicatorBO kpiIndicatorBO : kpiIndicatorBos) { |
467 | 490 | final Long kpiGroupIndicatorId = kpiIndicatorBO.getKpiGroupIndicatorId(); |
... | ... | @@ -481,6 +504,28 @@ public class KpiCalculateService { |
481 | 504 | .eq(KpiGroupIndicatorParam::getYn, Boolean.TRUE) |
482 | 505 | ); |
483 | 506 | kpiIndicatorBO.setParams(Optional.ofNullable(params).orElse(new ArrayList<>())); |
507 | + | |
508 | + //指标角色编码(指标自定义角色) | |
509 | + Set<String> indicatorCodes = params.stream().map(KpiGroupIndicatorParam::getIndicatorCode).collect(Collectors.toSet()); | |
510 | + Set<String> indicatorRoleCodes = commonService.getIndicatorRoleCodes(indicatorCodes); | |
511 | + kpiIndicatorBO.setIndicatorRoleCodes(indicatorRoleCodes); | |
512 | + kpiIndicatorBO.setCheckHasIndicatorRole(Boolean.FALSE); | |
513 | + | |
514 | + if (PublicUtil.isNotEmpty(indicatorRoleCodes)) { | |
515 | + kpiIndicatorBO.setCheckHasIndicatorRole(Boolean.TRUE); | |
516 | + Set<Long> kpiGroupUserIds = users.stream().map(KpiGroupUser::getUserId).collect(Collectors.toSet()); | |
517 | + //角色授权记录 | |
518 | + List<UserRoleAuthLog> userRoleAuthLogs = userRoleAuthLogService.list(Wrappers.<UserRoleAuthLog>lambdaQuery() | |
519 | + .in(UserRoleAuthLog::getUserId, kpiGroupUserIds) | |
520 | + .le(UserRoleAuthLog::getBeginDate, calcDate) | |
521 | + .ge(UserRoleAuthLog::getEndDate, calcDate) | |
522 | + .in(UserRoleAuthLog::getRoleCode, indicatorRoleCodes) | |
523 | + .eq(UserRoleAuthLog::getYn, Boolean.TRUE) | |
524 | + ); | |
525 | + Set<Long> hasRoleUserIds = userRoleAuthLogs.stream().map(UserRoleAuthLog::getUserId).collect(Collectors.toSet()); | |
526 | + kpiIndicatorBO.setRoleAuthUserIds(hasRoleUserIds); | |
527 | + } | |
528 | + | |
484 | 529 | } |
485 | 530 | return kpiIndicatorBos; |
486 | 531 | } | ... | ... |
fw-morax-service/src/main/java/cn/fw/morax/service/biz/kpi/KpiGroupUserTaskService.java
... | ... | @@ -6,13 +6,18 @@ import cn.fw.morax.common.constant.Constant; |
6 | 6 | import cn.fw.morax.common.utils.DateUtil; |
7 | 7 | import cn.fw.morax.common.utils.PublicUtil; |
8 | 8 | import cn.fw.morax.domain.bo.kpi.KpiExtractUserBO; |
9 | -import cn.fw.morax.domain.db.kpi.KpiGroup; | |
10 | -import cn.fw.morax.domain.db.kpi.KpiGroupRank; | |
11 | -import cn.fw.morax.domain.db.kpi.KpiGroupUser; | |
12 | -import cn.fw.morax.service.data.kpi.KpiCalcService; | |
13 | -import cn.fw.morax.service.data.kpi.KpiGroupRankService; | |
14 | -import cn.fw.morax.service.data.kpi.KpiGroupService; | |
15 | -import cn.fw.morax.service.data.kpi.KpiGroupUserService; | |
9 | +import cn.fw.morax.domain.db.UserRoleAuthLog; | |
10 | +import cn.fw.morax.domain.db.kpi.*; | |
11 | +import cn.fw.morax.domain.enums.ApplicableRoleEnum; | |
12 | +import cn.fw.morax.domain.enums.IndicatorCodeTypeEnum; | |
13 | +import cn.fw.morax.rpc.ehr.EhrRpcService; | |
14 | +import cn.fw.morax.rpc.erp.ErpRpcService; | |
15 | +import cn.fw.morax.rpc.erp.dto.HRoleAuthRangeVO; | |
16 | +import cn.fw.morax.rpc.oop.OopRpcService; | |
17 | +import cn.fw.morax.rpc.oop.dto.ShopDTO; | |
18 | +import cn.fw.morax.service.biz.CommonService; | |
19 | +import cn.fw.morax.service.data.UserRoleAuthLogService; | |
20 | +import cn.fw.morax.service.data.kpi.*; | |
16 | 21 | import cn.hutool.core.date.StopWatch; |
17 | 22 | import com.alibaba.fastjson.JSON; |
18 | 23 | import com.alibaba.fastjson.JSONObject; |
... | ... | @@ -50,17 +55,24 @@ import java.util.stream.Collectors; |
50 | 55 | @RequiredArgsConstructor |
51 | 56 | public class KpiGroupUserTaskService { |
52 | 57 | |
58 | + private final KpiGroupIndicatorParamService kpiGroupIndicatorParamService; | |
59 | + private final PlatformTransactionManager platformTransactionManager; | |
60 | + private final KpiGroupIndicatorService kpiGroupIndicatorService; | |
61 | + private final UserRoleAuthLogService userRoleAuthLogService; | |
53 | 62 | private final KpiGroupUserBizService kpiGroupUserBizService; |
63 | + private final TransactionDefinition transactionDefinition; | |
54 | 64 | private final KpiGroupUserService kpiGroupUserService; |
55 | - private final KpiCalcService kpiCalcService; | |
56 | - private final KpiGroupBizService kpiGroupBizService; | |
57 | 65 | private final KpiGroupRankService kpiGroupRankService; |
58 | - private final KpiGroupService kpiGroupService; | |
59 | - private final DistributedLocker distributedLocker; | |
60 | 66 | private final StringRedisTemplate stringRedisTemplate; |
61 | - private final PlatformTransactionManager platformTransactionManager; | |
62 | - private final TransactionDefinition transactionDefinition; | |
67 | + private final KpiGroupBizService kpiGroupBizService; | |
68 | + private final IndicatorsService indicatorsService; | |
69 | + private final CommonService commonService; | |
70 | + private final DistributedLocker distributedLocker; | |
63 | 71 | private final KpiCacheService kpiCacheService; |
72 | + private final KpiGroupService kpiGroupService; | |
73 | + private final KpiCalcService kpiCalcService; | |
74 | + private final ErpRpcService erpRpcService; | |
75 | + private final OopRpcService oopRpcService; | |
64 | 76 | private final KpiVal kpiVal; |
65 | 77 | |
66 | 78 | @Value("${spring.cache.custom.global-prefix}:kpi:group:user") |
... | ... | @@ -93,6 +105,9 @@ public class KpiGroupUserTaskService { |
93 | 105 | } |
94 | 106 | } |
95 | 107 | |
108 | + /** | |
109 | + * 抽取绩效人员 | |
110 | + */ | |
96 | 111 | public void extractKpiUser(KpiExtractUserBO extractUserBO) { |
97 | 112 | final Long kpiGroupRankId = extractUserBO.getKpiGroupRankId(); |
98 | 113 | final Set<Long> kpiGroupIds = extractUserBO.getKpiGroupIds(); |
... | ... | @@ -103,10 +118,12 @@ public class KpiGroupUserTaskService { |
103 | 118 | return; |
104 | 119 | } |
105 | 120 | final Long groupId = kpiGroupRank.getGroupId(); |
121 | + List<ShopDTO> shopDTOS = oopRpcService.queryGroupShops(groupId); | |
122 | + final List<Long> shopIds = shopDTOS.stream().map(ShopDTO::getId).distinct().collect(Collectors.toList()); | |
123 | + List<KpiGroup> kpiGroups = kpiGroupService.getByIds(kpiGroupIds); | |
124 | + | |
106 | 125 | TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition); |
107 | 126 | try { |
108 | - List<KpiGroup> kpiGroups = kpiGroupService.getByIds(kpiGroupIds); | |
109 | - | |
110 | 127 | List<KpiGroupUser> kpiGroupUsersForSave = Lists.newArrayListWithCapacity(300); |
111 | 128 | Map<Long, List<KpiGroup>> postKpiGroupMap = kpiGroups.stream().collect(Collectors.groupingBy(KpiGroup::getPostId)); |
112 | 129 | for (Map.Entry<Long, List<KpiGroup>> postEntry : postKpiGroupMap.entrySet()) { |
... | ... | @@ -129,6 +146,11 @@ public class KpiGroupUserTaskService { |
129 | 146 | } |
130 | 147 | kpiGroupUserService.insertBatchSomeColumn(kpiGroupUsersForSave); |
131 | 148 | } |
149 | + | |
150 | + Set<Long> userIds = kpiGroupUsersForSave.stream().map(KpiGroupUser::getUserId).collect(Collectors.toSet()); | |
151 | + //保存用户角色授权日志 | |
152 | + this.saveUserRoleAuthLogs(groupId, calcDate, kpiGroupIds, shopIds); | |
153 | + | |
132 | 154 | //缓存计算绩效 |
133 | 155 | kpiCacheService.cacheCalcKpi(extractUserBO, groupId); |
134 | 156 | platformTransactionManager.commit(transactionStatus); |
... | ... | @@ -139,6 +161,65 @@ public class KpiGroupUserTaskService { |
139 | 161 | } |
140 | 162 | |
141 | 163 | /** |
164 | + * 保存绩效排名组下 角色授权信息 | |
165 | + * @param kpiGroupRankId | |
166 | + * @param calcDate | |
167 | + */ | |
168 | + public void saveUserRoleAuthLogsForDebug(final Long kpiGroupRankId, final LocalDate calcDate) { | |
169 | + KpiGroupRank kpiGroupRank = kpiGroupRankService.getById(kpiGroupRankId); | |
170 | + if (PublicUtil.isEmpty(kpiGroupRank)) { | |
171 | + log.error("找不到绩效排名组信息:{}", kpiGroupRankId); | |
172 | + return; | |
173 | + } | |
174 | + List<KpiGroup> kpiGroups = kpiGroupService.list(Wrappers.<KpiGroup>lambdaQuery() | |
175 | + .in(KpiGroup::getKpiGroupRankId, kpiGroupRankId) | |
176 | + .eq(KpiGroup::getYn, Boolean.TRUE) | |
177 | + ); | |
178 | + final Set<Long> kpiGroupIds = kpiGroups.stream().map(KpiGroup::getId).collect(Collectors.toSet()); | |
179 | + final Long groupId = kpiGroupRank.getGroupId(); | |
180 | + List<ShopDTO> shopDTOS = oopRpcService.queryGroupShops(groupId); | |
181 | + final List<Long> shopIds = shopDTOS.stream().map(ShopDTO::getId).distinct().collect(Collectors.toList()); | |
182 | + | |
183 | + //保存用户角色授权日志 | |
184 | + this.saveUserRoleAuthLogs(groupId, calcDate, kpiGroupIds, shopIds); | |
185 | + | |
186 | + } | |
187 | + | |
188 | + public void saveUserRoleAuthLogs(final Long groupId, final LocalDate calcDate, final Set<Long> kpiGroupIds, final List<Long> shopIds) { | |
189 | + //抽取指标角色信息 | |
190 | + List<KpiGroupIndicatorParam> kpiIndicators = kpiGroupIndicatorParamService.list(Wrappers.<KpiGroupIndicatorParam>lambdaQuery() | |
191 | + .in(KpiGroupIndicatorParam::getKpiGroupId, kpiGroupIds) | |
192 | + .eq(KpiGroupIndicatorParam::getCodeType, IndicatorCodeTypeEnum.INDICATOR) | |
193 | + .eq(KpiGroupIndicatorParam::getYn, Boolean.TRUE) | |
194 | + ); | |
195 | + if (PublicUtil.isNotEmpty(kpiIndicators)) { | |
196 | + Set<String> indicatorCodes = kpiIndicators.stream().map(KpiGroupIndicatorParam::getIndicatorCode).collect(Collectors.toSet()); | |
197 | + Set<String> indicatorRoleCodes = commonService.getIndicatorRoleCodes(indicatorCodes); | |
198 | + | |
199 | + List<UserRoleAuthLog> userRoleAuthLogs = Lists.newArrayListWithCapacity(200); | |
200 | + for (String indicatorRoleCode : indicatorRoleCodes) { | |
201 | + List<HRoleAuthRangeVO> hRoleAuthRangeVos = erpRpcService.queryRoleHistoryAuthRange(groupId, shopIds, indicatorRoleCode, calcDate); | |
202 | + for (HRoleAuthRangeVO hRoleAuthRangeVO : Optional.ofNullable(hRoleAuthRangeVos).orElse(new ArrayList<>())) { | |
203 | + UserRoleAuthLog userRoleAuthLog = new UserRoleAuthLog(); | |
204 | + userRoleAuthLog.setUserId(hRoleAuthRangeVO.getUserId()); | |
205 | + userRoleAuthLog.setUserName(hRoleAuthRangeVO.getUserName()); | |
206 | + userRoleAuthLog.setShopId(hRoleAuthRangeVO.getRangeValue()); | |
207 | + userRoleAuthLog.setShopName(hRoleAuthRangeVO.getRangeName()); | |
208 | + userRoleAuthLog.setBeginDate(DateUtil.date2LocalDate(hRoleAuthRangeVO.getStartTime())); | |
209 | + userRoleAuthLog.setEndDate(calcDate); | |
210 | + userRoleAuthLog.setRoleCode(hRoleAuthRangeVO.getRoleCode()); | |
211 | + userRoleAuthLog.setGroupId(groupId); | |
212 | + userRoleAuthLog.setYn(Boolean.TRUE); | |
213 | + userRoleAuthLogs.add(userRoleAuthLog); | |
214 | + } | |
215 | + } | |
216 | + if (PublicUtil.isNotEmpty(userRoleAuthLogs)) { | |
217 | + userRoleAuthLogService.insertBatchSomeColumn(userRoleAuthLogs); | |
218 | + } | |
219 | + } | |
220 | + } | |
221 | + | |
222 | + /** | |
142 | 223 | * 每天凌晨30分执行(人事角色、岗位调整在5点执行) |
143 | 224 | * 1. 将待生效数据改为生效中 |
144 | 225 | * 2. 将之前的配置设置为失效 | ... | ... |
fw-morax-service/src/main/java/cn/fw/morax/service/biz/kpi/KpiPoolBizService.java
... | ... | @@ -1051,11 +1051,11 @@ public class KpiPoolBizService { |
1051 | 1051 | buildPoolData(kpiPool, kpiPoolDetailVo); |
1052 | 1052 | LocalDate dataDate = LocalDate.from(kpiPoolDetailVo.getEndTime()); |
1053 | 1053 | |
1054 | - kpiPoolDetailVo.setTotalScore(this.getKpiGroupIndicatorTotalScore(kpiGroupId)); | |
1054 | +// kpiPoolDetailVo.setTotalScore(this.getKpiGroupIndicatorTotalScore(kpiGroupId)); | |
1055 | + this.setIndicatorVos(kpiPoolId, kpiGroupId, dataDate, kpiPoolDetailVo); | |
1055 | 1056 | kpiPoolDetailVo.setKpiScoreRatio(kpiPoolDetailVo.getKpiScoreRatio().multiply(Constant.ONE_HUNDRED)); |
1056 | 1057 | this.setRewardPunishScore(kpiPool, kpiPoolDetailVo); |
1057 | 1058 | this.setRewardPunishScoreRate(kpiPool, kpiPoolDetailVo); |
1058 | - this.setIndicatorVos(kpiPoolId, kpiGroupId, dataDate, kpiPoolDetailVo); | |
1059 | 1059 | this.setAssess(kpiPoolDetailVo); |
1060 | 1060 | return kpiPoolDetailVo; |
1061 | 1061 | } |
... | ... | @@ -1227,6 +1227,10 @@ public class KpiPoolBizService { |
1227 | 1227 | // BigDecimal.ZERO : Constant.ONE_HUNDRED.subtract(indicatorScoreRatio); |
1228 | 1228 | // indicatorValueVO.setLossIndicatorScoreRatio(decimalFormat.format(lossIndicatorScoreRatio)); |
1229 | 1229 | } |
1230 | + | |
1231 | + final BigDecimal totalScore = indicatorValueVOS.stream().map(indicator -> indicator.getBaseScore()) | |
1232 | + .reduce(BigDecimal.ZERO, BigDecimal::add); | |
1233 | + kpiPoolDetailVo.setTotalScore(totalScore); | |
1230 | 1234 | kpiPoolDetailVo.setKpiValues(indicatorValueVOS); |
1231 | 1235 | } |
1232 | 1236 | ... | ... |
fw-morax-service/src/main/java/cn/fw/morax/service/biz/kpi/KpiReportBizService.java
... | ... | @@ -268,6 +268,13 @@ public class KpiReportBizService { |
268 | 268 | if (! pool.getKpiGroupId().equals(kpiGroupIndicator.getKpiGroupId())) { |
269 | 269 | continue; |
270 | 270 | } |
271 | + //检查员工是否有指标角色,没有就不抽数据 | |
272 | + if (pool.getMonthly().compareTo(Constant.CHECK_HAS_INDICATOR_ROLE_START_MONTH) >= 0) { | |
273 | + if ((PublicUtil.isNotEmpty(pool.getCalcKpiGroupIndicatorIds())) && (! pool.getCalcKpiGroupIndicatorIds().contains(kpiGroupIndicator.getId()))) { | |
274 | + log.info("员工:{}没有指标角色授权,不抽取指标数据:{}", JSON.toJSONString(pool), JSON.toJSONString(kpiGroupIndicator)); | |
275 | + continue; | |
276 | + } | |
277 | + } | |
271 | 278 | final Long kpiGroupIndicatorId = kpiGroupIndicator.getId(); |
272 | 279 | BigDecimal indicatorScore = userIndicatorScoreMap.get(userId, kpiGroupIndicatorId); |
273 | 280 | BigDecimal rawKpiValue = userIndicatorHitMap.get(userId, kpiGroupIndicatorId); | ... | ... |
fw-morax-service/src/main/java/cn/fw/morax/service/data/UserRoleAuthLogService.java
0 → 100644
fw-morax-service/src/main/java/cn/fw/morax/service/data/impl/UserRoleAuthLogImpl.java
0 → 100644
1 | +package cn.fw.morax.service.data.impl; | |
2 | + | |
3 | +import cn.fw.morax.dao.UserRoleAuthLogDao; | |
4 | +import cn.fw.morax.domain.db.UserRoleAuthLog; | |
5 | +import cn.fw.morax.service.data.UserRoleAuthLogService; | |
6 | +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |
7 | +import org.springframework.stereotype.Service; | |
8 | + | |
9 | +/** | |
10 | + * 用户角色授权记录 | |
11 | + * | |
12 | + * @author : kurisu | |
13 | + * @version : 1.0 | |
14 | + * @className : PayrollRecordServiceImpl | |
15 | + * @description : 用户角色授权记录 | |
16 | + * @date : 2022-05-07 10:55 | |
17 | + */ | |
18 | +@Service | |
19 | +public class UserRoleAuthLogImpl extends ServiceImpl<UserRoleAuthLogDao, UserRoleAuthLog> implements UserRoleAuthLogService { | |
20 | + | |
21 | +} | ... | ... |