Blame view

fw-morax-service/src/main/java/cn/fw/morax/service/biz/CommonService.java 14.6 KB
fc885c22   姜超   feature(*): 绩效组阶梯...
1
2
3
  package cn.fw.morax.service.biz;
  
  import cn.fw.common.exception.BusinessException;
0a90b3d7   姜超   feature(*): 考评组审批修改
4
  import cn.fw.ehr.sdk.api.enums.RoleManagerEnum;
99471c63   姜超   feature(*): 指标排名
5
  import cn.fw.morax.common.constant.Constant;
59d58c08   姜超   feature(*): excel...
6
  import cn.fw.morax.common.utils.ExcelDataUtil;
fc885c22   姜超   feature(*): 绩效组阶梯...
7
  import cn.fw.morax.common.utils.PublicUtil;
41a1d9fe   姜超   feature(*): 考评草稿修改
8
  import cn.fw.morax.domain.db.SettingDraft;
5ff2c525   姜超   feature(*): 并列排名计算
9
  import cn.fw.morax.domain.db.eval.EvalGroupRewardRankLog;
c06a04fb   姜超   feature(*): 考评指标详情
10
  import cn.fw.morax.domain.db.eval.EvalIndicatorValue;
3d4edc47   姜超   feature(*): 薪酬项目下钻
11
  import cn.fw.morax.domain.db.kpi.IndicatorUserValue;
41a1d9fe   姜超   feature(*): 考评草稿修改
12
  import cn.fw.morax.domain.db.kpi.KpiGroup;
fc885c22   姜超   feature(*): 绩效组阶梯...
13
  import cn.fw.morax.domain.dto.AbstractLaddersDto;
554c0be5   姜超   feature(*): 修改属性
14
  import cn.fw.morax.domain.enums.DataTypeEnum;
3d4edc47   姜超   feature(*): 薪酬项目下钻
15
  import cn.fw.morax.domain.enums.IndicatorValueTypeEnum;
eb829e71   姜超   feature(*): 绩效组重复...
16
  import cn.fw.morax.domain.enums.SettingDraftStatusEnum;
41a1d9fe   姜超   feature(*): 考评草稿修改
17
  import cn.fw.morax.domain.enums.SettingDraftTypeEnum;
99471c63   姜超   feature(*): 指标排名
18
  import cn.fw.morax.domain.vo.kpi.IndicatorUserValueVO;
5ff2c525   姜超   feature(*): 并列排名计算
19
  import cn.fw.morax.domain.vo.kpi.KpiIndicatorRankStaffVO;
baf571c2   姜超   feature(*): 查询员工星...
20
21
  import cn.fw.morax.rpc.ehr.EhrRpcService;
  import cn.fw.morax.rpc.ehr.dto.StaffBaseInfoDTO;
41a1d9fe   姜超   feature(*): 考评草稿修改
22
  import cn.fw.morax.service.data.SettingDraftService;
59d58c08   姜超   feature(*): excel...
23
24
25
  import cn.hutool.core.io.IoUtil;
  import cn.hutool.poi.excel.ExcelUtil;
  import cn.hutool.poi.excel.ExcelWriter;
3d4edc47   姜超   feature(*): 薪酬项目下钻
26
  import com.alibaba.fastjson.JSONObject;
41a1d9fe   姜超   feature(*): 考评草稿修改
27
28
  import com.baomidou.mybatisplus.core.conditions.Wrapper;
  import com.baomidou.mybatisplus.core.toolkit.Wrappers;
fc885c22   姜超   feature(*): 绩效组阶梯...
29
30
  import lombok.RequiredArgsConstructor;
  import lombok.extern.slf4j.Slf4j;
fc885c22   姜超   feature(*): 绩效组阶梯...
31
32
  import org.springframework.stereotype.Service;
  
59d58c08   姜超   feature(*): excel...
33
  import javax.servlet.ServletOutputStream;
ed509f38   姜超   feature(*): 格式化excel
34
  import javax.servlet.http.HttpServletRequest;
59d58c08   姜超   feature(*): excel...
35
36
  import javax.servlet.http.HttpServletResponse;
  import java.io.IOException;
ed509f38   姜超   feature(*): 格式化excel
37
  import java.io.UnsupportedEncodingException;
fc885c22   姜超   feature(*): 绩效组阶梯...
38
  import java.math.BigDecimal;
ed509f38   姜超   feature(*): 格式化excel
39
40
  import java.net.URLEncoder;
  import java.nio.charset.StandardCharsets;
