Commit bad8a098b958f9236615880cac522bb0f75335ba

Authored by 张志伟
1 parent 9612b098

新增手动运维的接口

fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/app/CommonController.java
... ... @@ -25,6 +25,7 @@ import java.time.LocalDateTime;
25 25 import java.time.ZoneId;
26 26 import java.util.Date;
27 27 import java.util.List;
  28 +import java.util.Objects;
28 29  
29 30 import static cn.fw.common.web.util.ResultBuilder.success;
30 31  
... ... @@ -108,10 +109,22 @@ public class CommonController {
108 109 return success();
109 110 }
110 111  
111   - @PutMapping("/create/next-clue")
  112 + @PutMapping("/clue/manual/create")
112 113 @Authorization(AuthType.NONE)
113   - @ControllerMethod("处理过期续保")
114   - public Message<Integer> createNextClue() {
115   - return success(commonService.createClue());
  114 + @ControllerMethod("处理续保数据缺失")
  115 + public Message<Integer> createNextClue(Long groupId) {
  116 + if (Objects.isNull(groupId)) {
  117 + groupId = 2L;
  118 + }
  119 + commonService.createClue(groupId);
  120 + return success();
  121 + }
  122 +
  123 + @PutMapping("/clue/manual/start")
  124 + @Authorization(AuthType.NONE)
  125 + @ControllerMethod("手动开始任务")
  126 + public Message<Integer> manualStartClue() {
  127 + commonService.startClue();
  128 + return success();
116 129 }
117 130 }
... ...
fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/task/FollowTaskDealTask.java
... ... @@ -48,7 +48,7 @@ public class FollowTaskDealTask {
48 48 public void startClue() {
49 49 List<FollowClue> list = followClueService.list(Wrappers.<FollowClue>lambdaQuery()
50 50 .eq(FollowClue::getClueState, ClueStatusEnum.WAITING)
51   - .ge(FollowClue::getStartTime, DateUtil.localDateTime2Date(LocalDate.now().atStartOfDay()))
  51 + .ge(FollowClue::getStartTime, DateUtil.localDateTime2Date(LocalDate.now().minusDays(1L).atTime(23, 59, 59)))
52 52 .le(FollowClue::getStartTime, DateUtil.localDateTime2Date(LocalDateTime.now()))
53 53 .last("limit 0, 500")
54 54 );
... ...
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/CommonService.java
... ... @@ -3,35 +3,40 @@ package cn.fw.valhalla.service.bus;
3 3 import cn.fw.common.util.ValidationUtils;
4 4 import cn.fw.valhalla.common.constant.RoleCode;
5 5 import cn.fw.valhalla.common.utils.DateUtil;
  6 +import cn.fw.valhalla.domain.db.OriginalData;
6 7 import cn.fw.valhalla.domain.db.customer.AccidentPool;
7 8 import cn.fw.valhalla.domain.db.customer.Customer;
8 9 import cn.fw.valhalla.domain.db.customer.CustomerBaseInfo;
9   -import cn.fw.valhalla.domain.db.pool.CustomerCluePool;
  10 +import cn.fw.valhalla.domain.db.follow.FollowClue;
10 11 import cn.fw.valhalla.domain.db.pool.StammkundePool;
11 12 import cn.fw.valhalla.domain.enums.ClueStatusEnum;
12 13 import cn.fw.valhalla.domain.enums.FollowTypeEnum;
  14 +import cn.fw.valhalla.domain.enums.SettingTypeEnum;
13 15 import cn.fw.valhalla.domain.enums.StammkundeStatusEnum;
14 16 import cn.fw.valhalla.domain.vo.PostUserVO;
  17 +import cn.fw.valhalla.domain.vo.setting.SettingVO;
15 18 import cn.fw.valhalla.rpc.ehr.EhrRpcService;
16 19 import cn.fw.valhalla.rpc.ehr.dto.StaffInfoDTO;
17 20 import cn.fw.valhalla.rpc.erp.UserService;
18 21 import cn.fw.valhalla.rpc.erp.dto.PostUserDTO;
19 22 import cn.fw.valhalla.rpc.pstn.PstnService;
  23 +import cn.fw.valhalla.sdk.enums.DataTypeEnum;
20 24 import cn.fw.valhalla.service.bus.cust.CustomerChangeBizService;
  25 +import cn.fw.valhalla.service.bus.follow.FollowBizService;
  26 +import cn.fw.valhalla.service.bus.setting.SettingBizService;
21 27 import cn.fw.valhalla.service.data.*;
  28 +import cn.hutool.core.collection.ListUtil;
  29 +import cn.hutool.core.map.MapUtil;
22 30 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
23 31 import lombok.RequiredArgsConstructor;
24 32 import lombok.extern.slf4j.Slf4j;
25   -import org.springframework.beans.BeanUtils;
26 33 import org.springframework.stereotype.Service;
27 34 import org.springframework.transaction.annotation.Transactional;
28 35 import org.springframework.util.CollectionUtils;
29 36  
30 37 import java.time.LocalDate;
31   -import java.util.ArrayList;
32   -import java.util.List;
33   -import java.util.Objects;
34   -import java.util.Random;
  38 +import java.time.LocalDateTime;
  39 +import java.util.*;
35 40  
36 41 import static cn.fw.common.businessvalidator.Validator.BV;
37 42  
... ... @@ -53,7 +58,20 @@ public class CommonService {
53 58 private final EhrRpcService ehrRpcService;
54 59 private final AccidentPoolService accidentPoolService;
55 60 private final CustomerChangeBizService customerChangeBizService;
56   - private final CustomerCluePoolService customerCluePoolService;
  61 + private final FollowClueService followClueService;
  62 + private final FollowBizService followBizService;
  63 + private final OriginalDataService originalDataService;
  64 + private final SettingBizService settingBizService;
  65 + Map<Long, List<Integer>> map = MapUtil.builder(new HashMap<Long, List<Integer>>())
  66 + .put(-1L, ListUtil.toList(67, 65, 66))
  67 + .put(28L, ListUtil.toList(67, 70, 79, 66, 65, 73, 69))
  68 + .put(29L, ListUtil.toList(79, 69, 66, 70, 65, 73, 147, 67))
  69 + .put(30L, ListUtil.toList(67))
  70 + .put(59L, ListUtil.toList(161, 159, 66))
  71 + .put(148L, ListUtil.toList(159))
  72 + .put(175L, ListUtil.toList(67))
  73 + .put(180L, ListUtil.toList(66, 67, 79, 65, 70, 69))
  74 + .build();
57 75  
58 76  
59 77 public List<PostUserVO> getUsers(final Long shopId) {
... ... @@ -121,89 +139,111 @@ public class CommonService {
121 139 return virtualNumber;
122 140 }
123 141  
124   - @Transactional(rollbackFor = Exception.class)
125   - public int createClue() {
126   - List<CustomerCluePool> list = customerCluePoolService.list(Wrappers.<CustomerCluePool>lambdaQuery()
127   - .eq(CustomerCluePool::getClueType, FollowTypeEnum.IR)
128   - .in(CustomerCluePool::getClueStatus, ClueStatusEnum.FAILURE, ClueStatusEnum.COMPLETE)
129   - .lt(CustomerCluePool::getUpdateTime, DateUtil.localDate2Date(LocalDate.now()))
130   - .ne(CustomerCluePool::getGroupId, 1L)
131   - .last(" limit 2000")
  142 + /**
  143 + * 手动开始任务
  144 + */
  145 + public void startClue() {
  146 + List<FollowClue> list = followClueService.list(Wrappers.<FollowClue>lambdaQuery()
  147 + .eq(FollowClue::getClueState, ClueStatusEnum.WAITING)
  148 + .le(FollowClue::getStartTime, DateUtil.localDateTime2Date(LocalDateTime.now()))
  149 + .last("limit 0, 2000")
132 150 );
133 151 if (CollectionUtils.isEmpty(list)) {
134   - return 0;
  152 + return;
  153 + }
  154 + for (FollowClue cluePool : list) {
  155 + followBizService.startClue(cluePool);
135 156 }
  157 + }
136 158  
137   - Long[] shopArr = new Long[]{65L, 66L, 67L};
138   - String[] shopNameArr = new String[]{"宁夏瑞静售后店", "宁夏翔之星售后店", "贺兰捷联售后店"};
139   -
140   - for (int i = 0; i < list.size(); i++) {
141   - CustomerCluePool pool = list.get(i);
142   - Long customerId = pool.getRefererId();
143   - int count = customerCluePoolService.count(Wrappers.<CustomerCluePool>lambdaQuery()
144   - .eq(CustomerCluePool::getClueType, FollowTypeEnum.IR)
145   - .eq(CustomerCluePool::getRefererId, customerId)
146   - .in(CustomerCluePool::getClueStatus, ClueStatusEnum.WAITING, ClueStatusEnum.ONGOING));
147   - if (count > 0) {
148   - continue;
149   - }
150   - Customer customer = customerService.queryById(customerId);
151   - if (Objects.isNull(customer)) {
152   - continue;
153   - }
154   - Long shopId = pool.getOriginalShopId();
155   - String shopName = pool.getOriginalShopName();
156   - if (Long.valueOf(146L).equals(shopId)) {
157   - shopId = shopArr[i % 3];
158   - shopName = shopNameArr[i % 3];
159   - }
160   - CustomerCluePool customerCluePool = new CustomerCluePool();
161   - List<PostUserDTO> dtoList = userService.getUserByRole(shopId, RoleCode.XBGJ);
162   - BV.isNotEmpty(dtoList, "门店[" + shopId + "]没有续保跟进人员");
163   - int index = new Random().nextInt(dtoList.size());
164   - PostUserDTO userDTO = dtoList.get(index);
165   - BeanUtils.copyProperties(pool, customerCluePool);
166   - customerCluePool.setId(null);
167   - customerCluePool.setOriginalUserId(userDTO.getUserId());
168   - customerCluePool.setOriginalUserName(userDTO.getUserName());
169   - customerCluePool.setOriginalShopId(shopId);
170   - customerCluePool.setOriginalShopName(shopName);
171   - customerCluePool.setClueStatus(ClueStatusEnum.WAITING);
172   - customerCluePool.setRedistribution(Boolean.FALSE);
173   - customerCluePool.setClueType(FollowTypeEnum.IR);
174   - customerCluePool.setFinishShopId(null);
175   - customerCluePool.setFinishShopName(null);
176   - customerCluePool.setFinishUserId(null);
177   - customerCluePool.setFinishUserName(null);
178   - customerCluePool.setCreateTime(null);
179   - customerCluePool.setUpdateTime(null);
180   -
181   - LocalDate addTime = DateUtil.date2LocalDate(pool.getAddTime());
182   - while (!addTime.minusDays(40L).isAfter(LocalDate.now())) {
183   - addTime = addTime.plusYears(1L);
184   - }
  159 + public void createClue(Long groupId) {
  160 + int count = customerService.count(Wrappers.<Customer>lambdaQuery()
  161 + .eq(Customer::getGroupId, groupId)
  162 + .eq(Customer::getYn, Boolean.TRUE)
  163 + );
  164 + if (count <= 0) {
  165 + return;
  166 + }
  167 + List<Customer> list = customerService.list(Wrappers.<Customer>lambdaQuery()
  168 + .eq(Customer::getGroupId, groupId)
  169 + .eq(Customer::getYn, Boolean.TRUE)
  170 + );
  171 + for (Customer customer : list) {
  172 + createClue(customer);
  173 + }
  174 + }
185 175  
186   - customerCluePool.setStartTime(DateUtil.localDate2Date(addTime.minusDays(40L)));
187   - customerCluePool.setAddTime(DateUtil.localDate2Date(addTime));
188   - customerCluePool.setDeadline(DateUtil.localDate2Date(addTime));
189   - customerCluePool.setCloseTime(null);
190   - customerCluePoolService.save(customerCluePool);
  176 + @Transactional(rollbackFor = Exception.class)
  177 + public void createClue(Customer customer) {
  178 + String day = DateUtil.getStringDateShort(new Date());
  179 + Long customerId = customer.getId();
  180 + Long shopId = customer.getShopId();
  181 + Long adviserId = customer.getAdviserId();
  182 +
  183 + String vin = customer.getFrameNo();
  184 + ArrayList<ClueStatusEnum> statusEnums = ListUtil.toList(ClueStatusEnum.WAITING, ClueStatusEnum.ONGOING);
  185 + int count = followClueService.count(Wrappers.<FollowClue>lambdaQuery()
  186 + .eq(FollowClue::getClueType, FollowTypeEnum.IR)
  187 + .eq(FollowClue::getVin, vin)
  188 + .in(FollowClue::getClueState, statusEnums)
  189 + );
  190 + if (count > 0) {
  191 + return;
191 192 }
192 193  
193   - customerCluePoolService.updateBatchById(list);
194   - return list.size();
  194 + OriginalData originalData = originalDataService.getOne(Wrappers.<OriginalData>lambdaQuery()
  195 + .eq(OriginalData::getType, DataTypeEnum.BI)
  196 + .eq(OriginalData::getCustomerId, customerId)
  197 + .orderByDesc(OriginalData::getCreateTime)
  198 + .last(" limit 1 ")
  199 + );
  200 + LocalDate generateTime = generateTime(originalData, customer);
  201 + if (Objects.isNull(generateTime)) {
  202 + return;
  203 + }
  204 + OriginalData data = new OriginalData();
  205 + data.setType(DataTypeEnum.BI);
  206 + data.setCustomerId(customerId);
  207 + data.setPlateNo(customer.getPlateNo());
  208 + data.setFrameNo(customer.getFrameNo());
  209 + if (Objects.nonNull(shopId)) {
  210 + data.setUserId(adviserId);
  211 + data.setShopId(shopId);
  212 + } else {
  213 + Long brandId = Optional.ofNullable(customer.getBrandId()).orElse(-1L);
  214 + List<Integer> list = map.get(brandId);
  215 + int randomIndex = new Random().nextInt(list.size());
  216 + data.setShopId(Long.valueOf(list.get(randomIndex)));
  217 + }
  218 + data.setGenerateTime(DateUtil.localDate2Date(generateTime));
  219 + data.setDetailId(customer.getPlateNo() + "_" + day);
  220 + data.setSolved(false);
  221 + data.setGroupId(customer.getGroupId());
  222 + originalDataService.save(data);
195 223 }
196 224  
197   - private String getRoleCode(FollowTypeEnum followTypeEnum) {
198   - switch (followTypeEnum) {
199   - case AC:
200   - return RoleCode.SGCGJ;
201   - case IR:
202   - return RoleCode.XBGJ;
203   - case FM:
204   - case RM:
205   - default:
206   - return RoleCode.FWGW;
  225 + private LocalDate generateTime(OriginalData originalData, Customer customer) {
  226 + LocalDate generateTime;
  227 + if (Objects.nonNull(originalData)) {
  228 + generateTime = DateUtil.date2LocalDate(originalData.getGenerateTime());
  229 + } else {
  230 + Date date = customer.getInsuranceExpires();
  231 + if (Objects.isNull(date)) {
  232 + date = Objects.isNull(customer.getBuyDate()) ? customer.getRegDate() : customer.getBuyDate();
  233 + }
  234 + if (Objects.isNull(date)) {
  235 + return null;
  236 + }
  237 + generateTime = DateUtil.date2LocalDate(date);
  238 + }
  239 + Optional<SettingVO> settingVO = settingBizService.querySettingByType(FollowTypeEnum.IR, SettingTypeEnum.FIRST_TRIGGER_TIME, customer.getGroupId(), null);
  240 + if (!settingVO.isPresent()) {
  241 + return null;
  242 + }
  243 + int detailValue = Optional.ofNullable(settingVO.get().getDetailValue()).orElse(0);
  244 + while (!generateTime.minusDays(detailValue).isAfter(LocalDate.now().minusDays(4L))) {
  245 + generateTime = generateTime.plusYears(1L);
207 246 }
  247 + return generateTime;
208 248 }
209 249 }
... ...
fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/follow/strategy/impl/IRFollowStrategy.java
... ... @@ -84,7 +84,7 @@ public class IRFollowStrategy extends AbstractFollowStrategy {
84 84 return;
85 85 }
86 86 Customer customer = customerService.queryByFrameNo(followClue.getVin(), followClue.getGroupId());
87   - if (Objects.isNull(customer) || Objects.isNull(customer.getAdviserId())) {
  87 + if (Objects.isNull(customer)) {
88 88 followClueService.removeById(followClue.getId());
89 89 return;
90 90 }
... ...