Blame view

fw-morax-server/src/main/java/cn/fw/morax/server/task/SalaryReportTask.java 40.8 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
                  }
                  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,
f32fbcdc   姜超   feature(*): 薪酬抽数据修改
222
                                                    LocalDate dataDate,
a38c5a05   姜超   feature(*): 薪酬报表
223
224
                                                    List<SalaryPool> pools,
                                                    Long reportSalaryId) {
f32fbcdc   姜超   feature(*): 薪酬抽数据修改
225
          MultiKeyMap<Long, BigDecimal> userSalaryMap = this.getUserIndicatorHitMap(salaryGroupProjects, dataDate, pools);
f99b77fe   姜超   feature(*): 薪酬报表
226
          List<ReportSalaryDimValue> reportSalaryValues = new ArrayList<>();
a38c5a05   姜超   feature(*): 薪酬报表
227
          //人的维度为基础,计算各个指标信息对应的数据
3d1718cf   姜超   feature(*): 薪酬报表
228
          for (SalaryPool pool : pools) {
b7c28a4a   姜超   feature(*): 注释校验,...
229
              //如果计算日期 与 报表数据抽取日期不一致,使用计算日期(计算日期每个人都可能不一致)
f32fbcdc   姜超   feature(*): 薪酬抽数据修改
230
              Boolean changeStaff = pool.getDataDate().compareTo(dataDate) != 0;
b7c28a4a   姜超   feature(*): 注释校验,...
231
232
  
              ReportSalaryDim reportSalaryDim = saveStaffDim(pool, dataDate, reportSalaryId);
f99b77fe   姜超   feature(*): 薪酬报表
233
              userDims.add(reportSalaryDim);
3d1718cf   姜超   feature(*): 薪酬报表
234
              final Long userId = pool.getUserId();
f99b77fe   姜超   feature(*): 薪酬报表
235
236
              final Long reportSalaryDimId = reportSalaryDim.getId();
              //薪酬排名组下的所有指标集合
a38c5a05   姜超   feature(*): 薪酬报表
237
              for (SalaryGroupProjectBO salaryGroupProject : salaryGroupProjects) {
f99b77fe   姜超   feature(*): 薪酬报表
238
                  if (! pool.getSalaryGroupId().equals(salaryGroupProject.getSalaryGroupId())) {
ab0e54c3   姜超   feature(mq): 门店名称...
239
                      continue;
584c7bfd   姜超   feature(*): 保存薪酬、...
240
                  }
f99b77fe   姜超   feature(*): 薪酬报表
241
                  final Long salaryGroupProjectId = salaryGroupProject.getId();
f32fbcdc   姜超   feature(*): 薪酬抽数据修改
242
243
244
245
246
                  BigDecimal salaryValue = userSalaryMap.get(userId, salaryGroupProjectId);
                  if (changeStaff) {
                      salaryValue = this.getUserIndicatorHitValue(salaryGroupProject, pool.getDataDate(), pool);
                  }
                  reportSalaryValues.add(this.convertDB(salaryGroupProject, reportSalaryDimId, dataDate, salaryValue));
a38c5a05   姜超   feature(*): 薪酬报表
247
                  List<SalaryGroupProjectParamVO> salaryGroupProjectParamVos = salaryGroupProjectParamService.getSalaryGroupProjectParamVO(salaryGroupProject.getId());
9f47fb88   姜超   feature(*): 薪酬组人员日期
248
249
  
                  if (salaryGroupProject.getCalMethod().equals(SalaryCalMethodEnum.CAR_SERIES)) {
9f47fb88   姜超   feature(*): 薪酬组人员日期
250
251
252
                      continue;
                  }
  
a38c5a05   姜超   feature(*): 薪酬报表
253
254
255
256
257
258
                  Set<String> paramCodes = new HashSet<>();
                  for (SalaryGroupProjectParamVO salaryGroupProjectParam : salaryGroupProjectParamVos) {
                      //一个薪酬项目中,指标只能出现一次
                      if (! paramCodes.add(salaryGroupProjectParam.getIndicatorCode())) {
                          continue;
                      }
f32fbcdc   姜超   feature(*): 薪酬抽数据修改
259
                      LocalDate calcDate = (changeStaff) ? pool.getDataDate() : dataDate;
a38c5a05   姜超   feature(*): 薪酬报表
260
261
                      if (TargetTypeEnum.NO.equals(salaryGroupProjectParam.getTargetType())) {
                          //无目标
f32fbcdc   姜超   feature(*): 薪酬抽数据修改
262
                          Map<Long, BigDecimal> userValueMap = queryUserOriginValue(salaryGroupProjectParam.getIndicatorCode(), userId, calcDate);
a38c5a05   姜超   feature(*): 薪酬报表
263
                          BigDecimal value = userValueMap.getOrDefault(userId, BigDecimal.ZERO);
b7c28a4a   姜超   feature(*): 注释校验,...
264
                          reportSalaryValues.add(this.convertNoTargetDB(salaryGroupProject, salaryGroupProjectParam, dataDate, reportSalaryDimId, value));
a38c5a05   姜超   feature(*): 薪酬报表
265
266
                      } else {
                          //有目标
f32fbcdc   姜超   feature(*): 薪酬抽数据修改
267
                          Map<Long, SalaryGroupProjectTargetHitLog> targetHitLogMap = queryUserTargetValue(salaryGroupProjectParam.getId(), userId, calcDate);
a38c5a05   姜超   feature(*): 薪酬报表
268
269
                          SalaryGroupProjectTargetHitLog hitLog = targetHitLogMap.get(userId);
                          BigDecimal value = Optional.ofNullable(hitLog).map(SalaryGroupProjectTargetHitLog::getReachValue).orElse(BigDecimal.ZERO);
b7c28a4a   姜超   feature(*): 注释校验,...
270
                          reportSalaryValues.add(this.convertTargetDB(salaryGroupProject, salaryGroupProjectParam, dataDate, reportSalaryDimId, value));
f1e68b31   姜超   feature(*): 报表修改
271
                      }
3d1718cf   姜超   feature(*): 薪酬报表
272
273
274
                  }
              }
          }
a38c5a05   姜超   feature(*): 薪酬报表
275
          if (PublicUtil.isNotEmpty(reportSalaryValues)){
f99b77fe   姜超   feature(*): 薪酬报表
276
              reportSalaryDimValueService.saveBatch(reportSalaryValues);
3d1718cf   姜超   feature(*): 薪酬报表
277
278
279
          }
          return reportSalaryValues;
      }
