CustomEventListener.java
4.85 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
package cn.fw.valhalla.service.bus;
import cn.fw.valhalla.domain.db.ApproveRecord;
import cn.fw.valhalla.domain.db.follow.FollowTask;
import cn.fw.valhalla.domain.enums.ApproveStateEnum;
import cn.fw.valhalla.domain.enums.ApproveTypeEnum;
import cn.fw.valhalla.domain.enums.FollowTypeEnum;
import cn.fw.valhalla.domain.vo.setting.SettingVO;
import cn.fw.valhalla.rpc.flow.FlowApproveRpc;
import cn.fw.valhalla.service.bus.follow.FollowBizService;
import cn.fw.valhalla.service.bus.setting.SettingBizService;
import cn.fw.valhalla.service.data.ApproveRecordService;
import cn.fw.valhalla.service.event.*;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* @author : kurisu
* @className : CustomEventListener
* @description : 事件监听器
* @date: 2020-08-18 16:28
*/
@Component
@Slf4j
public class CustomEventListener {
private final SettingBizService settingBizService;
private final FollowBizService followBizService;
private final ApproveRecordService approveRecordService;
private final FlowApproveRpc flowApproveRpc;
@Autowired
public CustomEventListener(final SettingBizService settingBizService,
final FollowBizService followBizService,
final ApproveRecordService approveRecordService,
final FlowApproveRpc flowApproveRpc) {
this.settingBizService = settingBizService;
this.followBizService = followBizService;
this.approveRecordService = approveRecordService;
this.flowApproveRpc = flowApproveRpc;
}
/**
* 监听跟进任务取消事件
*
* @param event
*/
@EventListener(TaskCancelEvent.class)
public void onDataCancel(final TaskCancelEvent event) {
followBizService.onDataCancel(event);
}
/**
* 当设置发生改变时
*
* @param event
*/
@EventListener(SettingChangeEvent.class)
public void onSettingChange(final SettingChangeEvent event) {
final FollowTypeEnum type = event.getType();
if (Objects.isNull(type)) {
return;
}
Optional<List<SettingVO>> listOptional = Optional.ofNullable(settingBizService.querySettingByCat(type.getValue(), event.getGroupId()));
listOptional.ifPresent(settingList -> followBizService.synFollowTask(settingList, type, event.getGroupId()));
}
/**
* 档案进入公共池
*
* @param event
*/
@EventListener(PublicPoolEvent.class)
public void stopTaskAndAddPublic(final PublicPoolEvent event) {
Long getCustomerId = event.getCustomerId();
Boolean forbidden = event.getForbidden();
if (Boolean.TRUE.equals(forbidden)) {
followBizService.onForbidden(getCustomerId, event.getGroupId());
} else {
followBizService.stopTask(getCustomerId, event.getGroupId());
}
}
/**
* 终止任务
*
* @param event
*/
@EventListener(StopTaskEvent.class)
public void stopTask(final StopTaskEvent event) {
FollowTask task = event.getTask();
followBizService.stopTask(task);
}
/**
* 取消审批
*
* @param event
*/
@EventListener(CancelApproveEvent.class)
public void cancelApprove(final CancelApproveEvent event) {
Long taskId = event.getTaskId();
ApproveTypeEnum typeEnum = event.getTypeEnum();
ApproveRecord approveRecord = approveRecordService.getOne(Wrappers.<ApproveRecord>lambdaQuery()
.eq(ApproveRecord::getDataId, taskId)
.eq(ApproveRecord::getType, typeEnum)
.eq(ApproveRecord::getState, ApproveStateEnum.WAIT)
.last("limit 1")
);
if (Objects.isNull(approveRecord)) {
return;
}
//FIXME 优化项 处理审批取消失败的场景
boolean canceled = flowApproveRpc.cancel(approveRecord.getOrderNo());
approveRecord.setState(ApproveStateEnum.CANCELED);
approveRecordService.updateById(approveRecord);
}
/**
* 档案专属顾问发生改变后
*
* @param event
*/
@EventListener(CustomerDefeatedEvent.class)
public void updateTask(final CustomerDefeatedEvent event) {
Long customerId = event.getCustomerId();
FollowTypeEnum eventFollowTypeEnum = event.getFollowTypeEnum();
if (FollowTypeEnum.FM.equals(eventFollowTypeEnum)) {
followBizService.updateTask(customerId, FollowTypeEnum.RM);
} else if (FollowTypeEnum.RM.equals(eventFollowTypeEnum)) {
followBizService.updateTask(customerId, FollowTypeEnum.FM);
}
}
}