Blame view

fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/cust/CustomerChangeBizService.java 24.5 KB
9e476657   张志伟   :art:
1
2
  package cn.fw.valhalla.service.bus.cust;
  
34b20e3a   张志伟   :sparkles:
3
  import cn.fw.common.cache.locker.DistributedLocker;
6f401c2d   张志伟   feature(*): 公共池完成逻辑
4
  import cn.fw.common.constant.CommonConstant;
e5a78ff0   张志伟   :rocket:
5
  import cn.fw.common.web.annotation.DisLock;
6c848e1d   张志伟   :art:
6
  import cn.fw.common.web.auth.LoginAuthBean;
6c848e1d   张志伟   :art:
7
  import cn.fw.passport.sdk.api.param.WxBCodeParam;
6c848e1d   张志伟   :art:
8
  import cn.fw.valhalla.common.constant.RoleCode;
9dad9666   张志伟   feature(*): 售后crm...
9
10
11
12
13
14
15
  import cn.fw.valhalla.common.utils.DateUtil;
  import cn.fw.valhalla.common.utils.MessageFormatUtil;
  import cn.fw.valhalla.common.utils.QRCodeKit;
  import cn.fw.valhalla.common.utils.StringUtils;
  import cn.fw.valhalla.domain.db.customer.AffiliationRecord;
  import cn.fw.valhalla.domain.db.customer.Customer;
  import cn.fw.valhalla.domain.db.customer.CustomerBaseInfo;
9dad9666   张志伟   feature(*): 售后crm...
16
17
  import cn.fw.valhalla.domain.db.follow.FollowRecord;
  import cn.fw.valhalla.domain.db.follow.FollowRecordLog;
9dad9666   张志伟   feature(*): 售后crm...
18
19
  import cn.fw.valhalla.domain.db.pool.PublicCluePool;
  import cn.fw.valhalla.domain.db.pool.StammkundePool;
60595301   张志伟   :rocket:
20
  import cn.fw.valhalla.domain.dto.*;
2b628098   张志伟   🚀 v1.0.1 服务顾问离职分配...
21
  import cn.fw.valhalla.domain.enums.*;
6c848e1d   张志伟   :art:
22
23
  import cn.fw.valhalla.domain.vo.customer.CustomerChangeInfoVO;
  import cn.fw.valhalla.domain.vo.customer.CustomerChangeQrCodeVO;
6c848e1d   张志伟   :art:
24
  import cn.fw.valhalla.rpc.angel.dto.InsuranceDTO;
9dad9666   张志伟   feature(*): 售后crm...
25
26
  import cn.fw.valhalla.rpc.erp.dto.UserInfoDTO;
  import cn.fw.valhalla.rpc.erp.dto.UserRoleDataRangeDTO;
6c848e1d   张志伟   :art:
27
28
29
  import cn.fw.valhalla.rpc.member.MemberRpcService;
  import cn.fw.valhalla.rpc.member.dto.MemberUserDTO;
  import cn.fw.valhalla.rpc.oop.dto.ShopDTO;
6c848e1d   张志伟   :art:
30
  import cn.fw.valhalla.rpc.passport.PassportService;
f920ebc1   张志伟   :rocket:
31
  import cn.fw.valhalla.sdk.enums.*;
03b7b995   张志伟   ✨ 公共池后端逻辑 100%
32
  import cn.fw.valhalla.sdk.param.ChangeAdviserReq;
f920ebc1   张志伟   :rocket:
33
  import cn.fw.valhalla.sdk.result.CustomerInfoDto;
34b20e3a   张志伟   :sparkles:
34
  import cn.fw.valhalla.service.bus.CommonService;
57a32b62   张志伟   bug fix
35
36
37
38
  import cn.fw.valhalla.service.data.AffiliationRecordService;
  import cn.fw.valhalla.service.data.FollowRecordLogService;
  import cn.fw.valhalla.service.data.FollowRecordService;
  import cn.fw.valhalla.service.data.PublicPoolService;
6c848e1d   张志伟   :art:
39
40
  import com.alibaba.fastjson.JSON;
  import com.baomidou.mybatisplus.core.toolkit.Wrappers;
6f401c2d   张志伟   feature(*): 公共池完成逻辑
41
42
  import lombok.AccessLevel;
  import lombok.Getter;
8587e21d   张志伟   :art:
43
  import lombok.RequiredArgsConstructor;
9e476657   张志伟   :art:
44
  import lombok.extern.slf4j.Slf4j;
