Blame view

fw-morax-server/src/main/java/cn/fw/morax/server/task/SalaryReportTask.java 39.6 KB
584c7bfd   姜超   feature(*): 保存薪酬、...
1
2
3
  package cn.fw.morax.server.task;
  
  import cn.fw.common.cache.locker.DistributedLocker;
3d1718cf   姜超   feature(*): 薪酬报表
4
  import cn.fw.morax.common.constant.Constant;
584c7bfd   姜超   feature(*): 保存薪酬、...
5
  import cn.fw.morax.common.constant.TimeTaskConstant;
84d3fe49   姜超   feature(*): 薪酬报表
6
  import cn.fw.morax.common.utils.DateUtil;
584c7bfd   姜超   feature(*): 保存薪酬、...
7
  import cn.fw.morax.common.utils.PublicUtil;
a38c5a05   姜超   feature(*): 薪酬报表
8
  import cn.fw.morax.domain.bo.salary.SalaryGroupProjectBO;
4a3bdac5   姜超   feature(*): 考评报表修改
9
  import cn.fw.morax.domain.db.kpi.*;
3d1718cf   姜超   feature(*): 薪酬报表
10
11
  import cn.fw.morax.domain.db.salary.*;
  import cn.fw.morax.domain.enums.*;
f99b77fe   姜超   feature(*): 薪酬报表
12
  import cn.fw.morax.domain.vo.salary.SalaryGroupProjectParamVO;
19983bbb   姜超   feature(*): 薪酬报表
13
14
  import cn.fw.morax.rpc.ehr.EhrRpcService;
  import cn.fw.morax.rpc.ehr.dto.ManagerDTO;
751d3eef   姜超   feature(*): 薪酬报表
15
16
  import cn.fw.morax.rpc.ehr.dto.ManagerStaffRoleDTO;
  import cn.fw.morax.rpc.ehr.dto.ManagerStaffShopDTO;
19983bbb   姜超   feature(*): 薪酬报表
17
  import cn.fw.morax.rpc.ehr.dto.StaffBaseInfoDTO;
8f66b194   姜超   feature(*): 注释判断计...
18
  import cn.fw.morax.rpc.oop.OopRpcService;
3d1718cf   姜超   feature(*): 薪酬报表
19
  import cn.fw.morax.service.biz.CommonService;
3a182cd0   姜超   feature(*): 绩效报表新...
20
  import cn.fw.morax.service.biz.kpi.KpiPoolCommonService;
b365d22a   姜超   feature(*): 申述日期修...
21
  import cn.fw.morax.service.biz.salary.SalarySettingCommonService;
3d1718cf   姜超   feature(*): 薪酬报表
22
  import cn.fw.morax.service.data.kpi.IndicatorUserValueService;
3a182cd0   姜超   feature(*): 绩效报表新...
23
  import cn.fw.morax.service.data.kpi.KpiPoolService;
3d1718cf   姜超   feature(*): 薪酬报表
24
  import cn.fw.morax.service.data.salary.*;
19983bbb   姜超   feature(*): 薪酬报表
25
  import com.alibaba.fastjson.JSON;
3d1718cf   姜超   feature(*): 薪酬报表
26
  import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
584c7bfd   姜超   feature(*): 保存薪酬、...
27
  import com.baomidou.mybatisplus.core.toolkit.Wrappers;
3d1718cf   姜超   feature(*): 薪酬报表
28
  import com.google.common.collect.Maps;
7d59a85e   姜超   feature(*): redis...
29
  import lombok.Getter;
584c7bfd   姜超   feature(*): 保存薪酬、...
30
31
32
  import lombok.RequiredArgsConstructor;
  import lombok.extern.slf4j.Slf4j;
  import org.apache.commons.collections4.map.MultiKeyMap;
584c7bfd   姜超   feature(*): 保存薪酬、...
33
  import org.redisson.api.RLock;
7d59a85e   姜超   feature(*): redis...
34
  import org.springframework.beans.factory.annotation.Value;
584c7bfd   姜超   feature(*): 保存薪酬、...
35
36
37
  import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  import org.springframework.scheduling.annotation.Scheduled;
  import org.springframework.stereotype.Component;
3d1718cf   姜超   feature(*): 薪酬报表
38
39
40
  import org.springframework.transaction.PlatformTransactionManager;
  import org.springframework.transaction.TransactionDefinition;
  import org.springframework.transaction.TransactionStatus;
584c7bfd   姜超   feature(*): 保存薪酬、...
41
42
43
44
  import org.springframework.transaction.annotation.Transactional;
  import org.springframework.util.CollectionUtils;
  
  import java.math.BigDecimal;
584c7bfd   姜超   feature(*): 保存薪酬、...
45
46
  import java.time.LocalDate;
  import java.time.YearMonth;
3d1718cf   姜超   feature(*): 薪酬报表
47
  import java.time.temporal.TemporalAdjusters;
584c7bfd   姜超   feature(*): 保存薪酬、...
48
  import java.util.*;
3d1718cf   姜超   feature(*): 薪酬报表
49
  import java.util.concurrent.atomic.AtomicInteger;
584c7bfd   姜超   feature(*): 保存薪酬、...
50
  import java.util.concurrent.locks.Lock;
3d1718cf   姜超   feature(*): 薪酬报表
51
  import java.util.function.Function;