f1e68b31   姜超   feature(*): 报表修改
280
  
a38c5a05   姜超   feature(*): 薪酬报表
281
      public void calcShop(List<SalaryGroupProjectBO> salaryGroupProjects,
3d1718cf   姜超   feature(*): 薪酬报表
282
                            List<SalaryPool> pools,
50e72955   姜超   feature(*): 薪酬报表
283
                            Long reportSalaryId,
f99b77fe   姜超   feature(*): 薪酬报表
284
                            List<ReportSalaryDimValue> userSalaryValues,
50e72955   姜超   feature(*): 薪酬报表
285
                            List<ReportSalaryDim> userDims,
3d1718cf   姜超   feature(*): 薪酬报表
286
287
                            LocalDate date) {
          Map<Long, String> shopMap = pools.stream().collect(Collectors.toMap(SalaryPool::getShopId, SalaryPool::getShopName, (v1, v2) -> v1));
a38c5a05   姜超   feature(*): 薪酬报表
288
          List<ReportSalaryDimValue> reportSalaryDimValues = new ArrayList<>();
3d1718cf   姜超   feature(*): 薪酬报表
289
          for (Long shopId : shopMap.keySet()) {
a38c5a05   姜超   feature(*): 薪酬报表
290
              List<ReportSalaryDimValue> childReportSalaryDimValues = new ArrayList<>();
3d1718cf   姜超   feature(*): 薪酬报表
291
              Set<Long> shopDimReportIds = userDims.stream()
751d3eef   姜超   feature(*): 薪酬报表
292
                      .filter(user -> shopId.equals(user.getShopId()))
50e72955   姜超   feature(*): 薪酬报表
293
                      .map(ReportSalaryDim::getId).collect(Collectors.toSet());
751d3eef   姜超   feature(*): 薪酬报表
294
295
296
              if (PublicUtil.isEmpty(shopDimReportIds)) {
                  continue;
              }
4a3bdac5   姜超   feature(*): 考评报表修改
297
298
299
              BigDecimal averageSalary = calcAverageTotalSalary(userDims, shopDimReportIds);
              BigDecimal kpiScoreRatio = calcAverageKpiScoreRatio(userDims, shopDimReportIds);
              final Long shopReportSalaryDimId = this.saveShopDimDB(shopId, shopMap, date, reportSalaryId, averageSalary, kpiScoreRatio);
3d1718cf   姜超   feature(*): 薪酬报表
300
  
a38c5a05   姜超   feature(*): 薪酬报表
301
              for (SalaryGroupProjectBO salaryGroupProject : salaryGroupProjects) {
751d3eef   姜超   feature(*): 薪酬报表
302
                  BigDecimal value = calcAverageValue(userSalaryValues, shopDimReportIds, salaryGroupProject.getId().toString());
a38c5a05   姜超   feature(*): 薪酬报表
303
304
305
306
307
308
                  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
309
                      }
a38c5a05   姜超   feature(*): 薪酬报表
310
311
                      BigDecimal paramValue = calcAverageValue(userSalaryValues, shopDimReportIds, salaryGroupProjectParam.getIndicatorCode());
                      childReportSalaryDimValues.add(this.convertShopValueDBPcode(salaryGroupProjectParam, paramValue, salaryGroupProject));
f1e68b31   姜超   feature(*): 报表修改
312
                  }
ab0e54c3   姜超   feature(mq): 门店名称...
313
              }
