Commit ab43e89a48709453c51b2ddd1f51e5e15cf196c2

Authored by anhaohao
1 parent 7bb17151

修改:CRM 商业智能,合同金额排行榜和回款金额排行榜

Showing 24 changed files with 797 additions and 0 deletions
yudao-module-crm/pom.xml
... ... @@ -10,6 +10,8 @@
10 10 <modules>
11 11 <module>yudao-module-crm-api</module>
12 12 <module>yudao-module-crm-biz</module>
  13 + <module>yudao-module-bi-biz</module>
  14 + <module>yudao-module-bi-api</module>
13 15 </modules>
14 16 <modelVersion>4.0.0</modelVersion>
15 17 <artifactId>yudao-module-crm</artifactId>
... ... @@ -20,6 +22,7 @@
20 22 <description>
21 23 crm 包下,客户关系管理(Customer Relationship Management)。
22 24 例如说:客户、联系人、商机、合同、回款等等
  25 + 商业智能 BI 模块,包括:报表、图表、数据大屏等等
23 26 </description>
24 27  
25 28 </project>
... ...
yudao-module-crm/yudao-module-bi-api/pom.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5 + <parent>
  6 + <groupId>cn.iocoder.boot</groupId>
  7 + <artifactId>yudao-module-crm</artifactId>
  8 + <version>${revision}</version>
  9 + </parent>
  10 + <modelVersion>4.0.0</modelVersion>
  11 + <artifactId>yudao-module-bi-api</artifactId>
  12 +
  13 + <name>${project.artifactId}</name>
  14 + <description>
  15 + bi 模块 API,暴露给其它模块调用
  16 + </description>
  17 +
  18 + <dependencies>
  19 + <dependency>
  20 + <groupId>cn.iocoder.boot</groupId>
  21 + <artifactId>yudao-module-system-api</artifactId>
  22 + <version>${revision}</version>
  23 + </dependency>
  24 + <dependency>
  25 + <groupId>cn.iocoder.boot</groupId>
  26 + <artifactId>yudao-module-crm-api</artifactId>
  27 + <version>${revision}</version>
  28 + </dependency>
  29 +
  30 + <!-- 业务组件 -->
  31 + <dependency>
  32 + <groupId>cn.iocoder.boot</groupId>
  33 + <artifactId>yudao-spring-boot-starter-biz-operatelog</artifactId>
  34 + </dependency>
  35 + <dependency>
  36 + <groupId>cn.iocoder.boot</groupId>
  37 + <artifactId>yudao-spring-boot-starter-biz-ip</artifactId>
  38 + </dependency>
  39 +
  40 + <!-- Web 相关 -->
  41 + <dependency>
  42 + <groupId>cn.iocoder.boot</groupId>
  43 + <artifactId>yudao-spring-boot-starter-web</artifactId>
  44 + </dependency>
  45 +
  46 + <dependency>
  47 + <groupId>cn.iocoder.boot</groupId>
  48 + <artifactId>yudao-spring-boot-starter-security</artifactId>
  49 + </dependency>
  50 +
  51 + <!-- DB 相关 -->
  52 + <dependency>
  53 + <groupId>cn.iocoder.boot</groupId>
  54 + <artifactId>yudao-spring-boot-starter-mybatis</artifactId>
  55 + </dependency>
  56 +
  57 + <!-- 工具类相关 -->
  58 + <dependency>
  59 + <groupId>cn.iocoder.boot</groupId>
  60 + <artifactId>yudao-spring-boot-starter-excel</artifactId>
  61 + </dependency>
  62 + <dependency>
  63 + <groupId>cn.iocoder.boot</groupId>
  64 + <artifactId>yudao-spring-boot-starter-biz-dict</artifactId>
  65 + </dependency>
  66 +
  67 + <!-- Test 测试相关 -->
  68 + <dependency>
  69 + <groupId>cn.iocoder.boot</groupId>
  70 + <artifactId>yudao-spring-boot-starter-test</artifactId>
  71 + </dependency>
  72 + </dependencies>
  73 +</project>
0 74 \ No newline at end of file
... ...
yudao-module-crm/yudao-module-bi-api/src/main/java/cn/iocoder/yudao/module/bi/api/package-info.java 0 → 100644
  1 +package cn.iocoder.yudao.module.bi.api;
0 2 \ No newline at end of file
... ...
yudao-module-crm/yudao-module-bi-api/src/main/java/cn/iocoder/yudao/module/bi/enums/package-info.java 0 → 100644
  1 +package cn.iocoder.yudao.module.bi.enums;