584c7bfd   姜超   feature(*): 保存薪酬、...
52
53
54
55
  import java.util.stream.Collectors;
  
  /**
   * @author : jiangchao
3d1718cf   姜超   feature(*): 薪酬报表
56
   * @className : SalaryReportRatioTask
f99b77fe   姜超   feature(*): 薪酬报表
57
   * @description : 薪酬报表定时器
584c7bfd   姜超   feature(*): 保存薪酬、...
58
59
60
61
62
63
64
65
   * @date : 2022-04-07 15:29
   */
  @Component
  @Slf4j
  @RequiredArgsConstructor
  @ConditionalOnProperty(prefix = "task", name = "switch", havingValue = "on")
  public class SalaryReportTask {
  
3d1718cf   姜超   feature(*): 薪酬报表
66
      private final DistributedLocker distributedLocker;
584c7bfd   姜超   feature(*): 保存薪酬、...
67
68
      private final SalaryGroupService salaryGroupService;
      private final SalaryPoolService salaryPoolService;
3a182cd0   姜超   feature(*): 绩效报表新...
69
70
      private final KpiPoolService kpiPoolService;
      private final KpiPoolCommonService kpiPoolCommonService;
84d3fe49   姜超   feature(*): 薪酬报表
71
      private final ReportSalaryService reportSalaryService;
9f47fb88   姜超   feature(*): 薪酬组人员日期
72
      private final TransactionDefinition transactionDefinition;
84d3fe49   姜超   feature(*): 薪酬报表
73
      private final ReportSalaryDimService reportSalaryDimService;
9f47fb88   姜超   feature(*): 薪酬组人员日期
74
75
      private final ReportSalaryCodeService reportSalaryCodeService;
      private final IndicatorUserValueService indicatorUserValueService;
84d3fe49   姜超   feature(*): 薪酬报表
76
      private final SalaryGroupProjectService salaryGroupProjectService;
9f47fb88   姜超   feature(*): 薪酬组人员日期
77
      private final PlatformTransactionManager platformTransactionManager;
751d3eef   姜超   feature(*): 薪酬报表
78
      private final ReportSalaryDimExtraService reportSalaryDimExtraService;
9f47fb88   姜超   feature(*): 薪酬组人员日期
79
      private final ReportSalaryDimValueService reportSalaryDimValueService;
84d3fe49   姜超   feature(*): 薪酬报表
80
      private final SalaryGroupProjectHitLogService salaryGroupProjectHitLogService;
8f66b194   姜超   feature(*): 注释判断计...
81
      private final SalaryGeneralSettinService salaryGeneralSettinService;
9f47fb88   姜超   feature(*): 薪酬组人员日期
82
      private final SalaryGroupProjectSettinService salaryGroupProjectSettinService;
b365d22a   姜超   feature(*): 申述日期修...
83
      private final SalarySettingCommonService salarySettingCommonService;
84d3fe49   姜超   feature(*): 薪酬报表
84
      private final SalaryGroupProjectParamService salaryGroupProjectParamService;
84d3fe49   姜超   feature(*): 薪酬报表
85
      private final SalaryGroupProjectTargetHitLogService salaryGroupProjectTargetHitLogService;
9f47fb88   姜超   feature(*): 薪酬组人员日期
86
      private final CommonService commonService;
19983bbb   姜超   feature(*): 薪酬报表
87
      private final EhrRpcService ehrRpcService;
8f66b194   姜超   feature(*): 注释判断计...
88
      private final OopRpcService oopRpcService;
3d1718cf   姜超   feature(*): 薪酬报表
89
90
  
  
a38c5a05   姜超   feature(*): 薪酬报表
91
92
93
      @Value("${special-indicator-code.car-series}")
      @Getter
      private String carSeries;
5d2a2a83   姜超   feature(*): 基本工资不能下钻
94
95
96
      @Value("${special-indicator-code.base-salary}")
      @Getter
      private String baseSalaryCode;
7d59a85e   姜超   feature(*): redis...
97
98
      @Value("${spring.cache.custom.global-prefix}:salary:group:report")
      @Getter
3d1718cf   姜超   feature(*): 薪酬报表
99
      private String salaryGroupReportDistKey;
584c7bfd   姜超   feature(*): 保存薪酬、...
100
  
584c7bfd   姜超   feature(*): 保存薪酬、...
101
      /**
f99b77fe   姜超   feature(*): 薪酬报表
102
       * 薪酬报表定时任务
3d1718cf   姜超   feature(*): 薪酬报表
103
       *
584c7bfd   姜超   feature(*): 保存薪酬、...
104
       */
50e72955   姜超   feature(*): 薪酬报表
105
      @Scheduled(cron = TimeTaskConstant.SALARY_REPORT)
584c7bfd   姜超   feature(*): 保存薪酬、...
106
107
108
109
110
111
      @Transactional(rollbackFor = Exception.class)
      public void salaryReportTask() {
          this.salaryReport(LocalDate.now().minusDays(1));
      }
  
      /**
8f66b194   姜超   feature(*): 注释判断计...
112
       * 薪酬报表最终定时任务(
f99b77fe   姜超   feature(*): 薪酬报表
113
       * 人员质量评测每月2号计算上月、计算完成后会操作上月薪酬分,所以再次抽取上月报表)
3d1718cf   姜超   feature(*): 薪酬报表
114
       */
50e72955   姜超   feature(*): 薪酬报表
115
      @Scheduled(cron = TimeTaskConstant.SALARY_MONTH_FINAL_REPORT)
3d1718cf   姜超   feature(*): 薪酬报表
116
117
      @Transactional(rollbackFor = Exception.class)
      public void salaryLastMonthReportTask() {
8f66b194   姜超   feature(*): 注释判断计...
118
          LocalDate lastMonthEndDay = LocalDate.now().minusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
b365d22a   姜超   feature(*): 申述日期修...
119
          YearMonth monthly = YearMonth.now().minusMonths(1);
8f66b194   姜超   feature(*): 注释判断计...
120
121
          oopRpcService.allGroups().stream().forEach(group -> {
              final Long groupId = group.getId();
8920efe7   姜超   feature(*): 申述日期修...
122
              Boolean hasEndAppeal = salarySettingCommonService.lastDayHasClosureForReport(groupId, monthly);
b365d22a   姜超   feature(*): 申述日期修...
123
              if (hasEndAppeal) {
8f66b194   姜超   feature(*): 注释判断计...
124
125
126
                  this.salaryReport(lastMonthEndDay);
              }
          });
3d1718cf   姜超   feature(*): 薪酬报表
127
128
129
      }
  
      /**
f99b77fe   姜超   feature(*): 薪酬报表
130
       * 薪酬报表定时任务
584c7bfd   姜超   feature(*): 保存薪酬、...
131
132
133
       *
       * @param date
       */
584c7bfd   姜超   feature(*): 保存薪酬、...
134
      public void salaryReport(LocalDate date) {
3d1718cf   姜超   feature(*): 薪酬报表
135
136
          Lock lock = distributedLocker.lock(getSalaryGroupReportDistKey());
          if (! ((RLock) lock).isLocked()) {
584c7bfd   姜超   feature(*): 保存薪酬、...
137
138
              return;
          }
3d1718cf   姜超   feature(*): 薪酬报表
139
          TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition);
584c7bfd   姜超   feature(*): 保存薪酬、...
140
          try {
f99b77fe   姜超   feature(*): 薪酬报表
141
              log.info("定时任务【薪酬报表数据抽取-新】开始执行");
fae07964   姜超   feature(*): 报表清除数据修改
142
143
              //清理数据,每天留一条当月最新数据,每个月留一条月最后一天的数据
              cleanData(date);
50e72955   姜超   feature(*): 薪酬报表
144
              //查询所有需要处理的薪酬组
84d3fe49   姜超   feature(*): 薪酬报表
145
              List<SalaryGroup> salaryGroups = salaryGroupService.getAllEffectGroups(DateUtil.localDate2Date(date));
84d3fe49   姜超   feature(*): 薪酬报表
146
              for (SalaryGroup salaryGroup : salaryGroups) {
3d1718cf   姜超   feature(*): 薪酬报表
147
                  //抽取排名组数据
84d3fe49   姜超   feature(*): 薪酬报表
148
                  createReport(salaryGroup, salaryGroup.getGroupId(), date);
3d1718cf   姜超   feature(*): 薪酬报表
149
150
151
152
              }
              platformTransactionManager.commit(transactionStatus);
          } catch (Exception e){
              platformTransactionManager.rollback(transactionStatus);
584c7bfd   姜超   feature(*): 保存薪酬、...
153
154
155
156
157
158
              log.error(e.getMessage(), e);
          } finally {
              lock.unlock();
          }
      }
  
3d1718cf   姜超   feature(*): 薪酬报表
159
  
584c7bfd   姜超   feature(*): 保存薪酬、...
160
      /**
f99b77fe   姜超   feature(*): 薪酬报表
161
       * 薪酬排名组报表数据抽取
84d3fe49   姜超   feature(*): 薪酬报表
162
       * @param salaryGroup
3d1718cf   姜超   feature(*): 薪酬报表
163
164
       * @param groupId
       * @param date
584c7bfd   姜超   feature(*): 保存薪酬、...
165
       */
84d3fe49   姜超   feature(*): 薪酬报表
166
167
      private void createReport(SalaryGroup salaryGroup, Long groupId, LocalDate date) {
          final Long salaryGroupId = salaryGroup.getId();
3d1718cf   姜超   feature(*): 薪酬报表
168
          List<SalaryPool> pools = salaryPoolService.list(Wrappers.<SalaryPool>lambdaQuery()
84d3fe49   姜超   feature(*): 薪酬报表
169
                  .eq(SalaryPool::getSalaryGroupId, salaryGroupId)
3d1718cf   姜超   feature(*): 薪酬报表
170
171
172
173
174
175
                  .eq(SalaryPool::getMonthly, YearMonth.from(date))
                  .eq(SalaryPool::getYn, Boolean.TRUE)
          );
          if (PublicUtil.isEmpty(pools)) {
              return;
          }
f99b77fe   姜超   feature(*): 薪酬报表
176
          //保存 报表薪酬排名组 信息
19983bbb   姜超   feature(*): 薪酬报表
177
          final Long reportSalaryId = saveReportSalary(salaryGroup, groupId, date);
f99b77fe   姜超   feature(*): 薪酬报表
178
179
  
          //薪酬排名组下归属的所有薪酬组的对应指标集合
a38c5a05   姜超   feature(*): 薪酬报表
180
          List<SalaryGroupProjectBO> salaryGroupProjects = getProjectBO(salaryGroupId);
3d1718cf   姜超   feature(*): 薪酬报表
181
  
f99b77fe   姜超   feature(*): 薪酬报表
182
          //一个薪酬排名组对应多个薪酬组,也对应薪酬组下的所有指标集合
50e72955   姜超   feature(*): 薪酬报表
183
184
          saveReportSalaryCodes(date, reportSalaryId, salaryGroupProjects);
          List<ReportSalaryDim> userDims = new ArrayList();
3d1718cf   姜超   feature(*): 薪酬报表
185
          //人员维度
50e72955   姜超   feature(*): 薪酬报表
186
          List<ReportSalaryDimValue> userSalaryValues = calcUser(salaryGroupProjects, userDims, date, pools, reportSalaryId);
3d1718cf   姜超   feature(*): 薪酬报表
187
          //门店维度
50e72955   姜超   feature(*): 薪酬报表
188
          calcShop(salaryGroupProjects, pools, reportSalaryId, userSalaryValues, userDims, date);
19983bbb   姜超   feature(*): 薪酬报表
189
190
          //管理层维度
          calcManager(salaryGroupProjects, pools, reportSalaryId, userSalaryValues, userDims, date);
3d1718cf   姜超   feature(*): 薪酬报表
191
192
      }
  
