Commit c6ea42b42c8bc19bf6e3e67584c8727502302604

Authored by 张志伟
1 parent 7fe573d9

feature(*): 新增线索结束的通知mq

- 新增线索结束的通知mq
- 升级sdk
fw-valhalla-sdk/pom.xml
... ... @@ -10,7 +10,7 @@
10 10 <relativePath>../pom.xml</relativePath>
11 11 </parent>
12 12 <artifactId>fw-valhalla-sdk</artifactId>
13   - <version>1.2.3</version>
  13 + <version>1.2.4</version>
14 14 <packaging>jar</packaging>
15 15 <name>fw-valhalla-sdk</name>
16 16  
... ...
fw-valhalla-sdk/src/main/java/cn/fw/valhalla/sdk/result/ClueChangeResult.java 0 → 100644
  1 +package cn.fw.valhalla.sdk.result;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import java.util.Objects;
  6 +
  7 +/**
  8 + * 线索改变信息
  9 + *
  10 + * @author : kurisu
  11 + * @version : 1.0
  12 + * @className : ClueChangeResult
  13 + * @description : 线索改变信息
  14 + * @date : 2022-12-06 16:13
  15 + */
  16 +@Data
  17 +public class ClueChangeResult {
  18 + public final static String TOPIC = "Follow_Clue_Change";
  19 + /**
  20 + * 车架号
  21 + */
  22 + private String frameNo;
  23 + /**
  24 + * 保有客跟进类型
  25 + *
  26 + * @see cn.fw.valhalla.sdk.enums.CustomerFollowTypeEnum
  27 + */
  28 + private Integer clueType;
  29 + /**
  30 + * 变更类型
  31 + */
  32 + private ChangeType changeType;
  33 +
  34 + /**
  35 + * 新开始的线索
  36 + *
  37 + * @return boolean
  38 + */
  39 + public boolean isNewStartClue() {
  40 + if (Objects.isNull(changeType)) {
  41 + return Boolean.FALSE;
  42 + }
  43 + return ChangeType.ADD.equals(changeType);
  44 + }
  45 +
  46 + /**
  47 + * 中途终止的线索
  48 + *
  49 + * @return boolean
  50 + */
  51 + public boolean isStopClue() {
  52 + if (Objects.isNull(changeType)) {
  53 + return Boolean.FALSE;
  54 + }
  55 + return ChangeType.STOP.equals(changeType);
  56 + }
  57 +
  58 + public enum ChangeType {
  59 + ADD,
  60 + STOP
  61 + }
  62 +}
... ...
fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/task/ClueChangeNoticeTask.java 0 → 100644
  1 +package cn.fw.valhalla.controller.task;
  2 +
  3 +import cn.fw.valhalla.component.ClueChangeProducer;
  4 +import cn.fw.valhalla.domain.db.follow.FollowClue;
  5 +import cn.fw.valhalla.domain.enums.FollowTypeEnum;
  6 +import cn.fw.valhalla.sdk.enums.CustomerFollowTypeEnum;
  7 +import cn.fw.valhalla.sdk.result.ClueChangeResult;
  8 +import cn.fw.valhalla.service.data.FollowClueService;
  9 +import lombok.Getter;
  10 +import lombok.extern.slf4j.Slf4j;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.beans.factory.annotation.Value;
  13 +import org.springframework.data.redis.core.StringRedisTemplate;
  14 +import org.springframework.scheduling.annotation.Scheduled;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +import java.util.Objects;
  18 +import java.util.concurrent.CompletableFuture;
  19 +
  20 +/**
  21 + * 线索变更后的通知事件
  22 + *
  23 + * @author : kurisu
  24 + * @version : 1.0
  25 + * @className : ClueChangeNoticeTask
  26 + * @description : 线索变更后的通知事件
  27 + * @date : 2022-12-07 11:45
  28 + */
  29 +@Component
  30 +@Slf4j
  31 +//@ConditionalOnProperty(prefix = "task", name = "switch", havingValue = "on")
  32 +public class ClueChangeNoticeTask {
  33 + private final ClueChangeProducer clueChangeProducer;
  34 + private final FollowClueService followClueService;
  35 + private final StringRedisTemplate redisTemplate;
  36 + @Value("${spring.cache.custom.global-prefix}:follow:clue:change")
  37 + @Getter
  38 + private String clueChangeKeyPrefix;
  39 +
  40 + @Autowired
  41 + public ClueChangeNoticeTask(final ClueChangeProducer clueChangeProducer,
  42 + final FollowClueService followClueService,
  43 + final StringRedisTemplate redisTemplate) {
  44 + this.clueChangeProducer = clueChangeProducer;
  45 + this.followClueService = followClueService;
  46 + this.redisTemplate = redisTemplate;
  47 + }
  48 +
  49 + @Scheduled(initialDelay = 1000 * 30, fixedRate = 1000 * 60)
  50 + public void sendStopNotice() {
  51 + String pop = null;
  52 + while ((pop = redisTemplate.opsForSet().pop(generateStopKey())) != null) {
  53 + try {
  54 + final Long clueId = Long.valueOf(pop);
  55 + CompletableFuture.runAsync(() -> {
  56 + FollowClue clue = followClueService.getById(clueId);
  57 + if (Objects.nonNull(clue)) {
  58 +
  59 + ClueChangeResult result = new ClueChangeResult();
  60 + result.setFrameNo(clue.getVin());
  61 + result.setChangeType(ClueChangeResult.ChangeType.STOP);
  62 + if (FollowTypeEnum.RM.equals(clue.getClueType())) {
  63 + result.setClueType(CustomerFollowTypeEnum.RM.getValue());
  64 + } else if (FollowTypeEnum.IR.equals(clue.getClueType())) {
  65 + result.setClueType(CustomerFollowTypeEnum.IR.getValue());
  66 + }
  67 + clueChangeProducer.send(result);
  68 + }
  69 + });
  70 + } catch (Exception ex) {
  71 + log.error(ex.getMessage(), ex);
  72 + }
  73 + }
  74 + }
  75 +
  76 + private String generateAddKey() {
  77 + return String.format("%s:%s", getClueChangeKeyPrefix(), "ADD");
  78 + }
  79 +
  80 + private String generateStopKey() {
  81 + return String.format("%s:%s", getClueChangeKeyPrefix(), "STOP");
  82 + }
  83 +}