0 2 \ No newline at end of file
... ...
yudao-module-crm/yudao-module-bi-biz/pom.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5 + <parent>
  6 + <groupId>cn.iocoder.boot</groupId>
  7 + <artifactId>yudao-module-crm</artifactId>
  8 + <version>${revision}</version>
  9 + </parent>
  10 + <modelVersion>4.0.0</modelVersion>
  11 + <artifactId>yudao-module-bi-biz</artifactId>
  12 +
  13 + <name>${project.artifactId}</name>
  14 + <description>
  15 + crm 包下,商业智能(Business Intelligence)。
  16 + 例如说:报表、图表、数据分析等等
  17 + </description>
  18 +
  19 + <dependencies>
  20 + <dependency>
  21 + <groupId>cn.iocoder.boot</groupId>
  22 + <artifactId>yudao-module-system-api</artifactId>
  23 + <version>${revision}</version>
  24 + </dependency>
  25 + <dependency>
  26 + <groupId>cn.iocoder.boot</groupId>
  27 + <artifactId>yudao-module-crm-api</artifactId>
  28 + <version>${revision}</version>
  29 + </dependency>
  30 +
  31 + <!-- 业务组件 -->
  32 + <dependency>
  33 + <groupId>cn.iocoder.boot</groupId>
  34 + <artifactId>yudao-spring-boot-starter-biz-operatelog</artifactId>
  35 + </dependency>
  36 + <dependency>
  37 + <groupId>cn.iocoder.boot</groupId>
  38 + <artifactId>yudao-spring-boot-starter-biz-ip</artifactId>
  39 + </dependency>
  40 +
  41 + <!-- Web 相关 -->
  42 + <dependency>
  43 + <groupId>cn.iocoder.boot</groupId>
  44 + <artifactId>yudao-spring-boot-starter-web</artifactId>
  45 + </dependency>
  46 +
  47 + <dependency>
  48 + <groupId>cn.iocoder.boot</groupId>
  49 + <artifactId>yudao-spring-boot-starter-security</artifactId>
  50 + </dependency>
  51 +
  52 + <!-- DB 相关 -->
  53 + <dependency>
  54 + <groupId>cn.iocoder.boot</groupId>
  55 + <artifactId>yudao-spring-boot-starter-mybatis</artifactId>
  56 + </dependency>
  57 +
  58 + <!-- 工具类相关 -->
  59 + <dependency>
  60 + <groupId>cn.iocoder.boot</groupId>
  61 + <artifactId>yudao-spring-boot-starter-excel</artifactId>
  62 + </dependency>
  63 + <dependency>
  64 + <groupId>cn.iocoder.boot</groupId>
  65 + <artifactId>yudao-spring-boot-starter-biz-dict</artifactId>
  66 + </dependency>
  67 +
  68 + <!-- Test 测试相关 -->
  69 + <dependency>
  70 + <groupId>cn.iocoder.boot</groupId>
  71 + <artifactId>yudao-spring-boot-starter-test</artifactId>
  72 + </dependency>
  73 + </dependencies>
  74 +</project>
0 75 \ No newline at end of file
... ...
yudao-module-crm/yudao-module-bi-biz/src/main/java/cn/iocoder/yudao/module/bi/controller/admin/ranking/BiRankingController.http 0 → 100644
  1 +### 合同金额排行榜
  2 +GET {{baseUrl}}/bi/rank/contract-ranKing
  3 +Authorization: Bearer {{token}}
  4 +tenant-id: {{adminTenentId}}
  5 +
  6 +
  7 +### 回款金额排行榜
  8 +GET {{baseUrl}}/bi/rank/receivables-ranKing
  9 +Authorization: Bearer {{token}}
  10 +tenant-id: {{adminTenentId}}
... ...
yudao-module-crm/yudao-module-bi-biz/src/main/java/cn/iocoder/yudao/module/bi/controller/admin/ranking/BiRankingController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.bi.controller.admin.ranking;
  2 +
  3 +
  4 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  5 +import cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiContractRanKingRespVO;
  6 +import cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiRankReqVO;
  7 +import cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiReceivablesRanKingRespVO;
  8 +import cn.iocoder.yudao.module.bi.service.ranking.BiRankingService;
  9 +import io.swagger.v3.oas.annotations.Operation;
  10 +import io.swagger.v3.oas.annotations.tags.Tag;
  11 +import jakarta.annotation.Resource;
  12 +import org.springframework.security.access.prepost.PreAuthorize;
  13 +import org.springframework.validation.annotation.Validated;
  14 +import org.springframework.web.bind.annotation.GetMapping;
  15 +import org.springframework.web.bind.annotation.RequestMapping;
  16 +import org.springframework.web.bind.annotation.RestController;
  17 +
  18 +import java.util.List;
  19 +
  20 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  21 +
  22 +/**
  23 + * @author anhaohao
  24 + */
  25 +@Tag(name = "管理后台 - 排行榜")
  26 +@RestController
  27 +@RequestMapping("/bi/ranking")
  28 +@Validated
  29 +public class BiRankingController {
  30 +
  31 + @Resource
  32 + private BiRankingService biRankingService;
  33 +
  34 + /**
  35 + * 合同金额排行榜
  36 + */
  37 + @GetMapping("/contract-ranking")
  38 + @Operation(summary = "合同金额排行榜")
  39 + @PreAuthorize("@ss.hasPermission('bi:ranking:query')")
  40 + public CommonResult<List<BiContractRanKingRespVO>> contractAmountRanking(BiRankReqVO biRankReqVO) {
  41 + return success(biRankingService.contractRanKing(biRankReqVO));
  42 + }
  43 +
  44 + /**
  45 + * 回款金额排行榜
  46 + */
  47 + @GetMapping("/receivables-ranking")
  48 + @Operation(summary = "回款金额排行榜")
  49 + @PreAuthorize("@ss.hasPermission('bi:ranking:query')")
  50 + public CommonResult<List<BiReceivablesRanKingRespVO>> receivablesRanKing(BiRankReqVO biRankReqVO) {
  51 + return success(biRankingService.receivablesRanKing(biRankReqVO));
  52 + }
  53 +}
