Commit bba32c6ba3ce29b8a72977688850906cf58ab335

Authored by 芋道源码
Committed by Gitee
2 parents 5955f39e 3213cad3

!866 新增:CRM 商业智能,其他排名接口

Merge pull request !866 from 安浩浩/develop
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/bi/CrmBiRankController.java
@@ -42,4 +42,46 @@ public class CrmBiRankController { @@ -42,4 +42,46 @@ public class CrmBiRankController {
42 return success(rankingService.getReceivablePriceRank(rankingReqVO)); 42 return success(rankingService.getReceivablePriceRank(rankingReqVO));
43 } 43 }
44 44
  45 + @GetMapping("/get-contract-count-rank")
  46 + @Operation(summary = "获得签约合同数量排行榜")
  47 + @PreAuthorize("@ss.hasPermission('crm:bi-rank:query')")
  48 + public CommonResult<List<CrmBiRanKRespVO>> getContractCountRank(@Valid CrmBiRankReqVO rankingReqVO) {
  49 + return success(rankingService.getContractCountRank(rankingReqVO));
  50 + }
  51 +
  52 + @GetMapping("/get-product-sales-rank")
  53 + @Operation(summary = "获得产品销量排行榜")
  54 + @PreAuthorize("@ss.hasPermission('crm:bi-rank:query')")
  55 + public CommonResult<List<CrmBiRanKRespVO>> getProductSalesRank(@Valid CrmBiRankReqVO rankingReqVO) {
  56 + return success(rankingService.getProductSalesRank(rankingReqVO));
  57 + }
  58 +
  59 + @GetMapping("/get-customer-count-rank")
  60 + @Operation(summary = "获得新增客户数排行榜")
  61 + @PreAuthorize("@ss.hasPermission('crm:bi-rank:query')")
  62 + public CommonResult<List<CrmBiRanKRespVO>> getCustomerCountRank(@Valid CrmBiRankReqVO rankingReqVO) {
  63 + return success(rankingService.getCustomerCountRank(rankingReqVO));
  64 + }
  65 +
  66 + @GetMapping("/get-contacts-count-rank")
  67 + @Operation(summary = "获得新增联系人数排行榜")
  68 + @PreAuthorize("@ss.hasPermission('crm:bi-rank:query')")
  69 + public CommonResult<List<CrmBiRanKRespVO>> getContactsCountRank(@Valid CrmBiRankReqVO rankingReqVO) {
  70 + return success(rankingService.getContactsCountRank(rankingReqVO));
  71 + }
  72 +
  73 + @GetMapping("/get-follow-count-rank")
  74 + @Operation(summary = "获得跟进次数排行榜")
  75 + @PreAuthorize("@ss.hasPermission('crm:bi-rank:query')")
  76 + public CommonResult<List<CrmBiRanKRespVO>> getFollowCountRank(@Valid CrmBiRankReqVO rankingReqVO) {
  77 + return success(rankingService.getFollowCountRank(rankingReqVO));
  78 + }
  79 +
  80 + @GetMapping("/get-follow-customer-count-rank")
  81 + @Operation(summary = "获得跟进客户数排行榜")
  82 + @PreAuthorize("@ss.hasPermission('crm:bi-rank:query')")
  83 + public CommonResult<List<CrmBiRanKRespVO>> getFollowCustomerCountRank(@Valid CrmBiRankReqVO rankingReqVO) {
  84 + return success(rankingService.getFollowCustomerCountRank(rankingReqVO));
  85 + }
  86 +
