Blame view

fw-morax-service/src/main/java/cn/fw/morax/service/biz/eval/EvalGroupBizService.java 45.7 KB
028bb253   姜超   feature(*): 考评组相关文件
1
2
  package cn.fw.morax.service.biz.eval;
  
1a21d9d4   姜超   feature(*): 考评导入修改
3
  import cn.fw.common.data.mybatis.pagination.PageData;
a3d13c97   姜超   feature(*): 考评组保存
4
  import cn.fw.common.exception.BusinessException;
1a21d9d4   姜超   feature(*): 考评导入修改
5
  import cn.fw.common.page.AppPage;
028bb253   姜超   feature(*): 考评组相关文件
6
7
8
9
  import cn.fw.common.web.annotation.DisLock;
  import cn.fw.common.web.auth.LoginAuthBean;
  import cn.fw.morax.common.config.FlowVal;
  import cn.fw.morax.common.constant.Constant;
556ff3c3   姜超   feature(*): 考评草稿
10
  import cn.fw.morax.common.pojo.event.ApprovalResultEvent;
028bb253   姜超   feature(*): 考评组相关文件
11
  import cn.fw.morax.common.utils.PublicUtil;
556ff3c3   姜超   feature(*): 考评草稿
12
13
  import cn.fw.morax.domain.db.ApprovalRecord;
  import cn.fw.morax.domain.db.SettingDraft;
a3d13c97   姜超   feature(*): 考评组保存
14
  import cn.fw.morax.domain.db.eval.*;
1a21d9d4   姜超   feature(*): 考评导入修改
15
  import cn.fw.morax.domain.db.kpi.KpiGroup;
fc5db912   姜超   feature(*): 新增台阶类型
16
  import cn.fw.morax.domain.db.kpi.KpiGroupIndicatorLadders;
36a2a360   姜超   feature(*): 禁用考评
17
  import cn.fw.morax.domain.db.kpi.KpiPool;
028bb253   姜超   feature(*): 考评组相关文件
18
  import cn.fw.morax.domain.dto.eval.*;
556ff3c3   姜超   feature(*): 考评草稿
19
  import cn.fw.morax.domain.dto.kpi.KpiGroupDTO;
ffdae9fa   姜超   feature(*): 上报数据修改
20
21
22
  import cn.fw.morax.domain.dto.kpi.KpiGroupIndicatorDTO;
  import cn.fw.morax.domain.dto.kpi.KpiGroupIndicatorParamDTO;
  import cn.fw.morax.domain.dto.kpi.KpiGroupIndicatorPreconditionDTO;
1a21d9d4   姜超   feature(*): 考评导入修改
23
24
  import cn.fw.morax.domain.dto.query.EvalGroupQueryDTO;
  import cn.fw.morax.domain.dto.query.KpiGroupQueryDTO;
280563a2   姜超   feature(*): 考评组保存
25
  import cn.fw.morax.domain.enums.*;
b1409572   姜超   feature(*): 考评组保存
26
  import cn.fw.morax.domain.vo.eval.*;
ffdae9fa   姜超   feature(*): 上报数据修改
27
  import cn.fw.morax.domain.vo.kpi.KpiGroupIndicatorTargetVO;
fc5db912   姜超   feature(*): 新增台阶类型
28
  import cn.fw.morax.domain.vo.kpi.KpiGroupIndicatorVO;
556ff3c3   姜超   feature(*): 考评草稿
29
  import cn.fw.morax.domain.vo.kpi.KpiGroupSavePromptVO;
1a21d9d4   姜超   feature(*): 考评导入修改
30
  import cn.fw.morax.domain.vo.kpi.KpiGroupVO;
028bb253   姜超   feature(*): 考评组相关文件
31
  import cn.fw.morax.rpc.approval.FlowApproveRpc;
280563a2   姜超   feature(*): 考评组保存
32
  import cn.fw.morax.service.biz.ApprovalBizService;
a3d13c97   姜超   feature(*): 考评组保存
33
  import cn.fw.morax.service.biz.CommonService;
028bb253   姜超   feature(*): 考评组相关文件
34
35
  import cn.fw.morax.service.biz.kpi.KpiGroupUserBizService;
  import cn.fw.morax.service.data.ApprovalRecordService;
556ff3c3   姜超   feature(*): 考评草稿
36
  import cn.fw.morax.service.data.SettingDraftService;
028bb253   姜超   feature(*): 考评组相关文件
37
  import cn.fw.morax.service.data.eval.*;
556ff3c3   姜超   feature(*): 考评草稿
38
39
  import com.alibaba.fastjson.JSON;
  import com.alibaba.fastjson.JSONObject;
a3d13c97   姜超   feature(*): 考评组保存
40
  import com.baomidou.mybatisplus.core.toolkit.Wrappers;
028bb253   姜超   feature(*): 考评组相关文件
41
42
43
44
45
46
47
  import lombok.Getter;
  import lombok.RequiredArgsConstructor;
  import lombok.extern.slf4j.Slf4j;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
  
a3d13c97   姜超   feature(*): 考评组保存
48
  import java.math.BigDecimal;
028bb253   姜超   feature(*): 考评组相关文件
49
  import java.math.RoundingMode;
7060fbd3   姜超   feature(*): 修改代码格式
50
  import java.time.LocalDate;
36a2a360   姜超   feature(*): 禁用考评
51
  import java.time.YearMonth;
a3d13c97   姜超   feature(*): 考评组保存
52
  import java.util.*;
b1409572   姜超   feature(*): 考评组保存
53
  import java.util.stream.Collectors;
a3d13c97   姜超   feature(*): 考评组保存
54
55
  
  import static cn.fw.common.businessvalidator.Validator.BV;