a38c5a05   姜超   feature(*): 薪酬报表
314
315
316
317
318
319
320
321
322
  
              childReportSalaryDimValues.forEach(reportSalaryDimValue -> {
                  reportSalaryDimValue.setDataDate(date);
                  reportSalaryDimValue.setReportSalaryDimId(shopReportSalaryDimId);
              });
              reportSalaryDimValues.addAll(childReportSalaryDimValues);
          }
          if (PublicUtil.isNotEmpty(reportSalaryDimValues)){
              reportSalaryDimValueService.saveBatch(reportSalaryDimValues);
3d1718cf   姜超   feature(*): 薪酬报表
323
324
          }
      }
f1e68b31   姜超   feature(*): 报表修改
325
  
a38c5a05   姜超   feature(*): 薪酬报表
326
      public void calcManager(List<SalaryGroupProjectBO> salaryGroupProjects,
19983bbb   姜超   feature(*): 薪酬报表
327
328
329
330
331
332
333
334
335
336
337
338
339
340
                            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(*): 薪酬报表
341
              List<ReportSalaryDimValue> childReportSalaryDimValues = new ArrayList<>();
7a1a8fd1   姜超   feature(*): 管理人员判断
342
343
344
              if (PublicUtil.isEmpty(manager.getManageStaffList())) {
                  continue;
              }
19983bbb   姜超   feature(*): 薪酬报表
345
346
              List<Long> manageStaffIds = manager.getManageStaffList().stream().map(StaffBaseInfoDTO::getId).distinct().collect(Collectors.toList());
              Set<Long> managerStaffDimReportIds = userDims.stream()
751d3eef   姜超   feature(*): 薪酬报表
347
                      .filter(user -> manageStaffIds.contains(user.getUserId()))
19983bbb   姜超   feature(*): 薪酬报表
348
349
350
351
                      .map(ReportSalaryDim::getId).collect(Collectors.toSet());
              if (PublicUtil.isEmpty(managerStaffDimReportIds)) {
                  continue;
              }
4a3bdac5   姜超   feature(*): 考评报表修改
352
353
354
              BigDecimal kpiScoreRatio = calcAverageKpiScoreRatio(userDims, managerStaffDimReportIds);
              BigDecimal averageSalary = calcAverageTotalSalary(userDims, managerStaffDimReportIds);
              final Long reportSalaryDimId = this.saveManagerDimDB(manager, date, reportSalaryId, managerMap, averageSalary, kpiScoreRatio, manageStaffIds);
a38c5a05   姜超   feature(*): 薪酬报表
355
              for (SalaryGroupProjectBO salaryGroupProject : salaryGroupProjects) {
751d3eef   姜超   feature(*): 薪酬报表
356
                  BigDecimal value = calcAverageValue(userSalaryValues, managerStaffDimReportIds, salaryGroupProject.getId().toString());
9897d479   姜超   feature(*): 绩效报表
357
                  childReportSalaryDimValues.add(this.convertProjectValueDB(salaryGroupProject, value));
a38c5a05   姜超   feature(*): 薪酬报表
358
359
360
                  List<SalaryGroupProjectParamVO> salaryGroupProjectParamVos = salaryGroupProjectParamService.getSalaryGroupProjectParamVO(salaryGroupProject.getId());
                  for (SalaryGroupProjectParamVO salaryGroupProjectParam : salaryGroupProjectParamVos) {
                      BigDecimal paramValue = calcAverageValue(userSalaryValues, managerStaffDimReportIds, salaryGroupProjectParam.getIndicatorCode());
9897d479   姜超   feature(*): 绩效报表
361
                      childReportSalaryDimValues.add(this.convertShopValueDBPcode(salaryGroupProjectParam, paramValue, salaryGroupProject));
19983bbb   姜超   feature(*): 薪酬报表
362
363
                  }
              }
a38c5a05   姜超   feature(*): 薪酬报表
364
365
366
367
368
369
  
              childReportSalaryDimValues.forEach(reportSalaryDimValue -> {
                  reportSalaryDimValue.setDataDate(date);
                  reportSalaryDimValue.setReportSalaryDimId(reportSalaryDimId);
              });
              reportSalaryDimValues.addAll(childReportSalaryDimValues);
19983bbb   姜超   feature(*): 薪酬报表
370
371
372
373
374
375
376
377
378
379
380
381
          }
          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(*): 薪酬报表
