|
@@ -1,38 +1,32 @@
|
|
|
package com.fjhx.customer.service.customer.impl;
|
|
|
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
-import cn.hutool.core.util.ArrayUtil;
|
|
|
+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.LambdaQueryWrapper;
|
|
|
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.CustomerUserDto;
|
|
|
+import com.fjhx.customer.entity.customer.dto.CustomerDto;
|
|
|
+import com.fjhx.customer.entity.customer.dto.CustomerSelectDto;
|
|
|
import com.fjhx.customer.entity.customer.po.Customer;
|
|
|
+import com.fjhx.customer.entity.customer.po.CustomerFollowRecords;
|
|
|
import com.fjhx.customer.entity.customer.po.CustomerUser;
|
|
|
+import com.fjhx.customer.entity.customer.vo.CustomerVo;
|
|
|
import com.fjhx.customer.mapper.customer.CustomerMapper;
|
|
|
+import com.fjhx.customer.service.customer.CustomerFollowRecordsService;
|
|
|
import com.fjhx.customer.service.customer.CustomerService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.customer.service.customer.CustomerUserService;
|
|
|
import com.fjhx.customer.utils.code.CodeEnum;
|
|
|
import com.obs.services.internal.ServiceException;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.fjhx.customer.entity.customer.vo.CustomerVo;
|
|
|
-import com.fjhx.customer.entity.customer.dto.CustomerSelectDto;
|
|
|
-import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
-import com.fjhx.customer.entity.customer.dto.CustomerDto;
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.rmi.ServerException;
|
|
|
-import java.security.Security;
|
|
|
-import java.util.*;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -47,31 +41,33 @@ import java.util.stream.Collectors;
|
|
|
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {
|
|
|
@Autowired
|
|
|
private CustomerUserService customerUserService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private CustomerFollowRecordsService customerFollowRecordsService;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 查询客户的列表
|
|
|
+ *
|
|
|
* @param dto
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public Page<CustomerVo> getPage(CustomerSelectDto dto) {
|
|
|
LambdaQueryWrapper<Customer> wrapper = Wrappers.<Customer>lambdaQuery();
|
|
|
- wrapper.eq(ObjectUtil.isNotEmpty(dto.getSource()),Customer::getSource,dto.getSource());
|
|
|
- wrapper.eq(ObjectUtil.isNotEmpty(dto.getStatus()),Customer::getStatus,dto.getStatus());
|
|
|
+ wrapper.eq(ObjectUtil.isNotEmpty(dto.getSource()), Customer::getSource, dto.getSource());
|
|
|
+ wrapper.eq(ObjectUtil.isNotEmpty(dto.getStatus()), Customer::getStatus, dto.getStatus());
|
|
|
//客户状态(0:公海客户 1:私海客户)(业务员ID为null为公海客户,业务员ID不为null为私海客户)
|
|
|
- if (ObjectUtil.isNotEmpty(dto.getType())){
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getType())) {
|
|
|
//私海客户查询
|
|
|
- if (dto.getType().equals("1")){
|
|
|
+ if (dto.getType().equals("1")) {
|
|
|
wrapper.isNotNull(Customer::getUserId);
|
|
|
- }else if (dto.getType().equals("0")){
|
|
|
- wrapper.and(wrapper1 -> wrapper1.isNull(Customer::getUserId).or().eq(Customer::getUserId,""));
|
|
|
+ } else if (dto.getType().equals("0")) {
|
|
|
+ wrapper.and(wrapper1 -> wrapper1.isNull(Customer::getUserId).or().eq(Customer::getUserId, ""));
|
|
|
}
|
|
|
}
|
|
|
- if (ObjectUtil.isNotEmpty(dto.getKeyword())){
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getKeyword())) {
|
|
|
//查询客户名称或者客户编码
|
|
|
- wrapper.and(wrapper1 -> wrapper1.like(Customer::getName,dto.getKeyword()).or().eq(Customer::getCode,dto.getKeyword()));
|
|
|
+ wrapper.and(wrapper1 -> wrapper1.like(Customer::getName, dto.getKeyword()).or().eq(Customer::getCode, dto.getKeyword()));
|
|
|
}
|
|
|
wrapper.orderByDesc(Customer::getCreateTime);
|
|
|
Page<CustomerVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
@@ -79,11 +75,21 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
|
|
//复制城市信息
|
|
|
List<CustomerVo> records = page.getRecords();
|
|
|
AreaUtil.setAreaName(records);
|
|
|
+ //赋值客户跟进记录
|
|
|
+ List<Long> customerIds = records.stream().map(Customer::getId).collect(Collectors.toList());
|
|
|
+ if (ObjectUtil.isNotEmpty(customerIds)) {
|
|
|
+ Map<Long, List<CustomerFollowRecords>> longListMap = customerFollowRecordsService.mapKGroup(CustomerFollowRecords::getCustomerId,
|
|
|
+ q -> q.in(CustomerFollowRecords::getCustomerId, customerIds));
|
|
|
+ for (CustomerVo record : records) {
|
|
|
+ record.setCustomerFollowRecordsList(longListMap.get(record.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询客户的详情
|
|
|
+ *
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
@@ -92,7 +98,7 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
|
|
//查询客户表的信息
|
|
|
Customer Customer = this.getById(id);
|
|
|
CustomerVo result = BeanUtil.toBean(Customer, CustomerVo.class);
|
|
|
- if (ObjectUtil.isEmpty(result)){
|
|
|
+ if (ObjectUtil.isEmpty(result)) {
|
|
|
throw new ServiceException("没有找到该用户信息");
|
|
|
}
|
|
|
//查询客户-联系人表的信息
|
|
@@ -105,6 +111,7 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
|
|
|
|
|
/**
|
|
|
* 添加客户表的数据
|
|
|
+ *
|
|
|
* @param customerDto
|
|
|
*/
|
|
|
@Override
|
|
@@ -118,6 +125,7 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
|
|
|
|
|
/**
|
|
|
* 修改客户表的数据
|
|
|
+ *
|
|
|
* @param customerDto
|
|
|
*/
|
|
|
@Transactional(rollbackFor = {Exception.class})
|
|
@@ -126,13 +134,14 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
|
|
//修改客户表的信息
|
|
|
this.updateById(customerDto);
|
|
|
//删除客户-用户表的信息
|
|
|
- customerUserService.remove(Wrappers.<CustomerUser>lambdaQuery().eq(CustomerUser::getCustomerId,customerDto.getId()));
|
|
|
+ customerUserService.remove(Wrappers.<CustomerUser>lambdaQuery().eq(CustomerUser::getCustomerId, customerDto.getId()));
|
|
|
//添加客户-联系人表的信息
|
|
|
saveCustomerUse(customerDto);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除客户表的数据
|
|
|
+ *
|
|
|
* @param
|
|
|
*/
|
|
|
@Override
|
|
@@ -141,7 +150,7 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
|
|
//删除客户表的数据
|
|
|
this.removeById(id);
|
|
|
//删除客户-联系人表的数据
|
|
|
- customerUserService.remove(Wrappers.<CustomerUser>lambdaQuery().eq(CustomerUser::getCustomerId,id));
|
|
|
+ customerUserService.remove(Wrappers.<CustomerUser>lambdaQuery().eq(CustomerUser::getCustomerId, id));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -150,24 +159,34 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
|
|
@Override
|
|
|
public Page<CustomerVo> privateSeaPage(CustomerSelectDto dto) {
|
|
|
LambdaQueryWrapper<Customer> wrapper = Wrappers.<Customer>lambdaQuery();
|
|
|
- wrapper.eq(ObjectUtil.isNotEmpty(dto.getSource()),Customer::getSource,dto.getSource());
|
|
|
- wrapper.eq(ObjectUtil.isNotEmpty(dto.getStatus()),Customer::getStatus,dto.getStatus());
|
|
|
- if (ObjectUtil.isNotEmpty(dto.getKeyword())){
|
|
|
+ wrapper.eq(ObjectUtil.isNotEmpty(dto.getSource()), Customer::getSource, dto.getSource());
|
|
|
+ wrapper.eq(ObjectUtil.isNotEmpty(dto.getStatus()), Customer::getStatus, dto.getStatus());
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getKeyword())) {
|
|
|
//查询客户名称或者客户编码
|
|
|
- wrapper.and(wrapper1 -> wrapper1.like(Customer::getName,dto.getKeyword()).or().eq(Customer::getCode,dto.getKeyword()));
|
|
|
+ wrapper.and(wrapper1 -> wrapper1.like(Customer::getName, dto.getKeyword()).or().eq(Customer::getCode, dto.getKeyword()));
|
|
|
}
|
|
|
//添加权限(自己看自己)
|
|
|
wrapper.eq(Customer::getUserId, SecurityUtils.getUserId());
|
|
|
wrapper.orderByDesc(Customer::getCreateTime);
|
|
|
- Page<CustomerVo> page =baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ Page<CustomerVo> page = baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
//复制城市信息
|
|
|
List<CustomerVo> records = page.getRecords();
|
|
|
AreaUtil.setAreaName(records);
|
|
|
+ //赋值客户跟进记录
|
|
|
+ List<Long> customerIds = records.stream().map(Customer::getId).collect(Collectors.toList());
|
|
|
+ if (ObjectUtil.isNotEmpty(customerIds)) {
|
|
|
+ Map<Long, List<CustomerFollowRecords>> longListMap = customerFollowRecordsService.mapKGroup(CustomerFollowRecords::getCustomerId,
|
|
|
+ q -> q.in(CustomerFollowRecords::getCustomerId, customerIds));
|
|
|
+ for (CustomerVo record : records) {
|
|
|
+ record.setCustomerFollowRecordsList(longListMap.get(record.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 来源存量(客户分析)
|
|
|
+ *
|
|
|
* @param query
|
|
|
* @return
|
|
|
*/
|
|
@@ -178,6 +197,7 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
|
|
|
|
|
/**
|
|
|
* 来源增量(客户分析)
|
|
|
+ *
|
|
|
* @param query
|
|
|
* @return
|
|
|
*/
|
|
@@ -188,7 +208,7 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
|
|
|
|
|
|
|
|
//添加客户用户表的信息
|
|
|
- private void saveCustomerUse(CustomerDto customerDto){
|
|
|
+ private void saveCustomerUse(CustomerDto customerDto) {
|
|
|
List<CustomerUser> customerUserDtoList = customerDto.getCustomerUserList();
|
|
|
customerUserDtoList.forEach(customerUserDto -> customerUserDto.setCustomerId(customerDto.getId()));
|
|
|
customerUserService.saveBatch(customerUserDtoList);
|