Bladeren bron

!810 fix:修复 issues 提到的一些公众号上的问题
Merge pull request !810 from puhui999/develop

芋道源码 1 jaar geleden
bovenliggende
commit
3c7f63c356
47 gewijzigde bestanden met toevoegingen van 744 en 563 verwijderingen
  1. 5 0
      yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java
  2. 2 2
      yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogV2Configuration.java
  3. 10 6
      yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/core/service/LogRecordServiceImpl.java
  4. 1 1
      yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
  5. 58 18
      yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/LogRecordConstants.java
  6. 8 0
      yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/customer/CrmCustomerLimitConfigTypeEnum.java
  7. 50 44
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
  8. 5 7
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerLimitConfigController.java
  9. 2 4
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerPoolConfigController.java
  10. 0 20
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerCreateReqVO.java
  11. 21 0
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerDistributeReqVO.java
  12. 0 93
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerExcelVO.java
  13. 0 20
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerOperateLogPageReqVO.java
  14. 0 17
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerQueryAllRespVO.java
  15. 92 10
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerRespVO.java
  16. 8 5
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerSaveReqVO.java
  17. 20 0
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerSimpleRespVO.java
  18. 0 20
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerUpdateReqVO.java
  19. 0 14
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/limitconfig/CrmCustomerLimitConfigCreateReqVO.java
  20. 19 5
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/limitconfig/CrmCustomerLimitConfigRespVO.java
  21. 12 6
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/limitconfig/CrmCustomerLimitConfigSaveReqVO.java
  22. 0 20
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/limitconfig/CrmCustomerLimitConfigUpdateReqVO.java
  23. 0 31
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/poolconfig/CrmCustomerPoolConfigBaseVO.java
  24. 18 5
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/poolconfig/CrmCustomerPoolConfigRespVO.java
  25. 44 17
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/poolconfig/CrmCustomerPoolConfigSaveReqVO.java
  26. 0 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/CrmPermissionController.java
  27. 13 12
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerConvert.java
  28. 2 5
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerLimitConfigConvert.java
  29. 6 0
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/permission/CrmPermissionConvert.java
  30. 7 0
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java
  31. 21 10
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/permission/core/aop/CrmPermissionAspect.java
  32. 4 5
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerLimitConfigService.java
  33. 29 13
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerLimitConfigServiceImpl.java
  34. 16 4
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerPoolConfigServiceImpl.java
  35. 9 13
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java
  36. 153 112
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
  37. 9 0
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java
  38. 5 0
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java
  39. 5 7
      yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImplTest.java
  40. 5 7
      yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/customerlimitconfig/CrmCustomerLimitConfigServiceImplTest.java
  41. 2 2
      yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/statistics/vo/MpStatisticsGetReqVO.java
  42. 14 2
      yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/statistics/MpStatisticsConvert.java
  43. 9 3
      yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/message/MpMessageServiceImpl.java
  44. 6 0
      yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/PostApi.java
  45. 7 0
      yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/dto/OperateLogV2RespDTO.java
  46. 4 2
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/logger/OperateLogConvert.java
  47. 43 0
      yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/operatelog/core/DeptParseFunction.java

+ 5 - 0
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java

@@ -6,6 +6,7 @@ import java.time.Duration;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
+import java.time.temporal.ChronoUnit;
 import java.time.temporal.TemporalAdjusters;
 
 /**
@@ -121,4 +122,8 @@ public class LocalDateTimeUtils {
         return date.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX);
     }
 
+    public static Long between(LocalDateTime dateTime) {
+        return LocalDateTimeUtil.between(dateTime, LocalDateTime.now(), ChronoUnit.DAYS);
+    }
+
 }

+ 2 - 2
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogV2Configuration.java

@@ -1,6 +1,6 @@
 package cn.iocoder.yudao.framework.operatelog.config;
 
-import cn.iocoder.yudao.framework.operatelog.core.service.ILogRecordServiceImpl;
+import cn.iocoder.yudao.framework.operatelog.core.service.LogRecordServiceImpl;
 import com.mzt.logapi.service.ILogRecordService;
 import com.mzt.logapi.starter.annotation.EnableLogRecord;
 import lombok.extern.slf4j.Slf4j;
@@ -21,7 +21,7 @@ public class YudaoOperateLogV2Configuration {
     @Bean
     @Primary
     public ILogRecordService iLogRecordServiceImpl() {
-        return new ILogRecordServiceImpl();
+        return new LogRecordServiceImpl();
     }
 
 }

+ 10 - 6
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/core/service/ILogRecordServiceImpl.java → yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/core/service/LogRecordServiceImpl.java

@@ -2,7 +2,8 @@ package cn.iocoder.yudao.framework.operatelog.core.service;
 
 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.framework.security.core.LoginUser;
+import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
 import cn.iocoder.yudao.module.system.api.logger.OperateLogApi;
 import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2CreateReqDTO;
 import com.mzt.logapi.beans.LogRecord;
@@ -13,7 +14,6 @@ import lombok.extern.slf4j.Slf4j;
 
 import java.util.List;
 
-// TODO @puhui999:LogRecordServiceImpl 改成这个名字哈
 /**
  * 操作日志 ILogRecordService 实现类
  *
@@ -22,7 +22,7 @@ import java.util.List;
  * @author HUIHUI
  */
 @Slf4j