382
383
384
385
386
387
388
389
390
      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(*): 绩效报表新...
391
392
393
394
395
396
397
398
399
      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(*): 薪酬报表
400
      public BigDecimal calcAverageValue(List<ReportSalaryDimValue> userSalaryValues, Set<Long> ReportDimIds, String code) {
3d1718cf   姜超   feature(*): 薪酬报表
401
          Double averageRatioDouble = userSalaryValues.stream()
19983bbb   姜超   feature(*): 薪酬报表
402
                  .filter(user -> ReportDimIds.contains(user.getReportSalaryDimId()) && code.equals(user.getCode()))
3d1718cf   姜超   feature(*): 薪酬报表
403
404
405
406
407
                  .mapToDouble(userValue -> Optional.ofNullable(userValue.getValue()).orElse(BigDecimal.ZERO).doubleValue())
                  .average()
                  .orElse(0);
          return new BigDecimal(averageRatioDouble.toString());
      }
584c7bfd   姜超   feature(*): 保存薪酬、...
408
  
4a3bdac5   姜超   feature(*): 考评报表修改
409
410
      public Long saveShopDimDB(Long shopId, Map<Long, String> shopMap,
                                           LocalDate date, Long reportSalaryId, BigDecimal averageSalary, BigDecimal kpiScoreRatio) {
751d3eef   姜超   feature(*): 薪酬报表
411
412
413
414
415
416
417
          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(*): 考评报表修改
418
419
          reportSalaryDim.setTotalReward(averageSalary);
          reportSalaryDim.setKpiScoreRatio(kpiScoreRatio);
751d3eef   姜超   feature(*): 薪酬报表
420
421
          reportSalaryDimService.save(reportSalaryDim);
          return reportSalaryDim.getId();
19983bbb   姜超   feature(*): 薪酬报表
422
      }
751d3eef   姜超   feature(*): 薪酬报表
423
424
425
426
      public Long saveManagerDimDB(ManagerDTO manager,
                                   LocalDate date,
                                   Long reportSalaryId,
                                   Map<Long, StaffBaseInfoDTO> managerMap,
4a3bdac5   姜超   feature(*): 考评报表修改
427
428
429
                                   BigDecimal averageSalary,
                                   BigDecimal kpiScoreRatio,
                                   List<Long> manageStaffIds) {
19983bbb   姜超   feature(*): 薪酬报表
430
431
432
433
          ReportSalaryDim reportSalaryDim = new ReportSalaryDim();
          reportSalaryDim.setDimension(ReportDimensionEnum.MANAGER);
          reportSalaryDim.setUserId(manager.getStaffId());
          reportSalaryDim.setUserName(manager.getStaffName());
4a3bdac5   姜超   feature(*): 考评报表修改
434
435
          reportSalaryDim.setTotalReward(averageSalary);
          reportSalaryDim.setKpiScoreRatio(kpiScoreRatio);
19983bbb   姜超   feature(*): 薪酬报表
436
437
438
439
440
441
          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(*): 薪酬报表
442
443
              reportSalaryDim.setPostId(staffInfo.getPostId());
              reportSalaryDim.setPostName(staffInfo.getPostName());
19983bbb   姜超   feature(*): 薪酬报表
444
          }
751d3eef   姜超   feature(*): 薪酬报表
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
  
          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(*): 薪酬报表
473
          return reportSalaryDim.getId();
3d1718cf   姜超   feature(*): 薪酬报表
474
      }
584c7bfd   姜超   feature(*): 保存薪酬、...
475
  
a38c5a05   姜超   feature(*): 薪酬报表
476
      public ReportSalaryDimValue convertProjectValueDB(SalaryGroupProjectBO salaryGroupProject, BigDecimal value) {
f99b77fe   姜超   feature(*): 薪酬报表
477
          ReportSalaryDimValue reportSalaryValue = new ReportSalaryDimValue();
9897d479   姜超   feature(*): 绩效报表
478
          reportSalaryValue.setCode(salaryGroupProject.getId().toString());
f99b77fe   姜超   feature(*): 薪酬报表
479
          reportSalaryValue.setCodeType(salaryGroupProject.getCodeType());
3d1718cf   姜超   feature(*): 薪酬报表
480
          reportSalaryValue.setValue(value);
f99b77fe   姜超   feature(*): 薪酬报表
481
          reportSalaryValue.setSalaryGroupProjectId(salaryGroupProject.getId());
3d1718cf   姜超   feature(*): 薪酬报表
482
483
          return reportSalaryValue;
      }
