SysCustomerFollowAuditService.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package com.jtzx.crm.module.sys.service;
  2. import cc.uncarbon.framework.core.context.UserContextHolder;
  3. import cc.uncarbon.framework.core.exception.BusinessException;
  4. import cn.hutool.core.bean.BeanUtil;
  5. import cn.hutool.core.collection.CollUtil;
  6. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  7. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  8. import com.google.common.collect.Lists;
  9. import com.jtzx.crm.module.sys.entity.SysCustomerDataEntity;
  10. import com.jtzx.crm.module.sys.entity.SysCustomerFollowAuditEntity;
  11. import com.jtzx.crm.module.sys.mapper.SysCustomerDataMapper;
  12. import com.jtzx.crm.module.sys.mapper.SysCustomerFollowAuditMapper;
  13. import com.jtzx.crm.module.sys.model.response.SysCustomerFollowAuditBO;
  14. import com.jtzx.crm.module.sys.model.response.SysCustomerFollowAuditDataBO;
  15. import lombok.RequiredArgsConstructor;
  16. import lombok.extern.slf4j.Slf4j;
  17. import org.springframework.stereotype.Service;
  18. import java.util.*;
  19. /**
  20. * 赢单跟进审核信息
  21. */
  22. @RequiredArgsConstructor
  23. @Service
  24. @Slf4j
  25. public class SysCustomerFollowAuditService {
  26. private final SysCustomerFollowAuditMapper sysCustomerFollowAuditMapper;
  27. private final SysCustomerDataMapper sysCustomerDataMapper;
  28. /**
  29. * 赢单审核申请列表查询
  30. */
  31. public SysCustomerFollowAuditDataBO adminList(Integer auditStatus) {
  32. if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
  33. throw new BusinessException(403, "无权操作");
  34. }
  35. if (!Arrays.asList(0, 1, 2).contains(auditStatus)) {
  36. throw new BusinessException(400, "审核参数错误");
  37. }
  38. SysCustomerFollowAuditDataBO resultData = SysCustomerFollowAuditDataBO.builder().build();
  39. resultData.setAudit0(0);
  40. resultData.setAudit1(0);
  41. resultData.setAudit2(0);
  42. List<SysCustomerFollowAuditEntity> entityPage = sysCustomerFollowAuditMapper.selectList(
  43. new QueryWrapper<SysCustomerFollowAuditEntity>()
  44. .lambda()
  45. .eq(SysCustomerFollowAuditEntity::getAuditUserId, UserContextHolder.getUserId())
  46. // 排序
  47. .orderByDesc(SysCustomerFollowAuditEntity::getCreatedAt)
  48. );
  49. if (auditStatus == null) {
  50. auditStatus = 0;
  51. }
  52. List<SysCustomerFollowAuditBO> dataList = Lists.newArrayList();
  53. if (CollUtil.isNotEmpty(entityPage)) {
  54. resultData.setAudit0(entityPage.stream().filter(e -> e.getAuditStatus() == 0).toList().size());
  55. resultData.setAudit1(entityPage.stream().filter(e -> e.getAuditStatus() == 1).toList().size());
  56. resultData.setAudit2(entityPage.stream().filter(e -> e.getAuditStatus() == 2).toList().size());
  57. Integer finalAuditStatus = auditStatus;
  58. List<SysCustomerFollowAuditEntity> list = entityPage.stream()
  59. .filter(e -> Objects.equals(e.getAuditStatus(), finalAuditStatus))
  60. .toList();
  61. List<SysCustomerFollowAuditBO> boList = this.entityList2BOs(list);
  62. if (CollUtil.isNotEmpty(boList)) {
  63. dataList.addAll(boList);
  64. }
  65. }
  66. resultData.setAuditData(dataList);
  67. return resultData;
  68. }
  69. /**
  70. * 审核操作
  71. * auditStatus 1-通过,2-不通过
  72. *
  73. * @param id
  74. */
  75. public void auditFollow(Long id, Integer auditStatus) {
  76. if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
  77. throw new BusinessException(403, "无权操作");
  78. }
  79. if (!Arrays.asList(1, 2).contains(auditStatus)) {
  80. throw new BusinessException(400, "审核参数错误");
  81. }
  82. SysCustomerFollowAuditEntity entity = sysCustomerFollowAuditMapper.selectById(id);
  83. if (entity == null) {
  84. throw new BusinessException(400, "赢单跟进审核信息不存在");
  85. }
  86. SysCustomerDataEntity sysCustomerDataEntity = sysCustomerDataMapper.selectById(entity.getCustomerId());
  87. if (sysCustomerDataEntity == null) {
  88. throw new BusinessException(400, "客户数据不存在");
  89. }
  90. sysCustomerFollowAuditMapper.updateById(entity);
  91. List<SysCustomerFollowAuditEntity> sysCustomerFollowAuditEntities =
  92. sysCustomerFollowAuditMapper.selectList(
  93. new LambdaQueryWrapper<>(SysCustomerFollowAuditEntity.class)
  94. .select(
  95. SysCustomerFollowAuditEntity::getId
  96. )
  97. .eq(SysCustomerFollowAuditEntity::getCustomerId, entity.getCustomerId())
  98. );
  99. if (CollUtil.isNotEmpty(sysCustomerFollowAuditEntities)) {
  100. sysCustomerFollowAuditEntities.forEach(e -> {
  101. e.setAuditStatus(auditStatus);
  102. e.setAuditUserId(UserContextHolder.getUserId());
  103. e.setAuditUserName(UserContextHolder.getUserName());
  104. sysCustomerFollowAuditMapper.updateById(e);
  105. });
  106. }
  107. // 审核通过,设置客户数据表的赢单信息,以及赢单审核信息
  108. if (auditStatus == 1) {
  109. sysCustomerDataEntity.setSuccessStatus(1);
  110. sysCustomerDataEntity.setSuccessUserId(entity.getClaimUserId());
  111. sysCustomerDataEntity.setSuccessUserName(entity.getClaimUserName());
  112. sysCustomerDataMapper.updateById(sysCustomerDataEntity);
  113. }
  114. }
  115. /*
  116. ----------------------------------------------------------------
  117. 私有方法 private methods
  118. ----------------------------------------------------------------
  119. */
  120. /**
  121. * 实体转 BO
  122. *
  123. * @param entity 实体
  124. * @return BO
  125. */
  126. private SysCustomerFollowAuditBO entity2BO(SysCustomerFollowAuditEntity entity) {
  127. if (entity == null) {
  128. return null;
  129. }
  130. SysCustomerFollowAuditBO bo = new SysCustomerFollowAuditBO();
  131. BeanUtil.copyProperties(entity, bo);
  132. // 可以在此处为BO填充字段
  133. bo.setId(entity.getId());
  134. return bo;
  135. }
  136. /**
  137. * 实体 List 转 BO List
  138. *
  139. * @param entityList 实体 List
  140. * @return BO List
  141. */
  142. private List<SysCustomerFollowAuditBO> entityList2BOs(List<SysCustomerFollowAuditEntity> entityList) {
  143. if (CollUtil.isEmpty(entityList)) {
  144. return Collections.emptyList();
  145. }
  146. // 深拷贝
  147. List<SysCustomerFollowAuditBO> ret = new ArrayList<>(entityList.size());
  148. entityList.forEach(
  149. entity -> ret.add(this.entity2BO(entity))
  150. );
  151. return ret;
  152. }
  153. }