a38c5a05   姜超   feature(*): 薪酬报表
193
194
195
196
      private List<ReportSalaryCode> saveReportSalaryCodes(LocalDate date, Long reportSalaryId, List<SalaryGroupProjectBO> salaryGroupProjects) {
          LinkedList<ReportSalaryCode> reportSalaryCodes = new LinkedList<>();
          AtomicInteger order = new AtomicInteger();
          for (SalaryGroupProjectBO salaryGroupProject : salaryGroupProjects) {
a38c5a05   姜超   feature(*): 薪酬报表
197
198
199
200
201
              reportSalaryCodes.add(createProjectCode(salaryGroupProject, order));
              if (IndicatorCodeTypeEnum.COMBINE_INDICATOR.equals(salaryGroupProject.getCodeType())) {
                  List<SalaryGroupProjectParamVO> salaryGroupProjectParamVos = salaryGroupProjectParamService.
                          getSalaryGroupProjectParamVO(salaryGroupProject.getId());
                  if (salaryGroupProject.getCalMethod().equals(SalaryCalMethodEnum.CAR_SERIES)) {
9f47fb88   姜超   feature(*): 薪酬组人员日期
202
                      continue;
a38c5a05   姜超   feature(*): 薪酬报表
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
                  }
                  reportSalaryCodes.addAll(createParamCodes(salaryGroupProject, salaryGroupProjectParamVos, order));
              }
          }
  
          if (PublicUtil.isNotEmpty(reportSalaryCodes)) {
              reportSalaryCodes.forEach(reportSalaryCode -> {
                  reportSalaryCode.setReportSalaryId(reportSalaryId);
                  reportSalaryCode.setDataDate(date);
              });
              reportSalaryCodeService.saveBatch(reportSalaryCodes);
          }
          return reportSalaryCodes;
      }
  
  
  
      private List<ReportSalaryDimValue> calcUser(List<SalaryGroupProjectBO> salaryGroupProjects,
                                                    List<ReportSalaryDim> userDims,
                                                    LocalDate date,
                                                    List<SalaryPool> pools,
                                                    Long reportSalaryId) {
          MultiKeyMap<Long, BigDecimal> userSalaryMap = this.getUserIndicatorHitMap(salaryGroupProjects, date, pools);
f99b77fe   姜超   feature(*): 薪酬报表
226
          List<ReportSalaryDimValue> reportSalaryValues = new ArrayList<>();
a38c5a05   姜超   feature(*): 薪酬报表
227
          //人的维度为基础,计算各个指标信息对应的数据
3d1718cf   姜超   feature(*): 薪酬报表
228
          for (SalaryPool pool : pools) {
4a3bdac5   姜超   feature(*): 考评报表修改
229
              ReportSalaryDim reportSalaryDim = saveStaffDim(pool, date, reportSalaryId);
f99b77fe   姜超   feature(*): 薪酬报表
230
              userDims.add(reportSalaryDim);
3d1718cf   姜超   feature(*): 薪酬报表
231
              final Long userId = pool.getUserId();
f99b77fe   姜超   feature(*): 薪酬报表
232
233
              final Long reportSalaryDimId = reportSalaryDim.getId();
              //薪酬排名组下的所有指标集合
a38c5a05   姜超   feature(*): 薪酬报表
234
              for (SalaryGroupProjectBO salaryGroupProject : salaryGroupProjects) {
f99b77fe   姜超   feature(*): 薪酬报表
235
                  if (! pool.getSalaryGroupId().equals(salaryGroupProject.getSalaryGroupId())) {
ab0e54c3   姜超   feature(mq): 门店名称...
236
                      continue;
584c7bfd   姜超   feature(*): 保存薪酬、...
237
                  }
f99b77fe   姜超   feature(*): 薪酬报表
238
                  final Long salaryGroupProjectId = salaryGroupProject.getId();
a38c5a05   姜超   feature(*): 薪酬报表
239
240
                  reportSalaryValues.add(this.convertDB(salaryGroupProject, reportSalaryDimId, date, userSalaryMap.get(userId, salaryGroupProjectId)));
                  List<SalaryGroupProjectParamVO> salaryGroupProjectParamVos = salaryGroupProjectParamService.getSalaryGroupProjectParamVO(salaryGroupProject.getId());
9f47fb88   姜超   feature(*): 薪酬组人员日期
241
242
  
                  if (salaryGroupProject.getCalMethod().equals(SalaryCalMethodEnum.CAR_SERIES)) {
9f47fb88   姜超   feature(*): 薪酬组人员日期
243
244
245
                      continue;
                  }
  
a38c5a05   姜超   feature(*): 薪酬报表
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
                  Set<String> paramCodes = new HashSet<>();
                  for (SalaryGroupProjectParamVO salaryGroupProjectParam : salaryGroupProjectParamVos) {
                      //一个薪酬项目中,指标只能出现一次
                      if (! paramCodes.add(salaryGroupProjectParam.getIndicatorCode())) {
                          continue;
                      }
                      if (TargetTypeEnum.NO.equals(salaryGroupProjectParam.getTargetType())) {
                          //无目标
                          Map<Long, BigDecimal> userValueMap = queryUserOriginValue(salaryGroupProjectParam.getIndicatorCode(), userId, date);
                          BigDecimal value = userValueMap.getOrDefault(userId, BigDecimal.ZERO);
                          reportSalaryValues.add(this.convertNoTargetDB(salaryGroupProject, salaryGroupProjectParam, date, reportSalaryDimId, value));
                      } else {
                          //有目标
                          Map<Long, SalaryGroupProjectTargetHitLog> targetHitLogMap = queryUserTargetValue(salaryGroupProjectParam.getId(), userId, date);
                          SalaryGroupProjectTargetHitLog hitLog = targetHitLogMap.get(userId);
                          BigDecimal value = Optional.ofNullable(hitLog).map(SalaryGroupProjectTargetHitLog::getReachValue).orElse(BigDecimal.ZERO);
                          reportSalaryValues.add(this.convertTargetDB(salaryGroupProject, salaryGroupProjectParam, date, reportSalaryDimId, value));
f1e68b31   姜超   feature(*): 报表修改
263
                      }
3d1718cf   姜超   feature(*): 薪酬报表
264
265
266
                  }
              }
          }
a38c5a05   姜超   feature(*): 薪酬报表
267
          if (PublicUtil.isNotEmpty(reportSalaryValues)){
f99b77fe   姜超   feature(*): 薪酬报表
268
              reportSalaryDimValueService.saveBatch(reportSalaryValues);
3d1718cf   姜超   feature(*): 薪酬报表
269
270
271
          }
          return reportSalaryValues;
      }
f1e68b31   姜超   feature(*): 报表修改
272
  