1a596c74   姜超   feature(*): 绩效报表
484
  
a38c5a05   姜超   feature(*): 薪酬报表
485
      public ReportSalaryDimValue convertShopValueDBPcode(SalaryGroupProjectParamVO salaryGroupProjectParam, BigDecimal value,SalaryGroupProjectBO salaryGroupProject) {
f99b77fe   姜超   feature(*): 薪酬报表
486
487
          ReportSalaryDimValue reportSalaryValue = new ReportSalaryDimValue();
          reportSalaryValue.setCode(salaryGroupProjectParam.getIndicatorCode());
3d1718cf   姜超   feature(*): 薪酬报表
488
489
          reportSalaryValue.setCodeType(IndicatorCodeTypeEnum.INDICATOR);
          reportSalaryValue.setValue(value);
f99b77fe   姜超   feature(*): 薪酬报表
490
          reportSalaryValue.setSalaryGroupProjectId(salaryGroupProjectParam.getSalaryGroupProjectId());
9897d479   姜超   feature(*): 绩效报表
491
          reportSalaryValue.setParentCode(salaryGroupProject.getId().toString());
3d1718cf   姜超   feature(*): 薪酬报表
492
493
          return reportSalaryValue;
      }
1a596c74   姜超   feature(*): 绩效报表
494
  
584c7bfd   姜超   feature(*): 保存薪酬、...
495
  
a38c5a05   姜超   feature(*): 薪酬报表
496
      public ReportSalaryDimValue convertDB(SalaryGroupProjectBO salaryGroupProject, Long reportSalaryDimId, LocalDate date, BigDecimal salaryValue) {
f99b77fe   姜超   feature(*): 薪酬报表
497
          ReportSalaryDimValue reportSalaryValue = new ReportSalaryDimValue();
0db06804   姜超   feature(*): 薪酬报表数据抽取
498
          reportSalaryValue.setCode(salaryGroupProject.getId().toString());
f99b77fe   姜超   feature(*): 薪酬报表
499
          reportSalaryValue.setCodeType(salaryGroupProject.getCodeType());
a38c5a05   姜超   feature(*): 薪酬报表
500
501
502
503
504
          if (PublicUtil.isEmpty(salaryValue)) {
              reportSalaryValue.setValue(BigDecimal.ZERO);
          } else {
              reportSalaryValue.setValue(salaryValue);
          }
3d1718cf   姜超   feature(*): 薪酬报表
505
506
          reportSalaryValue.setDataDate(date);
          reportSalaryValue.setReportSalaryDimId(reportSalaryDimId);
f99b77fe   姜超   feature(*): 薪酬报表
507
          reportSalaryValue.setSalaryGroupProjectId(salaryGroupProject.getId());
3d1718cf   姜超   feature(*): 薪酬报表
508
509
          return reportSalaryValue;
      }
584c7bfd   姜超   feature(*): 保存薪酬、...
510
  
a38c5a05   姜超   feature(*): 薪酬报表
511
      public ReportSalaryDimValue convertNoTargetDB(SalaryGroupProjectBO salaryGroupProject,
f99b77fe   姜超   feature(*): 薪酬报表
512
                                              SalaryGroupProjectParamVO salaryGroupProjectParam,
3d1718cf   姜超   feature(*): 薪酬报表
513
514
515
                                              LocalDate date,
                                              Long reportSalaryDimId,
                                              BigDecimal value) {
f99b77fe   姜超   feature(*): 薪酬报表
516
517
          ReportSalaryDimValue reportSalaryValue = new ReportSalaryDimValue();
          reportSalaryValue.setCode(salaryGroupProjectParam.getIndicatorCode());
3d1718cf   姜超   feature(*): 薪酬报表
518
          reportSalaryValue.setCodeType(IndicatorCodeTypeEnum.INDICATOR);
0db06804   姜超   feature(*): 薪酬报表数据抽取
519
          reportSalaryValue.setParentCode(salaryGroupProject.getId().toString());
3d1718cf   姜超   feature(*): 薪酬报表
520
521
          reportSalaryValue.setValue(value);
          //百分数处理
f99b77fe   姜超   feature(*): 薪酬报表
522
          if (DataTypeEnum.RATIO.equals(salaryGroupProjectParam.getDataType())){
3d1718cf   姜超   feature(*): 薪酬报表
523
              reportSalaryValue.setValue(value.multiply(Constant.ONE_HUNDRED));
584c7bfd   姜超   feature(*): 保存薪酬、...
524
          }
3d1718cf   姜超   feature(*): 薪酬报表
525
526
          reportSalaryValue.setDataDate(date);
          reportSalaryValue.setReportSalaryDimId(reportSalaryDimId);
f99b77fe   姜超   feature(*): 薪酬报表
527
          reportSalaryValue.setSalaryGroupProjectId(salaryGroupProject.getId());
3d1718cf   姜超   feature(*): 薪酬报表
528
529
          return reportSalaryValue;
      }
