| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- package com.jtzx.crm.module.sys.service;
- import cc.uncarbon.framework.core.context.UserContextHolder;
- import cc.uncarbon.framework.core.exception.BusinessException;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.collection.CollUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.google.common.collect.Lists;
- import com.jtzx.crm.module.sys.entity.SysCustomerDataEntity;
- import com.jtzx.crm.module.sys.entity.SysCustomerFollowAuditEntity;
- import com.jtzx.crm.module.sys.mapper.SysCustomerDataMapper;
- import com.jtzx.crm.module.sys.mapper.SysCustomerFollowAuditMapper;
- import com.jtzx.crm.module.sys.model.response.SysCustomerFollowAuditBO;
- import com.jtzx.crm.module.sys.model.response.SysCustomerFollowAuditDataBO;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Service;
- import java.util.*;
- /**
- * 赢单跟进审核信息
- */
- @RequiredArgsConstructor
- @Service
- @Slf4j
- public class SysCustomerFollowAuditService {
- private final SysCustomerFollowAuditMapper sysCustomerFollowAuditMapper;
- private final SysCustomerDataMapper sysCustomerDataMapper;
- /**
- * 赢单审核申请列表查询
- */
- public SysCustomerFollowAuditDataBO adminList(Integer auditStatus) {
- if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
- throw new BusinessException(403, "无权操作");
- }
- if (!Arrays.asList(0, 1, 2).contains(auditStatus)) {
- throw new BusinessException(400, "审核参数错误");
- }
- SysCustomerFollowAuditDataBO resultData = SysCustomerFollowAuditDataBO.builder().build();
- resultData.setAudit0(0);
- resultData.setAudit1(0);
- resultData.setAudit2(0);
- List<SysCustomerFollowAuditEntity> entityPage = sysCustomerFollowAuditMapper.selectList(
- new QueryWrapper<SysCustomerFollowAuditEntity>()
- .lambda()
- .eq(SysCustomerFollowAuditEntity::getAuditUserId, UserContextHolder.getUserId())
- // 排序
- .orderByDesc(SysCustomerFollowAuditEntity::getCreatedAt)
- );
- if (auditStatus == null) {
- auditStatus = 0;
- }
- List<SysCustomerFollowAuditBO> dataList = Lists.newArrayList();
- if (CollUtil.isNotEmpty(entityPage)) {
- resultData.setAudit0(entityPage.stream().filter(e -> e.getAuditStatus() == 0).toList().size());
- resultData.setAudit1(entityPage.stream().filter(e -> e.getAuditStatus() == 1).toList().size());
- resultData.setAudit2(entityPage.stream().filter(e -> e.getAuditStatus() == 2).toList().size());
- Integer finalAuditStatus = auditStatus;
- List<SysCustomerFollowAuditEntity> list = entityPage.stream()
- .filter(e -> Objects.equals(e.getAuditStatus(), finalAuditStatus))
- .toList();
- List<SysCustomerFollowAuditBO> boList = this.entityList2BOs(list);
- if (CollUtil.isNotEmpty(boList)) {
- dataList.addAll(boList);
- }
- }
- resultData.setAuditData(dataList);
- return resultData;
- }
- /**
- * 审核操作
- * auditStatus 1-通过,2-不通过
- *
- * @param id
- */
- public void auditFollow(Long id, Integer auditStatus) {
- if (!UserContextHolder.getUserContext().getRoles().contains("Admin")) {
- throw new BusinessException(403, "无权操作");
- }
- if (!Arrays.asList(1, 2).contains(auditStatus)) {
- throw new BusinessException(400, "审核参数错误");
- }
- SysCustomerFollowAuditEntity entity = sysCustomerFollowAuditMapper.selectById(id);
- if (entity == null) {
- throw new BusinessException(400, "赢单跟进审核信息不存在");
- }
- SysCustomerDataEntity sysCustomerDataEntity = sysCustomerDataMapper.selectById(entity.getCustomerId());
- if (sysCustomerDataEntity == null) {
- throw new BusinessException(400, "客户数据不存在");
- }
- sysCustomerFollowAuditMapper.updateById(entity);
- List<SysCustomerFollowAuditEntity> sysCustomerFollowAuditEntities =
- sysCustomerFollowAuditMapper.selectList(
- new LambdaQueryWrapper<>(SysCustomerFollowAuditEntity.class)
- .select(
- SysCustomerFollowAuditEntity::getId
- )
- .eq(SysCustomerFollowAuditEntity::getCustomerId, entity.getCustomerId())
- );
- if (CollUtil.isNotEmpty(sysCustomerFollowAuditEntities)) {
- sysCustomerFollowAuditEntities.forEach(e -> {
- e.setAuditStatus(auditStatus);
- e.setAuditUserId(UserContextHolder.getUserId());
- e.setAuditUserName(UserContextHolder.getUserName());
- sysCustomerFollowAuditMapper.updateById(e);
- });
- }
- // 审核通过,设置客户数据表的赢单信息,以及赢单审核信息
- if (auditStatus == 1) {
- sysCustomerDataEntity.setSuccessStatus(1);
- sysCustomerDataEntity.setSuccessUserId(entity.getClaimUserId());
- sysCustomerDataEntity.setSuccessUserName(entity.getClaimUserName());
- sysCustomerDataMapper.updateById(sysCustomerDataEntity);
- }
- }
- /*
- ----------------------------------------------------------------
- 私有方法 private methods
- ----------------------------------------------------------------
- */
- /**
- * 实体转 BO
- *
- * @param entity 实体
- * @return BO
- */
- private SysCustomerFollowAuditBO entity2BO(SysCustomerFollowAuditEntity entity) {
- if (entity == null) {
- return null;
- }
- SysCustomerFollowAuditBO bo = new SysCustomerFollowAuditBO();
- BeanUtil.copyProperties(entity, bo);
- // 可以在此处为BO填充字段
- bo.setId(entity.getId());
- return bo;
- }
- /**
- * 实体 List 转 BO List
- *
- * @param entityList 实体 List
- * @return BO List
- */
- private List<SysCustomerFollowAuditBO> entityList2BOs(List<SysCustomerFollowAuditEntity> entityList) {
- if (CollUtil.isEmpty(entityList)) {
- return Collections.emptyList();
- }
- // 深拷贝
- List<SysCustomerFollowAuditBO> ret = new ArrayList<>(entityList.size());
- entityList.forEach(
- entity -> ret.add(this.entity2BO(entity))
- );
- return ret;
- }
- }
|