34b20e3a   张志伟   :sparkles:
45
46
  import org.apache.commons.lang3.tuple.Pair;
  import org.redisson.api.RLock;
6c848e1d   张志伟   :art:
47
  import org.springframework.beans.BeanUtils;
6f401c2d   张志伟   feature(*): 公共池完成逻辑
48
  import org.springframework.beans.factory.annotation.Value;
34b20e3a   张志伟   :sparkles:
49
  import org.springframework.data.redis.core.StringRedisTemplate;
9e476657   张志伟   :art:
50
  import org.springframework.stereotype.Service;
6c848e1d   张志伟   :art:
51
  import org.springframework.transaction.annotation.Transactional;
376d3231   张志伟   ✨ 主动放弃跟进 100%
52
  import org.springframework.util.CollectionUtils;
6c848e1d   张志伟   :art:
53
  
03b7b995   张志伟   ✨ 公共池后端逻辑 100%
54
  import java.time.LocalDateTime;
6c848e1d   张志伟   :art:
55
  import java.util.*;
34b20e3a   张志伟   :sparkles:
56
  import java.util.concurrent.TimeUnit;
776234a0   张志伟   :sparkles:
57
  import java.util.function.Consumer;
6c848e1d   张志伟   :art:
58
59
  
  import static cn.fw.common.businessvalidator.Validator.BV;
9e476657   张志伟   :art:
60
61
62
63
64
65
66
67
68
  
  /**
   * @author : kurisu
   * @className : CustomerChangeBizService
   * @description : 档案变更服务
   * @date: 2020-08-12 11:23
   */
  @Slf4j
  @Service
8587e21d   张志伟   :art:
69
  @RequiredArgsConstructor
