CusFollowService.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. package com.dk.mdm.service.mst;
  2. import com.dk.common.exception.BaseBusinessException;
  3. import com.dk.common.infrastructure.annotaiton.Pagination;
  4. import com.dk.common.infrastructure.constant.Constant;
  5. import com.dk.common.infrastructure.enums.ErrorCodeEnum;
  6. import com.dk.common.model.pojo.PageList;
  7. import com.dk.common.model.vo.core.StaffEntity;
  8. import com.dk.common.response.ResponseCodeEnum;
  9. import com.dk.common.response.ResponseResultUtil;
  10. import com.dk.common.response.ResponseResultVO;
  11. import com.dk.mdm.infrastructure.convert.mst.CusFollowConvert;
  12. import com.dk.mdm.infrastructure.convert.mst.MeasureReceiptConvert;
  13. import com.dk.mdm.infrastructure.util.AuthUtils;
  14. import com.dk.mdm.mapper.mst.*;
  15. import com.dk.mdm.model.pojo.mst.*;
  16. import com.dk.common.service.BaseService;
  17. import com.dk.common.mapper.BaseMapper;
  18. import com.dk.mdm.model.query.mst.CusFollowQuery;
  19. import com.dk.mdm.model.query.mst.CustomerQuery;
  20. import com.dk.mdm.model.response.mst.CusFollowResponse;
  21. import com.dk.mdm.model.response.mst.CustomerResponse;
  22. import com.dk.common.model.response.mst.StaffResponse;
  23. import com.dk.mdm.model.vo.mst.CusFollowVO;
  24. import com.dk.mdm.model.vo.mst.MeasureReceiptVO;
  25. import com.dk.mdm.service.common.CommonService;
  26. import org.springframework.stereotype.Service;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.transaction.annotation.Transactional;
  29. import java.time.LocalDate;
  30. import java.time.LocalDateTime;
  31. import java.util.*;
  32. @Service
  33. @Transactional
  34. public class CusFollowService extends BaseService<CusFollow> {
  35. @Override
  36. public BaseMapper<CusFollow> getRepository() {
  37. return cusFollowMapper;
  38. }
  39. @Autowired
  40. private CusFollowMapper cusFollowMapper;
  41. @Autowired
  42. private CustomerMapper customerMapper;
  43. @Autowired
  44. private CustomerService customerService;
  45. @Autowired
  46. private CusFollowStaffMapper cusFollowStaffMapper;
  47. @Autowired
  48. private CommonService commonService;
  49. @Autowired
  50. private CusFollowConvert cusFollowConvert;
  51. @Autowired
  52. private StaffMapper staffMapper;
  53. @Autowired
  54. private AuthUtils authUtils;
  55. @Autowired
  56. private MeasureRoomService measureRoomService;
  57. @Autowired
  58. private MeasureReceiptService measureReceiptService;
  59. @Autowired
  60. private MeasureReceiptMapper measureReceiptMapper;
  61. @Autowired
  62. private MeasureRoomMapper measureRoomMapper;
  63. @Autowired
  64. private MeasureReceiptConvert measureReceiptConvert;
  65. /**
  66. * @desc : 重写主键
  67. * @author : 于继渤
  68. * @date : 2024/2/29 20:29
  69. */
  70. @Override
  71. public String getPrimaryKey() {
  72. return "follow_id";
  73. }
  74. /**
  75. * @desc : 查询
  76. * @author : 于继渤
  77. * @date : 2023/1/5 9:39
  78. */
  79. @Pagination
  80. public ResponseResultVO<PageList<CusFollowResponse>> selectByCond(CusFollowQuery cusFollowQuery) {
  81. return super.mergeListWithCount(cusFollowQuery, cusFollowMapper.selectByCond(cusFollowQuery),
  82. cusFollowMapper.countByCond(cusFollowQuery));
  83. }
  84. public ResponseResultVO<List<CusFollowResponse>> selectByList(CusFollowQuery cusFollowQuery) {
  85. return ResponseResultUtil.success(cusFollowMapper.selectByList(cusFollowQuery));
  86. }
  87. /**
  88. * @desc : 跟进id查询
  89. * @author : 于继渤
  90. * @date : 2023/1/5 9:39
  91. */
  92. public ResponseResultVO<CusFollowResponse> selectById(CusFollowQuery cusFollowQuery) {
  93. CusFollowResponse cusFollowResponse = cusFollowMapper.selectByCond(cusFollowQuery).get(0);
  94. if (cusFollowResponse.getFollowId() != null && cusFollowResponse.getMeasureStatus().equals(Constant.BasicDataConstant.MEASURE_STATUS_1.getValue())) {
  95. //已量尺
  96. MeasureReceipt measureReceipts = measureReceiptMapper.selectByFollowId(new MeasureReceipt().setFollowId(cusFollowResponse.getFollowId()));
  97. cusFollowResponse.setMeasureReceipt(measureReceipts);
  98. //查询 空间
  99. List<MeasureRoom> measureRooms = measureRoomMapper.selectByReceiptId(new MeasureRoom().setReceiptId(measureReceipts.getReceiptId()));
  100. cusFollowResponse.setMeasureRoomList(measureRooms);
  101. }
  102. return ResponseResultUtil.success(cusFollowResponse);
  103. }
  104. /**
  105. * @desc : 新建
  106. * @author : 于继渤
  107. * @date : 2023/1/5 9:39
  108. */
  109. @Transactional(
  110. rollbackFor = {Exception.class}
  111. )
  112. public ResponseResultVO<?> insert(CusFollowVO cusFollowVO) {
  113. CusFollow cusFollow = cusFollowConvert.convertToPo(cusFollowVO);
  114. //设置ID
  115. Map<String, Object> uniqueNoteCode = commonService.getUniqueNoteCode(Constant.docNameConstant.CUSTOMERFOLLOW.getName(), true);
  116. cusFollow.setFollowId(uniqueNoteCode.get("outId").toString());
  117. //跟进时间
  118. cusFollow.setFollowTime(LocalDateTime.now());
  119. //跟进人
  120. cusFollow.setFollowStaff(authUtils.getStaff().getStaffId());
  121. //跟进部门
  122. // cusFollow.setFollowOrg(authUtils.getStaff().getOrgId());
  123. if (cusFollowVO.getCusId() != null) {
  124. //查询客户
  125. Customer customer = customerMapper.selectById(cusFollowVO.getCusId());
  126. // 查询跟进人是否存在
  127. CusFollowStaff followStaff = cusFollowStaffMapper.selectByCusFollowStaffId(cusFollowVO.getCusId(), authUtils.getStaff().getStaffId());
  128. //追加跟进人表
  129. if (followStaff == null) {
  130. cusFollowStaffMapper.insert(new CusFollowStaff()
  131. .setCusId(cusFollowVO.getCusId())
  132. .setFollowStaff(authUtils.getStaff().getStaffId())
  133. .setLastFollowId(authUtils.getStaff().getStaffId())
  134. .setLastFollowTime(LocalDateTime.now())
  135. .setCpId(authUtils.getStaff().getCpId())
  136. .setLastFollowStatus(cusFollowVO.getFollowStatus())
  137. .setFollowCount(1)
  138. );
  139. }
  140. //追加跟进人
  141. List<Long> users = new ArrayList<>();
  142. Object o = customerMapper.selectFollowStaffs(cusFollowVO.getCusId());
  143. if (o != null && o instanceof Long[]) {
  144. users = Arrays.asList((Long[]) o);
  145. }
  146. if (users == null || users.size() == 0 || (users != null && users.stream().allMatch(Objects::isNull))) {
  147. users = new ArrayList<>();
  148. }
  149. //公海客户跟进后 变成潜客状态
  150. if (Constant.saleCustomerStatusConstant.SALE_STATUS_INTE.getName().equals(customer.getSaleStatus())) {
  151. customer.setSaleStatus(Constant.saleCustomerStatusConstant.SALE_STATUS_POTE.getName());
  152. }
  153. //已流失客户重新接待后应该变成潜客
  154. if (Constant.saleCustomerStatusConstant.SALE_STATUS_LOST.getName().equals(customer.getSaleStatus())) {
  155. customer.setSaleStatus(Constant.saleCustomerStatusConstant.SALE_STATUS_POTE.getName());
  156. }
  157. //放入公海客户,清除跟进人
  158. if (Constant.IntentionConstant.SEA.getValue().equals(cusFollowVO.getIntention())) {
  159. customer.setFollowStaffs(new ArrayList<>());
  160. customer.setSaleStatus(Constant.saleCustomerStatusConstant.SALE_STATUS_INTE.getName());
  161. } else {
  162. if (!users.contains(authUtils.getStaff().getStaffId())) {
  163. List arrList = new ArrayList(users);
  164. arrList.add(authUtils.getStaff().getStaffId());
  165. customer.setFollowStaffs(arrList);
  166. }
  167. }
  168. //已流失客户,修改状态为流失
  169. if (Constant.IntentionConstant.LOST.getValue().equals(cusFollowVO.getIntention())) {
  170. customer.setSaleStatus(Constant.saleCustomerStatusConstant.SALE_STATUS_LOST.getName());
  171. }
  172. //如果不是留资接待 修改客户信息
  173. if (!Constant.BasicDataConstant.FOLLOW_STATUS_4.getValue().equals(cusFollowVO.getFollowStatus())) {
  174. customer.setCusName(cusFollowVO.getCusName());
  175. customer.setCusPhone(cusFollowVO.getCusPhone());
  176. customer.setAddressName(cusFollowVO.getAddressName());
  177. customer.setAddressNo(cusFollowVO.getAddressNo());
  178. customer.setAddressGcj02(cusFollowVO.getAddressGcj02());
  179. customer.setAddressFull(cusFollowVO.getAddressFull());
  180. customer.setAddressArea(cusFollowVO.getAddressArea());
  181. }
  182. customer.setCpId(authUtils.getStaff().getCpId());
  183. // 同商户 电话不同
  184. List<CustomerResponse> cusList = customerMapper.selectByCond(
  185. new CustomerQuery().setCpId(customer.getCpId()).setCusPhone(customer.getCusPhone()).setFlgValid(true)
  186. );
  187. if (cusList != null && cusList.size() > 0 && cusList.stream().anyMatch(a -> !a.getCusId().equals(customer.getCusId()))) {
  188. throw new BaseBusinessException(ErrorCodeEnum.CUSTOMER_SAME_COMPANY_TELEPHONE.getCode(),
  189. ErrorCodeEnum.CUSTOMER_SAME_COMPANY_TELEPHONE.getMessage());
  190. }
  191. customer.setLastFollowId(cusFollow.getFollowId());
  192. customer.setLastFollowTime(cusFollow.getFollowTime());
  193. customer.setLastFollowStaff(cusFollow.getFollowStaff());
  194. //修改跟进次数
  195. customer.setFollowCount(customer.getFollowCount() + 1);
  196. customerService.updateByUuid(customer);
  197. } else if (cusFollowVO.getCusPhone() != null && cusFollowVO.getCusName() != null) {
  198. //留资接待 新建客户
  199. Customer customer = new Customer();
  200. //设置编码
  201. Map<String, Object> customerNoteCode = commonService.getUniqueNoteCode(Constant.docNameConstant.CUSTOMER.getName(), true);
  202. customer.setCusId(customerNoteCode.get("outId").toString());
  203. customer.setCusCode(customerNoteCode.get("outNote").toString());
  204. //TODO 渠道 取当前登录人员工的渠道
  205. customer.setChannelId("10112024-0302-0000-0000-00000759d8a4");
  206. customer.setCusName(cusFollowVO.getCusName());
  207. customer.setCusPhone(cusFollowVO.getCusPhone());
  208. customer.setAddressName(cusFollowVO.getAddressName());
  209. customer.setAddressNo(cusFollowVO.getAddressNo());
  210. customer.setAddressGcj02(cusFollowVO.getAddressGcj02());
  211. customer.setAddressFull(cusFollowVO.getAddressFull());
  212. customer.setAddressArea(cusFollowVO.getAddressArea());
  213. customer.setReportStaff(authUtils.getStaff().getStaffId());
  214. customer.setReportTime(LocalDateTime.now());
  215. customer.setCpId(authUtils.getStaff().getCpId());
  216. customer.setStaffId(authUtils.getStaff().getStaffId());
  217. customer.setOrgId(cusFollowVO.getFollowOrg());
  218. customer.setFollowCount(1);
  219. customer.setLastFollowId(cusFollow.getFollowId());
  220. customer.setLastFollowTime(cusFollow.getFollowTime());
  221. customer.setLastFollowStaff(cusFollow.getFollowStaff());
  222. cusFollow.setCusId(customer.getCusId());
  223. // 同商户 电话不同
  224. Long count = customerMapper.countByCond(
  225. new CustomerQuery().setCpId(customer.getCpId()).setCusPhone(customer.getCusPhone()).setFlgValid(true)
  226. );
  227. if (count > 0) {
  228. return ResponseResultUtil.error(ErrorCodeEnum.CUSTOMER_SAME_COMPANY_TELEPHONE.getCode(),
  229. ErrorCodeEnum.CUSTOMER_SAME_COMPANY_TELEPHONE.getMessage());
  230. }
  231. //放入公海客户,清除跟进人
  232. if (Constant.IntentionConstant.SEA.getValue().equals(cusFollowVO.getIntention())) {
  233. customer.setFollowStaffs(new ArrayList<>());
  234. customer.setSaleStatus(Constant.saleCustomerStatusConstant.SALE_STATUS_INTE.getName());
  235. } else {
  236. //当前跟进人(业务员)
  237. customer.setFollowStaffs(new ArrayList<String>() {{
  238. add(authUtils.getStaff().getStaffId());
  239. }});
  240. customer.setSaleStatus(Constant.saleCustomerStatusConstant.SALE_STATUS_POTE.getName());
  241. }
  242. //新建客户或编辑客户
  243. customerMapper.insert(customer);
  244. }
  245. // 约量尺
  246. if (Constant.BasicDataConstant.FOLLOW_STATUS_3.getValue().equals(cusFollow.getFollowStatus())) {
  247. // 量尺状态:待量尺
  248. cusFollow.setMeasureStatus(Constant.BasicDataConstant.MEASURE_STATUS_2.getValue());
  249. }
  250. if (cusFollow.getFollowData() == null) {
  251. cusFollow.setFollowData("无");
  252. }
  253. super.insert(cusFollow);
  254. //设计师
  255. StaffResponse designStaff = null;
  256. if (cusFollow.getDesignStaff() != null) {
  257. designStaff = staffMapper.selectById(cusFollow.getDesignStaff());
  258. }
  259. // 约尺 同意邀约 有设计师 设计师绑定企微
  260. boolean pushFlag = Constant.BasicDataConstant.FOLLOW_STATUS_3.getValue().equals(cusFollow.getFollowStatus()) &&
  261. Constant.BasicDataConstant.FOLLOW_INVITE_RESULT.getValue().equals(cusFollow.getInviteResult()) &&
  262. designStaff != null;
  263. if (cusFollow.getNextFollowTime() != null || pushFlag) {
  264. // 保存跟进信息
  265. // saveToXxlJob(cusFollow);
  266. }
  267. return ResponseResultUtil.success();
  268. }
  269. /**
  270. * @desc : 保存跟进信息到xxl job
  271. * @author : 于继渤海
  272. * @date : 2022-05-27 09:53
  273. */
  274. // @Transactional(rollbackFor = {Exception.class})
  275. // public void saveToXxlJob(CusFollow cusFollow) {
  276. //
  277. // Long nextId = followPlanMapper.getNextId();
  278. //
  279. //
  280. // // 约量尺 && 接受邀约
  281. //// 预约量尺,邀约结果接受,通知设计师提醒时间是(服务时间);邀约结果拒绝,通知创建者提醒时间是(提醒时间)
  282. // if (Constant.BasicDataConstant.FOLLOW_STATUS_3.getValue().equals(follow.getFollowStatus()) &&
  283. // Constant.BasicDataConstant.FOLLOW_INVITE_RESULT.getValue().equals(follow.getInviteResult())) {
  284. // follow.setNextFollowTime(follow.getInviteTime()).setFollowUser(follow.getDesignUser());
  285. // }
  286. //
  287. // int id = xxlJobUtils.create(Math.toIntExact(
  288. // (follow.getNextFollowTime().toInstant(ZoneOffset.of("+8")).toEpochMilli() - System.currentTimeMillis()) / 1000
  289. // ), nextId, Constant.XxlJobInfo.FOLLOW.getValue());
  290. //
  291. //
  292. // // 生成主键
  293. // followPlanMapper.insert(
  294. // new FollowPlan().setPlanId(nextId).setCustomerId(follow.getCustomerId())
  295. // .setPlanType(Constant.IntegerConstant.PLAN_TYPE_FOLLOW.getValue())
  296. // .setFollowId(follow.getFollowId())
  297. // .setFollowUser(follow.getFollowUser())
  298. // .setNextFollowPlan(follow.getNextFollowPlan())
  299. // .setNextFollowTime(follow.getNextFollowTime())
  300. // .setXxlJobId(id)
  301. // .setCpId(follow.getCpId())
  302. // );
  303. // }
  304. /**
  305. * @desc : 新建量尺回执
  306. * @author : 于继渤
  307. * @date : 2023/1/5 9:39
  308. */
  309. @Transactional(
  310. rollbackFor = {Exception.class}
  311. )
  312. public ResponseResultVO<?> saveMeasure(CusFollowVO cusFollowVO) {
  313. CusFollow cusFollow = cusFollowConvert.convertToPo(cusFollowVO);
  314. //更新总单
  315. // int update = cusFollowMapper.updateMeasure(cusFollow);
  316. //更新客户信息
  317. Customer customer = new Customer();
  318. customer.setCusId(cusFollowVO.getCusId());
  319. customer.setCusName(cusFollowVO.getCusName());
  320. customer.setCusPhone(cusFollowVO.getCusPhone());
  321. customer.setAddressName(cusFollowVO.getAddressName());
  322. customer.setAddressNo(cusFollowVO.getAddressNo());
  323. customer.setAddressFull(cusFollowVO.getAddressFull()); //全路径地址
  324. customer.setAddressArea(cusFollowVO.getAddressArea()); //省市区
  325. customer.setAddressGcj02(cusFollowVO.getAddressGcj02());//经纬度
  326. customerService.updateByUuid(customer);
  327. CusFollow Follow = cusFollowMapper.selectById(cusFollowVO.getFollowId());
  328. if (Follow == null) {
  329. return ResponseResultUtil.error(ResponseCodeEnum.SELECT_NULL);
  330. } else if (Constant.BasicDataConstant.MEASURE_STATUS_1.getValue().equals(Follow.getMeasureStatus())) {
  331. return ResponseResultUtil.error(ErrorCodeEnum.CUSTOMER_FOLLOW_MEASURE_STATUS_DONE.getCode(),
  332. ErrorCodeEnum.CUSTOMER_FOLLOW_MEASURE_STATUS_DONE.getMessage());
  333. }
  334. StaffEntity staff = authUtils.getStaff();
  335. //设置id
  336. Map<String, Object> uniqueNoteCode = commonService.getUniqueNoteCode(Constant.docNameConstant.RECEIPT.getName(), true);
  337. // 新建一条量尺记录
  338. MeasureReceipt measureReceipt = new MeasureReceipt();
  339. if (cusFollowVO.getFlgAgainMeasure() != null) {
  340. measureReceipt.setFlgAgainMeasure(cusFollowVO.getFlgAgainMeasure());
  341. } else {
  342. measureReceipt.setFlgAgainMeasure(false);
  343. }
  344. measureReceipt.setReceiptId(uniqueNoteCode.get("outId").toString());
  345. measureReceipt.setCusId(cusFollowVO.getCusId());
  346. measureReceipt.setFollowId(cusFollowVO.getFollowId());
  347. measureReceipt.setMeasureStatus(Constant.BasicDataConstant.MEASURE_STATUS_1.getValue());
  348. measureReceipt.setMeasureTime(LocalDateTime.now());
  349. measureReceipt.setMeasureRemarks(cusFollowVO.getMeasureRemarks());
  350. //剩下参数有前台传
  351. measureReceiptService.insert(measureReceipt);
  352. // 新建空间
  353. if (cusFollowVO.getMeasureRoomList() != null && cusFollowVO.getMeasureRoomList().size() > 0) {
  354. for (MeasureRoom measureRoom : cusFollowVO.getMeasureRoomList()) {
  355. //设置ID
  356. Map<String, Object> uniqueNoteCode1 = commonService.getUniqueNoteCode(Constant.docNameConstant.ROOM.getName(), true);
  357. measureRoom.setRoomId(uniqueNoteCode1.get("outId").toString());
  358. measureRoom.setFollowId(cusFollowVO.getFollowId());
  359. measureRoom.setCusId(cusFollowVO.getCusId());
  360. measureRoom.setCpId(authUtils.getStaff().getCpId());
  361. measureRoom.setReceiptId(measureReceipt.getReceiptId());
  362. measureRoomService.insert(measureRoom);
  363. }
  364. }
  365. //修改量尺状态为 已量尺
  366. cusFollow.setMeasureStatus(Constant.BasicDataConstant.MEASURE_STATUS_1.getValue());
  367. //修改跟进
  368. super.updateByUuid(cusFollow);
  369. return ResponseResultUtil.success();
  370. }
  371. /**
  372. * @desc : 编辑量尺回执
  373. * @author : 于继渤
  374. * @date : 2023/1/5 9:39
  375. */
  376. @Transactional(
  377. rollbackFor = {Exception.class}
  378. )
  379. public ResponseResultVO<?> updateMeasure(MeasureReceiptVO measureReceipt) {
  380. // 新建空间
  381. if (measureReceipt.getMeasureRoomList() != null && measureReceipt.getMeasureRoomList().size() > 0) {
  382. for (MeasureRoom measureRoom : measureReceipt.getMeasureRoomList()) {
  383. if (measureRoom.getRoomId() != null) {
  384. measureRoomMapper.deleteByUuid(measureRoom.getRoomId());
  385. //设置ID
  386. Map<String, Object> uniqueNoteCode1 = commonService.getUniqueNoteCode(Constant.docNameConstant.ROOM.getName(), true);
  387. measureRoom.setRoomId(uniqueNoteCode1.get("outId").toString());
  388. measureRoom.setFollowId(measureReceipt.getFollowId());
  389. measureRoom.setCusId(measureReceipt.getCusId());
  390. measureRoom.setCpId(authUtils.getStaff().getCpId());
  391. measureRoom.setReceiptId(measureReceipt.getReceiptId());
  392. measureRoomService.insert(measureRoom);
  393. }
  394. }
  395. MeasureReceipt measureReceipt1 = measureReceiptConvert.convertToPo(measureReceipt);
  396. measureReceiptService.updateByUuid(measureReceipt1);
  397. }
  398. return ResponseResultUtil.success();
  399. }
  400. /**
  401. * @desc : 编辑
  402. * @author : 于继渤
  403. * @date : 2024-03-13 17:03
  404. */
  405. @Transactional(rollbackFor = {Exception.class})
  406. public ResponseResultVO<?> update(CusFollowVO cusFollowVO) {
  407. CusFollow cusFollow = cusFollowConvert.convertToPo(cusFollowVO);
  408. //编辑时更改客户意向要把对应客户也需要更改
  409. if (cusFollowVO.getSaleStatus() != null && (cusFollowVO.getSaleStatus().equals(Constant.saleCustomerStatusConstant.SALE_STATUS_INTE.getName()) || cusFollowVO.getSaleStatus().equals(Constant.saleCustomerStatusConstant.SALE_STATUS_LOST.getName()))) {
  410. //公海客户清空跟进人
  411. if (cusFollowVO.getSaleStatus().equals(Constant.saleCustomerStatusConstant.SALE_STATUS_INTE.getName())) {
  412. customerMapper.updateFollowStaffs(new Customer().setCusId(cusFollowVO.getCusId()));
  413. }
  414. }
  415. if (cusFollowVO.getCusId() != null) {
  416. Customer customer = new Customer();
  417. customer.setCusId(cusFollowVO.getCusId());
  418. customer.setAddressName(cusFollowVO.getAddressName());
  419. customer.setAddressNo(cusFollowVO.getAddressNo());
  420. customer.setCusPhone(cusFollowVO.getCusPhone());
  421. customer.setCusName(cusFollowVO.getCusName());
  422. customer.setOrgId(cusFollowVO.getFollowOrg());
  423. customer.setAddressFull(cusFollowVO.getAddressFull());
  424. customer.setAddressArea(cusFollowVO.getAddressArea());
  425. customer.setSaleStatus(cusFollowVO.getSaleStatus());
  426. customer.setAddressGcj02(cusFollowVO.getAddressGcj02());
  427. //更新客户信息
  428. customerService.updateByUuid(customer);
  429. } else {
  430. //不是陌生接待
  431. if(!cusFollowVO.getFollowStatus().equals(Constant.BasicDataConstant.FOLLOW_STATUS_4.getValue())){
  432. StaffEntity staff = authUtils.getStaff();
  433. Customer customer = new Customer();
  434. customer.setCusName(cusFollowVO.getCusName());
  435. customer.setCusPhone(cusFollowVO.getCusPhone());
  436. customer.setAddressName(cusFollowVO.getAddressName());
  437. customer.setAddressNo(cusFollowVO.getAddressNo());
  438. customer.setOrgId(cusFollowVO.getFollowOrg());
  439. customer.setAddressFull(cusFollowVO.getAddressFull());
  440. customer.setAddressArea(cusFollowVO.getAddressArea());
  441. customer.setSaleStatus(cusFollowVO.getSaleStatus());
  442. customer.setAddressGcj02(cusFollowVO.getAddressGcj02());
  443. customer.setReportStaff(cusFollowVO.getFollowStaff());
  444. customer.setReportTime(LocalDateTime.now());
  445. customer.setCpId(staff.getCpId());
  446. List<String> list = new ArrayList<>();
  447. list.add(staff.getStaffId());
  448. customer.setFollowStaffs(list);
  449. customer.setSaleStatus("客成状态-潜客");
  450. customer.setChannelId(cusFollowVO.getChannelId());
  451. Map<String, Object> customerNoteCode = commonService.getUniqueNoteCode(Constant.docNameConstant.CUSTOMER.getName(), true);
  452. customer.setCusId(customerNoteCode.get("outId").toString());
  453. //新建客户
  454. customerMapper.insert(customer);
  455. cusFollow.setCusId(customer.getCusId());
  456. }
  457. }
  458. //更新总单
  459. super.updateByUuid(cusFollow);
  460. return ResponseResultUtil.success();
  461. }
  462. }