a38c5a05   姜超   feature(*): 薪酬报表
530
      public ReportSalaryDimValue convertTargetDB(SalaryGroupProjectBO salaryGroupProject,
f99b77fe   姜超   feature(*): 薪酬报表
531
                                              SalaryGroupProjectParamVO salaryGroupProjectParam,
3d1718cf   姜超   feature(*): 薪酬报表
532
533
534
                                              LocalDate date,
                                              Long reportSalaryDimId,
                                              BigDecimal value) {
f99b77fe   姜超   feature(*): 薪酬报表
535
536
          ReportSalaryDimValue reportSalaryValue = new ReportSalaryDimValue();
          reportSalaryValue.setCode(salaryGroupProjectParam.getIndicatorCode());
3d1718cf   姜超   feature(*): 薪酬报表
537
          reportSalaryValue.setCodeType(IndicatorCodeTypeEnum.INDICATOR);
0db06804   姜超   feature(*): 薪酬报表数据抽取
538
          reportSalaryValue.setParentCode(salaryGroupProject.getId().toString());
3d1718cf   姜超   feature(*): 薪酬报表
539
540
541
542
          //有目标 乘以 100
          reportSalaryValue.setValue(value.multiply(Constant.ONE_HUNDRED));
          reportSalaryValue.setDataDate(date);
          reportSalaryValue.setReportSalaryDimId(reportSalaryDimId);
f99b77fe   姜超   feature(*): 薪酬报表
543
          reportSalaryValue.setSalaryGroupProjectId(salaryGroupProject.getId());
3d1718cf   姜超   feature(*): 薪酬报表
544
          return reportSalaryValue;
584c7bfd   姜超   feature(*): 保存薪酬、...
545
546
      }
  
a38c5a05   姜超   feature(*): 薪酬报表
547
      public MultiKeyMap<Long, BigDecimal> getUserIndicatorHitMap(List<SalaryGroupProjectBO> salaryGroupProjects, LocalDate date, List<SalaryPool> pools) {
f99b77fe   姜超   feature(*): 薪酬报表
548
          List<SalaryGroupProjectHitLog> indicatorHitLogs = salaryGroupProjectHitLogService.list(Wrappers.<SalaryGroupProjectHitLog>lambdaQuery()
a38c5a05   姜超   feature(*): 薪酬报表
549
                  .in(SalaryGroupProjectHitLog::getSalaryGroupProjectId, salaryGroupProjects.stream().map(SalaryGroupProjectBO::getId).collect(Collectors.toList()))
f99b77fe   姜超   feature(*): 薪酬报表
550
551
552
                  .in(SalaryGroupProjectHitLog::getUserId, pools.stream().map(SalaryPool::getUserId).collect(Collectors.toList()))
                  .eq(SalaryGroupProjectHitLog::getDataDate, date)
                  .eq(SalaryGroupProjectHitLog::getYn, Boolean.TRUE)
3d1718cf   姜超   feature(*): 薪酬报表
553
554
          );
          MultiKeyMap<Long, BigDecimal> userGroupIndicatorHitMap = new MultiKeyMap<>();
f99b77fe   姜超   feature(*): 薪酬报表
555
556
          for (SalaryGroupProjectHitLog hitLog : indicatorHitLogs) {
              userGroupIndicatorHitMap.put(hitLog.getUserId(), hitLog.getSalaryGroupProjectId(), hitLog.getSalaryValue());
f1e68b31   姜超   feature(*): 报表修改
557
          }
3d1718cf   姜超   feature(*): 薪酬报表
558
559
          return userGroupIndicatorHitMap;
      }
584c7bfd   姜超   feature(*): 保存薪酬、...
560
  
f32fbcdc   姜超   feature(*): 薪酬抽数据修改
561
562
563
564
565
566
567
568
569
570
      public BigDecimal getUserIndicatorHitValue(SalaryGroupProjectBO salaryGroupProject, LocalDate date, SalaryPool pool) {
          SalaryGroupProjectHitLog indicatorHitLog = salaryGroupProjectHitLogService.getOne(Wrappers.<SalaryGroupProjectHitLog>lambdaQuery()
                  .eq(SalaryGroupProjectHitLog::getSalaryGroupProjectId, salaryGroupProject.getId())
                  .eq(SalaryGroupProjectHitLog::getUserId, pool.getUserId())
                  .eq(SalaryGroupProjectHitLog::getDataDate, date)
                  .eq(SalaryGroupProjectHitLog::getYn, Boolean.TRUE)
                  , Boolean.FALSE
          );
          return Optional.ofNullable(indicatorHitLog).map(SalaryGroupProjectHitLog::getSalaryValue).orElse(BigDecimal.ZERO);
      }