6c848e1d   张志伟   :art:
70
71
72
  public class CustomerChangeBizService extends AbstractCustomerService {
      public final String CUSTOMER_CHANGE_CODE = "valhalla:customer:change:key:{0}:{1}";
  
34b20e3a   张志伟   :sparkles:
73
74
      private final DistributedLocker distributedLocker;
      private final StringRedisTemplate stringRedisTemplate;
6c848e1d   张志伟   :art:
75
76
77
78
79
      /**
       * 会员服务
       */
      private final PassportService passportService;
      private final MemberRpcService memberRpcService;
03b7b995   张志伟   ✨ 公共池后端逻辑 100%
80
      private final AffiliationRecordService affiliationRecordService;
27291f56   张志伟   :bug:
81
      private final PublicPoolService publicPoolService;
fab1c500   张志伟   :ambulance:
82
      private final FollowRecordService followRecordService;
5a66d54c   张志伟   公共线索池成交判断逻辑调整
83
      private final FollowRecordLogService followRecordLogService;
34b20e3a   张志伟   :sparkles:
84
      private final CommonService commonService;
6c848e1d   张志伟   :art:
85
  
6f401c2d   张志伟   feature(*): 公共池完成逻辑
86
87
88
89
      @Value("${spring.cache.custom.global-prefix}:pub-clue:complete")
      @Getter(AccessLevel.PRIVATE)
      private String pubClueCompleteKey;
  
6c848e1d   张志伟   :art:
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
      /**
       * 生成档案变更二维码
       *
       * @param user
       * @param customerChangeDto
       * @return
       */
      public CustomerChangeQrCodeVO createQrCode(LoginAuthBean user, CustomerChangeDto customerChangeDto) {
          String plateNo = customerChangeDto.getPlateNo();
          String vin = customerChangeDto.getFrameNo();
          ShopDTO shopDTO = queryDealId(user.getUserId(), RoleCode.FWGW);
          BV.notNull(shopDTO, () -> "用户权限不正确");
  
          if (customerChangeDto.getId() == null) {
              customerChangeDto.setGroupId(shopDTO.getGroupId());
              customerChangeDto.setDealerId(shopDTO.getDealerId());
              customerChangeDto.setShopId(shopDTO.getId());
              customerChangeDto.setAdviserId(user.getUserId());
          } else {
              Customer cust = customerService.queryById(customerChangeDto.getId());
              customerChangeDto.setGroupId(cust.getGroupId());
              customerChangeDto.setDealerId(shopDTO.getDealerId());
              customerChangeDto.setShopId(cust.getShopId());
              customerChangeDto.setAdviserId(cust.getAdviserId());
              customerChangeDto.setModelCode(cust.getSpecCode());
          }
          String str = plateNo + vin + user.getUserId();
b571eb94   张志伟   :sparkles:
117
          if (Objects.isNull(customerChangeDto.getShopId())) {
910703fe   张志伟   :sparkles:
118
119
120
              customerChangeDto.setShopId(shopDTO.getId());
              customerChangeDto.setAdviserId(user.getUserId());
          }
6c848e1d   张志伟   :art:
121
          String key = MessageFormatUtil.MessageFormatTransfer(CUSTOMER_CHANGE_CODE, customerChangeDto.getShopId(), str);
34b20e3a   张志伟   :sparkles:
122
123
124
125
126
127
128
129
130
131
          String customerString = JSON.toJSONString(customerChangeDto);
          Pair<Boolean, RLock> lockPair = distributedLocker.tryLock(key, TimeUnit.SECONDS, 0, 1000 * 15);
          RLock rLock = lockPair.getRight();
          boolean flag = rLock.isLocked();
          BV.isTrue(flag, "重复操作,请稍后重试");
          int expires = 60 * 30;
          stringRedisTemplate.opsForValue().set(key, customerString, expires, TimeUnit.SECONDS);
          String code = createCode(key, expires, customerChangeDto.getDealerId());
          distributedLocker.unlock(key);
          return new CustomerChangeQrCodeVO(code, key);
6c848e1d   张志伟   :art:
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
      }
  
      /**
       * 根据主键查询档案信息
       *
       * @param customerId
       * @return
       */
      public CustomerChangeInfoVO mpGetById(Long customerId) {
          final CustomerChangeInfoVO detailVO = new CustomerChangeInfoVO();
          Customer customer = customerService.queryById(customerId);
          if (customer == null) {
              return null;
          }
          CustomerDetailDto customerDetailDto = renderDto(customer);
          BeanUtils.copyProperties(customerDetailDto, detailVO);
          detailVO.setId(customer.getId());
          Optional<InsuranceDTO> dtoOptional = queryInsuInfo(customerId);
          dtoOptional.ifPresent(t -> {
              detailVO.setInsurCompanyId(t.getInsurerId());
              detailVO.setInsurCompanyName(t.getInsurerName());
              detailVO.setInsurExpireDate(t.getExpiryDate());
          });
          return detailVO;
      }
  
  
      /**
f920ebc1   张志伟   :rocket:
160
161
       * C 档案新增或者变更
       *
f920ebc1   张志伟   :rocket:
162
163
164
       * @param dto
       */
      @Transactional(rollbackFor = Exception.class)
34b20e3a   张志伟   :sparkles:
165
      @DisLock(prefix = "'save-customer:'", key = "#dto.memberId + ':' + #dto.frameNo", message = "系统繁忙,请5秒后再试")
e143f587   夏天   新增档案接口
166
167
      public Long saveCustomer(NewCustomerDTO dto) {
          Long memberId = dto.getMemberId();
f920ebc1   张志伟   :rocket:
168
169
170
171
172
173
174
          // 客户类型
          Integer cusType = dto.getCusType();
          MemberUserDTO memberDTO = memberRpcService.user(memberId);
          BV.notNull(memberDTO, () -> "用户信息不存在");
          ShopDTO shop = oopService.shop(dto.getShopId());
          BV.notNull(shop, () -> "服务站信息不存在");
          Long groupId = shop.getGroupId();
b9c46167   夏天   新增档案 fix
175
          dto.setGroupId(groupId);
f920ebc1   张志伟   :rocket:
176
177
178
179
180
181
182
183
184
185
186
          // 处理基础信息
          Long[] baseIds = updateBaseInfo(memberDTO, groupId, dto.getName(), cusType);
  
          Long customerId = dto.getId();
          Long oldBaseId = baseIds[1];
          Long baseId = baseIds[0];
          String plateNo = dto.getPlateNo();
          String frameNo = dto.getFrameNo();
  
          Customer customerByFrameNo = customerService.queryByFrameNo(frameNo, groupId);
          if (Objects.isNull(customerId)) {
e143f587   夏天   新增档案接口
187
              customerId = addCustomer(customerByFrameNo, dto, baseId, memberId);
f920ebc1   张志伟   :rocket:
188
189
190
          } else {
              Customer customer = customerService.queryById(customerId);
              if (Objects.isNull(customer)) {
e143f587   夏天   新增档案接口
191
                  customerId = addCustomer(customerByFrameNo, dto, baseId, memberId);
f920ebc1   张志伟   :rocket:
192
              } else {
8cd965a1   张志伟   feature(*): 续保跟进调整
193
                  final CustomerInfoDto customerInfoDto = new CustomerInfoDto();
f920ebc1   张志伟   :rocket:
194
195
196
197
198
199
                  if (Objects.nonNull(customerByFrameNo)) {
                      if (!customerByFrameNo.getId().equals(customerId)) {
                          if (customer.getGroupId().equals(groupId)) {
                              stammkundePoolService.reject(customerId, groupId, DefeatReasonEnum.CI);
                              publicCluePoolService.removeClue(customerId, customer.getAdviserId());
                              customerService.forbidden(customerId);
f920ebc1   张志伟   :rocket:
200
201
202
                          }
                      }
                      packageCustomer(customerByFrameNo, dto, baseId);
8cd965a1   张志伟   feature(*): 续保跟进调整
203
204
205
                      BeanUtils.copyProperties(customerByFrameNo, customerInfoDto);
                      customerInfoDto.setConsultantId(customerByFrameNo.getAdviserId());
                      customerInfoDto.setMemberId(memberId);
f920ebc1   张志伟   :rocket:
206
207
208
                      customerService.updateById(customerByFrameNo);
                  } else {
                      packageCustomer(customer, dto, baseId);
8cd965a1   张志伟   feature(*): 续保跟进调整
209
210
211
                      BeanUtils.copyProperties(customer, customerInfoDto);
                      customerInfoDto.setConsultantId(customer.getAdviserId());
                      customerInfoDto.setMemberId(memberId);
f920ebc1   张志伟   :rocket:
212
213
                      customerService.updateById(customer);
                  }
8cd965a1   张志伟   feature(*): 续保跟进调整
214
                  this.customerChangeProducer.send(customerInfoDto);
f920ebc1   张志伟   :rocket:
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
              }
          }
  
          Customer customerByPlateNo = customerService.queryByPlateNo(plateNo, groupId);
          if (Objects.nonNull(customerByPlateNo)) {
              if (!customerByPlateNo.getFrameNo().equals(frameNo)) {
                  customerByPlateNo.setPlateNo("临" + plateNo);
                  customerService.updateById(customerByPlateNo);
              }
          }
  
          List<Customer> list = customerService.queryByBaseId(oldBaseId);
          list.forEach(r -> {
              r.setBaseId(baseId);
              if (!StringUtils.isEmpty(r.getTags())) {
                  Set<String> tagSet = new HashSet<>(Arrays.asList(r.getTags().split(",")));
                  //质保卡
                  tagSet.remove(CusTagEnum.QUA_ASS_CARD.getValue());
                  //套餐卡
                  tagSet.remove(CusTagEnum.MAINTAIN_CARD.getValue());
                  String newTags = String.join(",", tagSet);
                  r.setTags(newTags);
              }
          });
          customerService.updateBatchById(list);
e143f587   夏天   新增档案接口
240
          return customerId;
f920ebc1   张志伟   :rocket:
241
242
243
      }
  
      /**
60595301   张志伟   :rocket:
244
245
246
247
248
       * 变更地址信息
       *
       * @param dto
       */
      @Transactional(rollbackFor = Exception.class)
34b20e3a   张志伟   :sparkles:
249
      @DisLock(prefix = "'change-address-customer:'", key = "#dto.id", message = "系统繁忙,请5秒后再试")
60595301   张志伟   :rocket:
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
      public void updateCustomerAddress(CustomerAddressChangeDTO dto) {
          Long id = dto.getId();
          Customer customer = customerService.getById(id);
          BV.notNull(customer, () -> "档案信息不存在");
          Long baseId = customer.getBaseId();
          CustomerBaseInfo baseInfo = customerBaseInfoService.queryById(baseId);
          BV.notNull(baseInfo, () -> "车主信息不存在");
          baseInfo.setAddress(dto.getAddress());
          baseInfo.setLat(dto.getLat());
          baseInfo.setLng(dto.getLng());
          baseInfo.setCityCode(dto.getCityCode());
          baseInfo.setCityName(dto.getCityName());
          baseInfo.setHobby(dto.getHobby());
          baseInfo.setJob(dto.getJob());
          baseInfo.setCompanyName(dto.getCompanyName());
          customerBaseInfoService.updateById(baseInfo);
      }
  
6c848e1d   张志伟   :art:
268
  
6c848e1d   张志伟   :art:
269
      /**
03b7b995   张志伟   ✨ 公共池后端逻辑 100%
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
       * 变更档案标签
       *
       * @param cusId
       * @param tags
       * @return
       */
      @Transactional(rollbackFor = Exception.class)
      public int updateTagById(Long cusId, String tags) {
          Customer customer = customerService.queryById(cusId);
          BV.notNull(customer, "档案信息异常");
          customer.setTags(tags);
          customer.setUpdateTime(new Date());
          int updateCount = customerService.getBaseMapper().updateById(customer);
          if (updateCount > 0) {
              customerChangeHandler(customer);
          }
          return updateCount;
      }
  
      /**
       * 更新保有客专属服务顾问
       *
       * @param changeAdviserReq 新的服务顾问
       * @return 是否成功
       */
      @Transactional(rollbackFor = Exception.class)
      public Boolean changeAdviser(ChangeAdviserReq changeAdviserReq) {
          Customer customer = customerService.queryById(changeAdviserReq.getCusId());
          if (Objects.isNull(customer)) {
              return true;
          }
b3f56a8f   张志伟   :fire:
301
          boolean isCard = ReasonEnum.MC.getValue().equals(changeAdviserReq.getReason()) || ReasonEnum.WC.getValue().equals(changeAdviserReq.getReason());
8f82f213   张志伟   :construction_wor...
302
303
304
          if (isCard) {
              return true;
          }
03b7b995   张志伟   ✨ 公共池后端逻辑 100%
305
          Long adviserId = changeAdviserReq.getAdviserId();
03b7b995   张志伟   ✨ 公共池后端逻辑 100%
306
          List<UserRoleDataRangeDTO> dataRange = userService.getUserRoleDataRange(adviserId, RoleCode.FWGW);
9b497427   张志伟   :art:
307
          if (CollectionUtils.isEmpty(dataRange) || Objects.isNull(dataRange.get(0).getRangeValue())) {
03b7b995   张志伟   ✨ 公共池后端逻辑 100%
308
309
              return true;
          }
6f401c2d   张志伟   feature(*): 公共池完成逻辑
310
311
312
313
314
315
316
317
318
          String sb = customer.getFrameNo() +
                  CommonConstant.Symbol.AT +
                  adviserId +
                  CommonConstant.Symbol.AT +
                  customer.getGroupId() +
                  CommonConstant.Symbol.AT +
                  dataRange.get(0).getRangeValue();
          stringRedisTemplate.opsForList().rightPush(getPubClueCompleteKey(), sb);
  
d9ece85a   张志伟   :sparkles:
319
320
321
322
323
324
          if (adviserId.equals(customer.getAdviserId())) {
              StammkundePool stammkundePool = stammkundePoolService.queryAktivAble(customer.getId(), customer.getGroupId(), customer.getShopId());
              if (Objects.nonNull(stammkundePool)) {
                  stammkundePool.setAktiv(Boolean.TRUE);
                  stammkundePool.setActivationTime(new Date());
                  stammkundePool.setPoolStatus(StammkundeStatusEnum.KUNDE);
b571eb94   张志伟   :sparkles:
325
326
                  Date createTime = DateUtil.getBeginInTime(stammkundePool.getCreateTime());
                  Date expiration = DateUtil.getBeginInTime(new Date());
94e3379e   张志伟   :sparkles:
327
  
5a66d54c   张志伟   公共线索池成交判断逻辑调整
328
329
                  boolean flag = expiration.after(createTime);
  
18554890   张志伟   :bug:
330
                  if (StammkundeSourcesEnum.PUBLIC_POOL.equals(stammkundePool.getSources())) {
5a66d54c   张志伟   公共线索池成交判断逻辑调整
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
                      PublicCluePool cluePool = publicCluePoolService.queryByAdviserAndCust(customer.getId(), adviserId);
                      if (Objects.nonNull(cluePool)) {
                          flag = flag || expiration.after(cluePool.getCreateTime());
                          List<FollowRecord> recordList = followRecordService.list(Wrappers.<FollowRecord>lambdaQuery()
                                  .eq(FollowRecord::getTaskId, cluePool.getId())
                                  .eq(FollowRecord::getType, FollowTypeEnum.OT)
                                  .eq(FollowRecord::getAddTodo, Boolean.TRUE)
                                  .orderByAsc(FollowRecord::getId)
                          );
                          if (!CollectionUtils.isEmpty(recordList)) {
                              FollowRecord followRecord = recordList.get(0);
                              int count = followRecordLogService.count(Wrappers.<FollowRecordLog>lambdaQuery().eq(FollowRecordLog::getRecordId, followRecord.getId()));
                              flag = flag && (count > 0);
                          }
                      }
  
                      if (flag) {
18554890   张志伟   :bug:
348
349
350
351
352
353
                          publicCluePoolService.closeClue(customer.getId(), adviserId);
                      } else {
                          stammkundePool.setCreateTime(new Date());
                          stammkundePool.setSources(StammkundeSourcesEnum.NATURAL);
                          publicCluePoolService.removeClue(customer.getId(), adviserId);
                      }
b571eb94   张志伟   :sparkles:
354
                  }
ccee7886   张志伟   feature(*): 修复bug
355
356
                  customer.setTemporary(Boolean.FALSE);
                  customerService.updateById(customer);
d9ece85a   张志伟   :sparkles:
357
                  stammkundePoolService.updateById(stammkundePool);
d9ece85a   张志伟   :sparkles:
358
359
360
              }
              return true;
          }
03b7b995   张志伟   ✨ 公共池后端逻辑 100%
361
362
363
364
365
          Long shopId = dataRange.get(0).getRangeValue();
  
          boolean updated = customerService.update(Wrappers.<Customer>lambdaUpdate()
                  .set(Customer::getAdviserId, adviserId)
                  .set(Customer::getShopId, shopId)
ccee7886   张志伟   feature(*): 修复bug
366
                  .set(Customer::getTemporary, Boolean.FALSE)
03b7b995   张志伟   ✨ 公共池后端逻辑 100%
367
                  .eq(Customer::getId, changeAdviserReq.getCusId()));
d9ece85a   张志伟   :sparkles:
368
  
e0e33af7   张志伟   :bug:
369
          BV.isTrue(updated, () -> "变更档案服务顾问失败,请重试");
d9ece85a   张志伟   :sparkles:
370
  
e0e33af7   张志伟   :bug:
371
          if (Objects.nonNull(customer.getAdviserId()) && Objects.nonNull(customer.getShopId())) {
1b7b7d85   张志伟   ✨ v1.1.1 调整保有客池查...
372
373
374
              Integer reason = changeAdviserReq.getReason();
              DefeatReasonEnum reasonEnum = DefeatReasonEnum.ofValue(reason);
              BV.notNull(reasonEnum, () -> "档案变更原因不正确");
03b7b995   张志伟   ✨ 公共池后端逻辑 100%
375
              AffiliationRecord entity = createEntity(customer, adviserId, shopId);
1b7b7d85   张志伟   ✨ v1.1.1 调整保有客池查...
376
              entity.setReason(reasonEnum.getName());
03b7b995   张志伟   ✨ 公共池后端逻辑 100%
377
              affiliationRecordService.save(entity);
6c37b6e3   张志伟   :bug:
378
379
380
381
382
              //处理保有客池数据
              StammkundeDto stammkundeDto = new StammkundeDto();
              stammkundeDto.setCustomerId(customer.getId());
              stammkundeDto.setReason(reasonEnum);
              stammkundeDto.setShopId(customer.getShopId());
3fc19e59   张志伟   升级erpsdk
383
              UserInfoDTO user = ehrRpcService.user(adviserId);
6c37b6e3   张志伟   :bug:
384
385
386
387
388
389
390
391
              stammkundeDto.setNewUserId(adviserId);
              if (Objects.nonNull(user)) {
                  stammkundeDto.setNewUserName(user.getUserName());
              }
              ShopDTO shop = oopService.shop(shopId);
              stammkundeDto.setNewShopId(shopId);
              if (Objects.nonNull(shop)) {
                  stammkundeDto.setNewShopName(shop.getShortName());
27291f56   张志伟   :bug:
392
              }
6c37b6e3   张志伟   :bug:
393
394
              stammkundeDto.setGroupId(customer.getGroupId());
              stammkundePoolService.reject(stammkundeDto);
d9ece85a   张志伟   :sparkles:
395
396
              publicCluePoolService.removeClue(customer.getId(), adviserId);
              create(customer, adviserId, shopId);
03b7b995   张志伟   ✨ 公共池后端逻辑 100%
397
          }
d9ece85a   张志伟   :sparkles:
398
  
e0e33af7   张志伟   :bug:
399
400
          if (Objects.isNull(customer.getAdviserId()) && Objects.isNull(customer.getShopId())) {
              publicPoolService.removeByCustomerId(customer.getId(), customer.getGroupId());
776234a0   张志伟   :sparkles:
401
              create(customer, adviserId, shopId, r -> r.setFromPublic(Boolean.TRUE));
e0e33af7   张志伟   :bug:
402
          }
03b7b995   张志伟   ✨ 公共池后端逻辑 100%
403
404
405
          return updated;
      }
  
6c848e1d   张志伟   :art:
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
  
      private String createCode(String key, int expires, Long dealerId) {
          final WxBCodeParam param = new WxBCodeParam();
          final Map<String, String> map = new HashMap<>(1);
          map.put("customerKey", key);
          param.setParam(map);
          param.setPage("pgCas/CarArchives/index");
          param.setExpires(expires);
          param.setDealerId(dealerId);
          final byte[] bytes = passportService.getWxBCode(param);
          if (Objects.isNull(bytes)) {
              return null;
          }
          return QRCodeKit.byte2Base64String(bytes);
      }
  
  
d9ece85a   张志伟   :sparkles:
423
      private void create(Customer customer, Long adviserId, Long shopId) {
776234a0   张志伟   :sparkles:
424
425
426
427
          create(customer, adviserId, shopId, null);
      }
  
      private void create(Customer customer, Long adviserId, Long shopId, Consumer<StammkundePool> cs) {
1b7b7d85   张志伟   ✨ v1.1.1 调整保有客池查...
428
          StammkundePool stammkundePool = createSimpleInfo(customer, adviserId);
d9ece85a   张志伟   :sparkles:
429
          stammkundePool.setSources(StammkundeSourcesEnum.NATURAL);
8b565927   张志伟   :construction:
430
          stammkundePool.setShopId(shopId);
e0e33af7   张志伟   :bug:
431
432
433
434
          stammkundePool.setPoolStatus(StammkundeStatusEnum.KUNDE);
          stammkundePool.setAktiv(Boolean.TRUE);
          stammkundePool.setActivationTime(new Date());
          stammkundePool.setCreateTime(new Date());
776234a0   张志伟   :sparkles:
435
436
437
          if (cs != null) {
              cs.accept(stammkundePool);
          }
e0e33af7   张志伟   :bug:
438
439
440
          stammkundePoolService.save(stammkundePool);
      }
  
03b7b995   张志伟   ✨ 公共池后端逻辑 100%
441
442
443
444
445
446
447
448
449
450
451
452
      private AffiliationRecord createEntity(Customer customer, Long adviserId, Long shopId) {
          AffiliationRecord record = new AffiliationRecord();
          record.setCustomerId(customer.getId());
          record.setType(CustomerChangeTypeEnum.DEFEAT);
          record.setDefeatTime(DateUtil.localDateTime2Date(LocalDateTime.now()));
          record.setOriginUserId(customer.getAdviserId());
          record.setOriginShopId(customer.getShopId());
          record.setCurUserId(adviserId);
          record.setCurShopId(shopId);
          record.setCreateTime(DateUtil.localDateTime2Date(LocalDateTime.now()));
          return record;
      }
f920ebc1   张志伟   :rocket:
453
454
  
      private Long[] updateBaseInfo(MemberUserDTO memberDTO, Long groupId, String name, Integer cusType) {
f59458ea   张志伟   :bug:
455
          CustomerBaseInfo baseInfo = customerBaseInfoService.queryByMemberId(memberDTO.getUserId(), groupId);
e5a78ff0   张志伟   :rocket:
456
457
          CusTypeEnum cusTypeEnum = CusTypeEnum.ofValue(cusType);
          if (!CusTypeEnum.COMPANY.equals(cusTypeEnum)) {
3e7dc0fa   张志伟   :bug:
458
              BV.isTrue(Objects.equals(memberDTO.getRealName(), name), () -> "本人姓名与行驶证不符");
e5a78ff0   张志伟   :rocket:
459
          }
f920ebc1   张志伟   :rocket:
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
          CustomerBaseInfo mobileBaseInfo = customerBaseInfoService.queryByMobile(memberDTO.getPhone(), groupId);
          if (Objects.nonNull(baseInfo)) {
              if (Objects.nonNull(mobileBaseInfo)) {
                  if (!baseInfo.getId().equals(mobileBaseInfo.getId())) {
                      mobileBaseInfo.setYn(Boolean.FALSE);
                      customerBaseInfoService.updateById(mobileBaseInfo);
                  }
              }
          } else {
              if (Objects.nonNull(mobileBaseInfo)) {
                  mobileBaseInfo.setYn(Boolean.FALSE);
                  customerBaseInfoService.updateById(mobileBaseInfo);
              }
              baseInfo = new CustomerBaseInfo();
          }
          baseInfo.setName(name);
          baseInfo.setMemberId(memberDTO.getUserId());
          baseInfo.setContact(memberDTO.getRealName());
          baseInfo.setMobile(memberDTO.getPhone());
          baseInfo.setGender(GenderEnum.ofValue(memberDTO.getSex()));
          baseInfo.setBirthday(memberDTO.getBirthday());
          baseInfo.setIdCode(memberDTO.getCredentNo());
e5a78ff0   张志伟   :rocket:
482
          baseInfo.setCusType(cusTypeEnum);
f920ebc1   张志伟   :rocket:
483
484
485
486
          baseInfo.setGroupId(groupId);
          baseInfo.setYn(Boolean.TRUE);
  
          customerBaseInfoService.saveOrUpdate(baseInfo);
55003764   张志伟   feature(*): 售后crm...
487
          return new Long[]{baseInfo.getId(), Objects.isNull(mobileBaseInfo) ? null : mobileBaseInfo.getId()};
f920ebc1   张志伟   :rocket:
488
489
490
      }
  
  
e143f587   夏天   新增档案接口
491
      private Long addCustomer(Customer customer, NewCustomerDTO dto, Long baseId, Long memberId) {
f920ebc1   张志伟   :rocket:
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
          if (Objects.nonNull(customer)) {
              packageCustomer(customer, dto, baseId);
              customerService.updateById(customer);
          } else {
              customer = new Customer();
              packageCustomer(customer, dto, baseId);
              customer.setAdviserId(dto.getAdviserId());
              customer.setShopId(dto.getShopId());
              customerService.save(customer);
  
              StammkundePool simpleInfo = createSimpleInfo(customer, dto.getAdviserId());
              simpleInfo.setSources(StammkundeSourcesEnum.NATURAL);
              simpleInfo.setPoolStatus(StammkundeStatusEnum.KUNDE);
              simpleInfo.setAktiv(Boolean.TRUE);
              simpleInfo.setActivationTime(new Date());
              stammkundePoolService.save(simpleInfo);
34b20e3a   张志伟   :sparkles:
508
              commonService.createClue(customer);
f920ebc1   张志伟   :rocket:
509
          }
ccee7886   张志伟   feature(*): 修复bug
510
          customer.setTemporary(Boolean.FALSE);
60595301   张志伟   :rocket:
511
512
513
514
515
          final CustomerInfoDto customerInfoDto = new CustomerInfoDto();
          BeanUtils.copyProperties(customer, customerInfoDto);
          customerInfoDto.setConsultantId(customer.getAdviserId());
          customerInfoDto.setMemberId(memberId);
          this.customerChangeProducer.send(customerInfoDto);
e143f587   夏天   新增档案接口
516
          return customer.getId();
f920ebc1   张志伟   :rocket:
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
      }
  
      private void packageCustomer(Customer customer, NewCustomerDTO dto, Long baseId) {
          if (Objects.nonNull(customer.getBaseId()) && !customer.getBaseId().equals(baseId)) {
              if (StringUtils.isValid(customer.getTags())) {
                  Set<String> tagSet = new HashSet<>(Arrays.asList(customer.getTags().split(",")));
                  //质保卡
                  tagSet.remove(CusTagEnum.QUA_ASS_CARD.getValue());
                  //套餐卡
                  tagSet.remove(CusTagEnum.MAINTAIN_CARD.getValue());
                  String newTags = String.join(",", tagSet);
                  customer.setTags(newTags);
              }
          }
          customer.setBaseId(baseId);
          customer.setPlateNo(dto.getPlateNo());
          customer.setFrameNo(dto.getFrameNo());
          customer.setRegDate(dto.getRegDate());
f920ebc1   张志伟   :rocket:
535
536
537
538
539
540
541
542
543
544
545
          customer.setEngineNo(dto.getEngineNo());
          customer.setBrandId(dto.getBrandId());
          customer.setBrandName(dto.getBrandName());
          customer.setSeriesId(dto.getSeriesId());
          customer.setSeriesName(dto.getSeriesName());
          customer.setSpecId(dto.getSpecId());
          customer.setSpecName(dto.getSpecName());
          customer.setSpecCode(dto.getSpecCode());
          customer.setUseType(CarUseTypeEnum.ofValue(dto.getUseType()));
          customer.setSource(SourceTypeEnum.TO_SHOP);
          customer.setYn(Boolean.TRUE);
b9c46167   夏天   新增档案 fix
546
          customer.setGroupId(dto.getGroupId());
6f401c2d   张志伟   feature(*): 公共池完成逻辑
547
          if (Objects.isNull(customer.getBuyDate())) {
fbaa3db2   夏天   调整车辆认证逻辑
548
549
              customer.setBuyDate(dto.getRegDate());
          }
f920ebc1   张志伟   :rocket:
550
      }
9e476657   张志伟   :art:
551
  }