a38c5a05   姜超   feature(*): 薪酬报表
273
      public void calcShop(List<SalaryGroupProjectBO> salaryGroupProjects,
3d1718cf   姜超   feature(*): 薪酬报表
274
                            List<SalaryPool> pools,
50e72955   姜超   feature(*): 薪酬报表
275
                            Long reportSalaryId,
f99b77fe   姜超   feature(*): 薪酬报表
276
                            List<ReportSalaryDimValue> userSalaryValues,
50e72955   姜超   feature(*): 薪酬报表
277
                            List<ReportSalaryDim> userDims,
3d1718cf   姜超   feature(*): 薪酬报表
278
279
                            LocalDate date) {
          Map<Long, String> shopMap = pools.stream().collect(Collectors.toMap(SalaryPool::getShopId, SalaryPool::getShopName, (v1, v2) -> v1));
a38c5a05   姜超   feature(*): 薪酬报表
280
          List<ReportSalaryDimValue> reportSalaryDimValues = new ArrayList<>();
3d1718cf   姜超   feature(*): 薪酬报表
281
          for (Long shopId : shopMap.keySet()) {
a38c5a05   姜超   feature(*): 薪酬报表
282
              List<ReportSalaryDimValue> childReportSalaryDimValues = new ArrayList<>();
3d1718cf   姜超   feature(*): 薪酬报表
283
              Set<Long> shopDimReportIds = userDims.stream()
751d3eef   姜超   feature(*): 薪酬报表
284
                      .filter(user -> shopId.equals(user.getShopId()))
50e72955   姜超   feature(*): 薪酬报表
285
                      .map(ReportSalaryDim::getId).collect(Collectors.toSet());
751d3eef   姜超   feature(*): 薪酬报表
286
287
288
              if (PublicUtil.isEmpty(shopDimReportIds)) {
                  continue;
              }
4a3bdac5   姜超   feature(*): 考评报表修改
289
290
291
              BigDecimal averageSalary = calcAverageTotalSalary(userDims, shopDimReportIds);
              BigDecimal kpiScoreRatio = calcAverageKpiScoreRatio(userDims, shopDimReportIds);
              final Long shopReportSalaryDimId = this.saveShopDimDB(shopId, shopMap, date, reportSalaryId, averageSalary, kpiScoreRatio);
3d1718cf   姜超   feature(*): 薪酬报表
292
  
a38c5a05   姜超   feature(*): 薪酬报表
293
              for (SalaryGroupProjectBO salaryGroupProject : salaryGroupProjects) {
751d3eef   姜超   feature(*): 薪酬报表
294
                  BigDecimal value = calcAverageValue(userSalaryValues, shopDimReportIds, salaryGroupProject.getId().toString());
a38c5a05   姜超   feature(*): 薪酬报表
295
296
297
298
299
300
                  childReportSalaryDimValues.add(this.convertProjectValueDB(salaryGroupProject, value));
                  Set<String> paramCodes = new HashSet<>();
                  List<SalaryGroupProjectParamVO> salaryGroupProjectParamVos = salaryGroupProjectParamService.getSalaryGroupProjectParamVO(salaryGroupProject.getId());
                  for (SalaryGroupProjectParamVO salaryGroupProjectParam : salaryGroupProjectParamVos) {
                      if (! paramCodes.add(salaryGroupProjectParam.getIndicatorCode())) {
                          continue;
1efe930e   姜超   fix(*): 修改bug
301
                      }
a38c5a05   姜超   feature(*): 薪酬报表
302
303
                      BigDecimal paramValue = calcAverageValue(userSalaryValues, shopDimReportIds, salaryGroupProjectParam.getIndicatorCode());
                      childReportSalaryDimValues.add(this.convertShopValueDBPcode(salaryGroupProjectParam, paramValue, salaryGroupProject));
f1e68b31   姜超   feature(*): 报表修改
304
                  }
ab0e54c3   姜超   feature(mq): 门店名称...
305
              }
a38c5a05   姜超   feature(*): 薪酬报表
306
307
308
309
310
311
312
313
314
  
              childReportSalaryDimValues.forEach(reportSalaryDimValue -> {
                  reportSalaryDimValue.setDataDate(date);
                  reportSalaryDimValue.setReportSalaryDimId(shopReportSalaryDimId);
              });
              reportSalaryDimValues.addAll(childReportSalaryDimValues);
          }
          if (PublicUtil.isNotEmpty(reportSalaryDimValues)){
              reportSalaryDimValueService.saveBatch(reportSalaryDimValues);
3d1718cf   姜超   feature(*): 薪酬报表
315
316
          }
      }
f1e68b31   姜超   feature(*): 报表修改
317
  
a38c5a05   姜超   feature(*): 薪酬报表
318
      public void calcManager(List<SalaryGroupProjectBO> salaryGroupProjects,
19983bbb   姜超   feature(*): 薪酬报表
319
320
321
322
323
324
325
326
327
328
329
330
331
332
                            List<SalaryPool> pools,
                            Long reportSalaryId,
                            List<ReportSalaryDimValue> userSalaryValues,
                            List<ReportSalaryDim> userDims,
                            LocalDate date) {
          List<Long> shopIds = pools.stream().map(SalaryPool::getShopId).collect(Collectors.toList());
          List<ManagerDTO> managerDTOS = ehrRpcService.getRealTimeShopManager(new ArrayList<>(shopIds));
          log.info("查询门店实时管理者:{},{}", JSON.toJSONString(shopIds), JSON.toJSONString(managerDTOS));
          if (PublicUtil.isEmpty(managerDTOS)) {
              return;
          }
          Map<Long, StaffBaseInfoDTO> managerMap = staffInfoMap(managerDTOS);
          List<ReportSalaryDimValue> reportSalaryDimValues = new ArrayList<>();
          for (ManagerDTO manager : managerDTOS) {
a38c5a05   姜超   feature(*): 薪酬报表
333
              List<ReportSalaryDimValue> childReportSalaryDimValues = new ArrayList<>();
7a1a8fd1   姜超   feature(*): 管理人员判断
334
335
336
              if (PublicUtil.isEmpty(manager.getManageStaffList())) {
                  continue;
              }
19983bbb   姜超   feature(*): 薪酬报表
337
338
              List<Long> manageStaffIds = manager.getManageStaffList().stream().map(StaffBaseInfoDTO::getId).distinct().collect(Collectors.toList());
              Set<Long> managerStaffDimReportIds = userDims.stream()
751d3eef   姜超   feature(*): 薪酬报表
339
                      .filter(user -> manageStaffIds.contains(user.getUserId()))
19983bbb   姜超   feature(*): 薪酬报表
340
341
342
343
                      .map(ReportSalaryDim::getId).collect(Collectors.toSet());
              if (PublicUtil.isEmpty(managerStaffDimReportIds)) {
                  continue;
              }
4a3bdac5   姜超   feature(*): 考评报表修改
344
345
346
              BigDecimal kpiScoreRatio = calcAverageKpiScoreRatio(userDims, managerStaffDimReportIds);
              BigDecimal averageSalary = calcAverageTotalSalary(userDims, managerStaffDimReportIds);
              final Long reportSalaryDimId = this.saveManagerDimDB(manager, date, reportSalaryId, managerMap, averageSalary, kpiScoreRatio, manageStaffIds);
a38c5a05   姜超   feature(*): 薪酬报表
347
              for (SalaryGroupProjectBO salaryGroupProject : salaryGroupProjects) {
751d3eef   姜超   feature(*): 薪酬报表
348
                  BigDecimal value = calcAverageValue(userSalaryValues, managerStaffDimReportIds, salaryGroupProject.getId().toString());
9897d479   姜超   feature(*): 绩效报表
349
                  childReportSalaryDimValues.add(this.convertProjectValueDB(salaryGroupProject, value));
a38c5a05   姜超   feature(*): 薪酬报表
350
351
352
                  List<SalaryGroupProjectParamVO> salaryGroupProjectParamVos = salaryGroupProjectParamService.getSalaryGroupProjectParamVO(salaryGroupProject.getId());
                  for (SalaryGroupProjectParamVO salaryGroupProjectParam : salaryGroupProjectParamVos) {
                      BigDecimal paramValue = calcAverageValue(userSalaryValues, managerStaffDimReportIds, salaryGroupProjectParam.getIndicatorCode());
9897d479   姜超   feature(*): 绩效报表
353
                      childReportSalaryDimValues.add(this.convertShopValueDBPcode(salaryGroupProjectParam, paramValue, salaryGroupProject));
19983bbb   姜超   feature(*): 薪酬报表
354
355
                  }
              }
a38c5a05   姜超   feature(*): 薪酬报表
356
357
358
359
360
361
  
              childReportSalaryDimValues.forEach(reportSalaryDimValue -> {
                  reportSalaryDimValue.setDataDate(date);
                  reportSalaryDimValue.setReportSalaryDimId(reportSalaryDimId);
              });
              reportSalaryDimValues.addAll(childReportSalaryDimValues);
19983bbb   姜超   feature(*): 薪酬报表
362
363
364
365
366
367
368
369
370
371
372
373
          }
          if (PublicUtil.isNotEmpty(reportSalaryDimValues)) {
              reportSalaryDimValueService.saveBatch(reportSalaryDimValues);
          }
      }
  
      public Map<Long, StaffBaseInfoDTO> staffInfoMap(List<ManagerDTO> managerDTOS) {
          List<Long> staffIds = managerDTOS.stream().map(ManagerDTO::getStaffId).collect(Collectors.toList());
          List<StaffBaseInfoDTO> staffInfos = ehrRpcService.queryStaffBaseInfo(staffIds);
          return staffInfos.stream().collect(Collectors.toMap(StaffBaseInfoDTO::getId, Function.identity(), (v1, v2) -> v1));
      }
  
