Blame view

fw-morax-server/src/main/java/cn/fw/morax/server/task/SalaryReportTask.java 49.2 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;
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
9
  import cn.fw.morax.domain.db.kpi.IndicatorUserValue;
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;
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
52
53
  import java.util.function.Predicate;
  import java.util.function.ToDoubleFunction;
584c7bfd   姜超   feature(*): 保存薪酬、...
54
55
56
57
  import java.util.stream.Collectors;
  
  /**
   * @author : jiangchao
3d1718cf   姜超   feature(*): 薪酬报表
58
   * @className : SalaryReportRatioTask
f99b77fe   姜超   feature(*): 薪酬报表
59
   * @description : 薪酬报表定时器
584c7bfd   姜超   feature(*): 保存薪酬、...
60
61
62
63
64
65
66
67
   * @date : 2022-04-07 15:29
   */
  @Component
  @Slf4j
  @RequiredArgsConstructor
  @ConditionalOnProperty(prefix = "task", name = "switch", havingValue = "on")
  public class SalaryReportTask {
  
3d1718cf   姜超   feature(*): 薪酬报表
68
      private final DistributedLocker distributedLocker;
584c7bfd   姜超   feature(*): 保存薪酬、...
69
70
      private final SalaryGroupService salaryGroupService;
      private final SalaryPoolService salaryPoolService;
3a182cd0   姜超   feature(*): 绩效报表新...
71
72
      private final KpiPoolService kpiPoolService;
      private final KpiPoolCommonService kpiPoolCommonService;
84d3fe49   姜超   feature(*): 薪酬报表
73
      private final ReportSalaryService reportSalaryService;
9f47fb88   姜超   feature(*): 薪酬组人员日期
74
      private final TransactionDefinition transactionDefinition;
84d3fe49   姜超   feature(*): 薪酬报表
75
      private final ReportSalaryDimService reportSalaryDimService;
9f47fb88   姜超   feature(*): 薪酬组人员日期
76
77
      private final ReportSalaryCodeService reportSalaryCodeService;
      private final IndicatorUserValueService indicatorUserValueService;
84d3fe49   姜超   feature(*): 薪酬报表
78
      private final SalaryGroupProjectService salaryGroupProjectService;
9f47fb88   姜超   feature(*): 薪酬组人员日期
79
      private final PlatformTransactionManager platformTransactionManager;
751d3eef   姜超   feature(*): 薪酬报表
80
      private final ReportSalaryDimExtraService reportSalaryDimExtraService;
9f47fb88   姜超   feature(*): 薪酬组人员日期
81
      private final ReportSalaryDimValueService reportSalaryDimValueService;
84d3fe49   姜超   feature(*): 薪酬报表
82
      private final SalaryGroupProjectHitLogService salaryGroupProjectHitLogService;
8f66b194   姜超   feature(*): 注释判断计...
83
      private final SalaryGeneralSettinService salaryGeneralSettinService;
9f47fb88   姜超   feature(*): 薪酬组人员日期
84
      private final SalaryGroupProjectSettinService salaryGroupProjectSettinService;
b365d22a   姜超   feature(*): 申述日期修...
85
      private final SalarySettingCommonService salarySettingCommonService;
84d3fe49   姜超   feature(*): 薪酬报表
86
      private final SalaryGroupProjectParamService salaryGroupProjectParamService;
84d3fe49   姜超   feature(*): 薪酬报表
87
      private final SalaryGroupProjectTargetHitLogService salaryGroupProjectTargetHitLogService;
9f47fb88   姜超   feature(*): 薪酬组人员日期
88
      private final CommonService commonService;
19983bbb   姜超   feature(*): 薪酬报表
89
      private final EhrRpcService ehrRpcService;
8f66b194   姜超   feature(*): 注释判断计...
90
      private final OopRpcService oopRpcService;
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
91
      private final SalaryPoolDetailService salaryPoolDetailService;
3d1718cf   姜超   feature(*): 薪酬报表
92
93
  
  
a38c5a05   姜超   feature(*): 薪酬报表
94
95
96
      @Value("${special-indicator-code.car-series}")
      @Getter
      private String carSeries;
5d2a2a83   姜超   feature(*): 基本工资不能下钻
97
98
99
      @Value("${special-indicator-code.base-salary}")
      @Getter
      private String baseSalaryCode;
7d59a85e   姜超   feature(*): redis...
100
101
      @Value("${spring.cache.custom.global-prefix}:salary:group:report")
      @Getter
3d1718cf   姜超   feature(*): 薪酬报表
102
      private String salaryGroupReportDistKey;
584c7bfd   姜超   feature(*): 保存薪酬、...
103
  
584c7bfd   姜超   feature(*): 保存薪酬、...
104
      /**
f99b77fe   姜超   feature(*): 薪酬报表
105
       * 薪酬报表定时任务
3d1718cf   姜超   feature(*): 薪酬报表
106
       *
584c7bfd   姜超   feature(*): 保存薪酬、...
107
       */
50e72955   姜超   feature(*): 薪酬报表
108
      @Scheduled(cron = TimeTaskConstant.SALARY_REPORT)
584c7bfd   姜超   feature(*): 保存薪酬、...
109
110
111
112
113
114
      @Transactional(rollbackFor = Exception.class)
      public void salaryReportTask() {
          this.salaryReport(LocalDate.now().minusDays(1));
      }
  
      /**
8f66b194   姜超   feature(*): 注释判断计...
115
       * 薪酬报表最终定时任务(
f99b77fe   姜超   feature(*): 薪酬报表
116
       * 人员质量评测每月2号计算上月、计算完成后会操作上月薪酬分,所以再次抽取上月报表)
3d1718cf   姜超   feature(*): 薪酬报表
117
       */
50e72955   姜超   feature(*): 薪酬报表
118
      @Scheduled(cron = TimeTaskConstant.SALARY_MONTH_FINAL_REPORT)
3d1718cf   姜超   feature(*): 薪酬报表
119
120
      @Transactional(rollbackFor = Exception.class)
      public void salaryLastMonthReportTask() {
8f66b194   姜超   feature(*): 注释判断计...
121
          LocalDate lastMonthEndDay = LocalDate.now().minusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
b365d22a   姜超   feature(*): 申述日期修...
122
          YearMonth monthly = YearMonth.now().minusMonths(1);
8f66b194   姜超   feature(*): 注释判断计...
123
124
          oopRpcService.allGroups().stream().forEach(group -> {
              final Long groupId = group.getId();
8920efe7   姜超   feature(*): 申述日期修...
125
              Boolean hasEndAppeal = salarySettingCommonService.lastDayHasClosureForReport(groupId, monthly);
b365d22a   姜超   feature(*): 申述日期修...
126
              if (hasEndAppeal) {
8f66b194   姜超   feature(*): 注释判断计...
127
128
129
                  this.salaryReport(lastMonthEndDay);
              }
          });
3d1718cf   姜超   feature(*): 薪酬报表
130
131
132
      }
  
      /**
f99b77fe   姜超   feature(*): 薪酬报表
133
       * 薪酬报表定时任务
584c7bfd   姜超   feature(*): 保存薪酬、...
134
135
136
       *
       * @param date
       */
584c7bfd   姜超   feature(*): 保存薪酬、...
137
      public void salaryReport(LocalDate date) {
3d1718cf   姜超   feature(*): 薪酬报表
138
139
          Lock lock = distributedLocker.lock(getSalaryGroupReportDistKey());
          if (! ((RLock) lock).isLocked()) {
584c7bfd   姜超   feature(*): 保存薪酬、...
140
141
              return;
          }
3d1718cf   姜超   feature(*): 薪酬报表
142
          TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition);
584c7bfd   姜超   feature(*): 保存薪酬、...
143
          try {
f99b77fe   姜超   feature(*): 薪酬报表
144
              log.info("定时任务【薪酬报表数据抽取-新】开始执行");
fae07964   姜超   feature(*): 报表清除数据修改
145
146
              //清理数据,每天留一条当月最新数据,每个月留一条月最后一天的数据
              cleanData(date);
50e72955   姜超   feature(*): 薪酬报表
147
              //查询所有需要处理的薪酬组
84d3fe49   姜超   feature(*): 薪酬报表
148
              List<SalaryGroup> salaryGroups = salaryGroupService.getAllEffectGroups(DateUtil.localDate2Date(date));
84d3fe49   姜超   feature(*): 薪酬报表
149
              for (SalaryGroup salaryGroup : salaryGroups) {
3d1718cf   姜超   feature(*): 薪酬报表
150
                  //抽取排名组数据
84d3fe49   姜超   feature(*): 薪酬报表
151
                  createReport(salaryGroup, salaryGroup.getGroupId(), date);
3d1718cf   姜超   feature(*): 薪酬报表
152
153
154
155
              }
              platformTransactionManager.commit(transactionStatus);
          } catch (Exception e){
              platformTransactionManager.rollback(transactionStatus);
584c7bfd   姜超   feature(*): 保存薪酬、...
156
157
158
159
160
161
              log.error(e.getMessage(), e);
          } finally {
              lock.unlock();
          }
      }
  