4a3bdac5   姜超   feature(*): 考评报表修改
571
  
f1e68b31   姜超   feature(*): 报表修改
572
  
f99b77fe   姜超   feature(*): 薪酬报表
573
574
575
576
577
578
579
      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(*): 薪酬报表
580
581
          );
          return targetHitLogs.stream()
f99b77fe   姜超   feature(*): 薪酬报表
582
                  .collect(Collectors.toMap(SalaryGroupProjectTargetHitLog::getUserId, Function.identity(), (v1, v2) -> v1));
584c7bfd   姜超   feature(*): 保存薪酬、...
583
584
      }
  
91b69450   姜超   feature(mq): 门店名称...
585
  
3d1718cf   姜超   feature(*): 薪酬报表
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
  
      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): 门店名称...
605
          }
3d1718cf   姜超   feature(*): 薪酬报表
606
607
          return referValueMap;
      }
91b69450   姜超   feature(mq): 门店名称...
608
  
a38c5a05   姜超   feature(*): 薪酬报表
609
610
611
      public ReportSalaryCode createProjectCode(SalaryGroupProjectBO salaryGroupProject,AtomicInteger order) {
          ReportSalaryCode reportSalaryCode = new ReportSalaryCode();
          reportSalaryCode.setSalaryGroupProjectId(salaryGroupProject.getId());
0db06804   姜超   feature(*): 薪酬报表数据抽取
612
          reportSalaryCode.setCode(salaryGroupProject.getId().toString());
a38c5a05   姜超   feature(*): 薪酬报表
613
614
615
616
617
618
          reportSalaryCode.setCodeType(salaryGroupProject.getCodeType());
          reportSalaryCode.setIndicatorName(salaryGroupProject.getName());
          reportSalaryCode.setOrderNum(order.incrementAndGet());
          return reportSalaryCode;
      }
  
a38c5a05   姜超   feature(*): 薪酬报表
619
620
621
622
623
624
625
626
627
628
      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(*): 薪酬报表数据抽取
629
              reportSalaryCode.setParentCode(salaryGroupProject.getId().toString());
a38c5a05   姜超   feature(*): 薪酬报表
630
631
              reportSalaryCode.setOrderNum(order.incrementAndGet());
              saveReportSalaryCodes.add(reportSalaryCode);
3d1718cf   姜超   feature(*): 薪酬报表
632
          }
a38c5a05   姜超   feature(*): 薪酬报表
633
          return saveReportSalaryCodes;
3d1718cf   姜超   feature(*): 薪酬报表
634
      }
91b69450   姜超   feature(mq): 门店名称...
635
  
19983bbb   姜超   feature(*): 薪酬报表
636
      private Long saveReportSalary(SalaryGroup salaryGroup, Long groupId, LocalDate date) {
3d1718cf   姜超   feature(*): 薪酬报表
637
  
f99b77fe   姜超   feature(*): 薪酬报表
638
639
640
          ReportSalary reportSalary = new ReportSalary();
          reportSalary.setSalaryGroupId(salaryGroup.getId());
          reportSalary.setSalaryName(salaryGroup.getName());
3d1718cf   姜超   feature(*): 薪酬报表
641
          //门店id
f99b77fe   姜超   feature(*): 薪酬报表
642
643
644
645
646
          reportSalary.setShopIds(salaryGroup.getShopIds());
          reportSalary.setMonthly(YearMonth.from(date));
          reportSalary.setDataDate(date);
          reportSalary.setGroupId(groupId);
          reportSalaryService.save(reportSalary);
19983bbb   姜超   feature(*): 薪酬报表
647
          return reportSalary.getId();
3d1718cf   姜超   feature(*): 薪酬报表
648
      }
91b69450   姜超   feature(mq): 门店名称...
649
  
