|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
package com.daqing.financial.crms.service.impl; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
@ -7,6 +8,7 @@ import com.daqing.financial.crms.dao.CustomerDao; |
|
|
|
|
import com.daqing.financial.crms.feign.HrmsFeignService; |
|
|
|
|
import com.daqing.financial.crms.service.CustomerService; |
|
|
|
|
import com.daqing.framework.domain.crms.CustomerEntity; |
|
|
|
|
import com.daqing.framework.domain.crms.ext.CrmsConstant; |
|
|
|
|
import com.daqing.framework.domain.crms.ext.CustomerTO; |
|
|
|
|
import com.daqing.framework.domain.crms.request.CustomerRequest; |
|
|
|
|
import com.daqing.framework.domain.hrms.ext.EmployeeTO; |
|
|
|
@ -18,8 +20,6 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service("customerService") |
|
|
|
@ -31,36 +31,23 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerDao, CustomerEntity |
|
|
|
|
@Autowired |
|
|
|
|
private HrmsFeignService hrmsFeignService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void t() { |
|
|
|
|
hrmsFeignService.list(new HashMap<>()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 查询客户列表(所有)、根据创建时间筛选、根据客户类型筛选、根据客户编号或者名称搜索 |
|
|
|
|
* |
|
|
|
|
* @param page 当前页 |
|
|
|
|
* @param size 每页条数 |
|
|
|
|
* @param page 当前页 |
|
|
|
|
* @param size 每页条数 |
|
|
|
|
* @param customerRequest 请求参数 |
|
|
|
|
* @return 所有客户以及关联信息并完成分页的集合 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public PageUtils queryList(Integer page, Integer size, CustomerRequest customerRequest) { |
|
|
|
|
|
|
|
|
|
// 没有选择自定义时间且选择了固定的"3个月内、6个月内、9个月内...."时间
|
|
|
|
|
if (customerRequest.getStartTime() == null && customerRequest.getEndTime() == null && customerRequest.getCreateTime() != null) { |
|
|
|
|
if (customerRequest.getCreateTime() != 0) { |
|
|
|
|
String pastTime = pastTime(customerRequest.getCreateTime()); |
|
|
|
|
customerRequest.setStartTime(pastTime); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 选择某段时间内客户信息的时间参数校验
|
|
|
|
|
timeCheckout(customerRequest.getCreateTime(),customerRequest.getStartTime(),customerRequest.getEndTime(),customerRequest); |
|
|
|
|
|
|
|
|
|
// 选择了自定义时间且选择了固定时间则固定时间无效
|
|
|
|
|
if (customerRequest.getCreateTime() != null && (customerRequest.getStartTime() != null || customerRequest.getEndTime() != null)) { |
|
|
|
|
customerRequest.setCreateTime(null); |
|
|
|
|
} |
|
|
|
|
Page<Object> pages = new Page<>(page, size); |
|
|
|
|
//分页参数校验
|
|
|
|
|
Page<Object> pages = pageCheckout(page, size); |
|
|
|
|
//查询所有客户的基本信息
|
|
|
|
|
IPage<CustomerEntity> customerEntityIPage = customerDao.queryList(pages, customerRequest); |
|
|
|
|
|
|
|
|
|
// 获取所有的客户基本信息
|
|
|
|
@ -68,13 +55,87 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerDao, CustomerEntity |
|
|
|
|
// 获取所有的客户经理id
|
|
|
|
|
Long[] ids = customers.stream().map(CustomerEntity::getId).toArray(Long[]::new); |
|
|
|
|
|
|
|
|
|
// 用于拼装客户信息和员工及部门信息的集合
|
|
|
|
|
List<CustomerTO> customerTOS = new ArrayList<>(); |
|
|
|
|
CustomerTO customerTO; |
|
|
|
|
//TODO 远程调用查询客户经理信息的接口
|
|
|
|
|
ResponseResult responseResult = hrmsFeignService.getEmployeeAndDeptById(ids); |
|
|
|
|
List<EmployeeTO> employeeTO = (List<EmployeeTO>) responseResult.getData(); |
|
|
|
|
|
|
|
|
|
// 将客户信息和客户经理及部门信息拼装起来
|
|
|
|
|
List<CustomerTO> customerTOS = jointCustomerEmployee(customers, employeeTO); |
|
|
|
|
|
|
|
|
|
// 属性拷贝,将泛型为CustomerEntity类型的IPage的属性拷贝给泛型为CustomerTO类型的IPage,才能赋值给PageUtils
|
|
|
|
|
IPage<CustomerTO> iPage = new Page<>(); |
|
|
|
|
BeanUtils.copyProperties(customerEntityIPage, iPage); |
|
|
|
|
iPage.setRecords(customerTOS); |
|
|
|
|
|
|
|
|
|
return new PageUtils(iPage); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 选择某段时间内客户信息的时间参数校验 |
|
|
|
|
* @param createTime 创建时间 |
|
|
|
|
* @param startTime 起始时间 |
|
|
|
|
* @param endTime 结束时间 |
|
|
|
|
*/ |
|
|
|
|
private void timeCheckout(Integer createTime, String startTime, String endTime, CustomerRequest customerRequest){ |
|
|
|
|
// 没有选择自定义时间且选择了固定的"3个月内、6个月内、9个月内...."时间
|
|
|
|
|
if (startTime == null && endTime == null && createTime != null) { |
|
|
|
|
if (createTime != 0) { |
|
|
|
|
String pastTime = pastTime(createTime); |
|
|
|
|
customerRequest.setStartTime(pastTime); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 选择了自定义时间且选择了固定时间则固定时间无效
|
|
|
|
|
if (createTime != null && (startTime != null || endTime != null)) { |
|
|
|
|
customerRequest.setCreateTime(null); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 得到过去number月内的时间 |
|
|
|
|
* |
|
|
|
|
* @param number |
|
|
|
|
* @return 字符串类型 |
|
|
|
|
*/ |
|
|
|
|
private String pastTime(Integer number) { |
|
|
|
|
Date date = new Date(); |
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
calendar.setTime(date); |
|
|
|
|
calendar.add(Calendar.MONTH, -number); |
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:ss:mm"); |
|
|
|
|
return sdf.format(calendar.getTime()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 分页参数校验 |
|
|
|
|
* @param page 当前页 |
|
|
|
|
* @param size 每页条数 |
|
|
|
|
*/ |
|
|
|
|
private Page<Object> pageCheckout(Integer page, Integer size){ |
|
|
|
|
Integer count = this.count(new QueryWrapper<CustomerEntity>().eq("del_or_not", CrmsConstant.NOT_DELETE));//查询客户有效总条数
|
|
|
|
|
if (size == null || size < 1) { |
|
|
|
|
size = 10; |
|
|
|
|
} |
|
|
|
|
Integer maxPage = count % size == 0 ? count / size : count / size + 1; |
|
|
|
|
if (page == null || page < 1) { |
|
|
|
|
page = 1; |
|
|
|
|
} |
|
|
|
|
if (page > maxPage) { |
|
|
|
|
page = maxPage; |
|
|
|
|
} |
|
|
|
|
Page<Object> pages = new Page<>(page, size); |
|
|
|
|
return pages; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 拼接客户及其对应的客户经理及部门信息 |
|
|
|
|
* @param customers 客户基本信息集合 |
|
|
|
|
* @param employeeTO 员工及部门信息集合 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<CustomerTO> jointCustomerEmployee(List<CustomerEntity> customers, List<EmployeeTO> employeeTO){ |
|
|
|
|
List<CustomerTO> customerTOS = new ArrayList<>();// 用于拼装客户信息和员工及部门信息的集合
|
|
|
|
|
CustomerTO customerTO; |
|
|
|
|
|
|
|
|
|
// 将客户信息和客户经理及部门信息拼装起来
|
|
|
|
|
for (CustomerEntity customer : customers) { |
|
|
|
|
// 每一个客户对应一个不同的对象
|
|
|
|
@ -100,27 +161,6 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerDao, CustomerEntity |
|
|
|
|
customerTOS.add(customerTO); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 属性拷贝,将泛型为CustomerEntity类型的IPage的属性拷贝给泛型为CustomerTO类型的IPage,才能赋值给PageUtils
|
|
|
|
|
IPage<CustomerTO> iPage = new Page<>(); |
|
|
|
|
BeanUtils.copyProperties(customerEntityIPage, iPage); |
|
|
|
|
iPage.setRecords(customerTOS); |
|
|
|
|
|
|
|
|
|
return new PageUtils(iPage); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 得到过去number月内的时间 |
|
|
|
|
* |
|
|
|
|
* @param number |
|
|
|
|
* @return 字符串类型 |
|
|
|
|
*/ |
|
|
|
|
private String pastTime(Integer number) { |
|
|
|
|
Date date = new Date(); |
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
|
calendar.setTime(date); |
|
|
|
|
calendar.add(Calendar.MONTH, -number); |
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:ss:mm"); |
|
|
|
|
return sdf.format(calendar.getTime()); |
|
|
|
|
return customerTOS; |
|
|
|
|
} |
|
|
|
|
} |