-public class ILogRecordServiceImpl implements ILogRecordService {
+public class LogRecordServiceImpl implements ILogRecordService {
 
     @Resource
     private OperateLogApi operateLogApi;
@@ -46,9 +46,13 @@ public class ILogRecordServiceImpl implements ILogRecordService {
     }
 
     private static void fillUserFields(OperateLogV2CreateReqDTO reqDTO) {
-        // TODO @puhui999:使用 SecurityFrameworkUtils。因为要考虑,rpc、mq、job,它其实不是 web;
-        reqDTO.setUserId(WebFrameworkUtils.getLoginUserId());
-        reqDTO.setUserType(WebFrameworkUtils.getLoginUserType());
+        // 使用 SecurityFrameworkUtils。因为要考虑,rpc、mq、job,它其实不是 web;
+        LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
+        if (loginUser == null) {
+            return;
+        }
+        reqDTO.setUserId(loginUser.getId());
+        reqDTO.setUserType(loginUser.getUserType());
     }
 
     public static void fillModuleFields(OperateLogV2CreateReqDTO reqDTO, LogRecord logRecord) {

+ 1 - 1
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java

@@ -41,7 +41,7 @@ public interface ErrorCodeConstants {
     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_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, "操作失败,超出客户数拥有上限");
 

+ 58 - 18
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/LogRecordConstants.java

@@ -2,32 +2,72 @@ package cn.iocoder.yudao.module.crm.enums;
 
 /**
  * CRM 操作日志枚举
+ * 目的:统一管理,也减少 Service 里各种“复杂”字符串
  *
  * @author HUIHUI
  */
 public interface LogRecordConstants {
 
-    //======================= 客户模块类型 =======================
-    // TODO puhui999: 确保模块命名方式为 module + 子模块名称的方式。统一定义模块名称是为了方便查询各自记录的操作日志,列如说:查询客户【张三的操作日志】就可以 module + bizId
-    String CRM_LEADS = "CRM 线索";
-    String CRM_CUSTOMER = "CRM 客户";
-    String CRM_CONTACT = "CRM 联系人";
-    String CRM_BUSINESS = "CRM 商机";
-    String CRM_CONTRACT = "CRM 合同";
-    String CRM_PRODUCT = "CRM 产品";
-    String CRM_RECEIVABLE = "CRM 回款";
-    String CRM_RECEIVABLE_PLAN = "CRM 回款计划";
+    // ======================= CRM_LEADS 线索 =======================
 
-    //======================= 客户转移操作日志 =======================
+    String CRM_LEADS_TYPE = "CRM 线索";
 
-    String TRANSFER_CUSTOMER_LOG_SUCCESS = "把客户【{{#crmCustomer.name}}】的负责人从【{getAdminUserById{#crmCustomer.ownerUserId}}】变更为了【{getAdminUserById{#reqVO.newOwnerUserId}}】";
+    // ======================= CRM_CUSTOMER 客户 =======================
 
-    // TODO @puhui999:这里格式是不是可以这样;目的是:统一管理,也减少 Service 里各种“复杂”字符串
-    // ======================= Customer 客户 =======================
-    String CUSTOMER_TYPE = "CRM 客户";
-    String CUSTOMER_CREATE_SUB_TYPE = "创建客户";
-    String CUSTOMER_CREATE_SUCCESS = "更新了客户{_DIFF{#updateReqVO}}";
+    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 = "将客户【{{#crmCustomer.name}}】的负责人从【{getAdminUserById{#crmCustomer.ownerUserId}}】变更为了【{getAdminUserById{#reqVO.newOwnerUserId}}】";
+    String CRM_CUSTOMER_LOCK_SUB_TYPE = "{{#crmCustomer.lockStatus ? '解锁客户' : '锁定客户'}}";
+    String CRM_CUSTOMER_LOCK_SUCCESS = "{{#crmCustomer.lockStatus ? '将客户【' + #crmCustomer.name + '】解锁' : '将客户【' + #crmCustomer.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 CUSTOMER_UPDATE_SUB_TYPE = "更新客户";
+    // ======================= 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 联系人";
+
+    // ======================= CRM_BUSINESS 商机 =======================
+
+    String CRM_BUSINESS_TYPE = "CRM 商机";
+
+    // ======================= CRM_CONTRACT 合同 =======================
+
+    String CRM_CONTRACT_TYPE = "CRM 合同";
+
+    // ======================= CRM_PRODUCT 产品 =======================
+
+    String CRM_PRODUCT_TYPE = "CRM 产品";
+
+    // ======================= CRM_RECEIVABLE 回款 =======================
+
+    String CRM_RECEIVABLE_TYPE = "CRM 回款";
+
+    // ======================= CRM_RECEIVABLE_PLAN 回款计划 =======================
+
+    String CRM_RECEIVABLE_PLAN_TYPE = "CRM 回款计划";
 
 }

+ 8 - 0
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/customer/CrmCustomerLimitConfigTypeEnum.java

@@ -1,5 +1,7 @@
 package cn.iocoder.yudao.module.crm.enums.customer;
 
+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;
@@ -36,6 +38,12 @@ public enum CrmCustomerLimitConfigTypeEnum implements IntArrayValuable {
      */
     private final String name;
 
+    public static String getNameByType(Integer type) {
+        CrmCustomerLimitConfigTypeEnum typeEnum = CollUtil.findOne(CollUtil.newArrayList(CrmCustomerLimitConfigTypeEnum.values()),
+                item -> ObjUtil.equal(item.type, type));
+        return typeEnum == null ? null : typeEnum.getName();
+    }
+
     @Override
     public int[] array() {
         return ARRAYS;

+ 50 - 44
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java

@@ -3,12 +3,15 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer;
 import cn.hutool.core.collection.CollUtil;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
 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;
@@ -19,7 +22,6 @@ 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;
@@ -36,11 +38,10 @@ import java.util.stream.Stream;
 
 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.convertSet;
-import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
-import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_CUSTOMER;
+import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_CUSTOMER_TYPE;
 
 @Tag(name = "管理后台 - CRM 客户")
 @RestController
@@ -50,7 +51,8 @@ public class CrmCustomerController {
 
     @Resource
     private CrmCustomerService customerService;
-
+    @Resource
+    private CrmCustomerPoolConfigService customerPoolConfigService;
     @Resource
     private DeptApi deptApi;
     @Resource
@@ -58,28 +60,24 @@ public class CrmCustomerController {
     @Resource
     private OperateLogApi operateLogApi;
 
-    // TODO @puhui999:把 CrmCustomerCreateReqVO、CrmCustomerUpdateReqVO、CrmCustomerRespVO 按照新的规范,搞一下哈;
     @PostMapping("/create")
     @Operation(summary = "创建客户")
-    @OperateLog(enable = false) // TODO 关闭原有日志记录;@puhui999:注解都先删除。先记录,没关系。我们下个迭代,就都删除掉操作日志了;
     @PreAuthorize("@ss.hasPermission('crm:customer:create')")
-    public CommonResult<Long> createCustomer(@Valid @RequestBody CrmCustomerCreateReqVO createReqVO) {
+    public CommonResult<Long> createCustomer(@Valid @RequestBody CrmCustomerSaveReqVO createReqVO) {
         return success(customerService.createCustomer(createReqVO, getLoginUserId()));
     }
 
     @PutMapping("/update")
     @Operation(summary = "更新客户")
-    @OperateLog(enable = false) // TODO 关闭原有日志记录
     @PreAuthorize("@ss.hasPermission('crm:customer:update')")
-    public CommonResult<Boolean> updateCustomer(@Valid @RequestBody CrmCustomerUpdateReqVO updateReqVO) {
+    public CommonResult<Boolean> updateCustomer(@Valid @RequestBody CrmCustomerSaveReqVO updateReqVO) {
         customerService.updateCustomer(updateReqVO);
         return success(true);
     }
 
     @DeleteMapping("/delete")
     @Operation(summary = "删除客户")
-    @OperateLog(enable = false) // TODO 关闭原有日志记录
-    @Parameter(name = "id", description = "编号", required = true)
+    @Parameter(name = "id", description = "客户编号", required = true)
     @PreAuthorize("@ss.hasPermission('crm:customer:delete')")
     public CommonResult<Boolean> deleteCustomer(@RequestParam("id") Long id) {
         customerService.deleteCustomer(id);
@@ -103,7 +101,6 @@ public class CrmCustomerController {
         return success(CrmCustomerConvert.INSTANCE.convert(customer, userMap, deptMap));
     }
 
-    // TODO @puhui999:这个查询会查出多个;微信发你图了
     @GetMapping("/page")
     @Operation(summary = "获得客户分页")
     @PreAuthorize("@ss.hasPermission('crm:customer:query')")
@@ -115,11 +112,37 @@ public class CrmCustomerController {
         }
 
         // 2. 拼接数据
-        // TODO @puhui999:距离进入公海的时间
+        // 距离进入公海的时间
+        Map<Long, Long> poolDayMap = getPoolDayMap(pageResult);
         Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
                 convertSetByFlatMap(pageResult.getList(), user -> Stream.of(Long.parseLong(user.getCreator()), user.getOwnerUserId())));
         Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
-        return success(CrmCustomerConvert.INSTANCE.convertPage(pageResult, userMap, deptMap));
+        return success(CrmCustomerConvert.INSTANCE.convertPage(pageResult, userMap, deptMap, poolDayMap));
+    }
+
+    private Map<Long, Long> getPoolDayMap(PageResult<CrmCustomerDO> pageResult) {
+        Map<Long, Long> poolDayMap = null;
+        CrmCustomerPoolConfigDO customerPoolConfig = customerPoolConfigService.getCustomerPoolConfig();
+        if (customerPoolConfig != null && customerPoolConfig.getEnabled()) { // 有公海配置的情况
+            poolDayMap = convertMap(pageResult.getList(), CrmCustomerDO::getId, item -> {
+                long dealExpireDay = 0;
+                if (!item.getDealStatus()) { // 检查是否成交
+                    dealExpireDay = customerPoolConfig.getDealExpireDays() - LocalDateTimeUtils.between(item.getCreateTime());
+                }
+                long contactExpireDay = customerPoolConfig.getContactExpireDays() - LocalDateTimeUtils.between(item.getContactLastTime());
+                return dealExpireDay == 0 ? contactExpireDay : Math.min(dealExpireDay, contactExpireDay);
+            });
+        }
+        return poolDayMap;
+    }
+
+    @GetMapping(value = "/list-all-simple")
+    @Operation(summary = "获取客户精简信息列表", description = "只包含有读权限的客户,主要用于前端的下拉选项")
+    public CommonResult<List<CrmCustomerSimpleRespVO>> getSimpleDeptList() {
+        CrmCustomerPageReqVO reqVO = new CrmCustomerPageReqVO();
+        reqVO.setPageSize(PAGE_SIZE_NONE); // 不分页
+        List<CrmCustomerDO> list = customerService.getCustomerPage(reqVO, getLoginUserId()).getList();
+        return success(BeanUtils.toBean(list, CrmCustomerSimpleRespVO.class));
     }
 
     @GetMapping("/export-excel")
@@ -131,32 +154,32 @@ public class CrmCustomerController {
         pageVO.setPageSize(PAGE_SIZE_NONE); // 不分页
         List<CrmCustomerDO> list = customerService.getCustomerPage(pageVO, getLoginUserId()).getList();
         // 导出 Excel
-        List<CrmCustomerExcelVO> datas = CrmCustomerConvert.INSTANCE.convertList02(list);
-        ExcelUtils.write(response, "客户.xls", "数据", CrmCustomerExcelVO.class, datas);
+        List<CrmCustomerRespVO> datas = CrmCustomerConvert.INSTANCE.convertList02(list);
+        ExcelUtils.write(response, "客户.xls", "数据", CrmCustomerRespVO.class, datas);
     }
 
     @PutMapping("/transfer")
     @Operation(summary = "转移客户")
-    @OperateLog(enable = false) // TODO 关闭原有日志记录
     @PreAuthorize("@ss.hasPermission('crm:customer:update')")
     public CommonResult<Boolean> transfer(@Valid @RequestBody CrmCustomerTransferReqVO reqVO) {
         customerService.transferCustomer(reqVO, getLoginUserId());
         return success(true);
     }
 
-    // TODO @puhui999:是不是接口只要传递 bizId,由 Controller 自己组装出 OperateLogV2PageReqDTO
     @GetMapping("/operate-log-page")
     @Operation(summary = "获得客户操作日志")
+    @Parameter(name = "id", description = "客户编号", required = true)
     @PreAuthorize("@ss.hasPermission('crm:customer:query')")
-    public CommonResult<PageResult<OperateLogV2RespDTO>> getCustomerOperateLog(CrmCustomerOperateLogPageReqVO reqVO) {
-        reqVO.setPageSize(PAGE_SIZE_NONE); // 不分页
-        reqVO.setBizType(CRM_CUSTOMER);
-        return success(operateLogApi.getOperateLogPage(BeanUtils.toBean(reqVO, OperateLogV2PageReqDTO.class)));
+    public CommonResult<PageResult<OperateLogV2RespDTO>> getCustomerOperateLog(@RequestParam("id") Long id) {
+        OperateLogV2PageReqDTO reqDTO = new OperateLogV2PageReqDTO();
+        reqDTO.setPageSize(PAGE_SIZE_NONE); // 不分页
+        reqDTO.setBizType(CRM_CUSTOMER_TYPE);
+        reqDTO.setBizId(id);
+        return success(operateLogApi.getOperateLogPage(reqDTO));
     }
 
     @PutMapping("/lock")
     @Operation(summary = "锁定/解锁客户")
-    @OperateLog(enable = false) // TODO 关闭原有日志记录
     @PreAuthorize("@ss.hasPermission('crm:customer:update')")
     public CommonResult<Boolean> lockCustomer(@Valid @RequestBody CrmCustomerLockReqVO lockReqVO) {
         customerService.lockCustomer(lockReqVO, getLoginUserId());
@@ -167,7 +190,6 @@ public class CrmCustomerController {
 
     @PutMapping("/put-pool")
     @Operation(summary = "数据放入公海")
-    @OperateLog(enable = false) // TODO 关闭原有日志记录
     @Parameter(name = "id", description = "客户编号", required = true, example = "1024")
     @PreAuthorize("@ss.hasPermission('crm:customer:update')")
     public CommonResult<Boolean> putCustomerPool(@RequestParam("id") Long id) {
@@ -180,32 +202,16 @@ public class CrmCustomerController {
     @Parameter(name = "ids", description = "编号数组", required = true, example = "1,2,3")
     @PreAuthorize("@ss.hasPermission('crm:customer:receive')")
     public CommonResult<Boolean> receiveCustomer(@RequestParam(value = "ids") List<Long> ids) {
-        customerService.receiveCustomer(ids, getLoginUserId());
+        customerService.receiveCustomer(ids, getLoginUserId(), Boolean.TRUE);
         return success(true);
     }
 
-    // TODO @puhui999:需要搞个 VO 类
     @PutMapping("/distribute")
     @Operation(summary = "分配公海给对应负责人")
-    @Parameters({
-            @Parameter(name = "ids", description = "客户编号数组", required = true, example = "1,2,3"),
-            @Parameter(name = "ownerUserId", description = "分配的负责人编号", required = true, example = "12345")
-    })
     @PreAuthorize("@ss.hasPermission('crm:customer:distribute')")
-    public CommonResult<Boolean> distributeCustomer(@RequestParam(value = "ids") List<Long> ids,
-                                                    @RequestParam(value = "ownerUserId") Long ownerUserId) {
-        customerService.receiveCustomer(ids, ownerUserId);
+    public CommonResult<Boolean> distributeCustomer(@Valid @RequestBody CrmCustomerDistributeReqVO distributeReqVO) {
+        customerService.receiveCustomer(distributeReqVO.getIds(), distributeReqVO.getOwnerUserId(), Boolean.FALSE);
         return success(true);
     }
 
-    // TODO 芋艿:这个接口要调整下
-    @GetMapping("/query-all-list")
-    @Operation(summary = "查询客户列表")
-    @PreAuthorize("@ss.hasPermission('crm:customer:all')")
-    public CommonResult<List<CrmCustomerQueryAllRespVO>> queryAll() {
-        List<CrmCustomerDO> crmCustomerDOList = customerService.getCustomerList();
-        List<CrmCustomerQueryAllRespVO> data = CrmCustomerConvert.INSTANCE.convertQueryAll(crmCustomerDOList);
-        return success(data);
-    }
-
 }

+ 5 - 7
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerLimitConfigController.java

@@ -3,10 +3,9 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer;
 import cn.hutool.core.collection.CollUtil;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigPageReqVO;
 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigRespVO;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigUpdateReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerLimitConfigConvert;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
 import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerLimitConfigService;
@@ -17,12 +16,12 @@ 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.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
-import jakarta.annotation.Resource;
-import jakarta.validation.Valid;
 import java.util.Collection;
 import java.util.Map;
 
@@ -43,18 +42,17 @@ public class CrmCustomerLimitConfigController {
     @Resource
     private AdminUserApi adminUserApi;
 
-    // TODO @puhui999:可以把 vo 改下哈
     @PostMapping("/create")
     @Operation(summary = "创建客户限制配置")
     @PreAuthorize("@ss.hasPermission('crm:customer-limit-config:create')")
-    public CommonResult<Long> createCustomerLimitConfig(@Valid @RequestBody CrmCustomerLimitConfigCreateReqVO createReqVO) {
+    public CommonResult<Long> createCustomerLimitConfig(@Valid @RequestBody CrmCustomerLimitConfigSaveReqVO createReqVO) {
         return success(customerLimitConfigService.createCustomerLimitConfig(createReqVO));
     }
 
     @PutMapping("/update")
     @Operation(summary = "更新客户限制配置")
     @PreAuthorize("@ss.hasPermission('crm:customer-limit-config:update')")
-    public CommonResult<Boolean> updateCustomerLimitConfig(@Valid @RequestBody CrmCustomerLimitConfigUpdateReqVO updateReqVO) {
+    public CommonResult<Boolean> updateCustomerLimitConfig(@Valid @RequestBody CrmCustomerLimitConfigSaveReqVO updateReqVO) {
         customerLimitConfigService.updateCustomerLimitConfig(updateReqVO);
         return success(true);
     }

+ 2 - 4
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerPoolConfigController.java

@@ -8,13 +8,12 @@ import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfig
 import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerPoolConfigService;
 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.*;
 
-import jakarta.annotation.Resource;
-import jakarta.validation.Valid;
-
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
 @Tag(name = "管理后台 - CRM 客户公海配置")
@@ -26,7 +25,6 @@ public class CrmCustomerPoolConfigController {
     @Resource
     private CrmCustomerPoolConfigService customerPoolConfigService;
 
-    // TODO @puhui999:可以把 vo 改下哈
     @GetMapping("/get")
     @Operation(summary = "获取客户公海规则设置")
     @PreAuthorize("@ss.hasPermission('crm:customer-pool-config:query')")

+ 0 - 20
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerCreateReqVO.java

@@ -1,20 +0,0 @@
-package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
-
-import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.ToString;
-
-import jakarta.validation.constraints.NotNull;
-
-@Schema(description = "管理后台 - CRM 客户创建 Request VO")
-@Data
-@EqualsAndHashCode(callSuper = true)
-@ToString(callSuper = true)
-public class CrmCustomerCreateReqVO extends CrmCustomerBaseVO {
-
-    @Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
-    @NotNull(message = "负责人不能为空")
-    private Long ownerUserId;
-
-}

+ 21 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerDistributeReqVO.java

@@ -0,0 +1,21 @@
+package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
+
+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 CrmCustomerDistributeReqVO {
+
+    @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1024]")
+    @NotNull(message = "客户编号不能为空")
+    private List<Long> ids;
+
+    @Schema(description = "负责人", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    @NotNull(message = "负责人不能为空")
+    private Long ownerUserId;
+
+}

+ 0 - 93
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerExcelVO.java

@@ -1,93 +0,0 @@
-package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
-
-import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
-import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
-import cn.iocoder.yudao.module.infra.enums.DictTypeConstants;
-import com.alibaba.excel.annotation.ExcelProperty;
-import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.Data;
-
-import java.time.LocalDateTime;
-
-// TODO 芋艿:导出最后做,等基本确认的差不多之后;
-/**
- * CRM 客户 Excel VO
- *
- * @author Wanwan
- */
-@Data
-public class CrmCustomerExcelVO {
-
-    @ExcelProperty("编号")
-    private Long id;
-
-    @ExcelProperty("客户名称")
-    private String name;
-
-    @ExcelProperty(value = "跟进状态", converter = DictConvert.class)
-    @DictFormat(DictTypeConstants.BOOLEAN_STRING)
-    private Boolean followUpStatus;
-
-    @ExcelProperty(value = "锁定状态", converter = DictConvert.class)
-    @DictFormat(DictTypeConstants.BOOLEAN_STRING)
-    private Boolean lockStatus;
-
-    @ExcelProperty(value = "成交状态", converter = DictConvert.class)
-    @DictFormat(DictTypeConstants.BOOLEAN_STRING)
-    private Boolean dealStatus;
-
-    @ExcelProperty(value = "所属行业", converter = DictConvert.class)
-    @DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_INDUSTRY)
-    private Integer industryId;
-
-    @ExcelProperty(value = "客户等级", converter = DictConvert.class)
-    @DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_LEVEL)
-    private Integer level;
-
-    @ExcelProperty(value = "客户来源", converter = DictConvert.class)
-    @DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_SOURCE)
-    private Integer source;
-
-    @ExcelProperty("手机")
-    private String mobile;
-
-    @ExcelProperty("电话")
-    private String telephone;
-
-    @ExcelProperty("网址")
-    private String website;
-
-    @ExcelProperty("QQ")
-    private String qq;
-
-    @ExcelProperty("wechat")
-    private String wechat;
-
-    @ExcelProperty("email")
-    private String email;
-
-    @ExcelProperty("客户描述")
-    private String description;
-
-    @ExcelProperty("备注")
-    private String remark;
-
-    @ExcelProperty("负责人的用户编号")
-    private Long ownerUserId;
-
-    @ExcelProperty("地区编号")
-    private Integer areaId;
-
-    @ExcelProperty("详细地址")
-    private String detailAddress;
-
-    @ExcelProperty("最后跟进时间")
-    private LocalDateTime contactLastTime;
-
-    @ExcelProperty("下次联系时间")
-    private LocalDateTime contactNextTime;
-
-    @ExcelProperty("创建时间")
-    private LocalDateTime createTime;
-
-}

+ 0 - 20
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerOperateLogPageReqVO.java

@@ -1,20 +0,0 @@
-package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
-
-import cn.iocoder.yudao.framework.common.pojo.PageParam;
-import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.Data;
-
-@Schema(description = "管理后台 - crm 客户操作日志分页 Request VO")
-@Data
-public class CrmCustomerOperateLogPageReqVO extends PageParam {
-
-    @Schema(description = "模块数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
-    private Long bizId;
-
-    @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
-    private Long userId;
-
-    @Schema(description = "模块类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
-    private String bizType;
-
-}

+ 0 - 17
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerQueryAllRespVO.java

@@ -1,17 +0,0 @@
-package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
-
-import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.Data;
-
-// TODO 芋艿:这块要统一下;
-@Schema(description = "管理后台 - CRM 全部客户 Response VO")
-@Data
-public class CrmCustomerQueryAllRespVO{
-
-    @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
-    private Long id;
-
-    @Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
-    private String name;
-
-}

+ 92 - 10
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerRespVO.java

@@ -1,9 +1,12 @@
 package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
 
+import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
+import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
+import cn.iocoder.yudao.module.infra.enums.DictTypeConstants;
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
+import com.alibaba.excel.annotation.ExcelProperty;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.ToString;
 import org.springframework.format.annotation.DateTimeFormat;
 
 import java.time.LocalDateTime;
@@ -12,45 +15,124 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
 
 @Schema(description = "管理后台 - CRM 客户 Response VO")
 @Data
-@EqualsAndHashCode(callSuper = true)
-@ToString(callSuper = true)
-public class CrmCustomerRespVO extends CrmCustomerBaseVO {
+@ExcelIgnoreUnannotated
+public class CrmCustomerRespVO {
 
     @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
+    @ExcelProperty("编号")
     private Long id;
 
-    @Schema(description = "跟进状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
+    @Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
+    @ExcelProperty("客户名称")
+    private String name;
+
+    @Schema(description = "跟进状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
+    @ExcelProperty(value = "跟进状态", converter = DictConvert.class)
+    @DictFormat(DictTypeConstants.BOOLEAN_STRING)
     private Boolean followUpStatus;
 
-    @Schema(description = "锁定状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
+    @Schema(description = "锁定状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
+    @ExcelProperty(value = "锁定状态", converter = DictConvert.class)
+    @DictFormat(DictTypeConstants.BOOLEAN_STRING)
     private Boolean lockStatus;
 
-    @Schema(description = "成交状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
+    @Schema(description = "成交状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
+    @ExcelProperty(value = "成交状态", converter = DictConvert.class)
+    @DictFormat(DictTypeConstants.BOOLEAN_STRING)
     private Boolean dealStatus;
 
+    @Schema(description = "所属行业", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
+    @ExcelProperty(value = "所属行业", converter = DictConvert.class)
+    @DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_INDUSTRY)
+    private Integer industryId;
+
+    @Schema(description = "客户等级", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
+    @ExcelProperty(value = "客户等级", converter = DictConvert.class)
+    @DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_LEVEL)
+    private Integer level;
+
+    @Schema(description = "客户来源", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
+    @ExcelProperty(value = "客户来源", converter = DictConvert.class)
+    @DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_SOURCE)
+    private Integer source;
+
+    @Schema(description = "负责人的用户编号", example = "25682")
+    @ExcelProperty("手机")
+    private String mobile;
+
+    @Schema(description = "负责人的用户编号", example = "25682")
+    @ExcelProperty("电话")
+    private String telephone;
+
+    @Schema(description = "负责人的用户编号", example = "25682")
+    @ExcelProperty("网址")
+    private String website;
+
+    @Schema(description = "负责人的用户编号", example = "25682")
+    @ExcelProperty("QQ")
+    private String qq;
+
+    @Schema(description = "负责人的用户编号", example = "25682")
+    @ExcelProperty("wechat")
+    private String wechat;
+
     @Schema(description = "负责人的用户编号", example = "25682")
+    @ExcelProperty("email")
+    private String email;
+
+    @Schema(description = "负责人的用户编号", example = "25682")
+    @ExcelProperty("客户描述")
+    private String description;
+
+    @Schema(description = "负责人的用户编号", example = "25682")
+    @ExcelProperty("备注")
+    private String remark;
+
+    @Schema(description = "负责人的用户编号", example = "25682")
+    @ExcelProperty("负责人的用户编号")
     private Long ownerUserId;
     @Schema(description = "负责人名字", example = "25682")
+    @ExcelProperty("负责人名字")
     private String ownerUserName;
     @Schema(description = "负责人部门")
+    @ExcelProperty("负责人部门")
     private String ownerUserDeptName;
 
+    @Schema(description = "地区编号", example = "1024")
+    @ExcelProperty("地区编号")
+    private Integer areaId;
     @Schema(description = "地区名称", example = "北京市")
+    @ExcelProperty("地区名称")
     private String areaName;
+    @Schema(description = "详细地址", example = "北京市成华大道")
+    @ExcelProperty("详细地址")
+    private String detailAddress;
 
     @Schema(description = "最后跟进时间")
+    @ExcelProperty("最后跟进时间")
     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
     private LocalDateTime contactLastTime;
 
+    @Schema(description = "下次联系时间")
+    @ExcelProperty("下次联系时间")
+    private LocalDateTime contactNextTime;
+
     @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("创建时间")
     private LocalDateTime createTime;
 
     @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("更新时间")
     private LocalDateTime updateTime;
 
-    @Schema(description = "创建人")
+    @Schema(description = "创建人", example = "1024")
+    @ExcelProperty("创建人")
     private String creator;
-    @Schema(description = "创建人名字")
+    @Schema(description = "创建人名字", example = "芋道源码")
+    @ExcelProperty("创建人名字")
     private String creatorName;
 
+    @Schema(description = "距离加入公海时间", example = "1")
+    private Long poolDay;
+
 }

+ 8 - 5
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerBaseVO.java → yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerSaveReqVO.java

@@ -21,12 +21,12 @@ import java.time.LocalDateTime;
 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
 import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_INDUSTRY;
 
-/**
- * 客户 Base VO,提供给添加、修改、详细的子 VO 使用
- * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
- */
+@Schema(description = "管理后台 - CRM 客户新增/修改 Request VO")
 @Data
-public class CrmCustomerBaseVO {
+public class CrmCustomerSaveReqVO {
+
+    @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
+    private Long id;
 
     @Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
     @DiffLogField(name = "客户名称")
@@ -99,4 +99,7 @@ public class CrmCustomerBaseVO {
     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
     private LocalDateTime contactNextTime;
 
+    @Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
+    private Long ownerUserId;
+
 }

+ 20 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerSimpleRespVO.java

@@ -0,0 +1,20 @@
+package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Schema(description = "管理后台 - 客户精简信息 Response VO")
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class CrmCustomerSimpleRespVO {
+
+    @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+    private Long id;
+
+    @Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
+    private String name;
+
+}

+ 0 - 20
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerUpdateReqVO.java

@@ -1,20 +0,0 @@
-package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
-
-import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.ToString;
-
-import jakarta.validation.constraints.NotNull;
-
-@Schema(description = "管理后台 - CRM 客户更新 Request VO")
-@Data
-@EqualsAndHashCode(callSuper = true)
-@ToString(callSuper = true)
-public class CrmCustomerUpdateReqVO extends CrmCustomerBaseVO {
-
-    @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
-    @NotNull(message = "编号不能为空")
-    private Long id;
-
-}

+ 0 - 14
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/limitconfig/CrmCustomerLimitConfigCreateReqVO.java

@@ -1,14 +0,0 @@
-package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig;
-
-import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.ToString;
-
-@Schema(description = "管理后台 - 客户限制配置创建 Request VO")
-@Data
-@EqualsAndHashCode(callSuper = true)
-@ToString(callSuper = true)
-public class CrmCustomerLimitConfigCreateReqVO extends CrmCustomerLimitConfigBaseVO {
-
-}

+ 19 - 5
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/limitconfig/CrmCustomerLimitConfigRespVO.java

@@ -3,22 +3,36 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig;
 import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
 import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotNull;
 import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.ToString;
 
 import java.time.LocalDateTime;
 import java.util.List;
 
 @Schema(description = "管理后台 - 客户限制配置 Response VO")
 @Data
-@EqualsAndHashCode(callSuper = true)
-@ToString(callSuper = true)
-public class CrmCustomerLimitConfigRespVO extends CrmCustomerLimitConfigBaseVO {
+public class CrmCustomerLimitConfigRespVO {
 
     @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27930")
     private Long id;
 
+    @Schema(description = "规则类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
+    @NotNull(message = "规则类型不能为空")
+    private Integer type;
+
+    @Schema(description = "规则适用人群")
+    private List<Long> userIds;
+
+    @Schema(description = "规则适用部门")
+    private List<Long> deptIds;
+
+    @Schema(description = "数量上限", requiredMode = Schema.RequiredMode.REQUIRED, example = "28384")
+    @NotNull(message = "数量上限不能为空")
+    private Integer maxCount;
+
+    @Schema(description = "成交客户是否占有拥有客户数(当 type = 1 时)")
+    private Boolean dealCountEnabled;
+
     @Schema(description = "规则适用人群名称")
     private List<AdminUserRespDTO> users;
 

+ 12 - 6
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/limitconfig/CrmCustomerLimitConfigBaseVO.java → yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/limitconfig/CrmCustomerLimitConfigSaveReqVO.java

@@ -1,33 +1,39 @@
 package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig;
 
+import com.mzt.logapi.starter.annotation.DiffLogField;
 import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotNull;
 import lombok.Data;
 
-import jakarta.validation.constraints.NotNull;
 import java.util.List;
 
-/**
- * 客户限制配置 Base VO,提供给添加、修改、详细的子 VO 使用
- * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
- */
+@Schema(description = "管理后台 - 客户限制配置创建/更新 Request VO")
 @Data
-public class CrmCustomerLimitConfigBaseVO {
+public class CrmCustomerLimitConfigSaveReqVO {
+
+    @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27930")
+    private Long id;
 
     @Schema(description = "规则类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
+    @DiffLogField(name = "规则类型")
     @NotNull(message = "规则类型不能为空")
     private Integer type;
 
     @Schema(description = "规则适用人群")
+    @DiffLogField(name = "规则适用人群", function = "getAdminUserById")
     private List<Long> userIds;
 
     @Schema(description = "规则适用部门")
+    @DiffLogField(name = "规则适用部门", function = "getDeptById")
     private List<Long> deptIds;
 
     @Schema(description = "数量上限", requiredMode = Schema.RequiredMode.REQUIRED, example = "28384")
+    @DiffLogField(name = "数量上限")
     @NotNull(message = "数量上限不能为空")
     private Integer maxCount;
 
     @Schema(description = "成交客户是否占有拥有客户数(当 type = 1 时)")
+    @DiffLogField(name = "成交客户是否占有拥有客户数")
     private Boolean dealCountEnabled;
 
 }

+ 0 - 20
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/limitconfig/CrmCustomerLimitConfigUpdateReqVO.java

@@ -1,20 +0,0 @@
-package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig;
-
-import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.ToString;
-
-import jakarta.validation.constraints.NotNull;
-
-@Schema(description = "管理后台 - 客户限制配置更新 Request VO")
-@Data
-@EqualsAndHashCode(callSuper = true)
-@ToString(callSuper = true)
-public class CrmCustomerLimitConfigUpdateReqVO extends CrmCustomerLimitConfigBaseVO {
-
-    @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27930")
-    @NotNull(message = "编号不能为空")
-    private Long id;
-
-}

+ 0 - 31
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/poolconfig/CrmCustomerPoolConfigBaseVO.java

@@ -1,31 +0,0 @@
-package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig;
-
-import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.Data;
-
-import jakarta.validation.constraints.NotNull;
-
-/**
- * 客户公海配置 Base VO,提供给添加、修改、详细的子 VO 使用
- * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
- */
-@Data
-public class CrmCustomerPoolConfigBaseVO {
-
-    @Schema(description = "是否启用客户公海", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
-    @NotNull(message = "是否启用客户公海不能为空")
-    private Boolean enabled;
-
-    @Schema(description = "未跟进放入公海天数", example = "2")
-    private Integer contactExpireDays;
-
-    @Schema(description = "未成交放入公海天数", example = "2")
-    private Integer dealExpireDays;
-
-    @Schema(description = "是否开启提前提醒", example = "true")
-    private Boolean notifyEnabled;
-
-    @Schema(description = "提前提醒天数", example = "2")
-    private Integer notifyDays;
-
-}

+ 18 - 5
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/poolconfig/CrmCustomerPoolConfigRespVO.java

@@ -1,14 +1,27 @@
 package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig;
 
 import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotNull;
 import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.ToString;
 
 @Schema(description = "管理后台 - CRM 客户公海规则 Response VO")
 @Data
-@EqualsAndHashCode(callSuper = true)
-@ToString(callSuper = true)
-public class CrmCustomerPoolConfigRespVO extends CrmCustomerPoolConfigBaseVO {
+public class CrmCustomerPoolConfigRespVO {
+
+    @Schema(description = "是否启用客户公海", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
+    @NotNull(message = "是否启用客户公海不能为空")
+    private Boolean enabled;
+
+    @Schema(description = "未跟进放入公海天数", example = "2")
+    private Integer contactExpireDays;
+
+    @Schema(description = "未成交放入公海天数", example = "2")
+    private Integer dealExpireDays;
+
+    @Schema(description = "是否开启提前提醒", example = "true")
+    private Boolean notifyEnabled;
+
+    @Schema(description = "提前提醒天数", example = "2")
+    private Integer notifyDays;
 
 }

+ 44 - 17
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/poolconfig/CrmCustomerPoolConfigSaveReqVO.java

@@ -1,34 +1,61 @@
 package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig;
 
 import cn.hutool.core.util.BooleanUtil;
-import cn.hutool.core.util.ObjectUtil;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.mzt.logapi.starter.annotation.DiffLogField;
 import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.AssertTrue;
+import jakarta.validation.constraints.NotNull;
 import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.ToString;
 
-import jakarta.validation.constraints.AssertTrue;
 import java.util.Objects;
 
-@Schema(description = "管理后台 - CRM 客户公海配置的保存 Request VO")
+@Schema(description = "管理后台 - CRM 客户公海配置的创建/更新 Request VO")
 @Data
-@EqualsAndHashCode(callSuper = true)
-@ToString(callSuper = true)
-public class CrmCustomerPoolConfigSaveReqVO extends CrmCustomerPoolConfigBaseVO {
-
-    // TODO @puhui999:AssertTrue 必须 is 开头哈;注意需要 json 忽略下,避免被序列化;
-    @AssertTrue(message = "客户公海规则设置不正确")
-    // TODO @puhui999:这个方法,是不是拆成 2 个,一个校验 contactExpireDays、一个校验 dealExpireDays;
-    public boolean poolEnableValid() {
+public class CrmCustomerPoolConfigSaveReqVO {
+
+    @Schema(description = "是否启用客户公海", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
+    @DiffLogField(name = "是否启用客户公海")
+    @NotNull(message = "是否启用客户公海不能为空")
+    private Boolean enabled;
+
+    @Schema(description = "未跟进放入公海天数", example = "2")
+    @DiffLogField(name = "未跟进放入公海天数")
+    private Integer contactExpireDays;
+
+    @Schema(description = "未成交放入公海天数", example = "2")
+    @DiffLogField(name = "未成交放入公海天数")
+    private Integer dealExpireDays;
+
+    @Schema(description = "是否开启提前提醒", example = "true")
+    @DiffLogField(name = "是否开启提前提醒")
+    private Boolean notifyEnabled;
+
+    @Schema(description = "提前提醒天数", example = "2")
+    @DiffLogField(name = "提前提醒天数")
+    private Integer notifyDays;
+
+    @AssertTrue(message = "未成交放入公海天数不能为空")
+    @JsonIgnore
+    public boolean isDealExpireDaysValid() {
+        if (!BooleanUtil.isTrue(getEnabled())) {
+            return true;
+        }
+        return Objects.nonNull(getDealExpireDays());
+    }
+
+    @AssertTrue(message = "未跟进放入公海天数不能为空")
+    @JsonIgnore
+    public boolean isContactExpireDaysValid() {
         if (!BooleanUtil.isTrue(getEnabled())) {
             return true;
         }
-        return ObjectUtil.isAllNotEmpty(getContactExpireDays(), getDealExpireDays());
+        return Objects.nonNull(getContactExpireDays());
     }
 
-    @AssertTrue(message = "客户公海规则设置不正确")
-    // TODO @puhui999:这个方法,是不是改成 isNotifyDaysValid() 更好点?本质校验的是 notifyDays 是否为空
-    public boolean notifyEnableValid() {
+    @AssertTrue(message = "提前提醒天数不能为空")
+    @JsonIgnore
+    public boolean isNotifyDaysValid() {
         if (!BooleanUtil.isTrue(getNotifyEnabled())) {
             return true;
         }

+ 0 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/permission/CrmPermissionController.java

@@ -103,7 +103,6 @@ public class CrmPermissionController {
         // 拼接数据
         List<AdminUserRespDTO> userList = adminUserApi.getUserList(convertSet(permission, CrmPermissionDO::getUserId));
         Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userList, AdminUserRespDTO::getDeptId));
-        // TODO @puhui999:可能 postIds 为空的时候,会导致报错,看看怎么 fix 下
         Set<Long> postIds = CollectionUtils.convertSetByFlatMap(userList, AdminUserRespDTO::getPostIds, Collection::stream);
         Map<Long, PostRespDTO> postMap = postApi.getPostMap(postIds);
         return success(CrmPermissionConvert.INSTANCE.convert(permission, userList, deptMap, postMap));

+ 13 - 12
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerConvert.java

@@ -2,7 +2,9 @@ package cn.iocoder.yudao.module.crm.convert.customer;
 
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerRespVO;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig.CrmCustomerPoolConfigRespVO;
 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig.CrmCustomerPoolConfigSaveReqVO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
@@ -29,18 +31,16 @@ public interface CrmCustomerConvert {
 
     CrmCustomerConvert INSTANCE = Mappers.getMapper(CrmCustomerConvert.class);
 
-    CrmCustomerDO convert(CrmCustomerCreateReqVO bean);
-
-    CrmCustomerDO convert(CrmCustomerUpdateReqVO bean);
+    CrmCustomerDO convert(CrmCustomerSaveReqVO bean);
 
     CrmCustomerRespVO convert(CrmCustomerDO bean);
 
     /**
      * 设置用户信息
      *
-     * @param customer  CRM 客户 Response VO
-     * @param userMap 用户信息 map
-     * @param deptMap 用户部门信息 map
+     * @param customer CRM 客户 Response VO
+     * @param userMap  用户信息 map
+     * @param deptMap  用户部门信息 map
      */
     static void setUserInfo(CrmCustomerRespVO customer, Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) {
         customer.setAreaName(AreaUtils.format(customer.getAreaId()));
@@ -51,7 +51,7 @@ public interface CrmCustomerConvert {
         findAndThen(userMap, Long.parseLong(customer.getCreator()), user -> customer.setCreatorName(user.getNickname()));
     }
 
-    List<CrmCustomerExcelVO> convertList02(List<CrmCustomerDO> list);
+    List<CrmCustomerRespVO> convertList02(List<CrmCustomerDO> list);
 
     @Mapping(target = "bizId", source = "reqVO.id")
     CrmPermissionTransferReqBO convert(CrmCustomerTransferReqVO reqVO, Long userId);
@@ -66,9 +66,12 @@ public interface CrmCustomerConvert {
     }
 
     default PageResult<CrmCustomerRespVO> convertPage(PageResult<CrmCustomerDO> pageResult, Map<Long, AdminUserRespDTO> userMap,
-                                                      Map<Long, DeptRespDTO> deptMap) {
+                                                      Map<Long, DeptRespDTO> deptMap, Map<Long, Long> poolDayMap) {
         PageResult<CrmCustomerRespVO> result = convertPage(pageResult);
-        result.getList().forEach(item -> setUserInfo(item, userMap, deptMap));
+        result.getList().forEach(item -> {
+            setUserInfo(item, userMap, deptMap);
+            findAndThen(poolDayMap, item.getId(), item::setPoolDay);
+        });
         return result;
     }
 
@@ -76,6 +79,4 @@ public interface CrmCustomerConvert {
 
     CrmCustomerPoolConfigDO convert(CrmCustomerPoolConfigSaveReqVO updateReqVO);
 
-    List<CrmCustomerQueryAllRespVO> convertQueryAll(List<CrmCustomerDO> crmCustomerDO);
-
 }

+ 2 - 5
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerLimitConfigConvert.java

@@ -2,9 +2,8 @@ package cn.iocoder.yudao.module.crm.convert.customer;
 
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigRespVO;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigUpdateReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
 import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
@@ -24,9 +23,7 @@ public interface CrmCustomerLimitConfigConvert {
 
     CrmCustomerLimitConfigConvert INSTANCE = Mappers.getMapper(CrmCustomerLimitConfigConvert.class);
 
-    CrmCustomerLimitConfigDO convert(CrmCustomerLimitConfigCreateReqVO bean);
-
-    CrmCustomerLimitConfigDO convert(CrmCustomerLimitConfigUpdateReqVO bean);
+    CrmCustomerLimitConfigDO convert(CrmCustomerLimitConfigSaveReqVO bean);
 
     CrmCustomerLimitConfigRespVO convert(CrmCustomerLimitConfigDO bean);
 

+ 6 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/permission/CrmPermissionConvert.java

@@ -1,5 +1,6 @@
 package cn.iocoder.yudao.module.crm.convert.permission;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
 import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
 import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionCreateReqVO;
@@ -15,6 +16,7 @@ import com.google.common.collect.Multimaps;
 import org.mapstruct.Mapper;
 import org.mapstruct.factory.Mappers;
 
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -50,6 +52,10 @@ public interface CrmPermissionConvert {
                     item.setDeptName(deptRespDTO.getName());
                 });
                 List<PostRespDTO> postRespList = MapUtils.getList(Multimaps.forMap(postMap), user.getPostIds());
+                if (CollUtil.isEmpty(postRespList)) {
+                    item.setPostNames(Collections.emptySet());
+                    return;
+                }
                 item.setPostNames(CollectionUtils.convertSet(postRespList, PostRespDTO::getName));
             });
             return item;

+ 7 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/permission/CrmPermissionMapper.java

@@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
 import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.Collection;
 import java.util.List;
 
 /**
@@ -28,6 +29,12 @@ public interface CrmPermissionMapper extends BaseMapperX<CrmPermissionDO> {
                 .eq(CrmPermissionDO::getBizId, bizId));
     }
 
+    default List<CrmPermissionDO> selectByBizTypeAndBizIds(Integer bizType, Collection<Long> bizIds) {
+        return selectList(new LambdaQueryWrapperX<CrmPermissionDO>()
+                .eq(CrmPermissionDO::getBizType, bizType)
+                .in(CrmPermissionDO::getBizId, bizIds));
+    }
+
     default List<CrmPermissionDO> selectListByBizTypeAndUserId(Integer bizType, Long userId) {
         return selectList(new LambdaQueryWrapperX<CrmPermissionDO>()
                 .eq(CrmPermissionDO::getBizType, bizType)

+ 21 - 10
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/permission/core/aop/CrmPermissionAspect.java

@@ -18,12 +18,10 @@ import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Before;
 import org.springframework.stereotype.Component;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
-import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.anyMatch;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
 import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CRM_PERMISSION_DENIED;
 
@@ -46,16 +44,29 @@ public class CrmPermissionAspect {
         Map<String, Object> expressionValues = parseExpressions(joinPoint, crmPermission);
         Integer bizType = StrUtil.isEmpty(crmPermission.bizTypeValue()) ?
                 crmPermission.bizType()[0].getType() : (Integer) expressionValues.get(crmPermission.bizTypeValue()); // 模块类型
-        Long bizId = (Long) expressionValues.get(crmPermission.bizId()); // 模块数据编号
+        // 处理兼容多个 bizId 的情况
+        Object object = expressionValues.get(crmPermission.bizId());// 模块数据编号
+        Set<Long> bizIds = new HashSet<>();
+        if (object instanceof Collection<?>) {
+            bizIds.addAll(convertSet((Collection<?>) object, item -> Long.parseLong(item.toString())));
+        } else {
+            bizIds.add(Long.parseLong(object.toString()));
+        }
         Integer permissionLevel = crmPermission.level().getLevel(); // 需要的权限级别
+        List<CrmPermissionDO> permissionList = crmPermissionService.getPermissionListByBiz(bizType, bizIds);
+        Map<Long, List<CrmPermissionDO>> multiMap = convertMultiMap(permissionList, CrmPermissionDO::getBizId);
+        bizIds.forEach(bizId -> {
+            validatePermission(bizType, multiMap.get(bizId), permissionLevel);
+        });
+    }
 
-        // 1.1 如果是超级管理员则直接通过
+    private void validatePermission(Integer bizType, List<CrmPermissionDO> bizPermissions, Integer permissionLevel) {
+        // 1. 如果是超级管理员则直接通过
         if (CrmPermissionUtils.isCrmAdmin()) {
             return;
         }
-        // 1.2 获取数据权限
-        List<CrmPermissionDO> bizPermissions = crmPermissionService.getPermissionListByBiz(bizType, bizId);
-        if (CollUtil.isEmpty(bizPermissions)) { // 没有数据权限的情况
+        // 1.1 没有数据权限的情况
+        if (CollUtil.isEmpty(bizPermissions)) {
             // 公海数据如果没有团队成员大家也因该有读权限才对
             if (CrmPermissionLevelEnum.isRead(permissionLevel)) {
                 return;
@@ -63,7 +74,7 @@ public class CrmPermissionAspect {
 
             // 没有数据权限的情况下超出了读权限直接报错,避免后面校验空指针
             throw exception(CRM_PERMISSION_DENIED, CrmBizTypeEnum.getNameByType(bizType));
-        } else { // 有数据权限但是没有负责人的情况
+        } else { // 1.2 有数据权限但是没有负责人的情况
             if (!anyMatch(bizPermissions, item -> CrmPermissionLevelEnum.isOwner(item.getLevel()))) {
                 if (CrmPermissionLevelEnum.isRead(permissionLevel)) {
                     return;

+ 4 - 5
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerLimitConfigService.java

@@ -1,9 +1,8 @@
 package cn.iocoder.yudao.module.crm.service.customer;
 
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigPageReqVO;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigUpdateReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
 import jakarta.validation.Valid;
 
@@ -22,14 +21,14 @@ public interface CrmCustomerLimitConfigService {
      * @param createReqVO 创建信息
      * @return 编号
      */
-    Long createCustomerLimitConfig(@Valid CrmCustomerLimitConfigCreateReqVO createReqVO);
+    Long createCustomerLimitConfig(@Valid CrmCustomerLimitConfigSaveReqVO createReqVO);
 
     /**
      * 更新客户限制配置
      *
      * @param updateReqVO 更新信息
      */
-    void updateCustomerLimitConfig(@Valid CrmCustomerLimitConfigUpdateReqVO updateReqVO);
+    void updateCustomerLimitConfig(@Valid CrmCustomerLimitConfigSaveReqVO updateReqVO);
 
     /**
      * 删除客户限制配置
@@ -57,7 +56,7 @@ public interface CrmCustomerLimitConfigService {
     /**
      * 查询用户对应的配置列表
      *
-     * @param type 类型
+     * @param type   类型
      * @param userId 用户类型
      */
     List<CrmCustomerLimitConfigDO> getCustomerLimitConfigListByUserId(Integer type, Long userId);

+ 29 - 13
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerLimitConfigServiceImpl.java

@@ -2,25 +2,29 @@ package cn.iocoder.yudao.module.crm.service.customer;
 
 import cn.hutool.core.lang.Assert;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigPageReqVO;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigUpdateReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerLimitConfigConvert;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
 import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerLimitConfigMapper;
+import cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum;
 import cn.iocoder.yudao.module.system.api.dept.DeptApi;
 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
+import com.mzt.logapi.context.LogRecordContext;
+import com.mzt.logapi.service.impl.DiffParseFunction;
+import com.mzt.logapi.starter.annotation.LogRecord;
+import jakarta.annotation.Resource;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
-import jakarta.annotation.Resource;
-
 import java.util.Collection;
 import java.util.List;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_LIMIT_CONFIG_NOT_EXISTS;
+import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
 
 /**
  * 客户限制配置 Service 实现类
@@ -40,34 +44,44 @@ public class CrmCustomerLimitConfigServiceImpl implements CrmCustomerLimitConfig
     private AdminUserApi adminUserApi;
 
     @Override
-    // TODO @puhui999:操作日志
-    public Long createCustomerLimitConfig(CrmCustomerLimitConfigCreateReqVO createReqVO) {
+    @LogRecord(type = CRM_CUSTOMER_LIMIT_CONFIG_TYPE, subType = CRM_CUSTOMER_LIMIT_CONFIG_CREATE_SUB_TYPE, bizNo = "{{#limitId}}", success = CRM_CUSTOMER_LIMIT_CONFIG_CREATE_SUCCESS)
+    public Long createCustomerLimitConfig(CrmCustomerLimitConfigSaveReqVO createReqVO) {
         validateUserAndDept(createReqVO.getUserIds(), createReqVO.getDeptIds());
         // 插入
         CrmCustomerLimitConfigDO customerLimitConfig = CrmCustomerLimitConfigConvert.INSTANCE.convert(createReqVO);
         customerLimitConfigMapper.insert(customerLimitConfig);
+
+        // 记录操作日志上下文
+        LogRecordContext.putVariable("limitType", CrmCustomerLimitConfigTypeEnum.getNameByType(customerLimitConfig.getType()));
+        LogRecordContext.putVariable("limitId", customerLimitConfig.getId());
         // 返回
         return customerLimitConfig.getId();
     }
 
     @Override
-    // TODO @puhui999:操作日志
-    public void updateCustomerLimitConfig(CrmCustomerLimitConfigUpdateReqVO updateReqVO) {
+    @LogRecord(type = CRM_CUSTOMER_LIMIT_CONFIG_TYPE, subType = CRM_CUSTOMER_LIMIT_CONFIG_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}", success = CRM_CUSTOMER_LIMIT_CONFIG_UPDATE_SUCCESS)
+    public void updateCustomerLimitConfig(CrmCustomerLimitConfigSaveReqVO updateReqVO) {
         // 校验存在
-        validateCustomerLimitConfigExists(updateReqVO.getId());
+        CrmCustomerLimitConfigDO oldLimitConfig = validateCustomerLimitConfigExists(updateReqVO.getId());
         validateUserAndDept(updateReqVO.getUserIds(), updateReqVO.getDeptIds());
         // 更新
         CrmCustomerLimitConfigDO updateObj = CrmCustomerLimitConfigConvert.INSTANCE.convert(updateReqVO);
         customerLimitConfigMapper.updateById(updateObj);
+
+        // 记录操作日志上下文
+        LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldLimitConfig, CrmCustomerLimitConfigSaveReqVO.class));
     }
 
     @Override
-    // TODO @puhui999:操作日志
+    @LogRecord(type = CRM_CUSTOMER_LIMIT_CONFIG_TYPE, subType = CRM_CUSTOMER_LIMIT_CONFIG_DELETE_SUB_TYPE, bizNo = "{{#id}}", success = CRM_CUSTOMER_LIMIT_CONFIG_DELETE_SUCCESS)
     public void deleteCustomerLimitConfig(Long id) {
         // 校验存在
-        validateCustomerLimitConfigExists(id);
+        CrmCustomerLimitConfigDO limitConfigDO = validateCustomerLimitConfigExists(id);
         // 删除
         customerLimitConfigMapper.deleteById(id);
+
+        // 记录操作日志上下文
+        LogRecordContext.putVariable("limitType", CrmCustomerLimitConfigTypeEnum.getNameByType(limitConfigDO.getType()));
     }
 
     @Override
@@ -80,10 +94,12 @@ public class CrmCustomerLimitConfigServiceImpl implements CrmCustomerLimitConfig
         return customerLimitConfigMapper.selectPage(pageReqVO);
     }
 
-    private void validateCustomerLimitConfigExists(Long id) {
-        if (customerLimitConfigMapper.selectById(id) == null) {
+    private CrmCustomerLimitConfigDO validateCustomerLimitConfigExists(Long id) {
+        CrmCustomerLimitConfigDO limitConfigDO = customerLimitConfigMapper.selectById(id);
+        if (limitConfigDO == null) {
             throw exception(CUSTOMER_LIMIT_CONFIG_NOT_EXISTS);
         }
+        return limitConfigDO;
     }
 
     /**

+ 16 - 4
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerPoolConfigServiceImpl.java

@@ -5,12 +5,16 @@ import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig.CrmCu
 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfigDO;
 import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerPoolConfigMapper;
+import com.mzt.logapi.context.LogRecordContext;
+import com.mzt.logapi.starter.annotation.LogRecord;
+import jakarta.annotation.Resource;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
-import jakarta.annotation.Resource;
 import java.util.Objects;
 
+import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
+
 /**
  * 客户公海配置 Service 实现类
  *
@@ -19,6 +23,7 @@ import java.util.Objects;
 @Service
 @Validated
 public class CrmCustomerPoolConfigServiceImpl implements CrmCustomerPoolConfigService {
+
     @Resource
     private CrmCustomerPoolConfigMapper customerPoolConfigMapper;
 
@@ -38,16 +43,23 @@ public class CrmCustomerPoolConfigServiceImpl implements CrmCustomerPoolConfigSe
      * @param saveReqVO 更新信息
      */
     @Override
-    // TODO @puhui999:操作日志
+    @LogRecord(type = CRM_CUSTOMER_POOL_CONFIG_TYPE, subType = CRM_CUSTOMER_POOL_CONFIG_SUB_TYPE, bizNo = "{{#poolConfigId}}", success = CRM_CUSTOMER_POOL_CONFIG_SUCCESS)
     public void saveCustomerPoolConfig(CrmCustomerPoolConfigSaveReqVO saveReqVO) {
         // 存在,则进行更新
         CrmCustomerPoolConfigDO dbConfig = getCustomerPoolConfig();
+        CrmCustomerPoolConfigDO poolConfig = CrmCustomerConvert.INSTANCE.convert(saveReqVO);
         if (Objects.nonNull(dbConfig)) {
-            customerPoolConfigMapper.updateById(CrmCustomerConvert.INSTANCE.convert(saveReqVO).setId(dbConfig.getId()));
+            customerPoolConfigMapper.updateById(poolConfig.setId(dbConfig.getId()));
+            // 记录操作日志上下文
+            LogRecordContext.putVariable("isPoolConfigUpdate", Boolean.TRUE);
+            LogRecordContext.putVariable("poolConfigId", poolConfig.getId());
             return;
         }
         // 不存在,则进行插入
-        customerPoolConfigMapper.insert(CrmCustomerConvert.INSTANCE.convert(saveReqVO));
+        customerPoolConfigMapper.insert(poolConfig);
+        // 记录操作日志上下文
+        LogRecordContext.putVariable("isPoolConfigUpdate", Boolean.FALSE);
+        LogRecordContext.putVariable("poolConfigId", poolConfig.getId());
     }
 
 }

+ 9 - 13
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java

@@ -1,7 +1,10 @@
 package cn.iocoder.yudao.module.crm.service.customer;
 
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLockReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
 import jakarta.validation.Valid;
 
@@ -22,14 +25,14 @@ public interface CrmCustomerService {
      * @param userId      用户编号
      * @return 编号
      */
-    Long createCustomer(@Valid CrmCustomerCreateReqVO createReqVO, Long userId);
+    Long createCustomer(@Valid CrmCustomerSaveReqVO createReqVO, Long userId);
 
     /**
      * 更新客户
      *
      * @param updateReqVO 更新信息
      */
-    void updateCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO);
+    void updateCustomer(@Valid CrmCustomerSaveReqVO updateReqVO);
 
     /**
      * 删除客户
@@ -83,7 +86,7 @@ public interface CrmCustomerService {
      * 锁定/解锁客户
      *
      * @param lockReqVO 更新信息
-     * @param userId 用户编号
+     * @param userId    用户编号
      */
     void lockCustomer(@Valid CrmCustomerLockReqVO lockReqVO, Long userId);
 
@@ -101,15 +104,8 @@ public interface CrmCustomerService {
      *
      * @param ids         要领取的客户编号数组
      * @param ownerUserId 负责人
+     * @param isReceive   是/否领取
      */
-    void receiveCustomer(List<Long> ids, Long ownerUserId);
-
-    /**
-     * 获取客户列表
-     *
-     * @return 客户列表
-     * @author zyna
-     */
-    List<CrmCustomerDO> getCustomerList();
+    void receiveCustomer(List<Long> ids, Long ownerUserId, Boolean isReceive);
 
 }

+ 153 - 112
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java

@@ -1,10 +1,15 @@
 package cn.iocoder.yudao.module.crm.service.customer;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.lang.Assert;
+import cn.hutool.extra.spring.SpringUtil;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLockReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
@@ -12,9 +17,11 @@ import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
 import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
 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.framework.permission.core.util.CrmPermissionUtils;
 import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
 import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
+import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
 import com.mzt.logapi.context.LogRecordContext;
 import com.mzt.logapi.service.impl.DiffParseFunction;
 import com.mzt.logapi.starter.annotation.LogRecord;
@@ -24,12 +31,14 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 
 import java.time.LocalDateTime;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
-import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_CUSTOMER;
-import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.TRANSFER_CUSTOMER_LOG_SUCCESS;
+import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
 import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_LOCK_LIMIT;
 import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_OWNER_LIMIT;
 import static java.util.Collections.singletonList;
@@ -56,8 +65,9 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    @LogRecord(type = CRM_CUSTOMER, subType = "创建客户", bizNo = "{{#customerId}}", success = "创建了客户") // TODO @puhui999:创建了客户【客户名】,要记录进去;不然在展示操作日志的全列表,看不清楚是哪个客户哈;
-    public Long createCustomer(CrmCustomerCreateReqVO createReqVO, Long userId) {
+    @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_CREATE_SUB_TYPE, bizNo = "{{#customer.id}}", success = CRM_CUSTOMER_CREATE_SUCCESS)
+    public Long createCustomer(CrmCustomerSaveReqVO createReqVO, Long userId) {
+        createReqVO.setId(null);
         // 1. 校验拥有客户是否到达上限
         validateCustomerExceedOwnerLimit(createReqVO.getOwnerUserId(), 1);
 
@@ -72,17 +82,19 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
         permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())
                 .setBizId(customer.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人
 
-        // 4. 记录操作日志
-        LogRecordContext.putVariable("customerId", customer.getId());
+        // 4. 记录操作日志上下文
+        LogRecordContext.putVariable("customer", customer);
         return customer.getId();
     }
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    @LogRecord(type = CRM_CUSTOMER, subType = "更新客户", bizNo = "{{#updateReqVO.id}}", success = "更新了客户{_DIFF{#updateReqVO}}", extra = "{{#extra}}")
+    @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}", success = CRM_CUSTOMER_UPDATE_SUCCESS)
     @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE)
-    public void updateCustomer(CrmCustomerUpdateReqVO updateReqVO) {
-        // TODO @puhui999:更新的时候,要把 updateReqVO 负责人设置为空,避免修改。
+    public void updateCustomer(CrmCustomerSaveReqVO updateReqVO) {
+        Assert.notNull(updateReqVO.getId(), "客户编号不能为空");
+        // 更新的时候,要把 updateReqVO 负责人设置为空,避免修改。
+        updateReqVO.setOwnerUserId(null);
         // 1. 校验存在
         CrmCustomerDO oldCustomer = validateCustomerExists(updateReqVO.getId());
 
@@ -90,21 +102,18 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
         CrmCustomerDO updateObj = CrmCustomerConvert.INSTANCE.convert(updateReqVO);
         customerMapper.updateById(updateObj);
 
-        // 3. 记录操作日志
-        LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldCustomer, CrmCustomerUpdateReqVO.class));
-        // TODO 扩展信息测试 @puhui999:看着没啥问题,可以删除啦;
-        HashMap<String, Object> extra = new HashMap<>();
-        extra.put("tips", "随便记录一点啦");
-        LogRecordContext.putVariable("extra", extra);
+        // 3. 记录操作日志上下文
+        LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldCustomer, CrmCustomerSaveReqVO.class));
+        LogRecordContext.putVariable("customerName", oldCustomer.getName());
     }
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    @LogRecord(type = CRM_CUSTOMER, subType = "删除客户", bizNo = "{{#id}}", success = "删除了客户")
+    @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_DELETE_SUB_TYPE, bizNo = "{{#id}}", success = CRM_CUSTOMER_DELETE_SUCCESS)
     @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
     public void deleteCustomer(Long id) {
         // 校验存在
-        validateCustomerExists(id);
+        CrmCustomerDO customer = validateCustomerExists(id);
         // TODO @puhui999:如果有联系人、商机,则不允许删除;
 
         // 删除
@@ -112,48 +121,14 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
         // 删除数据权限
         permissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), id);
         // TODO @puhui999:删除跟进记录
-    }
-
-    private CrmCustomerDO validateCustomerExists(Long id) {
-        CrmCustomerDO customerDO = customerMapper.selectById(id);
-        if (customerDO == null) {
-            throw exception(CUSTOMER_NOT_EXISTS);
-        }
-        return customerDO;
-    }
-
-    @Override
-    @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.READ)
-    public CrmCustomerDO getCustomer(Long id) {
-        return customerMapper.selectById(id);
-    }
 
-    @Override
-    public List<CrmCustomerDO> getCustomerList(Collection<Long> ids) {
-        if (CollUtil.isEmpty(ids)) {
-            return Collections.emptyList();
-        }
-        return customerMapper.selectBatchIds(ids);
-    }
-
-    @Override
-    public PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
-        return customerMapper.selectPage(pageReqVO, userId);
-    }
-
-    /**
-     * 校验客户是否存在
-     *
-     * @param customerId 客户 id
-     */
-    @Override
-    public void validateCustomer(Long customerId) {
-        validateCustomerExists(customerId);
+        // 记录操作日志上下文
+        LogRecordContext.putVariable("customerName", customer.getName());
     }
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    @LogRecord(type = CRM_CUSTOMER, subType = "转移客户", bizNo = "{{#reqVO.id}}", success = TRANSFER_CUSTOMER_LOG_SUCCESS)
+    @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}", success = CRM_CUSTOMER_TRANSFER_SUCCESS)
     @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
     public void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId) {
         // 1.1 校验客户是否存在
@@ -168,20 +143,17 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
         customerMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId());
 
         // 3. TODO 记录转移日志
+        // 记录操作日志上下文
         LogRecordContext.putVariable("crmCustomer", customer);
     }
 
     @Override
-    // TODO @puhui999:看看这个能不能根据条件,写操作日志;
-    // TODO 如果是 锁定,则 subType 为 锁定客户;success 为 将客户【】锁定
-    // TODO 如果是 解锁,则 subType 为 解锁客户;success 为 将客户【】解锁
-    @LogRecord(type = CRM_CUSTOMER, subType = "锁定/解锁客户", bizNo = "{{#updateReqVO.id}}", success = "锁定了客户")
-    // TODO @puhui999:数据权限
+    @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_LOCK_SUB_TYPE, bizNo = "{{#lockReqVO.id}}", success = CRM_CUSTOMER_LOCK_SUCCESS)
+    @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#lockReqVO.id", level = CrmPermissionLevelEnum.OWNER)
     public void lockCustomer(CrmCustomerLockReqVO lockReqVO, Long userId) {
         // 1.1 校验当前客户是否存在
-        validateCustomerExists(lockReqVO.getId());
+        CrmCustomerDO customer = validateCustomerExists(lockReqVO.getId());
         // 1.2 校验当前是否重复操作锁定/解锁状态
-        CrmCustomerDO customer = customerMapper.selectById(lockReqVO.getId());
         if (customer.getLockStatus().equals(lockReqVO.getLockStatus())) {
             throw exception(customer.getLockStatus() ? CUSTOMER_LOCK_FAIL_IS_LOCK : CUSTOMER_UNLOCK_FAIL_IS_UNLOCK);
         }
@@ -192,52 +164,16 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
 
         // 2. 更新锁定状态
         customerMapper.updateById(BeanUtils.toBean(lockReqVO, CrmCustomerDO.class));
-    }
 
-    /**
-     * 校验用户拥有的客户数量,是否到达上限
-     *
-     * @param userId 用户编号
-     * @param newCount 附加数量
-     */
-    private void validateCustomerExceedOwnerLimit(Long userId, int newCount) {
-        List<CrmCustomerLimitConfigDO> limitConfigs = customerLimitConfigService.getCustomerLimitConfigListByUserId(
-                CUSTOMER_OWNER_LIMIT.getType(), userId);
-        if (CollUtil.isEmpty(limitConfigs)) {
-            return;
-        }
-        Long ownerCount = customerMapper.selectCountByDealStatusAndOwnerUserId(null, userId);
-        Long dealOwnerCount = customerMapper.selectCountByDealStatusAndOwnerUserId(true, userId);
-        limitConfigs.forEach(limitConfig -> {
-            long nowCount = limitConfig.getDealCountEnabled() ? ownerCount : ownerCount - dealOwnerCount;
-            if (nowCount + newCount > limitConfig.getMaxCount()) {
-                throw exception(CUSTOMER_OWNER_EXCEED_LIMIT);
-            }
-        });
+        // 3. 记录操作日志上下文. tips: 因为这里使用的是老的状态所以记录时反着记录,也就是 lockStatus 为 true 那么就是解锁反之为锁定
+        LogRecordContext.putVariable("crmCustomer", customer);
     }
 
-    /**
-     * 校验用户锁定的客户数量,是否到达上限
-     *
-     * @param userId 用户编号
-     */
-    private void validateCustomerExceedLockLimit(Long userId) {
-        List<CrmCustomerLimitConfigDO> limitConfigs = customerLimitConfigService.getCustomerLimitConfigListByUserId(
-                CUSTOMER_LOCK_LIMIT.getType(), userId);
-        if (CollUtil.isEmpty(limitConfigs)) {
-            return;
-        }
-        Long lockCount = customerMapper.selectCountByLockStatusAndOwnerUserId(true, userId);
-        Integer maxCount = CollectionUtils.getMaxValue(limitConfigs, CrmCustomerLimitConfigDO::getMaxCount);
-        assert maxCount != null;
-        if (lockCount >= maxCount) {
-            throw exception(CUSTOMER_LOCK_EXCEED_LIMIT);
-        }
-    }
+    // ==================== 公海相关操作 ====================
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    @LogRecord(type = CRM_CUSTOMER, subType = "客户放入公海", bizNo = "{{#id}}", success = "将客户放入了公海") // TODO @puhui999:将客户【】放入了公海
+    @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_POOL_SUB_TYPE, bizNo = "{{#id}}", success = CRM_CUSTOMER_POOL_SUCCESS)
     @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
     public void putCustomerPool(Long id) {
         // 1. 校验存在
@@ -259,16 +195,18 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
         permissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), customer.getId(),
                 CrmPermissionLevelEnum.OWNER.getLevel());
         // TODO @puhui999:联系人的负责人,也要设置为 null;这块和领取是对应的;因为领取后,负责人也要关联过来;
+
+        // 记录操作日志上下文
+        LogRecordContext.putVariable("customerName", customer.getName());
     }
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    // TODO @puhui999:权限校验
+    public void receiveCustomer(List<Long> ids, Long ownerUserId, Boolean isReceive) {
+        if (!isReceive && !CrmPermissionUtils.isCrmAdmin()) { // 只有管理员可以分配
+            throw exception(CRM_PERMISSION_DENIED, CrmBizTypeEnum.CRM_CUSTOMER.getName());
+        }
 
-    // TODO @puhui999:如果是分配,操作日志是 “将客户【】分配给【】”
-    // TODO @puhui999:如果是领取,操作日志是“领取客户【】”;
-    // TODO @puhui999:如果是多条,则需要记录多条操作日志;不然 bizId 不好关联
-    public void receiveCustomer(List<Long> ids, Long ownerUserId) {
         // 1.1 校验存在
         List<CrmCustomerDO> customers = customerMapper.selectBatchIds(ids);
         if (customers.size() != ids.size()) {
@@ -303,6 +241,55 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
         // 2.3 创建负责人数据权限
         permissionService.createPermissionBatch(createPermissions);
         // TODO @芋艿:要不要处理关联的联系人???
+
+        // 3. 记录操作日志
+        AdminUserRespDTO user = null;
+        if (!isReceive) {
+            user = adminUserApi.getUser(ownerUserId);
+        }
+        for (CrmCustomerDO customer : customers) {
+            getSelf().receiveCustomerLog(customer, user == null ? null : user.getNickname());
+        }
+    }
+
+    @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_RECEIVE_SUB_TYPE, bizNo = "{{#customer.id}}", success = CRM_CUSTOMER_RECEIVE_SUCCESS)
+    public void receiveCustomerLog(CrmCustomerDO customer, String ownerUserName) {
+        // 记录操作日志上下文
+        LogRecordContext.putVariable("customer", customer);
+        LogRecordContext.putVariable("ownerUserName", ownerUserName);
+    }
+
+    //======================= 查询相关 =======================
+
+    @Override
+    @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.READ)
+    public CrmCustomerDO getCustomer(Long id) {
+        return customerMapper.selectById(id);
+    }
+
+    @Override
+    public List<CrmCustomerDO> getCustomerList(Collection<Long> ids) {
+        if (CollUtil.isEmpty(ids)) {
+            return Collections.emptyList();
+        }
+        return customerMapper.selectBatchIds(ids);
+    }
+
+    @Override
+    public PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
+        return customerMapper.selectPage(pageReqVO, userId);
+    }
+
+    //======================= 校验相关 =======================
+
+    /**
+     * 校验客户是否存在
+     *
+     * @param customerId 客户 id
+     */
+    @Override
+    public void validateCustomer(Long customerId) {
+        validateCustomerExists(customerId);
     }
 
     private void validateCustomerOwnerExists(CrmCustomerDO customer, Boolean pool) {
@@ -314,11 +301,19 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
             throw exception(CUSTOMER_IN_POOL, customer.getName());
         }
         // 负责人已存在
-        if (customer.getOwnerUserId() != null) {
+        if (!pool && customer.getOwnerUserId() != null) {
             throw exception(CUSTOMER_OWNER_EXISTS, customer.getName());
         }
     }
 
+    private CrmCustomerDO validateCustomerExists(Long id) {
+        CrmCustomerDO customerDO = customerMapper.selectById(id);
+        if (customerDO == null) {
+            throw exception(CUSTOMER_NOT_EXISTS);
+        }
+        return customerDO;
+    }
+
     private void validateCustomerIsLocked(CrmCustomerDO customer, Boolean pool) {
         if (customer.getLockStatus()) {
             throw exception(pool ? CUSTOMER_LOCKED_PUT_POOL_FAIL : CUSTOMER_LOCKED, customer.getName());
@@ -331,9 +326,55 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
         }
     }
 
-    @Override
-    public List<CrmCustomerDO> getCustomerList() {
-        return customerMapper.selectList();
+    /**
+     * 校验用户拥有的客户数量,是否到达上限
+     *
+     * @param userId   用户编号
+     * @param newCount 附加数量
+     */
+    private void validateCustomerExceedOwnerLimit(Long userId, int newCount) {
+        List<CrmCustomerLimitConfigDO> limitConfigs = customerLimitConfigService.getCustomerLimitConfigListByUserId(
+                CUSTOMER_OWNER_LIMIT.getType(), userId);
+        if (CollUtil.isEmpty(limitConfigs)) {
+            return;
+        }
+        Long ownerCount = customerMapper.selectCountByDealStatusAndOwnerUserId(null, userId);
+        Long dealOwnerCount = customerMapper.selectCountByDealStatusAndOwnerUserId(true, userId);
+        limitConfigs.forEach(limitConfig -> {
+            long nowCount = limitConfig.getDealCountEnabled() ? ownerCount : ownerCount - dealOwnerCount;
+            if (nowCount + newCount > limitConfig.getMaxCount()) {
+                throw exception(CUSTOMER_OWNER_EXCEED_LIMIT);
+            }
+        });
+    }
+
+    /**
+     * 校验用户锁定的客户数量,是否到达上限
+     *
+     * @param userId 用户编号
+     */
+    private void validateCustomerExceedLockLimit(Long userId) {
+        List<CrmCustomerLimitConfigDO> limitConfigs = customerLimitConfigService.getCustomerLimitConfigListByUserId(
+                CUSTOMER_LOCK_LIMIT.getType(), userId);
+        if (CollUtil.isEmpty(limitConfigs)) {
+            return;
+        }
+        Long lockCount = customerMapper.selectCountByLockStatusAndOwnerUserId(true, userId);
+        Integer maxCount = CollectionUtils.getMaxValue(limitConfigs, CrmCustomerLimitConfigDO::getMaxCount);
+        assert maxCount != null;
+        if (lockCount >= maxCount) {
+            throw exception(CUSTOMER_LOCK_EXCEED_LIMIT);
+        }
+    }
+
+
+    /**
+     * 获得自身的代理对象,解决 AOP 生效问题
+     *
+     * @return 自己
+     */
+    private CrmCustomerServiceImpl getSelf() {
+        return SpringUtil.getBean(getClass());
     }
 
 }

+ 9 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java

@@ -90,6 +90,15 @@ public interface CrmPermissionService {
      */
     List<CrmPermissionDO> getPermissionListByBiz(Integer bizType, Long bizId);
 
+    /**
+     * 获取数据权限列表,通过 数据类型 x 某个数据
+     *
+     * @param bizType 数据类型,关联 {@link CrmBizTypeEnum}
+     * @param bizIds  数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId()
+     * @return Crm 数据权限列表
+     */
+    List<CrmPermissionDO> getPermissionListByBiz(Integer bizType, Collection<Long> bizIds);
+
     /**
      * 获取用户参与的模块数据列表
      *

+ 5 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java

@@ -187,6 +187,11 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
         return crmPermissionMapper.selectByBizTypeAndBizId(bizType, bizId);
     }
 
+    @Override
+    public List<CrmPermissionDO> getPermissionListByBiz(Integer bizType, Collection<Long> bizIds) {
+        return crmPermissionMapper.selectByBizTypeAndBizIds(bizType, bizIds);
+    }
+
     @Override
     public List<CrmPermissionDO> getPermissionListByBizTypeAndUserId(Integer bizType, Long userId) {
         return crmPermissionMapper.selectListByBizTypeAndUserId(bizType, userId);

+ 5 - 7
yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImplTest.java

@@ -2,19 +2,17 @@ package cn.iocoder.yudao.module.crm.service.customer;
 
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerCreateReqVO;
 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerUpdateReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
 import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
 import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
+import jakarta.annotation.Resource;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.mock.mockito.MockBean;
 import org.springframework.context.annotation.Import;
 
-import jakarta.annotation.Resource;
-
 import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
 import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@@ -47,7 +45,7 @@ public class CrmCustomerServiceImplTest extends BaseDbUnitTest {
     @Test
     public void testCreateCustomer_success() {
         // 准备参数
-        CrmCustomerCreateReqVO reqVO = randomPojo(CrmCustomerCreateReqVO.class);
+        CrmCustomerSaveReqVO reqVO = randomPojo(CrmCustomerSaveReqVO.class);
 
         // 调用
         Long customerId = customerService.createCustomer(reqVO, getLoginUserId());
@@ -64,7 +62,7 @@ public class CrmCustomerServiceImplTest extends BaseDbUnitTest {
         CrmCustomerDO dbCustomer = randomPojo(CrmCustomerDO.class);
         customerMapper.insert(dbCustomer);// @Sql: 先插入出一条存在的数据
         // 准备参数
-        CrmCustomerUpdateReqVO reqVO = randomPojo(CrmCustomerUpdateReqVO.class, o -> {
+        CrmCustomerSaveReqVO reqVO = randomPojo(CrmCustomerSaveReqVO.class, o -> {
             o.setId(dbCustomer.getId()); // 设置更新的 ID
         });
 
@@ -78,7 +76,7 @@ public class CrmCustomerServiceImplTest extends BaseDbUnitTest {
     @Test
     public void testUpdateCustomer_notExists() {
         // 准备参数
-        CrmCustomerUpdateReqVO reqVO = randomPojo(CrmCustomerUpdateReqVO.class);
+        CrmCustomerSaveReqVO reqVO = randomPojo(CrmCustomerSaveReqVO.class);
 
         // 调用, 并断言异常
         assertServiceException(() -> customerService.updateCustomer(reqVO), CUSTOMER_NOT_EXISTS);

+ 5 - 7
yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/customerlimitconfig/CrmCustomerLimitConfigServiceImplTest.java

@@ -2,18 +2,16 @@ package cn.iocoder.yudao.module.crm.service.customerlimitconfig;
 
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigPageReqVO;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigUpdateReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
 import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerLimitConfigMapper;
 import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerLimitConfigServiceImpl;
+import jakarta.annotation.Resource;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.springframework.context.annotation.Import;
 
-import jakarta.annotation.Resource;
-
 import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
 import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
 import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
@@ -40,7 +38,7 @@ public class CrmCustomerLimitConfigServiceImplTest extends BaseDbUnitTest {
     @Test
     public void testCreateCustomerLimitConfig_success() {
         // 准备参数
-        CrmCustomerLimitConfigCreateReqVO reqVO = randomPojo(CrmCustomerLimitConfigCreateReqVO.class);
+        CrmCustomerLimitConfigSaveReqVO reqVO = randomPojo(CrmCustomerLimitConfigSaveReqVO.class);
 
         // 调用
         Long customerLimitConfigId = customerLimitConfigService.createCustomerLimitConfig(reqVO);
@@ -57,7 +55,7 @@ public class CrmCustomerLimitConfigServiceImplTest extends BaseDbUnitTest {
         CrmCustomerLimitConfigDO dbCustomerLimitConfig = randomPojo(CrmCustomerLimitConfigDO.class);
         customerLimitConfigMapper.insert(dbCustomerLimitConfig);// @Sql: 先插入出一条存在的数据
         // 准备参数
-        CrmCustomerLimitConfigUpdateReqVO reqVO = randomPojo(CrmCustomerLimitConfigUpdateReqVO.class, o -> {
+        CrmCustomerLimitConfigSaveReqVO reqVO = randomPojo(CrmCustomerLimitConfigSaveReqVO.class, o -> {
             o.setId(dbCustomerLimitConfig.getId()); // 设置更新的 ID
         });
 
@@ -71,7 +69,7 @@ public class CrmCustomerLimitConfigServiceImplTest extends BaseDbUnitTest {
     @Test
     public void testUpdateCustomerLimitConfig_notExists() {
         // 准备参数
-        CrmCustomerLimitConfigUpdateReqVO reqVO = randomPojo(CrmCustomerLimitConfigUpdateReqVO.class);
+        CrmCustomerLimitConfigSaveReqVO reqVO = randomPojo(CrmCustomerLimitConfigSaveReqVO.class);
 
         // 调用, 并断言异常
         assertServiceException(() -> customerLimitConfigService.updateCustomerLimitConfig(reqVO), CUSTOMER_LIMIT_CONFIG_NOT_EXISTS);

+ 2 - 2
yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/statistics/vo/MpStatisticsGetReqVO.java

@@ -1,10 +1,10 @@
 package cn.iocoder.yudao.module.mp.controller.admin.statistics.vo;
 
 import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotNull;
 import lombok.Data;
 import org.springframework.format.annotation.DateTimeFormat;
 
-import jakarta.validation.constraints.NotNull;
 import java.time.LocalDateTime;
 
 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@@ -17,7 +17,7 @@ public class MpStatisticsGetReqVO {
     @NotNull(message = "公众号账号的编号不能为空")
     private Long accountId;
 
-    @Schema(description = "查询时间范围")
+    @Schema(description = "查询时间范围", example = "[2022-07-01 00:00:00, 2022-07-01 23:59:59]")
     @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
     @NotNull(message = "查询时间范围不能为空")
     private LocalDateTime[] date;

+ 14 - 2
yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/statistics/MpStatisticsConvert.java

@@ -11,10 +11,16 @@ import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary;
 import org.mapstruct.Mapper;
 import org.mapstruct.Mapping;
 import org.mapstruct.Mappings;
+import org.mapstruct.Named;
 import org.mapstruct.factory.Mappers;
 
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.List;
 
+import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
+
 @Mapper
 public interface MpStatisticsConvert {
 
@@ -27,7 +33,7 @@ public interface MpStatisticsConvert {
     List<MpStatisticsUpstreamMessageRespVO> convertList03(List<WxDataCubeMsgResult> list);
 
     @Mappings({
-            @Mapping(source = "refDate", target = "refDate", dateFormat = "yyyy-MM-dd"),
+            @Mapping(target = "refDate", expression = "java(dateFormat0(bean.getRefDate()))"),
             @Mapping(source = "msgUser", target = "messageUser"),
             @Mapping(source = "msgCount", target = "messageCount"),
     })
@@ -35,6 +41,12 @@ public interface MpStatisticsConvert {
 
     List<MpStatisticsInterfaceSummaryRespVO> convertList04(List<WxDataCubeInterfaceResult> list);
 
-    @Mapping(source = "refDate", target = "refDate", dateFormat = "yyyy-MM-dd")
+    @Mapping(target = "refDate", expression = "java(dateFormat0(bean.getRefDate()))")
     MpStatisticsInterfaceSummaryRespVO convert(WxDataCubeInterfaceResult bean);
+
+    @Named("dateFormat0")
+    default LocalDateTime dateFormat0(String date) {
+        return LocalDate.parse(date, DateTimeFormatter.ofPattern(FORMAT_YEAR_MONTH_DAY)).atStartOfDay();
+    }
+
 }

+ 9 - 3
yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/message/MpMessageServiceImpl.java

@@ -1,6 +1,7 @@
 package cn.iocoder.yudao.module.mp.service.message;
 
 import cn.hutool.core.lang.Assert;
+import cn.hutool.core.util.ObjUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.module.mp.controller.admin.message.vo.message.MpMessagePageReqVO;
@@ -17,6 +18,8 @@ import cn.iocoder.yudao.module.mp.service.account.MpAccountService;
 import cn.iocoder.yudao.module.mp.service.material.MpMaterialService;
 import cn.iocoder.yudao.module.mp.service.message.bo.MpMessageSendOutReqBO;
 import cn.iocoder.yudao.module.mp.service.user.MpUserService;
+import jakarta.annotation.Resource;
+import jakarta.validation.Validator;
 import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.api.WxConsts;
 import me.chanjar.weixin.common.error.WxErrorException;
@@ -28,9 +31,6 @@ import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
-import jakarta.annotation.Resource;
-import jakarta.validation.Validator;
-
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.MESSAGE_SEND_FAIL;
 
@@ -72,6 +72,12 @@ public class MpMessageServiceImpl implements MpMessageService {
         // 获得关联信息
         MpAccountDO account = mpAccountService.getAccountFromCache(appId);
         Assert.notNull(account, "公众号账号({}) 不存在", appId);
+
+        // 订阅事件不记录,因为此时公众号粉丝表中还没有此粉丝的数据
+        if (ObjUtil.equal(wxMessage.getEvent(), WxConsts.EventType.SUBSCRIBE)) {
+            return;
+        }
+
         MpUserDO user = mpUserService.getUser(appId, wxMessage.getFromUser());
         Assert.notNull(user, "公众号粉丝({}/{}) 不存在", appId, wxMessage.getFromUser());
 

+ 6 - 0
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/PostApi.java

@@ -1,5 +1,7 @@
 package cn.iocoder.yudao.module.system.api.dept;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.map.MapUtil;
 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
 import cn.iocoder.yudao.module.system.api.dept.dto.PostRespDTO;
 
@@ -26,6 +28,10 @@ public interface PostApi {
     List<PostRespDTO> getPostList(Collection<Long> ids);
 
     default Map<Long, PostRespDTO> getPostMap(Collection<Long> ids) {
+        if (CollUtil.isEmpty(ids)) {
+            return MapUtil.empty();
+        }
+
         List<PostRespDTO> list = getPostList(ids);
         return CollectionUtils.convertMap(list, PostRespDTO::getId);
     }

+ 7 - 0
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/dto/OperateLogV2RespDTO.java

@@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.system.api.logger.dto;
 
 import lombok.Data;
 
+import java.time.LocalDateTime;
+
 /**
  * 系统操作日志 Resp DTO
  *
@@ -64,4 +66,9 @@ public class OperateLogV2RespDTO {
      */
     private String userAgent;
 
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
 }

+ 4 - 2
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/logger/OperateLogConvert.java

@@ -35,10 +35,12 @@ public interface OperateLogConvert {
         return BeanUtils.toBean(operateLogPage, OperateLogV2RespDTO.class).setList(setUserInfo(operateLogPage.getList(), userList));
     }
 
-    private static List<OperateLogV2RespDTO> setUserInfo(List<OperateLogV2DO> logList, List<AdminUserDO> userList) {
+    OperateLogV2RespDTO convert(OperateLogV2DO operateLogV2DO);
+
+    private List<OperateLogV2RespDTO> setUserInfo(List<OperateLogV2DO> logList, List<AdminUserDO> userList) {
         Map<Long, AdminUserDO> userMap = convertMap(userList, AdminUserDO::getId);
         return CollectionUtils.convertList(logList, item -> {
-            OperateLogV2RespDTO respDTO = BeanUtils.toBean(item, OperateLogV2RespDTO.class);
+            OperateLogV2RespDTO respDTO = convert(item);
             findAndThen(userMap, item.getUserId(), user -> respDTO.setUserName(user.getNickname()));
             return respDTO;
         });

+ 43 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/operatelog/core/DeptParseFunction.java

@@ -0,0 +1,43 @@
+package cn.iocoder.yudao.module.system.framework.operatelog.core;
+
+import cn.hutool.core.util.StrUtil;
+import cn.iocoder.yudao.module.system.api.dept.DeptApi;
+import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
+import com.mzt.logapi.service.IParseFunction;
+import jakarta.annotation.Resource;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * 管理员名字的 {@link IParseFunction} 实现类
+ *
+ * @author HUIHUI
+ */
+@Slf4j
+@Component
+public class DeptParseFunction implements IParseFunction {
+
+    @Resource
+    private DeptApi deptApi;
+
+    @Override
+    public String functionName() {
+        return "getDeptById";
+    }
+
+    @Override
+    public String apply(Object value) {
+        if (StrUtil.isEmptyIfStr(value)) {
+            return "";
+        }
+
+        // 获取部门信息
+        DeptRespDTO dept = deptApi.getDept(Long.parseLong(value.toString()));
+        if (dept == null) {
+            log.warn("[apply][获取部门{{}}为空", value);
+            return "";
+        }
+        return dept.getName();
+    }
+
+}