Commit db03b10d2419c00cd7d973da12340398e40b1b0b

Authored by YunaiV
1 parent 2d9f5cc4

crm: 增加基于客户查询商机分页

yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java
1 package cn.iocoder.yudao.module.crm.controller.admin.business; 1 package cn.iocoder.yudao.module.crm.controller.admin.business;
2 2
3 import cn.hutool.core.collection.CollUtil; 3 import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.lang.Assert;
4 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 5 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 import cn.iocoder.yudao.framework.common.pojo.PageResult; 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; 7 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
@@ -8,6 +9,7 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; @@ -8,6 +9,7 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
8 import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.*; 9 import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.*;
9 import cn.iocoder.yudao.module.crm.controller.admin.business.vo.status.CrmBusinessStatusQueryVO; 10 import cn.iocoder.yudao.module.crm.controller.admin.business.vo.status.CrmBusinessStatusQueryVO;
10 import cn.iocoder.yudao.module.crm.controller.admin.business.vo.type.CrmBusinessStatusTypeQueryVO; 11 import cn.iocoder.yudao.module.crm.controller.admin.business.vo.type.CrmBusinessStatusTypeQueryVO;
  12 +import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
11 import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert; 13 import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert;
12 import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; 14 import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
13 import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessStatusDO; 15 import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessStatusDO;
@@ -109,7 +111,32 @@ public class CrmBusinessController { @@ -109,7 +111,32 @@ public class CrmBusinessController {
109 List<CrmBusinessStatusTypeDO> statusTypeList = businessStatusTypeService.selectList(queryStatusTypeVO); 111 List<CrmBusinessStatusTypeDO> statusTypeList = businessStatusTypeService.selectList(queryStatusTypeVO);
110 // 处理商机状态名称回显 112 // 处理商机状态名称回显
111 Set<Long> statusIds = pageResult.getList().stream() 113 Set<Long> statusIds = pageResult.getList().stream()
  114 + .map(CrmBusinessDO::getStatusId).filter(Objects::nonNull).collect(Collectors.toSet());
  115 + CrmBusinessStatusQueryVO queryVO = new CrmBusinessStatusQueryVO();
  116 + queryVO.setIdList(statusIds);
  117 + List<CrmBusinessStatusDO> statusList = businessStatusService.selectList(queryVO);
  118 + return success(CrmBusinessConvert.INSTANCE.convertPage(pageResult, customerList, statusTypeList, statusList));
  119 + }
  120 +
  121 + @GetMapping("/page-by-customer")
  122 + @Operation(summary = "获得商机分页,基于指定客户")
  123 + public CommonResult<PageResult<CrmBusinessRespVO>> getBusinessPageByCustomer(@Valid CrmContractPageReqVO pageReqVO) {
  124 + Assert.notNull(pageReqVO.getCustomerId(), "客户编号不能为空");
  125 + PageResult<CrmBusinessDO> pageResult = businessService.getBusinessPageByCustomer(pageReqVO);
  126 + // 处理客户名称回显
  127 + // TODO @ljlleo:可以使用 CollectionUtils.convertSet 替代常用的 stream 操作,更简洁一点;下面几个也是哈;
  128 + Set<Long> customerIds = pageResult.getList().stream()
112 .map(CrmBusinessDO::getCustomerId).filter(Objects::nonNull).collect(Collectors.toSet()); 129 .map(CrmBusinessDO::getCustomerId).filter(Objects::nonNull).collect(Collectors.toSet());
  130 + List<CrmCustomerDO> customerList = customerService.getCustomerList(customerIds);
  131 + // 处理商机状态类型名称回显
  132 + Set<Long> statusTypeIds = pageResult.getList().stream()
  133 + .map(CrmBusinessDO::getStatusTypeId).filter(Objects::nonNull).collect(Collectors.toSet());
  134 + CrmBusinessStatusTypeQueryVO queryStatusTypeVO = new CrmBusinessStatusTypeQueryVO();
  135 + queryStatusTypeVO.setIdList(statusTypeIds);
  136 + List<CrmBusinessStatusTypeDO> statusTypeList = businessStatusTypeService.selectList(queryStatusTypeVO);
  137 + // 处理商机状态名称回显
  138 + Set<Long> statusIds = pageResult.getList().stream()
  139 + .map(CrmBusinessDO::getStatusId).filter(Objects::nonNull).collect(Collectors.toSet());
113 CrmBusinessStatusQueryVO queryVO = new CrmBusinessStatusQueryVO(); 140 CrmBusinessStatusQueryVO queryVO = new CrmBusinessStatusQueryVO();
114 queryVO.setIdList(statusIds); 141 queryVO.setIdList(statusIds);
115 List<CrmBusinessStatusDO> statusList = businessStatusService.selectList(queryVO); 142 List<CrmBusinessStatusDO> statusList = businessStatusService.selectList(queryVO);
@@ -128,12 +155,12 @@ public class CrmBusinessController { @@ -128,12 +155,12 @@ public class CrmBusinessController {
128 @Operation(summary = "导出商机 Excel") 155 @Operation(summary = "导出商机 Excel")
129 @PreAuthorize("@ss.hasPermission('crm:business:export')") 156 @PreAuthorize("@ss.hasPermission('crm:business:export')")
130 @OperateLog(type = EXPORT) 157 @OperateLog(type = EXPORT)
131 - public void exportBusinessExcel(@Valid CrmBusinessExportReqVO exportReqVO, 158 + public void exportBusinessExcel(@Valid CrmBusinessPageReqVO exportReqVO,
132 HttpServletResponse response) throws IOException { 159 HttpServletResponse response) throws IOException {
133 - List<CrmBusinessDO> list = businessService.getBusinessList(exportReqVO); 160 + PageResult<CrmBusinessDO> pageResult = businessService.getBusinessPage(exportReqVO, getLoginUserId());
134 // 导出 Excel 161 // 导出 Excel
135 - List<CrmBusinessExcelVO> datas = CrmBusinessConvert.INSTANCE.convertList02(list);  
136 - ExcelUtils.write(response, "商机.xls", "数据", CrmBusinessExcelVO.class, datas); 162 + ExcelUtils.write(response, "商机.xls", "数据", CrmBusinessExcelVO.class,
  163 + CrmBusinessConvert.INSTANCE.convertList02(pageResult.getList()));
137 } 164 }
138 165
139 @PutMapping("/transfer") 166 @PutMapping("/transfer")
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessExportReqVO.java deleted
1 -package cn.iocoder.yudao.module.crm.controller.admin.business.vo.business;  
2 -  
3 -import io.swagger.v3.oas.annotations.media.Schema;  
4 -import lombok.Data;  
5 -import org.springframework.format.annotation.DateTimeFormat;  
6 -  
7 -import java.math.BigDecimal;  
8 -import java.time.LocalDateTime;  
9 -  
10 -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;  
11 -  
12 -@Schema(description = "管理后台 - 商机 Excel 导出 Request VO,参数和 CrmBusinessPageReqVO 是一致的")  
13 -@Data  
14 -public class CrmBusinessExportReqVO {  
15 -  
16 - @Schema(description = "商机名称", example = "李四")  
17 - private String name;  
18 -  
19 - @Schema(description = "商机状态类型编号", example = "25714")  
20 - private Long statusTypeId;  
21 -  
22 - @Schema(description = "商机状态编号", example = "30320")  
23 - private Long statusId;  
24 -  
25 - @Schema(description = "下次联系时间")  
26 - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)  
27 - private LocalDateTime[] contactNextTime;  
28 -  
29 - @Schema(description = "客户编号", example = "10299")  
30 - private Long customerId;  
31 -  
32 - @Schema(description = "预计成交日期")  
33 - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)  
34 - private LocalDateTime[] dealTime;  
35 -  
36 - @Schema(description = "商机金额", example = "12371")  
37 - private BigDecimal price;  
38 -  
39 - @Schema(description = "整单折扣")  
40 - private BigDecimal discountPercent;  
41 -  
42 - @Schema(description = "产品总金额", example = "12025")  
43 - private BigDecimal productPrice;  
44 -  
45 - @Schema(description = "备注", example = "随便")  
46 - private String remark;  
47 -  
48 - @Schema(description = "负责人的用户编号", example = "25562")  
49 - private Long ownerUserId;  
50 -  
51 - @Schema(description = "创建时间")  
52 - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)  
53 - private LocalDateTime[] createTime;  
54 -  
55 - @Schema(description = "只读权限的用户编号数组")  
56 - private String roUserIds;  
57 -  
58 - @Schema(description = "读写权限的用户编号数组")  
59 - private String rwUserIds;  
60 -  
61 - @Schema(description = "1赢单2输单3无效", example = "1")  
62 - private Integer endStatus;  
63 -  
64 - @Schema(description = "结束时的备注", example = "你说的对")  
65 - private String endRemark;  
66 -  
67 - @Schema(description = "最后跟进时间")  
68 - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)  
69 - private LocalDateTime[] contactLastTime;  
70 -  
71 - @Schema(description = "跟进状态", example = "1")  
72 - private Integer followUpStatus;  
73 -  
74 -}  
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessPageReqVO.java
@@ -15,4 +15,7 @@ public class CrmBusinessPageReqVO extends PageParam { @@ -15,4 +15,7 @@ public class CrmBusinessPageReqVO extends PageParam {
15 @Schema(description = "商机名称", example = "李四") 15 @Schema(description = "商机名称", example = "李四")
16 private String name; 16 private String name;
17 17
  18 + @Schema(description = "客户编号", example = "10795")
  19 + private Long customerId;
  20 +
18 } 21 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactBaseVO.java
@@ -93,7 +93,6 @@ public class CrmContactBaseVO { @@ -93,7 +93,6 @@ public class CrmContactBaseVO {
93 @ExcelProperty(value = "最后跟进时间",order = 6) 93 @ExcelProperty(value = "最后跟进时间",order = 6)
94 private LocalDateTime lastTime; 94 private LocalDateTime lastTime;
95 95
96 -  
97 @Schema(description = "负责人用户编号", example = "14334") 96 @Schema(description = "负责人用户编号", example = "14334")
98 @NotNull(message = "负责人不能为空") 97 @NotNull(message = "负责人不能为空")
99 private Long ownerUserId; 98 private Long ownerUserId;
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/business/CrmBusinessMapper.java
@@ -3,13 +3,12 @@ package cn.iocoder.yudao.module.crm.dal.mysql.business; @@ -3,13 +3,12 @@ package cn.iocoder.yudao.module.crm.dal.mysql.business;
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; 5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
6 -import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessExportReqVO;  
7 import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessPageReqVO; 6 import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessPageReqVO;
  7 +import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
8 import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; 8 import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
9 import org.apache.ibatis.annotations.Mapper; 9 import org.apache.ibatis.annotations.Mapper;
10 10
11 import java.util.Collection; 11 import java.util.Collection;
12 -import java.util.List;  
13 12
14 /** 13 /**
15 * 商机 Mapper 14 * 商机 Mapper
@@ -26,23 +25,10 @@ public interface CrmBusinessMapper extends BaseMapperX&lt;CrmBusinessDO&gt; { @@ -26,23 +25,10 @@ public interface CrmBusinessMapper extends BaseMapperX&lt;CrmBusinessDO&gt; {
26 .orderByDesc(CrmBusinessDO::getId)); 25 .orderByDesc(CrmBusinessDO::getId));
27 } 26 }
28 27
29 - default List<CrmBusinessDO> selectList(CrmBusinessExportReqVO reqVO) {  
30 - return selectList(new LambdaQueryWrapperX<CrmBusinessDO>() 28 + default PageResult<CrmBusinessDO> selectPageByCustomer(CrmContractPageReqVO reqVO) {
  29 + return selectPage(reqVO, new LambdaQueryWrapperX<CrmBusinessDO>()
  30 + .eq(CrmBusinessDO::getCustomerId, reqVO.getCustomerId()) // 必须传递
31 .likeIfPresent(CrmBusinessDO::getName, reqVO.getName()) 31 .likeIfPresent(CrmBusinessDO::getName, reqVO.getName())
32 - .eqIfPresent(CrmBusinessDO::getStatusTypeId, reqVO.getStatusTypeId())  
33 - .eqIfPresent(CrmBusinessDO::getStatusId, reqVO.getStatusId())  
34 - .betweenIfPresent(CrmBusinessDO::getContactNextTime, reqVO.getContactNextTime())  
35 - .eqIfPresent(CrmBusinessDO::getCustomerId, reqVO.getCustomerId())  
36 - .betweenIfPresent(CrmBusinessDO::getDealTime, reqVO.getDealTime())  
37 - .eqIfPresent(CrmBusinessDO::getPrice, reqVO.getPrice())  
38 - .eqIfPresent(CrmBusinessDO::getDiscountPercent, reqVO.getDiscountPercent())  
39 - .eqIfPresent(CrmBusinessDO::getProductPrice, reqVO.getProductPrice())  
40 - .eqIfPresent(CrmBusinessDO::getRemark, reqVO.getRemark())  
41 - .betweenIfPresent(CrmBusinessDO::getCreateTime, reqVO.getCreateTime())  
42 - .eqIfPresent(CrmBusinessDO::getEndStatus, reqVO.getEndStatus())  
43 - .eqIfPresent(CrmBusinessDO::getEndRemark, reqVO.getEndRemark())  
44 - .betweenIfPresent(CrmBusinessDO::getContactLastTime, reqVO.getContactLastTime())  
45 - .eqIfPresent(CrmBusinessDO::getFollowUpStatus, reqVO.getFollowUpStatus())  
46 .orderByDesc(CrmBusinessDO::getId)); 32 .orderByDesc(CrmBusinessDO::getId));
47 } 33 }
48 34
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessService.java
1 package cn.iocoder.yudao.module.crm.service.business; 1 package cn.iocoder.yudao.module.crm.service.business;
2 2
3 import cn.iocoder.yudao.framework.common.pojo.PageResult; 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 -import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.*; 4 +import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessCreateReqVO;
  5 +import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessPageReqVO;
  6 +import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessTransferReqVO;
  7 +import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessUpdateReqVO;
  8 +import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
5 import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; 9 import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
  10 +import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
6 11
7 import javax.validation.Valid; 12 import javax.validation.Valid;
8 import java.util.Collection; 13 import java.util.Collection;
@@ -57,6 +62,8 @@ public interface CrmBusinessService { @@ -57,6 +62,8 @@ public interface CrmBusinessService {
57 /** 62 /**
58 * 获得商机分页 63 * 获得商机分页
59 * 64 *
  65 + * 数据权限:基于 {@link CrmBusinessDO}
  66 + *
60 * @param pageReqVO 分页查询 67 * @param pageReqVO 分页查询
61 * @param userId 用户编号 68 * @param userId 用户编号
62 * @return 商机分页 69 * @return 商机分页
@@ -64,12 +71,14 @@ public interface CrmBusinessService { @@ -64,12 +71,14 @@ public interface CrmBusinessService {
64 PageResult<CrmBusinessDO> getBusinessPage(CrmBusinessPageReqVO pageReqVO, Long userId); 71 PageResult<CrmBusinessDO> getBusinessPage(CrmBusinessPageReqVO pageReqVO, Long userId);
65 72
66 /** 73 /**
67 - * 获得商机列表, 用于 Excel 导出 74 + * 获得商机分页,基于指定客户
68 * 75 *
69 - * @param exportReqVO 查询条件  
70 - * @return 商机列表 76 + * 数据权限:基于 {@link CrmCustomerDO} 读取
  77 + *
  78 + * @param pageReqVO 分页查询
  79 + * @return 联系人分页
71 */ 80 */
72 - List<CrmBusinessDO> getBusinessList(CrmBusinessExportReqVO exportReqVO); 81 + PageResult<CrmBusinessDO> getBusinessPageByCustomer(CrmContractPageReqVO pageReqVO);
73 82
74 /** 83 /**
75 * 商机转移 84 * 商机转移
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
4 import cn.hutool.core.collection.ListUtil; 4 import cn.hutool.core.collection.ListUtil;
5 import cn.iocoder.yudao.framework.common.pojo.PageResult; 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.*; 6 import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.*;
  7 +import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
7 import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert; 8 import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert;
8 import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; 9 import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
9 import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO; 10 import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
@@ -116,8 +117,9 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { @@ -116,8 +117,9 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
116 } 117 }
117 118
118 @Override 119 @Override
119 - public List<CrmBusinessDO> getBusinessList(CrmBusinessExportReqVO exportReqVO) {  
120 - return businessMapper.selectList(exportReqVO); 120 + @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#pageReqVO.customerId", level = CrmPermissionLevelEnum.READ)
  121 + public PageResult<CrmBusinessDO> getBusinessPageByCustomer(CrmContractPageReqVO pageReqVO) {
  122 + return businessMapper.selectPageByCustomer(pageReqVO);
121 } 123 }
122 124
123 @Override 125 @Override
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactService.java
@@ -72,10 +72,10 @@ public interface CrmContactService { @@ -72,10 +72,10 @@ public interface CrmContactService {
72 * 72 *
73 * 数据权限:基于 {@link CrmCustomerDO} 读取 73 * 数据权限:基于 {@link CrmCustomerDO} 读取
74 * 74 *
75 - * @param pageVO 分页查询 75 + * @param pageReqVO 分页查询
76 * @return 联系人分页 76 * @return 联系人分页
77 */ 77 */
78 - PageResult<CrmContactDO> getContactPageByCustomer(CrmContactPageReqVO pageVO); 78 + PageResult<CrmContactDO> getContactPageByCustomer(CrmContactPageReqVO pageReqVO);
79 79
80 /** 80 /**
81 * 获取所有联系人列表 81 * 获取所有联系人列表