ac84063e
姜超
feature(*): 考评人员
|
1
2
3
4
|
package cn.fw.morax.server.task;
import cn.fw.common.cache.locker.DistributedLocker;
import cn.fw.morax.common.constant.TimeTaskConstant;
|
c285665c
姜超
feature(*): 考评阶段指标上报
|
5
|
import cn.fw.morax.common.utils.DateUtil;
|
ac84063e
姜超
feature(*): 考评人员
|
6
|
import cn.fw.morax.common.utils.PublicUtil;
|
c285665c
姜超
feature(*): 考评阶段指标上报
|
7
|
import cn.fw.morax.domain.bo.StageIndicatorBO;
|
8945afe5
姜超
feature(*): 考评保存修改
|
8
|
import cn.fw.morax.domain.db.eval.*;
|
c285665c
姜超
feature(*): 考评阶段指标上报
|
9
|
import cn.fw.morax.domain.db.kpi.KpiStageMqLog;
|
bc484bc4
姜超
feature(*): 定时任务发送修改
|
10
|
import cn.fw.morax.domain.enums.EvalScopeEnum;
|
ac84063e
姜超
feature(*): 考评人员
|
11
|
import cn.fw.morax.domain.enums.SettingStatusEnum;
|
c285665c
姜超
feature(*): 考评阶段指标上报
|
12
13
|
import cn.fw.morax.sdk.dto.kpi.KpiStageReportNoticeMQ;
import cn.fw.morax.service.component.KpiStageIndicatorReportProducer;
|
8945afe5
姜超
feature(*): 考评保存修改
|
14
|
import cn.fw.morax.service.data.eval.*;
|
c285665c
姜超
feature(*): 考评阶段指标上报
|
15
|
import cn.fw.morax.service.data.kpi.KpiStageMqLogService;
|
ac84063e
姜超
feature(*): 考评人员
|
16
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
ea6b2fd6
姜超
feature(*): 门店奖惩分配
|
17
|
import lombok.Getter;
|
ac84063e
姜超
feature(*): 考评人员
|
18
19
20
|
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
|
ea6b2fd6
姜超
feature(*): 门店奖惩分配
|
21
|
import org.springframework.beans.factory.annotation.Value;
|
ac84063e
姜超
feature(*): 考评人员
|
22
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
ac84063e
姜超
feature(*): 考评人员
|
23
24
25
|
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
|
c285665c
姜超
feature(*): 考评阶段指标上报
|
26
|
import org.springframework.util.CollectionUtils;
|
ac84063e
姜超
feature(*): 考评人员
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
import java.time.LocalDate;
import java.util.*;
import java.util.concurrent.locks.Lock;
import java.util.stream.Collectors;
/**
* @author : jiangchao
* @className : EvalGroupStatusTask
* @description : 考评组配置状态定时器
* @date : 2022-04-07 15:29
*/
@Component
@Slf4j
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = "task", name = "switch", havingValue = "on")
public class EvalGroupTask {
|
c285665c
姜超
feature(*): 考评阶段指标上报
|
45
|
private final EvalGroupIndicatorService evalGroupIndicatorService;
|
8945afe5
姜超
feature(*): 考评保存修改
|
46
|
private final EvalGroupRankStageService evalGroupRankStageService;
|
ffdae9fa
姜超
feature(*): 上报数据修改
|
47
|
private final EvalShopPoolService evalShopPoolService;
|
bc484bc4
姜超
feature(*): 定时任务发送修改
|
48
|
private final EvalGroupRewardDimService evalGroupRewardDimService;
|
c285665c
姜超
feature(*): 考评阶段指标上报
|
49
50
|
private final EvalGroupUserService evalGroupUserService;
private final KpiStageMqLogService kpiStageMqLogService;
|
bf5b8ef0
姜超
feature(*): 考评排名组状态
|
51
|
private final EvalGroupRankService evalGroupRankService;
|
ac84063e
姜超
feature(*): 考评人员
|
52
|
private final DistributedLocker distributedLocker;
|
8945afe5
姜超
feature(*): 考评保存修改
|
53
|
private final EvalGroupService evalGroupService;
|
c285665c
姜超
feature(*): 考评阶段指标上报
|
54
|
private final KpiStageIndicatorReportProducer kpiStageIndicatorReportProducer;
|
ac84063e
姜超
feature(*): 考评人员
|
55
|
|
7d59a85e
姜超
feature(*): redis...
|
56
|
@Value("${spring.cache.custom.global-prefix}:eval:group")
|
ea6b2fd6
姜超
feature(*): 门店奖惩分配
|
57
|
@Getter
|
7d59a85e
姜超
feature(*): redis...
|
58
|
private String evalGroupDistKey;
|
bf5b8ef0
姜超
feature(*): 考评排名组状态
|
59
60
61
|
@Value("${spring.cache.custom.global-prefix}:eval:group:rank")
@Getter
private String evalGroupRankKey;
|
ac84063e
姜超
feature(*): 考评人员
|
62
63
|
/**
|
c285665c
姜超
feature(*): 考评阶段指标上报
|
64
|
* 发送业务上报mq通知
|
ac84063e
姜超
feature(*): 考评人员
|
65
|
*/
|
c285665c
姜超
feature(*): 考评阶段指标上报
|
66
67
68
69
70
71
72
73
|
@Scheduled(cron = TimeTaskConstant.EVAL_GROUP_REPORT_MQ)
public void sendNotice() {
final String lockKey = ":kpiSendNotice";
Lock lock = distributedLocker.lock(lockKey);
if (((RLock) lock).isLocked()) {
LocalDate lastDate = LocalDate.now().minusDays(1);
List<StageIndicatorBO> evalGroupRankStages = evalGroupIndicatorService.getStageIndicators(lastDate);
if (CollectionUtils.isEmpty(evalGroupRankStages)) {
|
eccb0d64
姜超
feature(*): 考评详情查询
|
74
75
|
return;
}
|
c285665c
姜超
feature(*): 考评阶段指标上报
|
76
77
78
79
80
|
for (StageIndicatorBO stageIndicator : evalGroupRankStages) {
try {
sendNotice(stageIndicator, lastDate);
} catch (Exception e) {
log.error("发送绩效阶段上报mq失败: [{}]", stageIndicator, e);
|
f946d0a5
姜超
feature(*): 考评定时任务
|
81
82
|
}
}
|
ac84063e
姜超
feature(*): 考评人员
|
83
84
|
lock.unlock();
}
|
ac84063e
姜超
feature(*): 考评人员
|
85
86
|
}
|
bf5b8ef0
姜超
feature(*): 考评排名组状态
|
87
|
/**
|
c285665c
姜超
feature(*): 考评阶段指标上报
|
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
* 发送绩效数据上报mq
*
* @param localDate
*/
@Transactional(rollbackFor = Exception.class)
public void sendNotice(StageIndicatorBO stageIndicator, final LocalDate localDate) {
KpiStageMqLog mqLog = new KpiStageMqLog();
mqLog.setIndicatorCode(stageIndicator.getIndicatorCode());
mqLog.setBeginTime(stageIndicator.getBeginTime());
mqLog.setEndTime(localDate);
mqLog.setEvalGroupId(stageIndicator.getEvalGroupId());
mqLog.setEvalGroupRankId(stageIndicator.getEvalGroupRankId());
mqLog.setGroupId(stageIndicator.getGroupId());
List<EvalGroupUser> users = evalGroupUserService.list(Wrappers.<EvalGroupUser>lambdaQuery()
.eq(EvalGroupUser::getEvalGroupId, stageIndicator.getEvalGroupId())
.eq(EvalGroupUser::getDataDate, localDate)
.eq(EvalGroupUser::getYn, Boolean.TRUE)
);
List<Long> userIds = users.stream().map(EvalGroupUser::getUserId).distinct().collect(Collectors.toList());
|
bc484bc4
姜超
feature(*): 定时任务发送修改
|
107
108
109
110
111
112
113
114
|
List<EvalGroupRewardDim> rewardDims = evalGroupRewardDimService.list(Wrappers.<EvalGroupRewardDim>lambdaQuery()
.eq(EvalGroupRewardDim::getEvalGroupId, stageIndicator.getEvalGroupId())
.eq(EvalGroupRewardDim::getType, EvalScopeEnum.SHOP)
.eq(EvalGroupRewardDim::getYn, Boolean.TRUE)
);
List<Long> shopIds = rewardDims.stream().flatMap(dim -> dim.getShopIds().stream()).distinct().collect(Collectors.toList());
if (PublicUtil.isEmpty(userIds) && PublicUtil.isEmpty(shopIds)) {
|
c285665c
姜超
feature(*): 考评阶段指标上报
|
115
116
117
118
119
120
121
|
return;
}
mqLog.setShopIds(shopIds);
mqLog.setUserIds(userIds);
kpiStageMqLogService.save(mqLog);
kpiStageIndicatorReportProducer.send(KpiStageReportNoticeMQ.builder()
|
f727712b
姜超
feature(*): 考评阶段指标上报
|
122
|
.indicatorCode(stageIndicator.getIndicatorCode())
|
c285665c
姜超
feature(*): 考评阶段指标上报
|
123
124
125
126
127
128
129
130
131
|
.beginTime(DateUtil.localDateTime2Date(mqLog.getBeginTime().atTime(0,0,1)))
.endTime(DateUtil.localDateTime2Date(mqLog.getEndTime().atTime(23,59,59)))
.shopIds(mqLog.getShopIds())
.userIds(mqLog.getUserIds())
.uid(mqLog.getId().toString())
.build());
}
/**
|
bf5b8ef0
姜超
feature(*): 考评排名组状态
|
132
133
134
135
136
137
138
139
140
141
|
* 每月考评排名组配置状态改变
*/
@Scheduled(cron = TimeTaskConstant.EVAL_GROUP_RANK_STATUS)
@Transactional(rollbackFor = Exception.class)
public void processCurMonthRanks() {
Lock lock = distributedLocker.lock(getEvalGroupRankKey());
if (! ((RLock) lock).isLocked()) {
return;
}
try {
|
bf5b8ef0
姜超
feature(*): 考评排名组状态
|
142
143
|
LocalDate currentTime = LocalDate.now();
List<EvalGroupRank> evalGroupRanks = evalGroupRankService.list(Wrappers.<EvalGroupRank>lambdaQuery()
|
da2a6e7c
姜超
feature(*): 考评数据抽取修改
|
144
|
.eq(EvalGroupRank::getStatus, SettingStatusEnum.EFFECTIVE)
|
bf5b8ef0
姜超
feature(*): 考评排名组状态
|
145
146
147
148
149
|
.eq(EvalGroupRank::getYn, Boolean.TRUE)
);
if (PublicUtil.isEmpty(evalGroupRanks)) {
return;
}
|
8945afe5
姜超
feature(*): 考评保存修改
|
150
151
152
153
154
155
156
157
158
159
160
161
|
List<EvalGroupRank> ineffectiveRanks = new ArrayList<>();
for (EvalGroupRank evalGroupRank : evalGroupRanks) {
List<EvalGroupRankStage> stages = evalGroupRankStageService.list(Wrappers.<EvalGroupRankStage>lambdaQuery()
.eq(EvalGroupRankStage::getEvalGroupRankId, evalGroupRank.getId())
.eq(EvalGroupRankStage::getYn, Boolean.TRUE)
);
Boolean effective = stages.stream()
.filter(evalGroup -> evalGroup.getOverTime().isBefore(currentTime)).findFirst().isPresent();
if (! effective) {
evalGroupRank.setStatus(SettingStatusEnum.INEFFECTIVE);
ineffectiveRanks.add(evalGroupRank);
}
|
bf5b8ef0
姜超
feature(*): 考评排名组状态
|
162
|
}
|
bf5b8ef0
姜超
feature(*): 考评排名组状态
|
163
164
165
166
167
168
|
} catch (Exception e){
log.error(e.getMessage(), e);
} finally {
lock.unlock();
}
}
|
ac84063e
姜超
feature(*): 考评人员
|
169
170
|
}
|