751d3eef   姜超   feature(*): 薪酬报表
374
375
376
377
378
379
380
381
382
      public BigDecimal calcAverageTotalSalary(List<ReportSalaryDim> dims, Set<Long> ReportDimIds) {
          Double averageRatioDouble = dims.stream()
                  .filter(user -> ReportDimIds.contains(user.getId()))
                  .mapToDouble(userValue -> Optional.ofNullable(userValue.getTotalReward()).orElse(BigDecimal.ZERO).doubleValue())
                  .average()
                  .orElse(0);
          return new BigDecimal(averageRatioDouble.toString());
      }
  
3a182cd0   姜超   feature(*): 绩效报表新...
383
384
385
386
387
388
389
390
391
      public BigDecimal calcAverageKpiScoreRatio(List<ReportSalaryDim> dims, Set<Long> ReportDimIds) {
          Double averageRatioDouble = dims.stream()
                  .filter(user -> ReportDimIds.contains(user.getId()))
                  .mapToDouble(userValue -> Optional.ofNullable(userValue.getKpiScoreRatio()).orElse(BigDecimal.ZERO).doubleValue())
                  .average()
                  .orElse(0);
          return new BigDecimal(averageRatioDouble.toString());
      }
  
19983bbb   姜超   feature(*): 薪酬报表
392
      public BigDecimal calcAverageValue(List<ReportSalaryDimValue> userSalaryValues, Set<Long> ReportDimIds, String code) {
3d1718cf   姜超   feature(*): 薪酬报表
393
          Double averageRatioDouble = userSalaryValues.stream()
19983bbb   姜超   feature(*): 薪酬报表
394
                  .filter(user -> ReportDimIds.contains(user.getReportSalaryDimId()) && code.equals(user.getCode()))
3d1718cf   姜超   feature(*): 薪酬报表
395
396
397
398
399
                  .mapToDouble(userValue -> Optional.ofNullable(userValue.getValue()).orElse(BigDecimal.ZERO).doubleValue())
                  .average()
                  .orElse(0);
          return new BigDecimal(averageRatioDouble.toString());
      }
584c7bfd   姜超   feature(*): 保存薪酬、...
400
  
4a3bdac5   姜超   feature(*): 考评报表修改
401
402
      public Long saveShopDimDB(Long shopId, Map<Long, String> shopMap,
                                           LocalDate date, Long reportSalaryId, BigDecimal averageSalary, BigDecimal kpiScoreRatio) {
751d3eef   姜超   feature(*): 薪酬报表
403
404
405
406
407
408
409
          ReportSalaryDim reportSalaryDim = new ReportSalaryDim();
          reportSalaryDim.setDimension(ReportDimensionEnum.SHOP);
          reportSalaryDim.setReferId(shopId);
          reportSalaryDim.setShopId(shopId);
          reportSalaryDim.setShopName(shopMap.get(shopId));
          reportSalaryDim.setDataDate(date);
          reportSalaryDim.setReportSalaryId(reportSalaryId);
4a3bdac5   姜超   feature(*): 考评报表修改
410
411
          reportSalaryDim.setTotalReward(averageSalary);
          reportSalaryDim.setKpiScoreRatio(kpiScoreRatio);
751d3eef   姜超   feature(*): 薪酬报表
412
413
          reportSalaryDimService.save(reportSalaryDim);
          return reportSalaryDim.getId();
19983bbb   姜超   feature(*): 薪酬报表
414
      }
751d3eef   姜超   feature(*): 薪酬报表
415
416
417
418
      public Long saveManagerDimDB(ManagerDTO manager,
                                   LocalDate date,
                                   Long reportSalaryId,
                                   Map<Long, StaffBaseInfoDTO> managerMap,
4a3bdac5   姜超   feature(*): 考评报表修改
419
420
421
                                   BigDecimal averageSalary,
                                   BigDecimal kpiScoreRatio,
                                   List<Long> manageStaffIds) {
19983bbb   姜超   feature(*): 薪酬报表
422
423
424
425
          ReportSalaryDim reportSalaryDim = new ReportSalaryDim();
          reportSalaryDim.setDimension(ReportDimensionEnum.MANAGER);
          reportSalaryDim.setUserId(manager.getStaffId());
          reportSalaryDim.setUserName(manager.getStaffName());
4a3bdac5   姜超   feature(*): 考评报表修改
426
427
          reportSalaryDim.setTotalReward(averageSalary);
          reportSalaryDim.setKpiScoreRatio(kpiScoreRatio);
19983bbb   姜超   feature(*): 薪酬报表
428
429
430
431
432
433
          reportSalaryDim.setDataDate(date);
          reportSalaryDim.setReportSalaryId(reportSalaryId);
          if (managerMap.containsKey(manager.getStaffId())) {
              StaffBaseInfoDTO staffInfo = managerMap.get(manager.getStaffId());
              reportSalaryDim.setShopId(staffInfo.getShopId());
              reportSalaryDim.setShopName(staffInfo.getShopName());
751d3eef   姜超   feature(*): 薪酬报表
434
435
              reportSalaryDim.setPostId(staffInfo.getPostId());
              reportSalaryDim.setPostName(staffInfo.getPostName());
19983bbb   姜超   feature(*): 薪酬报表
436
          }
751d3eef   姜超   feature(*): 薪酬报表
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
  
          List<String> roleCodes = manager.getScopeList().stream()
                  .flatMap(managerStaffVo -> managerStaffVo.getRoleList().stream())
                  .map(ManagerStaffRoleDTO::getRoleCode)
                  .distinct()
                  .collect(Collectors.toList());
          List<String> roleNames = manager.getScopeList().stream()
                  .flatMap(managerStaffVo -> managerStaffVo.getRoleList().stream())
                  .map(ManagerStaffRoleDTO::getRoleName)
                  .distinct()
                  .collect(Collectors.toList());
          List<Long> shopIds = manager.getScopeList().stream()
                  .flatMap(managerStaffVo -> managerStaffVo.getShopList().stream())
                  .map(ManagerStaffShopDTO::getShopId)
                  .distinct()
                  .collect(Collectors.toList());
  
          reportSalaryDimService.save(reportSalaryDim);
          ReportSalaryDimExtra reportSalaryDimExtra = new ReportSalaryDimExtra();
          reportSalaryDimExtra.setReportSalaryDimId(reportSalaryDim.getId());
          ReportSalaryDimExtra dimExtra = ReportSalaryDimExtra.builder()
                  .reportSalaryDimId(reportSalaryDim.getId())
                  .roleCodes(roleCodes)
                  .roleNames(roleNames)
                  .shopIds(shopIds)
                  .staffIds(manageStaffIds)
                  .build();
          reportSalaryDimExtraService.save(dimExtra);
19983bbb   姜超   feature(*): 薪酬报表
465
          return reportSalaryDim.getId();
3d1718cf   姜超   feature(*): 薪酬报表
466
      }
584c7bfd   姜超   feature(*): 保存薪酬、...
467
  
a38c5a05   姜超   feature(*): 薪酬报表
468
      public ReportSalaryDimValue convertProjectValueDB(SalaryGroupProjectBO salaryGroupProject, BigDecimal value) {
f99b77fe   姜超   feature(*): 薪酬报表
469
          ReportSalaryDimValue reportSalaryValue = new ReportSalaryDimValue();
9897d479   姜超   feature(*): 绩效报表
470
          reportSalaryValue.setCode(salaryGroupProject.getId().toString());
f99b77fe   姜超   feature(*): 薪酬报表
471
          reportSalaryValue.setCodeType(salaryGroupProject.getCodeType());
3d1718cf   姜超   feature(*): 薪酬报表
472
          reportSalaryValue.setValue(value);
f99b77fe   姜超   feature(*): 薪酬报表
473
          reportSalaryValue.setSalaryGroupProjectId(salaryGroupProject.getId());
3d1718cf   姜超   feature(*): 薪酬报表
474
475
          return reportSalaryValue;
      }