... ...
yudao-module-crm/yudao-module-bi-biz/src/main/java/cn/iocoder/yudao/module/bi/controller/admin/ranking/vo/BiContractRanKingRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.bi.controller.admin.ranking.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +/**
  7 + * 管理后台 - BI 排行榜 Response VO
  8 + *
  9 + * @author anhaohao
  10 + */
  11 +@Schema(description = "管理后台 - BI 合同金额排行榜 Response VO")
  12 +@Data
  13 +public class BiContractRanKingRespVO {
  14 +
  15 + @Schema(description = "金额", example = "1")
  16 + private Integer price;
  17 +
  18 + @Schema(description = "姓名", example = "1")
  19 + private String nickname;
  20 +
  21 +
  22 + @Schema(description = "部门名称", example = "1")
  23 + private String deptName;
  24 +}
... ...
yudao-module-crm/yudao-module-bi-biz/src/main/java/cn/iocoder/yudao/module/bi/controller/admin/ranking/vo/BiParams.java 0 → 100644
  1 +package cn.iocoder.yudao.module.bi.controller.admin.ranking.vo;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +import lombok.Data;
  6 +import lombok.EqualsAndHashCode;
  7 +
  8 +import java.util.List;
  9 +
  10 +/**
  11 + * @author anhaohao
  12 + * bi参数
  13 + */
  14 +@EqualsAndHashCode(callSuper = true)
  15 +@Schema(description = "bi查询相关参数")
  16 +@Data
  17 +public class BiParams extends PageParam {
  18 +
  19 + @Schema(description = "部门ID")
  20 + private Long deptId;
  21 +
  22 + @Schema(description = "用户ID")
  23 + private Long userId;
  24 +
  25 + @Schema(description = "用户IDs")
  26 + private List<Long> userIds;
  27 +
  28 + @Schema(description = "类型")
  29 + private String type;
  30 +
  31 + @Schema(description = "开始时间")
  32 + private String startTime;
  33 +
  34 + @Schema(description = "结束时间")
  35 + private String endTime;
  36 +
  37 + @Schema(description = "0 部门 1员工")
  38 + private Integer isUser = 1;
  39 +
  40 +
  41 +}
