KpiDebugController.java
10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
package cn.fw.morax.server.controller.erp;
import cn.fw.common.web.annotation.ControllerMethod;
import cn.fw.data.base.domain.common.Message;
import cn.fw.morax.common.utils.DateUtil;
import cn.fw.morax.common.utils.PublicUtil;
import cn.fw.morax.domain.bo.kpi.KpiGroupCalculableBO;
import cn.fw.morax.domain.db.kpi.KpiGroup;
import cn.fw.morax.domain.db.kpi.KpiGroupRank;
import cn.fw.morax.domain.db.kpi.KpiGroupUser;
import cn.fw.morax.domain.db.kpi.KpiPool;
import cn.fw.morax.domain.dto.kpi.UserIndicatorDTO;
import cn.fw.morax.domain.enums.KpiIgnoreCauseEnum;
import cn.fw.morax.domain.enums.SettingStatusEnum;
import cn.fw.morax.rpc.ehr.EhrRpcService;
import cn.fw.morax.rpc.ehr.dto.StaffBaseInfoDTO;
import cn.fw.morax.server.task.GenericTask;
import cn.fw.morax.service.biz.CommonService;
import cn.fw.morax.service.biz.kpi.IndicatorBizService;
import cn.fw.morax.service.biz.kpi.KpiCalculateService;
import cn.fw.morax.service.biz.kpi.KpiPoolBizService;
import cn.fw.morax.service.data.kpi.KpiGroupRankService;
import cn.fw.morax.service.data.kpi.KpiGroupService;
import cn.fw.morax.service.data.kpi.KpiGroupUserService;
import cn.fw.morax.service.data.kpi.KpiPoolService;
import cn.fw.security.auth.client.annotation.Authorization;
import cn.fw.security.auth.client.enums.AuthType;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.BoundZSetOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import static cn.fw.common.web.util.ResultBuilder.success;
/**
* @author : kurisu
* @version : 1.0
* @className : DebugController
* @description : 绩效通用调试控制器
* @date : 2022-04-11 10:45
* @ignore
*/
@Slf4j
@RestController
@Authorization(AuthType.NONE)
@RequiredArgsConstructor
@Validated
@RequestMapping("/debug/kpi")
public class KpiDebugController {
private final KpiCalculateService kpiCalculateService;
private final KpiPoolBizService kpiPoolBizService;
private final CommonService commonService;
private final GenericTask genericTask;
private final KpiGroupUserService kpiGroupUserService;
private final KpiGroupService kpiGroupService;
private final KpiGroupRankService kpiGroupRankService;
private final KpiPoolService kpiPoolService;
private final IndicatorBizService indicatorBizService;
@PostMapping("/indicator/report/up")
@ControllerMethod("手动上报简单指标数据")
public Message<Void> reportIndicator(@Valid @RequestBody UserIndicatorDTO dto) {
indicatorBizService.reportData(dto);
return success();
}
@GetMapping("/regular-kpi")
@ControllerMethod("固定绩效数据")
public Message<Void> regularKpiStar() {
genericTask.regularKpiStar();
return success();
}
@PutMapping("/indicator/calc/score")
@ControllerMethod("计算绩效得分")
public Message<Void> calcScore(@RequestParam("kpiGroupId") Long kpiGroupId,
@RequestParam("date") LocalDate localDate) {
kpiCalculateService.calculateKpi(new KpiGroupCalculableBO(kpiGroupId, localDate));
return success();
}
@PutMapping("/indicator/calc/score-rate")
@ControllerMethod("手动计算绩效得分率")
public Message<Void> calcRate(@RequestParam("kpiGroupId") Long kpiGroupId,
@RequestParam("date") LocalDate localDate) {
kpiPoolBizService.calcuScoringRate(new KpiGroupCalculableBO(kpiGroupId, localDate));
return success();
}
@PutMapping("/indicator/calc/star")
@ControllerMethod("手动计算绩效排名和星级")
public Message<Void> calcLevel(@RequestParam("kpiGroupId") Long kpiGroupId,
@RequestParam("date") LocalDate localDate) {
kpiPoolBizService.cacheCalculableKpiGroupRank(kpiGroupId, localDate);
return success();
}
@PutMapping("/indicator/calc/rank")
@ControllerMethod("手动计算绩效排名")
public Message<Void> calcLevel(@RequestParam("shopId") Long shopId,
@RequestParam("postId") Long postId) {
List<KpiPool> poolList = kpiPoolService.list(Wrappers.<KpiPool>lambdaQuery()
.eq(KpiPool::getShopId, shopId)
.eq(KpiPool::getMonthly, YearMonth.from(YearMonth.now()))
.eq(KpiPool::getPostId, postId)
.eq(KpiPool::getYn, Boolean.TRUE)
);
kpiPoolBizService.calcRank(poolList);
return success();
}
@GetMapping("/manage-staff")
@ControllerMethod("查询管理员工")
public Message<List<StaffBaseInfoDTO>> initKgc(Long userId, String monthly) {
List<StaffBaseInfoDTO> staffBaseInfoDTOS = commonService.queryManageStaffs(userId, YearMonth.parse(monthly));
return success(staffBaseInfoDTOS);
}
private final EhrRpcService ehrRpcService;
@GetMapping("/manage-staff1")
@ControllerMethod("查询管理员工")
public Message<List<StaffBaseInfoDTO>> initKgc1(Long userId) {
System.out.println(ehrRpcService.queryProbationerSalary(userId, LocalDate.now()));
return success();
}
private final StringRedisTemplate stringRedisTemplate;
@GetMapping("/set")
@ControllerMethod("查询管理员工")
public Message<List<StaffBaseInfoDTO>> initKgc2(Long userId) {
BoundZSetOperations<String, String> zSetOps = stringRedisTemplate.boundZSetOps("eval:test");
stringRedisTemplate.expireAt("eval:test", DateUtil.localDateTime2Date(LocalDateTime.now().plus(2L,ChronoUnit.HOURS)));
zSetOps.add("1", new BigDecimal("0.99").doubleValue());
zSetOps.add("2", new BigDecimal("0.89").doubleValue());
zSetOps.add("3", new BigDecimal("0.79").doubleValue());
zSetOps.add("4", new BigDecimal("0.69").doubleValue());
zSetOps.add("5", new BigDecimal("0.59").doubleValue());
zSetOps.add("6", new BigDecimal("0.49").doubleValue());
zSetOps.add("7", new BigDecimal("0.39").doubleValue());
zSetOps.add("8", new BigDecimal("0.29").doubleValue());
zSetOps.add("9", new BigDecimal("0.19").doubleValue());
zSetOps.add("10", new BigDecimal("0.09").doubleValue());
System.out.println("-1,0 : " + zSetOps.reverseRange(-1,0));
System.out.println("0,0 : " + zSetOps.reverseRange(0,0));
System.out.println("0,1 : " + zSetOps.reverseRange(0,1));
System.out.println("1,2 : " + zSetOps.reverseRange(1,2));
System.out.println("1,2 : " + zSetOps.reverseRange(1,2));
System.out.println("1,3 : " + zSetOps.reverseRange(1,3));
System.out.println("1,4 : " + zSetOps.reverseRange(1,4));
System.out.println("5,6 : " + zSetOps.reverseRange(5,6));
System.out.println("9,9 : " + zSetOps.reverseRange(9,9));
System.out.println("10,10 : " + zSetOps.reverseRange(10,10));
return success();
}
@GetMapping("/probation-user")
@ControllerMethod("处理试用期员工")
public Message<Void> probationUser() {
List<KpiGroupUser> userList = kpiGroupUserService.list(Wrappers.<KpiGroupUser>lambdaQuery()
.eq(KpiGroupUser::getDataDate, LocalDate.now().minusDays(2))
.eq(KpiGroupUser::getIgnored, Boolean.TRUE)
.eq(KpiGroupUser::getIgnoreCause, KpiIgnoreCauseEnum.PROBATION)
.eq(KpiGroupUser::getYn, Boolean.TRUE)
);
if (PublicUtil.isEmpty(userList)) {
return success();
}
Set<Long> userIds = userList.stream().map(KpiGroupUser::getUserId).collect(Collectors.toSet());
kpiPoolService.update(Wrappers.<KpiPool>lambdaUpdate()
.set(KpiPool::getYn, Boolean.FALSE)
.eq(KpiPool::getYn, Boolean.TRUE)
.eq(KpiPool::getMonthly, YearMonth.now())
.in(KpiPool::getUserId, userIds)
);
return success();
}
@GetMapping("/process-kpi-rank")
@ControllerMethod("处理绩效排名组老数据")
public Message<Void> processKpiRank() {
List<KpiGroupRank> kpiGroupRanks = kpiGroupRankService.list(Wrappers.<KpiGroupRank>lambdaQuery()
.eq(KpiGroupRank::getYn, Boolean.TRUE)
.isNull(KpiGroupRank::getKpiGroupIds)
);
for (KpiGroupRank kpiGroupRank : kpiGroupRanks) {
List<KpiGroup> kpiGroups = kpiGroupService.list(Wrappers.<KpiGroup>lambdaQuery()
.eq(KpiGroup::getStatus, SettingStatusEnum.EFFECTIVE)
.in(KpiGroup::getKgc, kpiGroupRank.getKgcs())
);
if (PublicUtil.isNotEmpty(kpiGroups)) {
kpiGroupRank.setPostIds(kpiGroups.stream().map(KpiGroup::getPostId).distinct().collect(Collectors.toList()));
kpiGroupRank.setShopIds(kpiGroups.stream().flatMap(kpiGroup -> kpiGroup.getShopIds().stream()).distinct().collect(Collectors.toList()));
kpiGroupRank.setKpiGroupIds(kpiGroups.stream().map(KpiGroup::getId).distinct().collect(Collectors.toList()));
kpiGroupRank.setStatus(SettingStatusEnum.EFFECTIVE);
kpiGroupRankService.updateById(kpiGroupRank);
}
}
return success();
}
@GetMapping("/process-kpi-user")
@ControllerMethod("处理绩效用户老数据")
public Message<Void> processKpiUserInclusion() {
//纳入绩效考核人员
List<KpiGroupUser> groupUsers = kpiGroupUserService.list(Wrappers.<KpiGroupUser>lambdaQuery()
.eq(KpiGroupUser::getDataDate, LocalDate.now().minusDays(1))
.eq(KpiGroupUser::getIgnored, Boolean.FALSE)
.eq(KpiGroupUser::getYn, Boolean.TRUE)
);
for (KpiGroupUser groupUser : groupUsers) {
KpiPool kpiPool = kpiPoolService.getOne(Wrappers.<KpiPool>lambdaQuery()
.eq(KpiPool::getKpiGroupId, groupUser.getKpiGroupId())
.eq(KpiPool::getUserId, groupUser.getUserId())
.eq(KpiPool::getMonthly, YearMonth.from(groupUser.getDataDate()))
.eq(KpiPool::getYn, Boolean.TRUE)
, Boolean.FALSE);
if (PublicUtil.isNotEmpty(kpiPool)) {
//纳入绩效计算 绩效池不参与
if (! kpiPool.getInclusion()) {
kpiPool.setInclusion(Boolean.TRUE);
kpiPoolService.updateById(kpiPool);
}
}
}
return success();
}
}