1a596c74   姜超   feature(*): 绩效报表
476
  
a38c5a05   姜超   feature(*): 薪酬报表
477
      public ReportSalaryDimValue convertShopValueDBPcode(SalaryGroupProjectParamVO salaryGroupProjectParam, BigDecimal value,SalaryGroupProjectBO salaryGroupProject) {
f99b77fe   姜超   feature(*): 薪酬报表
478
479
          ReportSalaryDimValue reportSalaryValue = new ReportSalaryDimValue();
          reportSalaryValue.setCode(salaryGroupProjectParam.getIndicatorCode());
3d1718cf   姜超   feature(*): 薪酬报表
480
481
          reportSalaryValue.setCodeType(IndicatorCodeTypeEnum.INDICATOR);
          reportSalaryValue.setValue(value);
f99b77fe   姜超   feature(*): 薪酬报表
482
          reportSalaryValue.setSalaryGroupProjectId(salaryGroupProjectParam.getSalaryGroupProjectId());
9897d479   姜超   feature(*): 绩效报表
483
          reportSalaryValue.setParentCode(salaryGroupProject.getId().toString());
3d1718cf   姜超   feature(*): 薪酬报表
484
485
          return reportSalaryValue;
      }
1a596c74   姜超   feature(*): 绩效报表
486
  
584c7bfd   姜超   feature(*): 保存薪酬、...
487
  
a38c5a05   姜超   feature(*): 薪酬报表
488
      public ReportSalaryDimValue convertDB(SalaryGroupProjectBO salaryGroupProject, Long reportSalaryDimId, LocalDate date, BigDecimal salaryValue) {
f99b77fe   姜超   feature(*): 薪酬报表
489
          ReportSalaryDimValue reportSalaryValue = new ReportSalaryDimValue();
0db06804   姜超   feature(*): 薪酬报表数据抽取
490
          reportSalaryValue.setCode(salaryGroupProject.getId().toString());
f99b77fe   姜超   feature(*): 薪酬报表
491
          reportSalaryValue.setCodeType(salaryGroupProject.getCodeType());
a38c5a05   姜超   feature(*): 薪酬报表
492
493
494
495
496
          if (PublicUtil.isEmpty(salaryValue)) {
              reportSalaryValue.setValue(BigDecimal.ZERO);
          } else {
              reportSalaryValue.setValue(salaryValue);
          }
3d1718cf   姜超   feature(*): 薪酬报表
497
498
          reportSalaryValue.setDataDate(date);
          reportSalaryValue.setReportSalaryDimId(reportSalaryDimId);
f99b77fe   姜超   feature(*): 薪酬报表
499
          reportSalaryValue.setSalaryGroupProjectId(salaryGroupProject.getId());
3d1718cf   姜超   feature(*): 薪酬报表
500
501
          return reportSalaryValue;
      }
584c7bfd   姜超   feature(*): 保存薪酬、...
502
  
a38c5a05   姜超   feature(*): 薪酬报表
503
      public ReportSalaryDimValue convertNoTargetDB(SalaryGroupProjectBO salaryGroupProject,
f99b77fe   姜超   feature(*): 薪酬报表
504
                                              SalaryGroupProjectParamVO salaryGroupProjectParam,
3d1718cf   姜超   feature(*): 薪酬报表
505
506
507
                                              LocalDate date,
                                              Long reportSalaryDimId,
                                              BigDecimal value) {
f99b77fe   姜超   feature(*): 薪酬报表
508
509
          ReportSalaryDimValue reportSalaryValue = new ReportSalaryDimValue();
          reportSalaryValue.setCode(salaryGroupProjectParam.getIndicatorCode());
3d1718cf   姜超   feature(*): 薪酬报表
510
          reportSalaryValue.setCodeType(IndicatorCodeTypeEnum.INDICATOR);
0db06804   姜超   feature(*): 薪酬报表数据抽取
511
          reportSalaryValue.setParentCode(salaryGroupProject.getId().toString());
3d1718cf   姜超   feature(*): 薪酬报表
512
513
          reportSalaryValue.setValue(value);
          //百分数处理
f99b77fe   姜超   feature(*): 薪酬报表
514
          if (DataTypeEnum.RATIO.equals(salaryGroupProjectParam.getDataType())){
3d1718cf   姜超   feature(*): 薪酬报表
515
              reportSalaryValue.setValue(value.multiply(Constant.ONE_HUNDRED));
584c7bfd   姜超   feature(*): 保存薪酬、...
516
          }
3d1718cf   姜超   feature(*): 薪酬报表
517
518
          reportSalaryValue.setDataDate(date);
          reportSalaryValue.setReportSalaryDimId(reportSalaryDimId);
f99b77fe   姜超   feature(*): 薪酬报表
519
          reportSalaryValue.setSalaryGroupProjectId(salaryGroupProject.getId());
3d1718cf   姜超   feature(*): 薪酬报表
520
521
          return reportSalaryValue;
      }
a38c5a05   姜超   feature(*): 薪酬报表
522
      public ReportSalaryDimValue convertTargetDB(SalaryGroupProjectBO salaryGroupProject,
f99b77fe   姜超   feature(*): 薪酬报表
523
                                              SalaryGroupProjectParamVO salaryGroupProjectParam,
3d1718cf   姜超   feature(*): 薪酬报表
524
525
526
                                              LocalDate date,
                                              Long reportSalaryDimId,
                                              BigDecimal value) {
f99b77fe   姜超   feature(*): 薪酬报表
527
528
          ReportSalaryDimValue reportSalaryValue = new ReportSalaryDimValue();
          reportSalaryValue.setCode(salaryGroupProjectParam.getIndicatorCode());
3d1718cf   姜超   feature(*): 薪酬报表
529
          reportSalaryValue.setCodeType(IndicatorCodeTypeEnum.INDICATOR);
0db06804   姜超   feature(*): 薪酬报表数据抽取
530
          reportSalaryValue.setParentCode(salaryGroupProject.getId().toString());
3d1718cf   姜超   feature(*): 薪酬报表
531
532
533
534
          //有目标 乘以 100
          reportSalaryValue.setValue(value.multiply(Constant.ONE_HUNDRED));
          reportSalaryValue.setDataDate(date);
          reportSalaryValue.setReportSalaryDimId(reportSalaryDimId);
f99b77fe   姜超   feature(*): 薪酬报表
535
          reportSalaryValue.setSalaryGroupProjectId(salaryGroupProject.getId());
3d1718cf   姜超   feature(*): 薪酬报表
536
          return reportSalaryValue;
584c7bfd   姜超   feature(*): 保存薪酬、...
537
538
      }
  
a38c5a05   姜超   feature(*): 薪酬报表
539
      public MultiKeyMap<Long, BigDecimal> getUserIndicatorHitMap(List<SalaryGroupProjectBO> salaryGroupProjects, LocalDate date, List<SalaryPool> pools) {
f99b77fe   姜超   feature(*): 薪酬报表
540
          List<SalaryGroupProjectHitLog> indicatorHitLogs = salaryGroupProjectHitLogService.list(Wrappers.<SalaryGroupProjectHitLog>lambdaQuery()
a38c5a05   姜超   feature(*): 薪酬报表
541
                  .in(SalaryGroupProjectHitLog::getSalaryGroupProjectId, salaryGroupProjects.stream().map(SalaryGroupProjectBO::getId).collect(Collectors.toList()))
f99b77fe   姜超   feature(*): 薪酬报表
542
543
544
                  .in(SalaryGroupProjectHitLog::getUserId, pools.stream().map(SalaryPool::getUserId).collect(Collectors.toList()))
                  .eq(SalaryGroupProjectHitLog::getDataDate, date)
                  .eq(SalaryGroupProjectHitLog::getYn, Boolean.TRUE)
3d1718cf   姜超   feature(*): 薪酬报表
545
546
          );
          MultiKeyMap<Long, BigDecimal> userGroupIndicatorHitMap = new MultiKeyMap<>();
f99b77fe   姜超   feature(*): 薪酬报表
547
548
          for (SalaryGroupProjectHitLog hitLog : indicatorHitLogs) {
              userGroupIndicatorHitMap.put(hitLog.getUserId(), hitLog.getSalaryGroupProjectId(), hitLog.getSalaryValue());
f1e68b31   姜超   feature(*): 报表修改
549
          }
3d1718cf   姜超   feature(*): 薪酬报表
550
551
          return userGroupIndicatorHitMap;
      }