... ...
yudao-module-crm/yudao-module-bi-biz/src/main/java/cn/iocoder/yudao/module/bi/controller/admin/ranking/vo/BiRankReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.bi.controller.admin.ranking.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +/**
  7 + * 管理后台 - 排行榜 Request VO
  8 + *
  9 + * @author anhaohao
  10 + */
  11 +@Schema(description = "管理后台 - 排行榜 Request VO")
  12 +@Data
  13 +public class BiRankReqVO {
  14 +
  15 + @Schema(description = "部门id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  16 + private Long deptId;
  17 +
  18 + @Schema(description = "分析类型(1.今天 2.昨天 3.本周 4.上周 5.本月 6.上月 7.本季度 8.上季度 9.本年 10 上年)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  19 + private String type;
  20 +}
... ...
yudao-module-crm/yudao-module-bi-biz/src/main/java/cn/iocoder/yudao/module/bi/controller/admin/ranking/vo/BiReceivablesRanKingRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.bi.controller.admin.ranking.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +/**
  7 + * 管理后台 - BI 排行榜 Response VO
  8 + *
  9 + * @author anhaohao
  10 + */
  11 +@Schema(description = "管理后台 - BI 合同金额排行榜 Response VO")
  12 +@Data
  13 +public class BiReceivablesRanKingRespVO {
  14 +
  15 + @Schema(description = "金额", example = "100")
  16 + private Integer price;
  17 +
  18 + @Schema(description = "姓名", example = "张三")
  19 + private String nickname;
  20 +
  21 + @Schema(description = "部门名称", example = "研发部")
  22 + private String deptName;
  23 +}
... ...
yudao-module-crm/yudao-module-bi-biz/src/main/java/cn/iocoder/yudao/module/bi/controller/package-info.java 0 → 100644
  1 +/**
  2 + * 提供 RESTful API 给前端:
  3 + * 1. admin 包:提供给管理后台 yudao-ui-admin 前端项目
  4 + * 2. app 包:提供给用户 APP yudao-ui-app 前端项目,它的 Controller 和 VO 都要添加 App 前缀,用于和管理后台进行区分
  5 + */
  6 +package cn.iocoder.yudao.module.bi.controller;
... ...
yudao-module-crm/yudao-module-bi-biz/src/main/java/cn/iocoder/yudao/module/bi/dal/mysql/BiRankingMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.bi.dal.mysql;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  4 +import cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiContractRanKingRespVO;
  5 +import cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiReceivablesRanKingRespVO;
  6 +import cn.iocoder.yudao.module.bi.util.BiTimeUtil;
  7 +import org.apache.ibatis.annotations.Mapper;
  8 +
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * @author anhaohao
  13 + */
  14 +@Mapper
  15 +public interface BiRankingMapper extends BaseMapperX {
  16 + /**
  17 + * 合同金额排行榜
  18 + *
  19 + * @param biTimeEntity 参数
  20 + * @return List<BiContractAmountRankingRespVO>
  21 + */
  22 + List<BiContractRanKingRespVO> contractRanKing(BiTimeUtil.BiTimeEntity biTimeEntity);
  23 +
  24 + /**
  25 + * 回款金额排行榜
  26 + *
  27 + * @param biTimeEntity 参数
  28 + * @return List<BiContractAmountRankingRespVO>
  29 + */
  30 + List<BiReceivablesRanKingRespVO> receivablesRanKing(BiTimeUtil.BiTimeEntity biTimeEntity);
  31 +}
... ...
yudao-module-crm/yudao-module-bi-biz/src/main/java/cn/iocoder/yudao/module/bi/framework/package-info.java 0 → 100644
  1 +/**
  2 + * 属于 bi 模块的 framework 封装
  3 + *
  4 + * @author 芋道源码
  5 + */
  6 +package cn.iocoder.yudao.module.bi.framework;
... ...
yudao-module-crm/yudao-module-bi-biz/src/main/java/cn/iocoder/yudao/module/bi/framework/web/config/BiWebConfiguration.java 0 → 100644
  1 +package cn.iocoder.yudao.module.bi.framework.web.config;
  2 +
  3 +import cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration;
  4 +import org.springdoc.core.models.GroupedOpenApi;
  5 +import org.springframework.context.annotation.Bean;
  6 +import org.springframework.context.annotation.Configuration;
  7 +
  8 +/**
  9 + * bi 模块的 web 组件的 Configuration
  10 + *
  11 + * @author 芋道源码
  12 + */
  13 +@Configuration(proxyBeanMethods = false)
  14 +public class BiWebConfiguration {
  15 +
  16 + /**
  17 + * bi 模块的 API 分组
  18 + */
  19 + @Bean
  20 + public GroupedOpenApi biGroupedOpenApi() {
  21 + return YudaoSwaggerAutoConfiguration.buildGroupedOpenApi("bi");
  22 + }
  23 +
  24 +}
... ...
yudao-module-crm/yudao-module-bi-biz/src/main/java/cn/iocoder/yudao/module/bi/framework/web/package-info.java 0 → 100644
  1 +/**
  2 + * bi 模块的 web 配置
  3 + */
  4 +package cn.iocoder.yudao.module.bi.framework.web;
... ...
yudao-module-crm/yudao-module-bi-biz/src/main/java/cn/iocoder/yudao/module/bi/package-info.java 0 → 100644
  1 +/**
  2 + * crm 包下,商业智能(Business Intelligence)。
  3 + * 例如说:报表、图表、数据分析等等
  4 + * <p>
  5 + * 1. Controller URL:以 /bi/ 开头,避免和其它 Module 冲突
  6 + */
  7 +package cn.iocoder.yudao.module.bi;
0 8 \ No newline at end of file
... ...
yudao-module-crm/yudao-module-bi-biz/src/main/java/cn/iocoder/yudao/module/bi/service/ranking/BiRankingService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.bi.service.ranking;
  2 +
  3 +import cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiContractRanKingRespVO;
  4 +import cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiRankReqVO;
  5 +import cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiReceivablesRanKingRespVO;
  6 +
  7 +import java.util.List;
  8 +
  9 +/**
  10 + * BI 排行榜 Service 接口
  11 + *
  12 + * @author anhaohao
  13 + */
  14 +public interface BiRankingService {
  15 + /**
  16 + * 合同金额排行榜
  17 + *
  18 + * @param biRankReqVO 参数
  19 + * @return List<BiContractAmountRankingRespVO>
  20 + */
  21 + List<BiContractRanKingRespVO> contractRanKing(BiRankReqVO biRankReqVO);
  22 +
  23 + /**
  24 + * 回款金额排行榜
  25 + *
  26 + * @param biRankReqVO 参数
  27 + * @return List<BiContractAmountRankingRespVO>
  28 + */
  29 + List<BiReceivablesRanKingRespVO> receivablesRanKing(BiRankReqVO biRankReqVO);
  30 +}
... ...
yudao-module-crm/yudao-module-bi-biz/src/main/java/cn/iocoder/yudao/module/bi/service/ranking/BiRankingServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.bi.service.ranking;
  2 +
  3 +import cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiContractRanKingRespVO;
  4 +import cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiParams;
  5 +import cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiRankReqVO;
  6 +import cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiReceivablesRanKingRespVO;
  7 +import cn.iocoder.yudao.module.bi.dal.mysql.BiRankingMapper;
  8 +import cn.iocoder.yudao.module.bi.util.BiTimeUtil;
  9 +import jakarta.annotation.Resource;
  10 +import org.springframework.stereotype.Service;
  11 +import org.springframework.validation.annotation.Validated;
  12 +
  13 +import java.util.ArrayList;
  14 +import java.util.List;
  15 +
  16 +/**
  17 + * @author anhaohao
  18 + */
  19 +@Service(value = "biRankService")
  20 +@Validated
  21 +public class BiRankingServiceImpl implements BiRankingService {
  22 +
  23 + @Resource
  24 + private BiRankingMapper biRankingMapper;
  25 +
  26 + @Override
  27 + public List<BiContractRanKingRespVO> contractRanKing(BiRankReqVO biRankReqVO) {
  28 + BiParams biParams = new BiParams();
  29 + biParams.setType(biRankReqVO.getType());
  30 + biParams.setDeptId(biRankReqVO.getDeptId());
  31 + biParams.setIsUser(0);
  32 + BiTimeUtil.BiTimeEntity biTimeEntity = BiTimeUtil.analyzeType(biParams);
  33 + List<Long> userIds = biTimeEntity.getUserIds();
  34 + if (userIds.isEmpty()) {
  35 + return new ArrayList<>();
  36 + }
  37 + return biRankingMapper.contractRanKing(biTimeEntity);
  38 + }
  39 +
  40 + @Override
  41 + public List<BiReceivablesRanKingRespVO> receivablesRanKing(BiRankReqVO biRankReqVO) {
  42 + BiParams biParams = new BiParams();
  43 + biParams.setType(biRankReqVO.getType());
  44 + biParams.setDeptId(biRankReqVO.getDeptId());
  45 + biParams.setIsUser(0);
  46 + BiTimeUtil.BiTimeEntity biTimeEntity = BiTimeUtil.analyzeType(biParams);
  47 + List<Long> userIds = biTimeEntity.getUserIds();
  48 + if (userIds.isEmpty()) {
  49 + return new ArrayList<>();
  50 + }
  51 + return biRankingMapper.receivablesRanKing(biTimeEntity);
  52 + }
  53 +}
... ...
yudao-module-crm/yudao-module-bi-biz/src/main/java/cn/iocoder/yudao/module/bi/util/BiTimeUtil.java 0 → 100644
  1 +package cn.iocoder.yudao.module.bi.util;
  2 +
  3 +import cn.hutool.core.date.DateUnit;
  4 +import cn.hutool.core.date.DateUtil;
  5 +import cn.hutool.core.util.StrUtil;
  6 +import cn.hutool.extra.spring.SpringUtil;
  7 +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
  8 +import cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiParams;
  9 +import cn.iocoder.yudao.module.system.api.dept.DeptApi;
  10 +import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
  11 +import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
  12 +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
  13 +import lombok.Data;
  14 +import lombok.experimental.Accessors;
  15 +
  16 +import java.util.ArrayList;
  17 +import java.util.Date;
  18 +import java.util.List;
  19 +
  20 +/**
  21 + * bi时间工具类
  22 + *
  23 + * @author anhaohao
  24 + */
  25 +public class BiTimeUtil {
  26 +
  27 + public static BiTimeEntity analyzeType(BiParams biParams) {
  28 + // 解析时间
  29 + BiTimeEntity biTimeEntity = analyzeTime(biParams);
  30 + // 解析权限
  31 + biTimeEntity.setUserIds(analyzeAuth(biParams));
  32 + return biTimeEntity;
  33 + }
  34 +
  35 + /**
  36 + * 解析权限
  37 + *
  38 + * @param biParams bi参数
  39 + * @return List<Long>
  40 + */
  41 + public static List<Long> analyzeAuth(BiParams biParams) {
  42 + List<Long> userIdList = new ArrayList<>();
  43 + Long deptId = biParams.getDeptId();
  44 + Long userId = biParams.getUserId();
  45 + Integer isUser = biParams.getIsUser();
  46 + // 获取部门和用户的api
  47 + DeptApi deptApi = SpringUtil.getBean("deptApiImpl");
  48 + AdminUserApi adminUserApi = SpringUtil.getBean("adminUserApiImpl");
  49 + // 0.部门 1.用户
  50 + if (isUser == 0) {
  51 + if (deptId == null) {
  52 + deptId = adminUserApi.getUser(SecurityFrameworkUtils.getLoginUserId()).getDeptId();
  53 + }
  54 + List<DeptRespDTO> childDeptList = deptApi.getChildDeptList(deptId);
  55 + List<Long> deptIds = new ArrayList<>();
  56 + deptIds.add(deptId);
  57 + if (childDeptList != null && !childDeptList.isEmpty()) {
  58 + for (DeptRespDTO deptRespDTO : childDeptList) {
  59 + deptIds.add(deptRespDTO.getId());
  60 + }
  61 + }
  62 + // 获取部门下的用户
  63 + adminUserApi.getUserListByDeptIds(deptIds).forEach(adminUserRespDTO -> userIdList.add(adminUserRespDTO.getId()));
  64 + } else {
  65 + if (userId == null) {
  66 + List<AdminUserRespDTO> userListBySubordinate = adminUserApi.getUserListBySubordinate(SecurityFrameworkUtils.getLoginUserId());
  67 + userListBySubordinate.forEach(adminUserRespDTO -> userIdList.add(adminUserRespDTO.getId()));
  68 + } else {
  69 + userIdList.add(userId);
  70 + }
  71 + }
  72 + return userIdList;
  73 + }
  74 +
  75 +
  76 + /**
  77 + * 解析时间
  78 + *
  79 + * @param biParams bi参数
  80 + * @return BiTimeEntity
  81 + */
  82 + public static BiTimeEntity analyzeTime(BiParams biParams) {
  83 + Date beginDate = DateUtil.date();
  84 + Date endDate = DateUtil.date();
  85 + int cycleNum = 12;
  86 + String sqlDateFormat = "%Y%m";
  87 + String dateFormat = "yyyyMM";
  88 + String type = biParams.getType();
  89 + String startTime = biParams.getStartTime();
  90 + String endTime = biParams.getEndTime();
  91 + if (StrUtil.isNotEmpty(type)) {
  92 + //1.今天 2.昨天 3.本周 4.上周 5.本月 6.上月 7.本季度 8.上季度 9.本年 10 上年
  93 + switch (type) {
  94 + case "1":
  95 + beginDate = DateUtil.beginOfDay(DateUtil.date());
  96 + endDate = DateUtil.endOfDay(DateUtil.date());
  97 + sqlDateFormat = "%Y%m%d";
  98 + dateFormat = "yyyyMMdd";
  99 + cycleNum = 1;
  100 + break;
  101 + case "2":
  102 + beginDate = DateUtil.beginOfDay(new Date(System.currentTimeMillis() - 86400000));
  103 + endDate = DateUtil.endOfDay(new Date(System.currentTimeMillis() - 86400000));
  104 + sqlDateFormat = "%Y%m%d";
  105 + dateFormat = "yyyyMMdd";
  106 + cycleNum = 1;
  107 + break;
  108 + case "3":
  109 + beginDate = DateUtil.beginOfWeek(DateUtil.date());
  110 + endDate = DateUtil.endOfWeek(DateUtil.date());
  111 + sqlDateFormat = "%Y%m%d";
  112 + dateFormat = "yyyyMMdd";
  113 + cycleNum = 7;
  114 + break;
  115 + case "4":
  116 + beginDate = DateUtil.beginOfWeek(DateUtil.offsetWeek(DateUtil.date(), -1));
  117 + endDate = DateUtil.endOfWeek(DateUtil.offsetWeek(DateUtil.date(), -1));
  118 + sqlDateFormat = "%Y%m%d";
  119 + dateFormat = "yyyyMMdd";
  120 + cycleNum = 7;
  121 + break;
  122 + case "5":
  123 + beginDate = DateUtil.beginOfMonth(DateUtil.date());
  124 + endDate = DateUtil.endOfMonth(DateUtil.date());
  125 + sqlDateFormat = "%Y%m%d";
  126 + dateFormat = "yyyyMMdd";
  127 + cycleNum = (int) DateUtil.between(beginDate, endDate, DateUnit.DAY) + 1;
  128 + break;
  129 + case "6":
  130 + beginDate = DateUtil.beginOfMonth(DateUtil.offsetMonth(DateUtil.date(), -1));
  131 + endDate = DateUtil.endOfMonth(DateUtil.offsetMonth(DateUtil.date(), -1));
  132 + sqlDateFormat = "%Y%m%d";
  133 + dateFormat = "yyyyMMdd";
  134 + cycleNum = (int) DateUtil.between(beginDate, endDate, DateUnit.DAY) + 1;
  135 + break;
  136 + case "7":
  137 + beginDate = DateUtil.beginOfQuarter(DateUtil.date());
  138 + endDate = DateUtil.endOfQuarter(DateUtil.date());
  139 + cycleNum = 3;
  140 + break;
  141 + case "8":
  142 + beginDate = DateUtil.beginOfQuarter(DateUtil.offsetMonth(DateUtil.date(), -3));
  143 + endDate = DateUtil.endOfQuarter(DateUtil.offsetMonth(DateUtil.date(), -3));
  144 + cycleNum = 3;
  145 + break;
  146 + case "9":
  147 + beginDate = DateUtil.beginOfYear(DateUtil.date());
  148 + endDate = DateUtil.endOfYear(DateUtil.date());
  149 + break;
  150 + case "10":
  151 + beginDate = DateUtil.beginOfYear(DateUtil.offsetMonth(DateUtil.date(), -12));
  152 + endDate = DateUtil.endOfYear(DateUtil.offsetMonth(DateUtil.date(), -12));
  153 + break;
  154 + default:
  155 + break;
  156 + }
  157 + } else if (StrUtil.isNotEmpty(startTime) && StrUtil.isNotEmpty(endTime)) {
  158 + Date start;
  159 + Date end;
  160 + if (startTime.length() == 6) {
  161 + start = DateUtil.parse(startTime, "yyyyMM");
  162 + end = DateUtil.endOfMonth(DateUtil.parse(endTime, "yyyyMM"));
  163 + } else {
  164 + start = DateUtil.parse(startTime);
  165 + end = DateUtil.parse(endTime);
  166 + }
  167 + Integer startMonth = Integer.valueOf(DateUtil.format(start, "yyyyMM"));
  168 + int endMonth = Integer.parseInt(DateUtil.format(end, "yyyyMM"));
  169 + if (startMonth.equals(endMonth)) {
  170 + sqlDateFormat = "%Y%m%d";
  171 + dateFormat = "yyyyMMdd";
  172 + long diffDay = DateUtil.between(start, end, DateUnit.DAY);
  173 + cycleNum = (int) diffDay + 1;
  174 + } else {
  175 + sqlDateFormat = "%Y%m";
  176 + dateFormat = "yyyyMM";
  177 + int diffYear = Integer.parseInt(Integer.toString(endMonth).substring(0, 4)) - Integer.parseInt(startMonth.toString().substring(0, 4));
  178 + int diffMonth = endMonth % 100 - startMonth % 100 + 1;
  179 + cycleNum = diffYear * 12 + diffMonth;
  180 + }
  181 + beginDate = start;
  182 + endDate = end;
  183 + }
  184 + Integer beginTime = Integer.valueOf(DateUtil.format(beginDate, dateFormat));
  185 + Integer finalTime = Integer.valueOf(DateUtil.format(endDate, dateFormat));
  186 + return new BiTimeEntity(sqlDateFormat, dateFormat, beginDate, endDate, cycleNum, beginTime, finalTime, new ArrayList<>());
  187 + }
  188 +
  189 + @Data
  190 + @Accessors(chain = true)
  191 + public static class BiTimeEntity {
  192 + /**
  193 + * sql日期格式化
  194 + */
  195 + private String sqlDateFormat;
  196 +
  197 + /**
  198 + * 日期格式化
  199 + */
  200 + private String dateFormat;
  201 +
  202 + /**
  203 + * 开始时间
  204 + */
  205 + private Date beginDate;
  206 +
  207 + /**
  208 + * 结束时间
  209 + */
  210 + private Date endDate;
  211 +
  212 + /**
  213 + * 周期
  214 + */
  215 + private Integer cycleNum;
  216 +
  217 + /**
  218 + * 开始时间 字符串格式 如20200101
  219 + */
  220 + private Integer beginTime;
  221 +
  222 + /**
  223 + * 结束时间 字符串格式 如20200101
  224 + */
  225 + private Integer finalTime;
  226 +
  227 + /**
  228 + * user列表
  229 + */
  230 + private List<Long> userIds = new ArrayList<>();
  231 + private Integer page;
  232 + private Integer limit;
  233 +
  234 + public BiTimeEntity(String sqlDateFormat, String dateFormat, Date beginDate, Date endDate, Integer cycleNum, Integer beginTime, Integer finalTime, List<Long> userIds) {
  235 + this.sqlDateFormat = sqlDateFormat;
  236 + this.dateFormat = dateFormat;
  237 + this.beginDate = beginDate;
  238 + this.endDate = endDate;
  239 + this.cycleNum = cycleNum;
  240 + this.beginTime = beginTime;
  241 + this.finalTime = finalTime;
  242 + this.userIds = userIds;
  243 + }
  244 +
  245 + public BiTimeEntity() {
  246 + }
  247 +
  248 + }
  249 +}
... ...
yudao-module-crm/yudao-module-bi-biz/src/main/resources/mapper/rank/BiRankingMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="cn.iocoder.yudao.module.bi.dal.mysql.BiRankingMapper">
  4 +
  5 +
  6 + <select id="contractRanKing"
  7 + resultType="cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiContractRanKingRespVO">
  8 + SELECT IFNULL(SUM(t.price), 0) AS price, su.nickname, t.owner_user_id, dept.name AS deptName
  9 + FROM crm_contract t
  10 + LEFT JOIN system_users AS su ON su.id = t.owner_user_id
  11 + LEFT JOIN system_dept AS dept ON dept.id = su.dept_id
  12 + WHERE t.deleted = 0
  13 + AND t.audit_status = 20
  14 + <if test="userIds != null and userIds.size() > 0">
  15 + and t.owner_user_id in
  16 + <foreach collection="userIds" item="item" open="(" close=")" separator=",">
  17 + #{item}
  18 + </foreach>
  19 + </if>
  20 + AND DATE_FORMAT(t.order_date,'${sqlDateFormat}') between #{beginTime} and #{finalTime}
  21 + GROUP BY t.owner_user_id
  22 + ORDER BY price DESC
  23 + </select>
  24 + <select id="receivablesRanKing"
  25 + resultType="cn.iocoder.yudao.module.bi.controller.admin.ranking.vo.BiReceivablesRanKingRespVO">
  26 + SELECT IFNULL(SUM(t.price), 0) AS price, su.nickname, t.owner_user_id, dept.name AS deptName
  27 + FROM crm_receivable t
  28 + LEFT JOIN system_users AS su ON su.id = t.owner_user_id
  29 + LEFT JOIN system_dept AS dept ON dept.id = su.dept_id
  30 + WHERE t.deleted = 0
  31 + AND t.audit_status = 20
  32 + <if test="userIds != null and userIds.size() > 0">
  33 + and t.owner_user_id in
  34 + <foreach collection="userIds" item="item" open="(" close=")" separator=",">
  35 + #{item}
  36 + </foreach>
  37 + </if>
  38 + AND DATE_FORMAT(t.order_date,'${sqlDateFormat}') between #{beginTime} and #{finalTime}
  39 + GROUP BY t.owner_user_id
  40 + ORDER BY price DESC
  41 + </select>
  42 +</mapper>
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApi.java
... ... @@ -50,4 +50,12 @@ public interface DeptApi {
50 50 return CollectionUtils.convertMap(list, DeptRespDTO::getId);
51 51 }
52 52  
  53 + /**
  54 + * 获得指定部门的所有子部门
  55 + *
  56 + * @param id 部门编号
  57 + * @return 子部门列表
  58 + */
  59 + List<DeptRespDTO> getChildDeptList(Long id);
  60 +
53 61 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/DeptApiImpl.java
... ... @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
4 4 import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
5 5 import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
6 6 import cn.iocoder.yudao.module.system.service.dept.DeptService;
  7 +import org.springframework.context.annotation.Lazy;
7 8 import org.springframework.stereotype.Service;
8 9  
9 10 import jakarta.annotation.Resource;
... ... @@ -19,6 +20,7 @@ import java.util.List;
19 20 public class DeptApiImpl implements DeptApi {
20 21  
21 22 @Resource
  23 + @Lazy // 延迟加载,解决相互依赖的问题
22 24 private DeptService deptService;
23 25  
24 26 @Override
... ... @@ -38,4 +40,11 @@ public class DeptApiImpl implements DeptApi {
38 40 deptService.validateDeptList(ids);
39 41 }
40 42  
  43 + @Override
  44 + public List<DeptRespDTO> getChildDeptList(Long id) {
  45 + List<DeptDO> childDeptList = deptService.getChildDeptList(id);
  46 + return BeanUtils.toBean(childDeptList, DeptRespDTO.class);
  47 + }
  48 +
  49 +
41 50 }
... ...
yudao-server/pom.xml
... ... @@ -97,6 +97,11 @@
97 97 <artifactId>yudao-module-crm-biz</artifactId>
98 98 <version>${revision}</version>
99 99 </dependency>
  100 + <dependency>
  101 + <groupId>cn.iocoder.boot</groupId>
  102 + <artifactId>yudao-module-bi-biz</artifactId>
  103 + <version>${revision}</version>
  104 + </dependency>
100 105  
101 106 <!-- spring boot 配置所需依赖 -->
102 107 <dependency>
... ...