|
@@ -2,11 +2,13 @@ package com.fjhx.customer.service.customer.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.area.utils.AreaUtil;
|
|
|
+import com.fjhx.common.constant.SourceConstant;
|
|
|
import com.fjhx.customer.entity.customer.dto.CustomerDto;
|
|
|
import com.fjhx.customer.entity.customer.dto.CustomerSelectDto;
|
|
|
import com.fjhx.customer.entity.customer.po.Customer;
|
|
@@ -20,15 +22,22 @@ import com.fjhx.customer.service.customer.CustomerService;
|
|
|
import com.fjhx.customer.service.customer.CustomerTopService;
|
|
|
import com.fjhx.customer.service.customer.CustomerUserService;
|
|
|
import com.fjhx.customer.utils.code.CodeEnum;
|
|
|
+import com.fjhx.tenant.entity.dict.dto.DictTenantDataSelectDto;
|
|
|
+import com.fjhx.tenant.entity.dict.vo.DictTenantDataVo;
|
|
|
+import com.fjhx.tenant.service.dict.DictTenantDataService;
|
|
|
import com.obs.services.internal.ServiceException;
|
|
|
+import com.ruoyi.common.core.domain.BasePo;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.ruoyi.system.utils.UserUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -47,6 +56,9 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
|
|
@Autowired
|
|
|
private CustomerTopService customerTopService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DictTenantDataService dictTenantDataService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 查询客户的列表
|
|
@@ -255,5 +267,54 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
|
|
this.updateById(customerDto);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 客户来源统计
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String,Object> sourceStatistics(CustomerSelectDto customerDto) {
|
|
|
+ if (ObjectUtil.isEmpty(customerDto) && ObjectUtil.isEmpty(customerDto.getStatisticsType())){
|
|
|
+ throw new ServiceException("参数异常:统计类型不能为null");
|
|
|
+ }
|
|
|
+ //存放统计数据
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ QueryWrapper<Customer> query = Wrappers.query();
|
|
|
+ if (ObjectUtil.isNotEmpty(customerDto.getType())){
|
|
|
+ //私海客户查询
|
|
|
+ if (customerDto.getType().equals("1")) {
|
|
|
+ query.isNotNull("user_id");
|
|
|
+ //私海客户需要添加权限(自己查自己)
|
|
|
+ query.eq("user_id", SecurityUtils.getUserId());
|
|
|
+ } else if (customerDto.getType().equals("0")) {//公海客户
|
|
|
+ query.and(wrapper1 -> wrapper1.isNull("user_id").or().eq("user_id", ""));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (customerDto.getStatisticsType() == 1){//来源统计
|
|
|
+ query.groupBy("source");
|
|
|
+ query.select("count(*) count,source");
|
|
|
+ }else if (customerDto.getStatisticsType() == 2){//数据类型统计
|
|
|
+ query.groupBy("status");
|
|
|
+ query.select("count(*) count,status");
|
|
|
+ }else if (customerDto.getStatisticsType() == 3){//业务员统计
|
|
|
+ query.groupBy("user_id");
|
|
|
+ query.select("count(*) count,user_id");
|
|
|
+ }
|
|
|
+ List<Customer> customerList = baseMapper.selectList(query);
|
|
|
+
|
|
|
+
|
|
|
+ UserUtil.assignmentNickName(customerList, Customer::getUserId,Customer::setUserName);
|
|
|
+
|
|
|
+ Integer countAmount = customerList.stream().map(customer -> customer.getCount()).reduce(Integer::sum).orElse(0);
|
|
|
+ map.put("countAmount",countAmount);
|
|
|
+ map.put("customerList",customerList);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据字典编码获取字典的数据
|
|
|
+ private List<DictTenantDataVo> getDict(String code){
|
|
|
+ DictTenantDataSelectDto dto = new DictTenantDataSelectDto();
|
|
|
+ dto.setDictCode(code);
|
|
|
+ List<DictTenantDataVo> dictTenantDataServiceList = dictTenantDataService.getList(dto);
|
|
|
+ return dictTenantDataServiceList;
|
|
|
+ }
|
|
|
|
|
|
}
|