45c0814e   姜超   feature(*): 薪酬查询调整
41
  import java.time.*;
baf571c2   姜超   feature(*): 查询员工星...
42
  import java.time.temporal.TemporalAdjusters;
3d4edc47   姜超   feature(*): 薪酬项目下钻
43
  import java.util.*;
baf571c2   姜超   feature(*): 查询员工星...
44
  import java.util.stream.Collectors;
fc885c22   姜超   feature(*): 绩效组阶梯...
45
46
47
48
49
50
  
  @Slf4j
  @RequiredArgsConstructor
  @Service
  public class CommonService {
  
baf571c2   姜超   feature(*): 查询员工星...
51
      private final EhrRpcService ehrRpcService;
41a1d9fe   姜超   feature(*): 考评草稿修改
52
      private final SettingDraftService settingDraftService;
baf571c2   姜超   feature(*): 查询员工星...
53
  
fc885c22   姜超   feature(*): 绩效组阶梯...
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
      /**
       * 检查阶梯
       *
       * @param dtos
       */
      public static void checkLadders(List<? extends AbstractLaddersDto> dtos) {
          if (PublicUtil.isEmpty(dtos)) {
              return;
          }
          String errorPromptName = dtos.get(0).getBusinessName();
          checkLadders(dtos, errorPromptName);
      }
  
      /**
       * 检查阶梯
       *
       * @param dtos
       */
      public static void checkLadders(List<? extends AbstractLaddersDto> dtos, String errorPromptName) {
280563a2   姜超   feature(*): 考评组保存
73
74
75
          if (PublicUtil.isEmpty(dtos)) {
              return;
          }
fc885c22   姜超   feature(*): 绩效组阶梯...
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
          BigDecimal lastUpper = null;
          //阶梯值校验  标准分不能超过指标基础分,阶梯值必须连续
          for (AbstractLaddersDto laddersDto : dtos) {
              BigDecimal lower = laddersDto.getLower();
              BigDecimal upper = laddersDto.getUpper();
              //上一条的下限要等于下一条的上限
              if (PublicUtil.isNotEmpty(lastUpper) && (lastUpper.compareTo(lower) != 0) ) {
                  throw new BusinessException("【" + errorPromptName + "】的阶梯上限与下限不是连续,请编辑后重试");
              }
              //每条上限大于下限
              if (lower.compareTo(upper) >= 0) {
                  throw new BusinessException("【" + errorPromptName + "】的阶梯下限大于或等于阶梯上限,请修改错误阶梯");
              }
              lastUpper = laddersDto.getUpper();
          }
      }
  
59d58c08   姜超   feature(*): excel...
93
94
95
96
97
98
99
100
  
      /**
       * 导出文件
       *
       * @param response
       * @param rows
       * @param fileName
       */
ce966b05   姜超   feature(*): 导出文件编码修改
101
      public static <T> void downloadExcel(HttpServletResponse response, List<T> rows, String fileName, Class<?> source) {
59d58c08   姜超   feature(*): excel...
102
          ExcelWriter writer = ExcelUtil.getWriter();
2f26f193   姜超   feature(*): 个税导入、...
103
          ExcelDataUtil.setExcelHeadAndWidth(writer, source, Boolean.TRUE);
ed509f38   姜超   feature(*): 格式化excel
104
          writer.setOnlyAlias(true);
59d58c08   姜超   feature(*): excel...
105
          writer.write(rows, true);
2f26f193   姜超   feature(*): 个税导入、...
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
          ExcelDataUtil.setAutoSizeColumn(writer.getSheet());
          response.setContentType("application/vnd.ms-excel;charset=utf-8");
          response.setHeader("Content-Disposition","attachment;filename=" + fileName);
          ServletOutputStream out= null;
          try {
              out = response.getOutputStream();
          } catch (IOException e) {
              e.printStackTrace();
          }
          writer.flush(out, true);
          writer.close();
          IoUtil.close(out);
      }
  
      /**
       * 导出文件
       *
       * @param response
       * @param fileName
       */
      public static <T> void downloadTemplateExcel(HttpServletResponse response, String fileName, Class<?> source) {
          ExcelWriter writer = ExcelUtil.getWriter();
          Map<String, String> headMap = ExcelDataUtil.setExcelHeadAndWidth(writer, source, Boolean.FALSE);
          if (headMap.isEmpty()) {
              return;
          }
          writer.writeHeadRow(headMap.values());
          writer.setRowHeight(0, 25);
  //        ExcelDataUtil.setAutoSizeColumn(writer.getSheet(), headMap.size());
59d58c08   姜超   feature(*): excel...
135
          response.setContentType("application/vnd.ms-excel;charset=utf-8");
ce966b05   姜超   feature(*): 导出文件编码修改
136
          response.setHeader("Content-Disposition","attachment;filename=" + fileName);
59d58c08   姜超   feature(*): excel...
137
138
139
140
141
142
          ServletOutputStream out= null;
          try {
              out = response.getOutputStream();
          } catch (IOException e) {
              e.printStackTrace();
          }
59d58c08   姜超   feature(*): excel...
143
          writer.flush(out, true);
59d58c08   姜超   feature(*): excel...
144
          writer.close();
59d58c08   姜超   feature(*): excel...
145
146
147
          IoUtil.close(out);
      }
  
ce966b05   姜超   feature(*): 导出文件编码修改
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
      /**
       * 获取编码后的文件名
       *
       * @param request
       * @param fileName
       * @return
       */
      public static String getEncodeName(HttpServletRequest request, String fileName) {
          String userAgent = request.getHeader("User-Agent");
          if (userAgent.contains("MSIE") || userAgent.contains("Trident") || userAgent.contains("Postman")) {
              try {
                  fileName = URLEncoder.encode(fileName, "UTF-8");
              } catch (UnsupportedEncodingException e) {
                  e.printStackTrace();
              }
          } else {// 非IE浏览器的处理:
              fileName = new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
          }
          return fileName;
      }
59d58c08   姜超   feature(*): excel...
168
  
baf571c2   姜超   feature(*): 查询员工星...
169
      /**
8464701b   姜超   feature(*): 绩效组变动通知
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
       * 实时查询在职员工
       *
       * @param userId
       * @return
       */
      public List<StaffBaseInfoDTO> queryRealTimeManageStaffs(Long userId) {
          List<StaffBaseInfoDTO> managerStaffs = ehrRpcService.queryManageStaffs(userId);
          if (PublicUtil.isEmpty(managerStaffs)) {
              managerStaffs = new ArrayList<>();
          }
          List<StaffBaseInfoDTO> selectVOS = managerStaffs.stream()
                  .filter(staff -> (! staff.getId().equals(userId)))
                  .collect(Collectors.toList());
          return selectVOS;
      }
  
      /**
baf571c2   姜超   feature(*): 查询员工星...
187
188
189
190
191
192
193
194
195
196
197
       * 查询离职、在职员工
       *
       * @param userId
       * @param yearMonth
       * @return
       */
      public List<StaffBaseInfoDTO> queryManageStaffs(Long userId, YearMonth yearMonth) {
          List<StaffBaseInfoDTO> managerStaffs = ehrRpcService.queryManageStaffs(userId);
          if (PublicUtil.isEmpty(managerStaffs)) {
              managerStaffs = new ArrayList<>();
          }
45c0814e   姜超   feature(*): 薪酬查询调整
198
199
200
201
202
203
          LocalDate startDate = LocalDate.of(yearMonth.getYear(), yearMonth.getMonth(), 1);
          LocalDate endDate = startDate.with(TemporalAdjusters.lastDayOfMonth());
          LocalDateTime startDateTime = LocalDateTime.of(startDate, LocalTime.MIN);
          LocalDateTime endDateTime = LocalDateTime.of(endDate, LocalTime.MAX);
          Date firstDayOfMonth = Date.from(startDateTime.atZone(ZoneId.systemDefault()).toInstant());
          Date endDayOfMonth = Date.from(endDateTime.atZone(ZoneId.systemDefault()).toInstant());
baf571c2   姜超   feature(*): 查询员工星...
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
          List<StaffBaseInfoDTO> leaveManagerStaffs = ehrRpcService.queryLeaveManageStaffs(userId, firstDayOfMonth, endDayOfMonth);
          if (PublicUtil.isNotEmpty(leaveManagerStaffs)) {
              managerStaffs.addAll(leaveManagerStaffs);
          }
          List<StaffBaseInfoDTO> selectVOS = managerStaffs.stream()
                  .filter(staff -> (! staff.getId().equals(userId)))
                  .collect(Collectors.toList());
          return selectVOS;
      }
  
      /**
       * 查询离职、在职员工id
       *
       * @param userId
       * @param yearMonth
       * @return
       */
      public List<Long> queryManageStaffIds(Long userId, YearMonth yearMonth) {
          List<StaffBaseInfoDTO> staffBaseInfoDTOS = this.queryManageStaffs(userId, yearMonth);
          if (PublicUtil.isNotEmpty(staffBaseInfoDTOS)) {
              return staffBaseInfoDTOS.stream().map(StaffBaseInfoDTO::getId).collect(Collectors.toList());
          }
          return new ArrayList<>();
      }
  
a7a26e53   姜超   feature(*): 支付薪酬查看
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
      /**
       * 查询离职员工id
       *
       * @param shopId
       * @param yearMonth
       * @return
       */
      public List<Long> queryShopLeaveStaffIds(Long shopId, YearMonth yearMonth) {
          List<Long> shopIds = new ArrayList<Long>(){{add(shopId);}};
  
          LocalDate startDate = LocalDate.of(yearMonth.getYear(), yearMonth.getMonth(), 1);
          LocalDate endDate = startDate.with(TemporalAdjusters.lastDayOfMonth());
          LocalDateTime startDateTime = LocalDateTime.of(startDate, LocalTime.MIN);
          LocalDateTime endDateTime = LocalDateTime.of(endDate, LocalTime.MAX);
          Date firstDayOfMonth = Date.from(startDateTime.atZone(ZoneId.systemDefault()).toInstant());
          Date endDayOfMonth = Date.from(endDateTime.atZone(ZoneId.systemDefault()).toInstant());
  
          List<StaffBaseInfoDTO> staffBaseInfoDTOS = ehrRpcService.queryShopLeaveStaff(shopIds, firstDayOfMonth, endDayOfMonth);
          if (PublicUtil.isNotEmpty(staffBaseInfoDTOS)) {
              return staffBaseInfoDTOS.stream().map(StaffBaseInfoDTO::getId).collect(Collectors.toList());
          }
          return new ArrayList<>();
      }
  
3d4edc47   姜超   feature(*): 薪酬项目下钻
253
254
255
256
257
258
259
      /**
       * 查询具体指标值
       * @param indicatorCode
       * @param indicatorUserValue
       * @return
       */
      public BigDecimal queryIndicatorValue(String indicatorCode, IndicatorUserValue indicatorUserValue) {
c06a04fb   姜超   feature(*): 考评指标详情
260
261
262
          if (PublicUtil.isEmpty(indicatorUserValue)) {
              return BigDecimal.ZERO;
          }
3d4edc47   姜超   feature(*): 薪酬项目下钻
263
264
265
266
267
268
269
270
271
272
273
274
275
276
          BigDecimal value = BigDecimal.ZERO;
          //条件计算类型 是车系id:销售台数
          if (IndicatorValueTypeEnum.CONDITION.equals(indicatorUserValue.getValueType())) {
              return value;
          }
          try {
              JSONObject jsonObject = JSONObject.parseObject(indicatorUserValue.getIndicatorValue());
              value = Optional.ofNullable(jsonObject.getBigDecimal(indicatorCode)).orElse(BigDecimal.ZERO);
          } catch (Exception e) {
              log.error("[{}]指标值转化失败", indicatorCode, e);
          }
          return value;
      }
  
99471c63   姜超   feature(*): 指标排名
277
278
279
      /**
       * 查询具体指标值
       * @param indicatorCode
c06a04fb   姜超   feature(*): 考评指标详情
280
281
282
283
284
285
286
287
       * @param indicatorValue
       * @return
       */
      public BigDecimal queryEvalIndicatorValue(String indicatorCode, EvalIndicatorValue indicatorValue) {
          if (PublicUtil.isEmpty(indicatorValue)) {
              return BigDecimal.ZERO;
          }
          BigDecimal value = BigDecimal.ZERO;
c06a04fb   姜超   feature(*): 考评指标详情
288
          try {
554c0be5   姜超   feature(*): 修改属性
289
              value = Optional.ofNullable(indicatorValue.getIndicatorValue()).orElse(BigDecimal.ZERO);
c06a04fb   姜超   feature(*): 考评指标详情
290
291
292
293
294
295
296
297
298
          } catch (Exception e) {
              log.error("[{}]指标值转化失败", indicatorCode, e);
          }
          return value;
      }
  
      /**
       * 查询具体指标值
       * @param indicatorCode
99471c63   姜超   feature(*): 指标排名
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
       * @param indicatorUserValue
       * @return
       */
      public BigDecimal queryIndicatorValueVO(String indicatorCode, IndicatorUserValueVO indicatorUserValue) {
          BigDecimal value = BigDecimal.ZERO;
          //条件计算类型 是车系id:销售台数
          if (IndicatorValueTypeEnum.CONDITION.equals(indicatorUserValue.getValueType())) {
              return value;
          }
          try {
              JSONObject jsonObject = JSONObject.parseObject(indicatorUserValue.getIndicatorValue());
              value = Optional.ofNullable(jsonObject.getBigDecimal(indicatorCode)).orElse(BigDecimal.ZERO);
              if (IndicatorValueTypeEnum.RATIO.equals(indicatorUserValue.getValueType())) {
                  value = value.multiply(Constant.ONE_HUNDRED);
              }
          } catch (Exception e) {
              log.error("[{}]指标值转化失败", indicatorCode, e);
          }
          return value;
      }
  
0a90b3d7   姜超   feature(*): 考评组审批修改
320
      /**
bdcc7a51   姜超   feature(*): 查询指标排名
321
322
323
324
325
326
327
328
       * 查询具体指标值
       * @param indicatorCode
       * @param indicatorUserValue
       * @return
       */
      public BigDecimal queryEvalIndicatorValueVO(String indicatorCode, EvalIndicatorValue indicatorUserValue) {
          BigDecimal value = BigDecimal.ZERO;
          //条件计算类型 是车系id:销售台数
bdcc7a51   姜超   feature(*): 查询指标排名
329
          try {
554c0be5   姜超   feature(*): 修改属性
330
331
              value = Optional.ofNullable(indicatorUserValue.getIndicatorValue()).orElse(BigDecimal.ZERO);
              if (DataTypeEnum.RATIO.equals(indicatorUserValue.getDataType())) {
bdcc7a51   姜超   feature(*): 查询指标排名
332
333
334
335
336
337
338
339
340
                  value = value.multiply(Constant.ONE_HUNDRED);
              }
          } catch (Exception e) {
              log.error("[{}]指标值转化失败", indicatorCode, e);
          }
          return value;
      }
  
      /**
0a90b3d7   姜超   feature(*): 考评组审批修改
341
342
343
344
345
346
347
348
349
350
351
352
353
       * 是否拥有管理角色
       *
       * @return
       */
      public Boolean hasManagerRole(List<String> roleCodes) {
          if (PublicUtil.isEmpty(roleCodes)) {
              return Boolean.FALSE;
          }
          HashSet<String> roleCodeSet = new HashSet<>(roleCodes);
          return Arrays.stream(RoleManagerEnum.values())
                  .anyMatch(roleManagerEnum -> roleCodeSet.contains(roleManagerEnum.getCode()));
      }
  
98223590   姜超   Merge branch 'mai...
354
      /**
41a1d9fe   姜超   feature(*): 考评草稿修改
355
356
357
358
359
360
361
       * 获取重名的草稿
       *
       * @param name
       * @param type
       * @param excludeDraftId
       * @return
       */
eb829e71   姜超   feature(*): 绩效组重复...
362
      public List<SettingDraft> getEditDraftByName(String name, SettingDraftTypeEnum type, Long excludeDraftId) {
41a1d9fe   姜超   feature(*): 考评草稿修改
363
364
365
          List<SettingDraft> settingDrafts = settingDraftService.list(Wrappers.<SettingDraft>lambdaQuery()
                  .eq(SettingDraft::getName, name)
                  .eq(SettingDraft::getType, type)
eb829e71   姜超   feature(*): 绩效组重复...
366
                  .ne(SettingDraft::getStatus, SettingDraftStatusEnum.RELEASE_APPROVAL_AGREE)
41a1d9fe   姜超   feature(*): 考评草稿修改
367
368
369
370
371
372
                  .ne(PublicUtil.isNotEmpty(excludeDraftId), SettingDraft::getId, excludeDraftId)
                  .eq(SettingDraft::getYn, Boolean.TRUE)
          );
          return settingDrafts;
      }
  
5ff2c525   姜超   feature(*): 并列排名计算
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
      /**
       * 设置排名序号
       *
       * @return
       */
      public void calcRank(List<EvalGroupRewardRankLog> rankLogs) {
          int rank = 1;
          BigDecimal lastIndicatorValue = null;
          for (EvalGroupRewardRankLog rankLog : rankLogs) {
              //初始化
              if (PublicUtil.isEmpty(lastIndicatorValue)) {
                  rankLog.setRank(rank);
                  lastIndicatorValue = rankLog.getReachValue();
                  continue;
              }
              if (lastIndicatorValue.compareTo(rankLog.getReachValue()) != 0) {
                  rank++;
              }
              rankLog.setRank(rank);
              lastIndicatorValue = rankLog.getReachValue();
          }
      }
  
fc885c22   姜超   feature(*): 绩效组阶梯...
396
  }