CallReportConsumer.java
2.72 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
package cn.fw.valhalla.component;
import cn.fw.pstn.sdk.enums.DialTypeEnum;
import cn.fw.pstn.sdk.mq.CallReport;
import cn.fw.valhalla.common.utils.StringUtils;
import cn.fw.valhalla.domain.dto.CallReportDTO;
import cn.fw.valhalla.domain.enums.CallTypeEnum;
import cn.fw.valhalla.rpc.ehr.EhrRpcService;
import cn.fw.valhalla.rpc.ehr.dto.StaffInfoDTO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import java.util.Objects;
/**
* 监听关注公众号mq
*
* @author kurisu
*/
@Slf4j
@Component
@RocketMQMessageListener(topic = "call_report", consumerGroup = "${spring.application.name}" + "-call_report")
public class CallReportConsumer implements RocketMQListener<CallReport> {
private final StringRedisTemplate redisTemplate;
private final EhrRpcService ehrRpcService;
@Value("${spring.cache.custom.global-prefix}:mq:call:report")
@Getter
private String callReportKey;
@Autowired
public CallReportConsumer(final StringRedisTemplate redisTemplate,
final EhrRpcService ehrRpcService) {
this.redisTemplate = redisTemplate;
this.ehrRpcService = ehrRpcService;
}
@Override
public void onMessage(CallReport t) {
log.info("监听通话记录mq: CallReport=[{}]", t);
try {
if (Objects.isNull(t)) {
return;
}
CallReportDTO dto = new CallReportDTO();
BeanUtils.copyProperties(t, dto);
dto.setDialType(CallTypeEnum.CALL);
if (DialTypeEnum.P_CALL.equals(t.getCallType())) {
dto.setDialType(CallTypeEnum.P_CALL);
}
String staffMobile = t.getStaffMobile();
if (StringUtils.isEmpty(staffMobile)) {
return;
}
StaffInfoDTO info = ehrRpcService.queryStaffInfoByMobile(staffMobile);
if (Objects.nonNull(info)) {
dto.setStaffId(info.getId());
dto.setStaffName(info.getName());
dto.setGroupId(info.getGroupId());
}
redisTemplate.opsForList().rightPush(getCallReportKey(), JSONObject.toJSONString(dto));
} catch (Exception ex) {
log.error("消费通话记录mq失败,原因:{}", JSON.toJSONString(ex));
}
}
}