3d1718cf   姜超   feature(*): 薪酬报表
162
  
584c7bfd   姜超   feature(*): 保存薪酬、...
163
      /**
f99b77fe   姜超   feature(*): 薪酬报表
164
       * 薪酬排名组报表数据抽取
84d3fe49   姜超   feature(*): 薪酬报表
165
       * @param salaryGroup
3d1718cf   姜超   feature(*): 薪酬报表
166
167
       * @param groupId
       * @param date
584c7bfd   姜超   feature(*): 保存薪酬、...
168
       */
84d3fe49   姜超   feature(*): 薪酬报表
169
170
      private void createReport(SalaryGroup salaryGroup, Long groupId, LocalDate date) {
          final Long salaryGroupId = salaryGroup.getId();
3d1718cf   姜超   feature(*): 薪酬报表
171
          List<SalaryPool> pools = salaryPoolService.list(Wrappers.<SalaryPool>lambdaQuery()
84d3fe49   姜超   feature(*): 薪酬报表
172
                  .eq(SalaryPool::getSalaryGroupId, salaryGroupId)
3d1718cf   姜超   feature(*): 薪酬报表
173
174
175
176
177
178
                  .eq(SalaryPool::getMonthly, YearMonth.from(date))
                  .eq(SalaryPool::getYn, Boolean.TRUE)
          );
          if (PublicUtil.isEmpty(pools)) {
              return;
          }
f99b77fe   姜超   feature(*): 薪酬报表
179
          //保存 报表薪酬排名组 信息
19983bbb   姜超   feature(*): 薪酬报表
180
          final Long reportSalaryId = saveReportSalary(salaryGroup, groupId, date);
f99b77fe   姜超   feature(*): 薪酬报表
181
182
  
          //薪酬排名组下归属的所有薪酬组的对应指标集合
a38c5a05   姜超   feature(*): 薪酬报表
183
          List<SalaryGroupProjectBO> salaryGroupProjects = getProjectBO(salaryGroupId);
3d1718cf   姜超   feature(*): 薪酬报表
184
  
f99b77fe   姜超   feature(*): 薪酬报表
185
          //一个薪酬排名组对应多个薪酬组,也对应薪酬组下的所有指标集合
50e72955   姜超   feature(*): 薪酬报表
186
187
          saveReportSalaryCodes(date, reportSalaryId, salaryGroupProjects);
          List<ReportSalaryDim> userDims = new ArrayList();
3d1718cf   姜超   feature(*): 薪酬报表
188
          //人员维度
50e72955   姜超   feature(*): 薪酬报表
189
          List<ReportSalaryDimValue> userSalaryValues = calcUser(salaryGroupProjects, userDims, date, pools, reportSalaryId);
3d1718cf   姜超   feature(*): 薪酬报表
190
          //门店维度
50e72955   姜超   feature(*): 薪酬报表
191
          calcShop(salaryGroupProjects, pools, reportSalaryId, userSalaryValues, userDims, date);
19983bbb   姜超   feature(*): 薪酬报表
192
193
          //管理层维度
          calcManager(salaryGroupProjects, pools, reportSalaryId, userSalaryValues, userDims, date);
3d1718cf   姜超   feature(*): 薪酬报表
194
195
      }
  
a38c5a05   姜超   feature(*): 薪酬报表
196
197
198
199
      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(*): 薪酬报表
200
201
202
203
204
              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(*): 薪酬组人员日期
205
                      continue;
a38c5a05   姜超   feature(*): 薪酬报表
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
                  }
                  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);
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
229
          Map<Long, List<SalaryPoolDetail>> salaryPoolDetailMap = this.getSalaryPoolDetailMap(date, pools);
f99b77fe   姜超   feature(*): 薪酬报表
230
          List<ReportSalaryDimValue> reportSalaryValues = new ArrayList<>();
a38c5a05   姜超   feature(*): 薪酬报表
231
          //人的维度为基础,计算各个指标信息对应的数据