fae07964   姜超   feature(*): 报表清除数据修改
650
      private void cleanData(LocalDate endDate) {
50e72955   姜超   feature(*): 薪酬报表
651
          List<ReportSalary> reportSalaries = reportSalaryService.list(Wrappers.<ReportSalary>lambdaQuery()
fae07964   姜超   feature(*): 报表清除数据修改
652
  //                .eq(ReportSalary::getSalaryGroupId, salaryGroup.getId())
f99b77fe   姜超   feature(*): 薪酬报表
653
                  //.ge(ReportSalary::getDataDate, startDate.with(TemporalAdjusters.firstDayOfMonth()))
3d1718cf   姜超   feature(*): 薪酬报表
654
                  //取当前日期对应月的第一天
84d3fe49   姜超   feature(*): 薪酬报表
655
656
                  .ge(ReportSalary::getDataDate, endDate.with(TemporalAdjusters.firstDayOfMonth()))
                  .le(ReportSalary::getDataDate, endDate)
3d1718cf   姜超   feature(*): 薪酬报表
657
          );
50e72955   姜超   feature(*): 薪酬报表
658
          if (PublicUtil.isEmpty(reportSalaries)){
3d1718cf   姜超   feature(*): 薪酬报表
659
              return;
84f9d303   姜超   feature(*): 定时任务修改
660
          }
50e72955   姜超   feature(*): 薪酬报表
661
          this.cleanData(reportSalaries);
84d3fe49   姜超   feature(*): 薪酬报表
662
663
664
665
666
667
668
669
670
671
      }
  
      /**
       * 清理排名组下报表数据
       * @param reportSalaries
       */
      public void cleanData(List<ReportSalary> reportSalaries) {
          if (CollectionUtils.isEmpty(reportSalaries)){
              return;
          }
f99b77fe   姜超   feature(*): 薪酬报表
672
          //薪酬排名组ids
84d3fe49   姜超   feature(*): 薪酬报表
673
674
675
676
677
678
679
680
681
682
683
684
685
686
          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(*): 薪酬报表
687
688
689
          reportSalaryDimExtraService.remove(Wrappers.<ReportSalaryDimExtra>lambdaUpdate()
                  .in(ReportSalaryDimExtra::getReportSalaryDimId, reportSalaryDimIds)
          );
84d3fe49   姜超   feature(*): 薪酬报表
690
691
692
          reportSalaryDimValueService.remove(Wrappers.<ReportSalaryDimValue>lambdaUpdate()
                  .in(ReportSalaryDimValue::getReportSalaryDimId, reportSalaryDimIds)
          );
84f9d303   姜超   feature(*): 定时任务修改
693
      }
584c7bfd   姜超   feature(*): 保存薪酬、...
694
  
a38c5a05   姜超   feature(*): 薪酬报表
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
      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(*): 基本工资不能下钻
711
712
713
714
715
716
717
718
                      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(*): 薪酬报表
719
720
721
                      projectBO.setCodeType(codeType);
                      break;
                  }
4a3bdac5   姜超   feature(*): 考评报表修改
722
                  case FIXATION: CAR_SERIES: {
a38c5a05   姜超   feature(*): 薪酬报表
723
724
725
726
727
728
729
730
731
732
                      projectBO.setCode(project.getCommissionCode());
                      projectBO.setCodeType(IndicatorCodeTypeEnum.COMBINE_INDICATOR);
                      break;
                  }
                  case LADDER: {
                      projectBO.setCode(project.getLadderCode());
                      projectBO.setCodeType(IndicatorCodeTypeEnum.COMBINE_INDICATOR);
                      break;
                  }
              }
5d2a2a83   姜超   feature(*): 基本工资不能下钻
733
734
735
736
              //基本工资不能下钻
              if (getBaseSalaryCode().equals(projectBO.getCode())) {
                  projectBO.setCodeType(IndicatorCodeTypeEnum.INDICATOR);
              }
a38c5a05   姜超   feature(*): 薪酬报表
737
738
739
740
              projects.add(projectBO);
          }
          return projects;
      }
3d1718cf   姜超   feature(*): 薪酬报表
741
  
4a3bdac5   姜超   feature(*): 考评报表修改
742
      public ReportSalaryDim saveStaffDim(SalaryPool pool, LocalDate date, Long reportSalaryRankId){
f99b77fe   姜超   feature(*): 薪酬报表
743
744
745
746
747
748
749
750
751
752
753
754
          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(*): 薪酬报表
755
          reportSalaryDim.setStarLevel(pool.getStarLevel());
4a3bdac5   姜超   feature(*): 考评报表修改
756
          reportSalaryDim.setTotalReward(pool.getReward());
3a182cd0   姜超   feature(*): 绩效报表新...
757
758
759
760
761
  //        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(*): 薪酬报表
762
763
          reportSalaryDimService.save(reportSalaryDim);
          return reportSalaryDim;
584c7bfd   姜超   feature(*): 保存薪酬、...
764
765
      }
  
584c7bfd   姜超   feature(*): 保存薪酬、...
766
  }