From 033b5dabba4608fd95c120739e18316a92e36ed5 Mon Sep 17 00:00:00 2001 From: river <1376754470@qq.com> Date: Fri, 11 Sep 2020 12:41:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E8=B5=84=E6=BA=90=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../crms/controller/CustomerController.java | 10 ++ .../service/impl/CustomerServiceImpl.java | 134 ++++++++++++------ .../crms/DqFinancialCrmsApplicationTests.java | 7 - .../hrms/DqFinancialHrmsApplication.java | 1 - .../domain/crms/ext/CrmsConstant.java | 34 +++++ 5 files changed, 131 insertions(+), 55 deletions(-) diff --git a/dq-financial-crms/src/main/java/com/daqing/financial/crms/controller/CustomerController.java b/dq-financial-crms/src/main/java/com/daqing/financial/crms/controller/CustomerController.java index 9c8cd15d..0548df72 100644 --- a/dq-financial-crms/src/main/java/com/daqing/financial/crms/controller/CustomerController.java +++ b/dq-financial-crms/src/main/java/com/daqing/financial/crms/controller/CustomerController.java @@ -4,6 +4,7 @@ import com.daqing.financial.crms.CustomerControllerApi; 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.request.CustomerRequest; import com.daqing.framework.model.response.ResponseResult; import com.daqing.framework.utils.PageUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -39,5 +40,14 @@ public class CustomerController implements CustomerControllerApi { return hrmsFeignService.list(params); } + /** + * 查询客户列表(所有)、根据创建时间筛选、根据客户类型筛选、根据客户编号或者名称搜索 + */ + @GetMapping("/queryList") + public ResponseResult queryList(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, CustomerRequest customerRequest) { + PageUtils list = customerService.queryList(page, size, customerRequest); + + return new ResponseResult().SUCCESS(list); + } } diff --git a/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/impl/CustomerServiceImpl.java b/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/impl/CustomerServiceImpl.java index 92d5a19b..a348a508 100644 --- a/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/impl/CustomerServiceImpl.java +++ b/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/impl/CustomerServiceImpl.java @@ -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()); - } - - /** * 查询客户列表(所有)、根据创建时间筛选、根据客户类型筛选、根据客户编号或者名称搜索 * - * @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 pages = new Page<>(page, size); + //分页参数校验 + Page pages = pageCheckout(page, size); + //查询所有客户的基本信息 IPage customerEntityIPage = customerDao.queryList(pages, customerRequest); // 获取所有的客户基本信息 @@ -68,13 +55,87 @@ public class CustomerServiceImpl extends ServiceImpl customerTOS = new ArrayList<>(); - CustomerTO customerTO; //TODO 远程调用查询客户经理信息的接口 ResponseResult responseResult = hrmsFeignService.getEmployeeAndDeptById(ids); List employeeTO = (List) responseResult.getData(); + // 将客户信息和客户经理及部门信息拼装起来 + List customerTOS = jointCustomerEmployee(customers, employeeTO); + + // 属性拷贝,将泛型为CustomerEntity类型的IPage的属性拷贝给泛型为CustomerTO类型的IPage,才能赋值给PageUtils + IPage 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 pageCheckout(Integer page, Integer size){ + Integer count = this.count(new QueryWrapper().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 pages = new Page<>(page, size); + return pages; + } + + /** + * 拼接客户及其对应的客户经理及部门信息 + * @param customers 客户基本信息集合 + * @param employeeTO 员工及部门信息集合 + * @return + */ + private List jointCustomerEmployee(List customers, List employeeTO){ + List customerTOS = new ArrayList<>();// 用于拼装客户信息和员工及部门信息的集合 + CustomerTO customerTO; + // 将客户信息和客户经理及部门信息拼装起来 for (CustomerEntity customer : customers) { // 每一个客户对应一个不同的对象 @@ -100,27 +161,6 @@ public class CustomerServiceImpl extends ServiceImpl 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; } } \ No newline at end of file diff --git a/dq-financial-crms/src/test/java/com/daqing/financial/crms/DqFinancialCrmsApplicationTests.java b/dq-financial-crms/src/test/java/com/daqing/financial/crms/DqFinancialCrmsApplicationTests.java index 4d608576..cbf19786 100644 --- a/dq-financial-crms/src/test/java/com/daqing/financial/crms/DqFinancialCrmsApplicationTests.java +++ b/dq-financial-crms/src/test/java/com/daqing/financial/crms/DqFinancialCrmsApplicationTests.java @@ -33,11 +33,4 @@ public class DqFinancialCrmsApplicationTests { List list1 = (List) list.getList(); list1.forEach(customerEntity -> System.out.println(customerEntity)); } - - @Test - public void t() { - customerServiceimpl.t(); - } - - } diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/DqFinancialHrmsApplication.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/DqFinancialHrmsApplication.java index 285e9a6d..81c5eefa 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/DqFinancialHrmsApplication.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/DqFinancialHrmsApplication.java @@ -15,5 +15,4 @@ public class DqFinancialHrmsApplication { public static void main(String[] args) { SpringApplication.run(DqFinancialHrmsApplication.class, args); } - } diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/crms/ext/CrmsConstant.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/crms/ext/CrmsConstant.java index 116af1ec..1f7fcfff 100644 --- a/dq-framework-model/src/main/java/com/daqing/framework/domain/crms/ext/CrmsConstant.java +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/crms/ext/CrmsConstant.java @@ -12,6 +12,40 @@ import lombok.Setter; */ public class CrmsConstant { + /** + * 未删除 + */ + public static final Integer NOT_DELETE = 0; + +// /** +// * 是否删除:1、已删除,0:未删除 +// */ +// @AllArgsConstructor +// public enum isDel { +// /** +// * 已删除 +// */ +// DEL(1, "已删除"), +// /** +// * 未删除 +// */ +// NOT_DEL(0, "未删除"); +// +// /** +// * 类型代号 +// */ +// @Setter +// @Getter +// private Integer code; +// +// /** +// * 类型名称 +// */ +// @Setter +// @Getter +// private String description; +// } + /** * 客户类型:1、企业类型,0:个人类型 */