3d1718cf   姜超   feature(*): 薪酬报表
232
          for (SalaryPool pool : pools) {
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
233
234
              List<SalaryPoolDetail> salaryPoolIdDetails = Optional.ofNullable(salaryPoolDetailMap.get(pool.getId())).orElse(Collections.emptyList());
              ReportSalaryDim reportSalaryDim = saveStaffDim(pool, date, reportSalaryId,salaryPoolIdDetails);
f99b77fe   姜超   feature(*): 薪酬报表
235
              userDims.add(reportSalaryDim);
3d1718cf   姜超   feature(*): 薪酬报表
236
              final Long userId = pool.getUserId();
f99b77fe   姜超   feature(*): 薪酬报表
237
238
              final Long reportSalaryDimId = reportSalaryDim.getId();
              //薪酬排名组下的所有指标集合
a38c5a05   姜超   feature(*): 薪酬报表
239
              for (SalaryGroupProjectBO salaryGroupProject : salaryGroupProjects) {
f99b77fe   姜超   feature(*): 薪酬报表
240
                  if (! pool.getSalaryGroupId().equals(salaryGroupProject.getSalaryGroupId())) {
ab0e54c3   姜超   feature(mq): 门店名称...
241
                      continue;
584c7bfd   姜超   feature(*): 保存薪酬、...
242
                  }
f99b77fe   姜超   feature(*): 薪酬报表
243
                  final Long salaryGroupProjectId = salaryGroupProject.getId();
a38c5a05   姜超   feature(*): 薪酬报表
244
245
                  reportSalaryValues.add(this.convertDB(salaryGroupProject, reportSalaryDimId, date, userSalaryMap.get(userId, salaryGroupProjectId)));
                  List<SalaryGroupProjectParamVO> salaryGroupProjectParamVos = salaryGroupProjectParamService.getSalaryGroupProjectParamVO(salaryGroupProject.getId());
9f47fb88   姜超   feature(*): 薪酬组人员日期
246
247
  
                  if (salaryGroupProject.getCalMethod().equals(SalaryCalMethodEnum.CAR_SERIES)) {
9f47fb88   姜超   feature(*): 薪酬组人员日期
248
249
250
                      continue;
                  }
  
a38c5a05   姜超   feature(*): 薪酬报表
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
                  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(*): 报表修改
268
                      }
3d1718cf   姜超   feature(*): 薪酬报表
269
270
271
                  }
              }
          }
a38c5a05   姜超   feature(*): 薪酬报表
272
          if (PublicUtil.isNotEmpty(reportSalaryValues)){
f99b77fe   姜超   feature(*): 薪酬报表
273
              reportSalaryDimValueService.saveBatch(reportSalaryValues);
3d1718cf   姜超   feature(*): 薪酬报表
274
275
276
          }
          return reportSalaryValues;
      }
f1e68b31   姜超   feature(*): 报表修改
277
  
a38c5a05   姜超   feature(*): 薪酬报表
278
      public void calcShop(List<SalaryGroupProjectBO> salaryGroupProjects,
3d1718cf   姜超   feature(*): 薪酬报表
279
                            List<SalaryPool> pools,
50e72955   姜超   feature(*): 薪酬报表
280
                            Long reportSalaryId,
f99b77fe   姜超   feature(*): 薪酬报表
281
                            List<ReportSalaryDimValue> userSalaryValues,
50e72955   姜超   feature(*): 薪酬报表
282
                            List<ReportSalaryDim> userDims,
3d1718cf   姜超   feature(*): 薪酬报表
283
284
                            LocalDate date) {
          Map<Long, String> shopMap = pools.stream().collect(Collectors.toMap(SalaryPool::getShopId, SalaryPool::getShopName, (v1, v2) -> v1));
a38c5a05   姜超   feature(*): 薪酬报表
285
          List<ReportSalaryDimValue> reportSalaryDimValues = new ArrayList<>();
3d1718cf   姜超   feature(*): 薪酬报表
286
          for (Long shopId : shopMap.keySet()) {
a38c5a05   姜超   feature(*): 薪酬报表
287
              List<ReportSalaryDimValue> childReportSalaryDimValues = new ArrayList<>();
3d1718cf   姜超   feature(*): 薪酬报表
288
              Set<Long> shopDimReportIds = userDims.stream()
751d3eef   姜超   feature(*): 薪酬报表
289
                      .filter(user -> shopId.equals(user.getShopId()))
50e72955   姜超   feature(*): 薪酬报表
290
                      .map(ReportSalaryDim::getId).collect(Collectors.toSet());
751d3eef   姜超   feature(*): 薪酬报表
291
292
293
              if (PublicUtil.isEmpty(shopDimReportIds)) {
                  continue;
              }
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
294
              final Long shopReportSalaryDimId = this.saveShopDimDB(shopId, shopMap, date, reportSalaryId, userDims, shopDimReportIds);
3d1718cf   姜超   feature(*): 薪酬报表
295
  
a38c5a05   姜超   feature(*): 薪酬报表
296
              for (SalaryGroupProjectBO salaryGroupProject : salaryGroupProjects) {
751d3eef   姜超   feature(*): 薪酬报表
297
                  BigDecimal value = calcAverageValue(userSalaryValues, shopDimReportIds, salaryGroupProject.getId().toString());
a38c5a05   姜超   feature(*): 薪酬报表
298
299
300
301
302
303
                  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
304
                      }
a38c5a05   姜超   feature(*): 薪酬报表
305
306
                      BigDecimal paramValue = calcAverageValue(userSalaryValues, shopDimReportIds, salaryGroupProjectParam.getIndicatorCode());
                      childReportSalaryDimValues.add(this.convertShopValueDBPcode(salaryGroupProjectParam, paramValue, salaryGroupProject));
f1e68b31   姜超   feature(*): 报表修改
307
                  }
ab0e54c3   姜超   feature(mq): 门店名称...
308
              }
a38c5a05   姜超   feature(*): 薪酬报表
309
310
311
312
313
314
315
316
317
  
              childReportSalaryDimValues.forEach(reportSalaryDimValue -> {
                  reportSalaryDimValue.setDataDate(date);
                  reportSalaryDimValue.setReportSalaryDimId(shopReportSalaryDimId);
              });
              reportSalaryDimValues.addAll(childReportSalaryDimValues);
          }
          if (PublicUtil.isNotEmpty(reportSalaryDimValues)){
              reportSalaryDimValueService.saveBatch(reportSalaryDimValues);
3d1718cf   姜超   feature(*): 薪酬报表
318
319
          }
      }
f1e68b31   姜超   feature(*): 报表修改
320
  
