FlowConsumer.java
4.92 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
package cn.fw.valhalla.component;
import cn.fw.flow.enums.ApproveResultEnum;
import cn.fw.flow.result.ApproveCheckMessageDto;
import cn.fw.valhalla.domain.db.ApproveRecord;
import cn.fw.valhalla.domain.db.follow.FollowRecord;
import cn.fw.valhalla.domain.db.follow.FollowTask;
import cn.fw.valhalla.domain.enums.ApproveStateEnum;
import cn.fw.valhalla.domain.enums.FollowTypeEnum;
import cn.fw.valhalla.domain.enums.TaskStateEnum;
import cn.fw.valhalla.service.bus.cust.CustomerBizService;
import cn.fw.valhalla.service.bus.cust.CustomerChangeBizService;
import cn.fw.valhalla.service.bus.follow.FollowBizService;
import cn.fw.valhalla.service.data.ApproveRecordService;
import cn.fw.valhalla.service.data.FollowRecordService;
import cn.fw.valhalla.service.data.FollowTaskService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Objects;
/**
* @author : kurisu
* Date: 2020/9/16
* Time: 10:57
* Description:
*/
@Slf4j
@Service
@RocketMQMessageListener(topic = "flow_approval_result", consumerGroup = "${spring.application.name}_flow_approval_result")
public class FlowConsumer implements RocketMQListener<ApproveCheckMessageDto> {
private final CustomerChangeBizService customerChangeBizService;
private final CustomerBizService customerBizService;
private final ApproveRecordService approveRecordService;
private final FollowTaskService followTaskService;
private final FollowRecordService followRecordService;
private final FollowBizService followBizService;
@Autowired
public FlowConsumer(final CustomerChangeBizService customerChangeBizService,
final CustomerBizService customerBizService,
final ApproveRecordService approveRecordService,
final FollowTaskService followTaskService,
final FollowRecordService followRecordService,
final FollowBizService followBizService) {
this.customerChangeBizService = customerChangeBizService;
this.customerBizService = customerBizService;
this.approveRecordService = approveRecordService;
this.followTaskService = followTaskService;
this.followRecordService = followRecordService;
this.followBizService = followBizService;
}
@Override
public void onMessage(ApproveCheckMessageDto dto) {
log.info("审批系统MQ消息回调:{}", JSONObject.toJSONString(dto));
try {
ApproveRecord record = approveRecordService.getByOrderNo(dto.getOrderNo());
if (Objects.isNull(record)) {
return;
}
if (ApproveResultEnum.PENDING.getCode().equals(dto.getState())) {
return;
}
if (ApproveResultEnum.PASS.getCode().equals(dto.getState())) {
record.setPassed(Boolean.TRUE);
doChangeCustomer(record.getDataId());
}
record.setState(ApproveStateEnum.DONE);
approveRecordService.updateById(record);
} catch (Exception e) {
log.error("审批系统回调处理异常", e);
}
}
@Transactional(rollbackFor = Exception.class)
public void doChangeCustomer(Long taskId) {
FollowTask task = followTaskService.getById(taskId);
if (Objects.isNull(task) || TaskStateEnum.END.equals(task.getState())) {
return;
}
if (task.getChanged()) {
task.setState(TaskStateEnum.END);
customerBizService.abandon(task);
followTaskService.updateById(task);
return;
}
if (FollowTypeEnum.AC.equals(task.getType())) {
task.setState(TaskStateEnum.END);
task.setFinished(Boolean.FALSE);
followTaskService.updateById(task);
return;
}
if (FollowTypeEnum.IR.equals(task.getType())) {
customerChangeBizService.changeInsFollowUser(task);
return;
}
customerChangeBizService.changeFollowUser(task);
List<FollowRecord> list = followRecordService.list(Wrappers.<FollowRecord>lambdaQuery()
.eq(FollowRecord::getTaskId, taskId)
.eq(FollowRecord::getOutTime, Boolean.FALSE)
.isNotNull(FollowRecord::getFollowTime)
.eq(FollowRecord::getAddTodo, Boolean.TRUE)
);
if (!CollectionUtils.isEmpty(list)) {
for (FollowRecord record : list) {
followBizService.completeRecord2(record);
}
}
}
}