584c7bfd   姜超   feature(*): 保存薪酬、...
552
  
4a3bdac5   姜超   feature(*): 考评报表修改
553
  
f1e68b31   姜超   feature(*): 报表修改
554
  
f99b77fe   姜超   feature(*): 薪酬报表
555
556
557
558
559
560
561
      public Map<Long, SalaryGroupProjectTargetHitLog> queryUserTargetValue(Long referId, Long userId, LocalDate dataDate) {
          List<SalaryGroupProjectTargetHitLog> targetHitLogs = salaryGroupProjectTargetHitLogService.list(Wrappers.<SalaryGroupProjectTargetHitLog>lambdaQuery()
                  .eq(SalaryGroupProjectTargetHitLog::getReferId, referId)
                  .eq(SalaryGroupProjectTargetHitLog::getTargetType, IndicatorTypeEnum.EXAMINE)
                  .eq(SalaryGroupProjectTargetHitLog::getDataDate, dataDate)
                  .eq(SalaryGroupProjectTargetHitLog::getUserId, userId)
                  .eq(SalaryGroupProjectTargetHitLog::getYn, Boolean.TRUE)
3d1718cf   姜超   feature(*): 薪酬报表
562
563
          );
          return targetHitLogs.stream()
f99b77fe   姜超   feature(*): 薪酬报表
564
                  .collect(Collectors.toMap(SalaryGroupProjectTargetHitLog::getUserId, Function.identity(), (v1, v2) -> v1));
584c7bfd   姜超   feature(*): 保存薪酬、...
565
566
      }
  
91b69450   姜超   feature(mq): 门店名称...
567
  
3d1718cf   姜超   feature(*): 薪酬报表
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
  
      public Map<Long, BigDecimal> queryUserOriginValue(String code, Long userId, LocalDate dataDate) {
          Map<Long, BigDecimal> referValueMap = Maps.newHashMapWithExpectedSize(1);
          //无目标
          LambdaQueryWrapper<IndicatorUserValue> queryWrapper = Wrappers.<IndicatorUserValue>lambdaQuery();
          queryWrapper.eq(IndicatorUserValue::getUserId, userId);
          List<IndicatorUserValue> indicatorUserValues = indicatorUserValueService.list(queryWrapper
                  .eq(IndicatorUserValue::getIndicatorCode, code)
                  .eq(IndicatorUserValue::getDataDate, dataDate)
                  .eq(IndicatorUserValue::getDimensionType, DimensionTypeEnum.STAFF)
                  .eq(IndicatorUserValue::getYn, Boolean.TRUE)
          );
          for (IndicatorUserValue userValue : indicatorUserValues) {
              BigDecimal indicatorValue = commonService.queryIndicatorValue(code, userValue);
              referValueMap.put(userValue.getUserId(), indicatorValue);
              //如果原始值是百分比,乘以100,由于业务系统这个可能不准还是配置指标里面的data_type
              //if (IndicatorValueTypeEnum.RATIO.equals(userValue.getValueType())){
              //    referValueMap.put(userValue.getUserId(), indicatorValue.multiply(Constant.ONE_HUNDRED));
              //}
91b69450   姜超   feature(mq): 门店名称...
587
          }
3d1718cf   姜超   feature(*): 薪酬报表
588
589
          return referValueMap;
      }
91b69450   姜超   feature(mq): 门店名称...
590
  
a38c5a05   姜超   feature(*): 薪酬报表
591
592
593
      public ReportSalaryCode createProjectCode(SalaryGroupProjectBO salaryGroupProject,AtomicInteger order) {
          ReportSalaryCode reportSalaryCode = new ReportSalaryCode();
          reportSalaryCode.setSalaryGroupProjectId(salaryGroupProject.getId());
0db06804   姜超   feature(*): 薪酬报表数据抽取
594
          reportSalaryCode.setCode(salaryGroupProject.getId().toString());
a38c5a05   姜超   feature(*): 薪酬报表
595
596
597
598
599
600
          reportSalaryCode.setCodeType(salaryGroupProject.getCodeType());
          reportSalaryCode.setIndicatorName(salaryGroupProject.getName());
          reportSalaryCode.setOrderNum(order.incrementAndGet());
          return reportSalaryCode;
      }
  
a38c5a05   姜超   feature(*): 薪酬报表
601
602
603
604
605
606
607
608
609
610
      public List<ReportSalaryCode> createParamCodes(SalaryGroupProjectBO salaryGroupProject,
                                                     List<SalaryGroupProjectParamVO> salaryGroupProjectParamVos,
                                                     AtomicInteger order) {
          List<ReportSalaryCode> saveReportSalaryCodes = new ArrayList<>(salaryGroupProjectParamVos.size());
          for (SalaryGroupProjectParamVO salaryGroupProjectParam : salaryGroupProjectParamVos) {
              ReportSalaryCode reportSalaryCode = new ReportSalaryCode();
              reportSalaryCode.setSalaryGroupProjectId(salaryGroupProjectParam.getSalaryGroupProjectId());
              reportSalaryCode.setCode(salaryGroupProjectParam.getIndicatorCode());
              reportSalaryCode.setCodeType(IndicatorCodeTypeEnum.INDICATOR);
              reportSalaryCode.setIndicatorName(salaryGroupProjectParam.getIndicatorName());
0db06804   姜超   feature(*): 薪酬报表数据抽取
611
              reportSalaryCode.setParentCode(salaryGroupProject.getId().toString());
a38c5a05   姜超   feature(*): 薪酬报表
612
613
              reportSalaryCode.setOrderNum(order.incrementAndGet());
              saveReportSalaryCodes.add(reportSalaryCode);
3d1718cf   姜超   feature(*): 薪酬报表
614
          }
a38c5a05   姜超   feature(*): 薪酬报表
615
          return saveReportSalaryCodes;
3d1718cf   姜超   feature(*): 薪酬报表
616
      }
91b69450   姜超   feature(mq): 门店名称...
617
  
19983bbb   姜超   feature(*): 薪酬报表
618
      private Long saveReportSalary(SalaryGroup salaryGroup, Long groupId, LocalDate date) {
3d1718cf   姜超   feature(*): 薪酬报表
619
  
f99b77fe   姜超   feature(*): 薪酬报表
620
621
622
          ReportSalary reportSalary = new ReportSalary();
          reportSalary.setSalaryGroupId(salaryGroup.getId());
          reportSalary.setSalaryName(salaryGroup.getName());
3d1718cf   姜超   feature(*): 薪酬报表
623
          //门店id
f99b77fe   姜超   feature(*): 薪酬报表
624
625
626
627
628
          reportSalary.setShopIds(salaryGroup.getShopIds());
          reportSalary.setMonthly(YearMonth.from(date));
          reportSalary.setDataDate(date);
          reportSalary.setGroupId(groupId);
          reportSalaryService.save(reportSalary);
19983bbb   姜超   feature(*): 薪酬报表
629
          return reportSalary.getId();
3d1718cf   姜超   feature(*): 薪酬报表
630
      }
91b69450   姜超   feature(mq): 门店名称...
631
  