a38c5a05   姜超   feature(*): 薪酬报表
321
      public void calcManager(List<SalaryGroupProjectBO> salaryGroupProjects,
19983bbb   姜超   feature(*): 薪酬报表
322
323
324
325
326
327
328
329
330
331
332
333
334
335
                            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(*): 薪酬报表
336
              List<ReportSalaryDimValue> childReportSalaryDimValues = new ArrayList<>();
7a1a8fd1   姜超   feature(*): 管理人员判断
337
338
339
              if (PublicUtil.isEmpty(manager.getManageStaffList())) {
                  continue;
              }
19983bbb   姜超   feature(*): 薪酬报表
340
341
              List<Long> manageStaffIds = manager.getManageStaffList().stream().map(StaffBaseInfoDTO::getId).distinct().collect(Collectors.toList());
              Set<Long> managerStaffDimReportIds = userDims.stream()
751d3eef   姜超   feature(*): 薪酬报表
342
                      .filter(user -> manageStaffIds.contains(user.getUserId()))
19983bbb   姜超   feature(*): 薪酬报表
343
344
345
346
                      .map(ReportSalaryDim::getId).collect(Collectors.toSet());
              if (PublicUtil.isEmpty(managerStaffDimReportIds)) {
                  continue;
              }
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
347
348
349
              //BigDecimal kpiScoreRatio = calcAverageKpiScoreRatio(userDims, managerStaffDimReportIds);
              //BigDecimal averageSalary = calcAverageTotalSalary(userDims, managerStaffDimReportIds);
              final Long reportSalaryDimId = this.saveManagerDimDB(manager, date, reportSalaryId, managerMap,manageStaffIds,managerStaffDimReportIds,userDims);
a38c5a05   姜超   feature(*): 薪酬报表
350
              for (SalaryGroupProjectBO salaryGroupProject : salaryGroupProjects) {
751d3eef   姜超   feature(*): 薪酬报表
351
                  BigDecimal value = calcAverageValue(userSalaryValues, managerStaffDimReportIds, salaryGroupProject.getId().toString());
9897d479   姜超   feature(*): 绩效报表
352
                  childReportSalaryDimValues.add(this.convertProjectValueDB(salaryGroupProject, value));
a38c5a05   姜超   feature(*): 薪酬报表
353
354
355
                  List<SalaryGroupProjectParamVO> salaryGroupProjectParamVos = salaryGroupProjectParamService.getSalaryGroupProjectParamVO(salaryGroupProject.getId());
                  for (SalaryGroupProjectParamVO salaryGroupProjectParam : salaryGroupProjectParamVos) {
                      BigDecimal paramValue = calcAverageValue(userSalaryValues, managerStaffDimReportIds, salaryGroupProjectParam.getIndicatorCode());
9897d479   姜超   feature(*): 绩效报表
356
                      childReportSalaryDimValues.add(this.convertShopValueDBPcode(salaryGroupProjectParam, paramValue, salaryGroupProject));
19983bbb   姜超   feature(*): 薪酬报表
357
358
                  }
              }
a38c5a05   姜超   feature(*): 薪酬报表
359
360
361
362
363
364
  
              childReportSalaryDimValues.forEach(reportSalaryDimValue -> {
                  reportSalaryDimValue.setDataDate(date);
                  reportSalaryDimValue.setReportSalaryDimId(reportSalaryDimId);
              });
              reportSalaryDimValues.addAll(childReportSalaryDimValues);
19983bbb   姜超   feature(*): 薪酬报表
365
366
367
368
369
370
371
372
373
374
375
376
          }
          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));
      }
  
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
      /**
       * 抽象处理平均值计算
       * @param data
       * @param predicate
       * @param field
       * @return
       */
      private <T> BigDecimal calcAverage(final Collection<T> data,Predicate<T> predicate, final ToDoubleFunction<T> field) {
          if (CollectionUtils.isEmpty(data)) {
              return BigDecimal.ZERO;
          }
          Double averageRatioDouble = data.stream()
                  .filter(predicate)
                  .mapToDouble(field)
                  .average()
                  .orElse(0);
          return BigDecimal.valueOf(averageRatioDouble);
      }
  
      /**
       * 抽象处理平均值计算
       * @param data
       * @param field
       * @return
       * @param <T>
       */
      private <T> BigDecimal calcAverage(final Collection<T> data, final ToDoubleFunction<T> field) {
          if (CollectionUtils.isEmpty(data)) {
              return BigDecimal.ZERO;
          }
          Double averageRatioDouble = data.stream()
                  .mapToDouble(field)
                  .average()
                  .orElse(0);
          return BigDecimal.valueOf(averageRatioDouble);
      }
  
  
751d3eef   姜超   feature(*): 薪酬报表
415
416
417
418
419
420
421
422
423
      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(*): 绩效报表新...
424
425
426
427
428
429
430
431
432
      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(*): 薪酬报表
433
      public BigDecimal calcAverageValue(List<ReportSalaryDimValue> userSalaryValues, Set<Long> ReportDimIds, String code) {
3d1718cf   姜超   feature(*): 薪酬报表
434
          Double averageRatioDouble = userSalaryValues.stream()
19983bbb   姜超   feature(*): 薪酬报表
435
                  .filter(user -> ReportDimIds.contains(user.getReportSalaryDimId()) && code.equals(user.getCode()))
3d1718cf   姜超   feature(*): 薪酬报表
436
437
438
439
440
                  .mapToDouble(userValue -> Optional.ofNullable(userValue.getValue()).orElse(BigDecimal.ZERO).doubleValue())
                  .average()
                  .orElse(0);
          return new BigDecimal(averageRatioDouble.toString());
      }
584c7bfd   姜超   feature(*): 保存薪酬、...
441
  
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
442
443
444
445
446
447
      public Long saveShopDimDB(Long shopId,
                                Map<Long, String> shopMap,
                                LocalDate date,
                                Long reportSalaryId,
                                List<ReportSalaryDim> userDims,
                                Set<Long> shopDimReportIds) {
751d3eef   姜超   feature(*): 薪酬报表
448
449
450
451
452
453
454
          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);
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
455
456
          //计算平均值薪酬的额外项
          extCalcAverage(userDims, shopDimReportIds, reportSalaryDim);
751d3eef   姜超   feature(*): 薪酬报表
457
458
          reportSalaryDimService.save(reportSalaryDim);
          return reportSalaryDim.getId();
