Blame view

fw-morax-service/src/main/java/cn/fw/morax/service/biz/kpi/KpiGroupBizService.java 51.9 KB
57fffce6   姜超   [jiangchao] 绩效组查询接口
1
  package cn.fw.morax.service.biz.kpi;
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
2
  
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
3
  import cn.fw.common.data.mybatis.pagination.PageData;
b7dd7786   姜超   feature(*): 阶梯值校验...
4
  import cn.fw.common.exception.BusinessException;
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
5
  import cn.fw.common.page.AppPage;
a5953781   姜超   feature(*): 保存、修改...
6
  import cn.fw.common.web.annotation.DisLock;
358e9d65   姜超   feature(*): 绩效组审批...
7
  import cn.fw.common.web.auth.LoginAuthBean;
a4b02509   姜超   feature(*): 绩效组阶梯...
8
  import cn.fw.morax.common.constant.Constant;
29887f53   姜超   feature(*): 审批星级特...
9
  import cn.fw.morax.common.pojo.event.ApprovalResultEvent;
8464701b   姜超   feature(*): 绩效组变动通知
10
  import cn.fw.morax.common.pojo.event.KpiGroupChangeEvent;
5f57db6b   姜超   fix(*): 薪酬编码修改、绩效...
11
  import cn.fw.morax.common.utils.DateUtil;
8464701b   姜超   feature(*): 绩效组变动通知
12
  import cn.fw.morax.common.utils.EventBusUtil;
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
13
  import cn.fw.morax.common.utils.PublicUtil;
f4f1f40b   姜超   feature(*): 月定时器
14
  import cn.fw.morax.domain.db.ApprovalRecord;
770c421f   姜超   feature(*): 草稿查询
15
  import cn.fw.morax.domain.db.SettingDraft;
98f0b2aa   姜超   feature(*): 添加yn判断
16
  import cn.fw.morax.domain.db.kpi.*;
6786b5e1   姜超   feature(*): 绩效组配置修改
17
  import cn.fw.morax.domain.dto.kpi.*;
4b07306b   姜超   feature(*): 星级特殊调整申请
18
  import cn.fw.morax.domain.dto.query.KpiGroupQueryDTO;
f4f1f40b   姜超   feature(*): 月定时器
19
  import cn.fw.morax.domain.dto.query.KpiGroupRepeatQueryDTO;
fc885c22   姜超   feature(*): 绩效组阶梯...
20
  import cn.fw.morax.domain.enums.*;
f4f1f40b   姜超   feature(*): 月定时器
21
  import cn.fw.morax.domain.vo.kpi.*;
b0f4e55e   姜超   [jiangchao] 绩效组保存审批
22
  import cn.fw.morax.service.biz.ApprovalBizService;
fc885c22   姜超   feature(*): 绩效组阶梯...
23
  import cn.fw.morax.service.biz.CommonService;
770c421f   姜超   feature(*): 草稿查询
24
25
  import cn.fw.morax.service.data.ApprovalRecordService;
  import cn.fw.morax.service.data.SettingDraftService;
