EvalPoolCommonService.java
10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
package cn.fw.morax.service.biz.eval;
import cn.fw.ehr.sdk.api.enums.StaffShopTypeEnum;
import cn.fw.morax.common.utils.PublicUtil;
import cn.fw.morax.domain.db.eval.*;
import cn.fw.morax.domain.enums.EvalScopeEnum;
import cn.fw.morax.domain.enums.EvalShopPoolStatusEnum;
import cn.fw.morax.rpc.ehr.EhrRpcService;
import cn.fw.morax.rpc.ehr.dto.StaffBaseInfoDTO;
import cn.fw.morax.rpc.ehr.dto.StaffShopInfoDTO;
import cn.fw.morax.rpc.oop.OopRpcService;
import cn.fw.morax.rpc.oop.dto.ShopDTO;
import cn.fw.morax.service.data.eval.EvalGroupRewardDimService;
import cn.fw.morax.service.data.eval.EvalShopPoolService;
import cn.fw.morax.service.data.eval.EvalUserPoolService;
import cn.fw.morax.service.data.salary.SalaryGroupUserService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author : kurisu
* @version : 1.0
* @className : SalaryPoolCommonService
* @description : 绩效池公用方法
* @date : 2022-09-27 11:40
*/
@Slf4j
@Service
@AllArgsConstructor
public class EvalPoolCommonService {
private SalaryGroupUserService salaryGroupUserService;
private EvalUserPoolService evalUserPoolService;
private EvalGroupRewardDimService evalGroupRewardDimService;
private EvalShopPoolService evalShopPoolService;
private EhrRpcService ehrRpcService;
private OopRpcService oopRpcService;
public Map<Long, EvalUserPool> inspectionUserPoolMap(EvalGroup evalGroup, List<EvalGroupUser> users, LocalDate localDate) {
if (PublicUtil.isEmpty(users)) {
return new HashMap<>();
}
Set<Long> userIds = users.stream().map(EvalGroupUser::getUserId).collect(Collectors.toSet());
List<EvalUserPool> pools = evalUserPoolService.list(Wrappers.<EvalUserPool>lambdaQuery()
.eq(EvalUserPool::getEvalGroupId, evalGroup.getId())
.eq(EvalUserPool::getMonthly, YearMonth.from(localDate))
.in(EvalUserPool::getUserId, userIds)
.eq(EvalUserPool::getYn, Boolean.TRUE)
);
Map<Long, EvalUserPool> userPoolMap = pools.stream().collect(Collectors.toMap(EvalUserPool::getUserId, Function.identity(), (v1, v2) -> {
log.error("同一个考评组、考评人员出现两条考评池数据。用户id:{},考评组:{}", v1.getUserId(), evalGroup);
return v1;
}));
for (EvalGroupUser user : users) {
if (! userPoolMap.containsKey(user.getUserId())) {
EvalUserPool userPool = inspectionUserPool(user);
userPoolMap.put(userPool.getUserId(), userPool);
}
}
return userPoolMap;
}
public Map<Long, EvalShopPool> inspectionShopPools(EvalGroup evalGroup, LocalDate localDate, List<Long> distShopIds) {
Set<Long> evalGroupShopIds = new HashSet<>(evalGroup.getShopIds());
List<EvalShopPool> pools = evalShopPoolService.list(Wrappers.<EvalShopPool>lambdaQuery()
.eq(EvalShopPool::getEvalGroupId, evalGroup.getId())
.in(EvalShopPool::getShopId, evalGroupShopIds)
.eq(EvalShopPool::getMonthly, YearMonth.from(localDate))
.eq(EvalShopPool::getYn, Boolean.TRUE)
);
Map<Long, EvalShopPool> shopPoolMap = pools.stream().collect(Collectors.toMap(EvalShopPool::getShopId, Function.identity(), (v1, v2) -> {
log.error("同一个考评组、考评门店出现两条考评池数据。门店id:{},考评组:{}", v1.getShopId(), evalGroup);
return v1;
}));
if (PublicUtil.isEmpty(distShopIds)) {
return new HashMap<>();
}
for (Long shopId : distShopIds) {
if (! shopPoolMap.containsKey(shopId)) {
// EvalShopPoolStatusEnum status = (distShopIds.contains(shopId))
// ? EvalShopPoolStatusEnum.CALC_REWARD : EvalShopPoolStatusEnum.NO_REWARD;
EvalShopPool shopPool = this.inspectionShopPool(shopId, evalGroup, localDate, EvalShopPoolStatusEnum.CALC_REWARD);
shopPoolMap.put(shopId, shopPool);
}
}
return shopPoolMap;
}
/**
* 查询考评门店池
*
* @return
*/
@Transactional(rollbackFor = Exception.class)
public EvalShopPool inspectionShopPool(Long shopId, EvalGroup evalGroup, LocalDate localDate, EvalShopPoolStatusEnum status) {
EvalShopPool evalShopPool = evalShopPoolService.getOne(Wrappers.<EvalShopPool>lambdaQuery()
.eq(EvalShopPool::getId, evalGroup.getId())
.eq(EvalShopPool::getShopId, shopId)
.eq(EvalShopPool::getYn, Boolean.TRUE)
.eq(EvalShopPool::getMonthly, YearMonth.from(localDate).minusMonths(1))
, Boolean.FALSE);
if (PublicUtil.isNotEmpty(evalShopPool)) {
evalShopPoolService.update(Wrappers.<EvalShopPool>lambdaUpdate()
.eq(EvalShopPool::getId, evalShopPool.getId())
.set(EvalShopPool::getMonthly, YearMonth.from(localDate))
.set(EvalShopPool::getUpdateTime, new Date())
);
evalShopPool.setMonthly(YearMonth.from(localDate));
return evalShopPool;
}
return this.createShopPoolData(shopId, evalGroup, localDate, status);
}
@Transactional(rollbackFor = Exception.class)
public EvalShopPool createShopPoolData(Long shopId, EvalGroup evalGroup, LocalDate localDate, EvalShopPoolStatusEnum status) {
ShopDTO shopDTO = oopRpcService.queryShop(shopId);
EvalShopPool evalShopPool = new EvalShopPool();
evalShopPool.setEgc(evalGroup.getEgc());
evalShopPool.setEvalGroupId(evalGroup.getId());
evalShopPool.setEvalGroupRankId(evalGroup.getEvalGroupRankId());
evalShopPool.setEvalGroupRankStageId(evalGroup.getEvalGroupRankStageId());
// evalShopPool.setEvalId(evalGroup.getEvalId());
evalShopPool.setStatus(status);
evalShopPool.setShopId(shopId);
evalShopPool.setShopName(shopDTO.getShortName());
evalShopPool.setScore(BigDecimal.ZERO);
evalShopPool.setScoreRatio(BigDecimal.ZERO);
evalShopPool.setMonthly(YearMonth.from(localDate));
evalShopPool.setReward(BigDecimal.ZERO);
evalShopPool.setGroupId(evalGroup.getGroupId());
evalShopPool.setYn(Boolean.TRUE);
evalShopPoolService.save(evalShopPool);
return evalShopPool;
}
/**
* 查询薪酬池
*
* @param user
* @return
*/
@Transactional(rollbackFor = Exception.class)
public EvalUserPool inspectionUserPool(EvalGroupUser user) {
EvalUserPool evalUserPool = evalUserPoolService.getOne(Wrappers.<EvalUserPool>lambdaQuery()
.eq(EvalUserPool::getEgc, user.getEgc())
.eq(EvalUserPool::getUserId, user.getUserId())
.eq(EvalUserPool::getMonthly, YearMonth.from(user.getDataDate()))
.eq(EvalUserPool::getYn, Boolean.TRUE)
, Boolean.FALSE);
if (PublicUtil.isNotEmpty(evalUserPool)) {
return evalUserPool;
}
evalUserPool = evalUserPoolService.getOne(Wrappers.<EvalUserPool>lambdaQuery()
.eq(EvalUserPool::getEgc, user.getEgc())
.eq(EvalUserPool::getUserId, user.getUserId())
.eq(EvalUserPool::getMonthly, YearMonth.from(user.getDataDate()).minusMonths(1))
.eq(EvalUserPool::getYn, Boolean.TRUE)
, Boolean.FALSE);
if (PublicUtil.isNotEmpty(evalUserPool)) {
evalUserPoolService.update(Wrappers.<EvalUserPool>lambdaUpdate()
.eq(EvalUserPool::getId, evalUserPool.getId())
.set(EvalUserPool::getMonthly, YearMonth.from(user.getDataDate()))
.set(EvalUserPool::getUpdateTime, new Date())
);
evalUserPool.setMonthly(YearMonth.from(user.getDataDate()));
return evalUserPool;
}
return this.createUserPoolData(user);
}
/**
* 获取员工社保公积金门店
*
* @param userId
*/
private StaffShopInfoDTO getFundShopInfo(Long userId) {
StaffBaseInfoDTO staff = ehrRpcService.queryStaffBaseInfo(userId);
if (PublicUtil.isEmpty(staff) || PublicUtil.isEmpty(staff.getStaffShopList())) {
log.error("员工没有社保公积金门店,userId:{}", userId);
}
return staff.getStaffShopList().stream()
.filter(shop -> StaffShopTypeEnum.FUND_SHOP.getValue().equals(shop.getType()))
.findFirst()
.orElse(null);
}
@Transactional(rollbackFor = Exception.class)
public EvalUserPool modifyPoolData(EvalUserPool pool, EvalGroupUser user) {
pool.setEvalGroupId(user.getEvalGroupId());
pool.setShopId(user.getShopId());
pool.setShopName(user.getShopName());
pool.setEgc(user.getEgc());
evalUserPoolService.updateById(pool);
return pool;
}
@Transactional(rollbackFor = Exception.class)
public EvalUserPool createUserPoolData(EvalGroupUser user) {
EvalUserPool evalUserPool = new EvalUserPool();
// evalUserPool.setEvalId(user.getEvalGroupRankId());
evalUserPool.setEgc(user.getEgc());
evalUserPool.setEvalGroupId(user.getEvalGroupId());
evalUserPool.setEvalGroupRankId(user.getEvalGroupRankId());
evalUserPool.setEvalGroupRankStageId(user.getEvalGroupRankStageId());
evalUserPool.setUserId(user.getUserId());
evalUserPool.setUserName(user.getUserName());
evalUserPool.setPostId(user.getPostId());
evalUserPool.setPostName(user.getPostName());
evalUserPool.setShopId(user.getShopId());
evalUserPool.setShopName(user.getShopName());
evalUserPool.setScore(BigDecimal.ZERO);
evalUserPool.setScoreRatio(BigDecimal.ZERO);
evalUserPool.setInclusion(Boolean.FALSE.equals(user.getIgnored()));
// evalUserPool.setScoreRatio(BigDecimal.ZERO);
evalUserPool.setReward(BigDecimal.ZERO);
evalUserPool.setMonthly(YearMonth.from(user.getDataDate()));
// evalUserPool.setRegular(Boolean.FALSE);
evalUserPool.setGroupId(user.getGroupId());
evalUserPool.setYn(Boolean.TRUE);
StaffShopInfoDTO staffShopInfoDTO = this.getFundShopInfo(user.getUserId());
if (PublicUtil.isNotEmpty(staffShopInfoDTO)) {
evalUserPool.setFundShopId(staffShopInfoDTO.getShopId());
evalUserPool.setFundShopName(staffShopInfoDTO.getShopName());
}
evalUserPoolService.save(evalUserPool);
return evalUserPool;
}
}