19983bbb   姜超   feature(*): 薪酬报表
459
      }
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
  
      /**
       * 计算平均值薪酬的额外项
       * @param userDims
       * @param shopDimReportIds
       * @param reportSalaryDim
       */
      private void extCalcAverage(List<ReportSalaryDim> userDims, Set<Long> shopDimReportIds, ReportSalaryDim reportSalaryDim) {
          List<ReportSalaryDim> filterUserDims = userDims.stream().filter(e -> shopDimReportIds.contains(e.getId())).collect(Collectors.toList());
          //绩效得分率(N)
          reportSalaryDim.setKpiScoreRatio(calcAverage(filterUserDims, e -> Optional.ofNullable(e.getKpiScoreRatio()).orElse(BigDecimal.ZERO).doubleValue()));
          //收入-平均值
          reportSalaryDim.setActKpiMoney(calcAverage(filterUserDims, e -> Optional.ofNullable(e.getActKpiMoney()).orElse(BigDecimal.ZERO).doubleValue()));
          reportSalaryDim.setActAwardMoney(calcAverage(filterUserDims, e -> Optional.ofNullable(e.getActAwardMoney()).orElse(BigDecimal.ZERO).doubleValue()));
          reportSalaryDim.setActSubsidyMoney(calcAverage(filterUserDims, e -> Optional.ofNullable(e.getActSubsidyMoney()).orElse(BigDecimal.ZERO).doubleValue()));
          reportSalaryDim.setActProbationMoney(calcAverage(filterUserDims, e -> Optional.ofNullable(e.getActProbationMoney()).orElse(BigDecimal.ZERO).doubleValue()));
          reportSalaryDim.setActJobCompensateMoney(calcAverage(filterUserDims, e -> Optional.ofNullable(e.getActJobCompensateMoney()).orElse(BigDecimal.ZERO).doubleValue()));
          reportSalaryDim.setActEvalAwardMoney(calcAverage(filterUserDims, e -> Optional.ofNullable(e.getActEvalAwardMoney()).orElse(BigDecimal.ZERO).doubleValue()));
          //总收入合计平均值
          reportSalaryDim.setActRevenueTotalMoney(calcAverage(filterUserDims, e -> Optional.ofNullable(e.getActRevenueTotalMoney()).orElse(BigDecimal.ZERO).doubleValue()));
          //reportSalaryDim.setActRevenueTotalMoney(
          //        reportSalaryDim.getActKpiMoney()
          //                .add(reportSalaryDim.getActAwardMoney())
          //                .add(reportSalaryDim.getActSubsidyMoney())
          //                .add(reportSalaryDim.getActProbationMoney())
          //                .add(reportSalaryDim.getActJobCompensateMonry())
          //                .add(reportSalaryDim.getActEvalAwardMoney())
          //);
          //扣除-平均值
          reportSalaryDim.setActPenaltyMoney(calcAverage(filterUserDims, e -> Optional.ofNullable(e.getActPenaltyMoney()).orElse(BigDecimal.ZERO).doubleValue()));
          reportSalaryDim.setActNecessaryMoney(calcAverage(filterUserDims, e -> Optional.ofNullable(e.getActNecessaryMoney()).orElse(BigDecimal.ZERO).doubleValue()));
          reportSalaryDim.setActPersonTaxMoney(calcAverage(filterUserDims, e -> Optional.ofNullable(e.getActPersonTaxMoney()).orElse(BigDecimal.ZERO).doubleValue()));
          reportSalaryDim.setActAccumulationFundMoney(calcAverage(filterUserDims, e -> Optional.ofNullable(e.getActAccumulationFundMoney()).orElse(BigDecimal.ZERO).doubleValue()));
          //总扣除合计平均值
          reportSalaryDim.setActDeductTotalMoney(calcAverage(filterUserDims, e -> Optional.ofNullable(e.getActDeductTotalMoney()).orElse(BigDecimal.ZERO).doubleValue()));
          //reportSalaryDim.setActDeductTotalMoney(
          //        reportSalaryDim.getActPenaltyMoney()
          //                .add(reportSalaryDim.getActNecessaryMoney())
          //                .add(reportSalaryDim.getActPersonTaxMoney())
          //                .add(reportSalaryDim.getActAccumulationFundMoney())
          //);
          //总薪酬平均值 = 总收入合计 - 总扣除合计 or 直接取平均值
          reportSalaryDim.setTotalReward(calcAverage(filterUserDims, e -> Optional.ofNullable(e.getTotalReward()).orElse(BigDecimal.ZERO).doubleValue()));
          //reportSalaryDim.setTotalReward(
          //        reportSalaryDim.getActRevenueTotalMoney()
          //                .subtract(reportSalaryDim.getActDeductTotalMoney()));
      }
  
      /**
       * 计算人员的
       * 增加 薪资类型相关项目处理 ++
       * @param salaryPoolDetails
       * @param reportSalaryDim
       */
      private void extCaleUserMoney(List<SalaryPoolDetail> salaryPoolDetails, ReportSalaryDim reportSalaryDim) {
          //额外计算项++
          Map<SalaryTypeEnum, List<SalaryPoolDetail>> salaryTypeEnumListMap = salaryPoolDetails
                  .stream()
                  .collect(Collectors.groupingBy(SalaryPoolDetail::getType));
          //收入
          reportSalaryDim.setActKpiMoney(getSalaryTypeEnumMoney(salaryTypeEnumListMap,SalaryTypeEnum.ROYALTIES));
          reportSalaryDim.setActAwardMoney(getSalaryTypeEnumMoney(salaryTypeEnumListMap,SalaryTypeEnum.AWARD));
          reportSalaryDim.setActSubsidyMoney(getSalaryTypeEnumMoney(salaryTypeEnumListMap,SalaryTypeEnum.SUBSIDY));
          reportSalaryDim.setActProbationMoney(getSalaryTypeEnumMoney(salaryTypeEnumListMap,SalaryTypeEnum.PROBATION));
          reportSalaryDim.setActJobCompensateMoney(BigDecimal.ZERO);
          reportSalaryDim.setActEvalAwardMoney(BigDecimal.ZERO);
          //总收入合计
          reportSalaryDim.setActRevenueTotalMoney(
                  reportSalaryDim.getActKpiMoney()
                          .add(reportSalaryDim.getActAwardMoney())
                          .add(reportSalaryDim.getActSubsidyMoney())
                          .add(reportSalaryDim.getActProbationMoney())
                          .add(reportSalaryDim.getActJobCompensateMoney())
                          .add(reportSalaryDim.getActEvalAwardMoney())
          );
          //扣除
          reportSalaryDim.setActPenaltyMoney(getSalaryTypeEnumMoney(salaryTypeEnumListMap,SalaryTypeEnum.PENALTY));
          reportSalaryDim.setActNecessaryMoney(getSalaryTypeEnumMoney(salaryTypeEnumListMap,SalaryTypeEnum.NECESSARY));
          reportSalaryDim.setActPersonTaxMoney(getSalaryTypeEnumMoney(salaryTypeEnumListMap,SalaryTypeEnum.PERSON_TAX));
          reportSalaryDim.setActAccumulationFundMoney(BigDecimal.ZERO);
          //总扣除合计
          reportSalaryDim.setActDeductTotalMoney(
                  reportSalaryDim.getActPenaltyMoney()
                          .add(reportSalaryDim.getActNecessaryMoney())
                          .add(reportSalaryDim.getActPersonTaxMoney())
                          .add(reportSalaryDim.getActAccumulationFundMoney())
          );
          //总薪酬 = 总收入合计 - 总扣除合计
          reportSalaryDim.setTotalReward(
                  reportSalaryDim.getActRevenueTotalMoney()
                          .subtract(reportSalaryDim.getActDeductTotalMoney()));
      }
  
  
751d3eef   姜超   feature(*): 薪酬报表
554
555
556
557
      public Long saveManagerDimDB(ManagerDTO manager,
                                   LocalDate date,
                                   Long reportSalaryId,
                                   Map<Long, StaffBaseInfoDTO> managerMap,
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
558
559
560
                                   List<Long> manageStaffIds,
                                   Set<Long> managerStaffDimReportIds,
                                   List<ReportSalaryDim> userDims) {
19983bbb   姜超   feature(*): 薪酬报表
561
562
563
564
          ReportSalaryDim reportSalaryDim = new ReportSalaryDim();
          reportSalaryDim.setDimension(ReportDimensionEnum.MANAGER);
          reportSalaryDim.setUserId(manager.getStaffId());
          reportSalaryDim.setUserName(manager.getStaffName());
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
565
566
          //计算平均值薪酬的额外项
          extCalcAverage(userDims, managerStaffDimReportIds, reportSalaryDim);
19983bbb   姜超   feature(*): 薪酬报表
567
568
569
570
571
572
          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(*): 薪酬报表
573
574
              reportSalaryDim.setPostId(staffInfo.getPostId());
              reportSalaryDim.setPostName(staffInfo.getPostName());
19983bbb   姜超   feature(*): 薪酬报表
575
          }
