SysCustomerFollowAuditService.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. * @param id
  73. */
  74. public void auditSuccess(Long id, Integer auditStatus) {
  75. if(!Arrays.asList(1,2).contains(auditStatus)){
  76. throw new BusinessException(400, "审核参数错误");
  77. }
  78. if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
  79. throw new BusinessException(403, "无权操作");
  80. }
  81. SysCustomerFollowAuditEntity entity = sysCustomerFollowAuditMapper.selectById(id);
  82. if (entity == null) {
  83. throw new BusinessException(400, "赢单跟进审核信息不存在");
  84. }
  85. SysCustomerDataEntity sysCustomerDataEntity = sysCustomerDataMapper.selectById(entity.getCustomerId());
  86. if (sysCustomerDataEntity == null) {
  87. throw new BusinessException(400, "客户数据不存在");
  88. }
  89. sysCustomerFollowAuditMapper.updateById(entity);
  90. List<SysCustomerFollowAuditEntity> sysCustomerFollowAuditEntities =
  91. sysCustomerFollowAuditMapper.selectList(
  92. new LambdaQueryWrapper<>(SysCustomerFollowAuditEntity.class)
  93. .select(
  94. SysCustomerFollowAuditEntity::getId
  95. )
  96. .eq(SysCustomerFollowAuditEntity::getCustomerId, entity.getCustomerId())
  97. );
  98. if (CollUtil.isNotEmpty(sysCustomerFollowAuditEntities)) {
  99. sysCustomerFollowAuditEntities.forEach(e -> {
  100. e.setAuditStatus(auditStatus);
  101. e.setAuditUserId(UserContextHolder.getUserId());
  102. e.setAuditUserName(UserContextHolder.getUserName());
  103. sysCustomerFollowAuditMapper.updateById(e);
  104. });
  105. }
  106. // 审核通过,设置客户数据表的赢单信息,以及赢单审核信息
  107. if (auditStatus == 1) {
  108. sysCustomerDataEntity.setSuccessStatus(1);
  109. sysCustomerDataEntity.setSuccessUserId(entity.getClaimUserId());
  110. sysCustomerDataEntity.setSuccessUserName(entity.getClaimUserName());
  111. sysCustomerDataMapper.updateById(sysCustomerDataEntity);
  112. }
  113. }
  114. /*
  115. ----------------------------------------------------------------
  116. 私有方法 private methods
  117. ----------------------------------------------------------------
  118. */
  119. /**
  120. * 实体转 BO
  121. *
  122. * @param entity 实体
  123. * @return BO
  124. */
  125. private SysCustomerFollowAuditBO entity2BO(SysCustomerFollowAuditEntity entity) {
  126. if (entity == null) {
  127. return null;
  128. }
  129. SysCustomerFollowAuditBO bo = new SysCustomerFollowAuditBO();
  130. BeanUtil.copyProperties(entity, bo);
  131. // 可以在此处为BO填充字段
  132. bo.setId(entity.getId());
  133. return bo;
  134. }
  135. /**
  136. * 实体 List 转 BO List
  137. *
  138. * @param entityList 实体 List
  139. * @return BO List
  140. */
  141. private List<SysCustomerFollowAuditBO> entityList2BOs(List<SysCustomerFollowAuditEntity> entityList) {
  142. if (CollUtil.isEmpty(entityList)) {
  143. return Collections.emptyList();
  144. }
  145. // 深拷贝
  146. List<SysCustomerFollowAuditBO> ret = new ArrayList<>(entityList.size());
  147. entityList.forEach(
  148. entity -> ret.add(this.entity2BO(entity))
  149. );
  150. return ret;
  151. }
  152. }