3437d210   姜超   feature(Indicator...
26
  import cn.fw.morax.service.data.kpi.*;
b0f4e55e   姜超   [jiangchao] 绩效组保存审批
27
  import com.alibaba.fastjson.JSON;
770c421f   姜超   feature(*): 草稿查询
28
  import com.alibaba.fastjson.JSONObject;
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
29
  import com.baomidou.mybatisplus.core.toolkit.Wrappers;
ee345722   姜超   feature(*): 保存绩效排名组
30
  import com.google.common.collect.Lists;
dc2eb3fa   姜超   feature(*): 绩效组人员查看
31
  import com.google.common.collect.Maps;
a5953781   姜超   feature(*): 保存、修改...
32
  import lombok.Getter;
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
33
34
  import lombok.RequiredArgsConstructor;
  import lombok.extern.slf4j.Slf4j;
a5953781   姜超   feature(*): 保存、修改...
35
  import org.springframework.beans.factory.annotation.Value;
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
36
37
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
7a060493   xianpengcheng   绩效报表-配置详情
38
  import org.springframework.util.CollectionUtils;
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
39
  
6786b5e1   姜超   feature(*): 绩效组配置修改
40
  import java.math.BigDecimal;
ee345722   姜超   feature(*): 保存绩效排名组
41
  import java.math.RoundingMode;
5f57db6b   姜超   fix(*): 薪酬编码修改、绩效...
42
  import java.text.SimpleDateFormat;
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
43
  import java.time.LocalDate;
5f57db6b   姜超   fix(*): 薪酬编码修改、绩效...
44
  import java.time.LocalDateTime;
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
45
  import java.time.YearMonth;
dc2eb3fa   姜超   feature(*): 绩效组人员查看
46
  import java.util.*;
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
47
48
49
50
51
52
53
54
55
  import java.util.stream.Collectors;
  
  import static cn.fw.common.businessvalidator.Validator.BV;
  
  @RequiredArgsConstructor
  @Service
  @Slf4j
  public class KpiGroupBizService {
  
59d58c08   姜超   feature(*): excel...
56
      private final KpiGroupIndicatorLaddersService kpiGroupIndicatorLaddersService;
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
57
      private final KpiGroupIndicatorService kpiGroupIndicatorService;
bdca4a05   姜超   feature(*): 绩效审批修改
58
      private final KpiGroupUserBizService kpiGroupUserBizService;
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
59
      private final KpiStarLaddersService kpiStarLaddersService;
4b07306b   姜超   feature(*): 星级特殊调整申请
60
      private final KpiGroupDataService kpiGroupDataService;
b0f4e55e   姜超   [jiangchao] 绩效组保存审批
61
      private final ApprovalBizService approvalBizService;
770c421f   姜超   feature(*): 草稿查询
62
      private final ApprovalRecordService approvalRecordService;
41a1d9fe   姜超   feature(*): 考评草稿修改
63
      private final CommonService commonService;
3437d210   姜超   feature(Indicator...
64
      private final IndicatorsService indicatorsService;
770c421f   姜超   feature(*): 草稿查询
65
      private final SettingDraftService settingDraftService;
5376bae5   姜超   [jiangchao] 代码格式修改
66
      private final KpiGroupService kpiGroupService;
077e6941   姜超   feature(*): 草稿修改
67
      private final KpiPoolService kpiPoolService;
5679f350   张志伟   feature(*): 修改类名
68
      private final KpiGroupIndicatorPreconditionService kpiGroupIndicatorPreconditionService;
6786b5e1   姜超   feature(*): 绩效组配置修改
69
      private final KpiGroupIndicatorParamService kpiGroupIndicatorParamService;
caf55039   姜超   feature(*): 实体类修改
70
      private final KpiGroupIndicatorPreconditionLaddersService kpiGroupIndicatorCondLaddersService;
ee345722   姜超   feature(*): 保存绩效排名组
71
      private final KpiGroupRankStarLaddersService kpiGroupRankStarLaddersService;
566a519a   姜超   feature(*): 保存绩效排名组
72
      private final KpiGroupRankService kpiGroupRankService;
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
73
  
a5953781   姜超   feature(*): 保存、修改...
74
75
76
77
      @Value("${spring.cache.custom.global-prefix}:kpi:group:save:")
      @Getter
      private String savePrefix;
  
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
78
79
80
81
82
      /**
       * 分页查询
       * @param dto
       * @return
       */
83fc9174   姜超   feature(*): 薪酬项查询...
83
      public AppPage<KpiGroupVO> kpiGroupPage(KpiGroupQueryDTO dto) {
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
84
85
86
          PageData<KpiGroup> pageData = kpiGroupService.page(new PageData<>(dto.getCurrent(), dto.getPageSize()),
                  Wrappers.<KpiGroup>lambdaQuery()
                          .eq(KpiGroup::getGroupId, dto.getGroupId())
a7262215   姜超   feature(*): 薪酬组阶梯校验
87
                          .eq(PublicUtil.isNotEmpty(dto.getPostId()), KpiGroup::getPostId, dto.getPostId())
088e4c28   姜超   fix(group): 绩效组、薪...
88
                          .eq(PublicUtil.isNotEmpty(dto.getStatus()), KpiGroup::getStatus, dto.getStatus())
98f0b2aa   姜超   feature(*): 添加yn判断
89
                          .eq(KpiGroup::getYn, Boolean.TRUE)
a310d67e   姜超   feature(*): 绩效薪酬 ...
90
                          .last("ORDER BY FIELD(`status`,3,1,2,4)")
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
91
          );
770c421f   姜超   feature(*): 草稿查询
92
93
94
95
96
97
98
99
100
  
          Map<Long, String> approvalRecordMap = new HashMap<>();
          if (PublicUtil.isNotEmpty(pageData.getRecords())) {
              List<Long> kpiGroupIds = pageData.getRecords().stream().map(KpiGroup::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));
  
0f6a1e40   姜超   feature(bug): 修改分页查询
101
              approvalRecordMap = approvalRecords.stream().collect(Collectors.toMap(ApprovalRecord::getDataId, ApprovalRecord::getApprovalNo, (v1, v2) -> v1));
770c421f   姜超   feature(*): 草稿查询
102
103
          }
          Map<Long, String> finalApprovalRecordMap = approvalRecordMap;
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
104
          return PublicUtil.toPage(pageData, kpiGroup -> {
83fc9174   姜超   feature(*): 薪酬项查询...
105
              KpiGroupVO kpiGroupVo = PublicUtil.copy(kpiGroup, KpiGroupVO.class);
770c421f   姜超   feature(*): 草稿查询
106
              kpiGroupVo.setApprovalNo(finalApprovalRecordMap.getOrDefault(kpiGroup.getId(), ""));
088e4c28   姜超   fix(group): 绩效组、薪...
107
108
              kpiGroupVo.setBeginTime(kpiGroup.getBeginTime());
              kpiGroupVo.setOverTime(kpiGroup.getOverTime());
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
109
110
111
112
              return kpiGroupVo;
          });
      }
  
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
113
      /**
770c421f   姜超   feature(*): 草稿查询
114
115
116
117
118
119
120
121
122
123
124
125
126
       * 禁用绩效组
       *
       * @param kpiGroupId
       */
      public void disableKpiGroup(Long kpiGroupId) {
          KpiGroup kpiGroup = kpiGroupService.getById(kpiGroupId);
          BV.notNull(kpiGroup, "绩效配置不存在,请重试");
          BV.isTrue(SettingStatusEnum.EFFECTIVE.equals(kpiGroup.getStatus()), "生效中才能禁用,请重试");
  
          kpiGroup.setStatus(SettingStatusEnum.DRAFT);
          kpiGroup.setUpdateTime(new Date());
          kpiGroupService.updateById(kpiGroup);
  
3afee3e4   姜超   feature(*): 绩效排名组修改
127
      }
770c421f   姜超   feature(*): 草稿查询
128
  
3afee3e4   姜超   feature(*): 绩效排名组修改
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
      /**
       * 绩效组排名组合详情
       *
       * @param id
       * @return
       */
      public KpiGroupRankVO kpiGroupRankDetail(Long id) {
          KpiGroupRank kpiGroupRank = kpiGroupRankService.getById(id);
          KpiGroupRankVO kpiGroupRankVO = PublicUtil.copy(kpiGroupRank, KpiGroupRankVO.class);
          kpiGroupRankVO.setKpiGroups(new ArrayList<>());
          for (Long kpiGroupId : kpiGroupRankVO.getKpiGroupIds()) {
              KpiGroupVO kpiGroupVO = this.kpiGroupDetail(kpiGroupId);
              kpiGroupRankVO.getKpiGroups().add(kpiGroupVO);
          }
          List<KpiGroupRankStarLadders> starLadders = kpiGroupRankStarLaddersService.list(Wrappers.<KpiGroupRankStarLadders>lambdaQuery()
                  .eq(KpiGroupRankStarLadders::getKpiGroupRankId, id)
                  .eq(KpiGroupRankStarLadders::getYn, Boolean.TRUE)
          );
          List<KpiGroupRankStarLaddersVO> starLaddersVOS = PublicUtil.copyList(starLadders, KpiGroupRankStarLaddersVO.class);
          for (KpiGroupRankStarLaddersVO starLaddersVO : starLaddersVOS) {
              starLaddersVO.setUpper(starLaddersVO.getUpper().multiply(Constant.ONE_HUNDRED));
              starLaddersVO.setLower(starLaddersVO.getLower().multiply(Constant.ONE_HUNDRED));
          }
          kpiGroupRankVO.setStarLadders(starLaddersVOS);
          if (PublicUtil.isNotEmpty(kpiGroupRankVO.getRevokedScoreRatio())) {
              kpiGroupRankVO.setRevokedScoreRatio(kpiGroupRankVO.getRevokedScoreRatio().multiply(Constant.ONE_HUNDRED));
          }
          return kpiGroupRankVO;
770c421f   姜超   feature(*): 草稿查询
157
158
159
160
      }
  
  
      /**
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
161
162
163
164
       * 绩效组详情
       * @param kpiGroupId
       * @return
       */
83fc9174   姜超   feature(*): 薪酬项查询...
165
      public KpiGroupVO kpiGroupDetail(Long kpiGroupId) {
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
166
167
          KpiGroup kpiGroup = kpiGroupService.getById(kpiGroupId);
          BV.notNull(kpiGroup, "绩效配置不存在,请重试");
83fc9174   姜超   feature(*): 薪酬项查询...
168
          KpiGroupVO kpiGroupVo = KpiGroupVO.convertKpiGroup(kpiGroup);
6786b5e1   姜超   feature(*): 绩效组配置修改
169
170
  
          //星级数据
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
171
          List<KpiStarLadders> starLadders = kpiStarLaddersService.list(Wrappers.<KpiStarLadders>lambdaQuery()
6786b5e1   姜超   feature(*): 绩效组配置修改
172
                  .eq(KpiStarLadders::getKpiGroupId, kpiGroupVo.getId())
98f0b2aa   姜超   feature(*): 添加yn判断
173
                  .eq(KpiStarLadders::getYn, Boolean.TRUE)
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
174
          );
83fc9174   姜超   feature(*): 薪酬项查询...
175
          List<KpiStarLaddersVO> starLaddersVos = PublicUtil.copyList(starLadders, KpiStarLaddersVO.class);
96ab8564   姜超   feature(*): 薪酬组绩效...
176
          starLaddersVos.stream().forEach(KpiStarLaddersVO::processPercent);
59d58c08   姜超   feature(*): excel...
177
          kpiGroupVo.setStarLadders(starLaddersVos);
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
178
  
6786b5e1   姜超   feature(*): 绩效组配置修改
179
180
181
182
183
184
185
186
187
188
189
190
191
          //指标数据
          this.setIndicatorVo(kpiGroupVo);
          return kpiGroupVo;
      }
  
      /**
       * 设置指标
       *
       * @param kpiGroupVo
       */
      public void setIndicatorVo(KpiGroupVO kpiGroupVo) {
          Long kpiGroupId = kpiGroupVo.getId();
          List<KpiGroupIndicator> indicators = kpiGroupIndicatorService.list(Wrappers.<KpiGroupIndicator>lambdaQuery()
59d58c08   姜超   feature(*): excel...
192
                  .eq(KpiGroupIndicator::getKpiGroupId, kpiGroupId)
98f0b2aa   姜超   feature(*): 添加yn判断
193
                  .eq(KpiGroupIndicator::getYn, Boolean.TRUE)
59d58c08   姜超   feature(*): excel...
194
          );
6786b5e1   姜超   feature(*): 绩效组配置修改
195
  
58aa0677   姜超   feature(*): 绩效得分详情修改
196
          Map<Long, List<KpiGroupIndicatorParamVO>> paramMap = kpiGroupIndicatorParamService.getKpiGroupParamMap(kpiGroupId);
5679f350   张志伟   feature(*): 修改类名
197
          Map<Long, List<KpiGroupIndicatorPreconditionVO>> condMap = kpiGroupIndicatorPreconditionService.getKpiGroupIndicatorCondVO(kpiGroupId);
6786b5e1   姜超   feature(*): 绩效组配置修改
198
199
200
  
  
          List<KpiGroupIndicatorVO> kpiGroupIndicatorVOS = PublicUtil.copyList(indicators, KpiGroupIndicatorVO.class);
07ad15bb   姜超   fix(kpigroupservi...
201
          for (KpiGroupIndicatorVO indicatorVO : kpiGroupIndicatorVOS) {
6786b5e1   姜超   feature(*): 绩效组配置修改
202
              Long kpiGroupIndicatorId = indicatorVO.getId();
6786b5e1   姜超   feature(*): 绩效组配置修改
203
  
3c36f6c9   xianpengcheng   更新考评指标和绩效指标
204
              //参数-台阶得分
001d8a67   姜超   feature(*): 薪酬项目删除字段
205
206
              List<KpiGroupIndicatorParamVO> indicatorParamVOS = paramMap.getOrDefault(kpiGroupIndicatorId, new ArrayList<>());
              Map<ParamTypeEnum, List<KpiGroupIndicatorParamVO>> paramTypeMap = indicatorParamVOS.stream()
6786b5e1   姜超   feature(*): 绩效组配置修改
207
                      .collect(Collectors.groupingBy(KpiGroupIndicatorParamVO::getParamType));
001d8a67   姜超   feature(*): 薪酬项目删除字段
208
209
              indicatorVO.setCommissionParams(paramTypeMap.getOrDefault(ParamTypeEnum.COMMISSION, new ArrayList<>()));
              indicatorVO.setLadderParams(paramTypeMap.getOrDefault(ParamTypeEnum.LADDER, new ArrayList<>()));
6786b5e1   姜超   feature(*): 绩效组配置修改
210
  
3c36f6c9   xianpengcheng   更新考评指标和绩效指标
211
              //前置条件
001d8a67   姜超   feature(*): 薪酬项目删除字段
212
213
              List<KpiGroupIndicatorPreconditionVO> preconditionVOS = condMap.getOrDefault(kpiGroupIndicatorId, new ArrayList<>());
              for (KpiGroupIndicatorPreconditionVO cond : preconditionVOS) {
278ef9ef   姜超   feature(bug): 修改目...
214
215
216
  
                  List<KpiGroupIndicatorPreconditionLaddersVO> condLaddersVOS = kpiGroupIndicatorCondLaddersService.getVOS(
                          cond.getId(), cond.getTargetType(), cond.getDataType());
001d8a67   姜超   feature(*): 薪酬项目删除字段
217
                  cond.setCondLadders(condLaddersVOS);
6786b5e1   姜超   feature(*): 绩效组配置修改
218
              }
001d8a67   姜超   feature(*): 薪酬项目删除字段
219
220
221
222
223
              Collections.sort(preconditionVOS, Comparator.comparingInt(KpiGroupIndicatorPreconditionVO::getSort));
              indicatorVO.setConds(preconditionVOS);
  
              //设置目标对象
              setTargetVos(indicatorVO);
07ad15bb   姜超   fix(kpigroupservi...
224
          }
6786b5e1   姜超   feature(*): 绩效组配置修改
225
  
3c36f6c9   xianpengcheng   更新考评指标和绩效指标
226
          //设置台阶得分阶梯
59d58c08   姜超   feature(*): excel...
227
          List<KpiGroupIndicatorLadders> kpiGroupIndicatorLadders = kpiGroupIndicatorLaddersService.list(Wrappers.<KpiGroupIndicatorLadders>lambdaQuery()
6786b5e1   姜超   feature(*): 绩效组配置修改
228
229
                  .in(KpiGroupIndicatorLadders::getKpiGroupIndicatorId,
                          kpiGroupIndicatorVOS.stream().map(KpiGroupIndicatorVO::getId).collect(Collectors.toList()))
98f0b2aa   姜超   feature(*): 添加yn判断
230
                  .eq(KpiGroupIndicatorLadders::getYn, Boolean.TRUE)
7aeaf2fe   姜超   fix(*): 绩效、薪酬阶梯正序展示
231
                  .orderByAsc(KpiGroupIndicatorLadders::getId)
59d58c08   姜超   feature(*): excel...
232
233
          );
          Map<Long, List<KpiGroupIndicatorLadders>> indicatorLaddersMap = kpiGroupIndicatorLadders.stream().collect(Collectors.groupingBy(KpiGroupIndicatorLadders::getKpiGroupIndicatorId));
83fc9174   姜超   feature(*): 薪酬项查询...
234
          for (KpiGroupIndicatorVO indicatorVo : kpiGroupIndicatorVOS) {
59d58c08   姜超   feature(*): excel...
235
              if (indicatorLaddersMap.containsKey(indicatorVo.getId())) {
83fc9174   姜超   feature(*): 薪酬项查询...
236
                  List<KpiGroupIndicatorLaddersVO> laddersVos = PublicUtil.copyList(indicatorLaddersMap.get(indicatorVo.getId()), KpiGroupIndicatorLaddersVO.class);
a4b02509   姜超   feature(*): 绩效组阶梯...
237
                  for (KpiGroupIndicatorLaddersVO laddersVO : laddersVos) {
278ef9ef   姜超   feature(bug): 修改目...
238
                      laddersVO.convertLadderToPercent(indicatorVo.getLaddersType());
a4b02509   姜超   feature(*): 绩效组阶梯...
239
                  }
59d58c08   姜超   feature(*): excel...
240
241
242
                  indicatorVo.setIndicatorLadders(laddersVos);
              }
          }
83fc9174   姜超   feature(*): 薪酬项查询...
243
          kpiGroupVo.setIndicators(kpiGroupIndicatorVOS);
6786b5e1   姜超   feature(*): 绩效组配置修改
244
245
246
      }
  
      /**
001d8a67   姜超   feature(*): 薪酬项目删除字段
247
       * 装换为目标对象
6786b5e1   姜超   feature(*): 绩效组配置修改
248
       *
001d8a67   姜超   feature(*): 薪酬项目删除字段
249
       * @return
6786b5e1   姜超   feature(*): 绩效组配置修改
250
       */
001d8a67   姜超   feature(*): 薪酬项目删除字段
251
252
      public void setTargetVos(KpiGroupIndicatorVO indicatorVO) {
  
ff355f8f   姜超   feature(bug): 修改目...
253
254
255
          List<KpiGroupIndicatorParamVO> ladderParams = Optional.ofNullable(indicatorVO.getLadderParams()).orElse(new ArrayList<>());
          List<KpiGroupIndicatorParamVO> commissionParams = Optional.ofNullable(indicatorVO.getCommissionParams()).orElse(new ArrayList<>());
          List<KpiGroupIndicatorPreconditionVO> conds =Optional.ofNullable(indicatorVO.getConds()).orElse(new ArrayList<>());
001d8a67   姜超   feature(*): 薪酬项目删除字段
256
257
258
259
260
  
          List<KpiGroupIndicatorTargetVO> targetVOS = new ArrayList<>();
          for (KpiGroupIndicatorParamVO paramVO : ladderParams) {
              if (PublicUtil.isNotEmpty(paramVO.getTargetType())) {
                  KpiGroupIndicatorTargetVO targetVO = PublicUtil.copy(paramVO, KpiGroupIndicatorTargetVO.class);
001d8a67   姜超   feature(*): 薪酬项目删除字段
261
262
                  targetVOS.add(targetVO);
              }
6786b5e1   姜超   feature(*): 绩效组配置修改
263
          }
6786b5e1   姜超   feature(*): 绩效组配置修改
264
  
001d8a67   姜超   feature(*): 薪酬项目删除字段
265
266
267
          for (KpiGroupIndicatorParamVO paramVO : commissionParams) {
              if (PublicUtil.isNotEmpty(paramVO.getTargetType())) {
                  KpiGroupIndicatorTargetVO targetVO = PublicUtil.copy(paramVO, KpiGroupIndicatorTargetVO.class);
001d8a67   姜超   feature(*): 薪酬项目删除字段
268
269
                  targetVOS.add(targetVO);
              }
6786b5e1   姜超   feature(*): 绩效组配置修改
270
          }
001d8a67   姜超   feature(*): 薪酬项目删除字段
271
272
273
274
  
          for (KpiGroupIndicatorPreconditionVO preconditionVO : conds) {
              if (PublicUtil.isNotEmpty(preconditionVO.getTargetType())) {
                  KpiGroupIndicatorTargetVO targetVO = PublicUtil.copy(preconditionVO, KpiGroupIndicatorTargetVO.class);
001d8a67   姜超   feature(*): 薪酬项目删除字段
275
276
                  targetVOS.add(targetVO);
              }
6786b5e1   姜超   feature(*): 绩效组配置修改
277
          }
001d8a67   姜超   feature(*): 薪酬项目删除字段
278
279
  
          indicatorVO.setTargets(targetVOS);
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
280
281
      }
  
661e60e9   姜超   feature(*): 处理目标展示
282
283
284
285
286
287
288
289
      /**
       * 装换为目标对象
       *
       * @return
       */
      public void setTargetVos(KpiGroupDTO kpiGroupDTO) {
  
          for (KpiGroupIndicatorDTO indicatorDTO : kpiGroupDTO.getIndicators()) {
ff355f8f   姜超   feature(bug): 修改目...
290
291
292
              List<KpiGroupIndicatorParamDTO> ladderParams = Optional.ofNullable(indicatorDTO.getLadderParams()).orElse(new ArrayList<>());
              List<KpiGroupIndicatorParamDTO> commissionParams = Optional.ofNullable(indicatorDTO.getCommissionParams()).orElse(new ArrayList<>());
              List<KpiGroupIndicatorPreconditionDTO> conds = Optional.ofNullable(indicatorDTO.getConds()).orElse(new ArrayList<>());
661e60e9   姜超   feature(*): 处理目标展示
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
318
319
  
              List<KpiGroupIndicatorTargetVO> targetVOS = new ArrayList<>();
              for (KpiGroupIndicatorParamDTO paramDTO : ladderParams) {
                  if (PublicUtil.isNotEmpty(paramDTO.getTargetType()) && (! TargetTypeEnum.NO.equals(paramDTO.getTargetType()))) {
                      KpiGroupIndicatorTargetVO targetVO = PublicUtil.copy(paramDTO, KpiGroupIndicatorTargetVO.class);
                      targetVOS.add(targetVO);
                  }
              }
  
              for (KpiGroupIndicatorParamDTO paramDTO : commissionParams) {
                  if (PublicUtil.isNotEmpty(paramDTO.getTargetType()) && (! TargetTypeEnum.NO.equals(paramDTO.getTargetType()))) {
                      KpiGroupIndicatorTargetVO targetVO = PublicUtil.copy(paramDTO, KpiGroupIndicatorTargetVO.class);
                      targetVOS.add(targetVO);
                  }
              }
  
              for (KpiGroupIndicatorPreconditionDTO preconditionDTO : conds) {
                  if (PublicUtil.isNotEmpty(preconditionDTO.getTargetType()) && (! TargetTypeEnum.NO.equals(preconditionDTO.getTargetType()))) {
                      KpiGroupIndicatorTargetVO targetVO = PublicUtil.copy(preconditionDTO, KpiGroupIndicatorTargetVO.class);
                      targetVOS.add(targetVO);
                  }
              }
  
              indicatorDTO.setTargets(targetVOS);
          }
      }
  
ead23336   姜超   feature(*): 新增实体类...
320
321
322
323
324
325
      /**
       * 绩效组保存
       * @param dto
       */
      @Transactional(rollbackFor = Exception.class)
      @DisLock(prefix = "#this.getSavePrefix()", key = "#dto.getPostId()", message = "保存中,请勿重复操作")
38313e77   姜超   feature(*): 草稿审批修改
326
      public KpiGroupSavePromptVO saveKpi(KpiGroupDTO dto, LoginAuthBean user, Boolean submit) {
7b6ab90b   姜超   feature(*): 绩效保存修...
327
          //初始化数据
ee345722   姜超   feature(*): 保存绩效排名组
328
  //        this.initKpi(dto);
0684035f   姜超   feature(*): 人员绩效组...
329
          //检查数据
c19df250   姜超   feature(*): 绩效组人员...
330
          this.checkKpi(dto);
f0aa2cb7   姜超   feature(*): 审批修改
331
          this.checkNameRepetition(dto.getId(), dto.getName(), dto.getDraftId());
3743789f   姜超   [jiangchao] 绩效组查询接口
332
          this.checkKpiLadders(dto.getIndicators());
3083fec7   姜超   feature(*): 薪酬组保存...
333
          this.checkStarLadders(dto.getStarLadders(), dto.getStarEvaluationType());
83fc9174   姜超   feature(*): 薪酬项查询...
334
          KpiGroupSavePromptVO promptVo = this.checkShopKpiRepeat(dto);
f4f1f40b   姜超   feature(*): 月定时器
335
336
337
          if (promptVo.getPrompt()) {
              return promptVo;
          }
661e60e9   姜超   feature(*): 处理目标展示
338
          setTargetVos(dto);
077e6941   姜超   feature(*): 草稿修改
339
          SettingDraft settingDraft = getSettingDraft(dto, submit);
770c421f   姜超   feature(*): 草稿查询
340
          settingDraftService.saveOrUpdate(settingDraft);
38313e77   姜超   feature(*): 草稿审批修改
341
342
343
          if (! submit) {
              return new KpiGroupSavePromptVO(false);
          }
bdca4a05   姜超   feature(*): 绩效审批修改
344
          Integer staffNum = kpiGroupUserBizService.queryShopPostCurStaffNum(dto.getPostId(), dto.getShopIds());
770c421f   姜超   feature(*): 草稿查询
345
          approvalBizService.applyApproveKpiDraft(dto, settingDraft, user, staffNum);
83fc9174   姜超   feature(*): 薪酬项查询...
346
          return new KpiGroupSavePromptVO(false);
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
347
348
      }
  
c19df250   姜超   feature(*): 绩效组人员...
349
      /**
566a519a   姜超   feature(*): 保存绩效排名组
350
351
352
353
       * 绩效组保存
       * @param dto
       */
      @Transactional(rollbackFor = Exception.class)
93b9fcae   姜超   feature(*): 保存绩效排名组
354
      @DisLock(prefix = "#this.getSavePrefix()", key = "#dto.getName()", message = "保存中,请勿重复操作")
ee345722   姜超   feature(*): 保存绩效排名组
355
      public KpiGroupSavePromptVO saveKpiGroupRankDraft(KpiGroupRankDTO dto, LoginAuthBean user, Boolean submit) {
566a519a   姜超   feature(*): 保存绩效排名组
356
357
          checkNameRepetition(dto.getId(), dto.getName());
          checkRankStarLadders(dto.getStarLadders(), dto.getStarEvaluationType());
ee345722   姜超   feature(*): 保存绩效排名组
358
          this.initKpi(dto);
566a519a   姜超   feature(*): 保存绩效排名组
359
          for (KpiGroupDTO kpiGroupDTO : dto.getKpiGroups()) {
566a519a   姜超   feature(*): 保存绩效排名组
360
361
362
363
              //检查数据
              this.checkKpi(kpiGroupDTO);
              this.checkNameRepetition(kpiGroupDTO.getId(), kpiGroupDTO.getName(), kpiGroupDTO.getDraftId());
              this.checkKpiLadders(kpiGroupDTO.getIndicators());
79b684db   姜超   feature(*): 薪酬上报数据
364
365
366
367
  //            KpiGroupSavePromptVO promptVo = this.checkShopKpiRepeat(kpiGroupDTO);
  //            if (promptVo.getPrompt()) {
  //                return promptVo;
  //            }
566a519a   姜超   feature(*): 保存绩效排名组
368
369
370
371
372
373
374
375
376
377
378
379
              setTargetVos(kpiGroupDTO);
          }
  
          SettingDraft settingDraft = getSettingDraft(dto, submit);
          settingDraftService.saveOrUpdate(settingDraft);
          if (! submit) {
              return new KpiGroupSavePromptVO(false);
          }
          approvalBizService.applyApproveKpiRankDraft(dto, settingDraft, user);
          return new KpiGroupSavePromptVO(false);
      }
  
abab7730   姜超   feature(*): 修改请求路径
380
  
566a519a   姜超   feature(*): 保存绩效排名组
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
      /**
       * 获取草稿
       *
       * @param dto
       * @return
       */
      public SettingDraft getSettingDraft(KpiGroupRankDTO dto, Boolean submit) {
          SettingDraft settingDraft = null;
          if (PublicUtil.isEmpty(dto.getDraftId())) {
              settingDraft = new SettingDraft();
              settingDraft.setGroupId(dto.getGroupId());
              settingDraft.setYn(Boolean.TRUE);
              settingDraft.setType(SettingDraftTypeEnum.KPI_GROUP_RANK);
          } else {
              settingDraft = settingDraftService.getById(dto.getDraftId());
              BV.notNull(settingDraft, "草稿配置不存在,请重试");
          }
  
02eaea43   姜超   feature(*): 绩效排名组修改
399
400
401
402
          List<Long> postIds = dto.getKpiGroups().stream().map(KpiGroupDTO::getPostId).distinct().collect(Collectors.toList());
          List<Long> shopIds = dto.getKpiGroups().stream().flatMap(kpiGroup -> kpiGroup.getShopIds().stream()).distinct().collect(Collectors.toList());
          settingDraft.setPostIds(postIds);
          settingDraft.setShopIds(shopIds);
566a519a   姜超   feature(*): 保存绩效排名组
403
404
405
406
407
408
409
410
411
412
413
          List<KpiGroupRankBaseInfoDTO> baseInfoDTOs = dto.getKpiGroups().stream().map(kpiGroup -> {
              return new KpiGroupRankBaseInfoDTO(kpiGroup);
          }).collect(Collectors.toList());
          settingDraft.setBaseInfo(JSON.toJSONString(baseInfoDTOs));
          settingDraft.setStatus(submit ? SettingDraftStatusEnum.RELEASE_APPROVAL : SettingDraftStatusEnum.NO_RELEASE);
          settingDraft.setName(dto.getName());
          settingDraft.setContent(JSONObject.toJSONString(dto));
          return settingDraft;
      }
  
      /**
770c421f   姜超   feature(*): 草稿查询
414
415
416
417
418
       * 获取草稿
       *
       * @param dto
       * @return
       */
077e6941   姜超   feature(*): 草稿修改
419
      public SettingDraft getSettingDraft(KpiGroupDTO dto, Boolean submit) {
770c421f   姜超   feature(*): 草稿查询
420
421
422
423
424
425
426
427
          SettingDraft settingDraft = null;
          if (PublicUtil.isEmpty(dto.getDraftId())) {
              settingDraft = new SettingDraft();
              settingDraft.setGroupId(dto.getGroupId());
              settingDraft.setYn(Boolean.TRUE);
              settingDraft.setType(SettingDraftTypeEnum.KPI);
              settingDraft.setPostId(dto.getPostId());
              settingDraft.setShopIds(dto.getShopIds());
770c421f   姜超   feature(*): 草稿查询
428
429
430
431
          } else {
              settingDraft = settingDraftService.getById(dto.getDraftId());
              BV.notNull(settingDraft, "草稿配置不存在,请重试");
          }
077e6941   姜超   feature(*): 草稿修改
432
          settingDraft.setStatus(submit ? SettingDraftStatusEnum.RELEASE_APPROVAL : SettingDraftStatusEnum.NO_RELEASE);
41a1d9fe   姜超   feature(*): 考评草稿修改
433
          settingDraft.setName(dto.getName());
770c421f   姜超   feature(*): 草稿查询
434
435
436
437
438
439
          settingDraft.setContent(JSONObject.toJSONString(dto));
          return settingDraft;
      }
  
  
      /**
566a519a   姜超   feature(*): 保存绩效排名组
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
       * 检查绩效组排名名称是否重复
       *
       * @param id
       * @param name
       */
      public void checkNameRepetition(Long id, String name) {
          int count = kpiGroupRankService.count(Wrappers.<KpiGroupRank>lambdaQuery()
                  .eq(KpiGroupRank::getName, name)
                  .ne(PublicUtil.isNotEmpty(id), KpiGroupRank::getId, id)
                  .eq(KpiGroupRank::getYn, Boolean.TRUE)
          );
          BV.isTrue(count <= 0, "绩效组排名名称重复,请重新输入");
      }
  
      /**
c19df250   姜超   feature(*): 绩效组人员...
455
456
457
458
459
       * 检查绩效组配置状态
       *
       * @param dto
       */
      public void checkKpi(KpiGroupDTO dto) {
a310d67e   姜超   feature(*): 绩效薪酬 ...
460
461
          Long postId = dto.getPostId();
          List<Long> shopIds = dto.getShopIds();
770c421f   姜超   feature(*): 草稿查询
462
463
464
465
466
467
468
469
470
471
472
473
474
475
  //        List<KpiGroup> effectKpis = kpiGroupService.getRepeatKpis(postId, shopIds, dto.getId(), dto.getBeginTime());
  //        if (PublicUtil.isNotEmpty(effectKpis)) {
  //            Optional<KpiGroup> optional = effectKpis.stream()
  //                    .filter(kpi -> ! kpi.getStatus().equals(SettingStatusEnum.INEFFECTIVE)).findFirst();
  //            if (optional.isPresent()) {
  //                KpiGroup kpiGroup = optional.get();
  //                List<String> shopNames = new ArrayList<>(kpiGroup.getShopNames());
  //                shopNames.retainAll(dto.getShopNames());
  //                throw new BusinessException("绩效组门店【" + String.join(",", shopNames) + "】存在" +
  //                        kpiGroup.getStatus().getName() + "配置");
  //            }
  //        }
          List<SettingDraft> settingDrafts = settingDraftService.getRepeatApprovals(postId, shopIds, SettingDraftTypeEnum.KPI,
                  SettingDraftStatusEnum.RELEASE_APPROVAL, dto.getBeginTime());
38313e77   姜超   feature(*): 草稿审批修改
476
477
478
          if (PublicUtil.isNotEmpty(settingDrafts)) {
              throw new BusinessException("绩效组门店存在正在生效中配置");
          }
a310d67e   姜超   feature(*): 绩效薪酬 ...
479
  
d628deba   姜超   feature(*): 修改参数校验
480
          for (KpiGroupIndicatorDTO indicator : dto.getIndicators()) {
79fd1142   xianpengcheng   更新:
481
482
483
484
485
              if (IndicatorCodeTypeEnum.COMBINE_INDICATOR.equals(indicator.getCodeType())){
                  if (PublicUtil.isEmpty(indicator.getCode())){
                      throw new BusinessException("指标库["+indicator.getName()+"]台阶参数选择为组合指标时,必须传入对应的组合指标编码!");
                  }
              }
d628deba   姜超   feature(*): 修改参数校验
486
487
488
489
490
              if (PublicUtil.isNotEmpty(indicator.getLadderParams())) {
                  BigDecimal proportion = indicator.getLadderParams().stream()
                          .map(KpiGroupIndicatorParamDTO::getProportion)
                          .reduce(BigDecimal.ZERO, BigDecimal::add);
                  BV.isTrue(Constant.ONE_HUNDRED.compareTo(proportion) == 0, "【" + indicator.getName() + "】台阶占比总和必须为100");
f78e65b3   姜超   feature(*): 绩效组参数校验
491
  
b524c598   姜超   feature(*): 绩效组参数校验
492
                  for (KpiGroupIndicatorParamDTO commissionParam : indicator.getLadderParams()) {
3042c640   张志伟   :fire:
493
                      if (! TargetTypeEnum.NO.equals(commissionParam.getTargetType()) &&
b524c598   姜超   feature(*): 绩效组参数校验
494
                              (PublicUtil.isEmpty(commissionParam.getTargetType()) || PublicUtil.isEmpty(commissionParam.getTargetValue()))) {
3042c640   张志伟   :fire:
495
                          commissionParam.setTargetType(TargetTypeEnum.NO);
b524c598   姜超   feature(*): 绩效组参数校验
496
497
                      }
                  }
d628deba   姜超   feature(*): 修改参数校验
498
499
500
              }
  
              if (PublicUtil.isNotEmpty(indicator.getCommissionParams())) {
a3d13c97   姜超   feature(*): 考评组保存
501
                  BigDecimal proportion = indicator.getCommissionParams().stream()
d628deba   姜超   feature(*): 修改参数校验
502
503
504
                          .map(KpiGroupIndicatorParamDTO::getProportion)
                          .reduce(BigDecimal.ZERO, BigDecimal::add);
                  BV.isTrue(Constant.ONE_HUNDRED.compareTo(proportion) == 0, "【" + indicator.getName() + "】提成占比总和必须为100");
d628deba   姜超   feature(*): 修改参数校验
505
  
b524c598   姜超   feature(*): 绩效组参数校验
506
                  for (KpiGroupIndicatorParamDTO commissionParam : indicator.getCommissionParams()) {
3042c640   张志伟   :fire:
507
                      if (! TargetTypeEnum.NO.equals(commissionParam.getTargetType()) &&
b524c598   姜超   feature(*): 绩效组参数校验
508
                              (PublicUtil.isEmpty(commissionParam.getTargetType()) || PublicUtil.isEmpty(commissionParam.getTargetValue()))) {
3042c640   张志伟   :fire:
509
                          commissionParam.setTargetType(TargetTypeEnum.NO);
b524c598   姜超   feature(*): 绩效组参数校验
510
511
                      }
                  }
f78e65b3   姜超   feature(*): 绩效组参数校验
512
              }
d628deba   姜超   feature(*): 修改参数校验
513
  
9dc5d6a0   姜超   feature(*): 薪酬组参数校验
514
  
f78e65b3   姜超   feature(*): 绩效组参数校验
515
              if (PublicUtil.isNotEmpty(indicator.getConds())) {
b524c598   姜超   feature(*): 绩效组参数校验
516
                  for (KpiGroupIndicatorPreconditionDTO preconditionDTO : indicator.getConds()) {
3042c640   张志伟   :fire:
517
                      if (! TargetTypeEnum.NO.equals(preconditionDTO.getTargetType()) &&
b524c598   姜超   feature(*): 绩效组参数校验
518
                              (PublicUtil.isEmpty(preconditionDTO.getTargetType()) || PublicUtil.isEmpty(preconditionDTO.getTargetValue()))) {
3042c640   张志伟   :fire:
519
                          preconditionDTO.setTargetType(TargetTypeEnum.NO);
b524c598   姜超   feature(*): 绩效组参数校验
520
521
                      }
                  }
f78e65b3   姜超   feature(*): 绩效组参数校验
522
              }
d628deba   姜超   feature(*): 修改参数校验
523
  
b524c598   姜超   feature(*): 绩效组参数校验
524
525
          }
  
c19df250   姜超   feature(*): 绩效组人员...
526
527
528
529
530
          //原来的绩效组配置不能在审批中
          if (PublicUtil.isEmpty(dto.getId())) {
              return;
          }
          KpiGroup kpiGroup = kpiGroupService.getById(dto.getId());
278ef9ef   姜超   feature(bug): 修改目...
531
532
533
534
535
  //        BV.notNull(kpiGroup, "绩效配置不存在,请重试");
          if (PublicUtil.isNotEmpty(kpiGroup)) {
              BV.isFalse((SettingStatusEnum.APPROVING.equals(kpiGroup.getStatus())), "审批中的绩效组配置不能编辑");
              dto.setKgc(kpiGroup.getKgc());
          }
c19df250   姜超   feature(*): 绩效组人员...
536
      }
f4f1f40b   姜超   feature(*): 月定时器
537
  
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
538
      /**
6d89f27c   姜超   feature(*): 计算排名修改
539
540
       * 检查绩效组排名名称是否重复
       *
6d89f27c   姜超   feature(*): 计算排名修改
541
       * @param id
9cabf1b9   姜超   feature(salaryGro...
542
       * @param name
6d89f27c   姜超   feature(*): 计算排名修改
543
       */
f0aa2cb7   姜超   feature(*): 审批修改
544
      public void checkNameRepetition(Long id, String name, Long draftId) {
6d89f27c   姜超   feature(*): 计算排名修改
545
546
547
548
          int count = kpiGroupService.count(Wrappers.<KpiGroup>lambdaQuery()
                  .eq(KpiGroup::getName, name)
                  .ne(PublicUtil.isNotEmpty(id), KpiGroup::getId, id)
                  .eq(KpiGroup::getYn, Boolean.TRUE)
579d0a1e   姜超   fix(indicators): ...
549
                  .eq(KpiGroup::getStatus, SettingStatusEnum.EFFECTIVE)
6d89f27c   姜超   feature(*): 计算排名修改
550
          );
9503f076   姜超   feature(*): 日志打印
551
552
553
554
555
  //        BV.isTrue(count <= 0, "绩效组名称重复,请重新输入");
          if (count > 0) {
              log.info("绩效组名称重复,name:{},id:{}: ", name, Optional.ofNullable(id).orElse(0L).toString());
              throw new BusinessException("绩效组名称重复,请重新输入");
          }
41a1d9fe   姜超   feature(*): 考评草稿修改
556
  
eb829e71   姜超   feature(*): 绩效组重复...
557
          List<SettingDraft> drafts = commonService.getEditDraftByName(name, SettingDraftTypeEnum.KPI, draftId);
41a1d9fe   姜超   feature(*): 考评草稿修改
558
          BV.isTrue(drafts.size() <= 0, "绩效组名称在草稿中存在,请重新输入");
6d89f27c   姜超   feature(*): 计算排名修改
559
560
561
      }
  
      /**
a310d67e   姜超   feature(*): 绩效薪酬 ...
562
563
564
       * 检查指标修改的权限
       * @param dto
       */
ee345722   姜超   feature(*): 保存绩效排名组
565
      private void initKpi(KpiGroupRankDTO dto) {
a310d67e   姜超   feature(*): 绩效薪酬 ...
566
567
          LocalDate currentTime = LocalDate.now();
          dto.setBeginTime((EffectMonthEnum.CURRENT_MONTH.equals(dto.getBeginTimeType()) ? currentTime : PublicUtil.getNextMonthFirstDay()));
a310d67e   姜超   feature(*): 绩效薪酬 ...
568
569
570
      }
  
      /**
f4f1f40b   姜超   feature(*): 月定时器
571
572
573
574
575
576
577
       * 检查绩效组配置是否重复
       * 同月
       * 之前没有这些门店配置,不提示
       * 有这些门店配置
       *      1)门店和之前相同不提示
       *      2)门店比之前少,之前ABC门店,现A门店,提示BC门店缺失绩效组配置
       *      3)门店比之前多,配置1 ABC门店, 配置2 DE门店,新增ABCD门店,提示E门店缺失绩效配置
f4f1f40b   姜超   feature(*): 月定时器
578
       * @param kpiGroupDTO
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
579
       */
83fc9174   姜超   feature(*): 薪酬项查询...
580
      private KpiGroupSavePromptVO checkShopKpiRepeat(KpiGroupDTO kpiGroupDTO) {
f4f1f40b   姜超   feature(*): 月定时器
581
          //强制提交,退出检查
79b684db   姜超   feature(*): 薪酬上报数据
582
583
584
  //        if (kpiGroupDTO.getForce()) {
  //            return new KpiGroupSavePromptVO(false);
  //        }
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
585
  
b5f3bfd0   姜超   feature(*): 处理重复绩...
586
          YearMonth yearMonth = YearMonth.now();
13166424   姜超   feature(*): 参数校验修改
587
          YearMonth beginTime = YearMonth.from(kpiGroupDTO.getBeginTime());
b5f3bfd0   姜超   feature(*): 处理重复绩...
588
          StringBuilder msgBuilder = new StringBuilder();
13166424   姜超   feature(*): 参数校验修改
589
          if (yearMonth.equals(beginTime)) {
83fc9174   姜超   feature(*): 薪酬项查询...
590
              KpiGroupRepeatQueryDTO effectRepeatDTO = KpiGroupRepeatQueryDTO.convertDto(kpiGroupDTO, SettingStatusEnum.EFFECTIVE);
b5f3bfd0   姜超   feature(*): 处理重复绩...
591
592
              List<KpiGroup> effectKpiGroups = kpiGroupService.queryRepeatKpiGroup(effectRepeatDTO);
              if (PublicUtil.isNotEmpty(effectKpiGroups)) {
dc2eb3fa   姜超   feature(*): 绩效组人员查看
593
594
595
596
                  msgBuilder.append("审批通过后").append(yearMonth.getMonth().getValue()).append("月份已生效绩效组配置会被移除,门店【");
                  HashSet<String> shopNames = effectKpiGroups.stream().map(KpiGroup::getShopNames).collect(HashSet::new, HashSet::addAll, HashSet::addAll);
                  msgBuilder.append(String.join(",", shopNames));
                  msgBuilder.append("】。");
b5f3bfd0   姜超   feature(*): 处理重复绩...
597
              }
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
598
          }
83fc9174   姜超   feature(*): 薪酬项查询...
599
          KpiGroupRepeatQueryDTO beEffectRepeatDTO = KpiGroupRepeatQueryDTO.convertDto(kpiGroupDTO, SettingStatusEnum.BE_EFFECTIVE);
b5f3bfd0   姜超   feature(*): 处理重复绩...
600
601
602
603
604
605
606
          List<KpiGroup> beKpiGroups = kpiGroupService.queryRepeatKpiGroup(beEffectRepeatDTO);
          if (PublicUtil.isNotEmpty(beKpiGroups)) {
              if (msgBuilder.length() == 0) {
                  msgBuilder.append("审批通过后");
              }
              Map<LocalDate, List<KpiGroup>> monthKpiMap = beKpiGroups.stream().collect(Collectors.groupingBy(KpiGroup::getBeginTime));
              for (Map.Entry<LocalDate, List<KpiGroup>> monthKpi : monthKpiMap.entrySet()) {
dc2eb3fa   姜超   feature(*): 绩效组人员查看
607
608
609
                  msgBuilder.append(monthKpi.getKey().getMonth().getValue()).append("月份待生效绩效组配置会被移除,门店【");
                  HashSet<String> shopNames = monthKpi.getValue().stream().map(KpiGroup::getShopNames).collect(HashSet::new, HashSet::addAll, HashSet::addAll);
                  msgBuilder.append(String.join(",", shopNames));
b5f3bfd0   姜超   feature(*): 处理重复绩...
610
              }
dc2eb3fa   姜超   feature(*): 绩效组人员查看
611
              msgBuilder.append("】。");
b5f3bfd0   姜超   feature(*): 处理重复绩...
612
613
          }
          if (msgBuilder.length() == 0) {
83fc9174   姜超   feature(*): 薪酬项查询...
614
              return new KpiGroupSavePromptVO(false);
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
615
          }
83fc9174   姜超   feature(*): 薪酬项查询...
616
          return new KpiGroupSavePromptVO(true, msgBuilder.toString());
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
617
618
      }
  
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
619
      /**
ffdcc81d   姜超   feature(*): 阶梯配置检查修改
620
621
622
623
624
625
626
       * 检查阶梯分值
       * @param indicators
       */
      private void checkKpiLadders(List<KpiGroupIndicatorDTO> indicators) {
          Integer baseScore = null;
          List<KpiGroupIndicatorLaddersDTO> indicatorLadders = null;
          for (KpiGroupIndicatorDTO indicatorDto : indicators) {
8464701b   姜超   feature(*): 绩效组变动通知
627
628
629
              if (ScoreWayEnum.NORMAL.equals(indicatorDto.getScoreWay())) {
                  continue;
              }
9dc5d6a0   姜超   feature(*): 薪酬组参数校验
630
631
              BV.isTrue(PublicUtil.isNotEmpty(indicatorDto.getLadderParams()), "阶梯得分计算,台阶参数不能为空");
              BV.isTrue(PublicUtil.isNotEmpty(indicatorDto.getIndicatorLadders()), "阶梯得分计算,台阶不能为空");
ffdcc81d   姜超   feature(*): 阶梯配置检查修改
632
633
              baseScore = indicatorDto.getBaseScore();
              indicatorLadders = indicatorDto.getIndicatorLadders();
b7dd7786   姜超   feature(*): 阶梯值校验...
634
              Collections.sort(indicatorLadders);
fc885c22   姜超   feature(*): 绩效组阶梯...
635
  
6786b5e1   姜超   feature(*): 绩效组配置修改
636
637
638
639
640
641
642
643
644
645
646
              //阶梯值校验  标准分不能超过指标基础分,阶梯值必须连续
              for (KpiGroupIndicatorLaddersDTO laddersDtos : indicatorLadders) {
                  //阶梯标准分不能超过绩效分值
                  if (laddersDtos.getStandardScore().compareTo(baseScore) > 0) {
                      throw new BusinessException("【" + indicatorDto.getName() + "】的阶梯标准分不能超过绩效分值");
                  }
              }
              //校验阶梯
              CommonService.checkLadders(indicatorLadders, indicatorDto.getName());
  
              //校验条件
9dc5d6a0   姜超   feature(*): 薪酬组参数校验
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
              if (PublicUtil.isNotEmpty(indicatorDto.getConds())) {
                  for (KpiGroupIndicatorPreconditionDTO condDTO : indicatorDto.getConds()) {
                      BV.isTrue(PublicUtil.isNotEmpty(condDTO.getCondLadders()), "得分条件台阶不能为空");
                      CommonService.checkLadders(condDTO.getCondLadders(), indicatorDto.getName());
                  }
              }
  
              //赋空值
              if (PublicUtil.isEmpty(indicatorDto.getLadderParams())) {
                  indicatorDto.setLadderParams(new ArrayList<>());
              }
              if (PublicUtil.isEmpty(indicatorDto.getCommissionParams())) {
                  indicatorDto.setCommissionParams(new ArrayList<>());
              }
              if (PublicUtil.isEmpty(indicatorDto.getConds())) {
                  indicatorDto.setConds(new ArrayList<>());
6786b5e1   姜超   feature(*): 绩效组配置修改
663
664
665
666
667
              }
  
          }
      }
  
6786b5e1   姜超   feature(*): 绩效组配置修改
668
669
  
      /**
566a519a   姜超   feature(*): 保存绩效排名组
670
671
672
673
       * 检查星级阶梯分值
       * 1. 赋初始值
       * 2. 校验连续性、上限下限大小、所有星级都已经配置
       * @param laddersDTOS
6786b5e1   姜超   feature(*): 绩效组配置修改
674
       */
566a519a   姜超   feature(*): 保存绩效排名组
675
676
677
678
679
680
681
682
683
684
      private void checkRankStarLadders(List<KpiGroupRankStarLaddersDTO> laddersDTOS, StarEvaluationEnum starEvaluationType) {
          Set<StarLevelEnum> levelEnumSet = Arrays.stream(StarLevelEnum.values()).collect(Collectors.toSet());
          Collections.sort(laddersDTOS, new Comparator<KpiGroupRankStarLaddersDTO>() {
              @Override
              public int compare(KpiGroupRankStarLaddersDTO o1, KpiGroupRankStarLaddersDTO o2) {
                  if (starEvaluationType.equals(StarEvaluationEnum.SCORING_RATE)) {
                      return o2.getLevel().getValue() - o1.getLevel().getValue();
                  } else {
                      return o1.getLevel().getValue() - o2.getLevel().getValue();
                  }
6786b5e1   姜超   feature(*): 绩效组配置修改
685
              }
566a519a   姜超   feature(*): 保存绩效排名组
686
687
688
689
690
691
692
          });
          //校验阶梯
          CommonService.checkLadders(laddersDTOS);
          //阶梯值校验  标准分不能超过指标基础分,阶梯值必须连续
          for (KpiGroupRankStarLaddersDTO dto : laddersDTOS) {
              if (! levelEnumSet.remove(dto.getLevel())) {
                  throw new BusinessException("【" + dto.getLevel().getName() + "】级的阶梯配置重复");
6786b5e1   姜超   feature(*): 绩效组配置修改
693
              }
b7dd7786   姜超   feature(*): 阶梯值校验...
694
          }
566a519a   姜超   feature(*): 保存绩效排名组
695
696
697
698
699
700
          if (levelEnumSet.size() != 0) {
              List<String> levels = levelEnumSet.stream().map(level -> {
                  return level.getName() + "级";
              }).collect(Collectors.toList());
              throw new BusinessException("【" + String.join(",", levels) + "】阶梯未配置");
          }
b7dd7786   姜超   feature(*): 阶梯值校验...
701
702
703
704
705
706
707
708
      }
  
      /**
       * 检查星级阶梯分值
       * 1. 赋初始值
       * 2. 校验连续性、上限下限大小、所有星级都已经配置
       * @param laddersDTOS
       */
3083fec7   姜超   feature(*): 薪酬组保存...
709
      private void checkStarLadders(List<KpiStarLaddersDTO> laddersDTOS, StarEvaluationEnum starEvaluationType) {
b7dd7786   姜超   feature(*): 阶梯值校验...
710
          Set<StarLevelEnum> levelEnumSet = Arrays.stream(StarLevelEnum.values()).collect(Collectors.toSet());
3083fec7   姜超   feature(*): 薪酬组保存...
711
712
713
714
          Collections.sort(laddersDTOS, new Comparator<KpiStarLaddersDTO>() {
              @Override
              public int compare(KpiStarLaddersDTO o1, KpiStarLaddersDTO o2) {
                  if (starEvaluationType.equals(StarEvaluationEnum.SCORING_RATE)) {
3083fec7   姜超   feature(*): 薪酬组保存...
715
                      return o2.getLevel().getValue() - o1.getLevel().getValue();
a7262215   姜超   feature(*): 薪酬组阶梯校验
716
717
                  } else {
                      return o1.getLevel().getValue() - o2.getLevel().getValue();
3083fec7   姜超   feature(*): 薪酬组保存...
718
                  }
3083fec7   姜超   feature(*): 薪酬组保存...
719
720
              }
          });
fc885c22   姜超   feature(*): 绩效组阶梯...
721
722
          //校验阶梯
          CommonService.checkLadders(laddersDTOS);
b7dd7786   姜超   feature(*): 阶梯值校验...
723
724
          //阶梯值校验  标准分不能超过指标基础分,阶梯值必须连续
          for (KpiStarLaddersDTO dto : laddersDTOS) {
ffdcc81d   姜超   feature(*): 阶梯配置检查修改
725
726
727
728
729
730
731
732
733
              if (! levelEnumSet.remove(dto.getLevel())) {
                  throw new BusinessException("【" + dto.getLevel().getName() + "】级的阶梯配置重复");
              }
          }
          if (levelEnumSet.size() != 0) {
              List<String> levels = levelEnumSet.stream().map(level -> {
                  return level.getName() + "级";
              }).collect(Collectors.toList());
              throw new BusinessException("【" + String.join(",", levels) + "】阶梯未配置");
3743789f   姜超   [jiangchao] 绩效组查询接口
734
735
736
737
          }
      }
  
      /**
b0f4e55e   姜超   [jiangchao] 绩效组保存审批
738
       * 审批kpiGroup
f4f1f40b   姜超   feature(*): 月定时器
739
       * 生效时间  当前时间 之前,那么这个审批是无效的
38313e77   姜超   feature(*): 草稿审批修改
740
741
742
743
744
745
746
747
748
749
750
751
752
       * 次月生效
       * 1. 将次月生效的重复绩效配置设置为失效,等待月定时器执行
       * 当月生效
       * 1. 将当月生效的重复绩效配置设置为失效,将之前配置设置为无效,将状态设置为生效中
       * @param approvalRecord
       * @param result
       */
      @Transactional(rollbackFor = Exception.class)
      public void approvalKpiGroupDraft(ApprovalRecord approvalRecord, ApprovalResultEvent result) {
          log.info("收到绩效组配置变更审批信息:{}", JSON.toJSONString(approvalRecord));
  
          SettingDraft settingDraft = settingDraftService.getById(approvalRecord.getDataId());
          BV.isTrue(PublicUtil.isNotEmpty(settingDraft), "考评草稿数据不存在");
38313e77   姜超   feature(*): 草稿审批修改
753
  
f83b7a03   姜超   feature(*): 绩效草稿修改
754
755
          SettingDraftStatusEnum draftStatus = (result.getAgree()) ? SettingDraftStatusEnum.RELEASE_APPROVAL_AGREE :
                  SettingDraftStatusEnum.RELEASE_APPROVAL_REJECT;
f83b7a03   姜超   feature(*): 绩效草稿修改
756
757
  
          if (! result.getAgree()) {
f0aa2cb7   姜超   feature(*): 审批修改
758
759
760
761
762
763
764
              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())
                  );
              }
f83b7a03   姜超   feature(*): 绩效草稿修改
765
766
767
              return;
          }
  
38313e77   姜超   feature(*): 草稿审批修改
768
769
770
771
772
          KpiGroupDTO kpiGroupDTO = JSON.parseObject(settingDraft.getContent(), KpiGroupDTO.class);
          KpiGroup kpiGroup = kpiGroupDataService.saveKpiGroup(kpiGroupDTO);
          kpiGroupDataService.saveKpiIndicators(kpiGroupDTO.getIndicators(), kpiGroup);
          kpiGroupDataService.saveKpiStarLadders(kpiGroupDTO.getStarLadders(), kpiGroup);
  
077e6941   姜超   feature(*): 草稿修改
773
          settingDraftService.update(Wrappers.<SettingDraft>lambdaUpdate()
40d3a544   姜超   feature(*): 草稿查看
774
775
776
777
778
                  .set(SettingDraft::getUnionId, kpiGroup.getId())
                  .set(SettingDraft::getStatus, draftStatus)
                  .set(SettingDraft::getUpdateTime, new Date())
                  .eq(SettingDraft::getId, settingDraft.getId())
          );
38313e77   姜超   feature(*): 草稿审批修改
779
780
781
782
783
784
785
786
787
788
789
790
791
  
          //通知绩效组人员
          KpiGroupChangeEvent kpiGroupChangeEvent = PublicUtil.copy(kpiGroup, KpiGroupChangeEvent.class);
          EventBusUtil.asyncPost(kpiGroupChangeEvent);
  
          YearMonth yearMonth = YearMonth.now();
          YearMonth beginTime = YearMonth.from(kpiGroup.getBeginTime());
          kpiGroup.getBeginTime();
          if (yearMonth.isAfter(beginTime)) {
              log.info("审批通过时间在绩效组生效时间之后,等待定时器执行");
              return;
          }
  
f83b7a03   姜超   feature(*): 绩效草稿修改
792
793
          //处理重复绩效组配置数据
          this.processRepeatKpiGroup(kpiGroup);
38313e77   姜超   feature(*): 草稿审批修改
794
795
796
797
798
      }
  
      /**
       * 审批kpiGroup
       * 生效时间  当前时间 之前,那么这个审批是无效的
ee345722   姜超   feature(*): 保存绩效排名组
799
800
801
802
803
       * 次月生效
       * 1. 将次月生效的重复绩效配置设置为失效,等待月定时器执行
       * 当月生效
       * 1. 将当月生效的重复绩效配置设置为失效,将之前配置设置为无效,将状态设置为生效中
       * @param approvalRecord
ee345722   姜超   feature(*): 保存绩效排名组
804
805
       */
      @Transactional(rollbackFor = Exception.class)
c62ad9c0   姜超   feature(*): 计算薪酬修改
806
      public void saveKpiGroupRankDraft(ApprovalRecord approvalRecord, SettingDraft settingDraft) {
ee345722   姜超   feature(*): 保存绩效排名组
807
808
          log.info("收到绩效组配置变更审批信息:{}", JSON.toJSONString(approvalRecord));
          KpiGroupRankDTO kpiGroupRankDTO = JSON.parseObject(settingDraft.getContent(), KpiGroupRankDTO.class);
c62ad9c0   姜超   feature(*): 计算薪酬修改
809
          EffectMonthEnum effectMonth = kpiGroupRankDTO.getBeginTimeType();
ee345722   姜超   feature(*): 保存绩效排名组
810
811
          List<Long> kpiGroupIds = new ArrayList<>();
          for (KpiGroupDTO kpiGroupDTO : kpiGroupRankDTO.getKpiGroups()) {
f49aba31   姜超   feature(*): 绩效排名组...
812
813
              kpiGroupDTO.setBeginTime(kpiGroupRankDTO.getBeginTime());
              kpiGroupDTO.setGroupId(kpiGroupRankDTO.getGroupId());
ee345722   姜超   feature(*): 保存绩效排名组
814
815
816
817
818
819
              KpiGroup kpiGroup = kpiGroupDataService.saveKpiGroup(kpiGroupDTO);
              kpiGroupIds.add(kpiGroup.getId());
              kpiGroupDataService.saveKpiIndicators(kpiGroupDTO.getIndicators(), kpiGroup);
              //通知绩效组人员
              KpiGroupChangeEvent kpiGroupChangeEvent = PublicUtil.copy(kpiGroup, KpiGroupChangeEvent.class);
              EventBusUtil.asyncPost(kpiGroupChangeEvent);
c62ad9c0   姜超   feature(*): 计算薪酬修改
820
              if (effectMonth.equals(EffectMonthEnum.NEXT_MONTH)) {
ee345722   姜超   feature(*): 保存绩效排名组
821
                  log.info("审批通过时间在绩效组生效时间之后,等待定时器执行");
c62ad9c0   姜超   feature(*): 计算薪酬修改
822
                  continue;
ee345722   姜超   feature(*): 保存绩效排名组
823
              }
ee345722   姜超   feature(*): 保存绩效排名组
824
825
826
827
828
829
830
831
832
833
834
835
              //处理重复绩效组配置数据
              this.processRepeatKpiGroup(kpiGroup);
          }
          if (PublicUtil.isNotEmpty(kpiGroupRankDTO.getId())) {
              kpiGroupRankService.update(Wrappers.<KpiGroupRank>lambdaUpdate()
                      .set(KpiGroupRank::getStatus, SettingStatusEnum.INEFFECTIVE)
                      .set(KpiGroupRank::getUpdateTime, new Date())
                      .eq(KpiGroupRank::getId, settingDraft.getId())
              );
          }
          KpiGroupRank kpiGroupRank = this.convertPO(kpiGroupRankDTO, kpiGroupIds);
          kpiGroupRankService.saveOrUpdate(kpiGroupRank);
c62ad9c0   姜超   feature(*): 计算薪酬修改
836
          this.inEffectiveRank(kpiGroupRank.getGroupId());
ee345722   姜超   feature(*): 保存绩效排名组
837
838
839
840
841
842
843
844
845
          this.saveKpiGroupRankStarLadders(kpiGroupRankDTO, kpiGroupRank);
          settingDraftService.update(Wrappers.<SettingDraft>lambdaUpdate()
                  .set(SettingDraft::getUnionId, kpiGroupRank.getId())
                  .set(SettingDraft::getUpdateTime, new Date())
                  .eq(SettingDraft::getId, settingDraft.getId())
          );
      }
  
      /**
c62ad9c0   姜超   feature(*): 计算薪酬修改
846
847
848
849
850
851
       * 失效绩效组为空的排名组
       * @param groupId
       */
      @Transactional(rollbackFor = Exception.class)
      public void inEffectiveRank(Long groupId) {
          List<KpiGroupRank> kpiGroupRanks = kpiGroupRankService.list(Wrappers.<KpiGroupRank>lambdaQuery()
f49aba31   姜超   feature(*): 绩效排名组...
852
                  .eq(KpiGroupRank::getStatus, SettingStatusEnum.EFFECTIVE)
c62ad9c0   姜超   feature(*): 计算薪酬修改
853
854
855
856
857
                  .eq(KpiGroupRank::getYn, Boolean.TRUE)
                  .eq(KpiGroupRank::getGroupId, groupId)
          );
          for (KpiGroupRank kpiGroupRank : kpiGroupRanks) {
              int count = kpiGroupService.count(Wrappers.<KpiGroup>lambdaQuery()
f49aba31   姜超   feature(*): 绩效排名组...
858
                      .in(KpiGroup::getId, kpiGroupRank.getKpiGroupIds())
c62ad9c0   姜超   feature(*): 计算薪酬修改
859
860
861
862
863
864
865
866
867
868
869
870
871
                      .eq(KpiGroup::getYn, Boolean.TRUE)
                      .eq(KpiGroup::getStatus, SettingStatusEnum.EFFECTIVE)
              );
              if (count <= 0) {
                  kpiGroupRank.setEndTime(LocalDate.now().minusDays(1));
                  kpiGroupRank.setStatus(SettingStatusEnum.INEFFECTIVE);
                  kpiGroupRankService.updateById(kpiGroupRank);
              }
          }
  
      }
  
      /**
ee345722   姜超   feature(*): 保存绩效排名组
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
       * 保存绩效星级评定阶梯
       *
       * @param dto
       * @param kpiGroupRank
       * @return
       */
      @Transactional(rollbackFor = Exception.class)
      public void saveKpiGroupRankStarLadders(KpiGroupRankDTO dto, KpiGroupRank kpiGroupRank) {
          if (PublicUtil.isNotEmpty(dto.getId())) {
              kpiGroupRankStarLaddersService.update(Wrappers.<KpiGroupRankStarLadders>lambdaUpdate()
                      .eq(KpiGroupRankStarLadders::getKpiGroupRankId, dto.getId())
                      .eq(KpiGroupRankStarLadders::getYn, Boolean.TRUE)
                      .set(KpiGroupRankStarLadders::getYn, Boolean.FALSE)
              );
          }
          List<KpiGroupRankStarLaddersDTO> starLaddersDtos = dto.getStarLadders();
          List<KpiGroupRankStarLadders> starLadders = Lists.newArrayListWithCapacity(starLaddersDtos.size());
          Long kpiGroupRankId = kpiGroupRank.getId();
          KpiGroupRankStarLadders starLadder = null;
          for (KpiGroupRankStarLaddersDTO starLaddersDto : starLaddersDtos) {
              starLadder = PublicUtil.copy(starLaddersDto, KpiGroupRankStarLadders.class);
              starLadder.setUpper(starLadder.getUpper().divide(Constant.ONE_HUNDRED, 2, RoundingMode.HALF_UP));
              starLadder.setLower(starLadder.getLower().divide(Constant.ONE_HUNDRED, 2, RoundingMode.HALF_UP));
              starLadder.setKpiGroupRankId(kpiGroupRankId);
              starLadders.add(starLadder);
          }
          kpiGroupRankStarLaddersService.saveBatch(starLadders);
      }
  
      /**
       * 转换对象
       *
       * @param dto
       * @return
       */
      public KpiGroupRank convertPO(KpiGroupRankDTO dto, List<Long> kpiGroupIds) {
          KpiGroupRank kpiGroupRank = new KpiGroupRank();
          kpiGroupRank.setStatus(SettingStatusEnum.EFFECTIVE);
          kpiGroupRank.setKpiGroupIds(kpiGroupIds);
          kpiGroupRank.setGroupId(dto.getGroupId());
          kpiGroupRank.setYn(Boolean.TRUE);
          kpiGroupRank.setName(dto.getName());
          kpiGroupRank.setStarEvaluationType(dto.getStarEvaluationType());
c62ad9c0   姜超   feature(*): 计算薪酬修改
915
916
917
          if (EffectMonthEnum.CURRENT_MONTH.equals(dto.getBeginTimeType())) {
              kpiGroupRank.setBeginTime(LocalDate.now());
          }
ee345722   姜超   feature(*): 保存绩效排名组
918
919
920
          if (PublicUtil.isNotEmpty(dto.getRevokedScoreRatio())) {
              kpiGroupRank.setRevokedScoreRatio(dto.getRevokedScoreRatio().divide(Constant.ONE_HUNDRED, 2, RoundingMode.HALF_UP));
          }
27466a63   姜超   feature(*): 绩效排名组...
921
922
923
924
          List<Long> postIds = dto.getKpiGroups().stream().map(KpiGroupDTO::getPostId).distinct().collect(Collectors.toList());
          List<Long> shopIds = dto.getKpiGroups().stream().flatMap(kpiGroup -> kpiGroup.getShopIds().stream()).distinct().collect(Collectors.toList());
          kpiGroupRank.setPostIds(postIds);
          kpiGroupRank.setShopIds(shopIds);
ee345722   姜超   feature(*): 保存绩效排名组
925
926
927
928
929
930
          return kpiGroupRank;
      }
  
      /**
       * 审批kpiGroup
       * 生效时间  当前时间 之前,那么这个审批是无效的
f4f1f40b   姜超   feature(*): 月定时器
931
932
933
934
       * 次月生效
       * 1. 将次月生效的重复绩效配置设置为失效,等待月定时器执行
       * 当月生效
       * 1. 将当月生效的重复绩效配置设置为失效,将之前配置设置为无效,将状态设置为生效中
7c9d0419   姜超   feature(*): 注释修改、...
935
936
       * @param approvalRecord
       * @param result
b0f4e55e   姜超   [jiangchao] 绩效组保存审批
937
938
       */
      @Transactional(rollbackFor = Exception.class)
7c9d0419   姜超   feature(*): 注释修改、...
939
940
      public void approvalKpiGroup(ApprovalRecord approvalRecord, ApprovalResultEvent result) {
          log.info("收到绩效组配置变更审批信息:{}", JSON.toJSONString(approvalRecord));
29887f53   姜超   feature(*): 审批星级特...
941
          KpiGroup kpiGroup = kpiGroupService.getById(approvalRecord.getDataId());
7c9d0419   姜超   feature(*): 注释修改、...
942
          if (! result.getAgree()) {
088e4c28   姜超   fix(group): 绩效组、薪...
943
944
945
946
947
              kpiGroupService.update(Wrappers.<KpiGroup>lambdaUpdate()
                      .set(KpiGroup::getStatus, SettingStatusEnum.INEFFECTIVE)
                      .set(KpiGroup::getYn, Boolean.FALSE)
                      .eq(KpiGroup::getId, kpiGroup.getId())
              );
f4f1f40b   姜超   feature(*): 月定时器
948
949
              return;
          }
8464701b   姜超   feature(*): 绩效组变动通知
950
951
952
953
954
  
          //通知绩效组人员
          KpiGroupChangeEvent kpiGroupChangeEvent = PublicUtil.copy(kpiGroup, KpiGroupChangeEvent.class);
          EventBusUtil.asyncPost(kpiGroupChangeEvent);
  
f4f1f40b   姜超   feature(*): 月定时器
955
          YearMonth yearMonth = YearMonth.now();
f4f1f40b   姜超   feature(*): 月定时器
956
957
958
          YearMonth beginTime = YearMonth.from(kpiGroup.getBeginTime());
          kpiGroup.getBeginTime();
          if (yearMonth.isAfter(beginTime)) {
ff09083a   姜超   fix(*): 薪酬池查询修改
959
              log.info("审批通过时间在绩效组生效时间之后,等待定时器执行");
f4f1f40b   姜超   feature(*): 月定时器
960
961
              return;
          }
e01fd137   姜超   feat(*): 定时器修改、审批...
962
  
b5f3bfd0   姜超   feature(*): 处理重复绩...
963
964
          //处理重复绩效组配置数据
          this.processRepeatKpiGroup(kpiGroup);
e01fd137   姜超   feat(*): 定时器修改、审批...
965
      }
3743789f   姜超   [jiangchao] 绩效组查询接口
966
  
e01fd137   姜超   feat(*): 定时器修改、审批...
967
      /**
b5f3bfd0   姜超   feature(*): 处理重复绩...
968
969
970
       * 处理重复数据
       * 1. 次月之后生效,需要处理次月后重复的待生效数据
       * 2. 当月生效,   需要处理当月后重复的待生效数据,处理当前重复的生效数据
e01fd137   姜超   feat(*): 定时器修改、审批...
971
972
       * @param kpiGroup
       */
b5f3bfd0   姜超   feature(*): 处理重复绩...
973
      public void processRepeatKpiGroup(KpiGroup kpiGroup){
008e92b0   xianpengcheng   测试kgc重复,加日志
974
          log.info("原kgc: {}",kpiGroup.getKgc());
b5f3bfd0   姜超   feature(*): 处理重复绩...
975
976
977
          YearMonth yearMonth = YearMonth.now();
          YearMonth beginTime = YearMonth.from(kpiGroup.getBeginTime());
          //删除重复的待生效配置数据(时间在此绩效组配置之后、同岗位、同门店)
a207ee2d   姜超   feature(*): 星级调整查询人员
978
          KpiGroupRepeatQueryDTO beEffectRepeatDTO = KpiGroupRepeatQueryDTO.convertToBeEffectiveDTO(kpiGroup);
b5f3bfd0   姜超   feature(*): 处理重复绩...
979
          List<KpiGroup> beKpiGroups = kpiGroupService.queryRepeatKpiGroup(beEffectRepeatDTO);
a310d67e   姜超   feature(*): 绩效薪酬 ...
980
          kpiGroupDataService.delInEffective(beKpiGroups);
b5f3bfd0   姜超   feature(*): 处理重复绩...
981
982
983
984
985
  
          SettingStatusEnum status = SettingStatusEnum.BE_EFFECTIVE;
          //当月生效,处理当前重复的生效数据
          if (yearMonth.equals(beginTime)) {
              status = SettingStatusEnum.EFFECTIVE;
a207ee2d   姜超   feature(*): 星级调整查询人员
986
              KpiGroupRepeatQueryDTO effectRepeatDTO = KpiGroupRepeatQueryDTO.convertToEffectiveDTO(kpiGroup);
b5f3bfd0   姜超   feature(*): 处理重复绩...
987
988
              List<KpiGroup> effectKpiGroups = kpiGroupService.queryRepeatKpiGroup(effectRepeatDTO);
              kpiGroupDataService.modifyStatusByKpis(effectKpiGroups, SettingStatusEnum.INEFFECTIVE);
008e92b0   xianpengcheng   测试kgc重复,加日志
989
              log.info("effectKpiGroups : {}",JSON.toJSONString(effectKpiGroups));
f17d9632   xianpengcheng   更新kgc重复问题
990
991
992
993
              if (CollectionUtils.isEmpty(effectKpiGroups)){
                  //如果没有查询到,说明岗位和门店匹配不上,该条审批是一条新的kgc,查询到了会把数据置为失效,改条审批进行覆盖原数据,共用一个kgc
                  kpiGroup.setKgc(PublicUtil.getUUID());
              }
b0f4e55e   姜超   [jiangchao] 绩效组保存审批
994
          }
e01fd137   姜超   feat(*): 定时器修改、审批...
995
  
008e92b0   xianpengcheng   测试kgc重复,加日志
996
          log.info("最终kgc: {}",kpiGroup.getKgc());
43817799   姜超   feature(*): 星级考核审批
997
          kpiGroupDataService.modifyStatusById(kpiGroup, status);
e01fd137   姜超   feat(*): 定时器修改、审批...
998
999
1000
      }
  
      /**
dc2eb3fa   姜超   feature(*): 绩效组人员查看
1001
1002
1003
       * 所有集团生效的绩效组配置
       */
      public Map<Long, List<KpiGroup>> postEffectKpis(){
5f57db6b   姜超   fix(*): 薪酬编码修改、绩效...
1004
1005
          Date queryDate = DateUtil.localDateTime2Date(LocalDateTime.now().minusDays(1L));
          List<KpiGroup> kpiGroups = kpiGroupService.getAllEffectGroups(queryDate);
dc2eb3fa   姜超   feature(*): 绩效组人员查看
1006
          if (PublicUtil.isEmpty(kpiGroups)) {
5f57db6b   姜超   fix(*): 薪酬编码修改、绩效...
1007
              log.info("时间:{},没有正在生效中的绩效组配置", new SimpleDateFormat("yyyy-MM-dd").format(queryDate));
dc2eb3fa   姜超   feature(*): 绩效组人员查看
1008
1009
1010
              return Maps.newHashMap();
          }
          return kpiGroups.stream().collect(Collectors.groupingBy(KpiGroup::getPostId));
dc2eb3fa   姜超   feature(*): 绩效组人员查看
1011
      }
7bb129f4   姜超   fix(*): 修改报错
1012
  
770c421f   姜超   feature(*): 草稿查询
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
      /**
       * 删除绩效组
       *
       * @param id
       */
      public void delKpiGroup(Long id, LoginAuthBean currentUser) {
          KpiGroup kpiGroup = kpiGroupService.getById(id);
          BV.notNull(kpiGroup, "绩效配置不存在,请重试");
          BV.isTrue(SettingStatusEnum.DRAFT.equals(kpiGroup.getStatus()), "绩效配置不是草稿状态,不能删除");
  
          kpiGroup.setUpdateTime(new Date());
          kpiGroup.setUpdateBy(currentUser.getUserId());
          kpiGroup.setYn(Boolean.FALSE);
          kpiGroupService.updateById(kpiGroup);
  
          //删除草稿
          SettingDraft settingDraft = settingDraftService.getOne(Wrappers.<SettingDraft>lambdaQuery()
                          .eq(SettingDraft::getUnionId, id)
                          .eq(SettingDraft::getYn, Boolean.TRUE)
                  , Boolean.FALSE);
          if (PublicUtil.isEmpty(settingDraft)) {
              return;
          }
          settingDraft.setUpdateTime(new Date());
          settingDraft.setYn(Boolean.FALSE);
          settingDraftService.updateById(settingDraft);
      }
  
      /**
       * 保存考评草稿
       * @param dto
       */
      public void saveKpiDraft(KpiGroupDTO dto, LoginAuthBean currentUser) {
          KpiGroup kpiGroup = null;
          SettingDraft settingDraft = null;
          if (PublicUtil.isNotEmpty(dto.getId())) {
              kpiGroup = kpiGroupService.getById(dto.getId());
              BV.isTrue(PublicUtil.isNotEmpty(kpiGroup), "考评数据不存在");
              kpiGroup = PublicUtil.copy(dto, KpiGroup.class);
  
  
              settingDraft = settingDraftService.getOne(Wrappers.<SettingDraft>lambdaQuery()
                              .eq(SettingDraft::getUnionId, dto.getId())
                              .eq(SettingDraft::getYn, Boolean.TRUE)
                      , Boolean.FALSE);
              BV.isTrue(PublicUtil.isNotEmpty(settingDraft), "考评草稿数据不存在");
          } else {
              kpiGroup = PublicUtil.copy(dto, KpiGroup.class);
  
              settingDraft = new SettingDraft();
              settingDraft.setGroupId(currentUser.getGroupId());
              settingDraft.setUnionId(-1L);
              settingDraft.setUnionId(kpiGroup.getId());
              settingDraft.setType(SettingDraftTypeEnum.EVAL);
          }
          kpiGroup.setStatus(SettingStatusEnum.DRAFT);
          kpiGroupService.saveOrUpdate(kpiGroup);
  
          settingDraft.setContent(JSON.toJSONString(dto));
          settingDraftService.saveOrUpdate(settingDraft);
      }
  
077e6941   姜超   feature(*): 草稿修改
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
      /**
       * 禁用绩效组
       * @param id
       */
      public void disableGroup(Long id, LoginAuthBean currentUser) {
          KpiGroup kpiGroup = kpiGroupService.getById(id);
          BV.notNull(kpiGroup, "绩效配置不存在,请重试");
  
          Boolean statusCheck = SettingStatusEnum.BE_EFFECTIVE.equals(kpiGroup.getStatus()) ||
                  SettingStatusEnum.EFFECTIVE.equals(kpiGroup.getStatus());
          BV.isTrue(statusCheck, "只有生效中、待生效绩效组能禁用");
  
          log.info("禁用绩效组,id:{},操作人:{}", id, currentUser);
  
077e6941   姜超   feature(*): 草稿修改
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
          kpiGroupService.update(Wrappers.<KpiGroup>lambdaUpdate()
                  .set(KpiGroup::getUpdateTime, new Date())
                  .set(KpiGroup::getYn, Boolean.FALSE)
                  .eq(KpiGroup::getId, kpiGroup.getId())
          );
  
          if (SettingStatusEnum.EFFECTIVE.equals(kpiGroup.getStatus())) {
              kpiPoolService.update(Wrappers.<KpiPool>lambdaUpdate()
                      .set(KpiPool::getYn, Boolean.FALSE)
                      .set(KpiPool::getUpdateTime, new Date())
a92022b7   姜超   feature(*): 绩效不再使...
1099
                      .eq(KpiPool::getKpiGroupId, kpiGroup.getId())
077e6941   姜超   feature(*): 草稿修改
1100
1101
1102
1103
1104
1105
                      .eq(KpiPool::getYn, Boolean.TRUE)
                      .eq(KpiPool::getMonthly, YearMonth.now())
              );
          }
      }
  
bab09971   xianpengcheng   绩效组配置入参修改
1106
      public List<KpiGroupVO> reportGroupConfig(KpiGroupRankConfigQueryDTO dto) {
7a060493   xianpengcheng   绩效报表-配置详情
1107
          List<KpiGroupVO> res = new ArrayList<>();
bab09971   xianpengcheng   绩效组配置入参修改
1108
          for (Long kpiGroupId : dto.getKpiGroupIds()) {
7a060493   xianpengcheng   绩效报表-配置详情
1109
1110
1111
1112
1113
              KpiGroupVO kpiGroupVO = kpiGroupDetail(kpiGroupId);
              res.add(kpiGroupVO);
          }
          return res;
      }
9e73b4bb   姜超   [jiangchao] 绩效指标相关接口
1114
  }