751d3eef   姜超   feature(*): 薪酬报表
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
  
          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(*): 薪酬报表
604
          return reportSalaryDim.getId();
3d1718cf   姜超   feature(*): 薪酬报表
605
      }
584c7bfd   姜超   feature(*): 保存薪酬、...
606
  
a38c5a05   姜超   feature(*): 薪酬报表
607
      public ReportSalaryDimValue convertProjectValueDB(SalaryGroupProjectBO salaryGroupProject, BigDecimal value) {
f99b77fe   姜超   feature(*): 薪酬报表
608
          ReportSalaryDimValue reportSalaryValue = new ReportSalaryDimValue();
9897d479   姜超   feature(*): 绩效报表
609
          reportSalaryValue.setCode(salaryGroupProject.getId().toString());
f99b77fe   姜超   feature(*): 薪酬报表
610
          reportSalaryValue.setCodeType(salaryGroupProject.getCodeType());
3d1718cf   姜超   feature(*): 薪酬报表
611
          reportSalaryValue.setValue(value);
f99b77fe   姜超   feature(*): 薪酬报表
612
          reportSalaryValue.setSalaryGroupProjectId(salaryGroupProject.getId());
3d1718cf   姜超   feature(*): 薪酬报表
613
614
          return reportSalaryValue;
      }
1a596c74   姜超   feature(*): 绩效报表
615
  
a38c5a05   姜超   feature(*): 薪酬报表
616
      public ReportSalaryDimValue convertShopValueDBPcode(SalaryGroupProjectParamVO salaryGroupProjectParam, BigDecimal value,SalaryGroupProjectBO salaryGroupProject) {
f99b77fe   姜超   feature(*): 薪酬报表
617
618
          ReportSalaryDimValue reportSalaryValue = new ReportSalaryDimValue();
          reportSalaryValue.setCode(salaryGroupProjectParam.getIndicatorCode());
3d1718cf   姜超   feature(*): 薪酬报表
619
620
          reportSalaryValue.setCodeType(IndicatorCodeTypeEnum.INDICATOR);
          reportSalaryValue.setValue(value);
f99b77fe   姜超   feature(*): 薪酬报表
621
          reportSalaryValue.setSalaryGroupProjectId(salaryGroupProjectParam.getSalaryGroupProjectId());
9897d479   姜超   feature(*): 绩效报表
622
          reportSalaryValue.setParentCode(salaryGroupProject.getId().toString());
3d1718cf   姜超   feature(*): 薪酬报表
623
624
          return reportSalaryValue;
      }
1a596c74   姜超   feature(*): 绩效报表
625
  
584c7bfd   姜超   feature(*): 保存薪酬、...
626
  
a38c5a05   姜超   feature(*): 薪酬报表
627
      public ReportSalaryDimValue convertDB(SalaryGroupProjectBO salaryGroupProject, Long reportSalaryDimId, LocalDate date, BigDecimal salaryValue) {
f99b77fe   姜超   feature(*): 薪酬报表
628
          ReportSalaryDimValue reportSalaryValue = new ReportSalaryDimValue();
0db06804   姜超   feature(*): 薪酬报表数据抽取
629
          reportSalaryValue.setCode(salaryGroupProject.getId().toString());
f99b77fe   姜超   feature(*): 薪酬报表
630
          reportSalaryValue.setCodeType(salaryGroupProject.getCodeType());
a38c5a05   姜超   feature(*): 薪酬报表
631
632
633
634
635
          if (PublicUtil.isEmpty(salaryValue)) {
              reportSalaryValue.setValue(BigDecimal.ZERO);
          } else {
              reportSalaryValue.setValue(salaryValue);
          }
3d1718cf   姜超   feature(*): 薪酬报表
636
637
          reportSalaryValue.setDataDate(date);
          reportSalaryValue.setReportSalaryDimId(reportSalaryDimId);
f99b77fe   姜超   feature(*): 薪酬报表
638
          reportSalaryValue.setSalaryGroupProjectId(salaryGroupProject.getId());
3d1718cf   姜超   feature(*): 薪酬报表
639
640
          return reportSalaryValue;
      }
584c7bfd   姜超   feature(*): 保存薪酬、...
641
  
a38c5a05   姜超   feature(*): 薪酬报表
642
      public ReportSalaryDimValue convertNoTargetDB(SalaryGroupProjectBO salaryGroupProject,
f99b77fe   姜超   feature(*): 薪酬报表
643
                                              SalaryGroupProjectParamVO salaryGroupProjectParam,
3d1718cf   姜超   feature(*): 薪酬报表
644
645
646
                                              LocalDate date,
                                              Long reportSalaryDimId,
                                              BigDecimal value) {
f99b77fe   姜超   feature(*): 薪酬报表
647
648
          ReportSalaryDimValue reportSalaryValue = new ReportSalaryDimValue();
          reportSalaryValue.setCode(salaryGroupProjectParam.getIndicatorCode());
3d1718cf   姜超   feature(*): 薪酬报表
649
          reportSalaryValue.setCodeType(IndicatorCodeTypeEnum.INDICATOR);
0db06804   姜超   feature(*): 薪酬报表数据抽取
650
          reportSalaryValue.setParentCode(salaryGroupProject.getId().toString());
3d1718cf   姜超   feature(*): 薪酬报表
651
652
          reportSalaryValue.setValue(value);
          //百分数处理
f99b77fe   姜超   feature(*): 薪酬报表
653
          if (DataTypeEnum.RATIO.equals(salaryGroupProjectParam.getDataType())){
3d1718cf   姜超   feature(*): 薪酬报表
654
              reportSalaryValue.setValue(value.multiply(Constant.ONE_HUNDRED));
584c7bfd   姜超   feature(*): 保存薪酬、...
655
          }
3d1718cf   姜超   feature(*): 薪酬报表
656
657
          reportSalaryValue.setDataDate(date);
          reportSalaryValue.setReportSalaryDimId(reportSalaryDimId);
f99b77fe   姜超   feature(*): 薪酬报表
658
          reportSalaryValue.setSalaryGroupProjectId(salaryGroupProject.getId());
3d1718cf   姜超   feature(*): 薪酬报表
659
660
          return reportSalaryValue;
      }