... ...
fw-valhalla-service/src/main/java/cn/fw/valhalla/component/ClueChangeProducer.java 0 → 100644
  1 +package cn.fw.valhalla.component;
  2 +
  3 +import cn.fw.valhalla.sdk.result.ClueChangeResult;
  4 +import lombok.extern.slf4j.Slf4j;
  5 +import org.apache.rocketmq.spring.core.RocketMQTemplate;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.stereotype.Component;
  8 +import org.springframework.web.bind.annotation.RequestMapping;
  9 +
  10 +/**
  11 + * @author kurisu
  12 + */
  13 +@Slf4j
  14 +@Component
  15 +public class ClueChangeProducer {
  16 + @Autowired
  17 + private RocketMQTemplate rocketMQTemplate;
  18 +
  19 + @RequestMapping(value = "send")
  20 + public void send(ClueChangeResult clueChangeResult) {
  21 + try {
  22 + log.info("售后跟进线索变更mq: body:[{}]", clueChangeResult);
  23 + rocketMQTemplate.syncSend(ClueChangeResult.TOPIC + ":*", clueChangeResult);
  24 + } catch (Exception e) {
  25 + e.printStackTrace();
  26 + }
  27 + }
  28 +}
0 29 \ No newline at end of file
... ...
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/follow/strategy/AbstractFollowStrategy.java
... ... @@ -39,6 +39,7 @@ import lombok.extern.slf4j.Slf4j;
39 39 import org.springframework.beans.BeanUtils;
40 40 import org.springframework.beans.factory.annotation.Autowired;
41 41 import org.springframework.beans.factory.annotation.Value;
  42 +import org.springframework.data.redis.core.StringRedisTemplate;
