mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-08 07:11:53 +08:00
Merge remote-tracking branch 'yudao/develop' into develop
# Conflicts: # yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
### 合同金额排行榜
|
||||
GET {{baseUrl}}/crm/bi-rank/get-contract-price-rank?deptId=100×[0]=2022-12-12 00:00:00×[1]=2024-12-12 23:59:59
|
||||
Authorization: Bearer {{token}}
|
||||
tenant-id: {{adminTenentId}}
|
||||
|
||||
### 回款金额排行榜
|
||||
GET {{baseUrl}}/crm/bi-rank/get-receivable-price-rank?deptId=100×[0]=2022-12-12 00:00:00×[1]=2024-12-12 23:59:59
|
||||
Authorization: Bearer {{token}}
|
||||
tenant-id: {{adminTenentId}}
|
@@ -0,0 +1,45 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.bi;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.bi.vo.CrmBiRanKRespVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.bi.vo.CrmBiRankReqVO;
|
||||
import cn.iocoder.yudao.module.crm.service.bi.CrmBiRankingService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
|
||||
@Tag(name = "管理后台 - CRM BI 排行榜")
|
||||
@RestController
|
||||
@RequestMapping("/crm/bi-rank")
|
||||
@Validated
|
||||
public class CrmBiRankController {
|
||||
|
||||
@Resource
|
||||
private CrmBiRankingService rankingService;
|
||||
|
||||
@GetMapping("/get-contract-price-rank")
|
||||
@Operation(summary = "获得合同金额排行榜")
|
||||
@PreAuthorize("@ss.hasPermission('crm:bi-rank:query')")
|
||||
public CommonResult<List<CrmBiRanKRespVO>> getContractPriceRank(@Valid CrmBiRankReqVO rankingReqVO) {
|
||||
return success(rankingService.getContractPriceRank(rankingReqVO));
|
||||
}
|
||||
|
||||
@GetMapping("/get-receivable-price-rank")
|
||||
@Operation(summary = "获得回款金额排行榜")
|
||||
@PreAuthorize("@ss.hasPermission('crm:bi-rank:query')")
|
||||
public CommonResult<List<CrmBiRanKRespVO>> getReceivablePriceRank(@Valid CrmBiRankReqVO rankingReqVO) {
|
||||
return success(rankingService.getReceivablePriceRank(rankingReqVO));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.bi.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@Schema(description = "管理后台 - CRM BI 排行榜 Response VO")
|
||||
@Data
|
||||
public class CrmBiRanKRespVO {
|
||||
|
||||
@Schema(description = "负责人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long ownerUserId;
|
||||
|
||||
@Schema(description = "姓名", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private String nickname;
|
||||
|
||||
@Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private String deptName;
|
||||
|
||||
/**
|
||||
* 数量是个特别“抽象”的概念,在不同排行下,代表不同含义
|
||||
*
|
||||
* 1. 金额:合同金额排行、回款金额排行
|
||||
* 2. 个数:签约合同排行、产品销量排行、产品销量排行、新增客户数排行、新增联系人排行、跟进次数排行、跟进客户数排行
|
||||
*/
|
||||
@Schema(description = "数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer count;
|
||||
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.bi.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - CRM BI 排行榜 Request VO")
|
||||
@Data
|
||||
public class CrmBiRankReqVO {
|
||||
|
||||
@Schema(description = "部门 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "部门 id 不能为空")
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* userIds 目前不用前端传递,目前是方便后端通过 deptId 读取编号后,设置回来
|
||||
*
|
||||
* 后续,可能会支持选择部分用户进行查询
|
||||
*/
|
||||
@Schema(description = "负责人用户 id 集合", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "2")
|
||||
private List<Long> userIds;
|
||||
|
||||
@Schema(description = "时间范围", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@NotEmpty(message = "时间范围不能为空")
|
||||
private LocalDateTime[] times;
|
||||
|
||||
}
|
@@ -28,6 +28,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -55,6 +56,7 @@ public class CrmReceivablePlanController {
|
||||
@Resource
|
||||
private CrmReceivableService receivableService;
|
||||
@Resource
|
||||
@Lazy
|
||||
private CrmContractService contractService;
|
||||
@Resource
|
||||
private CrmCustomerService customerService;
|
||||
|
@@ -0,0 +1,33 @@
|
||||
package cn.iocoder.yudao.module.crm.dal.mysql.bi;
|
||||
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.bi.vo.CrmBiRanKRespVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.bi.vo.CrmBiRankReqVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* CRM BI 排行榜 Mapper
|
||||
*
|
||||
* @author anhaohao
|
||||
*/
|
||||
@Mapper
|
||||
public interface CrmBiRankingMapper {
|
||||
|
||||
/**
|
||||
* 查询合同金额排行榜
|
||||
*
|
||||
* @param rankReqVO 参数
|
||||
* @return 合同金额排行榜
|
||||
*/
|
||||
List<CrmBiRanKRespVO> selectContractPriceRank(CrmBiRankReqVO rankReqVO);
|
||||
|
||||
/**
|
||||
* 查询回款金额排行榜
|
||||
*
|
||||
* @param rankReqVO 参数
|
||||
* @return 回款金额排行榜
|
||||
*/
|
||||
List<CrmBiRanKRespVO> selectReceivablePriceRank(CrmBiRankReqVO rankReqVO);
|
||||
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package cn.iocoder.yudao.module.crm.service.bi;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.bi.vo.CrmBiRanKRespVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.bi.vo.CrmBiRankReqVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* CRM BI 排行榜 Service 接口
|
||||
*
|
||||
* @author anhaohao
|
||||
*/
|
||||
public interface CrmBiRankingService {
|
||||
|
||||
/**
|
||||
* 获得合同金额排行榜
|
||||
*
|
||||
* @param rankReqVO 排行参数
|
||||
* @return 合同金额排行榜
|
||||
*/
|
||||
List<CrmBiRanKRespVO> getContractPriceRank(CrmBiRankReqVO rankReqVO);
|
||||
|
||||
/**
|
||||
* 获得回款金额排行榜
|
||||
*
|
||||
* @param rankReqVO 排行参数
|
||||
* @return 回款金额排行榜
|
||||
*/
|
||||
List<CrmBiRanKRespVO> getReceivablePriceRank(CrmBiRankReqVO rankReqVO);
|
||||
|
||||
}
|
@@ -0,0 +1,104 @@
|
||||
package cn.iocoder.yudao.module.crm.service.bi;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.bi.vo.CrmBiRanKRespVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.bi.vo.CrmBiRankReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.bi.CrmBiRankingMapper;
|
||||
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
||||
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
|
||||
/**
|
||||
* CRM BI 排行榜 Service 实现类
|
||||
*
|
||||
* @author anhaohao
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class CrmBiRankingServiceImpl implements CrmBiRankingService {
|
||||
|
||||
@Resource
|
||||
private CrmBiRankingMapper biRankingMapper;
|
||||
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
@Resource
|
||||
private DeptApi deptApi;
|
||||
|
||||
@Override
|
||||
public List<CrmBiRanKRespVO> getContractPriceRank(CrmBiRankReqVO rankReqVO) {
|
||||
return getRank(rankReqVO, biRankingMapper::selectContractPriceRank);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CrmBiRanKRespVO> getReceivablePriceRank(CrmBiRankReqVO rankReqVO) {
|
||||
return getRank(rankReqVO, biRankingMapper::selectReceivablePriceRank);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得排行版数据
|
||||
*
|
||||
* @param rankReqVO 参数
|
||||
* @param rankFunction 排行榜方法
|
||||
* @return 排行版数据
|
||||
*/
|
||||
private List<CrmBiRanKRespVO> getRank(CrmBiRankReqVO rankReqVO, Function<CrmBiRankReqVO, List<CrmBiRanKRespVO>> rankFunction) {
|
||||
// 1. 获得用户编号数组
|
||||
rankReqVO.setUserIds(getUserIds(rankReqVO.getDeptId()));
|
||||
if (CollUtil.isEmpty(rankReqVO.getUserIds())) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// 2. 获得排行数据
|
||||
List<CrmBiRanKRespVO> ranks = rankFunction.apply(rankReqVO);
|
||||
if (CollUtil.isEmpty(ranks)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
ranks.sort(Comparator.comparing(CrmBiRanKRespVO::getCount).reversed());
|
||||
// 3. 拼接用户信息
|
||||
appendUserInfo(ranks);
|
||||
return ranks;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接用户信息(昵称、部门)
|
||||
*
|
||||
* @param ranks 排行榜数据
|
||||
*/
|
||||
private void appendUserInfo(List<CrmBiRanKRespVO> ranks) {
|
||||
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertSet(ranks, CrmBiRanKRespVO::getOwnerUserId));
|
||||
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
|
||||
ranks.forEach(rank -> MapUtils.findAndThen(userMap, rank.getOwnerUserId(), user -> {
|
||||
rank.setNickname(user.getNickname());
|
||||
MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> rank.setDeptName(dept.getName()));
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得部门下的用户编号数组,包括子部门的
|
||||
*
|
||||
* @param deptId 部门编号
|
||||
* @return 用户编号数组
|
||||
*/
|
||||
public List<Long> getUserIds(Long deptId) {
|
||||
// 1. 获得部门列表
|
||||
List<Long> deptIds = convertList(deptApi.getChildDeptList(deptId), DeptRespDTO::getId);
|
||||
deptIds.add(deptId);
|
||||
// 2. 获得用户编号
|
||||
return convertList(adminUserApi.getUserListByDeptIds(deptIds), AdminUserRespDTO::getId);
|
||||
}
|
||||
|
||||
}
|
@@ -57,7 +57,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
||||
@Resource
|
||||
private CrmBusinessProductService businessProductService;
|
||||
@Resource
|
||||
@Lazy
|
||||
@Lazy // 延迟加载,避免循环依赖
|
||||
private CrmContractService contractService;
|
||||
@Resource
|
||||
private CrmPermissionService permissionService;
|
||||
|
@@ -24,6 +24,7 @@ import com.mzt.logapi.context.LogRecordContext;
|
||||
import com.mzt.logapi.service.impl.DiffParseFunction;
|
||||
import com.mzt.logapi.starter.annotation.LogRecord;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
|
@@ -27,6 +27,7 @@ import com.mzt.logapi.context.LogRecordContext;
|
||||
import com.mzt.logapi.service.impl.DiffParseFunction;
|
||||
import com.mzt.logapi.starter.annotation.LogRecord;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
|
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.yudao.module.crm.dal.mysql.bi.CrmBiRankingMapper">
|
||||
|
||||
<select id="selectContractPriceRank"
|
||||
resultType="cn.iocoder.yudao.module.crm.controller.admin.bi.vo.CrmBiRanKRespVO">
|
||||
SELECT IFNULL(SUM(price), 0) AS count, owner_user_id
|
||||
FROM crm_contract
|
||||
WHERE deleted = 0
|
||||
AND audit_status = 20
|
||||
and owner_user_id in
|
||||
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
||||
#{userId}
|
||||
</foreach>
|
||||
AND order_date between #{times[0],javaType=java.time.LocalDateTime} and #{times[1],javaType=java.time.LocalDateTime}
|
||||
GROUP BY owner_user_id
|
||||
</select>
|
||||
|
||||
<select id="selectReceivablePriceRank"
|
||||
resultType="cn.iocoder.yudao.module.crm.controller.admin.bi.vo.CrmBiRanKRespVO">
|
||||
SELECT IFNULL(SUM(price), 0) AS count, owner_user_id
|
||||
FROM crm_receivable
|
||||
WHERE deleted = 0
|
||||
AND audit_status = 20
|
||||
and owner_user_id in
|
||||
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
|
||||
#{userId}
|
||||
</foreach>
|
||||
AND return_time between #{times[0],javaType=java.time.LocalDateTime} and #{times[1],javaType=java.time.LocalDateTime}
|
||||
GROUP BY owner_user_id
|
||||
</select>
|
||||
|
||||
</mapper>
|
Reference in New Issue
Block a user