a38c5a05   姜超   feature(*): 薪酬报表
661
      public ReportSalaryDimValue convertTargetDB(SalaryGroupProjectBO salaryGroupProject,
f99b77fe   姜超   feature(*): 薪酬报表
662
                                              SalaryGroupProjectParamVO salaryGroupProjectParam,
3d1718cf   姜超   feature(*): 薪酬报表
663
664
665
                                              LocalDate date,
                                              Long reportSalaryDimId,
                                              BigDecimal value) {
f99b77fe   姜超   feature(*): 薪酬报表
666
667
          ReportSalaryDimValue reportSalaryValue = new ReportSalaryDimValue();
          reportSalaryValue.setCode(salaryGroupProjectParam.getIndicatorCode());
3d1718cf   姜超   feature(*): 薪酬报表
668
          reportSalaryValue.setCodeType(IndicatorCodeTypeEnum.INDICATOR);
0db06804   姜超   feature(*): 薪酬报表数据抽取
669
          reportSalaryValue.setParentCode(salaryGroupProject.getId().toString());
3d1718cf   姜超   feature(*): 薪酬报表
670
671
672
673
          //有目标 乘以 100
          reportSalaryValue.setValue(value.multiply(Constant.ONE_HUNDRED));
          reportSalaryValue.setDataDate(date);
          reportSalaryValue.setReportSalaryDimId(reportSalaryDimId);
f99b77fe   姜超   feature(*): 薪酬报表
674
          reportSalaryValue.setSalaryGroupProjectId(salaryGroupProject.getId());
3d1718cf   姜超   feature(*): 薪酬报表
675
          return reportSalaryValue;
584c7bfd   姜超   feature(*): 保存薪酬、...
676
677
      }
  
a38c5a05   姜超   feature(*): 薪酬报表
678
      public MultiKeyMap<Long, BigDecimal> getUserIndicatorHitMap(List<SalaryGroupProjectBO> salaryGroupProjects, LocalDate date, List<SalaryPool> pools) {
f99b77fe   姜超   feature(*): 薪酬报表
679
          List<SalaryGroupProjectHitLog> indicatorHitLogs = salaryGroupProjectHitLogService.list(Wrappers.<SalaryGroupProjectHitLog>lambdaQuery()
a38c5a05   姜超   feature(*): 薪酬报表
680
                  .in(SalaryGroupProjectHitLog::getSalaryGroupProjectId, salaryGroupProjects.stream().map(SalaryGroupProjectBO::getId).collect(Collectors.toList()))
f99b77fe   姜超   feature(*): 薪酬报表
681
682
683
                  .in(SalaryGroupProjectHitLog::getUserId, pools.stream().map(SalaryPool::getUserId).collect(Collectors.toList()))
                  .eq(SalaryGroupProjectHitLog::getDataDate, date)
                  .eq(SalaryGroupProjectHitLog::getYn, Boolean.TRUE)
3d1718cf   姜超   feature(*): 薪酬报表
684
685
          );
          MultiKeyMap<Long, BigDecimal> userGroupIndicatorHitMap = new MultiKeyMap<>();
f99b77fe   姜超   feature(*): 薪酬报表
686
687
          for (SalaryGroupProjectHitLog hitLog : indicatorHitLogs) {
              userGroupIndicatorHitMap.put(hitLog.getUserId(), hitLog.getSalaryGroupProjectId(), hitLog.getSalaryValue());
f1e68b31   姜超   feature(*): 报表修改
688
          }
3d1718cf   姜超   feature(*): 薪酬报表
689
690
          return userGroupIndicatorHitMap;
      }
584c7bfd   姜超   feature(*): 保存薪酬、...
691
  
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
692
693
694
695
696
697
698
699
700
701
702
703
704
705
      /**
       * 这个薪酬详情每天6:00 会计算完成,cn.fw.morax.server.task.SalaryCalcTask#cacheCalculableKpiGroup()
       * @param date
       * @param pools
       * @return <薪酬池id: 薪酬池详情list>
       */
      private Map<Long, List<SalaryPoolDetail>> getSalaryPoolDetailMap(LocalDate date, List<SalaryPool> pools) {
          if (CollectionUtils.isEmpty(pools)){
              return Collections.emptyMap();
          }
          List<SalaryPoolDetail> salaryPoolDetailList = salaryPoolDetailService.list(Wrappers.<SalaryPoolDetail>lambdaQuery()
                  .in(SalaryPoolDetail::getSalaryPoolId, pools.stream().map(SalaryPool::getId).collect(Collectors.toSet()))
                  .eq(SalaryPoolDetail::getSalaryDate, date)
                  .eq(SalaryPoolDetail::getYn, Boolean.TRUE));
16c70f81   xianpengcheng   更新薪酬计算的校验
706
707
708
          if (CollectionUtils.isEmpty(salaryPoolDetailList)){
              return Collections.emptyMap();
          }
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
709
710
          return salaryPoolDetailList.stream().collect(Collectors.groupingBy(SalaryPoolDetail::getSalaryPoolId));
      }
f1e68b31   姜超   feature(*): 报表修改
711
  
f99b77fe   姜超   feature(*): 薪酬报表
712
713
714
715
716
717
718
      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(*): 薪酬报表
719
720
          );
          return targetHitLogs.stream()
f99b77fe   姜超   feature(*): 薪酬报表
721
                  .collect(Collectors.toMap(SalaryGroupProjectTargetHitLog::getUserId, Function.identity(), (v1, v2) -> v1));
584c7bfd   姜超   feature(*): 保存薪酬、...
722
723
      }
  
91b69450   姜超   feature(mq): 门店名称...
724
  
3d1718cf   姜超   feature(*): 薪酬报表
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
  
      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): 门店名称...
744
          }
3d1718cf   姜超   feature(*): 薪酬报表
745
746
          return referValueMap;
      }
91b69450   姜超   feature(mq): 门店名称...
747
  
a38c5a05   姜超   feature(*): 薪酬报表
748
749
750
      public ReportSalaryCode createProjectCode(SalaryGroupProjectBO salaryGroupProject,AtomicInteger order) {
          ReportSalaryCode reportSalaryCode = new ReportSalaryCode();
          reportSalaryCode.setSalaryGroupProjectId(salaryGroupProject.getId());
0db06804   姜超   feature(*): 薪酬报表数据抽取
751
          reportSalaryCode.setCode(salaryGroupProject.getId().toString());
a38c5a05   姜超   feature(*): 薪酬报表
752
753
754
755
756
757
          reportSalaryCode.setCodeType(salaryGroupProject.getCodeType());
          reportSalaryCode.setIndicatorName(salaryGroupProject.getName());
          reportSalaryCode.setOrderNum(order.incrementAndGet());
          return reportSalaryCode;
      }
  
a38c5a05   姜超   feature(*): 薪酬报表
758
759
760
761
762
763
764
765
766
767
      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(*): 薪酬报表数据抽取
768
              reportSalaryCode.setParentCode(salaryGroupProject.getId().toString());
a38c5a05   姜超   feature(*): 薪酬报表
769
770
              reportSalaryCode.setOrderNum(order.incrementAndGet());
              saveReportSalaryCodes.add(reportSalaryCode);
3d1718cf   姜超   feature(*): 薪酬报表
771
          }
a38c5a05   姜超   feature(*): 薪酬报表
772
          return saveReportSalaryCodes;
3d1718cf   姜超   feature(*): 薪酬报表
773
      }
91b69450   姜超   feature(mq): 门店名称...
774
  
