errorCodeRespDTOs = errorCodeApi.getErrorCodeList(applicationName, maxUpdateTime);
- if (CollUtil.isEmpty(errorCodeRespDTOs)) {
- return;
- }
- log.info("[loadErrorCodes0][加载到 ({}) 个错误码]", errorCodeRespDTOs.size());
-
- // 刷新错误码的缓存
- errorCodeRespDTOs.forEach(errorCodeRespDTO -> {
- // 写入到错误码的缓存
- putErrorCode(errorCodeRespDTO.getCode(), errorCodeRespDTO.getMessage());
- // 记录下更新时间,方便增量更新
- maxUpdateTime = DateUtils.max(maxUpdateTime, errorCodeRespDTO.getUpdateTime());
- });
- } catch (Exception ex) {
- log.error("[loadErrorCodes0][加载错误码失败({})]", ExceptionUtil.getRootCauseMessage(ex));
- }
- }
-
-}
diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/package-info.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/package-info.java
deleted file mode 100644
index ddba4f78a5..0000000000
--- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/errorcode/package-info.java
+++ /dev/null
@@ -1,10 +0,0 @@
-/**
- * 错误码 ErrorCode 的自动配置功能,提供如下功能:
- *
- * 1. 远程读取:项目启动时,从 system-service 服务,读取数据库中的 ErrorCode 错误码,实现错误码的提水可配置;
- * 2. 自动更新:管理员在管理后台修数据库中的 ErrorCode 错误码时,项目自动从 system-service 服务加载最新的 ErrorCode 错误码;
- * 3. 自动写入:项目启动时,将项目本地的错误码写到 system-server 服务中,方便管理员在管理后台编辑;
- *
- * @author 芋道源码
- */
-package cn.iocoder.yudao.framework.errorcode;
diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/config/YudaoJacksonAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/config/YudaoJacksonAutoConfiguration.java
index 6ea95b1962..4f94f16ec5 100644
--- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/config/YudaoJacksonAutoConfiguration.java
+++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/config/YudaoJacksonAutoConfiguration.java
@@ -2,9 +2,9 @@ package cn.iocoder.yudao.framework.jackson.config;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
-import cn.iocoder.yudao.framework.jackson.core.databind.LocalDateTimeDeserializer;
-import cn.iocoder.yudao.framework.jackson.core.databind.LocalDateTimeSerializer;
import cn.iocoder.yudao.framework.jackson.core.databind.NumberSerializer;
+import cn.iocoder.yudao.framework.jackson.core.databind.TimestampLocalDateTimeDeserializer;
+import cn.iocoder.yudao.framework.jackson.core.databind.TimestampLocalDateTimeSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
@@ -37,13 +37,13 @@ public class YudaoJacksonAutoConfiguration {
.addDeserializer(LocalDate.class, LocalDateDeserializer.INSTANCE)
.addSerializer(LocalTime.class, LocalTimeSerializer.INSTANCE)
.addDeserializer(LocalTime.class, LocalTimeDeserializer.INSTANCE)
- // 新增 LocalDateTime 序列化、反序列化规则
- .addSerializer(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE)
- .addDeserializer(LocalDateTime.class, LocalDateTimeDeserializer.INSTANCE);
+ // 新增 LocalDateTime 序列化、反序列化规则,使用 Long 时间戳
+ .addSerializer(LocalDateTime.class, TimestampLocalDateTimeSerializer.INSTANCE)
+ .addDeserializer(LocalDateTime.class, TimestampLocalDateTimeDeserializer.INSTANCE);
// 1.2 注册到 objectMapper
objectMappers.forEach(objectMapper -> objectMapper.registerModule(simpleModule));
- // 2. 设置 objectMapper 到 JsonUtils {
+ // 2. 设置 objectMapper 到 JsonUtils
JsonUtils.init(CollUtil.getFirst(objectMappers));
log.info("[init][初始化 JsonUtils 成功]");
return new JsonUtils();
diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalDateTimeDeserializer.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/TimestampLocalDateTimeDeserializer.java
similarity index 62%
rename from yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalDateTimeDeserializer.java
rename to yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/TimestampLocalDateTimeDeserializer.java
index 53c40254b3..71a480fbf2 100644
--- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalDateTimeDeserializer.java
+++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/TimestampLocalDateTimeDeserializer.java
@@ -10,16 +10,18 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
/**
- * LocalDateTime反序列化规则
- *
- * 会将毫秒级时间戳反序列化为LocalDateTime
+ * 基于时间戳的 LocalDateTime 反序列化器
+ *
+ * @author 老五
*/
-public class LocalDateTimeDeserializer extends JsonDeserializer {
+public class TimestampLocalDateTimeDeserializer extends JsonDeserializer {
- public static final LocalDateTimeDeserializer INSTANCE = new LocalDateTimeDeserializer();
+ public static final TimestampLocalDateTimeDeserializer INSTANCE = new TimestampLocalDateTimeDeserializer();
@Override
public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
+ // 将 Long 时间戳,转换为 LocalDateTime 对象
return LocalDateTime.ofInstant(Instant.ofEpochMilli(p.getValueAsLong()), ZoneId.systemDefault());
}
+
}
diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalDateTimeSerializer.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/TimestampLocalDateTimeSerializer.java
similarity index 62%
rename from yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalDateTimeSerializer.java
rename to yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/TimestampLocalDateTimeSerializer.java
index 286fb733ed..e72c47bb81 100644
--- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/LocalDateTimeSerializer.java
+++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/core/databind/TimestampLocalDateTimeSerializer.java
@@ -9,16 +9,18 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
/**
- * LocalDateTime序列化规则
- *
- * 会将LocalDateTime序列化为毫秒级时间戳
+ * 基于时间戳的 LocalDateTime 序列化器
+ *
+ * @author 老五
*/
-public class LocalDateTimeSerializer extends JsonSerializer {
+public class TimestampLocalDateTimeSerializer extends JsonSerializer {
- public static final LocalDateTimeSerializer INSTANCE = new LocalDateTimeSerializer();
+ public static final TimestampLocalDateTimeSerializer INSTANCE = new TimestampLocalDateTimeSerializer();
@Override
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
+ // 将 LocalDateTime 对象,转换为 Long 时间戳
gen.writeNumber(value.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
}
+
}
diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java
index 243f949f28..7c60141953 100644
--- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java
+++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java
@@ -11,6 +11,10 @@ import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils;
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.validation.ConstraintViolation;
+import jakarta.validation.ConstraintViolationException;
+import jakarta.validation.ValidationException;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
@@ -26,13 +30,8 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.servlet.NoHandlerFoundException;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.validation.ConstraintViolation;
-import jakarta.validation.ConstraintViolationException;
-import jakarta.validation.ValidationException;
import java.time.LocalDateTime;
import java.util.Map;
-import java.util.Objects;
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.*;
@@ -181,14 +180,6 @@ public class GlobalExceptionHandler {
return CommonResult.error(METHOD_NOT_ALLOWED.getCode(), String.format("请求方法不正确:%s", ex.getMessage()));
}
- /**
- * 处理 Resilience4j 限流抛出的异常
- */
- public CommonResult> requestNotPermittedExceptionHandler(HttpServletRequest req, Throwable ex) {
- log.warn("[requestNotPermittedExceptionHandler][url({}) 访问过于频繁]", req.getRequestURL(), ex);
- return CommonResult.error(TOO_MANY_REQUESTS);
- }
-
/**
* 处理 Spring Security 权限不足的异常
*
@@ -223,12 +214,7 @@ public class GlobalExceptionHandler {
return tableNotExistsResult;
}
- // 情况二:部分特殊的库的处理
- if (Objects.equals("io.github.resilience4j.ratelimiter.RequestNotPermitted", ex.getClass().getName())) {
- return requestNotPermittedExceptionHandler(req, ex);
- }
-
- // 情况三:处理异常
+ // 情况二:处理异常
log.error("[defaultExceptionHandler]", ex);
// 插入异常日志
this.createExceptionLog(req, ex);
diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/yudao-framework/yudao-spring-boot-starter-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
index 36ba94cbb7..9cdcd09c4e 100644
--- a/yudao-framework/yudao-spring-boot-starter-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
+++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -3,5 +3,4 @@ cn.iocoder.yudao.framework.jackson.config.YudaoJacksonAutoConfiguration
cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration
cn.iocoder.yudao.framework.web.config.YudaoWebAutoConfiguration
cn.iocoder.yudao.framework.xss.config.YudaoXssAutoConfiguration
-cn.iocoder.yudao.framework.banner.config.YudaoBannerAutoConfiguration
-cn.iocoder.yudao.framework.errorcode.config.YudaoErrorCodeAutoConfiguration
\ No newline at end of file
+cn.iocoder.yudao.framework.banner.config.YudaoBannerAutoConfiguration
\ No newline at end of file
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateExpressionStrategy.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateExpressionStrategy.java
new file mode 100644
index 0000000000..e0f9dabe5a
--- /dev/null
+++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/strategy/BpmTaskCandidateExpressionStrategy.java
@@ -0,0 +1,36 @@
+package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.strategy;
+
+import cn.hutool.core.convert.Convert;
+import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy;
+import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
+import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
+import org.flowable.engine.delegate.DelegateExecution;
+import org.springframework.stereotype.Component;
+
+import java.util.Set;
+
+/**
+ * 流程表达式 {@link BpmTaskCandidateStrategy} 实现类
+ *
+ * @author 芋道源码
+ */
+@Component
+public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrategy {
+
+ @Override
+ public BpmTaskCandidateStrategyEnum getStrategy() {
+ return BpmTaskCandidateStrategyEnum.EXPRESSION;
+ }
+
+ @Override
+ public void validateParam(String param) {
+ // do nothing 因为它基本做不了校验
+ }
+
+ @Override
+ public Set calculateUsers(DelegateExecution execution, String param) {
+ Object result = FlowableUtils.getExpressionValue(execution, param);
+ return Convert.toSet(Long.class, result);
+ }
+
+}
\ No newline at end of file
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/test/resources/application-unit-test.yaml b/yudao-module-bpm/yudao-module-bpm-biz/src/test/resources/application-unit-test.yaml
new file mode 100644
index 0000000000..dd9b95bfb9
--- /dev/null
+++ b/yudao-module-bpm/yudao-module-bpm-biz/src/test/resources/application-unit-test.yaml
@@ -0,0 +1,42 @@
+spring:
+ main:
+ lazy-initialization: true # 开启懒加载,加快速度
+ banner-mode: off # 单元测试,禁用 Banner
+
+--- #################### 数据库相关配置 ####################
+
+spring:
+ # 数据源配置项
+ datasource:
+ name: ruoyi-vue-pro
+ url: jdbc:h2:mem:testdb;MODE=MYSQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=value; # MODE 使用 MySQL 模式;DATABASE_TO_UPPER 配置表和字段使用小写
+ driver-class-name: org.h2.Driver
+ username: sa
+ password:
+ druid:
+ async-init: true # 单元测试,异步初始化 Druid 连接池,提升启动速度
+ initial-size: 1 # 单元测试,配置为 1,提升启动速度
+ sql:
+ init:
+ schema-locations: classpath:/sql/create_tables.sql
+
+mybatis-plus:
+ lazy-initialization: true # 单元测试,设置 MyBatis Mapper 延迟加载,加速每个单元测试
+ type-aliases-package: ${yudao.info.base-package}.module.*.dal.dataobject
+
+--- #################### 定时任务相关配置 ####################
+
+--- #################### 配置中心相关配置 ####################
+
+--- #################### 服务保障相关配置 ####################
+
+# Lock4j 配置项(单元测试,禁用 Lock4j)
+
+--- #################### 监控相关配置 ####################
+
+--- #################### 芋道相关配置 ####################
+
+# 芋道配置项,设置当前项目所有自定义的配置
+yudao:
+ info:
+ base-package: cn.iocoder.yudao.module
diff --git a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
new file mode 100644
index 0000000000..07a6dad60d
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
@@ -0,0 +1,108 @@
+package cn.iocoder.yudao.module.crm.enums;
+
+import cn.iocoder.yudao.framework.common.exception.ErrorCode;
+
+/**
+ * CRM 错误码枚举类
+ *
+ * crm 系统,使用 1-020-000-000 段
+ */
+public interface ErrorCodeConstants {
+
+ // ========== 合同管理 1-020-000-000 ==========
+ ErrorCode CONTRACT_NOT_EXISTS = new ErrorCode(1_020_000_000, "合同不存在");
+ ErrorCode CONTRACT_UPDATE_FAIL_NOT_DRAFT = new ErrorCode(1_020_000_001, "合同更新失败,原因:合同不是草稿状态");
+ ErrorCode CONTRACT_SUBMIT_FAIL_NOT_DRAFT = new ErrorCode(1_020_000_002, "合同提交审核失败,原因:合同没处在未提交状态");
+ ErrorCode CONTRACT_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS = new ErrorCode(1_020_000_003, "更新合同审核状态失败,原因:合同不是审核中状态");
+ ErrorCode CONTRACT_NO_EXISTS = new ErrorCode(1_020_000_004, "生成合同序列号重复,请重试");
+ ErrorCode CONTRACT_DELETE_FAIL = new ErrorCode(1_020_000_005, "删除合同失败,原因:有被回款所使用");
+
+ // ========== 线索管理 1-020-001-000 ==========
+ ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在");
+ ErrorCode CLUE_TRANSFORM_FAIL_ALREADY = new ErrorCode(1_020_001_001, "线索已经转化过了,请勿重复转化");
+
+ // ========== 商机管理 1-020-002-000 ==========
+ ErrorCode BUSINESS_NOT_EXISTS = new ErrorCode(1_020_002_000, "商机不存在");
+ ErrorCode BUSINESS_DELETE_FAIL_CONTRACT_EXISTS = new ErrorCode(1_020_002_001, "商机已关联合同,不能删除");
+ ErrorCode BUSINESS_UPDATE_STATUS_FAIL_END_STATUS = new ErrorCode(1_020_002_002, "更新商机状态失败,原因:已经是结束状态");
+ ErrorCode BUSINESS_UPDATE_STATUS_FAIL_STATUS_EQUALS = new ErrorCode(1_020_002_003, "更新商机状态失败,原因:已经是该状态");
+
+ // ========== 联系人管理 1-020-003-000 ==========
+ ErrorCode CONTACT_NOT_EXISTS = new ErrorCode(1_020_003_000, "联系人不存在");
+ ErrorCode CONTACT_DELETE_FAIL_CONTRACT_LINK_EXISTS = new ErrorCode(1_020_003_002, "联系人已关联合同,不能删除");
+ ErrorCode CONTACT_UPDATE_OWNER_USER_FAIL = new ErrorCode(1_020_003_003, "更新联系人负责人失败");
+
+ // ========== 回款 1-020-004-000 ==========
+ ErrorCode RECEIVABLE_NOT_EXISTS = new ErrorCode(1_020_004_000, "回款不存在");
+ ErrorCode RECEIVABLE_UPDATE_FAIL_EDITING_PROHIBITED = new ErrorCode(1_020_004_001, "更新回款失败,原因:禁止编辑");
+ ErrorCode RECEIVABLE_DELETE_FAIL = new ErrorCode(1_020_004_002, "删除回款失败,原因: 被回款计划所使用,不允许删除");
+ ErrorCode RECEIVABLE_SUBMIT_FAIL_NOT_DRAFT = new ErrorCode(1_020_004_003, "回款提交审核失败,原因:回款没处在未提交状态");
+ ErrorCode RECEIVABLE_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS = new ErrorCode(1_020_004_004, "更新回款审核状态失败,原因:回款不是审核中状态");
+ ErrorCode RECEIVABLE_NO_EXISTS = new ErrorCode(1_020_004_005, "生成回款序列号重复,请重试");
+ ErrorCode RECEIVABLE_CREATE_FAIL_CONTRACT_NOT_APPROVE = new ErrorCode(1_020_004_006, "创建回款失败,原因:合同不是审核通过状态");
+ ErrorCode RECEIVABLE_CREATE_FAIL_PRICE_EXCEEDS_LIMIT = new ErrorCode(1_020_004_007, "创建回款失败,原因:回款金额超出合同金额,目前剩余可退:{} 元");
+ ErrorCode RECEIVABLE_DELETE_FAIL_IS_APPROVE = new ErrorCode(1_020_004_008, "删除回款失败,原因:回款审批已通过");
+
+ // ========== 回款计划 1-020-005-000 ==========
+ ErrorCode RECEIVABLE_PLAN_NOT_EXISTS = new ErrorCode(1_020_005_000, "回款计划不存在");
+ ErrorCode RECEIVABLE_PLAN_UPDATE_FAIL = new ErrorCode(1_020_006_000, "更想回款计划失败,原因:已经有对应的还款");
+ ErrorCode RECEIVABLE_PLAN_EXISTS_RECEIVABLE = new ErrorCode(1_020_006_001, "回款计划已经有对应的回款,不能使用");
+
+ // ========== 客户管理 1_020_006_000 ==========
+ ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(1_020_006_000, "客户不存在");
+ ErrorCode CUSTOMER_OWNER_EXISTS = new ErrorCode(1_020_006_001, "客户【{}】已存在所属负责人");
+ ErrorCode CUSTOMER_LOCKED = new ErrorCode(1_020_006_002, "客户【{}】状态已锁定");
+ ErrorCode CUSTOMER_ALREADY_DEAL = new ErrorCode(1_020_006_003, "客户已交易");
+ ErrorCode CUSTOMER_IN_POOL = new ErrorCode(1_020_006_004, "客户【{}】放入公海失败,原因:已经是公海客户");
+ ErrorCode CUSTOMER_LOCKED_PUT_POOL_FAIL = new ErrorCode(1_020_006_005, "客户【{}】放入公海失败,原因:客户已锁定");
+ ErrorCode CUSTOMER_UPDATE_OWNER_USER_FAIL = new ErrorCode(1_020_006_006, "更新客户【{}】负责人失败, 原因:系统异常");
+ ErrorCode CUSTOMER_LOCK_FAIL_IS_LOCK = new ErrorCode(1_020_006_007, "锁定客户失败,它已经处于锁定状态");
+ ErrorCode CUSTOMER_UNLOCK_FAIL_IS_UNLOCK = new ErrorCode(1_020_006_008, "解锁客户失败,它已经处于未锁定状态");
+ ErrorCode CUSTOMER_LOCK_EXCEED_LIMIT = new ErrorCode(1_020_006_009, "锁定客户失败,超出锁定规则上限");
+ ErrorCode CUSTOMER_OWNER_EXCEED_LIMIT = new ErrorCode(1_020_006_010, "操作失败,超出客户数拥有上限");
+ ErrorCode CUSTOMER_DELETE_FAIL_HAVE_REFERENCE = new ErrorCode(1_020_006_011, "删除客户失败,有关联{}");
+ ErrorCode CUSTOMER_IMPORT_LIST_IS_EMPTY = new ErrorCode(1_020_006_012, "导入客户数据不能为空!");
+ ErrorCode CUSTOMER_CREATE_NAME_NOT_NULL = new ErrorCode(1_020_006_013, "客户名称不能为空!");
+ ErrorCode CUSTOMER_NAME_EXISTS = new ErrorCode(1_020_006_014, "已存在名为【{}】的客户!");
+ ErrorCode CUSTOMER_UPDATE_DEAL_STATUS_FAIL = new ErrorCode(1_020_006_015, "更新客户的成交状态失败,原因:已经是该状态,无需更新");
+
+ // ========== 权限管理 1_020_007_000 ==========
+ ErrorCode CRM_PERMISSION_NOT_EXISTS = new ErrorCode(1_020_007_000, "数据权限不存在");
+ ErrorCode CRM_PERMISSION_DENIED = new ErrorCode(1_020_007_001, "{}操作失败,原因:没有权限");
+ ErrorCode CRM_PERMISSION_MODEL_TRANSFER_FAIL_OWNER_USER_EXISTS = new ErrorCode(1_020_007_003, "{}操作失败,原因:转移对象已经是该负责人");
+ ErrorCode CRM_PERMISSION_DELETE_FAIL = new ErrorCode(1_020_007_004, "删除数据权限失败,原因:批量删除权限的时候,只能属于同一个 bizId 下");
+ ErrorCode CRM_PERMISSION_DELETE_DENIED = new ErrorCode(1_020_007_006, "删除数据权限失败,原因:没有权限");
+ ErrorCode CRM_PERMISSION_DELETE_SELF_PERMISSION_FAIL_EXIST_OWNER = new ErrorCode(1_020_007_007, "删除数据权限失败,原因:不能删除负责人");
+ ErrorCode CRM_PERMISSION_CREATE_FAIL = new ErrorCode(1_020_007_008, "创建数据权限失败,原因:所加用户已有权限");
+ ErrorCode CRM_PERMISSION_CREATE_FAIL_EXISTS = new ErrorCode(1_020_007_009, "同时添加数据权限失败,原因:用户【{}】已有模块【{}】数据【{}】的【{}】权限");
+
+ // ========== 产品 1_020_008_000 ==========
+ ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_020_008_000, "产品不存在");
+ ErrorCode PRODUCT_NO_EXISTS = new ErrorCode(1_020_008_001, "产品编号已存在");
+ ErrorCode PRODUCT_NOT_ENABLE = new ErrorCode(1_020_008_002, "产品【{}】已禁用");
+
+ // ========== 产品分类 1_020_009_000 ==========
+ ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_020_009_000, "产品分类不存在");
+ ErrorCode PRODUCT_CATEGORY_EXISTS = new ErrorCode(1_020_009_001, "产品分类已存在");
+ ErrorCode PRODUCT_CATEGORY_USED = new ErrorCode(1_020_009_002, "产品分类已关联产品");
+ ErrorCode PRODUCT_CATEGORY_PARENT_NOT_EXISTS = new ErrorCode(1_020_009_003, "父分类不存在");
+ ErrorCode PRODUCT_CATEGORY_PARENT_NOT_FIRST_LEVEL = new ErrorCode(1_020_009_004, "父分类不能是二级分类");
+ ErrorCode PRODUCT_CATEGORY_EXISTS_CHILDREN = new ErrorCode(1_020_009_005, "存在子分类,无法删除");
+
+ // ========== 商机状态 1_020_010_000 ==========
+ ErrorCode BUSINESS_STATUS_TYPE_NOT_EXISTS = new ErrorCode(1_020_010_000, "商机状态组不存在");
+ ErrorCode BUSINESS_STATUS_TYPE_NAME_EXISTS = new ErrorCode(1_020_010_001, "商机状态组的名称已存在");
+ ErrorCode BUSINESS_STATUS_UPDATE_FAIL_USED = new ErrorCode(1_020_010_002, "已经被使用的商机状态组,无法进行更新");
+ ErrorCode BUSINESS_STATUS_DELETE_FAIL_USED = new ErrorCode(1_020_010_002, "已经被使用的商机状态组,无法进行删除");
+ ErrorCode BUSINESS_STATUS_NOT_EXISTS = new ErrorCode(1_020_010_003, "商机状态不存在");
+
+ // ========== 客户公海规则设置 1_020_012_000 ==========
+ ErrorCode CUSTOMER_LIMIT_CONFIG_NOT_EXISTS = new ErrorCode(1_020_012_001, "客户限制配置不存在");
+
+ // ========== 跟进记录 1_020_013_000 ==========
+ ErrorCode FOLLOW_UP_RECORD_NOT_EXISTS = new ErrorCode(1_020_013_000, "跟进记录不存在");
+ ErrorCode FOLLOW_UP_RECORD_DELETE_DENIED = new ErrorCode(1_020_013_001, "删除跟进记录失败,原因:没有权限");
+
+ // ========== 数据统计 1_020_014_000 ==========
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/LogRecordConstants.java b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/LogRecordConstants.java
new file mode 100644
index 0000000000..aeeed316dd
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/LogRecordConstants.java
@@ -0,0 +1,163 @@
+package cn.iocoder.yudao.module.crm.enums;
+
+/**
+ * CRM 操作日志枚举
+ * 目的:统一管理,也减少 Service 里各种“复杂”字符串
+ *
+ * @author HUIHUI
+ */
+public interface LogRecordConstants {
+
+ // ======================= CRM_CLUE 线索 =======================
+
+ String CRM_CLUE_TYPE = "CRM 线索";
+ String CRM_CLUE_CREATE_SUB_TYPE = "创建线索";
+ String CRM_CLUE_CREATE_SUCCESS = "创建了线索{{#clue.name}}";
+ String CRM_CLUE_UPDATE_SUB_TYPE = "更新线索";
+ String CRM_CLUE_UPDATE_SUCCESS = "更新了线索【{{#clueName}}】: {_DIFF{#updateReq}}";
+ String CRM_CLUE_DELETE_SUB_TYPE = "删除线索";
+ String CRM_CLUE_DELETE_SUCCESS = "删除了线索【{{#clueName}}】";
+ String CRM_CLUE_TRANSFER_SUB_TYPE = "转移线索";
+ String CRM_CLUE_TRANSFER_SUCCESS = "将线索【{{#clue.name}}】的负责人从【{getAdminUserById{#clue.ownerUserId}}】变更为了【{getAdminUserById{#reqVO.newOwnerUserId}}】";
+ String CRM_CLUE_TRANSLATE_SUB_TYPE = "线索转化为客户";
+ String CRM_CLUE_TRANSLATE_SUCCESS = "将线索【{{#clueName}}】转化为客户";
+ String CRM_CLUE_FOLLOW_UP_SUB_TYPE = "线索跟进";
+ String CRM_CLUE_FOLLOW_UP_SUCCESS = "线索跟进【{{#clueName}}】";
+
+ // ======================= CRM_CUSTOMER 客户 =======================
+
+ String CRM_CUSTOMER_TYPE = "CRM 客户";
+ String CRM_CUSTOMER_CREATE_SUB_TYPE = "创建客户";
+ String CRM_CUSTOMER_CREATE_SUCCESS = "创建了客户{{#customer.name}}";
+ String CRM_CUSTOMER_UPDATE_SUB_TYPE = "更新客户";
+ String CRM_CUSTOMER_UPDATE_SUCCESS = "更新了客户【{{#customerName}}】: {_DIFF{#updateReqVO}}";
+ String CRM_CUSTOMER_DELETE_SUB_TYPE = "删除客户";
+ String CRM_CUSTOMER_DELETE_SUCCESS = "删除了客户【{{#customerName}}】";
+ String CRM_CUSTOMER_TRANSFER_SUB_TYPE = "转移客户";
+ String CRM_CUSTOMER_TRANSFER_SUCCESS = "将客户【{{#customer.name}}】的负责人从【{getAdminUserById{#customer.ownerUserId}}】变更为了【{getAdminUserById{#reqVO.newOwnerUserId}}】";
+ String CRM_CUSTOMER_LOCK_SUB_TYPE = "{{#customer.lockStatus ? '解锁客户' : '锁定客户'}}";
+ String CRM_CUSTOMER_LOCK_SUCCESS = "{{#customer.lockStatus ? '将客户【' + #customer.name + '】解锁' : '将客户【' + #customer.name + '】锁定'}}";
+ String CRM_CUSTOMER_POOL_SUB_TYPE = "客户放入公海";
+ String CRM_CUSTOMER_POOL_SUCCESS = "将客户【{{#customerName}}】放入了公海";
+ String CRM_CUSTOMER_RECEIVE_SUB_TYPE = "{{#ownerUserName != null ? '分配客户' : '领取客户'}}";
+ String CRM_CUSTOMER_RECEIVE_SUCCESS = "{{#ownerUserName != null ? '将客户【' + #customer.name + '】分配给【' + #ownerUserName + '】' : '领取客户【' + #customer.name + '】'}}";
+ String CRM_CUSTOMER_IMPORT_SUB_TYPE = "{{#isUpdate ? '导入并更新客户' : '导入客户'}}";
+ String CRM_CUSTOMER_IMPORT_SUCCESS = "{{#isUpdate ? '导入并更新了客户【'+ #customer.name +'】' : '导入了客户【'+ #customer.name +'】'}}";
+ String CRM_CUSTOMER_UPDATE_DEAL_STATUS_SUB_TYPE = "更新客户成交状态";
+ String CRM_CUSTOMER_UPDATE_DEAL_STATUS_SUCCESS = "更新了客户【{{#customerName}}】的成交状态为【{{#dealStatus ? '已成交' : '未成交'}}】";
+ String CRM_CUSTOMER_FOLLOW_UP_SUB_TYPE = "客户跟进";
+ String CRM_CUSTOMER_FOLLOW_UP_SUCCESS = "客户跟进【{{#customerName}}】";
+
+ // ======================= CRM_CUSTOMER_LIMIT_CONFIG 客户限制配置 =======================
+
+ String CRM_CUSTOMER_LIMIT_CONFIG_TYPE = "CRM 客户限制配置";
+ String CRM_CUSTOMER_LIMIT_CONFIG_CREATE_SUB_TYPE = "创建客户限制配置";
+ String CRM_CUSTOMER_LIMIT_CONFIG_CREATE_SUCCESS = "创建了【{{#limitType}}】类型的客户限制配置";
+ String CRM_CUSTOMER_LIMIT_CONFIG_UPDATE_SUB_TYPE = "更新客户限制配置";
+ String CRM_CUSTOMER_LIMIT_CONFIG_UPDATE_SUCCESS = "更新了客户限制配置: {_DIFF{#updateReqVO}}";
+ String CRM_CUSTOMER_LIMIT_CONFIG_DELETE_SUB_TYPE = "删除客户限制配置";
+ String CRM_CUSTOMER_LIMIT_CONFIG_DELETE_SUCCESS = "删除了【{{#limitType}}】类型的客户限制配置";
+
+ // ======================= CRM_CUSTOMER_POOL_CONFIG 客户公海规则 =======================
+
+ String CRM_CUSTOMER_POOL_CONFIG_TYPE = "CRM 客户公海规则";
+ String CRM_CUSTOMER_POOL_CONFIG_SUB_TYPE = "{{#isPoolConfigUpdate ? '更新客户公海规则' : '创建客户公海规则'}}";
+ String CRM_CUSTOMER_POOL_CONFIG_SUCCESS = "{{#isPoolConfigUpdate ? '更新了客户公海规则' : '创建了客户公海规则'}}";
+
+ // ======================= CRM_CONTACT 联系人 =======================
+
+ String CRM_CONTACT_TYPE = "CRM 联系人";
+ String CRM_CONTACT_CREATE_SUB_TYPE = "创建联系人";
+ String CRM_CONTACT_CREATE_SUCCESS = "创建了联系人{{#contact.name}}";
+ String CRM_CONTACT_UPDATE_SUB_TYPE = "更新联系人";
+ String CRM_CONTACT_UPDATE_SUCCESS = "更新了联系人【{{#contactName}}】: {_DIFF{#updateReqVO}}";
+ String CRM_CONTACT_DELETE_SUB_TYPE = "删除联系人";
+ String CRM_CONTACT_DELETE_SUCCESS = "删除了联系人【{{#contactName}}】";
+ String CRM_CONTACT_TRANSFER_SUB_TYPE = "转移联系人";
+ String CRM_CONTACT_TRANSFER_SUCCESS = "将联系人【{{#contact.name}}】的负责人从【{getAdminUserById{#contact.ownerUserId}}】变更为了【{getAdminUserById{#reqVO.newOwnerUserId}}】";
+ String CRM_CONTACT_FOLLOW_UP_SUB_TYPE = "联系人跟进";
+ String CRM_CONTACT_FOLLOW_UP_SUCCESS = "联系人跟进【{{#contactName}}】";
+ String CRM_CONTACT_UPDATE_OWNER_USER_SUB_TYPE = "更新联系人负责人";
+ String CRM_CONTACT_UPDATE_OWNER_USER_SUCCESS = "将联系人【{{#contact.name}}】的负责人从【{getAdminUserById{#contact.ownerUserId}}】变更为了【{getAdminUserById{#ownerUserId}}】";
+
+ // ======================= CRM_BUSINESS 商机 =======================
+
+ String CRM_BUSINESS_TYPE = "CRM 商机";
+ String CRM_BUSINESS_CREATE_SUB_TYPE = "创建商机";
+ String CRM_BUSINESS_CREATE_SUCCESS = "创建了商机{{#business.name}}";
+ String CRM_BUSINESS_UPDATE_SUB_TYPE = "更新商机";
+ String CRM_BUSINESS_UPDATE_SUCCESS = "更新了商机【{{#businessName}}】: {_DIFF{#updateReqVO}}";
+ String CRM_BUSINESS_DELETE_SUB_TYPE = "删除商机";
+ String CRM_BUSINESS_DELETE_SUCCESS = "删除了商机【{{#businessName}}】";
+ String CRM_BUSINESS_TRANSFER_SUB_TYPE = "转移商机";
+ String CRM_BUSINESS_TRANSFER_SUCCESS = "将商机【{{#business.name}}】的负责人从【{getAdminUserById{#business.ownerUserId}}】变更为了【{getAdminUserById{#reqVO.newOwnerUserId}}】";
+ String CRM_BUSINESS_FOLLOW_UP_SUB_TYPE = "商机跟进";
+ String CRM_BUSINESS_FOLLOW_UP_SUCCESS = "商机跟进【{{#businessName}}】";
+ String CRM_BUSINESS_UPDATE_STATUS_SUB_TYPE = "更新商机状态";
+ String CRM_BUSINESS_UPDATE_STATUS_SUCCESS = "更新了商机【{{#businessName}}】的状态从【{{#oldStatusName}}】变更为了【{{#newStatusName}}】";
+
+ // ======================= CRM_CONTRACT_CONFIG 合同配置 =======================
+
+ String CRM_CONTRACT_CONFIG_TYPE = "CRM 合同配置";
+ String CRM_CONTRACT_CONFIG_SUB_TYPE = "{{#isPoolConfigUpdate ? '更新合同配置' : '创建合同配置'}}";
+ String CRM_CONTRACT_CONFIG_SUCCESS = "{{#isPoolConfigUpdate ? '更新了合同配置' : '创建了合同配置'}}";
+
+ // ======================= CRM_CONTRACT 合同 =======================
+
+ String CRM_CONTRACT_TYPE = "CRM 合同";
+ String CRM_CONTRACT_CREATE_SUB_TYPE = "创建合同";
+ String CRM_CONTRACT_CREATE_SUCCESS = "创建了合同{{#contract.name}}";
+ String CRM_CONTRACT_UPDATE_SUB_TYPE = "更新合同";
+ String CRM_CONTRACT_UPDATE_SUCCESS = "更新了合同【{{#contractName}}】: {_DIFF{#updateReqVO}}";
+ String CRM_CONTRACT_DELETE_SUB_TYPE = "删除合同";
+ String CRM_CONTRACT_DELETE_SUCCESS = "删除了合同【{{#contractName}}】";
+ String CRM_CONTRACT_TRANSFER_SUB_TYPE = "转移合同";
+ String CRM_CONTRACT_TRANSFER_SUCCESS = "将合同【{{#contract.name}}】的负责人从【{getAdminUserById{#contract.ownerUserId}}】变更为了【{getAdminUserById{#reqVO.newOwnerUserId}}】";
+ String CRM_CONTRACT_SUBMIT_SUB_TYPE = "提交合同审批";
+ String CRM_CONTRACT_SUBMIT_SUCCESS = "提交合同【{{#contractName}}】审批成功";
+ String CRM_CONTRACT_FOLLOW_UP_SUB_TYPE = "合同跟进";
+ String CRM_CONTRACT_FOLLOW_UP_SUCCESS = "合同跟进【{{#contractName}}】";
+
+ // ======================= CRM_PRODUCT 产品 =======================
+
+ String CRM_PRODUCT_TYPE = "CRM 产品";
+ String CRM_PRODUCT_CREATE_SUB_TYPE = "创建产品";
+ String CRM_PRODUCT_CREATE_SUCCESS = "创建了产品【{{#createReqVO.name}}】";
+ String CRM_PRODUCT_UPDATE_SUB_TYPE = "更新产品";
+ String CRM_PRODUCT_UPDATE_SUCCESS = "更新了产品【{{#updateReqVO.name}}】: {_DIFF{#updateReqVO}}";
+ String CRM_PRODUCT_DELETE_SUB_TYPE = "删除产品";
+ String CRM_PRODUCT_DELETE_SUCCESS = "删除了产品【{{#product.name}}】";
+
+ // ======================= CRM_PRODUCT_CATEGORY 产品分类 =======================
+
+ String CRM_PRODUCT_CATEGORY_TYPE = "CRM 产品分类";
+ String CRM_PRODUCT_CATEGORY_CREATE_SUB_TYPE = "创建产品分类";
+ String CRM_PRODUCT_CATEGORY_CREATE_SUCCESS = "创建了产品分类【{{#createReqVO.name}}】";
+ String CRM_PRODUCT_CATEGORY_UPDATE_SUB_TYPE = "更新产品分类";
+ String CRM_PRODUCT_CATEGORY_UPDATE_SUCCESS = "更新了产品分类【{{#updateReqVO.name}}】: {_DIFF{#updateReqVO}}";
+ String CRM_PRODUCT_CATEGORY_DELETE_SUB_TYPE = "删除产品分类";
+ String CRM_PRODUCT_CATEGORY_DELETE_SUCCESS = "删除了产品分类【{{#productCategory.name}}】";
+
+ // ======================= CRM_RECEIVABLE 回款 =======================
+
+ String CRM_RECEIVABLE_TYPE = "CRM 回款";
+ String CRM_RECEIVABLE_CREATE_SUB_TYPE = "创建回款";
+ String CRM_RECEIVABLE_CREATE_SUCCESS = "创建了合同【{getContractById{#receivable.contractId}}】的{{#period != null ? '【第'+ #period +'期】' : '编号为【'+ #receivable.no +'】的'}}回款";
+ String CRM_RECEIVABLE_UPDATE_SUB_TYPE = "更新回款";
+ String CRM_RECEIVABLE_UPDATE_SUCCESS = "更新了合同【{getContractById{#receivable.contractId}}】的{{#period != null ? '【第'+ #period +'期】' : '编号为【'+ #receivable.no +'】的'}}回款: {_DIFF{#updateReqVO}}";
+ String CRM_RECEIVABLE_DELETE_SUB_TYPE = "删除回款";
+ String CRM_RECEIVABLE_DELETE_SUCCESS = "删除了合同【{getContractById{#receivable.contractId}}】的{{#period != null ? '【第'+ #period +'期】' : '编号为【'+ #receivable.no +'】的'}}回款";
+ String CRM_RECEIVABLE_SUBMIT_SUB_TYPE = "提交回款审批";
+ String CRM_RECEIVABLE_SUBMIT_SUCCESS = "提交编号为【{{#receivableNo}}】的回款审批成功";
+
+ // ======================= CRM_RECEIVABLE_PLAN 回款计划 =======================
+
+ String CRM_RECEIVABLE_PLAN_TYPE = "CRM 回款计划";
+ String CRM_RECEIVABLE_PLAN_CREATE_SUB_TYPE = "创建回款计划";
+ String CRM_RECEIVABLE_PLAN_CREATE_SUCCESS = "创建了合同【{getContractById{#receivablePlan.contractId}}】的第【{{#receivablePlan.period}}】期回款计划";
+ String CRM_RECEIVABLE_PLAN_UPDATE_SUB_TYPE = "更新回款计划";
+ String CRM_RECEIVABLE_PLAN_UPDATE_SUCCESS = "更新了合同【{getContractById{#receivablePlan.contractId}}】的第【{{#receivablePlan.period}}】期回款计划: {_DIFF{#updateReqVO}}";
+ String CRM_RECEIVABLE_PLAN_DELETE_SUB_TYPE = "删除回款计划";
+ String CRM_RECEIVABLE_PLAN_DELETE_SUCCESS = "删除了合同【{getContractById{#receivablePlan.contractId}}】的第【{{#receivablePlan.period}}】期回款计划";
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/permission/CrmPermissionLevelEnum.java b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/permission/CrmPermissionLevelEnum.java
new file mode 100644
index 0000000000..f36e8cfffb
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/permission/CrmPermissionLevelEnum.java
@@ -0,0 +1,60 @@
+package cn.iocoder.yudao.module.crm.enums.permission;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjUtil;
+import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.Arrays;
+
+/**
+ * CRM 数据权限级别枚举
+ *
+ * OWNER > WRITE > READ
+ *
+ * @author HUIHUI
+ */
+@Getter
+@AllArgsConstructor
+public enum CrmPermissionLevelEnum implements IntArrayValuable {
+
+ OWNER(1, "负责人"),
+ READ(2, "只读"),
+ WRITE(3, "读写");
+
+ public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CrmPermissionLevelEnum::getLevel).toArray();
+
+ /**
+ * 级别
+ */
+ private final Integer level;
+ /**
+ * 级别名称
+ */
+ private final String name;
+
+ @Override
+ public int[] array() {
+ return ARRAYS;
+ }
+
+ public static boolean isOwner(Integer level) {
+ return ObjUtil.equal(OWNER.level, level);
+ }
+
+ public static boolean isRead(Integer level) {
+ return ObjUtil.equal(READ.level, level);
+ }
+
+ public static boolean isWrite(Integer level) {
+ return ObjUtil.equal(WRITE.level, level);
+ }
+
+ public static String getNameByLevel(Integer level) {
+ CrmPermissionLevelEnum typeEnum = CollUtil.findOne(CollUtil.newArrayList(CrmPermissionLevelEnum.values()),
+ item -> ObjUtil.equal(item.level, level));
+ return typeEnum == null ? null : typeEnum.getName();
+ }
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java
new file mode 100644
index 0000000000..a2bbd06362
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java
@@ -0,0 +1,222 @@
+package cn.iocoder.yudao.module.crm.controller.admin.business;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
+import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.*;
+import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessProductDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessStatusDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessStatusTypeDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
+import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
+import cn.iocoder.yudao.module.crm.service.business.CrmBusinessStatusService;
+import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
+import cn.iocoder.yudao.module.crm.service.product.CrmProductService;
+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 io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.validation.Valid;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
+import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
+import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_NOT_EXISTS;
+
+@Tag(name = "管理后台 - CRM 商机")
+@RestController
+@RequestMapping("/crm/business")
+@Validated
+public class CrmBusinessController {
+
+ @Resource
+ private CrmBusinessService businessService;
+ @Resource
+ private CrmCustomerService customerService;
+ @Resource
+ private CrmBusinessStatusService businessStatusTypeService;
+ @Resource
+ private CrmBusinessStatusService businessStatusService;
+ @Resource
+ private CrmProductService productService;
+
+ @Resource
+ private AdminUserApi adminUserApi;
+ @Resource
+ private DeptApi deptApi;
+
+ @PostMapping("/create")
+ @Operation(summary = "创建商机")
+ @PreAuthorize("@ss.hasPermission('crm:business:create')")
+ public CommonResult createBusiness(@Valid @RequestBody CrmBusinessSaveReqVO createReqVO) {
+ return success(businessService.createBusiness(createReqVO, getLoginUserId()));
+ }
+
+ @PutMapping("/update")
+ @Operation(summary = "更新商机")
+ @PreAuthorize("@ss.hasPermission('crm:business:update')")
+ public CommonResult updateBusiness(@Valid @RequestBody CrmBusinessSaveReqVO updateReqVO) {
+ businessService.updateBusiness(updateReqVO);
+ return success(true);
+ }
+
+ @PutMapping("/update-status")
+ @Operation(summary = "更新商机状态")
+ @PreAuthorize("@ss.hasPermission('crm:business:update')")
+ public CommonResult updateBusinessStatus(@Valid @RequestBody CrmBusinessUpdateStatusReqVO updateStatusReqVO) {
+ businessService.updateBusinessStatus(updateStatusReqVO);
+ return success(true);
+ }
+
+ @DeleteMapping("/delete")
+ @Operation(summary = "删除商机")
+ @Parameter(name = "id", description = "编号", required = true)
+ @PreAuthorize("@ss.hasPermission('crm:business:delete')")
+ public CommonResult deleteBusiness(@RequestParam("id") Long id) {
+ businessService.deleteBusiness(id);
+ return success(true);
+ }
+
+ @GetMapping("/get")
+ @Operation(summary = "获得商机")
+ @Parameter(name = "id", description = "编号", required = true, example = "1024")
+ @PreAuthorize("@ss.hasPermission('crm:business:query')")
+ public CommonResult getBusiness(@RequestParam("id") Long id) {
+ CrmBusinessDO business = businessService.getBusiness(id);
+ return success(buildBusinessDetail(business));
+ }
+
+ private CrmBusinessRespVO buildBusinessDetail(CrmBusinessDO business) {
+ if (business == null) {
+ return null;
+ }
+ CrmBusinessRespVO businessVO = buildBusinessDetailList(Collections.singletonList(business)).get(0);
+ // 拼接产品项
+ List businessProducts = businessService.getBusinessProductListByBusinessId(businessVO.getId());
+ Map productMap = productService.getProductMap(
+ convertSet(businessProducts, CrmBusinessProductDO::getProductId));
+ businessVO.setProducts(BeanUtils.toBean(businessProducts, CrmBusinessRespVO.Product.class, businessProductVO ->
+ MapUtils.findAndThen(productMap, businessProductVO.getProductId(),
+ product -> businessProductVO.setProductName(product.getName())
+ .setProductNo(product.getNo()).setProductUnit(product.getUnit()))));
+ return businessVO;
+ }
+
+ @GetMapping("/simple-all-list")
+ @Operation(summary = "获得联系人的精简列表")
+ @PreAuthorize("@ss.hasPermission('crm:contact:query')")
+ public CommonResult> getSimpleContactList() {
+ CrmBusinessPageReqVO reqVO = new CrmBusinessPageReqVO();
+ reqVO.setPageSize(PAGE_SIZE_NONE); // 不分页
+ PageResult pageResult = businessService.getBusinessPage(reqVO, getLoginUserId());
+ return success(convertList(pageResult.getList(), business -> // 只返回 id、name 字段
+ new CrmBusinessRespVO().setId(business.getId()).setName(business.getName())
+ .setCustomerId(business.getCustomerId())));
+ }
+
+ @GetMapping("/page")
+ @Operation(summary = "获得商机分页")
+ @PreAuthorize("@ss.hasPermission('crm:business:query')")
+ public CommonResult> getBusinessPage(@Valid CrmBusinessPageReqVO pageVO) {
+ PageResult pageResult = businessService.getBusinessPage(pageVO, getLoginUserId());
+ return success(new PageResult<>(buildBusinessDetailList(pageResult.getList()), pageResult.getTotal()));
+ }
+
+ @GetMapping("/page-by-customer")
+ @Operation(summary = "获得商机分页,基于指定客户")
+ public CommonResult> getBusinessPageByCustomer(@Valid CrmBusinessPageReqVO pageReqVO) {
+ if (pageReqVO.getCustomerId() == null) {
+ throw exception(CUSTOMER_NOT_EXISTS);
+ }
+ PageResult pageResult = businessService.getBusinessPageByCustomerId(pageReqVO);
+ return success(new PageResult<>(buildBusinessDetailList(pageResult.getList()), pageResult.getTotal()));
+ }
+
+ @GetMapping("/page-by-contact")
+ @Operation(summary = "获得联系人的商机分页")
+ @PreAuthorize("@ss.hasPermission('crm:business:query')")
+ public CommonResult> getBusinessContactPage(@Valid CrmBusinessPageReqVO pageReqVO) {
+ PageResult pageResult = businessService.getBusinessPageByContact(pageReqVO);
+ return success(new PageResult<>(buildBusinessDetailList(pageResult.getList()), pageResult.getTotal()));
+ }
+
+ @GetMapping("/export-excel")
+ @Operation(summary = "导出商机 Excel")
+ @PreAuthorize("@ss.hasPermission('crm:business:export')")
+ @ApiAccessLog(operateType = EXPORT)
+ public void exportBusinessExcel(@Valid CrmBusinessPageReqVO exportReqVO,
+ HttpServletResponse response) throws IOException {
+ exportReqVO.setPageSize(PAGE_SIZE_NONE);
+ List list = businessService.getBusinessPage(exportReqVO, getLoginUserId()).getList();
+ // 导出 Excel
+ ExcelUtils.write(response, "商机.xls", "数据", CrmBusinessRespVO.class,
+ buildBusinessDetailList(list));
+ }
+
+ private List buildBusinessDetailList(List list) {
+ if (CollUtil.isEmpty(list)) {
+ return Collections.emptyList();
+ }
+ // 1.1 获取客户列表
+ Map customerMap = customerService.getCustomerMap(
+ convertSet(list, CrmBusinessDO::getCustomerId));
+ // 1.2 获取创建人、负责人列表
+ Map userMap = adminUserApi.getUserMap(convertListByFlatMap(list,
+ contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId())));
+ Map deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
+ // 1.3 获得商机状态组
+ Map statusTypeMap = businessStatusTypeService.getBusinessStatusTypeMap(
+ convertSet(list, CrmBusinessDO::getStatusTypeId));
+ Map statusMap = businessStatusService.getBusinessStatusMap(
+ convertSet(list, CrmBusinessDO::getStatusId));
+ // 2. 拼接数据
+ return BeanUtils.toBean(list, CrmBusinessRespVO.class, businessVO -> {
+ // 2.1 设置客户名称
+ MapUtils.findAndThen(customerMap, businessVO.getCustomerId(), customer -> businessVO.setCustomerName(customer.getName()));
+ // 2.2 设置创建人、负责人名称
+ MapUtils.findAndThen(userMap, NumberUtils.parseLong(businessVO.getCreator()),
+ user -> businessVO.setCreatorName(user.getNickname()));
+ MapUtils.findAndThen(userMap, businessVO.getOwnerUserId(), user -> {
+ businessVO.setOwnerUserName(user.getNickname());
+ MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> businessVO.setOwnerUserDeptName(dept.getName()));
+ });
+ // 2.3 设置商机状态
+ MapUtils.findAndThen(statusTypeMap, businessVO.getStatusTypeId(), statusType -> businessVO.setStatusTypeName(statusType.getName()));
+ MapUtils.findAndThen(statusMap, businessVO.getStatusId(), status -> businessVO.setStatusName(
+ businessService.getBusinessStatusName(businessVO.getEndStatus(), status)));
+ });
+ }
+
+ @PutMapping("/transfer")
+ @Operation(summary = "商机转移")
+ @PreAuthorize("@ss.hasPermission('crm:business:update')")
+ public CommonResult transferBusiness(@Valid @RequestBody CrmBusinessTransferReqVO reqVO) {
+ businessService.transferBusiness(reqVO, getLoginUserId());
+ return success(true);
+ }
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java
new file mode 100644
index 0000000000..fa86692e7b
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java
@@ -0,0 +1,95 @@
+package cn.iocoder.yudao.module.crm.controller.admin.business.vo.business;
+
+import cn.iocoder.yudao.module.crm.framework.operatelog.core.CrmCustomerParseFunction;
+import cn.iocoder.yudao.module.crm.framework.operatelog.core.SysAdminUserParseFunction;
+import com.mzt.logapi.starter.annotation.DiffLogField;
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotNull;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.math.BigDecimal;
+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 商机创建/更新 Request VO")
+@Data
+public class CrmBusinessSaveReqVO {
+
+ @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "32129")
+ private Long id;
+
+ @Schema(description = "商机名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
+ @DiffLogField(name = "商机名称")
+ @NotNull(message = "商机名称不能为空")
+ private String name;
+
+ @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10299")
+ @DiffLogField(name = "客户", function = CrmCustomerParseFunction.NAME)
+ @NotNull(message = "客户不能为空")
+ private Long customerId;
+
+ @Schema(description = "下次联系时间")
+ @DiffLogField(name = "下次联系时间")
+ @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+ private LocalDateTime contactNextTime;
+
+ @Schema(description = "负责人用户编号", example = "14334")
+ @NotNull(message = "负责人不能为空")
+ @DiffLogField(name = "负责人", function = SysAdminUserParseFunction.NAME)
+ private Long ownerUserId;
+
+ @Schema(description = "商机状态组编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25714")
+ @DiffLogField(name = "商机状态组")
+ @NotNull(message = "商机状态组不能为空")
+ private Long statusTypeId;
+
+ @Schema(description = "预计成交日期")
+ @DiffLogField(name = "预计成交日期")
+ @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+ private LocalDateTime dealTime;
+
+ @Schema(description = "整单折扣", requiredMode = Schema.RequiredMode.REQUIRED, example = "55.00")
+ @DiffLogField(name = "整单折扣")
+ @NotNull(message = "整单折扣不能为空")
+ private BigDecimal discountPercent;
+
+ @Schema(description = "备注", example = "随便")
+ @DiffLogField(name = "备注")
+ private String remark;
+
+ @Schema(description = "联系人编号", example = "110")
+ private Long contactId; // 使用场景,在【联系人详情】添加商机时,如果需要关联两者,需要传递 contactId 字段
+
+ @Schema(description = "产品列表")
+ private List businessProducts;
+
+ @Schema(description = "产品列表")
+ @Data
+ @NoArgsConstructor
+ @AllArgsConstructor
+ public static class BusinessProduct {
+
+ @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20529")
+ @NotNull(message = "产品编号不能为空")
+ private Long productId;
+
+ @Schema(description = "产品单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "123.00")
+ @NotNull(message = "产品单价不能为空")
+ private BigDecimal productPrice;
+
+ @Schema(description = "商机价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "123.00")
+ @NotNull(message = "商机价格不能为空")
+ private BigDecimal businessPrice;
+
+ @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "8911")
+ @NotNull(message = "产品数量不能为空")
+ private Integer count;
+
+ }
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessTransferReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessTransferReqVO.java
new file mode 100644
index 0000000000..e26ddfa63f
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessTransferReqVO.java
@@ -0,0 +1,35 @@
+package cn.iocoder.yudao.module.crm.controller.admin.business.vo.business;
+
+import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotNull;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Schema(description = "管理后台 - 商机转移 Request VO")
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class CrmBusinessTransferReqVO {
+
+ @Schema(description = "商机编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
+ @NotNull(message = "商机编号不能为空")
+ private Long id;
+
+ /**
+ * 新负责人的用户编号
+ */
+ @Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
+ @NotNull(message = "新负责人的用户编号不能为空")
+ private Long newOwnerUserId;
+
+ /**
+ * 老负责人加入团队后的权限级别。如果 null 说明移除
+ *
+ * 关联 {@link CrmPermissionLevelEnum}
+ */
+ @Schema(description = "老负责人加入团队后的权限级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
+ private Integer oldOwnerPermissionLevel;
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/CrmClueController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/CrmClueController.java
new file mode 100644
index 0000000000..992549b315
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/CrmClueController.java
@@ -0,0 +1,173 @@
+package cn.iocoder.yudao.module.crm.controller.admin.clue;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
+import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
+import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmCluePageReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueRespVO;
+import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueSaveReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueTransferReqVO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
+import cn.iocoder.yudao.module.crm.service.clue.CrmClueService;
+import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
+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 io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.validation.Valid;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
+import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
+import static java.util.Collections.singletonList;
+
+@Tag(name = "管理后台 - 线索")
+@RestController
+@RequestMapping("/crm/clue")
+@Validated
+public class CrmClueController {
+
+ @Resource
+ private CrmClueService clueService;
+ @Resource
+ private CrmCustomerService customerService;
+
+ @Resource
+ private AdminUserApi adminUserApi;
+ @Resource
+ private DeptApi deptApi;
+
+ @PostMapping("/create")
+ @Operation(summary = "创建线索")
+ @PreAuthorize("@ss.hasPermission('crm:clue:create')")
+ public CommonResult createClue(@Valid @RequestBody CrmClueSaveReqVO createReqVO) {
+ return success(clueService.createClue(createReqVO));
+ }
+
+ @PutMapping("/update")
+ @Operation(summary = "更新线索")
+ @PreAuthorize("@ss.hasPermission('crm:clue:update')")
+ public CommonResult updateClue(@Valid @RequestBody CrmClueSaveReqVO updateReqVO) {
+ clueService.updateClue(updateReqVO);
+ return success(true);
+ }
+
+ @DeleteMapping("/delete")
+ @Operation(summary = "删除线索")
+ @Parameter(name = "id", description = "编号", required = true)
+ @PreAuthorize("@ss.hasPermission('crm:clue:delete')")
+ public CommonResult deleteClue(@RequestParam("id") Long id) {
+ clueService.deleteClue(id);
+ return success(true);
+ }
+
+ @GetMapping("/get")
+ @Operation(summary = "获得线索")
+ @Parameter(name = "id", description = "编号", required = true, example = "1024")
+ @PreAuthorize("@ss.hasPermission('crm:clue:query')")
+ public CommonResult getClue(@RequestParam("id") Long id) {
+ CrmClueDO clue = clueService.getClue(id);
+ return success(buildClueDetail(clue));
+ }
+
+ private CrmClueRespVO buildClueDetail(CrmClueDO clue) {
+ if (clue == null) {
+ return null;
+ }
+ return buildClueDetailList(singletonList(clue)).get(0);
+ }
+
+ @GetMapping("/page")
+ @Operation(summary = "获得线索分页")
+ @PreAuthorize("@ss.hasPermission('crm:clue:query')")
+ public CommonResult> getCluePage(@Valid CrmCluePageReqVO pageVO) {
+ PageResult pageResult = clueService.getCluePage(pageVO, getLoginUserId());
+ return success(new PageResult<>(buildClueDetailList(pageResult.getList()), pageResult.getTotal()));
+ }
+
+ @GetMapping("/export-excel")
+ @Operation(summary = "导出线索 Excel")
+ @PreAuthorize("@ss.hasPermission('crm:clue:export')")
+ @ApiAccessLog(operateType = EXPORT)
+ public void exportClueExcel(@Valid CrmCluePageReqVO pageReqVO, HttpServletResponse response) throws IOException {
+ pageReqVO.setPageSize(PAGE_SIZE_NONE);
+ List list = clueService.getCluePage(pageReqVO, getLoginUserId()).getList();
+ // 导出 Excel
+ ExcelUtils.write(response, "线索.xls", "数据", CrmClueRespVO.class, buildClueDetailList(list));
+ }
+
+ private List buildClueDetailList(List list) {
+ if (CollUtil.isEmpty(list)) {
+ return Collections.emptyList();
+ }
+ // 1.1 获取客户列表
+ Map customerMap = customerService.getCustomerMap(
+ convertSet(list, CrmClueDO::getCustomerId));
+ // 1.2 获取创建人、负责人列表
+ Map userMap = adminUserApi.getUserMap(convertListByFlatMap(list,
+ contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId())));
+ Map deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
+ // 2. 转换成 VO
+ return BeanUtils.toBean(list, CrmClueRespVO.class, clueVO -> {
+ clueVO.setAreaName(AreaUtils.format(clueVO.getAreaId()));
+ // 2.1 设置客户名称
+ MapUtils.findAndThen(customerMap, clueVO.getCustomerId(), customer -> clueVO.setCustomerName(customer.getName()));
+ // 2.2 设置创建人、负责人名称
+ MapUtils.findAndThen(userMap, NumberUtils.parseLong(clueVO.getCreator()),
+ user -> clueVO.setCreatorName(user.getNickname()));
+ MapUtils.findAndThen(userMap, clueVO.getOwnerUserId(), user -> {
+ clueVO.setOwnerUserName(user.getNickname());
+ MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> clueVO.setOwnerUserDeptName(dept.getName()));
+ });
+ });
+ }
+
+ @PutMapping("/transfer")
+ @Operation(summary = "线索转移")
+ @PreAuthorize("@ss.hasPermission('crm:clue:update')")
+ public CommonResult transferClue(@Valid @RequestBody CrmClueTransferReqVO reqVO) {
+ clueService.transferClue(reqVO, getLoginUserId());
+ return success(true);
+ }
+
+ @PutMapping("/transform")
+ @Operation(summary = "线索转化为客户")
+ @Parameter(name = "id", description = "编号", required = true)
+ @PreAuthorize("@ss.hasPermission('crm:clue:update')")
+ public CommonResult transformClue(@RequestParam("id") Long id) {
+ clueService.transformClue(id, getLoginUserId());
+ return success(Boolean.TRUE);
+ }
+
+ @GetMapping("/follow-count")
+ @Operation(summary = "获得分配给我的、待跟进的线索数量")
+ @PreAuthorize("@ss.hasPermission('crm:clue:query')")
+ public CommonResult getFollowClueCount() {
+ return success(clueService.getFollowClueCount(getLoginUserId()));
+ }
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java
new file mode 100644
index 0000000000..58ea20d493
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java
@@ -0,0 +1,226 @@
+package cn.iocoder.yudao.module.crm.controller.admin.contact;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.lang.Assert;
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
+import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
+import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*;
+import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
+import cn.iocoder.yudao.module.crm.service.contact.CrmContactBusinessService;
+import cn.iocoder.yudao.module.crm.service.contact.CrmContactService;
+import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
+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 io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.validation.Valid;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
+import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
+import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
+import static java.util.Collections.singletonList;
+
+@Tag(name = "管理后台 - CRM 联系人")
+@RestController
+@RequestMapping("/crm/contact")
+@Validated
+@Slf4j
+public class CrmContactController {
+
+ @Resource
+ private CrmContactService contactService;
+ @Resource
+ private CrmCustomerService customerService;
+ @Resource
+ private CrmContactBusinessService contactBusinessLinkService;
+
+ @Resource
+ private AdminUserApi adminUserApi;
+ @Resource
+ private DeptApi deptApi;
+
+ @PostMapping("/create")
+ @Operation(summary = "创建联系人")
+ @PreAuthorize("@ss.hasPermission('crm:contact:create')")
+ public CommonResult createContact(@Valid @RequestBody CrmContactSaveReqVO createReqVO) {
+ return success(contactService.createContact(createReqVO, getLoginUserId()));
+ }
+
+ @PutMapping("/update")
+ @Operation(summary = "更新联系人")
+ @PreAuthorize("@ss.hasPermission('crm:contact:update')")
+ public CommonResult updateContact(@Valid @RequestBody CrmContactSaveReqVO updateReqVO) {
+ contactService.updateContact(updateReqVO);
+ return success(true);
+ }
+
+ @DeleteMapping("/delete")
+ @Operation(summary = "删除联系人")
+ @Parameter(name = "id", description = "编号", required = true)
+ @PreAuthorize("@ss.hasPermission('crm:contact:delete')")
+ public CommonResult deleteContact(@RequestParam("id") Long id) {
+ contactService.deleteContact(id);
+ return success(true);
+ }
+
+ @GetMapping("/get")
+ @Operation(summary = "获得联系人")
+ @Parameter(name = "id", description = "编号", required = true, example = "1024")
+ @PreAuthorize("@ss.hasPermission('crm:contact:query')")
+ public CommonResult getContact(@RequestParam("id") Long id) {
+ CrmContactDO contact = contactService.getContact(id);
+ return success(buildContactDetail(contact));
+ }
+
+ private CrmContactRespVO buildContactDetail(CrmContactDO contact) {
+ if (contact == null) {
+ return null;
+ }
+ return buildContactDetailList(singletonList(contact)).get(0);
+ }
+
+ @GetMapping("/simple-all-list")
+ @Operation(summary = "获得联系人的精简列表")
+ @PreAuthorize("@ss.hasPermission('crm:contact:query')")
+ public CommonResult> getSimpleContactList() {
+ List list = contactService.getContactList(getLoginUserId());
+ return success(convertList(list, contact -> // 只返回 id、name 字段
+ new CrmContactRespVO().setId(contact.getId()).setName(contact.getName())
+ .setCustomerId(contact.getCustomerId())));
+ }
+
+ @GetMapping("/page")
+ @Operation(summary = "获得联系人分页")
+ @PreAuthorize("@ss.hasPermission('crm:contact:query')")
+ public CommonResult> getContactPage(@Valid CrmContactPageReqVO pageVO) {
+ PageResult pageResult = contactService.getContactPage(pageVO, getLoginUserId());
+ return success(new PageResult<>(buildContactDetailList(pageResult.getList()), pageResult.getTotal()));
+ }
+
+ @GetMapping("/page-by-customer")
+ @Operation(summary = "获得联系人分页,基于指定客户")
+ public CommonResult> getContactPageByCustomer(@Valid CrmContactPageReqVO pageVO) {
+ Assert.notNull(pageVO.getCustomerId(), "客户编号不能为空");
+ PageResult pageResult = contactService.getContactPageByCustomerId(pageVO);
+ return success(new PageResult<>(buildContactDetailList(pageResult.getList()), pageResult.getTotal()));
+ }
+
+ @GetMapping("/page-by-business")
+ @Operation(summary = "获得联系人分页,基于指定商机")
+ public CommonResult> getContactPageByBusiness(@Valid CrmContactPageReqVO pageVO) {
+ Assert.notNull(pageVO.getBusinessId(), "商机编号不能为空");
+ PageResult pageResult = contactService.getContactPageByBusinessId(pageVO);
+ return success(new PageResult<>(buildContactDetailList(pageResult.getList()), pageResult.getTotal()));
+ }
+
+ @GetMapping("/export-excel")
+ @Operation(summary = "导出联系人 Excel")
+ @PreAuthorize("@ss.hasPermission('crm:contact:export')")
+ @ApiAccessLog(operateType = EXPORT)
+ public void exportContactExcel(@Valid CrmContactPageReqVO exportReqVO,
+ HttpServletResponse response) throws IOException {
+ exportReqVO.setPageNo(PAGE_SIZE_NONE);
+ List list = contactService.getContactPage(exportReqVO, getLoginUserId()).getList();
+ ExcelUtils.write(response, "联系人.xls", "数据", CrmContactRespVO.class, buildContactDetailList(list));
+ }
+
+ private List buildContactDetailList(List contactList) {
+ if (CollUtil.isEmpty(contactList)) {
+ return Collections.emptyList();
+ }
+ // 1.1 获取客户列表
+ Map customerMap = customerService.getCustomerMap(
+ convertSet(contactList, CrmContactDO::getCustomerId));
+ // 1.2 获取创建人、负责人列表
+ Map userMap = adminUserApi.getUserMap(convertListByFlatMap(contactList,
+ contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId())));
+ Map deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
+ // 1.3 直属上级 Map
+ Map parentContactMap = contactService.getContactMap(
+ convertSet(contactList, CrmContactDO::getParentId));
+ // 2. 转换成 VO
+ return BeanUtils.toBean(contactList, CrmContactRespVO.class, contactVO -> {
+ contactVO.setAreaName(AreaUtils.format(contactVO.getAreaId()));
+ // 2.1 设置客户名称
+ MapUtils.findAndThen(customerMap, contactVO.getCustomerId(), customer -> contactVO.setCustomerName(customer.getName()));
+ // 2.2 设置创建人、负责人名称
+ MapUtils.findAndThen(userMap, NumberUtils.parseLong(contactVO.getCreator()),
+ user -> contactVO.setCreatorName(user.getNickname()));
+ MapUtils.findAndThen(userMap, contactVO.getOwnerUserId(), user -> {
+ contactVO.setOwnerUserName(user.getNickname());
+ MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> contactVO.setOwnerUserDeptName(dept.getName()));
+ });
+ // 2.3 设置直属上级名称
+ findAndThen(parentContactMap, contactVO.getParentId(), contact -> contactVO.setParentName(contact.getName()));
+ });
+ }
+
+ @PutMapping("/transfer")
+ @Operation(summary = "联系人转移")
+ @PreAuthorize("@ss.hasPermission('crm:contact:update')")
+ public CommonResult transferContact(@Valid @RequestBody CrmContactTransferReqVO reqVO) {
+ contactService.transferContact(reqVO, getLoginUserId());
+ return success(true);
+ }
+
+ // ================== 关联/取关商机 ===================
+
+ @PostMapping("/create-business-list")
+ @Operation(summary = "创建联系人与商机的关联")
+ @PreAuthorize("@ss.hasPermission('crm:contact:create-business')")
+ public CommonResult createContactBusinessList(@Valid @RequestBody CrmContactBusinessReqVO createReqVO) {
+ contactBusinessLinkService.createContactBusinessList(createReqVO);
+ return success(true);
+ }
+
+
+ @PostMapping("/create-business-list2")
+ @Operation(summary = "创建联系人与商机的关联")
+ @PreAuthorize("@ss.hasPermission('crm:contact:create-business')")
+ public CommonResult createContactBusinessList2(@Valid @RequestBody CrmContactBusiness2ReqVO createReqVO) {
+ contactBusinessLinkService.createContactBusinessList2(createReqVO);
+ return success(true);
+ }
+
+ @DeleteMapping("/delete-business-list")
+ @Operation(summary = "删除联系人与联系人的关联")
+ @PreAuthorize("@ss.hasPermission('crm:contact:delete-business')")
+ public CommonResult deleteContactBusinessList(@Valid @RequestBody CrmContactBusinessReqVO deleteReqVO) {
+ contactBusinessLinkService.deleteContactBusinessList(deleteReqVO);
+ return success(true);
+ }
+
+ @DeleteMapping("/delete-business-list2")
+ @Operation(summary = "删除联系人与联系人的关联")
+ @PreAuthorize("@ss.hasPermission('crm:contact:delete-business')")
+ public CommonResult deleteContactBusinessList(@Valid @RequestBody CrmContactBusiness2ReqVO deleteReqVO) {
+ contactBusinessLinkService.deleteContactBusinessList2(deleteReqVO);
+ return success(true);
+ }
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java
new file mode 100644
index 0000000000..0cd128cf93
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java
@@ -0,0 +1,36 @@
+package cn.iocoder.yudao.module.crm.controller.admin.contact.vo;
+
+import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import jakarta.validation.constraints.NotNull;
+import lombok.NoArgsConstructor;
+
+@Schema(description = "管理后台 - CRM 联系人转移 Request VO")
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class CrmContactTransferReqVO {
+
+ @Schema(description = "联系人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
+ @NotNull(message = "联系人编号不能为空")
+ private Long id;
+
+ /**
+ * 新负责人的用户编号
+ */
+ @Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
+ @NotNull(message = "新负责人的用户编号不能为空")
+ private Long newOwnerUserId;
+
+ /**
+ * 老负责人加入团队后的权限级别。如果 null 说明移除
+ *
+ * 关联 {@link CrmPermissionLevelEnum}
+ */
+ @Schema(description = "老负责人加入团队后的权限级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
+ private Integer oldOwnerPermissionLevel;
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java
new file mode 100644
index 0000000000..b9fd295183
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java
@@ -0,0 +1,256 @@
+package cn.iocoder.yudao.module.crm.controller.admin.contract;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.lang.Assert;
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
+import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractPageReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractRespVO;
+import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractSaveReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractTransferReqVO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractProductDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
+import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
+import cn.iocoder.yudao.module.crm.service.contact.CrmContactService;
+import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
+import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
+import cn.iocoder.yudao.module.crm.service.product.CrmProductService;
+import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableService;
+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 io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.validation.Valid;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
+import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
+import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
+import static java.util.Collections.singletonList;
+
+@Tag(name = "管理后台 - CRM 合同")
+@RestController
+@RequestMapping("/crm/contract")
+@Validated
+public class CrmContractController {
+
+ @Resource
+ private CrmContractService contractService;
+ @Resource
+ private CrmCustomerService customerService;
+ @Resource
+ private CrmContactService contactService;
+ @Resource
+ private CrmBusinessService businessService;
+ @Resource
+ private CrmProductService productService;
+ @Resource
+ private CrmReceivableService receivableService;
+
+ @Resource
+ private AdminUserApi adminUserApi;
+ @Resource
+ private DeptApi deptApi;
+
+ @PostMapping("/create")
+ @Operation(summary = "创建合同")
+ @PreAuthorize("@ss.hasPermission('crm:contract:create')")
+ public CommonResult createContract(@Valid @RequestBody CrmContractSaveReqVO createReqVO) {
+ return success(contractService.createContract(createReqVO, getLoginUserId()));
+ }
+
+ @PutMapping("/update")
+ @Operation(summary = "更新合同")
+ @PreAuthorize("@ss.hasPermission('crm:contract:update')")
+ public CommonResult updateContract(@Valid @RequestBody CrmContractSaveReqVO updateReqVO) {
+ contractService.updateContract(updateReqVO);
+ return success(true);
+ }
+
+ @DeleteMapping("/delete")
+ @Operation(summary = "删除合同")
+ @Parameter(name = "id", description = "编号", required = true)
+ @PreAuthorize("@ss.hasPermission('crm:contract:delete')")
+ public CommonResult deleteContract(@RequestParam("id") Long id) {
+ contractService.deleteContract(id);
+ return success(true);
+ }
+
+ @GetMapping("/get")
+ @Operation(summary = "获得合同")
+ @Parameter(name = "id", description = "编号", required = true, example = "1024")
+ @PreAuthorize("@ss.hasPermission('crm:contract:query')")
+ public CommonResult getContract(@RequestParam("id") Long id) {
+ CrmContractDO contract = contractService.getContract(id);
+ return success(buildContractDetail(contract));
+ }
+
+ private CrmContractRespVO buildContractDetail(CrmContractDO contract) {
+ if (contract == null) {
+ return null;
+ }
+ CrmContractRespVO contractVO = buildContractDetailList(singletonList(contract)).get(0);
+ // 拼接产品项
+ List businessProducts = contractService.getContractProductListByContractId(contractVO.getId());
+ Map productMap = productService.getProductMap(
+ convertSet(businessProducts, CrmContractProductDO::getProductId));
+ contractVO.setProducts(BeanUtils.toBean(businessProducts, CrmContractRespVO.Product.class, businessProductVO ->
+ MapUtils.findAndThen(productMap, businessProductVO.getProductId(),
+ product -> businessProductVO.setProductName(product.getName())
+ .setProductNo(product.getNo()).setProductUnit(product.getUnit()))));
+ return contractVO;
+ }
+
+ @GetMapping("/page")
+ @Operation(summary = "获得合同分页")
+ @PreAuthorize("@ss.hasPermission('crm:contract:query')")
+ public CommonResult> getContractPage(@Valid CrmContractPageReqVO pageVO) {
+ PageResult pageResult = contractService.getContractPage(pageVO, getLoginUserId());
+ return success(BeanUtils.toBean(pageResult, CrmContractRespVO.class).setList(buildContractDetailList(pageResult.getList())));
+ }
+
+ @GetMapping("/page-by-customer")
+ @Operation(summary = "获得合同分页,基于指定客户")
+ public CommonResult> getContractPageByCustomer(@Valid CrmContractPageReqVO pageVO) {
+ Assert.notNull(pageVO.getCustomerId(), "客户编号不能为空");
+ PageResult pageResult = contractService.getContractPageByCustomerId(pageVO);
+ return success(BeanUtils.toBean(pageResult, CrmContractRespVO.class).setList(buildContractDetailList(pageResult.getList())));
+ }
+
+ @GetMapping("/page-by-business")
+ @Operation(summary = "获得合同分页,基于指定商机")
+ public CommonResult> getContractPageByBusiness(@Valid CrmContractPageReqVO pageVO) {
+ Assert.notNull(pageVO.getBusinessId(), "商机编号不能为空");
+ PageResult pageResult = contractService.getContractPageByBusinessId(pageVO);
+ return success(BeanUtils.toBean(pageResult, CrmContractRespVO.class).setList(buildContractDetailList(pageResult.getList())));
+ }
+
+ @GetMapping("/export-excel")
+ @Operation(summary = "导出合同 Excel")
+ @PreAuthorize("@ss.hasPermission('crm:contract:export')")
+ @ApiAccessLog(operateType = EXPORT)
+ public void exportContractExcel(@Valid CrmContractPageReqVO exportReqVO,
+ HttpServletResponse response) throws IOException {
+ PageResult pageResult = contractService.getContractPage(exportReqVO, getLoginUserId());
+ // 导出 Excel
+ ExcelUtils.write(response, "合同.xls", "数据", CrmContractRespVO.class,
+ BeanUtils.toBean(pageResult.getList(), CrmContractRespVO.class));
+ }
+
+ @PutMapping("/transfer")
+ @Operation(summary = "合同转移")
+ @PreAuthorize("@ss.hasPermission('crm:contract:update')")
+ public CommonResult transferContract(@Valid @RequestBody CrmContractTransferReqVO reqVO) {
+ contractService.transferContract(reqVO, getLoginUserId());
+ return success(true);
+ }
+
+ @PutMapping("/submit")
+ @Operation(summary = "提交合同审批")
+ @PreAuthorize("@ss.hasPermission('crm:contract:update')")
+ public CommonResult submitContract(@RequestParam("id") Long id) {
+ contractService.submitContract(id, getLoginUserId());
+ return success(true);
+ }
+
+ private List buildContractDetailList(List contractList) {
+ if (CollUtil.isEmpty(contractList)) {
+ return Collections.emptyList();
+ }
+ // 1.1 获取客户列表
+ Map customerMap = customerService.getCustomerMap(
+ convertSet(contractList, CrmContractDO::getCustomerId));
+ // 1.2 获取创建人、负责人列表
+ Map userMap = adminUserApi.getUserMap(convertListByFlatMap(contractList,
+ contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId())));
+ Map deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
+ // 1.3 获取联系人
+ Map contactMap = convertMap(contactService.getContactList(convertSet(contractList,
+ CrmContractDO::getSignContactId)), CrmContactDO::getId);
+ // 1.4 获取商机
+ Map businessMap = businessService.getBusinessMap(
+ convertSet(contractList, CrmContractDO::getBusinessId));
+ // 1.5 获得已回款金额
+ Map receivablePriceMap = receivableService.getReceivablePriceMapByContractId(
+ convertSet(contractList, CrmContractDO::getId));
+ // 2. 拼接数据
+ return BeanUtils.toBean(contractList, CrmContractRespVO.class, contractVO -> {
+ // 2.1 设置客户信息
+ findAndThen(customerMap, contractVO.getCustomerId(), customer -> contractVO.setCustomerName(customer.getName()));
+ // 2.2 设置用户信息
+ findAndThen(userMap, Long.parseLong(contractVO.getCreator()), user -> contractVO.setCreatorName(user.getNickname()));
+ MapUtils.findAndThen(userMap, contractVO.getOwnerUserId(), user -> {
+ contractVO.setOwnerUserName(user.getNickname());
+ MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> contractVO.setOwnerUserDeptName(dept.getName()));
+ });
+ findAndThen(userMap, contractVO.getSignUserId(), user -> contractVO.setSignUserName(user.getNickname()));
+ // 2.3 设置联系人信息
+ findAndThen(contactMap, contractVO.getSignContactId(), contact -> contractVO.setSignContactName(contact.getName()));
+ // 2.4 设置商机信息
+ findAndThen(businessMap, contractVO.getBusinessId(), business -> contractVO.setBusinessName(business.getName()));
+ // 2.5 设置已回款金额
+ contractVO.setTotalReceivablePrice(receivablePriceMap.getOrDefault(contractVO.getId(), BigDecimal.ZERO));
+ });
+ }
+
+ @GetMapping("/audit-count")
+ @Operation(summary = "获得待审核合同数量")
+ @PreAuthorize("@ss.hasPermission('crm:contract:query')")
+ public CommonResult getAuditContractCount() {
+ return success(contractService.getAuditContractCount(getLoginUserId()));
+ }
+
+ @GetMapping("/remind-count")
+ @Operation(summary = "获得即将到期(提醒)的合同数量")
+ @PreAuthorize("@ss.hasPermission('crm:contract:query')")
+ public CommonResult getRemindContractCount() {
+ return success(contractService.getRemindContractCount(getLoginUserId()));
+ }
+
+ @GetMapping("/simple-list")
+ @Operation(summary = "获得合同精简列表", description = "只包含的合同,主要用于前端的下拉选项")
+ @Parameter(name = "customerId", description = "客户编号", required = true)
+ @PreAuthorize("@ss.hasPermission('crm:contract:query')")
+ public CommonResult> getContractSimpleList(@RequestParam("customerId") Long customerId) {
+ CrmContractPageReqVO pageReqVO = new CrmContractPageReqVO().setCustomerId(customerId);
+ pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); // 不分页
+ PageResult pageResult = contractService.getContractPageByCustomerId(pageReqVO);
+ if (CollUtil.isEmpty(pageResult.getList())) {
+ return success(Collections.emptyList());
+ }
+ // 拼接数据
+ Map receivablePriceMap = receivableService.getReceivablePriceMapByContractId(
+ convertSet(pageResult.getList(), CrmContractDO::getId));
+ return success(convertList(pageResult.getList(), contract -> new CrmContractRespVO() // 只返回 id、name 等精简字段
+ .setId(contract.getId()).setName(contract.getName()).setAuditStatus(contract.getAuditStatus())
+ .setTotalPrice(contract.getTotalPrice())
+ .setTotalReceivablePrice(receivablePriceMap.getOrDefault(contract.getId(), BigDecimal.ZERO))));
+ }
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/contract/CrmContractTransferReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/contract/CrmContractTransferReqVO.java
new file mode 100644
index 0000000000..3860844f41
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/contract/CrmContractTransferReqVO.java
@@ -0,0 +1,30 @@
+package cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract;
+
+import cn.iocoder.yudao.framework.common.validation.InEnum;
+import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import jakarta.validation.constraints.NotNull;
+import lombok.NoArgsConstructor;
+
+@Schema(description = "管理后台 - CRM 合同转移 Request VO")
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class CrmContractTransferReqVO {
+
+ @Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
+ @NotNull(message = "联系人编号不能为空")
+ private Long id;
+
+ @Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
+ @NotNull(message = "新负责人的用户编号不能为空")
+ private Long newOwnerUserId;
+
+ @Schema(description = "老负责人加入团队后的权限级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
+ @InEnum(value = CrmPermissionLevelEnum.class)
+ private Integer oldOwnerPermissionLevel;
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
new file mode 100644
index 0000000000..34388dfdb2
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
@@ -0,0 +1,316 @@
+package cn.iocoder.yudao.module.crm.controller.admin.customer;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.map.MapUtil;
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
+import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
+import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
+import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.customer.*;
+import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfigDO;
+import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerPoolConfigService;
+import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
+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 io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Parameters;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.validation.Valid;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.IOException;
+import java.time.LocalDateTime;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
+import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
+import static java.util.Collections.singletonList;
+
+@Tag(name = "管理后台 - CRM 客户")
+@RestController
+@RequestMapping("/crm/customer")
+@Validated
+public class CrmCustomerController {
+
+ @Resource
+ private CrmCustomerService customerService;
+ @Resource
+ private CrmCustomerPoolConfigService customerPoolConfigService;
+
+ @Resource
+ private DeptApi deptApi;
+ @Resource
+ private AdminUserApi adminUserApi;
+
+ @PostMapping("/create")
+ @Operation(summary = "创建客户")
+ @PreAuthorize("@ss.hasPermission('crm:customer:create')")
+ public CommonResult createCustomer(@Valid @RequestBody CrmCustomerSaveReqVO createReqVO) {
+ return success(customerService.createCustomer(createReqVO, getLoginUserId()));
+ }
+
+ @PutMapping("/update")
+ @Operation(summary = "更新客户")
+ @PreAuthorize("@ss.hasPermission('crm:customer:update')")
+ public CommonResult updateCustomer(@Valid @RequestBody CrmCustomerSaveReqVO updateReqVO) {
+ customerService.updateCustomer(updateReqVO);
+ return success(true);
+ }
+
+ @PutMapping("/update-deal-status")
+ @Operation(summary = "更新客户的成交状态")
+ @Parameters({
+ @Parameter(name = "id", description = "客户编号", required = true),
+ @Parameter(name = "dealStatus", description = "成交状态", required = true)
+ })
+ public CommonResult updateCustomerDealStatus(@RequestParam("id") Long id,
+ @RequestParam("dealStatus") Boolean dealStatus) {
+ customerService.updateCustomerDealStatus(id, dealStatus);
+ return success(true);
+ }
+
+ @DeleteMapping("/delete")
+ @Operation(summary = "删除客户")
+ @Parameter(name = "id", description = "客户编号", required = true)
+ @PreAuthorize("@ss.hasPermission('crm:customer:delete')")
+ public CommonResult deleteCustomer(@RequestParam("id") Long id) {
+ customerService.deleteCustomer(id);
+ return success(true);
+ }
+
+ @GetMapping("/get")
+ @Operation(summary = "获得客户")
+ @Parameter(name = "id", description = "编号", required = true, example = "1024")
+ @PreAuthorize("@ss.hasPermission('crm:customer:query')")
+ public CommonResult getCustomer(@RequestParam("id") Long id) {
+ // 1. 获取客户
+ CrmCustomerDO customer = customerService.getCustomer(id);
+ // 2. 拼接数据
+ return success(buildCustomerDetail(customer));
+ }
+
+ public CrmCustomerRespVO buildCustomerDetail(CrmCustomerDO customer) {
+ if (customer == null) {
+ return null;
+ }
+ return buildCustomerDetailList(singletonList(customer)).get(0);
+ }
+
+ @GetMapping("/page")
+ @Operation(summary = "获得客户分页")
+ @PreAuthorize("@ss.hasPermission('crm:customer:query')")
+ public CommonResult> getCustomerPage(@Valid CrmCustomerPageReqVO pageVO) {
+ // 1. 查询客户分页
+ PageResult pageResult = customerService.getCustomerPage(pageVO, getLoginUserId());
+ if (CollUtil.isEmpty(pageResult.getList())) {
+ return success(PageResult.empty(pageResult.getTotal()));
+ }
+ // 2. 拼接数据
+ return success(new PageResult<>(buildCustomerDetailList(pageResult.getList()), pageResult.getTotal()));
+ }
+
+ public List buildCustomerDetailList(List list) {
+ if (CollUtil.isEmpty(list)) {
+ return java.util.Collections.emptyList();
+ }
+ // 1.1 获取创建人、负责人列表
+ Map userMap = adminUserApi.getUserMap(convertSetByFlatMap(list,
+ contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId())));
+ Map deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
+ // 1.2 获取距离进入公海的时间
+ Map poolDayMap = getPoolDayMap(list);
+ // 2. 转换成 VO
+ return BeanUtils.toBean(list, CrmCustomerRespVO.class, customerVO -> {
+ customerVO.setAreaName(AreaUtils.format(customerVO.getAreaId()));
+ // 2.1 设置创建人、负责人名称
+ MapUtils.findAndThen(userMap, NumberUtils.parseLong(customerVO.getCreator()),
+ user -> customerVO.setCreatorName(user.getNickname()));
+ MapUtils.findAndThen(userMap, customerVO.getOwnerUserId(), user -> {
+ customerVO.setOwnerUserName(user.getNickname());
+ MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> customerVO.setOwnerUserDeptName(dept.getName()));
+ });
+ // 2.2 设置距离进入公海的时间
+ if (customerVO.getOwnerUserId() != null) {
+ customerVO.setPoolDay(poolDayMap.get(customerVO.getId()));
+ }
+ });
+ }
+
+ @GetMapping("/put-pool-remind-page")
+ @Operation(summary = "获得待进入公海客户分页")
+ @PreAuthorize("@ss.hasPermission('crm:customer:query')")
+ public CommonResult> getPutPoolRemindCustomerPage(@Valid CrmCustomerPageReqVO pageVO) {
+ // 1. 查询客户分页
+ PageResult pageResult = customerService.getPutPoolRemindCustomerPage(pageVO, getLoginUserId());
+ // 2. 拼接数据
+ return success(new PageResult<>(buildCustomerDetailList(pageResult.getList()), pageResult.getTotal()));
+ }
+
+ @GetMapping("/put-pool-remind-count")
+ @Operation(summary = "获得待进入公海客户数量")
+ @PreAuthorize("@ss.hasPermission('crm:customer:query')")
+ public CommonResult getPutPoolRemindCustomerCount() {
+ return success(customerService.getPutPoolRemindCustomerCount(getLoginUserId()));
+ }
+
+ @GetMapping("/today-contact-count")
+ @Operation(summary = "获得今日需联系客户数量")
+ @PreAuthorize("@ss.hasPermission('crm:customer:query')")
+ public CommonResult getTodayContactCustomerCount() {
+ return success(customerService.getTodayContactCustomerCount(getLoginUserId()));
+ }
+
+ @GetMapping("/follow-count")
+ @Operation(summary = "获得分配给我、待跟进的线索数量的客户数量")
+ @PreAuthorize("@ss.hasPermission('crm:customer:query')")
+ public CommonResult getFollowCustomerCount() {
+ return success(customerService.getFollowCustomerCount(getLoginUserId()));
+ }
+
+ /**
+ * 获取距离进入公海的时间 Map
+ *
+ * @param list 客户列表
+ * @return key 客户编号, value 距离进入公海的时间
+ */
+ private Map getPoolDayMap(List list) {
+ CrmCustomerPoolConfigDO poolConfig = customerPoolConfigService.getCustomerPoolConfig();
+ if (poolConfig == null || !poolConfig.getEnabled()) {
+ return MapUtil.empty();
+ }
+ list = CollectionUtils.filterList(list, customer -> {
+ // 特殊:如果没负责人,则说明已经在公海,不用计算
+ if (customer.getOwnerUserId() == null) {
+ return false;
+ }
+ // 已成交 or 已锁定,不进入公海
+ return !customer.getDealStatus() && !customer.getLockStatus();
+ });
+ return convertMap(list, CrmCustomerDO::getId, customer -> {
+ // 1.1 未成交放入公海天数
+ long dealExpireDay = poolConfig.getDealExpireDays() - LocalDateTimeUtils.between(customer.getOwnerTime());
+ // 1.2 未跟进放入公海天数
+ LocalDateTime lastTime = customer.getOwnerTime();
+ if (customer.getContactLastTime() != null && customer.getContactLastTime().isAfter(lastTime)) {
+ lastTime = customer.getContactLastTime();
+ }
+ long contactExpireDay = poolConfig.getContactExpireDays() - LocalDateTimeUtils.between(lastTime);
+ // 2. 返回最小的天数
+ long poolDay = Math.min(dealExpireDay, contactExpireDay);
+ return poolDay > 0 ? poolDay : 0;
+ });
+ }
+
+ @GetMapping(value = "/simple-list")
+ @Operation(summary = "获取客户精简信息列表", description = "只包含有读权限的客户,主要用于前端的下拉选项")
+ public CommonResult> getCustomerSimpleList() {
+ CrmCustomerPageReqVO reqVO = new CrmCustomerPageReqVO();
+ reqVO.setPageSize(PAGE_SIZE_NONE); // 不分页
+ List list = customerService.getCustomerPage(reqVO, getLoginUserId()).getList();
+ return success(convertList(list, customer -> // 只返回 id、name 精简字段
+ new CrmCustomerRespVO().setId(customer.getId()).setName(customer.getName())));
+ }
+
+ @GetMapping("/export-excel")
+ @Operation(summary = "导出客户 Excel")
+ @PreAuthorize("@ss.hasPermission('crm:customer:export')")
+ @ApiAccessLog(operateType = EXPORT)
+ public void exportCustomerExcel(@Valid CrmCustomerPageReqVO pageVO,
+ HttpServletResponse response) throws IOException {
+ pageVO.setPageSize(PAGE_SIZE_NONE); // 不分页
+ List list = customerService.getCustomerPage(pageVO, getLoginUserId()).getList();
+ // 导出 Excel
+ ExcelUtils.write(response, "客户.xls", "数据", CrmCustomerRespVO.class,
+ buildCustomerDetailList(list));
+ }
+
+ @GetMapping("/get-import-template")
+ @Operation(summary = "获得导入客户模板")
+ public void importTemplate(HttpServletResponse response) throws IOException {
+ // 手动创建导出 demo
+ List list = Arrays.asList(
+ CrmCustomerImportExcelVO.builder().name("芋道").industryId(1).level(1).source(1)
+ .mobile("15601691300").telephone("").qq("").wechat("").email("yunai@iocoder.cn")
+ .areaId(null).detailAddress("").remark("").build(),
+ CrmCustomerImportExcelVO.builder().name("源码").industryId(1).level(1).source(1)
+ .mobile("15601691300").telephone("").qq("").wechat("").email("yunai@iocoder.cn")
+ .areaId(null).detailAddress("").remark("").build()
+ );
+ // 输出
+ ExcelUtils.write(response, "客户导入模板.xls", "客户列表", CrmCustomerImportExcelVO.class, list);
+ }
+
+ @PostMapping("/import")
+ @Operation(summary = "导入客户")
+ @PreAuthorize("@ss.hasPermission('crm:customer:import')")
+ public CommonResult importExcel(@Valid CrmCustomerImportReqVO importReqVO)
+ throws Exception {
+ List list = ExcelUtils.read(importReqVO.getFile(), CrmCustomerImportExcelVO.class);
+ return success(customerService.importCustomerList(list, importReqVO));
+ }
+
+ @PutMapping("/transfer")
+ @Operation(summary = "转移客户")
+ @PreAuthorize("@ss.hasPermission('crm:customer:update')")
+ public CommonResult transferCustomer(@Valid @RequestBody CrmCustomerTransferReqVO reqVO) {
+ customerService.transferCustomer(reqVO, getLoginUserId());
+ return success(true);
+ }
+
+ @PutMapping("/lock")
+ @Operation(summary = "锁定/解锁客户")
+ @PreAuthorize("@ss.hasPermission('crm:customer:update')")
+ public CommonResult lockCustomer(@Valid @RequestBody CrmCustomerLockReqVO lockReqVO) {
+ customerService.lockCustomer(lockReqVO, getLoginUserId());
+ return success(true);
+ }
+
+ // ==================== 公海相关操作 ====================
+
+ @PutMapping("/put-pool")
+ @Operation(summary = "数据放入公海")
+ @Parameter(name = "id", description = "客户编号", required = true, example = "1024")
+ @PreAuthorize("@ss.hasPermission('crm:customer:update')")
+ public CommonResult putCustomerPool(@RequestParam("id") Long id) {
+ customerService.putCustomerPool(id);
+ return success(true);
+ }
+
+ @PutMapping("/receive")
+ @Operation(summary = "领取公海客户")
+ @Parameter(name = "ids", description = "编号数组", required = true, example = "1,2,3")
+ @PreAuthorize("@ss.hasPermission('crm:customer:receive')")
+ public CommonResult receiveCustomer(@RequestParam(value = "ids") List ids) {
+ customerService.receiveCustomer(ids, getLoginUserId(), Boolean.TRUE);
+ return success(true);
+ }
+
+ @PutMapping("/distribute")
+ @Operation(summary = "分配公海给对应负责人")
+ @PreAuthorize("@ss.hasPermission('crm:customer:distribute')")
+ public CommonResult distributeCustomer(@Valid @RequestBody CrmCustomerDistributeReqVO distributeReqVO) {
+ customerService.receiveCustomer(distributeReqVO.getIds(), distributeReqVO.getOwnerUserId(), Boolean.FALSE);
+ return success(true);
+ }
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerImportExcelVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerImportExcelVO.java
new file mode 100644
index 0000000000..a45e9115fe
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerImportExcelVO.java
@@ -0,0 +1,70 @@
+package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.customer;
+
+import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
+import cn.iocoder.yudao.framework.excel.core.annotations.ExcelColumnSelect;
+import cn.iocoder.yudao.framework.excel.core.convert.AreaConvert;
+import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
+import cn.iocoder.yudao.module.crm.framework.excel.core.AreaExcelColumnSelectFunction;
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+
+import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.*;
+
+/**
+ * 客户 Excel 导入 VO
+ */
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+@Accessors(chain = false) // 设置 chain = false,避免用户导入有问题
+public class CrmCustomerImportExcelVO {
+
+ @ExcelProperty("客户名称")
+ private String name;
+
+ @ExcelProperty("手机")
+ private String mobile;
+
+ @ExcelProperty("电话")
+ private String telephone;
+
+ @ExcelProperty("QQ")
+ private String qq;
+
+ @ExcelProperty("微信")
+ private String wechat;
+
+ @ExcelProperty("邮箱")
+ private String email;
+
+ @ExcelProperty(value = "地区", converter = AreaConvert.class)
+ @ExcelColumnSelect(functionName = AreaExcelColumnSelectFunction.NAME)
+ private Integer areaId;
+
+ @ExcelProperty("详细地址")
+ private String detailAddress;
+
+ @ExcelProperty(value = "所属行业", converter = DictConvert.class)
+ @DictFormat(CRM_CUSTOMER_INDUSTRY)
+ @ExcelColumnSelect(dictType = CRM_CUSTOMER_INDUSTRY)
+ private Integer industryId;
+
+ @ExcelProperty(value = "客户等级", converter = DictConvert.class)
+ @DictFormat(CRM_CUSTOMER_LEVEL)
+ @ExcelColumnSelect(dictType = CRM_CUSTOMER_LEVEL)
+ private Integer level;
+
+ @ExcelProperty(value = "客户来源", converter = DictConvert.class)
+ @DictFormat(CRM_CUSTOMER_SOURCE)
+ @ExcelColumnSelect(dictType = CRM_CUSTOMER_SOURCE)
+ private Integer source;
+
+ @ExcelProperty("备注")
+ private String remark;
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerTransferReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerTransferReqVO.java
new file mode 100644
index 0000000000..547ca63665
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/customer/CrmCustomerTransferReqVO.java
@@ -0,0 +1,39 @@
+package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.customer;
+
+import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotNull;
+import lombok.Data;
+
+import java.util.List;
+
+@Schema(description = "管理后台 - CRM 客户转移 Request VO")
+@Data
+public class CrmCustomerTransferReqVO {
+
+ @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
+ @NotNull(message = "客户编号不能为空")
+ private Long id;
+
+ /**
+ * 新负责人的用户编号
+ */
+ @Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
+ @NotNull(message = "新负责人的用户编号不能为空")
+ private Long newOwnerUserId;
+
+ /**
+ * 老负责人加入团队后的权限级别。如果 null 说明移除
+ *
+ * 关联 {@link CrmPermissionLevelEnum}
+ */
+ @Schema(description = "老负责人加入团队后的权限级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
+ private Integer oldOwnerPermissionLevel;
+
+ /**
+ * 转移客户时,需要额外有【联系人】【商机】【合同】的 checkbox 选择。选中时,也一起转移
+ */
+ @Schema(description = "同时转移", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
+ private List toBizTypes;
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/followup/CrmFollowUpRecordController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/followup/CrmFollowUpRecordController.java
new file mode 100644
index 0000000000..7946aea0e8
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/followup/CrmFollowUpRecordController.java
@@ -0,0 +1,100 @@
+package cn.iocoder.yudao.module.crm.controller.admin.followup;
+
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessRespVO;
+import cn.iocoder.yudao.module.crm.controller.admin.followup.vo.CrmFollowUpRecordPageReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.followup.vo.CrmFollowUpRecordRespVO;
+import cn.iocoder.yudao.module.crm.controller.admin.followup.vo.CrmFollowUpRecordSaveReqVO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.followup.CrmFollowUpRecordDO;
+import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
+import cn.iocoder.yudao.module.crm.service.contact.CrmContactService;
+import cn.iocoder.yudao.module.crm.service.followup.CrmFollowUpRecordService;
+import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
+import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import jakarta.validation.Valid;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.Map;
+
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap;
+import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
+
+
+@Tag(name = "管理后台 - 跟进记录")
+@RestController
+@RequestMapping("/crm/follow-up-record")
+@Validated
+public class CrmFollowUpRecordController {
+
+ @Resource
+ private CrmFollowUpRecordService followUpRecordService;
+ @Resource
+ private CrmContactService contactService;
+ @Resource
+ private CrmBusinessService businessService;
+
+ @Resource
+ private AdminUserApi adminUserApi;
+
+ @PostMapping("/create")
+ @Operation(summary = "创建跟进记录")
+ public CommonResult createFollowUpRecord(@Valid @RequestBody CrmFollowUpRecordSaveReqVO createReqVO) {
+ return success(followUpRecordService.createFollowUpRecord(createReqVO));
+ }
+
+ @DeleteMapping("/delete")
+ @Operation(summary = "删除跟进记录")
+ @Parameter(name = "id", description = "编号", required = true)
+ public CommonResult deleteFollowUpRecord(@RequestParam("id") Long id) {
+ followUpRecordService.deleteFollowUpRecord(id, getLoginUserId());
+ return success(true);
+ }
+
+ @GetMapping("/get")
+ @Operation(summary = "获得跟进记录")
+ @Parameter(name = "id", description = "编号", required = true, example = "1024")
+ public CommonResult getFollowUpRecord(@RequestParam("id") Long id) {
+ CrmFollowUpRecordDO followUpRecord = followUpRecordService.getFollowUpRecord(id);
+ return success(BeanUtils.toBean(followUpRecord, CrmFollowUpRecordRespVO.class));
+ }
+
+ @GetMapping("/page")
+ @Operation(summary = "获得跟进记录分页")
+ public CommonResult> getFollowUpRecordPage(@Valid CrmFollowUpRecordPageReqVO pageReqVO) {
+ PageResult pageResult = followUpRecordService.getFollowUpRecordPage(pageReqVO);
+ // 1.1 查询联系人和商机
+ Map contactMap = contactService.getContactMap(
+ convertSetByFlatMap(pageResult.getList(), item -> item.getContactIds().stream()));
+ Map businessMap = businessService.getBusinessMap(
+ convertSetByFlatMap(pageResult.getList(), item -> item.getBusinessIds().stream()));
+ // 1.2 查询用户
+ Map userMap = adminUserApi.getUserMap(
+ convertSet(pageResult.getList(), item -> Long.valueOf(item.getCreator())));
+ // 2. 拼接数据
+ PageResult voPageResult = BeanUtils.toBean(pageResult, CrmFollowUpRecordRespVO.class, record -> {
+ // 2.1 设置联系人和商机信息
+ record.setBusinesses(new ArrayList<>()).setContacts(new ArrayList<>());
+ record.getContactIds().forEach(id -> MapUtils.findAndThen(contactMap, id, contact ->
+ record.getContacts().add(new CrmBusinessRespVO().setId(contact.getId()).setName(contact.getName()))));
+ record.getBusinessIds().forEach(id -> MapUtils.findAndThen(businessMap, id, business ->
+ record.getBusinesses().add(new CrmBusinessRespVO().setId(business.getId()).setName(business.getName()))));
+ // 2.2 设置用户信息
+ MapUtils.findAndThen(userMap, Long.valueOf(record.getCreator()), user -> record.setCreatorName(user.getNickname()));
+ });
+ return success(voPageResult);
+ }
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/operatelog/CrmOperateLogController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/operatelog/CrmOperateLogController.java
new file mode 100644
index 0000000000..a981462466
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/operatelog/CrmOperateLogController.java
@@ -0,0 +1,63 @@
+package cn.iocoder.yudao.module.crm.controller.admin.operatelog;
+
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.crm.controller.admin.operatelog.vo.CrmOperateLogPageReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.operatelog.vo.CrmOperateLogRespVO;
+import cn.iocoder.yudao.module.crm.enums.LogRecordConstants;
+import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
+import cn.iocoder.yudao.module.system.api.logger.OperateLogApi;
+import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogPageReqDTO;
+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.HashMap;
+import java.util.Map;
+
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
+import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
+
+@Tag(name = "管理后台 - CRM 操作日志")
+@RestController
+@RequestMapping("/crm/operate-log")
+@Validated
+public class CrmOperateLogController {
+
+ @Resource
+ private OperateLogApi operateLogApi;
+
+ /**
+ * {@link CrmBizTypeEnum} 与 {@link LogRecordConstants} 的映射关系
+ */
+ private static final Map BIZ_TYPE_MAP = new HashMap<>();
+
+ static {
+ BIZ_TYPE_MAP.put(CrmBizTypeEnum.CRM_CLUE.getType(), CRM_CLUE_TYPE);
+ BIZ_TYPE_MAP.put(CrmBizTypeEnum.CRM_CUSTOMER.getType(), CRM_CUSTOMER_TYPE);
+ BIZ_TYPE_MAP.put(CrmBizTypeEnum.CRM_CONTACT.getType(), CRM_CONTACT_TYPE);
+ BIZ_TYPE_MAP.put(CrmBizTypeEnum.CRM_BUSINESS.getType(), CRM_BUSINESS_TYPE);
+ BIZ_TYPE_MAP.put(CrmBizTypeEnum.CRM_CONTRACT.getType(), CRM_CONTRACT_TYPE);
+ BIZ_TYPE_MAP.put(CrmBizTypeEnum.CRM_PRODUCT.getType(), CRM_PRODUCT_TYPE);
+ BIZ_TYPE_MAP.put(CrmBizTypeEnum.CRM_RECEIVABLE.getType(), CRM_RECEIVABLE_TYPE);
+ BIZ_TYPE_MAP.put(CrmBizTypeEnum.CRM_RECEIVABLE_PLAN.getType(), CRM_RECEIVABLE_PLAN_TYPE);
+ }
+
+ @GetMapping("/page")
+ @Operation(summary = "获得操作日志")
+ public CommonResult> getCustomerOperateLog(@Valid CrmOperateLogPageReqVO pageReqVO) {
+ OperateLogPageReqDTO reqDTO = new OperateLogPageReqDTO();
+ reqDTO.setPageSize(PAGE_SIZE_NONE); // 默认不分页,需要分页需注释
+ reqDTO.setType(BIZ_TYPE_MAP.get(pageReqVO.getBizType())).setBizId(pageReqVO.getBizId());
+ return success(BeanUtils.toBean(operateLogApi.getOperateLogPage(reqDTO), CrmOperateLogRespVO.class));
+ }
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/CrmPermissionController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/CrmPermissionController.java
new file mode 100644
index 0000000000..3373b104a3
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/CrmPermissionController.java
@@ -0,0 +1,126 @@
+package cn.iocoder.yudao.module.crm.controller.admin.permission;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
+import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionRespVO;
+import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionSaveReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionUpdateReqVO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
+import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
+import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission;
+import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
+import cn.iocoder.yudao.module.system.api.dept.DeptApi;
+import cn.iocoder.yudao.module.system.api.dept.PostApi;
+import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
+import cn.iocoder.yudao.module.system.api.dept.dto.PostRespDTO;
+import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
+import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
+import com.google.common.collect.Multimaps;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Parameters;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import jakarta.validation.Valid;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap;
+import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
+import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
+
+@Tag(name = "管理后台 - CRM 数据权限")
+@RestController
+@RequestMapping("/crm/permission")
+@Validated
+public class CrmPermissionController {
+
+ @Resource
+ private CrmPermissionService permissionService;
+ @Resource
+ private AdminUserApi adminUserApi;
+ @Resource
+ private DeptApi deptApi;
+ @Resource
+ private PostApi postApi;
+
+ @PostMapping("/create")
+ @Operation(summary = "创建数据权限")
+ public CommonResult create(@Valid @RequestBody CrmPermissionSaveReqVO reqVO) {
+ permissionService.createPermission(reqVO, getLoginUserId());
+ return success(true);
+ }
+
+ @PutMapping("/update")
+ @Operation(summary = "编辑数据权限")
+ @CrmPermission(bizTypeValue = "#updateReqVO.bizType", bizId = "#updateReqVO.bizId"
+ , level = CrmPermissionLevelEnum.OWNER)
+ public CommonResult updatePermission(@Valid @RequestBody CrmPermissionUpdateReqVO updateReqVO) {
+ permissionService.updatePermission(updateReqVO);
+ return success(true);
+ }
+
+ @DeleteMapping("/delete")
+ @Operation(summary = "删除数据权限")
+ @Parameter(name = "ids", description = "数据权限编号", required = true, example = "1024")
+ public CommonResult deletePermission(@RequestParam("ids") Collection ids) {
+ permissionService.deletePermissionBatch(ids, getLoginUserId());
+ return success(true);
+ }
+
+ @DeleteMapping("/delete-self")
+ @Operation(summary = "删除自己的数据权限")
+ @Parameter(name = "id", description = "数据权限编号", required = true, example = "1024")
+ public CommonResult deleteSelfPermission(@RequestParam("id") Long id) {
+ permissionService.deleteSelfPermission(id, getLoginUserId());
+ return success(true);
+ }
+
+ @GetMapping("/list")
+ @Operation(summary = "获得数据权限列表")
+ @Parameters({
+ @Parameter(name = "bizType", description = "CRM 类型", required = true, example = "2"),
+ @Parameter(name = "bizId", description = "CRM 类型数据编号", required = true, example = "1024")
+ })
+ public CommonResult> getPermissionList(@RequestParam("bizType") Integer bizType,
+ @RequestParam("bizId") Long bizId) {
+ List permissions = permissionService.getPermissionListByBiz(bizType, bizId);
+ if (CollUtil.isEmpty(permissions)) {
+ return success(Collections.emptyList());
+ }
+
+ // 查询相关数据
+ Map userMap = adminUserApi.getUserMap(
+ convertSet(permissions, CrmPermissionDO::getUserId));
+ Map deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
+ Map postMap = postApi.getPostMap(
+ convertSetByFlatMap(userMap.values(), AdminUserRespDTO::getPostIds,
+ item -> item != null ? item.stream() : Stream.empty()));
+ // 拼接数据
+ return success(CollectionUtils.convertList(BeanUtils.toBean(permissions, CrmPermissionRespVO.class), item -> {
+ findAndThen(userMap, item.getUserId(), user -> {
+ item.setNickname(user.getNickname());
+ findAndThen(deptMap, user.getDeptId(), deptRespDTO -> item.setDeptName(deptRespDTO.getName()));
+ if (CollUtil.isEmpty(user.getPostIds())) {
+ item.setPostNames(Collections.emptySet());
+ return;
+ }
+ List postList = MapUtils.getList(Multimaps.forMap(postMap), user.getPostIds());
+ item.setPostNames(CollectionUtils.convertSet(postList, PostRespDTO::getName));
+ });
+ return item;
+ }));
+ }
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionRespVO.java
new file mode 100644
index 0000000000..aeddf1a5de
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionRespVO.java
@@ -0,0 +1,50 @@
+package cn.iocoder.yudao.module.crm.controller.admin.permission.vo;
+
+import cn.iocoder.yudao.framework.common.validation.InEnum;
+import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
+import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotNull;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+import java.util.Set;
+
+@Schema(description = "管理后台 - CRM 数据权限 Response VO")
+@Data
+public class CrmPermissionRespVO {
+
+ @Schema(description = "数据权限编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
+ private Long id;
+
+ @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
+ @NotNull(message = "用户编号不能为空")
+ private Long userId;
+
+ @Schema(description = "CRM 类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
+ @InEnum(CrmBizTypeEnum.class)
+ @NotNull(message = "CRM 类型不能为空")
+ private Integer bizType;
+
+ @Schema(description = "CRM 类型数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+ @NotNull(message = "CRM 类型数据编号不能为空")
+ private Long bizId;
+
+ @Schema(description = "权限级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
+ @InEnum(CrmPermissionLevelEnum.class)
+ @NotNull(message = "权限级别不能为空")
+ private Integer level;
+
+ @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
+ private String nickname;
+
+ @Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "研发部")
+ private String deptName;
+
+ @Schema(description = "岗位名称数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[BOOS,经理]")
+ private Set postNames;
+
+ @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2023-01-01 00:00:00")
+ private LocalDateTime createTime;
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionSaveReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionSaveReqVO.java
new file mode 100644
index 0000000000..2ec7ed8db6
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/vo/CrmPermissionSaveReqVO.java
@@ -0,0 +1,42 @@
+package cn.iocoder.yudao.module.crm.controller.admin.permission.vo;
+
+import cn.iocoder.yudao.framework.common.validation.InEnum;
+import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
+import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import jakarta.validation.constraints.NotNull;
+
+import java.util.List;
+
+@Schema(description = "管理后台 - CRM 数据权限创建/更新 Request VO")
+@Data
+public class CrmPermissionSaveReqVO {
+
+ @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
+ @NotNull(message = "用户编号不能为空")
+ private Long userId;
+
+ @Schema(description = "CRM 类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
+ @InEnum(CrmBizTypeEnum.class)
+ @NotNull(message = "CRM 类型不能为空")
+ private Integer bizType;
+
+ @Schema(description = "CRM 类型数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+ @NotNull(message = "CRM 类型数据编号不能为空")
+ private Long bizId;
+
+ @Schema(description = "权限级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
+ @InEnum(CrmPermissionLevelEnum.class)
+ @NotNull(message = "权限级别不能为空")
+ private Integer level;
+
+ /**
+ * 添加客户团队成员时,需要额外有【联系人】【商机】【合同】的 checkbox 选择。
+ * 选中时,同时添加对应的权限
+ */
+ @Schema(description = "同时添加", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
+ private List toBizTypes;
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/CrmProductController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/CrmProductController.java
new file mode 100644
index 0000000000..bf98a80606
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/CrmProductController.java
@@ -0,0 +1,107 @@
+package cn.iocoder.yudao.module.crm.controller.admin.product;
+
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.framework.translate.core.TranslateUtils;
+import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductRespVO;
+import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductSaveReqVO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
+import cn.iocoder.yudao.module.crm.enums.product.CrmProductStatusEnum;
+import cn.iocoder.yudao.module.crm.service.product.CrmProductService;
+import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.validation.Valid;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.IOException;
+import java.util.List;
+
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
+
+@Tag(name = "管理后台 - CRM 产品")
+@RestController
+@RequestMapping("/crm/product")
+@Validated
+public class CrmProductController {
+
+ @Resource
+ private CrmProductService productService;
+ @Resource
+ private AdminUserApi adminUserApi;
+
+ @PostMapping("/create")
+ @Operation(summary = "创建产品")
+ @PreAuthorize("@ss.hasPermission('crm:product:create')")
+ public CommonResult createProduct(@Valid @RequestBody CrmProductSaveReqVO createReqVO) {
+ return success(productService.createProduct(createReqVO));
+ }
+
+ @PutMapping("/update")
+ @Operation(summary = "更新产品")
+ @PreAuthorize("@ss.hasPermission('crm:product:update')")
+ public CommonResult updateProduct(@Valid @RequestBody CrmProductSaveReqVO updateReqVO) {
+ productService.updateProduct(updateReqVO);
+ return success(true);
+ }
+
+ @DeleteMapping("/delete")
+ @Operation(summary = "删除产品")
+ @Parameter(name = "id", description = "编号", required = true)
+ @PreAuthorize("@ss.hasPermission('crm:product:delete')")
+ public CommonResult deleteProduct(@RequestParam("id") Long id) {
+ productService.deleteProduct(id);
+ return success(true);
+ }
+
+ @GetMapping("/get")
+ @Operation(summary = "获得产品")
+ @Parameter(name = "id", description = "编号", required = true, example = "1024")
+ @PreAuthorize("@ss.hasPermission('crm:product:query')")
+ public CommonResult getProduct(@RequestParam("id") Long id) {
+ CrmProductDO product = productService.getProduct(id);
+ return success(BeanUtils.toBean(product, CrmProductRespVO.class));
+ }
+
+ @GetMapping("/simple-list")
+ @Operation(summary = "获得产品精简列表", description = "只包含被开启的产品,主要用于前端的下拉选项")
+ public CommonResult> getProductSimpleList() {
+ List list = productService.getProductListByStatus(CrmProductStatusEnum.ENABLE.getStatus());
+ return success(convertList(list, product -> new CrmProductRespVO().setId(product.getId()).setName(product.getName())
+ .setUnit(product.getUnit()).setNo(product.getNo()).setPrice(product.getPrice())));
+ }
+
+ @GetMapping("/page")
+ @Operation(summary = "获得产品分页")
+ @PreAuthorize("@ss.hasPermission('crm:product:query')")
+ public CommonResult> getProductPage(@Valid CrmProductPageReqVO pageVO) {
+ PageResult pageResult = productService.getProductPage(pageVO);
+ return success(BeanUtils.toBean(pageResult, CrmProductRespVO.class));
+ }
+
+ @GetMapping("/export-excel")
+ @Operation(summary = "导出产品 Excel")
+ @PreAuthorize("@ss.hasPermission('crm:product:export')")
+ @ApiAccessLog(operateType = EXPORT)
+ public void exportProductExcel(@Valid CrmProductPageReqVO exportReqVO,
+ HttpServletResponse response) throws IOException {
+ exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+ List list = productService.getProductPage(exportReqVO).getList();
+ // 导出 Excel
+ ExcelUtils.write(response, "产品.xls", "数据", CrmProductRespVO.class,
+ TranslateUtils.translate(BeanUtils.toBean(list, CrmProductRespVO.class)));
+ }
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/CrmReceivableController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/CrmReceivableController.java
new file mode 100644
index 0000000000..58e02d187b
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/CrmReceivableController.java
@@ -0,0 +1,183 @@
+package cn.iocoder.yudao.module.crm.controller.admin.receivable;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.lang.Assert;
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
+import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractRespVO;
+import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivablePageReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableRespVO;
+import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableSaveReqVO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivableDO;
+import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
+import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
+import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableService;
+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 io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.validation.Valid;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
+import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
+import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
+
+@Tag(name = "管理后台 - CRM 回款")
+@RestController
+@RequestMapping("/crm/receivable")
+@Validated
+public class CrmReceivableController {
+
+ @Resource
+ private CrmReceivableService receivableService;
+ @Resource
+ private CrmContractService contractService;
+ @Resource
+ private CrmCustomerService customerService;
+
+ @Resource
+ private AdminUserApi adminUserApi;
+ @Resource
+ private DeptApi deptApi;
+
+ @PostMapping("/create")
+ @Operation(summary = "创建回款")
+ @PreAuthorize("@ss.hasPermission('crm:receivable:create')")
+ public CommonResult createReceivable(@Valid @RequestBody CrmReceivableSaveReqVO createReqVO) {
+ return success(receivableService.createReceivable(createReqVO));
+ }
+
+ @PutMapping("/update")
+ @Operation(summary = "更新回款")
+ @PreAuthorize("@ss.hasPermission('crm:receivable:update')")
+ public CommonResult updateReceivable(@Valid @RequestBody CrmReceivableSaveReqVO updateReqVO) {
+ receivableService.updateReceivable(updateReqVO);
+ return success(true);
+ }
+
+ @DeleteMapping("/delete")
+ @Operation(summary = "删除回款")
+ @Parameter(name = "id", description = "编号", required = true)
+ @PreAuthorize("@ss.hasPermission('crm:receivable:delete')")
+ public CommonResult deleteReceivable(@RequestParam("id") Long id) {
+ receivableService.deleteReceivable(id);
+ return success(true);
+ }
+
+ @GetMapping("/get")
+ @Operation(summary = "获得回款")
+ @Parameter(name = "id", description = "编号", required = true, example = "1024")
+ @PreAuthorize("@ss.hasPermission('crm:receivable:query')")
+ public CommonResult getReceivable(@RequestParam("id") Long id) {
+ CrmReceivableDO receivable = receivableService.getReceivable(id);
+ return success(buildReceivableDetail(receivable));
+ }
+
+ private CrmReceivableRespVO buildReceivableDetail(CrmReceivableDO receivable) {
+ if (receivable == null) {
+ return null;
+ }
+ return buildReceivableDetailList(Collections.singletonList(receivable)).get(0);
+ }
+
+ @GetMapping("/page")
+ @Operation(summary = "获得回款分页")
+ @PreAuthorize("@ss.hasPermission('crm:receivable:query')")
+ public CommonResult> getReceivablePage(@Valid CrmReceivablePageReqVO pageReqVO) {
+ PageResult pageResult = receivableService.getReceivablePage(pageReqVO, getLoginUserId());
+ return success(new PageResult<>(buildReceivableDetailList(pageResult.getList()), pageResult.getTotal()));
+ }
+
+ @GetMapping("/page-by-customer")
+ @Operation(summary = "获得回款分页,基于指定客户")
+ public CommonResult> getReceivablePageByCustomer(@Valid CrmReceivablePageReqVO pageReqVO) {
+ Assert.notNull(pageReqVO.getCustomerId(), "客户编号不能为空");
+ PageResult pageResult = receivableService.getReceivablePageByCustomerId(pageReqVO);
+ return success(new PageResult<>(buildReceivableDetailList(pageResult.getList()), pageResult.getTotal()));
+ }
+
+ @GetMapping("/export-excel")
+ @Operation(summary = "导出回款 Excel")
+ @PreAuthorize("@ss.hasPermission('crm:receivable:export')")
+ @ApiAccessLog(operateType = EXPORT)
+ public void exportReceivableExcel(@Valid CrmReceivablePageReqVO exportReqVO,
+ HttpServletResponse response) throws IOException {
+ exportReqVO.setPageSize(PAGE_SIZE_NONE);
+ List list = receivableService.getReceivablePage(exportReqVO, getLoginUserId()).getList();
+ // 导出 Excel
+ ExcelUtils.write(response, "回款.xls", "数据", CrmReceivableRespVO.class,
+ buildReceivableDetailList(list));
+ }
+
+ private List buildReceivableDetailList(List receivableList) {
+ if (CollUtil.isEmpty(receivableList)) {
+ return Collections.emptyList();
+ }
+ // 1.1 获取客户列表
+ Map customerMap = customerService.getCustomerMap(
+ convertSet(receivableList, CrmReceivableDO::getCustomerId));
+ // 1.2 获取创建人、负责人列表
+ Map userMap = adminUserApi.getUserMap(convertListByFlatMap(receivableList,
+ contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId())));
+ Map deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
+ // 1.3 获得合同列表
+ Map contractMap = contractService.getContractMap(
+ convertSet(receivableList, CrmReceivableDO::getContractId));
+ // 2. 拼接结果
+ return BeanUtils.toBean(receivableList, CrmReceivableRespVO.class, (receivableVO) -> {
+ // 2.1 拼接客户名称
+ findAndThen(customerMap, receivableVO.getCustomerId(), customer -> receivableVO.setCustomerName(customer.getName()));
+ // 2.2 拼接负责人、创建人名称
+ MapUtils.findAndThen(userMap, NumberUtils.parseLong(receivableVO.getCreator()),
+ user -> receivableVO.setCreatorName(user.getNickname()));
+ MapUtils.findAndThen(userMap, receivableVO.getOwnerUserId(), user -> {
+ receivableVO.setOwnerUserName(user.getNickname());
+ MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> receivableVO.setOwnerUserDeptName(dept.getName()));
+ });
+ // 2.3 拼接合同信息
+ findAndThen(contractMap, receivableVO.getContractId(), contract ->
+ receivableVO.setContract(BeanUtils.toBean(contract, CrmContractRespVO.class)));
+ });
+ }
+
+ @PutMapping("/submit")
+ @Operation(summary = "提交回款审批")
+ @PreAuthorize("@ss.hasPermission('crm:receivable:update')")
+ public CommonResult submitContract(@RequestParam("id") Long id) {
+ receivableService.submitReceivable(id, getLoginUserId());
+ return success(true);
+ }
+
+ @GetMapping("/audit-count")
+ @Operation(summary = "获得待审核回款数量")
+ @PreAuthorize("@ss.hasPermission('crm:receivable:query')")
+ public CommonResult getAuditReceivableCount() {
+ return success(receivableService.getAuditReceivableCount(getLoginUserId()));
+ }
+
+}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/CrmReceivablePlanController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/CrmReceivablePlanController.java
new file mode 100644
index 0000000000..0e879ae38c
--- /dev/null
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/receivable/CrmReceivablePlanController.java
@@ -0,0 +1,190 @@
+package cn.iocoder.yudao.module.crm.controller.admin.receivable;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.lang.Assert;
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanPageReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanRespVO;
+import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan.CrmReceivablePlanSaveReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableRespVO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivableDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivablePlanDO;
+import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
+import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
+import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivablePlanService;
+import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableService;
+import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
+import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Parameters;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.validation.Valid;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
+import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
+import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
+
+@Tag(name = "管理后台 - CRM 回款计划")
+@RestController
+@RequestMapping("/crm/receivable-plan")
+@Validated
+public class CrmReceivablePlanController {
+
+ @Resource
+ private CrmReceivablePlanService receivablePlanService;
+ @Resource
+ private CrmReceivableService receivableService;
+ @Resource
+ private CrmContractService contractService;
+ @Resource
+ private CrmCustomerService customerService;
+
+ @Resource
+ private AdminUserApi adminUserApi;
+
+ @PostMapping("/create")
+ @Operation(summary = "创建回款计划")
+ @PreAuthorize("@ss.hasPermission('crm:receivable-plan:create')")
+ public CommonResult createReceivablePlan(@Valid @RequestBody CrmReceivablePlanSaveReqVO createReqVO) {
+ return success(receivablePlanService.createReceivablePlan(createReqVO));
+ }
+
+ @PutMapping("/update")
+ @Operation(summary = "更新回款计划")
+ @PreAuthorize("@ss.hasPermission('crm:receivable-plan:update')")
+ public CommonResult updateReceivablePlan(@Valid @RequestBody CrmReceivablePlanSaveReqVO updateReqVO) {
+ receivablePlanService.updateReceivablePlan(updateReqVO);
+ return success(true);
+ }
+
+ @DeleteMapping("/delete")
+ @Operation(summary = "删除回款计划")
+ @Parameter(name = "id", description = "编号", required = true)
+ @PreAuthorize("@ss.hasPermission('crm:receivable-plan:delete')")
+ public CommonResult deleteReceivablePlan(@RequestParam("id") Long id) {
+ receivablePlanService.deleteReceivablePlan(id);
+ return success(true);
+ }
+
+ @GetMapping("/get")
+ @Operation(summary = "获得回款计划")
+ @Parameter(name = "id", description = "编号", required = true, example = "1024")
+ @PreAuthorize("@ss.hasPermission('crm:receivable-plan:query')")
+ public CommonResult getReceivablePlan(@RequestParam("id") Long id) {
+ CrmReceivablePlanDO receivablePlan = receivablePlanService.getReceivablePlan(id);
+ return success(buildReceivablePlanDetail(receivablePlan));
+ }
+
+ private CrmReceivablePlanRespVO buildReceivablePlanDetail(CrmReceivablePlanDO receivablePlan) {
+ if (receivablePlan == null) {
+ return null;
+ }
+ return buildReceivableDetailList(Collections.singletonList(receivablePlan)).get(0);
+ }
+
+ @GetMapping("/page")
+ @Operation(summary = "获得回款计划分页")
+ @PreAuthorize("@ss.hasPermission('crm:receivable-plan:query')")
+ public CommonResult> getReceivablePlanPage(@Valid CrmReceivablePlanPageReqVO pageReqVO) {
+ PageResult pageResult = receivablePlanService.getReceivablePlanPage(pageReqVO, getLoginUserId());
+ return success(new PageResult<>(buildReceivableDetailList(pageResult.getList()), pageResult.getTotal()));
+ }
+
+ @GetMapping("/page-by-customer")
+ @Operation(summary = "获得回款计划分页,基于指定客户")
+ public CommonResult> getReceivablePlanPageByCustomer(@Valid CrmReceivablePlanPageReqVO pageReqVO) {
+ Assert.notNull(pageReqVO.getCustomerId(), "客户编号不能为空");
+ PageResult pageResult = receivablePlanService.getReceivablePlanPageByCustomerId(pageReqVO);
+ return success(new PageResult<>(buildReceivableDetailList(pageResult.getList()), pageResult.getTotal()));
+ }
+
+ @GetMapping("/export-excel")
+ @Operation(summary = "导出回款计划 Excel")
+ @PreAuthorize("@ss.hasPermission('crm:receivable-plan:export')")
+ @ApiAccessLog(operateType = EXPORT)
+ public void exportReceivablePlanExcel(@Valid CrmReceivablePlanPageReqVO exportReqVO,
+ HttpServletResponse response) throws IOException {
+ exportReqVO.setPageSize(PAGE_SIZE_NONE);
+ List