028bb253   姜超   feature(*): 考评组相关文件
56
57
58
59
60
61
  
  @Service
  @Slf4j
  @RequiredArgsConstructor
  public class EvalGroupBizService {
  
a3d13c97   姜超   feature(*): 考评组保存
62
63
64
65
66
67
68
69
70
      private final EvalGroupIndicatorPreconditionLaddersService evalGroupIndicatorPreconditionLaddersService;
      private final EvalGroupIndicatorPreconditionService evalGroupIndicatorPreconditionService;
      private final EvalGroupRewardPreconditionService evalGroupRewardPreconditionService;
      private final EvalGroupIndicatorLaddersService evalGroupIndicatorLaddersService;
      private final EvalGroupIndicatorParamService evalGroupIndicatorParamService;
      private final EvalGroupRewardLaddersService evalGroupRewardLaddersService;
      private final EvalGroupRewardParamService evalGroupRewardParamService;
      private final EvalGroupIndicatorService evalGroupIndicatorService;
      private final EvalGroupRewardService evalGroupRewardService;
280563a2   姜超   feature(*): 考评组保存
71
      private final EvalGroupDataService evalGroupDataService;
36a2a360   姜超   feature(*): 禁用考评
72
73
      private final EvalUserPoolService evalUserPoolService;
      private final EvalShopPoolService evalShopPoolService;
028bb253   姜超   feature(*): 考评组相关文件
74
      private final EvalGroupService evalGroupService;
2b0da87e   姜超   feature(*): 新增考评表
75
      private final EvalService evalService;
556ff3c3   姜超   feature(*): 考评草稿
76
      private final SettingDraftService settingDraftService;
280563a2   姜超   feature(*): 考评组保存
77
      private final ApprovalBizService approvalBizService;
028bb253   姜超   feature(*): 考评组相关文件
78
  
b1409572   姜超   feature(*): 考评组保存
79
      @Value("${spring.cache.custom.global-prefix}:eval:save:")
028bb253   姜超   feature(*): 考评组相关文件
80
81
82
83
84
      @Getter
      private String saveGroupPrefix;
  
  
      /**
280563a2   姜超   feature(*): 考评组保存
85
       * 考评组保存
028bb253   姜超   feature(*): 考评组相关文件
86
87
88
89
90
91
       *
       * @param dto
       * @param user
       * @return
       */
      @Transactional(rollbackFor = Exception.class)
41a1d9fe   姜超   feature(*): 考评草稿修改
92
      @DisLock(prefix = "#this.getSaveGroupPrefix()", key = "#dto.getName()", message = "保存中,请勿重复操作")
556ff3c3   姜超   feature(*): 考评草稿
93
      public void saveEvalGroup(EvalDTO dto, LoginAuthBean user, Boolean isSubmit) {
2b0da87e   姜超   feature(*): 新增考评表
94
95
  
          for (EvalGroupDTO evalGroupDTO : dto.getEvalGroups()) {
936e630c   姜超   feature(*): 门店奖惩分配
96
              initEvalGroupDTO(evalGroupDTO);
9dd1f916   姜超   feature(*): 指标启用禁用
97
              checkTime(evalGroupDTO);
2b0da87e   姜超   feature(*): 新增考评表
98
99
100
101
102
              checkNameRepetition(dto.getId(), dto.getName());
              checkIndicator(evalGroupDTO);
              checkReward(evalGroupDTO);
              checkEvalIndicatorLadders(evalGroupDTO.getIndicators());
              checkEvalRewardLadders(evalGroupDTO.getRewards());
ffdae9fa   姜超   feature(*): 上报数据修改
103
              setTargetVos(evalGroupDTO);
2b0da87e   姜超   feature(*): 新增考评表
104
          }
077e6941   姜超   feature(*): 草稿修改
105
          SettingDraft settingDraft = getSettingDraft(dto, isSubmit);
556ff3c3   姜超   feature(*): 考评草稿
106
107
108
109
          settingDraftService.saveOrUpdate(settingDraft);
          if (! isSubmit) {
              return;
          }
2b0da87e   姜超   feature(*): 新增考评表
110
  
556ff3c3   姜超   feature(*): 考评草稿
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
  //        Eval eval = evalGroupDataService.saveEval(dto);
  //        for (EvalGroupDTO evalGroupDTO : dto.getEvalGroups()) {
  //            EvalGroup evalGroup = evalGroupDataService.saveEvalGroup(evalGroupDTO, eval);
  //            evalGroupDataService.saveEvalGroupIndicator(evalGroup, evalGroupDTO.getIndicators());
  //            evalGroupDataService.saveEvalGroupReward(evalGroup, evalGroupDTO.getRewards());
  //        }
          approvalBizService.applyApproveEvalDraft(dto, dto.getEvalGroups(), settingDraft, user);
      }
  
      /**
       * 获取草稿
       *
       * @param dto
       * @return
       */
077e6941   姜超   feature(*): 草稿修改
126
      public SettingDraft getSettingDraft(EvalDTO dto, Boolean submit) {
556ff3c3   姜超   feature(*): 考评草稿
127
128
129
130
131
132
          SettingDraft settingDraft = null;
          if (PublicUtil.isEmpty(dto.getDraftId())) {
              settingDraft = new SettingDraft();
              settingDraft.setGroupId(dto.getGroupId());
              settingDraft.setYn(Boolean.TRUE);
              settingDraft.setType(SettingDraftTypeEnum.EVAL);
556ff3c3   姜超   feature(*): 考评草稿
133
134
135
          } else {
              settingDraft = settingDraftService.getById(dto.getDraftId());
              BV.notNull(settingDraft, "草稿配置不存在,请重试");
2b0da87e   姜超   feature(*): 新增考评表
136
          }
077e6941   姜超   feature(*): 草稿修改
137
          settingDraft.setStatus(submit ? SettingDraftStatusEnum.RELEASE_APPROVAL : SettingDraftStatusEnum.NO_RELEASE);
556ff3c3   姜超   feature(*): 考评草稿
138
          settingDraft.setEvalType(dto.getType());
936e630c   姜超   feature(*): 门店奖惩分配
139
          settingDraft.setName(dto.getName());
556ff3c3   姜超   feature(*): 考评草稿
140
141
          settingDraft.setContent(JSONObject.toJSONString(dto));
          return settingDraft;
280563a2   姜超   feature(*): 考评组保存
142
      }
a3d13c97   姜超   feature(*): 考评组保存
143
  
280563a2   姜超   feature(*): 考评组保存
144
      /**
ffdae9fa   姜超   feature(*): 上报数据修改
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
       * 装换为目标对象
       *
       * @return
       */
      public void setTargetVos(EvalGroupDTO evalGroupDTO) {
  
          for (EvalGroupIndicatorDTO indicatorDTO : evalGroupDTO.getIndicators()) {
              List<EvalGroupIndicatorParamDTO> ladderParams = Optional.ofNullable(indicatorDTO.getLadderParams()).orElse(new ArrayList<>());
              List<EvalGroupIndicatorParamDTO> commissionParams = Optional.ofNullable(indicatorDTO.getCommissionParams()).orElse(new ArrayList<>());
              List<EvalGroupIndicatorPreconditionDTO> conds = Optional.ofNullable(indicatorDTO.getConds()).orElse(new ArrayList<>());
  
              List<EvalGroupIndicatorTargetVO> targetVOS = new ArrayList<>();
              for (EvalGroupIndicatorParamDTO paramDTO : ladderParams) {
                  if (PublicUtil.isNotEmpty(paramDTO.getTargetType()) && (! TargetTypeEnum.NO.equals(paramDTO.getTargetType()))) {
                      EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(paramDTO, EvalGroupIndicatorTargetVO.class);
                      targetVOS.add(targetVO);
                  }
              }
  
              for (EvalGroupIndicatorParamDTO paramDTO : commissionParams) {
                  if (PublicUtil.isNotEmpty(paramDTO.getTargetType()) && (! TargetTypeEnum.NO.equals(paramDTO.getTargetType()))) {
                      EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(paramDTO, EvalGroupIndicatorTargetVO.class);
                      targetVOS.add(targetVO);
                  }
              }
  
              for (EvalGroupIndicatorPreconditionDTO preconditionDTO : conds) {
                  if (PublicUtil.isNotEmpty(preconditionDTO.getTargetType()) && (! TargetTypeEnum.NO.equals(preconditionDTO.getTargetType()))) {
                      EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(preconditionDTO, EvalGroupIndicatorTargetVO.class);
                      targetVOS.add(targetVO);
                  }
              }
  
              indicatorDTO.setTargets(targetVOS);
          }
  
          for (EvalGroupRewardDTO rewardDTO : evalGroupDTO.getRewards()) {
              List<EvalGroupRewardParamDTO> ladderParams = Optional.ofNullable(rewardDTO.getLadderParams()).orElse(new ArrayList<>());
              List<EvalGroupRewardParamDTO> commissionParams = Optional.ofNullable(rewardDTO.getCommissionParams()).orElse(new ArrayList<>());
              List<EvalGroupRewardPreconditionDTO> conds = Optional.ofNullable(rewardDTO.getConds()).orElse(new ArrayList<>());
  
              List<EvalGroupIndicatorTargetVO> targetVOS = new ArrayList<>();
              for (EvalGroupRewardParamDTO paramDTO : ladderParams) {
                  if (PublicUtil.isNotEmpty(paramDTO.getTargetType()) && (! TargetTypeEnum.NO.equals(paramDTO.getTargetType()))) {
                      EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(paramDTO, EvalGroupIndicatorTargetVO.class);
                      targetVOS.add(targetVO);
                  }
              }
  
              for (EvalGroupRewardParamDTO paramDTO : commissionParams) {
                  if (PublicUtil.isNotEmpty(paramDTO.getTargetType()) && (! TargetTypeEnum.NO.equals(paramDTO.getTargetType()))) {
                      EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(paramDTO, EvalGroupIndicatorTargetVO.class);
                      targetVOS.add(targetVO);
                  }
              }
  
              for (EvalGroupRewardPreconditionDTO preconditionDTO : conds) {
                  if (PublicUtil.isNotEmpty(preconditionDTO.getTargetType()) && (! TargetTypeEnum.NO.equals(preconditionDTO.getTargetType()))) {
                      EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(preconditionDTO, EvalGroupIndicatorTargetVO.class);
                      targetVOS.add(targetVO);
                  }
              }
              rewardDTO.setTargets(targetVOS);
          }
      }
  
      /**
       * 装换为目标对象
       *
       * @return
       */
      public void setTargetVos(EvalGroupVO evalGroupVO) {
  
          for (EvalGroupIndicatorVO indicatorDTO : evalGroupVO.getIndicators()) {
              List<EvalGroupIndicatorParamVO> ladderParams = Optional.ofNullable(indicatorDTO.getLadderParams()).orElse(new ArrayList<>());
              List<EvalGroupIndicatorParamVO> commissionParams = Optional.ofNullable(indicatorDTO.getCommissionParams()).orElse(new ArrayList<>());
              List<EvalGroupIndicatorPreconditionVO> conds = Optional.ofNullable(indicatorDTO.getConds()).orElse(new ArrayList<>());
  
              List<EvalGroupIndicatorTargetVO> targetVOS = new ArrayList<>();
              for (EvalGroupIndicatorParamVO paramDTO : ladderParams) {
                  if (PublicUtil.isNotEmpty(paramDTO.getTargetType()) && (! TargetTypeEnum.NO.equals(paramDTO.getTargetType()))) {
                      EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(paramDTO, EvalGroupIndicatorTargetVO.class);
                      targetVOS.add(targetVO);
                  }
              }
  
              for (EvalGroupIndicatorParamVO paramDTO : commissionParams) {
                  if (PublicUtil.isNotEmpty(paramDTO.getTargetType()) && (! TargetTypeEnum.NO.equals(paramDTO.getTargetType()))) {
                      EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(paramDTO, EvalGroupIndicatorTargetVO.class);
                      targetVOS.add(targetVO);
                  }
              }
  
              for (EvalGroupIndicatorPreconditionVO preconditionDTO : conds) {
                  if (PublicUtil.isNotEmpty(preconditionDTO.getTargetType()) && (! TargetTypeEnum.NO.equals(preconditionDTO.getTargetType()))) {
                      EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(preconditionDTO, EvalGroupIndicatorTargetVO.class);
                      targetVOS.add(targetVO);
                  }
              }
  
              indicatorDTO.setTargets(targetVOS);
          }
  
          for (EvalGroupRewardVO rewardDTO : evalGroupVO.getRewards()) {
              List<EvalGroupRewardParamVO> ladderParams = Optional.ofNullable(rewardDTO.getLadderParams()).orElse(new ArrayList<>());
              List<EvalGroupRewardParamVO> commissionParams = Optional.ofNullable(rewardDTO.getCommissionParams()).orElse(new ArrayList<>());
              List<EvalGroupRewardPreconditionVO> conds = Optional.ofNullable(rewardDTO.getConds()).orElse(new ArrayList<>());
  
              List<EvalGroupIndicatorTargetVO> targetVOS = new ArrayList<>();
              for (EvalGroupRewardParamVO paramDTO : ladderParams) {
                  if (PublicUtil.isNotEmpty(paramDTO.getTargetType()) && (! TargetTypeEnum.NO.equals(paramDTO.getTargetType()))) {
                      EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(paramDTO, EvalGroupIndicatorTargetVO.class);
                      targetVOS.add(targetVO);
                  }
              }
  
              for (EvalGroupRewardParamVO paramDTO : commissionParams) {
                  if (PublicUtil.isNotEmpty(paramDTO.getTargetType()) && (! TargetTypeEnum.NO.equals(paramDTO.getTargetType()))) {
                      EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(paramDTO, EvalGroupIndicatorTargetVO.class);
                      targetVOS.add(targetVO);
                  }
              }
  
              for (EvalGroupRewardPreconditionVO preconditionDTO : conds) {
                  if (PublicUtil.isNotEmpty(preconditionDTO.getTargetType()) && (! TargetTypeEnum.NO.equals(preconditionDTO.getTargetType()))) {
                      EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(preconditionDTO, EvalGroupIndicatorTargetVO.class);
                      targetVOS.add(targetVO);
                  }
              }
              rewardDTO.setTargets(targetVOS);
          }
      }
  
      /**
9dd1f916   姜超   feature(*): 指标启用禁用
279
280
281
282
       * 检查时间
       *
       * @param dto
       */
936e630c   姜超   feature(*): 门店奖惩分配
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
      public void initEvalGroupDTO(EvalGroupDTO dto) {
          for (EvalGroupIndicatorDTO indicatorDTO : dto.getIndicators()) {
              if (PublicUtil.isEmpty(indicatorDTO.getLadderParams())) {
                  indicatorDTO.setLadderParams(new ArrayList<>());
              }
              if (PublicUtil.isEmpty(indicatorDTO.getCommissionParams())) {
                  indicatorDTO.setCommissionParams(new ArrayList<>());
              }
              if (PublicUtil.isEmpty(indicatorDTO.getLadders())) {
                  indicatorDTO.setLadders(new ArrayList<>());
              }
              if (PublicUtil.isEmpty(indicatorDTO.getConds())) {
                  indicatorDTO.setConds(new ArrayList<>());
              }
          }
          for (EvalGroupRewardDTO rewardDTO : dto.getRewards()) {
              if (PublicUtil.isEmpty(rewardDTO.getLadderParams())) {
                  rewardDTO.setLadderParams(new ArrayList<>());
              }
              if (PublicUtil.isEmpty(rewardDTO.getCommissionParams())) {
                  rewardDTO.setCommissionParams(new ArrayList<>());
              }
              if (PublicUtil.isEmpty(rewardDTO.getLadders())) {
                  rewardDTO.setLadders(new ArrayList<>());
              }
              if (PublicUtil.isEmpty(rewardDTO.getConds())) {
                  rewardDTO.setConds(new ArrayList<>());
              }
          }
      }
      /**
       * 检查时间
       *
       * @param dto
       */
9dd1f916   姜超   feature(*): 指标启用禁用
318
      public void checkTime(EvalGroupDTO dto) {
eee77f4e   姜超   feature(*): 负数排名设置
319
  //        BV.isTrue(dto.getBeginTime().isBefore(dto.getOverTime()), "考评组【" + dto.getName()+ "】生效时间必须在结束时间之前");
7060fbd3   姜超   feature(*): 修改代码格式
320
321
322
323
324
325
326
327
328
329
330
331
332
  
          if (PublicUtil.isNotEmpty(dto.getId())) {
              List<EvalGroup> evalGroups = evalGroupService.list(Wrappers.<EvalGroup>lambdaQuery()
                      .eq(EvalGroup::getEvalId, dto.getId())
                      .eq(EvalGroup::getYn, Boolean.TRUE)
              );
              LocalDate now = LocalDate.now();
              Optional<EvalGroup> optionalEvalGroup = evalGroups.stream()
                      .filter(evalGroup -> EvalScopeEnum.SHOP.equals(evalGroup.getScopeType()) && now.equals(evalGroup.getOverTime())).findFirst();
              if (optionalEvalGroup.isPresent()) {
                  throw new BusinessException("考评组 " + optionalEvalGroup.get().getName() + "已结束,不能编辑");
              }
          }
9dd1f916   姜超   feature(*): 指标启用禁用
333
334
335
      }
  
      /**
280563a2   姜超   feature(*): 考评组保存
336
337
338
339
340
341
       * 检查绩效组排名名称是否重复
       *
       * @param id
       * @param name
       */
      public void checkNameRepetition(Long id, String name) {
98223590   姜超   Merge branch 'mai...
342
          int count = evalGroupService.count(Wrappers.<EvalGroup>lambdaQuery()
280563a2   姜超   feature(*): 考评组保存
343
344
345
                  .eq(EvalGroup::getName, name)
                  .ne(PublicUtil.isNotEmpty(id), EvalGroup::getId, id)
                  .eq(EvalGroup::getYn, Boolean.TRUE)
07e83c73   姜超   feature(*): 考评组修改
346
  //                .eq(EvalGroup::getStatus, SettingStatusEnum.EFFECTIVE)
280563a2   姜超   feature(*): 考评组保存
347
348
349
          );
          BV.isTrue(count <= 0, "绩效组名称重复,请重新输入");
      }
028bb253   姜超   feature(*): 考评组相关文件
350
  
280563a2   姜超   feature(*): 考评组保存
351
352
353
354
355
356
357
358
359
      /**
       * 检查阶梯分值
       * @param indicators
       */
      private void checkEvalIndicatorLadders(List<EvalGroupIndicatorDTO> indicators) {
          Integer baseScore = null;
          for (EvalGroupIndicatorDTO indicatorDto : indicators) {
              if (ScoreWayEnum.NORMAL.equals(indicatorDto.getScoreWay())) {
                  continue;
a3d13c97   姜超   feature(*): 考评组保存
360
361
              }
  
280563a2   姜超   feature(*): 考评组保存
362
363
364
              baseScore = indicatorDto.getBaseScore();
              List<EvalGroupIndicatorLaddersDTO> ladders = indicatorDto.getLadders();
              Collections.sort(ladders);
a3d13c97   姜超   feature(*): 考评组保存
365
  
280563a2   姜超   feature(*): 考评组保存
366
367
              //阶梯值校验  标准分不能超过指标基础分,阶梯值必须连续
              for (EvalGroupIndicatorLaddersDTO laddersDto : ladders) {
08c31209   姜超   feature(*): 考评详情
368
369
370
                  BV.isTrue(PublicUtil.isNotEmpty(laddersDto.getLower()), "阶梯下限不能为空");
                  BV.isTrue(PublicUtil.isNotEmpty(laddersDto.getUpper()), "阶梯上限不能为空");
  
280563a2   姜超   feature(*): 考评组保存
371
372
373
                  //阶梯标准分不能超过绩效分值
                  if (laddersDto.getStandardScore().compareTo(baseScore) > 0) {
                      throw new BusinessException("【" + indicatorDto.getName() + "】的阶梯标准分不能超过绩效分值");
a3d13c97   姜超   feature(*): 考评组保存
374
                  }
028bb253   姜超   feature(*): 考评组相关文件
375
              }
280563a2   姜超   feature(*): 考评组保存
376
377
              //校验阶梯
              CommonService.checkLadders(ladders, indicatorDto.getName());
028bb253   姜超   feature(*): 考评组相关文件
378
  
280563a2   姜超   feature(*): 考评组保存
379
380
381
382
              //校验条件
              for (EvalGroupIndicatorPreconditionDTO condDTO : indicatorDto.getConds()) {
                  CommonService.checkLadders(condDTO.getLadders(), indicatorDto.getName());
              }
a3d13c97   姜超   feature(*): 考评组保存
383
          }
280563a2   姜超   feature(*): 考评组保存
384
      }
a3d13c97   姜超   feature(*): 考评组保存
385
  
280563a2   姜超   feature(*): 考评组保存
386
387
388
389
390
391
      /**
       * 检查阶梯分值
       * @param rewards
       */
      private void checkEvalRewardLadders(List<EvalGroupRewardDTO> rewards) {
          for (EvalGroupRewardDTO reward : rewards) {
a3d13c97   姜超   feature(*): 考评组保存
392
  
280563a2   姜超   feature(*): 考评组保存
393
394
              String rewardName = reward.getName();
              List<EvalGroupRewardLaddersDTO> ladders = reward.getLadders();
08c31209   姜超   feature(*): 考评详情
395
396
397
              if (EvalRewardCalMethodEnum.RANK.equals(reward.getCalMethod()) ||
                      EvalRewardCalMethodEnum.LADDER.equals(reward.getCalMethod()) ||
                      EvalRewardCalMethodEnum.LADDER_DOUBLE.equals(reward.getCalMethod())) {
b1409572   姜超   feature(*): 考评组保存
398
399
400
401
                  BV.isTrue(PublicUtil.isNotEmpty(ladders), "阶梯不能为空");
                  Collections.sort(ladders);
              }
  
08c31209   姜超   feature(*): 考评详情
402
403
404
405
              for (EvalGroupRewardLaddersDTO ladder : ladders) {
                  BV.isTrue(PublicUtil.isNotEmpty(ladder.getLower()), "阶梯下限不能为空");
                  BV.isTrue(PublicUtil.isNotEmpty(ladder.getUpper()), "阶梯上限不能为空");
              }
280563a2   姜超   feature(*): 考评组保存
406
407
  
              switch (reward.getCalMethod()) {
56739290   姜超   feature(*): 考评组修改
408
                  case TOTAL_PROPORTION: case FIXATION:{
280563a2   姜超   feature(*): 考评组保存
409
410
411
412
413
                      if (PublicUtil.isNotEmpty(ladders)) {
                          throw new BusinessException("计算方式【" + reward.getCalMethod().getName() + "】不能配置阶梯");
                      }
                      break;
                  }
97c9de51   姜超   feature(*): 审批修改
414
  //                case RANK:
08c31209   姜超   feature(*): 考评详情
415
416
417
                  case LADDER:
                  case LADDER_DOUBLE:
                  {
280563a2   姜超   feature(*): 考评组保存
418
419
                      CommonService.checkLadders(ladders, rewardName);
                      break;
a3d13c97   姜超   feature(*): 考评组保存
420
                  }
a3d13c97   姜超   feature(*): 考评组保存
421
              }
a3d13c97   姜超   feature(*): 考评组保存
422
  
a3d13c97   姜超   feature(*): 考评组保存
423
          }
028bb253   姜超   feature(*): 考评组相关文件
424
425
426
      }
  
      /**
a3d13c97   姜超   feature(*): 考评组保存
427
428
429
430
431
432
       * 检查考评组指标
       *
       * @param evalGroupDTO
       */
      public void checkIndicator(EvalGroupDTO evalGroupDTO) {
          for (EvalGroupIndicatorDTO indicator : evalGroupDTO.getIndicators()) {
998f0d0b   姜超   feature(*): 修改计算考评
433
434
435
436
437
438
              String indicatorName = indicator.getName();
  
              if (ScoreWayEnum.LADDER.equals(indicator.getScoreWay())) {
                  BV.notNull(indicator.getLaddersType(), indicatorName + " 台阶数据类型不能为空");
              }
  
a3d13c97   姜超   feature(*): 考评组保存
439
440
441
442
443
              if (PublicUtil.isNotEmpty(indicator.getLadderParams())) {
                  BigDecimal proportion = indicator.getLadderParams().stream()
                          .map(EvalGroupIndicatorParamDTO::getProportion)
                          .reduce(BigDecimal.ZERO, BigDecimal::add);
                  BV.isTrue(Constant.ONE_HUNDRED.compareTo(proportion) == 0, "【" + indicator.getName() + "】台阶占比总和必须为100");
b1409572   姜超   feature(*): 考评组保存
444
445
  
                  for (EvalGroupIndicatorParamDTO paramDTO : indicator.getLadderParams()) {
3042c640   张志伟   :fire:
446
                      if (! TargetTypeEnum.NO.equals(paramDTO.getTargetType()) &&
b1409572   姜超   feature(*): 考评组保存
447
                              (PublicUtil.isEmpty(paramDTO.getTargetType()) || PublicUtil.isEmpty(paramDTO.getTargetValue()))) {
3042c640   张志伟   :fire:
448
                          paramDTO.setTargetType(TargetTypeEnum.NO);
b1409572   姜超   feature(*): 考评组保存
449
450
                      }
                  }
a3d13c97   姜超   feature(*): 考评组保存
451
452
453
454
455
456
457
              }
  
              if (PublicUtil.isNotEmpty(indicator.getCommissionParams())) {
                  BigDecimal proportion = indicator.getCommissionParams().stream()
                          .map(EvalGroupIndicatorParamDTO::getProportion)
                          .reduce(BigDecimal.ZERO, BigDecimal::add);
                  BV.isTrue(Constant.ONE_HUNDRED.compareTo(proportion) == 0, "【" + indicator.getName() + "】提成占比总和必须为100");
a3d13c97   姜超   feature(*): 考评组保存
458
  
b1409572   姜超   feature(*): 考评组保存
459
                  for (EvalGroupIndicatorParamDTO paramDTO : indicator.getCommissionParams()) {
3042c640   张志伟   :fire:
460
                      if (! TargetTypeEnum.NO.equals(paramDTO.getTargetType()) &&
b1409572   姜超   feature(*): 考评组保存
461
                              (PublicUtil.isEmpty(paramDTO.getTargetType()) || PublicUtil.isEmpty(paramDTO.getTargetValue()))) {
3042c640   张志伟   :fire:
462
                          paramDTO.setTargetType(TargetTypeEnum.NO);
b1409572   姜超   feature(*): 考评组保存
463
464
465
                      }
                  }
              }
a3d13c97   姜超   feature(*): 考评组保存
466
  
b1409572   姜超   feature(*): 考评组保存
467
468
              if (PublicUtil.isNotEmpty(indicator.getConds())) {
                  for (EvalGroupIndicatorPreconditionDTO preconditionDTO : indicator.getConds()) {
3042c640   张志伟   :fire:
469
                      if (! TargetTypeEnum.NO.equals(preconditionDTO.getTargetType()) &&
b1409572   姜超   feature(*): 考评组保存
470
                              (PublicUtil.isEmpty(preconditionDTO.getTargetType()) || PublicUtil.isEmpty(preconditionDTO.getTargetValue()))) {
3042c640   张志伟   :fire:
471
                          preconditionDTO.setTargetType(TargetTypeEnum.NO);
b1409572   姜超   feature(*): 考评组保存
472
473
474
                      }
                  }
              }
a3d13c97   姜超   feature(*): 考评组保存
475
  
a3d13c97   姜超   feature(*): 考评组保存
476
477
478
479
480
481
482
483
484
485
486
487
          }
      }
  
      /**
       * 检查考评组指标
       *
       * @param evalGroupDTO
       */
      public void checkReward(EvalGroupDTO evalGroupDTO) {
          for (EvalGroupRewardDTO reward : evalGroupDTO.getRewards()) {
              String rewardName = reward.getName();
  
998f0d0b   姜超   feature(*): 修改计算考评
488
489
490
491
492
493
              if (EvalRewardCalMethodEnum.LADDER.equals(reward.getCalMethod()) ||
                      EvalRewardCalMethodEnum.LADDER_DOUBLE.equals(reward.getCalMethod()) ||
                      EvalRewardCalMethodEnum.RANK.equals(reward.getCalMethod())) {
                  BV.notNull(reward.getLaddersType(), rewardName + " 台阶数据类型不能为空");
              }
  
a3d13c97   姜超   feature(*): 考评组保存
494
495
496
497
498
              if (PublicUtil.isNotEmpty(reward.getCommissionParams())) {
                  BigDecimal proportion = reward.getCommissionParams().stream()
                          .map(EvalGroupRewardParamDTO::getProportion)
                          .reduce(BigDecimal.ZERO, BigDecimal::add);
                  BV.isTrue(Constant.ONE_HUNDRED.compareTo(proportion) == 0, "【" + rewardName + "】台阶占比总和必须为100");
b1409572   姜超   feature(*): 考评组保存
499
500
  
                  for (EvalGroupRewardParamDTO commissionParam : reward.getCommissionParams()) {
3042c640   张志伟   :fire:
501
                      if (! TargetTypeEnum.NO.equals(commissionParam.getTargetType()) &&
b1409572   姜超   feature(*): 考评组保存
502
                              (PublicUtil.isEmpty(commissionParam.getTargetType()) || PublicUtil.isEmpty(commissionParam.getTargetValue()))) {
3042c640   张志伟   :fire:
503
                          commissionParam.setTargetType(TargetTypeEnum.NO);
b1409572   姜超   feature(*): 考评组保存
504
505
                      }
                  }
a3d13c97   姜超   feature(*): 考评组保存
506
507
508
509
510
511
512
              }
  
              if (PublicUtil.isNotEmpty(reward.getLadderParams())) {
                  BigDecimal proportion = reward.getLadderParams().stream()
                          .map(EvalGroupRewardParamDTO::getProportion)
                          .reduce(BigDecimal.ZERO, BigDecimal::add);
                  BV.isTrue(Constant.ONE_HUNDRED.compareTo(proportion) == 0, "【" + rewardName + "】提成占比总和必须为100");
b1409572   姜超   feature(*): 考评组保存
513
514
  
                  for (EvalGroupRewardParamDTO commissionParam : reward.getLadderParams()) {
3042c640   张志伟   :fire:
515
                      if (! TargetTypeEnum.NO.equals(commissionParam.getTargetType()) &&
b1409572   姜超   feature(*): 考评组保存
516
                              (PublicUtil.isEmpty(commissionParam.getTargetType()) || PublicUtil.isEmpty(commissionParam.getTargetValue()))) {
3042c640   张志伟   :fire:
517
                          commissionParam.setTargetType(TargetTypeEnum.NO);
b1409572   姜超   feature(*): 考评组保存
518
519
520
521
522
523
                      }
                  }
              }
  
              if (PublicUtil.isNotEmpty(reward.getConds())) {
                  for (EvalGroupRewardPreconditionDTO preconditionDTO : reward.getConds()) {
3042c640   张志伟   :fire:
524
                      if (! TargetTypeEnum.NO.equals(preconditionDTO.getTargetType()) &&
b1409572   姜超   feature(*): 考评组保存
525
                              (PublicUtil.isEmpty(preconditionDTO.getTargetType()) || PublicUtil.isEmpty(preconditionDTO.getTargetValue()))) {
3042c640   张志伟   :fire:
526
                          preconditionDTO.setTargetType(TargetTypeEnum.NO);
b1409572   姜超   feature(*): 考评组保存
527
528
529
                      }
                  }
              }
b1409572   姜超   feature(*): 考评组保存
530
531
532
533
          }
      }
  
      /**
1a21d9d4   姜超   feature(*): 考评导入修改
534
535
536
537
538
539
540
541
       * 分页查询
       * @param dto
       * @return
       */
      public AppPage<EvalVO> evalPage(EvalGroupQueryDTO dto) {
          PageData<Eval> pageData = evalService.page(new PageData<Eval>(dto.getCurrent(), dto.getPageSize()),
                  Wrappers.<Eval>lambdaQuery()
                          .eq(Eval::getGroupId, dto.getGroupId())
fe6f7227   姜超   feature(*): 考评导入修改
542
                          .eq(PublicUtil.isNotEmpty(dto.getStatus()), Eval::getStatus, dto.getStatus())
1a21d9d4   姜超   feature(*): 考评导入修改
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
                          .eq(Eval::getYn, Boolean.TRUE)
                          .last("ORDER BY FIELD(`status`,3,1,2,4)")
          );
  
  //        Map<Long, String> approvalRecordMap = new HashMap<>();
  //        if (PublicUtil.isNotEmpty(pageData.getRecords())) {
  //            List<Long> evalIds = pageData.getRecords().stream().map(Eval::getId).collect(Collectors.toList());
  //            List<ApprovalRecord> approvalRecords = approvalRecordService.list(Wrappers.<ApprovalRecord>lambdaQuery()
  //                    .in(ApprovalRecord::getDataId, kpiGroupIds)
  //                    .eq(ApprovalRecord::getApprovalType, ApprovalTypeEnum.KPI)
  //                    .eq(ApprovalRecord::getYn, Boolean.TRUE));
  //
  //            approvalRecordMap = approvalRecords.stream().collect(Collectors.toMap(ApprovalRecord::getDataId, ApprovalRecord::getApprovalNo));
  //        }
  //        Map<Long, String> finalApprovalRecordMap = approvalRecordMap;
          return PublicUtil.toPage(pageData, eval -> {
              EvalVO evalVO = PublicUtil.copy(eval, EvalVO.class);
  //            kpiGroupVo.setApprovalNo(finalApprovalRecordMap.getOrDefault(kpiGroup.getId(), ""));
  //            kpiGroupVo.setBeginTime(kpiGroup.getBeginTime());
  //            kpiGroupVo.setOverTime(kpiGroup.getOverTime());
              return evalVO;
          });
      }
  
      /**
b1409572   姜超   feature(*): 考评组保存
568
569
       * 考评组详情
       *
07e83c73   姜超   feature(*): 考评组修改
570
       * @param evalId
b1409572   姜超   feature(*): 考评组保存
571
572
       * @return
       */
07e83c73   姜超   feature(*): 考评组修改
573
      public EvalVO evalDetail(Long evalId) {
07e83c73   姜超   feature(*): 考评组修改
574
575
576
577
578
579
580
581
582
583
584
585
          Eval eval = evalService.getById(evalId);
          BV.notNull(eval, "考评配置不存在,请重试");
          EvalVO evalVO = PublicUtil.copy(eval, EvalVO.class);
  
          List<EvalGroup> evalGroups = evalGroupService.list(Wrappers.<EvalGroup>lambdaQuery()
                  .in(EvalGroup::getEvalId, evalId)
                  .in(EvalGroup::getYn, Boolean.TRUE)
          );
          List<EvalGroupVO> evalGroupVOs = PublicUtil.copyList(evalGroups, EvalGroupVO.class);
          for (EvalGroupVO evalGroupVO : evalGroupVOs) {
              this.setEvalGroupIndicator(evalGroupVO);
              this.setEvalGroupReward(evalGroupVO);
ffdae9fa   姜超   feature(*): 上报数据修改
586
              this.setTargetVos(evalGroupVO);
07e83c73   姜超   feature(*): 考评组修改
587
588
589
590
          }
          evalVO.setEvalGroups(evalGroupVOs);
  
          return evalVO;
b1409572   姜超   feature(*): 考评组保存
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
      }
  
  
      /**
       * 设置奖励
       *
       * @param evalGroupVO
       */
      public void setEvalGroupReward(EvalGroupVO evalGroupVO) {
          Long evalGroupId = evalGroupVO.getId();
          List<EvalGroupReward> rewards = evalGroupRewardService.list(Wrappers.<EvalGroupReward>lambdaQuery()
                  .eq(EvalGroupReward::getEvalGroupId, evalGroupId)
                  .eq(EvalGroupReward::getYn, Boolean.TRUE)
          );
          if (PublicUtil.isNotEmpty(rewards)) {
              List<EvalGroupRewardVO> rewardVOS = PublicUtil.copyList(rewards, EvalGroupRewardVO.class);
              evalGroupVO.setRewards(rewardVOS);
  
              Map<Long, List<EvalGroupRewardParamVO>> rewardParamMap = this.getEvalGroupRewardParamVO(evalGroupId);
4138a206   姜超   feature(*): 考评组保存修改
610
              Map<Long, List<EvalGroupRewardPreconditionVO>> rewardCondMap = this.getEvalGroupRewardPreconditionVO(evalGroupId);
b1409572   姜超   feature(*): 考评组保存
611
612
613
614
615
616
617
618
619
  
              for (EvalGroupRewardVO reward : rewardVOS) {
                  Long rewardId = reward.getId();
  
                  List<EvalGroupRewardParamVO> rewardParamVOS = rewardParamMap.getOrDefault(rewardId, new ArrayList<>());
                  Map<ParamTypeEnum, List<EvalGroupRewardParamVO>> paramTypeMap = rewardParamVOS.stream()
                          .collect(Collectors.groupingBy(EvalGroupRewardParamVO::getParamType));
                  reward.setCommissionParams(paramTypeMap.getOrDefault(ParamTypeEnum.COMMISSION, new ArrayList<>()));
                  reward.setLadderParams(paramTypeMap.getOrDefault(ParamTypeEnum.LADDER, new ArrayList<>()));
4138a206   姜超   feature(*): 考评组保存修改
620
                  reward.setConds(rewardCondMap.getOrDefault(rewardId, new ArrayList<>()));
b1409572   姜超   feature(*): 考评组保存
621
622
623
  
  
                  List<EvalGroupRewardLadders> rewardLadders = evalGroupRewardLaddersService.list(Wrappers.<EvalGroupRewardLadders>lambdaQuery()
fc5db912   姜超   feature(*): 新增台阶类型
624
                          .eq(EvalGroupRewardLadders::getEvalGroupRewardId, rewardId)
b1409572   姜超   feature(*): 考评组保存
625
626
627
628
629
                          .eq(EvalGroupRewardLadders::getYn, Boolean.TRUE)
                  );
                  List<EvalGroupRewardLaddersVO> rewardLaddersVOS = new ArrayList<>();
                  for (EvalGroupRewardLadders rewardLadder : rewardLadders) {
                      EvalGroupRewardLaddersVO rewardLaddersVO = PublicUtil.copy(rewardLadder, EvalGroupRewardLaddersVO.class);
ae86c608   姜超   feature(*): 新增台阶类型
630
                      rewardLaddersVO.processPercent(reward.getCalMethod(), reward.getRankType(), reward.getLaddersType());
b1409572   姜超   feature(*): 考评组保存
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
                      rewardLaddersVOS.add(rewardLaddersVO);
                  }
                  reward.setLadders(rewardLaddersVOS);
  
                  setRewardTargetVos(reward);
              }
          }
      }
  
      /**
       * 装换为目标对象
       *
       * @return
       */
      public void setRewardTargetVos(EvalGroupRewardVO reward) {
  
          List<EvalGroupRewardParamVO> ladderParams = reward.getLadderParams();
          List<EvalGroupRewardParamVO> commissionParams = reward.getCommissionParams();
          List<EvalGroupRewardPreconditionVO> conds = reward.getConds();
  
          List<EvalGroupIndicatorTargetVO> targetVOS = new ArrayList<>();
          for (EvalGroupRewardParamVO paramVO : ladderParams) {
              if (PublicUtil.isNotEmpty(paramVO.getTargetType())) {
                  EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(paramVO, EvalGroupIndicatorTargetVO.class);
3042c640   张志伟   :fire:
655
                  if (TargetTypeEnum.RATIO.equals(targetVO.getTargetType())) {
b1409572   姜超   feature(*): 考评组保存
656
657
658
659
660
661
662
663
664
                      targetVO.setTargetValue(targetVO.getTargetValue().divide(Constant.ONE_HUNDRED, 4, RoundingMode.HALF_UP));
                  }
                  targetVOS.add(targetVO);
              }
          }
  
          for (EvalGroupRewardParamVO paramVO : commissionParams) {
              if (PublicUtil.isNotEmpty(paramVO.getTargetType())) {
                  EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(paramVO, EvalGroupIndicatorTargetVO.class);
3042c640   张志伟   :fire:
665
                  if (TargetTypeEnum.RATIO.equals(targetVO.getTargetType())) {
b1409572   姜超   feature(*): 考评组保存
666
667
668
669
670
671
672
673
674
                      targetVO.setTargetValue(targetVO.getTargetValue().divide(Constant.ONE_HUNDRED, 4, RoundingMode.HALF_UP));
                  }
                  targetVOS.add(targetVO);
              }
          }
  
          for (EvalGroupRewardPreconditionVO preconditionVO : conds) {
              if (PublicUtil.isNotEmpty(preconditionVO.getTargetType())) {
                  EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(preconditionVO, EvalGroupIndicatorTargetVO.class);
3042c640   张志伟   :fire:
675
                  if (TargetTypeEnum.RATIO.equals(targetVO.getTargetType())) {
b1409572   姜超   feature(*): 考评组保存
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
                      targetVO.setTargetValue(targetVO.getTargetValue().divide(Constant.ONE_HUNDRED, 4, RoundingMode.HALF_UP));
                  }
                  targetVOS.add(targetVO);
              }
          }
  
          reward.setTargets(targetVOS);
      }
      /**
       * 装换为目标对象
       *
       * @return
       */
      public void setIndicatorTargetVos(EvalGroupIndicatorVO indicatorVO) {
  
          List<EvalGroupIndicatorParamVO> ladderParams = indicatorVO.getLadderParams();
          List<EvalGroupIndicatorParamVO> commissionParams = indicatorVO.getCommissionParams();
          List<EvalGroupIndicatorPreconditionVO> conds = indicatorVO.getConds();
  
          List<EvalGroupIndicatorTargetVO> targetVOS = new ArrayList<>();
          for (EvalGroupIndicatorParamVO paramVO : ladderParams) {
              if (PublicUtil.isNotEmpty(paramVO.getTargetType())) {
                  EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(paramVO, EvalGroupIndicatorTargetVO.class);
3042c640   张志伟   :fire:
699
                  if (TargetTypeEnum.RATIO.equals(targetVO.getTargetType())) {
b1409572   姜超   feature(*): 考评组保存
700
701
702
703
704
705
706
707
708
                      targetVO.setTargetValue(targetVO.getTargetValue().divide(Constant.ONE_HUNDRED, 4, RoundingMode.HALF_UP));
                  }
                  targetVOS.add(targetVO);
              }
          }
  
          for (EvalGroupIndicatorParamVO paramVO : commissionParams) {
              if (PublicUtil.isNotEmpty(paramVO.getTargetType())) {
                  EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(paramVO, EvalGroupIndicatorTargetVO.class);
3042c640   张志伟   :fire:
709
                  if (TargetTypeEnum.RATIO.equals(targetVO.getTargetType())) {
b1409572   姜超   feature(*): 考评组保存
710
711
712
713
714
715
716
717
718
                      targetVO.setTargetValue(targetVO.getTargetValue().divide(Constant.ONE_HUNDRED, 4, RoundingMode.HALF_UP));
                  }
                  targetVOS.add(targetVO);
              }
          }
  
          for (EvalGroupIndicatorPreconditionVO preconditionVO : conds) {
              if (PublicUtil.isNotEmpty(preconditionVO.getTargetType())) {
                  EvalGroupIndicatorTargetVO targetVO = PublicUtil.copy(preconditionVO, EvalGroupIndicatorTargetVO.class);
3042c640   张志伟   :fire:
719
                  if (TargetTypeEnum.RATIO.equals(targetVO.getTargetType())) {
b1409572   姜超   feature(*): 考评组保存
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
                      targetVO.setTargetValue(targetVO.getTargetValue().divide(Constant.ONE_HUNDRED, 4, RoundingMode.HALF_UP));
                  }
                  targetVOS.add(targetVO);
              }
          }
  
          indicatorVO.setTargets(targetVOS);
      }
  
  
      /**
       * 考评奖惩条件
       *
       * @param evalGroupId
       * @return
       */
      public Map<Long, List<EvalGroupRewardPreconditionVO>> getEvalGroupRewardPreconditionVO(Long evalGroupId) {
          List<EvalGroupRewardPrecondition> rewardPreconditions = evalGroupRewardPreconditionService.list(Wrappers.<EvalGroupRewardPrecondition>lambdaQuery()
                  .eq(EvalGroupRewardPrecondition::getEvalGroupId, evalGroupId)
                  .eq(EvalGroupRewardPrecondition::getYn, Boolean.TRUE)
          );
  
          List<EvalGroupRewardPreconditionVO> rewardPreconditionVOS = new ArrayList<>();
          for (EvalGroupRewardPrecondition precondition : rewardPreconditions) {
              EvalGroupRewardPreconditionVO preconditionVO = PublicUtil.copy(precondition, EvalGroupRewardPreconditionVO.class);
4138a206   姜超   feature(*): 考评组保存修改
745
              preconditionVO.convertToPercent();
b1409572   姜超   feature(*): 考评组保存
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
              rewardPreconditionVOS.add(preconditionVO);
          }
  
          Map<Long, List<EvalGroupRewardPreconditionVO>> rewardCondMap = rewardPreconditionVOS.stream()
                  .collect(Collectors.groupingBy(EvalGroupRewardPreconditionVO::getEvalGroupRewardId));
  
          return rewardCondMap;
      }
  
      /**
       * 考评奖惩参数
       *
       * @param evalGroupId
       * @return
       */
      public Map<Long, List<EvalGroupRewardParamVO>> getEvalGroupRewardParamVO(Long evalGroupId) {
          List<EvalGroupRewardParam> rewardParams = evalGroupRewardParamService.list(Wrappers.<EvalGroupRewardParam>lambdaQuery()
                  .eq(EvalGroupRewardParam::getEvalGroupId, evalGroupId)
                  .eq(EvalGroupRewardParam::getYn, Boolean.TRUE)
          );
  
          List<EvalGroupRewardParamVO> rewardParamVOS = new ArrayList<>();
          for (EvalGroupRewardParam rewardParam : rewardParams) {
              EvalGroupRewardParamVO paramVO = PublicUtil.copy(rewardParam, EvalGroupRewardParamVO.class);
4138a206   姜超   feature(*): 考评组保存修改
770
              paramVO.convertToPercent();
b1409572   姜超   feature(*): 考评组保存
771
772
              rewardParamVOS.add(paramVO);
          }
a3d13c97   姜超   feature(*): 考评组保存
773
  
b1409572   姜超   feature(*): 考评组保存
774
775
          Map<Long, List<EvalGroupRewardParamVO>> rewardParamMap = rewardParamVOS.stream()
                  .collect(Collectors.groupingBy(EvalGroupRewardParamVO::getEvalGroupRewardId));
a3d13c97   姜超   feature(*): 考评组保存
776
  
b1409572   姜超   feature(*): 考评组保存
777
778
          return rewardParamMap;
      }
a3d13c97   姜超   feature(*): 考评组保存
779
  
b1409572   姜超   feature(*): 考评组保存
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
      /**
       * 设置考评指标
       *
       * @param evalGroupVO
       */
      public void setEvalGroupIndicator(EvalGroupVO evalGroupVO) {
          Long evalGroupId = evalGroupVO.getId();
          List<EvalGroupIndicator> indicators = evalGroupIndicatorService.list(Wrappers.<EvalGroupIndicator>lambdaQuery()
                  .eq(EvalGroupIndicator::getEvalGroupId, evalGroupId)
                  .eq(EvalGroupIndicator::getYn, Boolean.TRUE)
          );
          if (PublicUtil.isNotEmpty(indicators)) {
              List<EvalGroupIndicatorVO> indicatorVOS = PublicUtil.copyList(indicators, EvalGroupIndicatorVO.class);
              evalGroupVO.setIndicators(indicatorVOS);
  
              Map<Long, List<EvalGroupIndicatorParamVO>> paramMap = this.getEvalGroupIndicatorParamVO(evalGroupId);
              Map<Long, List<EvalGroupIndicatorPreconditionVO>> condMap = this.getEvalGroupIndicatorCondVO(evalGroupId);
  
              for (EvalGroupIndicatorVO indicatorVO : indicatorVOS) {
                  Long kpiGroupIndicatorId = indicatorVO.getId();
  
                  //参数
                  List<EvalGroupIndicatorParamVO> indicatorParamVOS = paramMap.getOrDefault(kpiGroupIndicatorId, new ArrayList<>());
                  Map<ParamTypeEnum, List<EvalGroupIndicatorParamVO>> paramTypeMap = indicatorParamVOS.stream()
                          .collect(Collectors.groupingBy(EvalGroupIndicatorParamVO::getParamType));
                  indicatorVO.setCommissionParams(paramTypeMap.getOrDefault(ParamTypeEnum.COMMISSION, new ArrayList<>()));
                  indicatorVO.setLadderParams(paramTypeMap.getOrDefault(ParamTypeEnum.LADDER, new ArrayList<>()));
  
                  //条件
                  List<EvalGroupIndicatorPreconditionVO> preconditionVOS = condMap.getOrDefault(kpiGroupIndicatorId, new ArrayList<>());
                  for (EvalGroupIndicatorPreconditionVO cond : preconditionVOS) {
4138a206   姜超   feature(*): 考评组保存修改
811
                      List<EvalGroupIndicatorPreconditionLadders> condLadders = evalGroupIndicatorPreconditionLaddersService.list(Wrappers.<EvalGroupIndicatorPreconditionLadders>lambdaQuery()
b1409572   姜超   feature(*): 考评组保存
812
                                      .eq(EvalGroupIndicatorPreconditionLadders::getPreconditionId, cond.getId())
4138a206   姜超   feature(*): 考评组保存修改
813
                                      .eq(EvalGroupIndicatorPreconditionLadders::getYn, Boolean.TRUE));
b1409572   姜超   feature(*): 考评组保存
814
815
816
817
  
                      List<EvalGroupIndicatorPreconditionLaddersVO> condLaddersVOS = new ArrayList<>();
                      for (EvalGroupIndicatorPreconditionLadders condLadder : condLadders) {
                          EvalGroupIndicatorPreconditionLaddersVO condLaddersVO = PublicUtil.copy(condLadder, EvalGroupIndicatorPreconditionLaddersVO.class);
ae86c608   姜超   feature(*): 新增台阶类型
818
                          condLaddersVO.convertLaddersToPercent(cond.getTargetType(), cond.getDataType());
b1409572   姜超   feature(*): 考评组保存
819
820
821
822
823
824
825
                          condLaddersVOS.add(condLaddersVO);
                      }
                      cond.setLadders(condLaddersVOS);
                  }
                  Collections.sort(preconditionVOS, Comparator.comparingInt(EvalGroupIndicatorPreconditionVO::getSort));
                  indicatorVO.setConds(preconditionVOS);
  
fc5db912   姜超   feature(*): 新增台阶类型
826
827
828
829
830
831
832
833
834
835
836
837
                  //设置阶梯
                  if (ScoreWayEnum.LADDER.equals(indicatorVO.getScoreWay())) {
                      List<EvalGroupIndicatorLadders> ladders = evalGroupIndicatorLaddersService.list(Wrappers.<EvalGroupIndicatorLadders>lambdaQuery()
                              .in(EvalGroupIndicatorLadders::getEvalGroupIndicatorId, kpiGroupIndicatorId)
                              .eq(EvalGroupIndicatorLadders::getYn, Boolean.TRUE)
                              .orderByAsc(EvalGroupIndicatorLadders::getId)
                      );
                      List<EvalGroupIndicatorLaddersVO> laddersVOS = PublicUtil.copyList(ladders, EvalGroupIndicatorLaddersVO.class);
                      laddersVOS.stream().forEach(l -> l.convertLadderToPercent(indicatorVO.getLaddersType()));
                      indicatorVO.setLadders(laddersVOS);
                  }
  
b1409572   姜超   feature(*): 考评组保存
838
839
840
841
                  setIndicatorTargetVos(indicatorVO);
              }
          }
      }
a3d13c97   姜超   feature(*): 考评组保存
842
  
b1409572   姜超   feature(*): 考评组保存
843
844
845
846
847
848
849
850
851
852
853
      /**
       * 考评参数
       *
       * @param evalGroupId
       * @return
       */
      public Map<Long, List<EvalGroupIndicatorParamVO>> getEvalGroupIndicatorParamVO(Long evalGroupId) {
          List<EvalGroupIndicatorParam> params = evalGroupIndicatorParamService.list(Wrappers.<EvalGroupIndicatorParam>lambdaQuery()
                  .eq(EvalGroupIndicatorParam::getEvalGroupId, evalGroupId)
                  .eq(EvalGroupIndicatorParam::getYn, Boolean.TRUE)
          );
a3d13c97   姜超   feature(*): 考评组保存
854
  
b1409572   姜超   feature(*): 考评组保存
855
856
857
          List<EvalGroupIndicatorParamVO> paramVOS = new ArrayList<>();
          for (EvalGroupIndicatorParam param : params) {
              EvalGroupIndicatorParamVO paramVO = PublicUtil.copy(param, EvalGroupIndicatorParamVO.class);
4138a206   姜超   feature(*): 考评组保存修改
858
              paramVO.processPercent();
b1409572   姜超   feature(*): 考评组保存
859
              paramVOS.add(paramVO);
a3d13c97   姜超   feature(*): 考评组保存
860
          }
b1409572   姜超   feature(*): 考评组保存
861
862
863
864
865
  
          Map<Long, List<EvalGroupIndicatorParamVO>> indicatorParamMap = paramVOS.stream()
                  .collect(Collectors.groupingBy(EvalGroupIndicatorParamVO::getEvalGroupIndicatorId));
  
          return indicatorParamMap;
a3d13c97   姜超   feature(*): 考评组保存
866
867
      }
  
b1409572   姜超   feature(*): 考评组保存
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
      /**
       * 获取指标条件
       *
       * @param evalGroupId
       * @return
       */
      public Map<Long, List<EvalGroupIndicatorPreconditionVO>> getEvalGroupIndicatorCondVO(Long evalGroupId) {
          List<EvalGroupIndicatorPrecondition> preconditions = evalGroupIndicatorPreconditionService.list(Wrappers.<EvalGroupIndicatorPrecondition>lambdaQuery()
                  .eq(EvalGroupIndicatorPrecondition::getEvalGroupId, evalGroupId)
                  .eq(EvalGroupIndicatorPrecondition::getYn, Boolean.TRUE)
          );
  
          List<EvalGroupIndicatorPreconditionVO> preconditionVOS = new ArrayList<>();
          for (EvalGroupIndicatorPrecondition precondition : preconditions) {
              EvalGroupIndicatorPreconditionVO preconditionVO = PublicUtil.copy(precondition, EvalGroupIndicatorPreconditionVO.class);
4138a206   姜超   feature(*): 考评组保存修改
883
              preconditionVO.processPercent();
b1409572   姜超   feature(*): 考评组保存
884
885
              preconditionVOS.add(preconditionVO);
          }
280563a2   姜超   feature(*): 考评组保存
886
  
b1409572   姜超   feature(*): 考评组保存
887
888
889
890
          Map<Long, List<EvalGroupIndicatorPreconditionVO>> indicatorCondMap = preconditionVOS.stream()
                  .collect(Collectors.groupingBy(EvalGroupIndicatorPreconditionVO::getEvalGroupIndicatorId));
  
          return indicatorCondMap;
280563a2   姜超   feature(*): 考评组保存
891
      }
028bb253   姜超   feature(*): 考评组相关文件
892
  
b1409572   姜超   feature(*): 考评组保存
893
  
556ff3c3   姜超   feature(*): 考评草稿
894
895
896
897
898
899
900
901
902
903
904
905
906
907
      /**
       * 审批考评组
       *
       * @param approvalRecord
       * @param result
       */
      public void approvalEvalConfig(ApprovalRecord approvalRecord, ApprovalResultEvent result) {
          log.info("收到岗位最低收入补偿审批信息:{}", JSON.toJSONString(result));
          Boolean agree = result.getAgree();
          SettingDraft settingDraft = settingDraftService.getById(approvalRecord.getDataId());
          BV.isTrue(PublicUtil.isNotEmpty(settingDraft), "考评草稿数据不存在");
  
          SettingDraftStatusEnum draftStatus = (agree) ? SettingDraftStatusEnum.RELEASE_APPROVAL_AGREE :
                  SettingDraftStatusEnum.RELEASE_APPROVAL_REJECT;
556ff3c3   姜超   feature(*): 考评草稿
908
909
  
          if (! agree) {
1a21d9d4   姜超   feature(*): 考评导入修改
910
911
912
913
914
915
916
              if (! SettingDraftStatusEnum.RELEASE_APPROVAL_CANCEL.equals(settingDraft.getStatus())) {
                  settingDraftService.update(Wrappers.<SettingDraft>lambdaUpdate()
                          .set(SettingDraft::getStatus, draftStatus)
                          .set(SettingDraft::getUpdateTime, new Date())
                          .eq(SettingDraft::getId, settingDraft.getId())
                  );
              }
556ff3c3   姜超   feature(*): 考评草稿
917
918
919
920
921
922
923
924
925
926
927
              return;
          }
  
          EvalDTO evalDTO = JSON.parseObject(settingDraft.getContent(), EvalDTO.class);
          Eval eval = evalGroupDataService.saveEval(evalDTO);
          for (EvalGroupDTO evalGroupDTO : evalDTO.getEvalGroups()) {
              EvalGroup evalGroup = evalGroupDataService.saveEvalGroup(evalGroupDTO, eval);
              evalGroupDataService.saveEvalGroupIndicator(evalGroup, evalGroupDTO.getIndicators());
              evalGroupDataService.saveEvalGroupReward(evalGroup, evalGroupDTO.getRewards());
          }
  
1a21d9d4   姜超   feature(*): 考评导入修改
928
929
930
931
932
933
934
          settingDraftService.update(Wrappers.<SettingDraft>lambdaUpdate()
                  .set(SettingDraft::getUnionId, eval.getId())
                  .set(SettingDraft::getStatus, draftStatus)
                  .set(SettingDraft::getUpdateTime, new Date())
                  .eq(SettingDraft::getId, settingDraft.getId())
          );
  
556ff3c3   姜超   feature(*): 考评草稿
935
      }
b1409572   姜超   feature(*): 考评组保存
936
  
36a2a360   姜超   feature(*): 禁用考评
937
938
939
940
941
942
943
944
945
      /**
       * 禁用考评
       *
       * @param id
       * @param currentUser
       */
      public void disableEval(Long id, LoginAuthBean currentUser) {
          Eval eval = evalService.getById(id);
          BV.notNull(eval, "考评配置不存在,请重试");
b1409572   姜超   feature(*): 考评组保存
946
  
36a2a360   姜超   feature(*): 禁用考评
947
948
949
950
951
952
          Boolean statusCheck = SettingStatusEnum.BE_EFFECTIVE.equals(eval.getStatus()) ||
                  SettingStatusEnum.EFFECTIVE.equals(eval.getStatus());
          BV.isTrue(statusCheck, "只有生效中、待生效考评配置能禁用");
  
          log.info("禁用绩效组,id:{},操作人:{}", id, currentUser);
  
c06a04fb   姜超   feature(*): 考评指标详情
953
954
955
956
957
958
          evalService.update(Wrappers.<Eval>lambdaUpdate()
                  .set(Eval::getUpdateTime, new Date())
                  .set(Eval::getYn, Boolean.FALSE)
                  .eq(Eval::getId, eval.getId())
          );
  
36a2a360   姜超   feature(*): 禁用考评
959
960
961
962
963
964
965
966
967
968
969
970
971
972
          if (SettingStatusEnum.EFFECTIVE.equals(eval.getStatus())) {
              evalUserPoolService.update(Wrappers.<EvalUserPool>lambdaUpdate()
                      .set(EvalUserPool::getUpdateTime, new Date())
                      .set(EvalUserPool::getYn, Boolean.FALSE)
                      .eq(EvalUserPool::getId, id)
                      .eq(EvalUserPool::getYn, Boolean.TRUE)
              );
              evalShopPoolService.update(Wrappers.<EvalShopPool>lambdaUpdate()
                      .set(EvalShopPool::getUpdateTime, new Date())
                      .set(EvalShopPool::getYn, Boolean.FALSE)
                      .eq(EvalShopPool::getId, id)
                      .eq(EvalShopPool::getYn, Boolean.TRUE)
              );
          }
c06a04fb   姜超   feature(*): 考评指标详情
973
  
36a2a360   姜超   feature(*): 禁用考评
974
      }
028bb253   姜超   feature(*): 考评组相关文件
975
  }