19983bbb   姜超   feature(*): 薪酬报表
775
      private Long saveReportSalary(SalaryGroup salaryGroup, Long groupId, LocalDate date) {
3d1718cf   姜超   feature(*): 薪酬报表
776
  
f99b77fe   姜超   feature(*): 薪酬报表
777
778
779
          ReportSalary reportSalary = new ReportSalary();
          reportSalary.setSalaryGroupId(salaryGroup.getId());
          reportSalary.setSalaryName(salaryGroup.getName());
3d1718cf   姜超   feature(*): 薪酬报表
780
          //门店id
f99b77fe   姜超   feature(*): 薪酬报表
781
782
783
784
785
          reportSalary.setShopIds(salaryGroup.getShopIds());
          reportSalary.setMonthly(YearMonth.from(date));
          reportSalary.setDataDate(date);
          reportSalary.setGroupId(groupId);
          reportSalaryService.save(reportSalary);
19983bbb   姜超   feature(*): 薪酬报表
786
          return reportSalary.getId();
3d1718cf   姜超   feature(*): 薪酬报表
787
      }
91b69450   姜超   feature(mq): 门店名称...
788
  
fae07964   姜超   feature(*): 报表清除数据修改
789
      private void cleanData(LocalDate endDate) {
50e72955   姜超   feature(*): 薪酬报表
790
          List<ReportSalary> reportSalaries = reportSalaryService.list(Wrappers.<ReportSalary>lambdaQuery()
fae07964   姜超   feature(*): 报表清除数据修改
791
  //                .eq(ReportSalary::getSalaryGroupId, salaryGroup.getId())
f99b77fe   姜超   feature(*): 薪酬报表
792
                  //.ge(ReportSalary::getDataDate, startDate.with(TemporalAdjusters.firstDayOfMonth()))
3d1718cf   姜超   feature(*): 薪酬报表
793
                  //取当前日期对应月的第一天
84d3fe49   姜超   feature(*): 薪酬报表
794
795
                  .ge(ReportSalary::getDataDate, endDate.with(TemporalAdjusters.firstDayOfMonth()))
                  .le(ReportSalary::getDataDate, endDate)
3d1718cf   姜超   feature(*): 薪酬报表
796
          );
50e72955   姜超   feature(*): 薪酬报表
797
          if (PublicUtil.isEmpty(reportSalaries)){
3d1718cf   姜超   feature(*): 薪酬报表
798
              return;
84f9d303   姜超   feature(*): 定时任务修改
799
          }
50e72955   姜超   feature(*): 薪酬报表
800
          this.cleanData(reportSalaries);
84d3fe49   姜超   feature(*): 薪酬报表
801
802
803
804
805
806
807
808
809
810
      }
  
      /**
       * 清理排名组下报表数据
       * @param reportSalaries
       */
      public void cleanData(List<ReportSalary> reportSalaries) {
          if (CollectionUtils.isEmpty(reportSalaries)){
              return;
          }
f99b77fe   姜超   feature(*): 薪酬报表
811
          //薪酬排名组ids
84d3fe49   姜超   feature(*): 薪酬报表
812
813
814
815
816
817
818
819
820
821
822
823
824
825
          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(*): 薪酬报表
826
827
828
          reportSalaryDimExtraService.remove(Wrappers.<ReportSalaryDimExtra>lambdaUpdate()
                  .in(ReportSalaryDimExtra::getReportSalaryDimId, reportSalaryDimIds)
          );
84d3fe49   姜超   feature(*): 薪酬报表
829
830
831
          reportSalaryDimValueService.remove(Wrappers.<ReportSalaryDimValue>lambdaUpdate()
                  .in(ReportSalaryDimValue::getReportSalaryDimId, reportSalaryDimIds)
          );
84f9d303   姜超   feature(*): 定时任务修改
832
      }
584c7bfd   姜超   feature(*): 保存薪酬、...
833
  
a38c5a05   姜超   feature(*): 薪酬报表
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
      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(*): 基本工资不能下钻
850
851
852
853
854
855
856
857
                      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(*): 薪酬报表
858
859
860
                      projectBO.setCodeType(codeType);
                      break;
                  }
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
861
862
                  case FIXATION:
                  case CAR_SERIES: {
a38c5a05   姜超   feature(*): 薪酬报表
863
864
865
866
867
868
869
870
871
872
                      projectBO.setCode(project.getCommissionCode());
                      projectBO.setCodeType(IndicatorCodeTypeEnum.COMBINE_INDICATOR);
                      break;
                  }
                  case LADDER: {
                      projectBO.setCode(project.getLadderCode());
                      projectBO.setCodeType(IndicatorCodeTypeEnum.COMBINE_INDICATOR);
                      break;
                  }
              }
5d2a2a83   姜超   feature(*): 基本工资不能下钻
873
874
875
876
              //基本工资不能下钻
              if (getBaseSalaryCode().equals(projectBO.getCode())) {
                  projectBO.setCodeType(IndicatorCodeTypeEnum.INDICATOR);
              }
a38c5a05   姜超   feature(*): 薪酬报表
877
878
879
880
              projects.add(projectBO);
          }
          return projects;
      }
3d1718cf   姜超   feature(*): 薪酬报表
881
  
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
882
      public ReportSalaryDim saveStaffDim(SalaryPool pool, LocalDate date, Long reportSalaryRankId,List<SalaryPoolDetail> salaryPoolDetails){
f99b77fe   姜超   feature(*): 薪酬报表
883
884
885
886
887
888
889
890
891
892
893
894
          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(*): 薪酬报表
895
          reportSalaryDim.setStarLevel(pool.getStarLevel());
3a182cd0   姜超   feature(*): 绩效报表新...
896
897
898
899
900
  //        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));
  //        }
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
901
902
          //薪资类型相关项目处理
          extCaleUserMoney(salaryPoolDetails, reportSalaryDim);
f99b77fe   姜超   feature(*): 薪酬报表
903
904
          reportSalaryDimService.save(reportSalaryDim);
          return reportSalaryDim;
584c7bfd   姜超   feature(*): 保存薪酬、...
905
906
      }
  
25c3f574   xianpengcheng   更新-薪酬额外项字段的计算和添加
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
      /**
       * 获取 SalaryTypeEnum 对应的薪酬总值
       * @param salaryTypeEnumListMap
       * @param salaryTypeEnum
       * @return
       */
      private BigDecimal getSalaryTypeEnumMoney(Map<SalaryTypeEnum, List<SalaryPoolDetail>> salaryTypeEnumListMap,SalaryTypeEnum salaryTypeEnum){
          if (CollectionUtils.isEmpty(salaryTypeEnumListMap)){
              return BigDecimal.ZERO;
          }
          List<SalaryPoolDetail> list = salaryTypeEnumListMap.get(salaryTypeEnum);
          if (CollectionUtils.isEmpty(list)){
              return BigDecimal.ZERO;
          }
          return list.stream().filter(Objects::nonNull).map(SalaryPoolDetail::getSalaryAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
      }
  
584c7bfd   姜超   feature(*): 保存薪酬、...
924
  }