Blame view

fw-morax-server/src/main/java/cn/fw/morax/server/controller/erp/KpiDebugController.java 10.8 KB
61c41ffa   张志伟   feature(Controlle...
1
2
3
  package cn.fw.morax.server.controller.erp;
  
  import cn.fw.common.web.annotation.ControllerMethod;
61c41ffa   张志伟   feature(Controlle...
4
  import cn.fw.data.base.domain.common.Message;
beac6c98   姜超   feature(*): 分配查询
5
  import cn.fw.morax.common.utils.DateUtil;
1c236c95   姜超   feature(*): 绩效池查询
6
  import cn.fw.morax.common.utils.PublicUtil;
61c41ffa   张志伟   feature(Controlle...
7
  import cn.fw.morax.domain.bo.kpi.KpiGroupCalculableBO;
3afee3e4   姜超   feature(*): 绩效排名组修改
8
9
  import cn.fw.morax.domain.db.kpi.KpiGroup;
  import cn.fw.morax.domain.db.kpi.KpiGroupRank;
8fb407fa   姜超   fix(kpigroupuser)...
10
  import cn.fw.morax.domain.db.kpi.KpiGroupUser;
864042ba   姜超   feature(*): 通过绩效组...
11
  import cn.fw.morax.domain.db.kpi.KpiPool;
46276518   张志伟   feature(*): 完善deb...
12
  import cn.fw.morax.domain.dto.kpi.UserIndicatorDTO;
8fb407fa   姜超   fix(kpigroupuser)...
13
  import cn.fw.morax.domain.enums.KpiIgnoreCauseEnum;
3afee3e4   姜超   feature(*): 绩效排名组修改
14
  import cn.fw.morax.domain.enums.SettingStatusEnum;
2d8a2217   姜超   feature(*): 绩效、薪酬...
15
  import cn.fw.morax.rpc.ehr.EhrRpcService;
0185237a   姜超   feature(*): 查询管理员工
16
  import cn.fw.morax.rpc.ehr.dto.StaffBaseInfoDTO;
8920efe7   姜超   feature(*): 申述日期修...
17
  import cn.fw.morax.server.task.GenericTask;
0185237a   姜超   feature(*): 查询管理员工
18
  import cn.fw.morax.service.biz.CommonService;
46276518   张志伟   feature(*): 完善deb...
19
  import cn.fw.morax.service.biz.kpi.IndicatorBizService;
7652457e   张志伟   feature(*): 手动计算绩...
20
21
  import cn.fw.morax.service.biz.kpi.KpiCalculateService;
  import cn.fw.morax.service.biz.kpi.KpiPoolBizService;
3afee3e4   姜超   feature(*): 绩效排名组修改
22
23
  import cn.fw.morax.service.data.kpi.KpiGroupRankService;
  import cn.fw.morax.service.data.kpi.KpiGroupService;
0b67bdb4   张志伟   feature(*): 完成绩效分计算
24
  import cn.fw.morax.service.data.kpi.KpiGroupUserService;
0b67bdb4   张志伟   feature(*): 完成绩效分计算
25
  import cn.fw.morax.service.data.kpi.KpiPoolService;
61c41ffa   张志伟   feature(Controlle...
26
  import cn.fw.security.auth.client.annotation.Authorization;
61c41ffa   张志伟   feature(Controlle...
27
  import cn.fw.security.auth.client.enums.AuthType;
8ffdc70e   姜超   feature(*): 薪酬、绩效查询
28
  import com.baomidou.mybatisplus.core.toolkit.Wrappers;
61c41ffa   张志伟   feature(Controlle...
29
30
  import lombok.RequiredArgsConstructor;
  import lombok.extern.slf4j.Slf4j;
beac6c98   姜超   feature(*): 分配查询
31
32
  import org.springframework.data.redis.core.BoundZSetOperations;
  import org.springframework.data.redis.core.StringRedisTemplate;
61c41ffa   张志伟   feature(Controlle...
33
  import org.springframework.validation.annotation.Validated;
46276518   张志伟   feature(*): 完善deb...
34
  import org.springframework.web.bind.annotation.*;
61c41ffa   张志伟   feature(Controlle...
35
  
46276518   张志伟   feature(*): 完善deb...
36
  import javax.validation.Valid;
beac6c98   姜超   feature(*): 分配查询
37
  import java.math.BigDecimal;
61c41ffa   张志伟   feature(Controlle...
38
  import java.time.LocalDate;
beac6c98   姜超   feature(*): 分配查询
39
  import java.time.LocalDateTime;
25a37717   张志伟   feature(*): 完成星级变...
40
  import java.time.YearMonth;
beac6c98   姜超   feature(*): 分配查询
41
  import java.time.temporal.ChronoUnit;
1c236c95   姜超   feature(*): 绩效池查询
42
  import java.util.List;
8fb407fa   姜超   fix(kpigroupuser)...
43
44
  import java.util.Set;
  import java.util.stream.Collectors;
61c41ffa   张志伟   feature(Controlle...
45
  
61c41ffa   张志伟   feature(Controlle...
46
47
48
49
50
51
52
53
54
55
56
57
  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
61c41ffa   张志伟   feature(Controlle...
58
  @Authorization(AuthType.NONE)
f7bec0dc   姜超   feature(*): 禁用启用薪酬指标
59
  @RequiredArgsConstructor
61c41ffa   张志伟   feature(Controlle...
60
61
62
  @Validated
  @RequestMapping("/debug/kpi")
  public class KpiDebugController {
61c41ffa   张志伟   feature(Controlle...
63
64
      private final KpiCalculateService kpiCalculateService;
      private final KpiPoolBizService kpiPoolBizService;
0185237a   姜超   feature(*): 查询管理员工
65
      private final CommonService commonService;
8920efe7   姜超   feature(*): 申述日期修...
66
      private final GenericTask genericTask;
8fb407fa   姜超   fix(kpigroupuser)...
67
      private final KpiGroupUserService kpiGroupUserService;
3afee3e4   姜超   feature(*): 绩效排名组修改
68
69
      private final KpiGroupService kpiGroupService;
      private final KpiGroupRankService kpiGroupRankService;
1c236c95   姜超   feature(*): 绩效池查询
70
      private final KpiPoolService kpiPoolService;
46276518   张志伟   feature(*): 完善deb...
71
      private final IndicatorBizService indicatorBizService;
61c41ffa   张志伟   feature(Controlle...
72
  
61c41ffa   张志伟   feature(Controlle...
73
  
46276518   张志伟   feature(*): 完善deb...
74
75
76
77
78
79
80
      @PostMapping("/indicator/report/up")
      @ControllerMethod("手动上报简单指标数据")
      public Message<Void> reportIndicator(@Valid @RequestBody UserIndicatorDTO dto) {
          indicatorBizService.reportData(dto);
          return success();
      }
  
8920efe7   姜超   feature(*): 申述日期修...
81
82
83
84
85
86
87
      @GetMapping("/regular-kpi")
      @ControllerMethod("固定绩效数据")
      public Message<Void> regularKpiStar() {
          genericTask.regularKpiStar();
          return success();
      }
  
46276518   张志伟   feature(*): 完善deb...
88
      @PutMapping("/indicator/calc/score")
61c41ffa   张志伟   feature(Controlle...
89
90
91
      @ControllerMethod("计算绩效得分")
      public Message<Void> calcScore(@RequestParam("kpiGroupId") Long kpiGroupId,
                                     @RequestParam("date") LocalDate localDate) {
61c41ffa   张志伟   feature(Controlle...
92
93
94
95
          kpiCalculateService.calculateKpi(new KpiGroupCalculableBO(kpiGroupId, localDate));
          return success();
      }
  
46276518   张志伟   feature(*): 完善deb...
96
      @PutMapping("/indicator/calc/score-rate")
7652457e   张志伟   feature(*): 手动计算绩...
97
      @ControllerMethod("手动计算绩效得分率")
61c41ffa   张志伟   feature(Controlle...
98
99
      public Message<Void> calcRate(@RequestParam("kpiGroupId") Long kpiGroupId,
                                    @RequestParam("date") LocalDate localDate) {
61c41ffa   张志伟   feature(Controlle...
100
101
102
103
          kpiPoolBizService.calcuScoringRate(new KpiGroupCalculableBO(kpiGroupId, localDate));
          return success();
      }
  
46276518   张志伟   feature(*): 完善deb...
104
      @PutMapping("/indicator/calc/star")
7652457e   张志伟   feature(*): 手动计算绩...
105
106
107
108
109
110
      @ControllerMethod("手动计算绩效排名和星级")
      public Message<Void> calcLevel(@RequestParam("kpiGroupId") Long kpiGroupId,
                                     @RequestParam("date") LocalDate localDate) {
          kpiPoolBizService.cacheCalculableKpiGroupRank(kpiGroupId, localDate);
          return success();
      }
bbb00e01   姜超   feature(*): 启用禁用指标
111
  
46276518   张志伟   feature(*): 完善deb...
112
      @PutMapping("/indicator/calc/rank")
7652457e   张志伟   feature(*): 手动计算绩...
113
      @ControllerMethod("手动计算绩效排名")
60f70b0b   姜超   feature(*): 绩效组排名...
114
115
116
117
118
119
120
121
122
123
124
125
      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();
      }
  
0185237a   姜超   feature(*): 查询管理员工
126
127
128
129
130
131
      @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);
      }
c222645a   姜超   fix(*): 修改bug
132
  
2d8a2217   姜超   feature(*): 绩效、薪酬...
133
      private final EhrRpcService ehrRpcService;
08ef9699   张志伟   feature(*): 重新处理上...
134
  
2d8a2217   姜超   feature(*): 绩效、薪酬...
135
136
137
138
139
      @GetMapping("/manage-staff1")
      @ControllerMethod("查询管理员工")
      public Message<List<StaffBaseInfoDTO>> initKgc1(Long userId) {
          System.out.println(ehrRpcService.queryProbationerSalary(userId, LocalDate.now()));
          return success();
beac6c98   姜超   feature(*): 分配查询
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
      }
  
      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();
2d8a2217   姜超   feature(*): 绩效、薪酬...
172
173
      }
  
8fb407fa   姜超   fix(kpigroupuser)...
174
175
176
      @GetMapping("/probation-user")
      @ControllerMethod("处理试用期员工")
      public Message<Void> probationUser() {
8fb407fa   姜超   fix(kpigroupuser)...
177
          List<KpiGroupUser> userList = kpiGroupUserService.list(Wrappers.<KpiGroupUser>lambdaQuery()
655c8002   姜超   fix(kpiuser): 查询参数修改
178
                  .eq(KpiGroupUser::getDataDate, LocalDate.now().minusDays(2))
8fb407fa   姜超   fix(kpigroupuser)...
179
180
181
182
                  .eq(KpiGroupUser::getIgnored, Boolean.TRUE)
                  .eq(KpiGroupUser::getIgnoreCause, KpiIgnoreCauseEnum.PROBATION)
                  .eq(KpiGroupUser::getYn, Boolean.TRUE)
          );
08ef9699   张志伟   feature(*): 重新处理上...
183
          if (PublicUtil.isEmpty(userList)) {
8fb407fa   姜超   fix(kpigroupuser)...
184
185
186
187
188
189
190
191
192
193
194
195
196
              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();
      }
  
3afee3e4   姜超   feature(*): 绩效排名组修改
197
198
199
200
201
202
203
204
205
206
207
208
209
      @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)) {
39136da3   姜超   feature(*): 绩效排名组...
210
211
212
                  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()));
3afee3e4   姜超   feature(*): 绩效排名组修改
213
214
215
216
217
218
219
                  kpiGroupRank.setStatus(SettingStatusEnum.EFFECTIVE);
                  kpiGroupRankService.updateById(kpiGroupRank);
              }
          }
          return success();
      }
  
aeb54175   姜超   feature(*): 绩效组人员...
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
      @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();
      }
  
61c41ffa   张志伟   feature(Controlle...
248
  }