42 43 import org.springframework.transaction.annotation.Transactional;
43 44 import org.springframework.util.CollectionUtils;
44 45  
... ... @@ -86,26 +87,26 @@ public abstract class AbstractFollowStrategy implements FollowStrategy {
86 87 protected EhrRpcService ehrRpcService;
87 88 @Autowired
88 89 protected MemberRpcService memberRpcService;
89   -
  90 + @Autowired
  91 + protected StringRedisTemplate redisTemplate;
90 92 @Value("${spring.cache.custom.global-prefix}:follow")
91 93 @Getter
92 94 private String keyPrefix;
93   -
94 95 @Value("${follow.todo.FMCode}")
95 96 @Getter
96 97 private String FMCode;
97   -
98 98 @Value("${follow.todo.RMCode}")
99 99 @Getter
100 100 private String RMCode;
101   -
102 101 @Value("${follow.todo.IRCode}")
103 102 @Getter
104 103 private String IRCode;
105   -
106 104 @Value("${follow.todo.ACCode}")
107 105 @Getter
108 106 private String ACCode;
  107 + @Value("${spring.cache.custom.global-prefix}:follow:clue:change")
  108 + @Getter
  109 + private String clueChangeKeyPrefix;
109 110  
110 111  
111 112 /**
... ... @@ -208,6 +209,7 @@ public abstract class AbstractFollowStrategy implements FollowStrategy {
208 209 clue.setCloseTime(task.getCloseTime());
209 210 clue.setClueState(ClueStatusEnum.FAILURE);
210 211 followClueService.updateById(clue);
  212 + redisTemplate.opsForSet().add(generateStopKey(), String.valueOf(clueId));
211 213 customerBizService.taskEndAbandon(task, clue);
212 214 } else {
213 215 createSecondaryTask(clue, task);
... ... @@ -254,6 +256,7 @@ public abstract class AbstractFollowStrategy implements FollowStrategy {
254 256 clue.setCloseTime(task.getCloseTime());
255 257 clue.setClueState(ClueStatusEnum.FAILURE);
256 258 followClueService.updateById(clue);
  259 + redisTemplate.opsForSet().add(generateStopKey(), String.valueOf(clueId));
257 260 } else {
258 261 createSecondaryTask(clue, adviserId);
259 262 }
... ... @@ -266,6 +269,7 @@ public abstract class AbstractFollowStrategy implements FollowStrategy {
266 269 clue.setClueState(ClueStatusEnum.FAILURE);
267 270 clue.setCloseTime(LocalDateTime.now());
268 271 followClueService.updateById(clue);
  272 + redisTemplate.opsForSet().add(generateStopKey(), String.valueOf(clue.getId()));
269 273 ClueTask task = clueTaskService.queryOngoingTaskByClueId(clue.getId());
270 274 if (Objects.isNull(task)) {
271 275 return;
... ... @@ -293,6 +297,7 @@ public abstract class AbstractFollowStrategy implements FollowStrategy {
293 297 clue.setClueState(ClueStatusEnum.FAILURE);
294 298 clue.setCloseTime(LocalDateTime.now());
295 299 followClueService.updateById(clue);
  300 + redisTemplate.opsForSet().add(generateStopKey(), String.valueOf(clueId));
296 301 }
297 302 }
298 303  
... ... @@ -499,7 +504,6 @@ public abstract class AbstractFollowStrategy implements FollowStrategy {
499 504 followNoticeRecordService.updateBatchById(noticeList);
500 505 }
501 506  
502   -
503 507 /**
504 508 * 线索成交
505 509 *
... ... @@ -865,4 +869,12 @@ public abstract class AbstractFollowStrategy implements FollowStrategy {
865 869 followClueService.updateById(clue);
866 870 clueTaskService.save(redistributionTask);
867 871 }
  872 +
  873 + protected String generateAddKey() {
  874 + return String.format("%s:%s", getClueChangeKeyPrefix(), "ADD");
  875 + }
  876 +
  877 + protected String generateStopKey() {
  878 + return String.format("%s:%s", getClueChangeKeyPrefix(), "STOP");
  879 + }
868 880 }
... ...
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/follow/strategy/impl/IRFollowStrategy.java
... ... @@ -122,6 +122,7 @@ public class IRFollowStrategy extends AbstractFollowStrategy {
122 122 clue.setClueState(ClueStatusEnum.FAILURE);
123 123 clue.setCloseTime(task.getCloseTime());
124 124 followClueService.updateById(clue);
  125 + redisTemplate.opsForSet().add(generateStopKey(), String.valueOf(clueId));
125 126 afterStopClue(clue);
126 127 }
127 128 clueTaskService.updateById(task);
... ... @@ -153,6 +154,7 @@ public class IRFollowStrategy extends AbstractFollowStrategy {
153 154 clue.setCloseTime(task.getCloseTime());
154 155 followClueService.updateById(clue);
155 156 afterStopClue(clue);
  157 + redisTemplate.opsForSet().add(generateStopKey(), String.valueOf(clueId));
156 158 }
157 159 clueTaskService.updateById(task);
158 160 if (Objects.nonNull(clue) && !redistribution) {
... ... @@ -176,6 +178,7 @@ public class IRFollowStrategy extends AbstractFollowStrategy {
176 178 clue.setCloseTime(LocalDateTime.now());
177 179 followClueService.updateById(clue);
178 180 afterStopClue(clue);
  181 + redisTemplate.opsForSet().add(generateStopKey(), String.valueOf(clueId));
179 182 }
180 183 }
181 184  
... ...
... ... @@ -118,7 +118,7 @@
118 118 <dependency>
119 119 <groupId>cn.fw</groupId>
120 120 <artifactId>fw-valhalla-sdk</artifactId>
121   - <version>1.2.3</version>
  121 + <version>1.2.4</version>
122 122 </dependency>
123 123 <dependency>
124 124 <groupId>cn.fw</groupId>
... ...