45 } 87 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/bi/CrmBiRankingMapper.java
@@ -30,4 +30,51 @@ public interface CrmBiRankingMapper { @@ -30,4 +30,51 @@ public interface CrmBiRankingMapper {
30 */ 30 */
31 List<CrmBiRanKRespVO> selectReceivablePriceRank(CrmBiRankReqVO rankReqVO); 31 List<CrmBiRanKRespVO> selectReceivablePriceRank(CrmBiRankReqVO rankReqVO);
32 32
  33 + /**
  34 + * 查询签约合同数量排行榜
  35 + *
  36 + * @param rankReqVO 参数
  37 + * @return 签约合同数量排行榜
  38 + */
  39 + List<CrmBiRanKRespVO> selectContractCountRank(CrmBiRankReqVO rankReqVO);
  40 +
  41 + /**
  42 + * 查询产品销量排行榜
  43 + *
  44 + * @param rankReqVO 参数
  45 + * @return 产品销量排行榜
  46 + */
  47 + List<CrmBiRanKRespVO> selectProductSalesRank(CrmBiRankReqVO rankReqVO);
  48 +
  49 + /**
  50 + * 查询新增客户数排行榜
  51 + *
  52 + * @param rankReqVO 参数
  53 + * @return 新增客户数排行榜
  54 + */
  55 + List<CrmBiRanKRespVO> selectCustomerCountRank(CrmBiRankReqVO rankReqVO);
  56 +
  57 + /**
  58 + * 查询联系人数量排行榜
  59 + *
  60 + * @param rankReqVO 参数
  61 + * @return 联系人数量排行榜
  62 + */
  63 + List<CrmBiRanKRespVO> selectContactsCountRank(CrmBiRankReqVO rankReqVO);
  64 +
  65 + /**
  66 + * 查询跟进次数排行榜
  67 + *
  68 + * @param rankReqVO 参数
  69 + * @return 跟进次数排行榜
  70 + */
  71 + List<CrmBiRanKRespVO> selectFollowCountRank(CrmBiRankReqVO rankReqVO);
  72 +
  73 + /**
  74 + * 查询跟进客户数排行榜
  75 + *
  76 + * @param rankReqVO 参数
  77 + * @return 跟进客户数排行榜
  78 + */
  79 + List<CrmBiRanKRespVO> selectFollowCustomerCountRank(CrmBiRankReqVO rankReqVO);
33 } 80 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/bi/CrmBiRankingService.java
@@ -29,4 +29,51 @@ public interface CrmBiRankingService { @@ -29,4 +29,51 @@ public interface CrmBiRankingService {
29 */ 29 */
30 List<CrmBiRanKRespVO> getReceivablePriceRank(CrmBiRankReqVO rankReqVO); 30 List<CrmBiRanKRespVO> getReceivablePriceRank(CrmBiRankReqVO rankReqVO);
31 31
  32 + /**
  33 + * 获得签约合同数量排行榜
  34 + *
  35 + * @param rankReqVO 排行参数
  36 + * @return 签约合同数量排行榜
  37 + */
  38 + List<CrmBiRanKRespVO> getContractCountRank(CrmBiRankReqVO rankReqVO);
  39 +
  40 + /**
  41 + * 获得产品销量排行榜
  42 + *
  43 + * @param rankReqVO 排行参数
  44 + * @return 产品销量排行榜
  45 + */
  46 + List<CrmBiRanKRespVO> getProductSalesRank(CrmBiRankReqVO rankReqVO);
  47 +
  48 + /**
  49 + * 获得新增客户数排行榜
  50 + *
  51 + * @param rankReqVO 排行参数
  52 + * @return 新增客户数排行榜
  53 + */
  54 + List<CrmBiRanKRespVO> getCustomerCountRank(CrmBiRankReqVO rankReqVO);
  55 +
  56 + /**
  57 + * 获得联系人数量排行榜
  58 + *
  59 + * @param rankReqVO 排行参数
  60 + * @return 联系人数量排行榜
  61 + */
  62 + List<CrmBiRanKRespVO> getContactsCountRank(CrmBiRankReqVO rankReqVO);
  63 +
  64 + /**
  65 + * 获得跟进次数排行榜
  66 + *
  67 + * @param rankReqVO 排行参数
  68 + * @return 跟进次数排行榜
  69 + */
  70 + List<CrmBiRanKRespVO> getFollowCountRank(CrmBiRankReqVO rankReqVO);
  71 +
  72 + /**
  73 + * 获得跟进客户数排行榜
  74 + *
  75 + * @param rankReqVO 排行参数
  76 + * @return 跟进客户数排行榜
  77 + */
  78 + List<CrmBiRanKRespVO> getFollowCustomerCountRank(CrmBiRankReqVO rankReqVO);
32 } 79 }
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/bi/CrmBiRankingServiceImpl.java
@@ -49,6 +49,36 @@ public class CrmBiRankingServiceImpl implements CrmBiRankingService { @@ -49,6 +49,36 @@ public class CrmBiRankingServiceImpl implements CrmBiRankingService {
49 return getRank(rankReqVO, biRankingMapper::selectReceivablePriceRank); 49 return getRank(rankReqVO, biRankingMapper::selectReceivablePriceRank);
50 } 50 }
51 51
  52 + @Override
  53 + public List<CrmBiRanKRespVO> getContractCountRank(CrmBiRankReqVO rankReqVO) {
  54 + return getRank(rankReqVO, biRankingMapper::selectContractCountRank);
  55 + }
  56 +
  57 + @Override
  58 + public List<CrmBiRanKRespVO> getProductSalesRank(CrmBiRankReqVO rankReqVO) {
  59 + return getRank(rankReqVO, biRankingMapper::selectProductSalesRank);
  60 + }
  61 +
  62 + @Override
  63 + public List<CrmBiRanKRespVO> getCustomerCountRank(CrmBiRankReqVO rankReqVO) {
  64 + return getRank(rankReqVO, biRankingMapper::selectCustomerCountRank);
  65 + }
  66 +
  67 + @Override
  68 + public List<CrmBiRanKRespVO> getContactsCountRank(CrmBiRankReqVO rankReqVO) {
  69 + return getRank(rankReqVO, biRankingMapper::selectContactsCountRank);
  70 + }
  71 +
  72 + @Override
  73 + public List<CrmBiRanKRespVO> getFollowCountRank(CrmBiRankReqVO rankReqVO) {
  74 + return getRank(rankReqVO, biRankingMapper::selectFollowCountRank);
  75 + }
  76 +
  77 + @Override
  78 + public List<CrmBiRanKRespVO> getFollowCustomerCountRank(CrmBiRankReqVO rankReqVO) {
  79 + return getRank(rankReqVO, biRankingMapper::selectFollowCustomerCountRank);
  80 + }
  81 +
52 /** 82 /**
53 * 获得排行版数据 83 * 获得排行版数据
54 * 84 *
yudao-module-crm/yudao-module-crm-biz/src/main/resources/mapper/bi/CrmBiRankingMapper.xml
@@ -9,10 +9,11 @@ @@ -9,10 +9,11 @@
9 WHERE deleted = 0 9 WHERE deleted = 0
10 AND audit_status = 20 10 AND audit_status = 20
11 and owner_user_id in 11 and owner_user_id in
12 - <foreach collection="userIds" item="userId" open="(" close=")" separator=",">  
13 - #{userId}  
14 - </foreach>  
15 - AND order_date between #{times[0],javaType=java.time.LocalDateTime} and #{times[1],javaType=java.time.LocalDateTime} 12 + <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  13 + #{userId}
  14 + </foreach>
  15 + AND order_date between #{times[0],javaType=java.time.LocalDateTime} and
  16 + #{times[1],javaType=java.time.LocalDateTime}
16 GROUP BY owner_user_id 17 GROUP BY owner_user_id
17 </select> 18 </select>
18 19
@@ -22,12 +23,102 @@ @@ -22,12 +23,102 @@
22 FROM crm_receivable 23 FROM crm_receivable
23 WHERE deleted = 0 24 WHERE deleted = 0
24 AND audit_status = 20 25 AND audit_status = 20
25 - and owner_user_id in  
26 - <foreach collection="userIds" item="userId" open="(" close=")" separator=",">  
27 - #{userId}  
28 - </foreach>  
29 - AND return_time between #{times[0],javaType=java.time.LocalDateTime} and #{times[1],javaType=java.time.LocalDateTime} 26 + AND owner_user_id in
  27 + <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  28 + #{userId}
  29 + </foreach>
  30 + AND return_time between #{times[0],javaType=java.time.LocalDateTime} and
  31 + #{times[1],javaType=java.time.LocalDateTime}
  32 + GROUP BY owner_user_id
  33 + </select>
  34 +
  35 + <select id="selectContractCountRank"
  36 + resultType="cn.iocoder.yudao.module.crm.controller.admin.bi.vo.CrmBiRanKRespVO">
  37 + SELECT COUNT(1) AS count, owner_user_id
  38 + FROM crm_contract
  39 + WHERE deleted = 0
  40 + AND audit_status = 20
  41 + AND owner_user_id in
  42 + <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  43 + #{userId}
  44 + </foreach>
  45 + AND order_date between #{times[0],javaType=java.time.LocalDateTime} and
  46 + #{times[1],javaType=java.time.LocalDateTime}
30 GROUP BY owner_user_id 47 GROUP BY owner_user_id
31 </select> 48 </select>
32 49
  50 + <!-- TODO 待定 这里是否需要关联 crm_contract_product 表,计算销售额 -->
  51 + <select id="selectProductSalesRank"
  52 + resultType="cn.iocoder.yudao.module.crm.controller.admin.bi.vo.CrmBiRanKRespVO">
  53 + SELECT COUNT(1) AS count, owner_user_id
  54 + FROM crm_contract
  55 + WHERE deleted = 0
  56 + AND audit_status = 20
  57 + AND owner_user_id in
  58 + <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  59 + #{userId}
  60 + </foreach>
  61 + AND order_date between #{times[0],javaType=java.time.LocalDateTime} and
  62 + #{times[1],javaType=java.time.LocalDateTime}
  63 + GROUP BY owner_user_id
  64 + </select>
  65 +
  66 + <select id="selectCustomerCountRank"
  67 + resultType="cn.iocoder.yudao.module.crm.controller.admin.bi.vo.CrmBiRanKRespVO">
  68 + SELECT COUNT(1) AS count, owner_user_id
  69 + FROM crm_customer
  70 + WHERE deleted = 0
  71 + AND owner_user_id in
  72 + <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  73 + #{userId}
  74 + </foreach>
  75 + AND create_time between #{times[0],javaType=java.time.LocalDateTime} and
  76 + #{times[1],javaType=java.time.LocalDateTime}
  77 + GROUP BY owner_user_id
  78 + </select>
  79 +
  80 + <select id="selectContactsCountRank"
  81 + resultType="cn.iocoder.yudao.module.crm.controller.admin.bi.vo.CrmBiRanKRespVO">
  82 + SELECT COUNT(1) AS count, owner_user_id
  83 + FROM crm_contact
  84 + WHERE deleted = 0
  85 + AND owner_user_id in
  86 + <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  87 + #{userId}
  88 + </foreach>
  89 + AND create_time between #{times[0],javaType=java.time.LocalDateTime} and
  90 + #{times[1],javaType=java.time.LocalDateTime}
  91 + GROUP BY owner_user_id
  92 + </select>
  93 +
  94 + <select id="selectFollowCountRank"
  95 + resultType="cn.iocoder.yudao.module.crm.controller.admin.bi.vo.CrmBiRanKRespVO">
  96 + SELECT COUNT(1) AS count, cc.owner_user_id
  97 + FROM crm_follow_up_record AS cfur LEFT JOIN crm_contact AS cc ON FIND_IN_SET(cc.id, cfur.contact_ids)
  98 + WHERE cfur.deleted = 0
  99 + AND cc.deleted = 0
  100 + AND cc.owner_user_id in
  101 + <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  102 + #{userId}
  103 + </foreach>
  104 + AND cfur.create_time between #{times[0],javaType=java.time.LocalDateTime} and
  105 + #{times[1],javaType=java.time.LocalDateTime}
  106 + GROUP BY cc.owner_user_id
  107 + </select>
  108 +
  109 + <select id="selectFollowCustomerCountRank"
  110 + resultType="cn.iocoder.yudao.module.crm.controller.admin.bi.vo.CrmBiRanKRespVO">
  111 + SELECT COUNT(DISTINCT cc.id) AS count, cc.owner_user_id
  112 + FROM crm_follow_up_record AS cfur LEFT JOIN crm_contact AS cc ON FIND_IN_SET(cc.id, cfur.contact_ids)
  113 + WHERE cfur.deleted = 0
  114 + AND cc.deleted = 0
  115 + AND cc.owner_user_id in
  116 + <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  117 + #{userId}
  118 + </foreach>
  119 + AND cfur.create_time between #{times[0],javaType=java.time.LocalDateTime} and
  120 + #{times[1],javaType=java.time.LocalDateTime}
  121 + GROUP BY cc.owner_user_id
  122 + </select>
  123 +
33 </mapper> 124 </mapper>