fae07964   姜超   feature(*): 报表清除数据修改
632
      private void cleanData(LocalDate endDate) {
50e72955   姜超   feature(*): 薪酬报表
633
          List<ReportSalary> reportSalaries = reportSalaryService.list(Wrappers.<ReportSalary>lambdaQuery()
fae07964   姜超   feature(*): 报表清除数据修改
634
  //                .eq(ReportSalary::getSalaryGroupId, salaryGroup.getId())
f99b77fe   姜超   feature(*): 薪酬报表
635
                  //.ge(ReportSalary::getDataDate, startDate.with(TemporalAdjusters.firstDayOfMonth()))
3d1718cf   姜超   feature(*): 薪酬报表
636
                  //取当前日期对应月的第一天
84d3fe49   姜超   feature(*): 薪酬报表
637
638
                  .ge(ReportSalary::getDataDate, endDate.with(TemporalAdjusters.firstDayOfMonth()))
                  .le(ReportSalary::getDataDate, endDate)
3d1718cf   姜超   feature(*): 薪酬报表
639
          );
50e72955   姜超   feature(*): 薪酬报表
640
          if (PublicUtil.isEmpty(reportSalaries)){
3d1718cf   姜超   feature(*): 薪酬报表
641
              return;
84f9d303   姜超   feature(*): 定时任务修改
642
          }
50e72955   姜超   feature(*): 薪酬报表
643
          this.cleanData(reportSalaries);
84d3fe49   姜超   feature(*): 薪酬报表
644
645
646
647
648
649
650
651
652
653
      }
  
      /**
       * 清理排名组下报表数据
       * @param reportSalaries
       */
      public void cleanData(List<ReportSalary> reportSalaries) {
          if (CollectionUtils.isEmpty(reportSalaries)){
              return;
          }
f99b77fe   姜超   feature(*): 薪酬报表
654
          //薪酬排名组ids
84d3fe49   姜超   feature(*): 薪酬报表
655
656
657
658
659
660
661
662
663
664
665
666
667
668
          List<Long> reportSalaryIds = reportSalaries.stream().map(ReportSalary::getId).collect(Collectors.toList());
          reportSalaryService.removeByIds(reportSalaryIds);
          reportSalaryCodeService.remove(Wrappers.<ReportSalaryCode>lambdaUpdate()
                  .in(ReportSalaryCode::getReportSalaryId, reportSalaryIds)
          );
          //维度的删除要先查询
          List<ReportSalaryDim> reportSalaryDims = reportSalaryDimService.list(Wrappers.<ReportSalaryDim>lambdaQuery()
                  .in(ReportSalaryDim::getReportSalaryId, reportSalaryIds)
          );
          if (CollectionUtils.isEmpty(reportSalaryDims)){
              return;
          }
          List<Long> reportSalaryDimIds = reportSalaryDims.stream().map(ReportSalaryDim::getId).collect(Collectors.toList());
          reportSalaryDimService.removeByIds(reportSalaryDimIds);
751d3eef   姜超   feature(*): 薪酬报表
669
670
671
          reportSalaryDimExtraService.remove(Wrappers.<ReportSalaryDimExtra>lambdaUpdate()
                  .in(ReportSalaryDimExtra::getReportSalaryDimId, reportSalaryDimIds)
          );
84d3fe49   姜超   feature(*): 薪酬报表
672
673
674
          reportSalaryDimValueService.remove(Wrappers.<ReportSalaryDimValue>lambdaUpdate()
                  .in(ReportSalaryDimValue::getReportSalaryDimId, reportSalaryDimIds)
          );
84f9d303   姜超   feature(*): 定时任务修改
675
      }
584c7bfd   姜超   feature(*): 保存薪酬、...
676
  
a38c5a05   姜超   feature(*): 薪酬报表
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
      public LinkedList<SalaryGroupProjectBO> getProjectBO(Long salaryGroupId) {
          List<SalaryGroupProject> salaryGroupProjects = salaryGroupProjectService.list(Wrappers.<SalaryGroupProject>lambdaQuery()
                  .eq(SalaryGroupProject::getSalaryGroupId, salaryGroupId)
                  .eq(SalaryGroupProject::getYn, Boolean.TRUE)
                  .orderByAsc(SalaryGroupProject::getId)
          );
          if (PublicUtil.isEmpty(salaryGroupProjects)) {
              return new LinkedList<>();
          }
          LinkedList<SalaryGroupProjectBO> projects = new LinkedList();
          for (SalaryGroupProject project : salaryGroupProjects) {
              SalaryGroupProjectBO projectBO = PublicUtil.copy(project, SalaryGroupProjectBO.class);
              switch (projectBO.getCalMethod()) {
                  case STAR: {
                      projectBO.setCode(project.getId().toString());
                      List<SalaryGroupProjectParamVO> params = salaryGroupProjectParamService.getSalaryGroupProjectParamVO(projectBO.getId());
03419ea5   姜超   feature(*): 基本工资不能下钻
693
694
695
696
697
698
699
700
                      IndicatorCodeTypeEnum codeType = IndicatorCodeTypeEnum.INDICATOR;
                      //有基本工资指标就不下钻
                      if (PublicUtil.isNotEmpty(params)) {
                          Boolean hasBaseSalary = params.stream().filter(param -> getBaseSalaryCode().equals(param.getIndicatorCode())).findAny().isPresent();
                          if (! hasBaseSalary) {
                              codeType = IndicatorCodeTypeEnum.COMBINE_INDICATOR;
                          }
                      }
a38c5a05   姜超   feature(*): 薪酬报表
701
702
703
                      projectBO.setCodeType(codeType);
                      break;
                  }
4a3bdac5   姜超   feature(*): 考评报表修改
704
                  case FIXATION: CAR_SERIES: {
a38c5a05   姜超   feature(*): 薪酬报表
705
706
707
708
709
710
711
712
713
714
                      projectBO.setCode(project.getCommissionCode());
                      projectBO.setCodeType(IndicatorCodeTypeEnum.COMBINE_INDICATOR);
                      break;
                  }
                  case LADDER: {
                      projectBO.setCode(project.getLadderCode());
                      projectBO.setCodeType(IndicatorCodeTypeEnum.COMBINE_INDICATOR);
                      break;
                  }
              }
5d2a2a83   姜超   feature(*): 基本工资不能下钻
715
716
717
718
              //基本工资不能下钻
              if (getBaseSalaryCode().equals(projectBO.getCode())) {
                  projectBO.setCodeType(IndicatorCodeTypeEnum.INDICATOR);
              }
a38c5a05   姜超   feature(*): 薪酬报表
719
720
721
722
              projects.add(projectBO);
          }
          return projects;
      }
3d1718cf   姜超   feature(*): 薪酬报表
723
  
4a3bdac5   姜超   feature(*): 考评报表修改
724
      public ReportSalaryDim saveStaffDim(SalaryPool pool, LocalDate date, Long reportSalaryRankId){
f99b77fe   姜超   feature(*): 薪酬报表
725
726
727
728
729
730
731
732
733
734
735
736
          ReportSalaryDim reportSalaryDim = new ReportSalaryDim();
          reportSalaryDim.setDimension(ReportDimensionEnum.STAFF);
          reportSalaryDim.setReferId(pool.getUserId());
          reportSalaryDim.setSalaryPoolId(pool.getId());
          reportSalaryDim.setUserId(pool.getUserId());
          reportSalaryDim.setUserName(pool.getUserName());
          reportSalaryDim.setPostId(pool.getPostId());
          reportSalaryDim.setPostName(pool.getPostName());
          reportSalaryDim.setShopId(pool.getShopId());
          reportSalaryDim.setShopName(pool.getShopName());
          reportSalaryDim.setDataDate(date);
          reportSalaryDim.setReportSalaryId(reportSalaryRankId);
a38c5a05   姜超   feature(*): 薪酬报表
737
          reportSalaryDim.setStarLevel(pool.getStarLevel());
4a3bdac5   姜超   feature(*): 考评报表修改
738
          reportSalaryDim.setTotalReward(pool.getReward());
3a182cd0   姜超   feature(*): 绩效报表新...
739
740
741
742
743
  //        KpiPool kpiPool = kpiPoolCommonService.queryPool(pool);
  //        if (PublicUtil.isNotEmpty(kpiPool)) {
  //            BigDecimal kpiScoreRatio = Optional.ofNullable(kpiPool.getKpiScoreRatio()).orElse(BigDecimal.ZERO);
  //            reportSalaryDim.setKpiScoreRatio(kpiScoreRatio.multiply(Constant.ONE_HUNDRED));
  //        }
f99b77fe   姜超   feature(*): 薪酬报表
744
745
          reportSalaryDimService.save(reportSalaryDim);
          return reportSalaryDim;
584c7bfd   姜超   feature(*): 保存薪酬、...
746
747
      }
  
584c7bfd   姜超   feature(*): 保存薪酬、...
748
  }