Commit 3c7f63c356d2ee7a642bd525996e097288bae6c1

Authored by 芋道源码
Committed by Gitee
2 parents df9ff3fc 68f5edaa

!810 fix:修复 issues 提到的一些公众号上的问题

Merge pull request !810 from puhui999/develop
Showing 46 changed files with 732 additions and 551 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/date/LocalDateTimeUtils.java
... ... @@ -6,6 +6,7 @@ import java.time.Duration;
6 6 import java.time.LocalDate;
7 7 import java.time.LocalDateTime;
8 8 import java.time.LocalTime;
  9 +import java.time.temporal.ChronoUnit;
9 10 import java.time.temporal.TemporalAdjusters;
10 11  
11 12 /**
... ... @@ -121,4 +122,8 @@ public class LocalDateTimeUtils {
121 122 return date.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX);
122 123 }
123 124  
  125 + public static Long between(LocalDateTime dateTime) {
  126 + return LocalDateTimeUtil.between(dateTime, LocalDateTime.now(), ChronoUnit.DAYS);
  127 + }
  128 +
124 129 }
... ...
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogV2Configuration.java
1 1 package cn.iocoder.yudao.framework.operatelog.config;
2 2  
3   -import cn.iocoder.yudao.framework.operatelog.core.service.ILogRecordServiceImpl;
  3 +import cn.iocoder.yudao.framework.operatelog.core.service.LogRecordServiceImpl;
4 4 import com.mzt.logapi.service.ILogRecordService;
5 5 import com.mzt.logapi.starter.annotation.EnableLogRecord;
6 6 import lombok.extern.slf4j.Slf4j;
... ... @@ -21,7 +21,7 @@ public class YudaoOperateLogV2Configuration {
21 21 @Bean
22 22 @Primary
23 23 public ILogRecordService iLogRecordServiceImpl() {
24   - return new ILogRecordServiceImpl();
  24 + return new LogRecordServiceImpl();
25 25 }
26 26  
27 27 }
... ...
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/core/service/ILogRecordServiceImpl.java renamed to 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;
2 2  
3 3 import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils;
4 4 import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
5   -import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
  5 +import cn.iocoder.yudao.framework.security.core.LoginUser;
  6 +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
6 7 import cn.iocoder.yudao.module.system.api.logger.OperateLogApi;
7 8 import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2CreateReqDTO;
8 9 import com.mzt.logapi.beans.LogRecord;
... ... @@ -13,7 +14,6 @@ import lombok.extern.slf4j.Slf4j;
13 14  
14 15 import java.util.List;
15 16  
16   -// TODO @puhui999:LogRecordServiceImpl 改成这个名字哈
17 17 /**
18 18 * 操作日志 ILogRecordService 实现类
19 19 *
... ... @@ -22,7 +22,7 @@ import java.util.List;
22 22 * @author HUIHUI
23 23 */
24 24 @Slf4j
25   -public class ILogRecordServiceImpl implements ILogRecordService {
  25 +public class LogRecordServiceImpl implements ILogRecordService {
26 26  
27 27 @Resource
28 28 private OperateLogApi operateLogApi;
... ... @@ -46,9 +46,13 @@ public class ILogRecordServiceImpl implements ILogRecordService {
46 46 }
47 47  
48 48 private static void fillUserFields(OperateLogV2CreateReqDTO reqDTO) {
49   - // TODO @puhui999:使用 SecurityFrameworkUtils。因为要考虑,rpc、mq、job,它其实不是 web;
50   - reqDTO.setUserId(WebFrameworkUtils.getLoginUserId());
51   - reqDTO.setUserType(WebFrameworkUtils.getLoginUserType());
  49 + // 使用 SecurityFrameworkUtils。因为要考虑,rpc、mq、job,它其实不是 web;
  50 + LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
  51 + if (loginUser == null) {
  52 + return;
  53 + }
  54 + reqDTO.setUserId(loginUser.getId());
  55 + reqDTO.setUserType(loginUser.getUserType());
52 56 }
53 57  
54 58 public static void fillModuleFields(OperateLogV2CreateReqDTO reqDTO, LogRecord logRecord) {
... ...
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 {
41 41 ErrorCode CUSTOMER_LOCKED_PUT_POOL_FAIL = new ErrorCode(1_020_006_005, "客户【{}】放入公海失败,原因:客户已锁定");
42 42 ErrorCode CUSTOMER_UPDATE_OWNER_USER_FAIL = new ErrorCode(1_020_006_006, "更新客户【{}】负责人失败, 原因:系统异常");
43 43 ErrorCode CUSTOMER_LOCK_FAIL_IS_LOCK = new ErrorCode(1_020_006_007, "锁定客户失败,它已经处于锁定状态");
44   - ErrorCode CUSTOMER_UNLOCK_FAIL_IS_UNLOCK = new ErrorCode(1_020_006_008, "锁定客户失败,它已经处于未锁定状态");
  44 + ErrorCode CUSTOMER_UNLOCK_FAIL_IS_UNLOCK = new ErrorCode(1_020_006_008, "解锁客户失败,它已经处于未锁定状态");
45 45 ErrorCode CUSTOMER_LOCK_EXCEED_LIMIT = new ErrorCode(1_020_006_009, "锁定客户失败,超出锁定规则上限");
46 46 ErrorCode CUSTOMER_OWNER_EXCEED_LIMIT = new ErrorCode(1_020_006_010, "操作失败,超出客户数拥有上限");
47 47  
... ...
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;
2 2  
3 3 /**
4 4 * CRM 操作日志枚举
  5 + * 目的:统一管理,也减少 Service 里各种“复杂”字符串
5 6 *
6 7 * @author HUIHUI
7 8 */
8 9 public interface LogRecordConstants {
9 10  
10   - //======================= 客户模块类型 =======================
11   - // TODO puhui999: 确保模块命名方式为 module + 子模块名称的方式。统一定义模块名称是为了方便查询各自记录的操作日志,列如说:查询客户【张三的操作日志】就可以 module + bizId
12   - String CRM_LEADS = "CRM 线索";
13   - String CRM_CUSTOMER = "CRM 客户";
14   - String CRM_CONTACT = "CRM 联系人";
15   - String CRM_BUSINESS = "CRM 商机";
16   - String CRM_CONTRACT = "CRM 合同";
17   - String CRM_PRODUCT = "CRM 产品";
18   - String CRM_RECEIVABLE = "CRM 回款";
19   - String CRM_RECEIVABLE_PLAN = "CRM 回款计划";
  11 + // ======================= CRM_LEADS 线索 =======================
20 12  
21   - //======================= 客户转移操作日志 =======================
  13 + String CRM_LEADS_TYPE = "CRM 线索";
22 14  
23   - String TRANSFER_CUSTOMER_LOG_SUCCESS = "把客户【{{#crmCustomer.name}}】的负责人从【{getAdminUserById{#crmCustomer.ownerUserId}}】变更为了【{getAdminUserById{#reqVO.newOwnerUserId}}】";
  15 + // ======================= CRM_CUSTOMER 客户 =======================
24 16  
25   - // TODO @puhui999:这里格式是不是可以这样;目的是:统一管理,也减少 Service 里各种“复杂”字符串
26   - // ======================= Customer 客户 =======================
27   - String CUSTOMER_TYPE = "CRM 客户";
28   - String CUSTOMER_CREATE_SUB_TYPE = "创建客户";
29   - String CUSTOMER_CREATE_SUCCESS = "更新了客户{_DIFF{#updateReqVO}}";
  17 + String CRM_CUSTOMER_TYPE = "CRM 客户";
  18 + String CRM_CUSTOMER_CREATE_SUB_TYPE = "创建客户";
  19 + String CRM_CUSTOMER_CREATE_SUCCESS = "创建了客户{{#customer.name}}";
  20 + String CRM_CUSTOMER_UPDATE_SUB_TYPE = "更新客户";
  21 + String CRM_CUSTOMER_UPDATE_SUCCESS = "更新了客户【{{#customerName}}】: {_DIFF{#updateReqVO}}";
  22 + String CRM_CUSTOMER_DELETE_SUB_TYPE = "删除客户";
  23 + String CRM_CUSTOMER_DELETE_SUCCESS = "删除了客户【{{#customerName}}】";
  24 + String CRM_CUSTOMER_TRANSFER_SUB_TYPE = "转移客户";
  25 + String CRM_CUSTOMER_TRANSFER_SUCCESS = "将客户【{{#crmCustomer.name}}】的负责人从【{getAdminUserById{#crmCustomer.ownerUserId}}】变更为了【{getAdminUserById{#reqVO.newOwnerUserId}}】";
  26 + String CRM_CUSTOMER_LOCK_SUB_TYPE = "{{#crmCustomer.lockStatus ? '解锁客户' : '锁定客户'}}";
  27 + String CRM_CUSTOMER_LOCK_SUCCESS = "{{#crmCustomer.lockStatus ? '将客户【' + #crmCustomer.name + '】解锁' : '将客户【' + #crmCustomer.name + '】锁定'}}";
  28 + String CRM_CUSTOMER_POOL_SUB_TYPE = "客户放入公海";
  29 + String CRM_CUSTOMER_POOL_SUCCESS = "将客户【{{#customerName}}】放入了公海";
  30 + String CRM_CUSTOMER_RECEIVE_SUB_TYPE = "{{#ownerUserName != null ? '分配客户' : '领取客户'}}";
  31 + String CRM_CUSTOMER_RECEIVE_SUCCESS = "{{#ownerUserName != null ? '将客户【' + #customer.name + '】分配给【' + #ownerUserName + '】' : '领取客户【' + #customer.name + '】'}}";
30 32  
31   - String CUSTOMER_UPDATE_SUB_TYPE = "更新客户";
  33 + // ======================= CRM_CUSTOMER_LIMIT_CONFIG 客户限制配置 =======================
  34 +
  35 + String CRM_CUSTOMER_LIMIT_CONFIG_TYPE = "CRM 客户限制配置";
  36 + String CRM_CUSTOMER_LIMIT_CONFIG_CREATE_SUB_TYPE = "创建客户限制配置";
  37 + String CRM_CUSTOMER_LIMIT_CONFIG_CREATE_SUCCESS = "创建了【{{#limitType}}】类型的客户限制配置";
  38 + String CRM_CUSTOMER_LIMIT_CONFIG_UPDATE_SUB_TYPE = "更新客户限制配置";
  39 + String CRM_CUSTOMER_LIMIT_CONFIG_UPDATE_SUCCESS = "更新了客户限制配置: {_DIFF{#updateReqVO}}";
  40 + String CRM_CUSTOMER_LIMIT_CONFIG_DELETE_SUB_TYPE = "删除客户限制配置";
  41 + String CRM_CUSTOMER_LIMIT_CONFIG_DELETE_SUCCESS = "删除了【{{#limitType}}】类型的客户限制配置";
  42 +
  43 + // ======================= CRM_CUSTOMER_POOL_CONFIG 客户公海规则 =======================
  44 +
  45 + String CRM_CUSTOMER_POOL_CONFIG_TYPE = "CRM 客户公海规则";
  46 + String CRM_CUSTOMER_POOL_CONFIG_SUB_TYPE = "{{#isPoolConfigUpdate ? '更新客户公海规则' : '创建客户公海规则'}}";
  47 + String CRM_CUSTOMER_POOL_CONFIG_SUCCESS = "{{#isPoolConfigUpdate ? '更新了客户公海规则' : '创建了客户公海规则'}}";
  48 +
  49 + // ======================= CRM_CONTACT 联系人 =======================
  50 +
  51 + String CRM_CONTACT_TYPE = "CRM 联系人";
  52 +
  53 + // ======================= CRM_BUSINESS 商机 =======================
  54 +
  55 + String CRM_BUSINESS_TYPE = "CRM 商机";
  56 +
  57 + // ======================= CRM_CONTRACT 合同 =======================
  58 +
  59 + String CRM_CONTRACT_TYPE = "CRM 合同";
  60 +
  61 + // ======================= CRM_PRODUCT 产品 =======================
  62 +
  63 + String CRM_PRODUCT_TYPE = "CRM 产品";
  64 +
  65 + // ======================= CRM_RECEIVABLE 回款 =======================
  66 +
  67 + String CRM_RECEIVABLE_TYPE = "CRM 回款";
  68 +
  69 + // ======================= CRM_RECEIVABLE_PLAN 回款计划 =======================
  70 +
  71 + String CRM_RECEIVABLE_PLAN_TYPE = "CRM 回款计划";
32 72  
33 73 }
... ...
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/customer/CrmCustomerLimitConfigTypeEnum.java
1 1 package cn.iocoder.yudao.module.crm.enums.customer;
2 2  
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.util.ObjUtil;
3 5 import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
4 6 import lombok.AllArgsConstructor;
5 7 import lombok.Getter;
... ... @@ -36,6 +38,12 @@ public enum CrmCustomerLimitConfigTypeEnum implements IntArrayValuable {
36 38 */
37 39 private final String name;
38 40  
  41 + public static String getNameByType(Integer type) {
  42 + CrmCustomerLimitConfigTypeEnum typeEnum = CollUtil.findOne(CollUtil.newArrayList(CrmCustomerLimitConfigTypeEnum.values()),
  43 + item -> ObjUtil.equal(item.type, type));
  44 + return typeEnum == null ? null : typeEnum.getName();
  45 + }
  46 +
39 47 @Override
40 48 public int[] array() {
41 49 return ARRAYS;
... ...
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;
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
6 7 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
7 8 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
8 9 import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
9 10 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
10 11 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
11 12 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
  13 +import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfigDO;
  14 +import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerPoolConfigService;
12 15 import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
13 16 import cn.iocoder.yudao.module.system.api.dept.DeptApi;
14 17 import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
... ... @@ -19,7 +22,6 @@ import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
19 22 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
20 23 import io.swagger.v3.oas.annotations.Operation;
21 24 import io.swagger.v3.oas.annotations.Parameter;
22   -import io.swagger.v3.oas.annotations.Parameters;
23 25 import io.swagger.v3.oas.annotations.tags.Tag;
24 26 import jakarta.annotation.Resource;
25 27 import jakarta.servlet.http.HttpServletResponse;
... ... @@ -36,11 +38,10 @@ import java.util.stream.Stream;
36 38  
37 39 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
38 40 import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
39   -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
40   -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap;
  41 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
41 42 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
42 43 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
43   -import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_CUSTOMER;
  44 +import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_CUSTOMER_TYPE;
44 45  
45 46 @Tag(name = "管理后台 - CRM 客户")
46 47 @RestController
... ... @@ -50,7 +51,8 @@ public class CrmCustomerController {
50 51  
51 52 @Resource
52 53 private CrmCustomerService customerService;
53   -
  54 + @Resource
  55 + private CrmCustomerPoolConfigService customerPoolConfigService;
54 56 @Resource
55 57 private DeptApi deptApi;
56 58 @Resource
... ... @@ -58,28 +60,24 @@ public class CrmCustomerController {
58 60 @Resource
59 61 private OperateLogApi operateLogApi;
60 62  
61   - // TODO @puhui999:把 CrmCustomerCreateReqVO、CrmCustomerUpdateReqVO、CrmCustomerRespVO 按照新的规范,搞一下哈;
62 63 @PostMapping("/create")
63 64 @Operation(summary = "创建客户")
64   - @OperateLog(enable = false) // TODO 关闭原有日志记录;@puhui999:注解都先删除。先记录,没关系。我们下个迭代,就都删除掉操作日志了;
65 65 @PreAuthorize("@ss.hasPermission('crm:customer:create')")
66   - public CommonResult<Long> createCustomer(@Valid @RequestBody CrmCustomerCreateReqVO createReqVO) {
  66 + public CommonResult<Long> createCustomer(@Valid @RequestBody CrmCustomerSaveReqVO createReqVO) {
67 67 return success(customerService.createCustomer(createReqVO, getLoginUserId()));
68 68 }
69 69  
70 70 @PutMapping("/update")
71 71 @Operation(summary = "更新客户")
72   - @OperateLog(enable = false) // TODO 关闭原有日志记录
73 72 @PreAuthorize("@ss.hasPermission('crm:customer:update')")
74   - public CommonResult<Boolean> updateCustomer(@Valid @RequestBody CrmCustomerUpdateReqVO updateReqVO) {
  73 + public CommonResult<Boolean> updateCustomer(@Valid @RequestBody CrmCustomerSaveReqVO updateReqVO) {
75 74 customerService.updateCustomer(updateReqVO);
76 75 return success(true);
77 76 }
78 77  
79 78 @DeleteMapping("/delete")
80 79 @Operation(summary = "删除客户")
81   - @OperateLog(enable = false) // TODO 关闭原有日志记录
82   - @Parameter(name = "id", description = "编号", required = true)
  80 + @Parameter(name = "id", description = "客户编号", required = true)
83 81 @PreAuthorize("@ss.hasPermission('crm:customer:delete')")
84 82 public CommonResult<Boolean> deleteCustomer(@RequestParam("id") Long id) {
85 83 customerService.deleteCustomer(id);
... ... @@ -103,7 +101,6 @@ public class CrmCustomerController {
103 101 return success(CrmCustomerConvert.INSTANCE.convert(customer, userMap, deptMap));
104 102 }
105 103  
106   - // TODO @puhui999:这个查询会查出多个;微信发你图了
107 104 @GetMapping("/page")
108 105 @Operation(summary = "获得客户分页")
109 106 @PreAuthorize("@ss.hasPermission('crm:customer:query')")
... ... @@ -115,11 +112,37 @@ public class CrmCustomerController {
115 112 }
116 113  
117 114 // 2. 拼接数据
118   - // TODO @puhui999:距离进入公海的时间
  115 + // 距离进入公海的时间
  116 + Map<Long, Long> poolDayMap = getPoolDayMap(pageResult);
119 117 Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
120 118 convertSetByFlatMap(pageResult.getList(), user -> Stream.of(Long.parseLong(user.getCreator()), user.getOwnerUserId())));
121 119 Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
122   - return success(CrmCustomerConvert.INSTANCE.convertPage(pageResult, userMap, deptMap));
  120 + return success(CrmCustomerConvert.INSTANCE.convertPage(pageResult, userMap, deptMap, poolDayMap));
  121 + }
  122 +
  123 + private Map<Long, Long> getPoolDayMap(PageResult<CrmCustomerDO> pageResult) {
  124 + Map<Long, Long> poolDayMap = null;
  125 + CrmCustomerPoolConfigDO customerPoolConfig = customerPoolConfigService.getCustomerPoolConfig();
  126 + if (customerPoolConfig != null && customerPoolConfig.getEnabled()) { // 有公海配置的情况
  127 + poolDayMap = convertMap(pageResult.getList(), CrmCustomerDO::getId, item -> {
  128 + long dealExpireDay = 0;
  129 + if (!item.getDealStatus()) { // 检查是否成交
  130 + dealExpireDay = customerPoolConfig.getDealExpireDays() - LocalDateTimeUtils.between(item.getCreateTime());
  131 + }
  132 + long contactExpireDay = customerPoolConfig.getContactExpireDays() - LocalDateTimeUtils.between(item.getContactLastTime());
  133 + return dealExpireDay == 0 ? contactExpireDay : Math.min(dealExpireDay, contactExpireDay);
  134 + });
  135 + }
  136 + return poolDayMap;
  137 + }
  138 +
  139 + @GetMapping(value = "/list-all-simple")
  140 + @Operation(summary = "获取客户精简信息列表", description = "只包含有读权限的客户,主要用于前端的下拉选项")
  141 + public CommonResult<List<CrmCustomerSimpleRespVO>> getSimpleDeptList() {
  142 + CrmCustomerPageReqVO reqVO = new CrmCustomerPageReqVO();
  143 + reqVO.setPageSize(PAGE_SIZE_NONE); // 不分页
  144 + List<CrmCustomerDO> list = customerService.getCustomerPage(reqVO, getLoginUserId()).getList();
  145 + return success(BeanUtils.toBean(list, CrmCustomerSimpleRespVO.class));
123 146 }
124 147  
125 148 @GetMapping("/export-excel")
... ... @@ -131,32 +154,32 @@ public class CrmCustomerController {
131 154 pageVO.setPageSize(PAGE_SIZE_NONE); // 不分页
132 155 List<CrmCustomerDO> list = customerService.getCustomerPage(pageVO, getLoginUserId()).getList();
133 156 // 导出 Excel
134   - List<CrmCustomerExcelVO> datas = CrmCustomerConvert.INSTANCE.convertList02(list);
135   - ExcelUtils.write(response, "客户.xls", "数据", CrmCustomerExcelVO.class, datas);
  157 + List<CrmCustomerRespVO> datas = CrmCustomerConvert.INSTANCE.convertList02(list);
  158 + ExcelUtils.write(response, "客户.xls", "数据", CrmCustomerRespVO.class, datas);
136 159 }
137 160  
138 161 @PutMapping("/transfer")
139 162 @Operation(summary = "转移客户")
140   - @OperateLog(enable = false) // TODO 关闭原有日志记录
141 163 @PreAuthorize("@ss.hasPermission('crm:customer:update')")
142 164 public CommonResult<Boolean> transfer(@Valid @RequestBody CrmCustomerTransferReqVO reqVO) {
143 165 customerService.transferCustomer(reqVO, getLoginUserId());
144 166 return success(true);
145 167 }
146 168  
147   - // TODO @puhui999:是不是接口只要传递 bizId,由 Controller 自己组装出 OperateLogV2PageReqDTO
148 169 @GetMapping("/operate-log-page")
149 170 @Operation(summary = "获得客户操作日志")
  171 + @Parameter(name = "id", description = "客户编号", required = true)
150 172 @PreAuthorize("@ss.hasPermission('crm:customer:query')")
151   - public CommonResult<PageResult<OperateLogV2RespDTO>> getCustomerOperateLog(CrmCustomerOperateLogPageReqVO reqVO) {
152   - reqVO.setPageSize(PAGE_SIZE_NONE); // 不分页
153   - reqVO.setBizType(CRM_CUSTOMER);
154   - return success(operateLogApi.getOperateLogPage(BeanUtils.toBean(reqVO, OperateLogV2PageReqDTO.class)));
  173 + public CommonResult<PageResult<OperateLogV2RespDTO>> getCustomerOperateLog(@RequestParam("id") Long id) {
  174 + OperateLogV2PageReqDTO reqDTO = new OperateLogV2PageReqDTO();
  175 + reqDTO.setPageSize(PAGE_SIZE_NONE); // 不分页
  176 + reqDTO.setBizType(CRM_CUSTOMER_TYPE);
  177 + reqDTO.setBizId(id);
  178 + return success(operateLogApi.getOperateLogPage(reqDTO));
155 179 }
156 180  
157 181 @PutMapping("/lock")
158 182 @Operation(summary = "锁定/解锁客户")
159   - @OperateLog(enable = false) // TODO 关闭原有日志记录
160 183 @PreAuthorize("@ss.hasPermission('crm:customer:update')")
161 184 public CommonResult<Boolean> lockCustomer(@Valid @RequestBody CrmCustomerLockReqVO lockReqVO) {
162 185 customerService.lockCustomer(lockReqVO, getLoginUserId());
... ... @@ -167,7 +190,6 @@ public class CrmCustomerController {
167 190  
168 191 @PutMapping("/put-pool")
169 192 @Operation(summary = "数据放入公海")
170   - @OperateLog(enable = false) // TODO 关闭原有日志记录
171 193 @Parameter(name = "id", description = "客户编号", required = true, example = "1024")
172 194 @PreAuthorize("@ss.hasPermission('crm:customer:update')")
173 195 public CommonResult<Boolean> putCustomerPool(@RequestParam("id") Long id) {
... ... @@ -180,32 +202,16 @@ public class CrmCustomerController {
180 202 @Parameter(name = "ids", description = "编号数组", required = true, example = "1,2,3")
181 203 @PreAuthorize("@ss.hasPermission('crm:customer:receive')")
182 204 public CommonResult<Boolean> receiveCustomer(@RequestParam(value = "ids") List<Long> ids) {
183   - customerService.receiveCustomer(ids, getLoginUserId());
  205 + customerService.receiveCustomer(ids, getLoginUserId(), Boolean.TRUE);
184 206 return success(true);
185 207 }
186 208  
187   - // TODO @puhui999:需要搞个 VO 类
188 209 @PutMapping("/distribute")
189 210 @Operation(summary = "分配公海给对应负责人")
190   - @Parameters({
191   - @Parameter(name = "ids", description = "客户编号数组", required = true, example = "1,2,3"),
192   - @Parameter(name = "ownerUserId", description = "分配的负责人编号", required = true, example = "12345")
193   - })
194 211 @PreAuthorize("@ss.hasPermission('crm:customer:distribute')")
195   - public CommonResult<Boolean> distributeCustomer(@RequestParam(value = "ids") List<Long> ids,
196   - @RequestParam(value = "ownerUserId") Long ownerUserId) {
197   - customerService.receiveCustomer(ids, ownerUserId);
  212 + public CommonResult<Boolean> distributeCustomer(@Valid @RequestBody CrmCustomerDistributeReqVO distributeReqVO) {
  213 + customerService.receiveCustomer(distributeReqVO.getIds(), distributeReqVO.getOwnerUserId(), Boolean.FALSE);
198 214 return success(true);
199 215 }
200 216  
201   - // TODO 芋艿:这个接口要调整下
202   - @GetMapping("/query-all-list")
203   - @Operation(summary = "查询客户列表")
204   - @PreAuthorize("@ss.hasPermission('crm:customer:all')")
205   - public CommonResult<List<CrmCustomerQueryAllRespVO>> queryAll() {
206   - List<CrmCustomerDO> crmCustomerDOList = customerService.getCustomerList();
207   - List<CrmCustomerQueryAllRespVO> data = CrmCustomerConvert.INSTANCE.convertQueryAll(crmCustomerDOList);
208   - return success(data);
209   - }
210   -
211 217 }
... ...
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;
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
5 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6   -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
7 6 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigPageReqVO;
8 7 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigRespVO;
9   -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigUpdateReqVO;
  8 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
10 9 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerLimitConfigConvert;
11 10 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
12 11 import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerLimitConfigService;
... ... @@ -17,12 +16,12 @@ import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
17 16 import io.swagger.v3.oas.annotations.Operation;
18 17 import io.swagger.v3.oas.annotations.Parameter;
19 18 import io.swagger.v3.oas.annotations.tags.Tag;
  19 +import jakarta.annotation.Resource;
  20 +import jakarta.validation.Valid;
20 21 import org.springframework.security.access.prepost.PreAuthorize;
21 22 import org.springframework.validation.annotation.Validated;
22 23 import org.springframework.web.bind.annotation.*;
23 24  
24   -import jakarta.annotation.Resource;
25   -import jakarta.validation.Valid;
26 25 import java.util.Collection;
27 26 import java.util.Map;
28 27  
... ... @@ -43,18 +42,17 @@ public class CrmCustomerLimitConfigController {
43 42 @Resource
44 43 private AdminUserApi adminUserApi;
45 44  
46   - // TODO @puhui999:可以把 vo 改下哈
47 45 @PostMapping("/create")
48 46 @Operation(summary = "创建客户限制配置")
49 47 @PreAuthorize("@ss.hasPermission('crm:customer-limit-config:create')")
50   - public CommonResult<Long> createCustomerLimitConfig(@Valid @RequestBody CrmCustomerLimitConfigCreateReqVO createReqVO) {
  48 + public CommonResult<Long> createCustomerLimitConfig(@Valid @RequestBody CrmCustomerLimitConfigSaveReqVO createReqVO) {
51 49 return success(customerLimitConfigService.createCustomerLimitConfig(createReqVO));
52 50 }
53 51  
54 52 @PutMapping("/update")
55 53 @Operation(summary = "更新客户限制配置")
56 54 @PreAuthorize("@ss.hasPermission('crm:customer-limit-config:update')")
57   - public CommonResult<Boolean> updateCustomerLimitConfig(@Valid @RequestBody CrmCustomerLimitConfigUpdateReqVO updateReqVO) {
  55 + public CommonResult<Boolean> updateCustomerLimitConfig(@Valid @RequestBody CrmCustomerLimitConfigSaveReqVO updateReqVO) {
58 56 customerLimitConfigService.updateCustomerLimitConfig(updateReqVO);
59 57 return success(true);
60 58 }
... ...
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
8 8 import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerPoolConfigService;
9 9 import io.swagger.v3.oas.annotations.Operation;
10 10 import io.swagger.v3.oas.annotations.tags.Tag;
  11 +import jakarta.annotation.Resource;
  12 +import jakarta.validation.Valid;
11 13 import org.springframework.security.access.prepost.PreAuthorize;
12 14 import org.springframework.validation.annotation.Validated;
13 15 import org.springframework.web.bind.annotation.*;
14 16  
15   -import jakarta.annotation.Resource;
16   -import jakarta.validation.Valid;
17   -
18 17 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
19 18  
20 19 @Tag(name = "管理后台 - CRM 客户公海配置")
... ... @@ -26,7 +25,6 @@ public class CrmCustomerPoolConfigController {
26 25 @Resource
27 26 private CrmCustomerPoolConfigService customerPoolConfigService;
28 27  
29   - // TODO @puhui999:可以把 vo 改下哈
30 28 @GetMapping("/get")
31 29 @Operation(summary = "获取客户公海规则设置")
32 30 @PreAuthorize("@ss.hasPermission('crm:customer-pool-config:query')")
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerCreateReqVO.java deleted
1   -package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
2   -
3   -import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.Data;
5   -import lombok.EqualsAndHashCode;
6   -import lombok.ToString;
7   -
8   -import jakarta.validation.constraints.NotNull;
9   -
10   -@Schema(description = "管理后台 - CRM 客户创建 Request VO")
11   -@Data
12   -@EqualsAndHashCode(callSuper = true)
13   -@ToString(callSuper = true)
14   -public class CrmCustomerCreateReqVO extends CrmCustomerBaseVO {
15   -
16   - @Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
17   - @NotNull(message = "负责人不能为空")
18   - private Long ownerUserId;
19   -
20   -}
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerDistributeReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import jakarta.validation.constraints.NotNull;
  5 +import lombok.Data;
  6 +
  7 +import java.util.List;
  8 +
  9 +@Schema(description = "管理后台 - CRM 客户分配公海给对应负责人 Request VO")
  10 +@Data
  11 +public class CrmCustomerDistributeReqVO {
  12 +
  13 + @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1024]")
  14 + @NotNull(message = "客户编号不能为空")
  15 + private List<Long> ids;
  16 +
  17 + @Schema(description = "负责人", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
  18 + @NotNull(message = "负责人不能为空")
  19 + private Long ownerUserId;
  20 +
  21 +}
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerExcelVO.java deleted
1   -package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
2   -
3   -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
4   -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
5   -import cn.iocoder.yudao.module.infra.enums.DictTypeConstants;
6   -import com.alibaba.excel.annotation.ExcelProperty;
7   -import io.swagger.v3.oas.annotations.media.Schema;
8   -import lombok.Data;
9   -
10   -import java.time.LocalDateTime;
11   -
12   -// TODO 芋艿:导出最后做,等基本确认的差不多之后;
13   -/**
14   - * CRM 客户 Excel VO
15   - *
16   - * @author Wanwan
17   - */
18   -@Data
19   -public class CrmCustomerExcelVO {
20   -
21   - @ExcelProperty("编号")
22   - private Long id;
23   -
24   - @ExcelProperty("客户名称")
25   - private String name;
26   -
27   - @ExcelProperty(value = "跟进状态", converter = DictConvert.class)
28   - @DictFormat(DictTypeConstants.BOOLEAN_STRING)
29   - private Boolean followUpStatus;
30   -
31   - @ExcelProperty(value = "锁定状态", converter = DictConvert.class)
32   - @DictFormat(DictTypeConstants.BOOLEAN_STRING)
33   - private Boolean lockStatus;
34   -
35   - @ExcelProperty(value = "成交状态", converter = DictConvert.class)
36   - @DictFormat(DictTypeConstants.BOOLEAN_STRING)
37   - private Boolean dealStatus;
38   -
39   - @ExcelProperty(value = "所属行业", converter = DictConvert.class)
40   - @DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_INDUSTRY)
41   - private Integer industryId;
42   -
43   - @ExcelProperty(value = "客户等级", converter = DictConvert.class)
44   - @DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_LEVEL)
45   - private Integer level;
46   -
47   - @ExcelProperty(value = "客户来源", converter = DictConvert.class)
48   - @DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_SOURCE)
49   - private Integer source;
50   -
51   - @ExcelProperty("手机")
52   - private String mobile;
53   -
54   - @ExcelProperty("电话")
55   - private String telephone;
56   -
57   - @ExcelProperty("网址")
58   - private String website;
59   -
60   - @ExcelProperty("QQ")
61   - private String qq;
62   -
63   - @ExcelProperty("wechat")
64   - private String wechat;
65   -
66   - @ExcelProperty("email")
67   - private String email;
68   -
69   - @ExcelProperty("客户描述")
70   - private String description;
71   -
72   - @ExcelProperty("备注")
73   - private String remark;
74   -
75   - @ExcelProperty("负责人的用户编号")
76   - private Long ownerUserId;
77   -
78   - @ExcelProperty("地区编号")
79   - private Integer areaId;
80   -
81   - @ExcelProperty("详细地址")
82   - private String detailAddress;
83   -
84   - @ExcelProperty("最后跟进时间")
85   - private LocalDateTime contactLastTime;
86   -
87   - @ExcelProperty("下次联系时间")
88   - private LocalDateTime contactNextTime;
89   -
90   - @ExcelProperty("创建时间")
91   - private LocalDateTime createTime;
92   -
93   -}
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerOperateLogPageReqVO.java deleted
1   -package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
2   -
3   -import cn.iocoder.yudao.framework.common.pojo.PageParam;
4   -import io.swagger.v3.oas.annotations.media.Schema;
5   -import lombok.Data;
6   -
7   -@Schema(description = "管理后台 - crm 客户操作日志分页 Request VO")
8   -@Data
9   -public class CrmCustomerOperateLogPageReqVO extends PageParam {
10   -
11   - @Schema(description = "模块数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
12   - private Long bizId;
13   -
14   - @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
15   - private Long userId;
16   -
17   - @Schema(description = "模块类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
18   - private String bizType;
19   -
20   -}
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerRespVO.java
1 1 package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
2 2  
  3 +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
  4 +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
  5 +import cn.iocoder.yudao.module.infra.enums.DictTypeConstants;
  6 +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
  7 +import com.alibaba.excel.annotation.ExcelProperty;
3 8 import io.swagger.v3.oas.annotations.media.Schema;
4 9 import lombok.Data;
5   -import lombok.EqualsAndHashCode;
6   -import lombok.ToString;
7 10 import org.springframework.format.annotation.DateTimeFormat;
8 11  
9 12 import java.time.LocalDateTime;
... ... @@ -12,45 +15,124 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
12 15  
13 16 @Schema(description = "管理后台 - CRM 客户 Response VO")
14 17 @Data
15   -@EqualsAndHashCode(callSuper = true)
16   -@ToString(callSuper = true)
17   -public class CrmCustomerRespVO extends CrmCustomerBaseVO {
  18 +@ExcelIgnoreUnannotated
  19 +public class CrmCustomerRespVO {
18 20  
19 21 @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
  22 + @ExcelProperty("编号")
20 23 private Long id;
21 24  
22   - @Schema(description = "跟进状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  25 + @Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
  26 + @ExcelProperty("客户名称")
  27 + private String name;
  28 +
  29 + @Schema(description = "跟进状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
  30 + @ExcelProperty(value = "跟进状态", converter = DictConvert.class)
  31 + @DictFormat(DictTypeConstants.BOOLEAN_STRING)
23 32 private Boolean followUpStatus;
24 33  
25   - @Schema(description = "锁定状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  34 + @Schema(description = "锁定状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
  35 + @ExcelProperty(value = "锁定状态", converter = DictConvert.class)
  36 + @DictFormat(DictTypeConstants.BOOLEAN_STRING)
26 37 private Boolean lockStatus;
27 38  
28   - @Schema(description = "成交状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  39 + @Schema(description = "成交状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
  40 + @ExcelProperty(value = "成交状态", converter = DictConvert.class)
  41 + @DictFormat(DictTypeConstants.BOOLEAN_STRING)
29 42 private Boolean dealStatus;
30 43  
  44 + @Schema(description = "所属行业", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
  45 + @ExcelProperty(value = "所属行业", converter = DictConvert.class)
  46 + @DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_INDUSTRY)
  47 + private Integer industryId;
  48 +
  49 + @Schema(description = "客户等级", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
  50 + @ExcelProperty(value = "客户等级", converter = DictConvert.class)
  51 + @DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_LEVEL)
  52 + private Integer level;
  53 +
  54 + @Schema(description = "客户来源", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
  55 + @ExcelProperty(value = "客户来源", converter = DictConvert.class)
  56 + @DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_SOURCE)
  57 + private Integer source;
  58 +
  59 + @Schema(description = "负责人的用户编号", example = "25682")
  60 + @ExcelProperty("手机")
  61 + private String mobile;
  62 +
  63 + @Schema(description = "负责人的用户编号", example = "25682")
  64 + @ExcelProperty("电话")
  65 + private String telephone;
  66 +
  67 + @Schema(description = "负责人的用户编号", example = "25682")
  68 + @ExcelProperty("网址")
  69 + private String website;
  70 +
  71 + @Schema(description = "负责人的用户编号", example = "25682")
  72 + @ExcelProperty("QQ")
  73 + private String qq;
  74 +
  75 + @Schema(description = "负责人的用户编号", example = "25682")
  76 + @ExcelProperty("wechat")
  77 + private String wechat;
  78 +
31 79 @Schema(description = "负责人的用户编号", example = "25682")
  80 + @ExcelProperty("email")
  81 + private String email;
  82 +
  83 + @Schema(description = "负责人的用户编号", example = "25682")
  84 + @ExcelProperty("客户描述")
  85 + private String description;
  86 +
  87 + @Schema(description = "负责人的用户编号", example = "25682")
  88 + @ExcelProperty("备注")
  89 + private String remark;
  90 +
  91 + @Schema(description = "负责人的用户编号", example = "25682")
  92 + @ExcelProperty("负责人的用户编号")
32 93 private Long ownerUserId;
33 94 @Schema(description = "负责人名字", example = "25682")
  95 + @ExcelProperty("负责人名字")
34 96 private String ownerUserName;
35 97 @Schema(description = "负责人部门")
  98 + @ExcelProperty("负责人部门")
36 99 private String ownerUserDeptName;
37 100  
  101 + @Schema(description = "地区编号", example = "1024")
  102 + @ExcelProperty("地区编号")
  103 + private Integer areaId;
38 104 @Schema(description = "地区名称", example = "北京市")
  105 + @ExcelProperty("地区名称")
39 106 private String areaName;
  107 + @Schema(description = "详细地址", example = "北京市成华大道")
  108 + @ExcelProperty("详细地址")
  109 + private String detailAddress;
40 110  
41 111 @Schema(description = "最后跟进时间")
  112 + @ExcelProperty("最后跟进时间")
42 113 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
43 114 private LocalDateTime contactLastTime;
44 115  
  116 + @Schema(description = "下次联系时间")
  117 + @ExcelProperty("下次联系时间")
  118 + private LocalDateTime contactNextTime;
  119 +
45 120 @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  121 + @ExcelProperty("创建时间")
46 122 private LocalDateTime createTime;
47 123  
48 124 @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
  125 + @ExcelProperty("更新时间")
49 126 private LocalDateTime updateTime;
50 127  
51   - @Schema(description = "创建人")
  128 + @Schema(description = "创建人", example = "1024")
  129 + @ExcelProperty("创建人")
52 130 private String creator;
53   - @Schema(description = "创建人名字")
  131 + @Schema(description = "创建人名字", example = "芋道源码")
  132 + @ExcelProperty("创建人名字")
54 133 private String creatorName;
55 134  
  135 + @Schema(description = "距离加入公海时间", example = "1")
  136 + private Long poolDay;
  137 +
56 138 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerBaseVO.java renamed to 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;
21 21 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
22 22 import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_INDUSTRY;
23 23  
24   -/**
25   - * 客户 Base VO,提供给添加、修改、详细的子 VO 使用
26   - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
27   - */
  24 +@Schema(description = "管理后台 - CRM 客户新增/修改 Request VO")
28 25 @Data
29   -public class CrmCustomerBaseVO {
  26 +public class CrmCustomerSaveReqVO {
  27 +
  28 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
  29 + private Long id;
30 30  
31 31 @Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
32 32 @DiffLogField(name = "客户名称")
... ... @@ -99,4 +99,7 @@ public class CrmCustomerBaseVO {
99 99 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
100 100 private LocalDateTime contactNextTime;
101 101  
  102 + @Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
  103 + private Long ownerUserId;
  104 +
102 105 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerQueryAllRespVO.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerSimpleRespVO.java
1 1 package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.AllArgsConstructor;
4 5 import lombok.Data;
  6 +import lombok.NoArgsConstructor;
5 7  
6   -// TODO 芋艿:这块要统一下;
7   -@Schema(description = "管理后台 - CRM 全部客户 Response VO")
  8 +@Schema(description = "管理后台 - 客户精简信息 Response VO")
8 9 @Data
9   -public class CrmCustomerQueryAllRespVO{
  10 +@NoArgsConstructor
  11 +@AllArgsConstructor
  12 +public class CrmCustomerSimpleRespVO {
10 13  
11   - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
  14 + @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
12 15 private Long id;
13 16  
14   - @Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
  17 + @Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
15 18 private String name;
16 19  
17 20 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmCustomerUpdateReqVO.java deleted
1   -package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
2   -
3   -import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.Data;
5   -import lombok.EqualsAndHashCode;
6   -import lombok.ToString;
7   -
8   -import jakarta.validation.constraints.NotNull;
9   -
10   -@Schema(description = "管理后台 - CRM 客户更新 Request VO")
11   -@Data
12   -@EqualsAndHashCode(callSuper = true)
13   -@ToString(callSuper = true)
14   -public class CrmCustomerUpdateReqVO extends CrmCustomerBaseVO {
15   -
16   - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13563")
17   - @NotNull(message = "编号不能为空")
18   - private Long id;
19   -
20   -}
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/limitconfig/CrmCustomerLimitConfigCreateReqVO.java deleted
1   -package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig;
2   -
3   -import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.Data;
5   -import lombok.EqualsAndHashCode;
6   -import lombok.ToString;
7   -
8   -@Schema(description = "管理后台 - 客户限制配置创建 Request VO")
9   -@Data
10   -@EqualsAndHashCode(callSuper = true)
11   -@ToString(callSuper = true)
12   -public class CrmCustomerLimitConfigCreateReqVO extends CrmCustomerLimitConfigBaseVO {
13   -
14   -}
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;
3 3 import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
4 4 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
5 5 import io.swagger.v3.oas.annotations.media.Schema;
  6 +import jakarta.validation.constraints.NotNull;
6 7 import lombok.Data;
7   -import lombok.EqualsAndHashCode;
8   -import lombok.ToString;
9 8  
10 9 import java.time.LocalDateTime;
11 10 import java.util.List;
12 11  
13 12 @Schema(description = "管理后台 - 客户限制配置 Response VO")
14 13 @Data
15   -@EqualsAndHashCode(callSuper = true)
16   -@ToString(callSuper = true)
17   -public class CrmCustomerLimitConfigRespVO extends CrmCustomerLimitConfigBaseVO {
  14 +public class CrmCustomerLimitConfigRespVO {
18 15  
19 16 @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27930")
20 17 private Long id;
21 18  
  19 + @Schema(description = "规则类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  20 + @NotNull(message = "规则类型不能为空")
  21 + private Integer type;
  22 +
  23 + @Schema(description = "规则适用人群")
  24 + private List<Long> userIds;
  25 +
  26 + @Schema(description = "规则适用部门")
  27 + private List<Long> deptIds;
  28 +
  29 + @Schema(description = "数量上限", requiredMode = Schema.RequiredMode.REQUIRED, example = "28384")
  30 + @NotNull(message = "数量上限不能为空")
  31 + private Integer maxCount;
  32 +
  33 + @Schema(description = "成交客户是否占有拥有客户数(当 type = 1 时)")
  34 + private Boolean dealCountEnabled;
  35 +
22 36 @Schema(description = "规则适用人群名称")
23 37 private List<AdminUserRespDTO> users;
24 38  
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/limitconfig/CrmCustomerLimitConfigBaseVO.java renamed to yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/limitconfig/CrmCustomerLimitConfigSaveReqVO.java
1 1 package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig;
2 2  
  3 +import com.mzt.logapi.starter.annotation.DiffLogField;
3 4 import io.swagger.v3.oas.annotations.media.Schema;
  5 +import jakarta.validation.constraints.NotNull;
4 6 import lombok.Data;
5 7  
6   -import jakarta.validation.constraints.NotNull;
7 8 import java.util.List;
8 9  
9   -/**
10   - * 客户限制配置 Base VO,提供给添加、修改、详细的子 VO 使用
11   - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
12   - */
  10 +@Schema(description = "管理后台 - 客户限制配置创建/更新 Request VO")
13 11 @Data
14   -public class CrmCustomerLimitConfigBaseVO {
  12 +public class CrmCustomerLimitConfigSaveReqVO {
  13 +
  14 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27930")
  15 + private Long id;
15 16  
16 17 @Schema(description = "规则类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  18 + @DiffLogField(name = "规则类型")
17 19 @NotNull(message = "规则类型不能为空")
18 20 private Integer type;
19 21  
20 22 @Schema(description = "规则适用人群")
  23 + @DiffLogField(name = "规则适用人群", function = "getAdminUserById")
21 24 private List<Long> userIds;
22 25  
23 26 @Schema(description = "规则适用部门")
  27 + @DiffLogField(name = "规则适用部门", function = "getDeptById")
24 28 private List<Long> deptIds;
25 29  
26 30 @Schema(description = "数量上限", requiredMode = Schema.RequiredMode.REQUIRED, example = "28384")
  31 + @DiffLogField(name = "数量上限")
27 32 @NotNull(message = "数量上限不能为空")
28 33 private Integer maxCount;
29 34  
30 35 @Schema(description = "成交客户是否占有拥有客户数(当 type = 1 时)")
  36 + @DiffLogField(name = "成交客户是否占有拥有客户数")
31 37 private Boolean dealCountEnabled;
32 38  
33 39 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/limitconfig/CrmCustomerLimitConfigUpdateReqVO.java deleted
1   -package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig;
2   -
3   -import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.Data;
5   -import lombok.EqualsAndHashCode;
6   -import lombok.ToString;
7   -
8   -import jakarta.validation.constraints.NotNull;
9   -
10   -@Schema(description = "管理后台 - 客户限制配置更新 Request VO")
11   -@Data
12   -@EqualsAndHashCode(callSuper = true)
13   -@ToString(callSuper = true)
14   -public class CrmCustomerLimitConfigUpdateReqVO extends CrmCustomerLimitConfigBaseVO {
15   -
16   - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27930")
17   - @NotNull(message = "编号不能为空")
18   - private Long id;
19   -
20   -}
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/poolconfig/CrmCustomerPoolConfigBaseVO.java deleted
1   -package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig;
2   -
3   -import io.swagger.v3.oas.annotations.media.Schema;
4   -import lombok.Data;
5   -
6   -import jakarta.validation.constraints.NotNull;
7   -
8   -/**
9   - * 客户公海配置 Base VO,提供给添加、修改、详细的子 VO 使用
10   - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
11   - */
12   -@Data
13   -public class CrmCustomerPoolConfigBaseVO {
14   -
15   - @Schema(description = "是否启用客户公海", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
16   - @NotNull(message = "是否启用客户公海不能为空")
17   - private Boolean enabled;
18   -
19   - @Schema(description = "未跟进放入公海天数", example = "2")
20   - private Integer contactExpireDays;
21   -
22   - @Schema(description = "未成交放入公海天数", example = "2")
23   - private Integer dealExpireDays;
24   -
25   - @Schema(description = "是否开启提前提醒", example = "true")
26   - private Boolean notifyEnabled;
27   -
28   - @Schema(description = "提前提醒天数", example = "2")
29   - private Integer notifyDays;
30   -
31   -}
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/poolconfig/CrmCustomerPoolConfigRespVO.java
1 1 package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
  4 +import jakarta.validation.constraints.NotNull;
4 5 import lombok.Data;
5   -import lombok.EqualsAndHashCode;
6   -import lombok.ToString;
7 6  
8 7 @Schema(description = "管理后台 - CRM 客户公海规则 Response VO")
9 8 @Data
10   -@EqualsAndHashCode(callSuper = true)
11   -@ToString(callSuper = true)
12   -public class CrmCustomerPoolConfigRespVO extends CrmCustomerPoolConfigBaseVO {
  9 +public class CrmCustomerPoolConfigRespVO {
  10 +
  11 + @Schema(description = "是否启用客户公海", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  12 + @NotNull(message = "是否启用客户公海不能为空")
  13 + private Boolean enabled;
  14 +
  15 + @Schema(description = "未跟进放入公海天数", example = "2")
  16 + private Integer contactExpireDays;
  17 +
  18 + @Schema(description = "未成交放入公海天数", example = "2")
  19 + private Integer dealExpireDays;
  20 +
  21 + @Schema(description = "是否开启提前提醒", example = "true")
  22 + private Boolean notifyEnabled;
  23 +
  24 + @Schema(description = "提前提醒天数", example = "2")
  25 + private Integer notifyDays;
13 26  
14 27 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/poolconfig/CrmCustomerPoolConfigSaveReqVO.java
1 1 package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig;
2 2  
3 3 import cn.hutool.core.util.BooleanUtil;
4   -import cn.hutool.core.util.ObjectUtil;
  4 +import com.fasterxml.jackson.annotation.JsonIgnore;
  5 +import com.mzt.logapi.starter.annotation.DiffLogField;
5 6 import io.swagger.v3.oas.annotations.media.Schema;
  7 +import jakarta.validation.constraints.AssertTrue;
  8 +import jakarta.validation.constraints.NotNull;
6 9 import lombok.Data;
7   -import lombok.EqualsAndHashCode;
8   -import lombok.ToString;
9 10  
10   -import jakarta.validation.constraints.AssertTrue;
11 11 import java.util.Objects;
12 12  
13   -@Schema(description = "管理后台 - CRM 客户公海配置的保存 Request VO")
  13 +@Schema(description = "管理后台 - CRM 客户公海配置的创建/更新 Request VO")
14 14 @Data
15   -@EqualsAndHashCode(callSuper = true)
16   -@ToString(callSuper = true)
17   -public class CrmCustomerPoolConfigSaveReqVO extends CrmCustomerPoolConfigBaseVO {
18   -
19   - // TODO @puhui999:AssertTrue 必须 is 开头哈;注意需要 json 忽略下,避免被序列化;
20   - @AssertTrue(message = "客户公海规则设置不正确")
21   - // TODO @puhui999:这个方法,是不是拆成 2 个,一个校验 contactExpireDays、一个校验 dealExpireDays;
22   - public boolean poolEnableValid() {
  15 +public class CrmCustomerPoolConfigSaveReqVO {
  16 +
  17 + @Schema(description = "是否启用客户公海", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
  18 + @DiffLogField(name = "是否启用客户公海")
  19 + @NotNull(message = "是否启用客户公海不能为空")
  20 + private Boolean enabled;
  21 +
  22 + @Schema(description = "未跟进放入公海天数", example = "2")
  23 + @DiffLogField(name = "未跟进放入公海天数")
  24 + private Integer contactExpireDays;
  25 +
  26 + @Schema(description = "未成交放入公海天数", example = "2")
  27 + @DiffLogField(name = "未成交放入公海天数")
  28 + private Integer dealExpireDays;
  29 +
  30 + @Schema(description = "是否开启提前提醒", example = "true")
  31 + @DiffLogField(name = "是否开启提前提醒")
  32 + private Boolean notifyEnabled;
  33 +
  34 + @Schema(description = "提前提醒天数", example = "2")
  35 + @DiffLogField(name = "提前提醒天数")
  36 + private Integer notifyDays;
  37 +
  38 + @AssertTrue(message = "未成交放入公海天数不能为空")
  39 + @JsonIgnore
  40 + public boolean isDealExpireDaysValid() {
  41 + if (!BooleanUtil.isTrue(getEnabled())) {
  42 + return true;
  43 + }
  44 + return Objects.nonNull(getDealExpireDays());
  45 + }
  46 +
  47 + @AssertTrue(message = "未跟进放入公海天数不能为空")
  48 + @JsonIgnore
  49 + public boolean isContactExpireDaysValid() {
23 50 if (!BooleanUtil.isTrue(getEnabled())) {
24 51 return true;
25 52 }
26   - return ObjectUtil.isAllNotEmpty(getContactExpireDays(), getDealExpireDays());
  53 + return Objects.nonNull(getContactExpireDays());
27 54 }
28 55  
29   - @AssertTrue(message = "客户公海规则设置不正确")
30   - // TODO @puhui999:这个方法,是不是改成 isNotifyDaysValid() 更好点?本质校验的是 notifyDays 是否为空
31   - public boolean notifyEnableValid() {
  56 + @AssertTrue(message = "提前提醒天数不能为空")
  57 + @JsonIgnore
  58 + public boolean isNotifyDaysValid() {
32 59 if (!BooleanUtil.isTrue(getNotifyEnabled())) {
33 60 return true;
34 61 }
... ...
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 {
103 103 // 拼接数据
104 104 List<AdminUserRespDTO> userList = adminUserApi.getUserList(convertSet(permission, CrmPermissionDO::getUserId));
105 105 Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userList, AdminUserRespDTO::getDeptId));
106   - // TODO @puhui999:可能 postIds 为空的时候,会导致报错,看看怎么 fix 下
107 106 Set<Long> postIds = CollectionUtils.convertSetByFlatMap(userList, AdminUserRespDTO::getPostIds, Collection::stream);
108 107 Map<Long, PostRespDTO> postMap = postApi.getPostMap(postIds);
109 108 return success(CrmPermissionConvert.INSTANCE.convert(permission, userList, deptMap, postMap));
... ...
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;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 4 import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
5   -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
  5 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerRespVO;
  6 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
  7 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
6 8 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig.CrmCustomerPoolConfigRespVO;
7 9 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig.CrmCustomerPoolConfigSaveReqVO;
8 10 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
... ... @@ -29,18 +31,16 @@ public interface CrmCustomerConvert {
29 31  
30 32 CrmCustomerConvert INSTANCE = Mappers.getMapper(CrmCustomerConvert.class);
31 33  
32   - CrmCustomerDO convert(CrmCustomerCreateReqVO bean);
33   -
34   - CrmCustomerDO convert(CrmCustomerUpdateReqVO bean);
  34 + CrmCustomerDO convert(CrmCustomerSaveReqVO bean);
35 35  
36 36 CrmCustomerRespVO convert(CrmCustomerDO bean);
37 37  
38 38 /**
39 39 * 设置用户信息
40 40 *
41   - * @param customer CRM 客户 Response VO
42   - * @param userMap 用户信息 map
43   - * @param deptMap 用户部门信息 map
  41 + * @param customer CRM 客户 Response VO
  42 + * @param userMap 用户信息 map
  43 + * @param deptMap 用户部门信息 map
44 44 */
45 45 static void setUserInfo(CrmCustomerRespVO customer, Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) {
46 46 customer.setAreaName(AreaUtils.format(customer.getAreaId()));
... ... @@ -51,7 +51,7 @@ public interface CrmCustomerConvert {
51 51 findAndThen(userMap, Long.parseLong(customer.getCreator()), user -> customer.setCreatorName(user.getNickname()));
52 52 }
53 53  
54   - List<CrmCustomerExcelVO> convertList02(List<CrmCustomerDO> list);
  54 + List<CrmCustomerRespVO> convertList02(List<CrmCustomerDO> list);
55 55  
56 56 @Mapping(target = "bizId", source = "reqVO.id")
57 57 CrmPermissionTransferReqBO convert(CrmCustomerTransferReqVO reqVO, Long userId);
... ... @@ -66,9 +66,12 @@ public interface CrmCustomerConvert {
66 66 }
67 67  
68 68 default PageResult<CrmCustomerRespVO> convertPage(PageResult<CrmCustomerDO> pageResult, Map<Long, AdminUserRespDTO> userMap,
69   - Map<Long, DeptRespDTO> deptMap) {
  69 + Map<Long, DeptRespDTO> deptMap, Map<Long, Long> poolDayMap) {
70 70 PageResult<CrmCustomerRespVO> result = convertPage(pageResult);
71   - result.getList().forEach(item -> setUserInfo(item, userMap, deptMap));
  71 + result.getList().forEach(item -> {
  72 + setUserInfo(item, userMap, deptMap);
  73 + findAndThen(poolDayMap, item.getId(), item::setPoolDay);
  74 + });
72 75 return result;
73 76 }
74 77  
... ... @@ -76,6 +79,4 @@ public interface CrmCustomerConvert {
76 79  
77 80 CrmCustomerPoolConfigDO convert(CrmCustomerPoolConfigSaveReqVO updateReqVO);
78 81  
79   - List<CrmCustomerQueryAllRespVO> convertQueryAll(List<CrmCustomerDO> crmCustomerDO);
80   -
81 82 }
... ...
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;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 4 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
5   -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
6 5 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigRespVO;
7   -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigUpdateReqVO;
  6 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
8 7 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
9 8 import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
10 9 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
... ... @@ -24,9 +23,7 @@ public interface CrmCustomerLimitConfigConvert {
24 23  
25 24 CrmCustomerLimitConfigConvert INSTANCE = Mappers.getMapper(CrmCustomerLimitConfigConvert.class);
26 25  
27   - CrmCustomerLimitConfigDO convert(CrmCustomerLimitConfigCreateReqVO bean);
28   -
29   - CrmCustomerLimitConfigDO convert(CrmCustomerLimitConfigUpdateReqVO bean);
  26 + CrmCustomerLimitConfigDO convert(CrmCustomerLimitConfigSaveReqVO bean);
30 27  
31 28 CrmCustomerLimitConfigRespVO convert(CrmCustomerLimitConfigDO bean);
32 29  
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/permission/CrmPermissionConvert.java
1 1 package cn.iocoder.yudao.module.crm.convert.permission;
2 2  
  3 +import cn.hutool.core.collection.CollUtil;
3 4 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
4 5 import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
5 6 import cn.iocoder.yudao.module.crm.controller.admin.permission.vo.CrmPermissionCreateReqVO;
... ... @@ -15,6 +16,7 @@ import com.google.common.collect.Multimaps;
15 16 import org.mapstruct.Mapper;
16 17 import org.mapstruct.factory.Mappers;
17 18  
  19 +import java.util.Collections;
18 20 import java.util.List;
19 21 import java.util.Map;
20 22  
... ... @@ -50,6 +52,10 @@ public interface CrmPermissionConvert {
50 52 item.setDeptName(deptRespDTO.getName());
51 53 });
52 54 List<PostRespDTO> postRespList = MapUtils.getList(Multimaps.forMap(postMap), user.getPostIds());
  55 + if (CollUtil.isEmpty(postRespList)) {
  56 + item.setPostNames(Collections.emptySet());
  57 + return;
  58 + }
53 59 item.setPostNames(CollectionUtils.convertSet(postRespList, PostRespDTO::getName));
54 60 });
55 61 return item;
... ...
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;
5 5 import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
6 6 import org.apache.ibatis.annotations.Mapper;
7 7  
  8 +import java.util.Collection;
8 9 import java.util.List;
9 10  
10 11 /**
... ... @@ -28,6 +29,12 @@ public interface CrmPermissionMapper extends BaseMapperX&lt;CrmPermissionDO&gt; {
28 29 .eq(CrmPermissionDO::getBizId, bizId));
29 30 }
30 31  
  32 + default List<CrmPermissionDO> selectByBizTypeAndBizIds(Integer bizType, Collection<Long> bizIds) {
  33 + return selectList(new LambdaQueryWrapperX<CrmPermissionDO>()
  34 + .eq(CrmPermissionDO::getBizType, bizType)
  35 + .in(CrmPermissionDO::getBizId, bizIds));
  36 + }
  37 +
31 38 default List<CrmPermissionDO> selectListByBizTypeAndUserId(Integer bizType, Long userId) {
32 39 return selectList(new LambdaQueryWrapperX<CrmPermissionDO>()
33 40 .eq(CrmPermissionDO::getBizType, bizType)
... ...
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;
18 18 import org.aspectj.lang.annotation.Before;
19 19 import org.springframework.stereotype.Component;
20 20  
21   -import java.util.ArrayList;
22   -import java.util.List;
23   -import java.util.Map;
  21 +import java.util.*;
24 22  
25 23 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
26   -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.anyMatch;
  24 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
27 25 import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
28 26 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CRM_PERMISSION_DENIED;
29 27  
... ... @@ -46,16 +44,29 @@ public class CrmPermissionAspect {
46 44 Map<String, Object> expressionValues = parseExpressions(joinPoint, crmPermission);
47 45 Integer bizType = StrUtil.isEmpty(crmPermission.bizTypeValue()) ?
48 46 crmPermission.bizType()[0].getType() : (Integer) expressionValues.get(crmPermission.bizTypeValue()); // 模块类型
49   - Long bizId = (Long) expressionValues.get(crmPermission.bizId()); // 模块数据编号
  47 + // 处理兼容多个 bizId 的情况
  48 + Object object = expressionValues.get(crmPermission.bizId());// 模块数据编号
  49 + Set<Long> bizIds = new HashSet<>();
  50 + if (object instanceof Collection<?>) {
  51 + bizIds.addAll(convertSet((Collection<?>) object, item -> Long.parseLong(item.toString())));
  52 + } else {
  53 + bizIds.add(Long.parseLong(object.toString()));
  54 + }
50 55 Integer permissionLevel = crmPermission.level().getLevel(); // 需要的权限级别
  56 + List<CrmPermissionDO> permissionList = crmPermissionService.getPermissionListByBiz(bizType, bizIds);
  57 + Map<Long, List<CrmPermissionDO>> multiMap = convertMultiMap(permissionList, CrmPermissionDO::getBizId);
  58 + bizIds.forEach(bizId -> {
  59 + validatePermission(bizType, multiMap.get(bizId), permissionLevel);
  60 + });
  61 + }
51 62  
52   - // 1.1 如果是超级管理员则直接通过
  63 + private void validatePermission(Integer bizType, List<CrmPermissionDO> bizPermissions, Integer permissionLevel) {
  64 + // 1. 如果是超级管理员则直接通过
53 65 if (CrmPermissionUtils.isCrmAdmin()) {
54 66 return;
55 67 }
56   - // 1.2 获取数据权限
57   - List<CrmPermissionDO> bizPermissions = crmPermissionService.getPermissionListByBiz(bizType, bizId);
58   - if (CollUtil.isEmpty(bizPermissions)) { // 没有数据权限的情况
  68 + // 1.1 没有数据权限的情况
  69 + if (CollUtil.isEmpty(bizPermissions)) {
59 70 // 公海数据如果没有团队成员大家也因该有读权限才对
60 71 if (CrmPermissionLevelEnum.isRead(permissionLevel)) {
61 72 return;
... ... @@ -63,7 +74,7 @@ public class CrmPermissionAspect {
63 74  
64 75 // 没有数据权限的情况下超出了读权限直接报错,避免后面校验空指针
65 76 throw exception(CRM_PERMISSION_DENIED, CrmBizTypeEnum.getNameByType(bizType));
66   - } else { // 有数据权限但是没有负责人的情况
  77 + } else { // 1.2 有数据权限但是没有负责人的情况
67 78 if (!anyMatch(bizPermissions, item -> CrmPermissionLevelEnum.isOwner(item.getLevel()))) {
68 79 if (CrmPermissionLevelEnum.isRead(permissionLevel)) {
69 80 return;
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerLimitConfigService.java
1 1 package cn.iocoder.yudao.module.crm.service.customer;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
5 4 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigPageReqVO;
6   -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigUpdateReqVO;
  5 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
7 6 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
8 7 import jakarta.validation.Valid;
9 8  
... ... @@ -22,14 +21,14 @@ public interface CrmCustomerLimitConfigService {
22 21 * @param createReqVO 创建信息
23 22 * @return 编号
24 23 */
25   - Long createCustomerLimitConfig(@Valid CrmCustomerLimitConfigCreateReqVO createReqVO);
  24 + Long createCustomerLimitConfig(@Valid CrmCustomerLimitConfigSaveReqVO createReqVO);
26 25  
27 26 /**
28 27 * 更新客户限制配置
29 28 *
30 29 * @param updateReqVO 更新信息
31 30 */
32   - void updateCustomerLimitConfig(@Valid CrmCustomerLimitConfigUpdateReqVO updateReqVO);
  31 + void updateCustomerLimitConfig(@Valid CrmCustomerLimitConfigSaveReqVO updateReqVO);
33 32  
34 33 /**
35 34 * 删除客户限制配置
... ... @@ -57,7 +56,7 @@ public interface CrmCustomerLimitConfigService {
57 56 /**
58 57 * 查询用户对应的配置列表
59 58 *
60   - * @param type 类型
  59 + * @param type 类型
61 60 * @param userId 用户类型
62 61 */
63 62 List<CrmCustomerLimitConfigDO> getCustomerLimitConfigListByUserId(Integer type, Long userId);
... ...
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;
2 2  
3 3 import cn.hutool.core.lang.Assert;
4 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5   -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
  5 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 6 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigPageReqVO;
7   -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigUpdateReqVO;
  7 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
8 8 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerLimitConfigConvert;
9 9 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
10 10 import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerLimitConfigMapper;
  11 +import cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum;
11 12 import cn.iocoder.yudao.module.system.api.dept.DeptApi;
12 13 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
13 14 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
  15 +import com.mzt.logapi.context.LogRecordContext;
  16 +import com.mzt.logapi.service.impl.DiffParseFunction;
  17 +import com.mzt.logapi.starter.annotation.LogRecord;
  18 +import jakarta.annotation.Resource;
14 19 import org.springframework.stereotype.Service;
15 20 import org.springframework.validation.annotation.Validated;
16 21  
17   -import jakarta.annotation.Resource;
18   -
19 22 import java.util.Collection;
20 23 import java.util.List;
21 24  
22 25 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
23 26 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_LIMIT_CONFIG_NOT_EXISTS;
  27 +import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
24 28  
25 29 /**
26 30 * 客户限制配置 Service 实现类
... ... @@ -40,34 +44,44 @@ public class CrmCustomerLimitConfigServiceImpl implements CrmCustomerLimitConfig
40 44 private AdminUserApi adminUserApi;
41 45  
42 46 @Override
43   - // TODO @puhui999:操作日志
44   - public Long createCustomerLimitConfig(CrmCustomerLimitConfigCreateReqVO createReqVO) {
  47 + @LogRecord(type = CRM_CUSTOMER_LIMIT_CONFIG_TYPE, subType = CRM_CUSTOMER_LIMIT_CONFIG_CREATE_SUB_TYPE, bizNo = "{{#limitId}}", success = CRM_CUSTOMER_LIMIT_CONFIG_CREATE_SUCCESS)
  48 + public Long createCustomerLimitConfig(CrmCustomerLimitConfigSaveReqVO createReqVO) {
45 49 validateUserAndDept(createReqVO.getUserIds(), createReqVO.getDeptIds());
46 50 // 插入
47 51 CrmCustomerLimitConfigDO customerLimitConfig = CrmCustomerLimitConfigConvert.INSTANCE.convert(createReqVO);
48 52 customerLimitConfigMapper.insert(customerLimitConfig);
  53 +
  54 + // 记录操作日志上下文
  55 + LogRecordContext.putVariable("limitType", CrmCustomerLimitConfigTypeEnum.getNameByType(customerLimitConfig.getType()));
  56 + LogRecordContext.putVariable("limitId", customerLimitConfig.getId());
49 57 // 返回
50 58 return customerLimitConfig.getId();
51 59 }
52 60  
53 61 @Override
54   - // TODO @puhui999:操作日志
55   - public void updateCustomerLimitConfig(CrmCustomerLimitConfigUpdateReqVO updateReqVO) {
  62 + @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)
  63 + public void updateCustomerLimitConfig(CrmCustomerLimitConfigSaveReqVO updateReqVO) {
56 64 // 校验存在
57   - validateCustomerLimitConfigExists(updateReqVO.getId());
  65 + CrmCustomerLimitConfigDO oldLimitConfig = validateCustomerLimitConfigExists(updateReqVO.getId());
58 66 validateUserAndDept(updateReqVO.getUserIds(), updateReqVO.getDeptIds());
59 67 // 更新
60 68 CrmCustomerLimitConfigDO updateObj = CrmCustomerLimitConfigConvert.INSTANCE.convert(updateReqVO);
61 69 customerLimitConfigMapper.updateById(updateObj);
  70 +
  71 + // 记录操作日志上下文
  72 + LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldLimitConfig, CrmCustomerLimitConfigSaveReqVO.class));
62 73 }
63 74  
64 75 @Override
65   - // TODO @puhui999:操作日志
  76 + @LogRecord(type = CRM_CUSTOMER_LIMIT_CONFIG_TYPE, subType = CRM_CUSTOMER_LIMIT_CONFIG_DELETE_SUB_TYPE, bizNo = "{{#id}}", success = CRM_CUSTOMER_LIMIT_CONFIG_DELETE_SUCCESS)
66 77 public void deleteCustomerLimitConfig(Long id) {
67 78 // 校验存在
68   - validateCustomerLimitConfigExists(id);
  79 + CrmCustomerLimitConfigDO limitConfigDO = validateCustomerLimitConfigExists(id);
69 80 // 删除
70 81 customerLimitConfigMapper.deleteById(id);
  82 +
  83 + // 记录操作日志上下文
  84 + LogRecordContext.putVariable("limitType", CrmCustomerLimitConfigTypeEnum.getNameByType(limitConfigDO.getType()));
71 85 }
72 86  
73 87 @Override
... ... @@ -80,10 +94,12 @@ public class CrmCustomerLimitConfigServiceImpl implements CrmCustomerLimitConfig
80 94 return customerLimitConfigMapper.selectPage(pageReqVO);
81 95 }
82 96  
83   - private void validateCustomerLimitConfigExists(Long id) {
84   - if (customerLimitConfigMapper.selectById(id) == null) {
  97 + private CrmCustomerLimitConfigDO validateCustomerLimitConfigExists(Long id) {
  98 + CrmCustomerLimitConfigDO limitConfigDO = customerLimitConfigMapper.selectById(id);
  99 + if (limitConfigDO == null) {
85 100 throw exception(CUSTOMER_LIMIT_CONFIG_NOT_EXISTS);
86 101 }
  102 + return limitConfigDO;
87 103 }
88 104  
89 105 /**
... ...
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
5 5 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
6 6 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfigDO;
7 7 import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerPoolConfigMapper;
  8 +import com.mzt.logapi.context.LogRecordContext;
  9 +import com.mzt.logapi.starter.annotation.LogRecord;
  10 +import jakarta.annotation.Resource;
8 11 import org.springframework.stereotype.Service;
9 12 import org.springframework.validation.annotation.Validated;
10 13  
11   -import jakarta.annotation.Resource;
12 14 import java.util.Objects;
13 15  
  16 +import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
  17 +
14 18 /**
15 19 * 客户公海配置 Service 实现类
16 20 *
... ... @@ -19,6 +23,7 @@ import java.util.Objects;
19 23 @Service
20 24 @Validated
21 25 public class CrmCustomerPoolConfigServiceImpl implements CrmCustomerPoolConfigService {
  26 +
22 27 @Resource
23 28 private CrmCustomerPoolConfigMapper customerPoolConfigMapper;
24 29  
... ... @@ -38,16 +43,23 @@ public class CrmCustomerPoolConfigServiceImpl implements CrmCustomerPoolConfigSe
38 43 * @param saveReqVO 更新信息
39 44 */
40 45 @Override
41   - // TODO @puhui999:操作日志
  46 + @LogRecord(type = CRM_CUSTOMER_POOL_CONFIG_TYPE, subType = CRM_CUSTOMER_POOL_CONFIG_SUB_TYPE, bizNo = "{{#poolConfigId}}", success = CRM_CUSTOMER_POOL_CONFIG_SUCCESS)
42 47 public void saveCustomerPoolConfig(CrmCustomerPoolConfigSaveReqVO saveReqVO) {
43 48 // 存在,则进行更新
44 49 CrmCustomerPoolConfigDO dbConfig = getCustomerPoolConfig();
  50 + CrmCustomerPoolConfigDO poolConfig = CrmCustomerConvert.INSTANCE.convert(saveReqVO);
45 51 if (Objects.nonNull(dbConfig)) {
46   - customerPoolConfigMapper.updateById(CrmCustomerConvert.INSTANCE.convert(saveReqVO).setId(dbConfig.getId()));
  52 + customerPoolConfigMapper.updateById(poolConfig.setId(dbConfig.getId()));
  53 + // 记录操作日志上下文
  54 + LogRecordContext.putVariable("isPoolConfigUpdate", Boolean.TRUE);
  55 + LogRecordContext.putVariable("poolConfigId", poolConfig.getId());
47 56 return;
48 57 }
49 58 // 不存在,则进行插入
50   - customerPoolConfigMapper.insert(CrmCustomerConvert.INSTANCE.convert(saveReqVO));
  59 + customerPoolConfigMapper.insert(poolConfig);
  60 + // 记录操作日志上下文
  61 + LogRecordContext.putVariable("isPoolConfigUpdate", Boolean.FALSE);
  62 + LogRecordContext.putVariable("poolConfigId", poolConfig.getId());
51 63 }
52 64  
53 65 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java
1 1 package cn.iocoder.yudao.module.crm.service.customer;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4   -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
  4 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLockReqVO;
  5 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
  6 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
  7 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
5 8 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
6 9 import jakarta.validation.Valid;
7 10  
... ... @@ -22,14 +25,14 @@ public interface CrmCustomerService {
22 25 * @param userId 用户编号
23 26 * @return 编号
24 27 */
25   - Long createCustomer(@Valid CrmCustomerCreateReqVO createReqVO, Long userId);
  28 + Long createCustomer(@Valid CrmCustomerSaveReqVO createReqVO, Long userId);
26 29  
27 30 /**
28 31 * 更新客户
29 32 *
30 33 * @param updateReqVO 更新信息
31 34 */
32   - void updateCustomer(@Valid CrmCustomerUpdateReqVO updateReqVO);
  35 + void updateCustomer(@Valid CrmCustomerSaveReqVO updateReqVO);
33 36  
34 37 /**
35 38 * 删除客户
... ... @@ -83,7 +86,7 @@ public interface CrmCustomerService {
83 86 * 锁定/解锁客户
84 87 *
85 88 * @param lockReqVO 更新信息
86   - * @param userId 用户编号
  89 + * @param userId 用户编号
87 90 */
88 91 void lockCustomer(@Valid CrmCustomerLockReqVO lockReqVO, Long userId);
89 92  
... ... @@ -101,15 +104,8 @@ public interface CrmCustomerService {
101 104 *
102 105 * @param ids 要领取的客户编号数组
103 106 * @param ownerUserId 负责人
  107 + * @param isReceive 是/否领取
104 108 */
105   - void receiveCustomer(List<Long> ids, Long ownerUserId);
106   -
107   - /**
108   - * 获取客户列表
109   - *
110   - * @return 客户列表
111   - * @author zyna
112   - */
113   - List<CrmCustomerDO> getCustomerList();
  109 + void receiveCustomer(List<Long> ids, Long ownerUserId, Boolean isReceive);
114 110  
115 111 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
1 1 package cn.iocoder.yudao.module.crm.service.customer;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.lang.Assert;
  5 +import cn.hutool.extra.spring.SpringUtil;
4 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 7 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
6 8 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
7   -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
  9 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerLockReqVO;
  10 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
  11 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
  12 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
8 13 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
9 14 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
10 15 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
... ... @@ -12,9 +17,11 @@ import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
12 17 import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
13 18 import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
14 19 import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission;
  20 +import cn.iocoder.yudao.module.crm.framework.permission.core.util.CrmPermissionUtils;
15 21 import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
16 22 import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
17 23 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
  24 +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
18 25 import com.mzt.logapi.context.LogRecordContext;
19 26 import com.mzt.logapi.service.impl.DiffParseFunction;
20 27 import com.mzt.logapi.starter.annotation.LogRecord;
... ... @@ -24,12 +31,14 @@ import org.springframework.transaction.annotation.Transactional;
24 31 import org.springframework.validation.annotation.Validated;
25 32  
26 33 import java.time.LocalDateTime;
27   -import java.util.*;
  34 +import java.util.ArrayList;
  35 +import java.util.Collection;
  36 +import java.util.Collections;
  37 +import java.util.List;
28 38  
29 39 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
30 40 import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
31   -import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.CRM_CUSTOMER;
32   -import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.TRANSFER_CUSTOMER_LOG_SUCCESS;
  41 +import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
33 42 import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_LOCK_LIMIT;
34 43 import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_OWNER_LIMIT;
35 44 import static java.util.Collections.singletonList;
... ... @@ -56,8 +65,9 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
56 65  
57 66 @Override
58 67 @Transactional(rollbackFor = Exception.class)
59   - @LogRecord(type = CRM_CUSTOMER, subType = "创建客户", bizNo = "{{#customerId}}", success = "创建了客户") // TODO @puhui999:创建了客户【客户名】,要记录进去;不然在展示操作日志的全列表,看不清楚是哪个客户哈;
60   - public Long createCustomer(CrmCustomerCreateReqVO createReqVO, Long userId) {
  68 + @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_CREATE_SUB_TYPE, bizNo = "{{#customer.id}}", success = CRM_CUSTOMER_CREATE_SUCCESS)
  69 + public Long createCustomer(CrmCustomerSaveReqVO createReqVO, Long userId) {
  70 + createReqVO.setId(null);
61 71 // 1. 校验拥有客户是否到达上限
62 72 validateCustomerExceedOwnerLimit(createReqVO.getOwnerUserId(), 1);
63 73  
... ... @@ -72,17 +82,19 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
72 82 permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())
73 83 .setBizId(customer.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人
74 84  
75   - // 4. 记录操作日志
76   - LogRecordContext.putVariable("customerId", customer.getId());
  85 + // 4. 记录操作日志上下文
  86 + LogRecordContext.putVariable("customer", customer);
77 87 return customer.getId();
78 88 }
79 89  
80 90 @Override
81 91 @Transactional(rollbackFor = Exception.class)
82   - @LogRecord(type = CRM_CUSTOMER, subType = "更新客户", bizNo = "{{#updateReqVO.id}}", success = "更新了客户{_DIFF{#updateReqVO}}", extra = "{{#extra}}")
  92 + @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}", success = CRM_CUSTOMER_UPDATE_SUCCESS)
83 93 @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE)
84   - public void updateCustomer(CrmCustomerUpdateReqVO updateReqVO) {
85   - // TODO @puhui999:更新的时候,要把 updateReqVO 负责人设置为空,避免修改。
  94 + public void updateCustomer(CrmCustomerSaveReqVO updateReqVO) {
  95 + Assert.notNull(updateReqVO.getId(), "客户编号不能为空");
  96 + // 更新的时候,要把 updateReqVO 负责人设置为空,避免修改。
  97 + updateReqVO.setOwnerUserId(null);
86 98 // 1. 校验存在
87 99 CrmCustomerDO oldCustomer = validateCustomerExists(updateReqVO.getId());
88 100  
... ... @@ -90,21 +102,18 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
90 102 CrmCustomerDO updateObj = CrmCustomerConvert.INSTANCE.convert(updateReqVO);
91 103 customerMapper.updateById(updateObj);
92 104  
93   - // 3. 记录操作日志
94   - LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldCustomer, CrmCustomerUpdateReqVO.class));
95   - // TODO 扩展信息测试 @puhui999:看着没啥问题,可以删除啦;
96   - HashMap<String, Object> extra = new HashMap<>();
97   - extra.put("tips", "随便记录一点啦");
98   - LogRecordContext.putVariable("extra", extra);
  105 + // 3. 记录操作日志上下文
  106 + LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldCustomer, CrmCustomerSaveReqVO.class));
  107 + LogRecordContext.putVariable("customerName", oldCustomer.getName());
99 108 }
100 109  
101 110 @Override
102 111 @Transactional(rollbackFor = Exception.class)
103   - @LogRecord(type = CRM_CUSTOMER, subType = "删除客户", bizNo = "{{#id}}", success = "删除了客户")
  112 + @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_DELETE_SUB_TYPE, bizNo = "{{#id}}", success = CRM_CUSTOMER_DELETE_SUCCESS)
104 113 @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
105 114 public void deleteCustomer(Long id) {
106 115 // 校验存在
107   - validateCustomerExists(id);
  116 + CrmCustomerDO customer = validateCustomerExists(id);
108 117 // TODO @puhui999:如果有联系人、商机,则不允许删除;
109 118  
110 119 // 删除
... ... @@ -112,48 +121,14 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
112 121 // 删除数据权限
113 122 permissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), id);
114 123 // TODO @puhui999:删除跟进记录
115   - }
116   -
117   - private CrmCustomerDO validateCustomerExists(Long id) {
118   - CrmCustomerDO customerDO = customerMapper.selectById(id);
119   - if (customerDO == null) {
120   - throw exception(CUSTOMER_NOT_EXISTS);
121   - }
122   - return customerDO;
123   - }
124   -
125   - @Override
126   - @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.READ)
127   - public CrmCustomerDO getCustomer(Long id) {
128   - return customerMapper.selectById(id);
129   - }
130 124  
131   - @Override
132   - public List<CrmCustomerDO> getCustomerList(Collection<Long> ids) {
133   - if (CollUtil.isEmpty(ids)) {
134   - return Collections.emptyList();
135   - }
136   - return customerMapper.selectBatchIds(ids);
137   - }
138   -
139   - @Override
140   - public PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
141   - return customerMapper.selectPage(pageReqVO, userId);
142   - }
143   -
144   - /**
145   - * 校验客户是否存在
146   - *
147   - * @param customerId 客户 id
148   - */
149   - @Override
150   - public void validateCustomer(Long customerId) {
151   - validateCustomerExists(customerId);
  125 + // 记录操作日志上下文
  126 + LogRecordContext.putVariable("customerName", customer.getName());
152 127 }
153 128  
154 129 @Override
155 130 @Transactional(rollbackFor = Exception.class)
156   - @LogRecord(type = CRM_CUSTOMER, subType = "转移客户", bizNo = "{{#reqVO.id}}", success = TRANSFER_CUSTOMER_LOG_SUCCESS)
  131 + @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}", success = CRM_CUSTOMER_TRANSFER_SUCCESS)
157 132 @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
158 133 public void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId) {
159 134 // 1.1 校验客户是否存在
... ... @@ -168,20 +143,17 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
168 143 customerMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId());
169 144  
170 145 // 3. TODO 记录转移日志
  146 + // 记录操作日志上下文
171 147 LogRecordContext.putVariable("crmCustomer", customer);
172 148 }
173 149  
174 150 @Override
175   - // TODO @puhui999:看看这个能不能根据条件,写操作日志;
176   - // TODO 如果是 锁定,则 subType 为 锁定客户;success 为 将客户【】锁定
177   - // TODO 如果是 解锁,则 subType 为 解锁客户;success 为 将客户【】解锁
178   - @LogRecord(type = CRM_CUSTOMER, subType = "锁定/解锁客户", bizNo = "{{#updateReqVO.id}}", success = "锁定了客户")
179   - // TODO @puhui999:数据权限
  151 + @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_LOCK_SUB_TYPE, bizNo = "{{#lockReqVO.id}}", success = CRM_CUSTOMER_LOCK_SUCCESS)
  152 + @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#lockReqVO.id", level = CrmPermissionLevelEnum.OWNER)
180 153 public void lockCustomer(CrmCustomerLockReqVO lockReqVO, Long userId) {
181 154 // 1.1 校验当前客户是否存在
182   - validateCustomerExists(lockReqVO.getId());
  155 + CrmCustomerDO customer = validateCustomerExists(lockReqVO.getId());
183 156 // 1.2 校验当前是否重复操作锁定/解锁状态
184   - CrmCustomerDO customer = customerMapper.selectById(lockReqVO.getId());
185 157 if (customer.getLockStatus().equals(lockReqVO.getLockStatus())) {
186 158 throw exception(customer.getLockStatus() ? CUSTOMER_LOCK_FAIL_IS_LOCK : CUSTOMER_UNLOCK_FAIL_IS_UNLOCK);
187 159 }
... ... @@ -192,52 +164,16 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
192 164  
193 165 // 2. 更新锁定状态
194 166 customerMapper.updateById(BeanUtils.toBean(lockReqVO, CrmCustomerDO.class));
195   - }
196 167  
197   - /**
198   - * 校验用户拥有的客户数量,是否到达上限
199   - *
200   - * @param userId 用户编号
201   - * @param newCount 附加数量
202   - */
203   - private void validateCustomerExceedOwnerLimit(Long userId, int newCount) {
204   - List<CrmCustomerLimitConfigDO> limitConfigs = customerLimitConfigService.getCustomerLimitConfigListByUserId(
205   - CUSTOMER_OWNER_LIMIT.getType(), userId);
206   - if (CollUtil.isEmpty(limitConfigs)) {
207   - return;
208   - }
209   - Long ownerCount = customerMapper.selectCountByDealStatusAndOwnerUserId(null, userId);
210   - Long dealOwnerCount = customerMapper.selectCountByDealStatusAndOwnerUserId(true, userId);
211   - limitConfigs.forEach(limitConfig -> {
212   - long nowCount = limitConfig.getDealCountEnabled() ? ownerCount : ownerCount - dealOwnerCount;
213   - if (nowCount + newCount > limitConfig.getMaxCount()) {
214   - throw exception(CUSTOMER_OWNER_EXCEED_LIMIT);
215   - }
216   - });
  168 + // 3. 记录操作日志上下文. tips: 因为这里使用的是老的状态所以记录时反着记录,也就是 lockStatus 为 true 那么就是解锁反之为锁定
  169 + LogRecordContext.putVariable("crmCustomer", customer);
217 170 }
218 171  
219   - /**
220   - * 校验用户锁定的客户数量,是否到达上限
221   - *
222   - * @param userId 用户编号
223   - */
224   - private void validateCustomerExceedLockLimit(Long userId) {
225   - List<CrmCustomerLimitConfigDO> limitConfigs = customerLimitConfigService.getCustomerLimitConfigListByUserId(
226   - CUSTOMER_LOCK_LIMIT.getType(), userId);
227   - if (CollUtil.isEmpty(limitConfigs)) {
228   - return;
229   - }
230   - Long lockCount = customerMapper.selectCountByLockStatusAndOwnerUserId(true, userId);
231   - Integer maxCount = CollectionUtils.getMaxValue(limitConfigs, CrmCustomerLimitConfigDO::getMaxCount);
232   - assert maxCount != null;
233   - if (lockCount >= maxCount) {
234   - throw exception(CUSTOMER_LOCK_EXCEED_LIMIT);
235   - }
236   - }
  172 + // ==================== 公海相关操作 ====================
237 173  
238 174 @Override
239 175 @Transactional(rollbackFor = Exception.class)
240   - @LogRecord(type = CRM_CUSTOMER, subType = "客户放入公海", bizNo = "{{#id}}", success = "将客户放入了公海") // TODO @puhui999:将客户【】放入了公海
  176 + @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_POOL_SUB_TYPE, bizNo = "{{#id}}", success = CRM_CUSTOMER_POOL_SUCCESS)
241 177 @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
242 178 public void putCustomerPool(Long id) {
243 179 // 1. 校验存在
... ... @@ -259,16 +195,18 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
259 195 permissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), customer.getId(),
260 196 CrmPermissionLevelEnum.OWNER.getLevel());
261 197 // TODO @puhui999:联系人的负责人,也要设置为 null;这块和领取是对应的;因为领取后,负责人也要关联过来;
  198 +
  199 + // 记录操作日志上下文
  200 + LogRecordContext.putVariable("customerName", customer.getName());
262 201 }
263 202  
264 203 @Override
265 204 @Transactional(rollbackFor = Exception.class)
266   - // TODO @puhui999:权限校验
  205 + public void receiveCustomer(List<Long> ids, Long ownerUserId, Boolean isReceive) {
  206 + if (!isReceive && !CrmPermissionUtils.isCrmAdmin()) { // 只有管理员可以分配
  207 + throw exception(CRM_PERMISSION_DENIED, CrmBizTypeEnum.CRM_CUSTOMER.getName());
  208 + }
267 209  
268   - // TODO @puhui999:如果是分配,操作日志是 “将客户【】分配给【】”
269   - // TODO @puhui999:如果是领取,操作日志是“领取客户【】”;
270   - // TODO @puhui999:如果是多条,则需要记录多条操作日志;不然 bizId 不好关联
271   - public void receiveCustomer(List<Long> ids, Long ownerUserId) {
272 210 // 1.1 校验存在
273 211 List<CrmCustomerDO> customers = customerMapper.selectBatchIds(ids);
274 212 if (customers.size() != ids.size()) {
... ... @@ -303,6 +241,55 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
303 241 // 2.3 创建负责人数据权限
304 242 permissionService.createPermissionBatch(createPermissions);
305 243 // TODO @芋艿:要不要处理关联的联系人???
  244 +
  245 + // 3. 记录操作日志
  246 + AdminUserRespDTO user = null;
  247 + if (!isReceive) {
  248 + user = adminUserApi.getUser(ownerUserId);
  249 + }
  250 + for (CrmCustomerDO customer : customers) {
  251 + getSelf().receiveCustomerLog(customer, user == null ? null : user.getNickname());
  252 + }
  253 + }
  254 +
  255 + @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_RECEIVE_SUB_TYPE, bizNo = "{{#customer.id}}", success = CRM_CUSTOMER_RECEIVE_SUCCESS)
  256 + public void receiveCustomerLog(CrmCustomerDO customer, String ownerUserName) {
  257 + // 记录操作日志上下文
  258 + LogRecordContext.putVariable("customer", customer);
  259 + LogRecordContext.putVariable("ownerUserName", ownerUserName);
  260 + }
  261 +
  262 + //======================= 查询相关 =======================
  263 +
  264 + @Override
  265 + @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#id", level = CrmPermissionLevelEnum.READ)
  266 + public CrmCustomerDO getCustomer(Long id) {
  267 + return customerMapper.selectById(id);
  268 + }
  269 +
  270 + @Override
  271 + public List<CrmCustomerDO> getCustomerList(Collection<Long> ids) {
  272 + if (CollUtil.isEmpty(ids)) {
  273 + return Collections.emptyList();
  274 + }
  275 + return customerMapper.selectBatchIds(ids);
  276 + }
  277 +
  278 + @Override
  279 + public PageResult<CrmCustomerDO> getCustomerPage(CrmCustomerPageReqVO pageReqVO, Long userId) {
  280 + return customerMapper.selectPage(pageReqVO, userId);
  281 + }
  282 +
  283 + //======================= 校验相关 =======================
  284 +
  285 + /**
  286 + * 校验客户是否存在
  287 + *
  288 + * @param customerId 客户 id
  289 + */
  290 + @Override
  291 + public void validateCustomer(Long customerId) {
  292 + validateCustomerExists(customerId);
306 293 }
307 294  
308 295 private void validateCustomerOwnerExists(CrmCustomerDO customer, Boolean pool) {
... ... @@ -314,11 +301,19 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
314 301 throw exception(CUSTOMER_IN_POOL, customer.getName());
315 302 }
316 303 // 负责人已存在
317   - if (customer.getOwnerUserId() != null) {
  304 + if (!pool && customer.getOwnerUserId() != null) {
318 305 throw exception(CUSTOMER_OWNER_EXISTS, customer.getName());
319 306 }
320 307 }
321 308  
  309 + private CrmCustomerDO validateCustomerExists(Long id) {
  310 + CrmCustomerDO customerDO = customerMapper.selectById(id);
  311 + if (customerDO == null) {
  312 + throw exception(CUSTOMER_NOT_EXISTS);
  313 + }
  314 + return customerDO;
  315 + }
  316 +
322 317 private void validateCustomerIsLocked(CrmCustomerDO customer, Boolean pool) {
323 318 if (customer.getLockStatus()) {
324 319 throw exception(pool ? CUSTOMER_LOCKED_PUT_POOL_FAIL : CUSTOMER_LOCKED, customer.getName());
... ... @@ -331,9 +326,55 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
331 326 }
332 327 }
333 328  
334   - @Override
335   - public List<CrmCustomerDO> getCustomerList() {
336   - return customerMapper.selectList();
  329 + /**
  330 + * 校验用户拥有的客户数量,是否到达上限
  331 + *
  332 + * @param userId 用户编号
  333 + * @param newCount 附加数量
  334 + */
  335 + private void validateCustomerExceedOwnerLimit(Long userId, int newCount) {
  336 + List<CrmCustomerLimitConfigDO> limitConfigs = customerLimitConfigService.getCustomerLimitConfigListByUserId(
  337 + CUSTOMER_OWNER_LIMIT.getType(), userId);
  338 + if (CollUtil.isEmpty(limitConfigs)) {
  339 + return;
  340 + }
  341 + Long ownerCount = customerMapper.selectCountByDealStatusAndOwnerUserId(null, userId);
  342 + Long dealOwnerCount = customerMapper.selectCountByDealStatusAndOwnerUserId(true, userId);
  343 + limitConfigs.forEach(limitConfig -> {
  344 + long nowCount = limitConfig.getDealCountEnabled() ? ownerCount : ownerCount - dealOwnerCount;
  345 + if (nowCount + newCount > limitConfig.getMaxCount()) {
  346 + throw exception(CUSTOMER_OWNER_EXCEED_LIMIT);
  347 + }
  348 + });
  349 + }
  350 +
  351 + /**
  352 + * 校验用户锁定的客户数量,是否到达上限
  353 + *
  354 + * @param userId 用户编号
  355 + */
  356 + private void validateCustomerExceedLockLimit(Long userId) {
  357 + List<CrmCustomerLimitConfigDO> limitConfigs = customerLimitConfigService.getCustomerLimitConfigListByUserId(
  358 + CUSTOMER_LOCK_LIMIT.getType(), userId);
  359 + if (CollUtil.isEmpty(limitConfigs)) {
  360 + return;
  361 + }
  362 + Long lockCount = customerMapper.selectCountByLockStatusAndOwnerUserId(true, userId);
  363 + Integer maxCount = CollectionUtils.getMaxValue(limitConfigs, CrmCustomerLimitConfigDO::getMaxCount);
  364 + assert maxCount != null;
  365 + if (lockCount >= maxCount) {
  366 + throw exception(CUSTOMER_LOCK_EXCEED_LIMIT);
  367 + }
  368 + }
  369 +
  370 +
  371 + /**
  372 + * 获得自身的代理对象,解决 AOP 生效问题
  373 + *
  374 + * @return 自己
  375 + */
  376 + private CrmCustomerServiceImpl getSelf() {
  377 + return SpringUtil.getBean(getClass());
337 378 }
338 379  
339 380 }
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionService.java
... ... @@ -91,6 +91,15 @@ public interface CrmPermissionService {
91 91 List<CrmPermissionDO> getPermissionListByBiz(Integer bizType, Long bizId);
92 92  
93 93 /**
  94 + * 获取数据权限列表,通过 数据类型 x 某个数据
  95 + *
  96 + * @param bizType 数据类型,关联 {@link CrmBizTypeEnum}
  97 + * @param bizIds 数据编号,关联 {@link CrmBizTypeEnum} 对应模块 DO#getId()
  98 + * @return Crm 数据权限列表
  99 + */
  100 + List<CrmPermissionDO> getPermissionListByBiz(Integer bizType, Collection<Long> bizIds);
  101 +
  102 + /**
94 103 * 获取用户参与的模块数据列表
95 104 *
96 105 * @param bizType 模块类型
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java
... ... @@ -188,6 +188,11 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
188 188 }
189 189  
190 190 @Override
  191 + public List<CrmPermissionDO> getPermissionListByBiz(Integer bizType, Collection<Long> bizIds) {
  192 + return crmPermissionMapper.selectByBizTypeAndBizIds(bizType, bizIds);
  193 + }
  194 +
  195 + @Override
191 196 public List<CrmPermissionDO> getPermissionListByBizTypeAndUserId(Integer bizType, Long userId) {
192 197 return crmPermissionMapper.selectListByBizTypeAndUserId(bizType, userId);
193 198 }
... ...
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;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 4 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
5   -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerCreateReqVO;
6 5 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
7   -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerUpdateReqVO;
  6 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
8 7 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
9 8 import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
10 9 import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
  10 +import jakarta.annotation.Resource;
11 11 import org.junit.jupiter.api.Disabled;
12 12 import org.junit.jupiter.api.Test;
13 13 import org.springframework.boot.test.mock.mockito.MockBean;
14 14 import org.springframework.context.annotation.Import;
15 15  
16   -import jakarta.annotation.Resource;
17   -
18 16 import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
19 17 import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
20 18 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
... ... @@ -47,7 +45,7 @@ public class CrmCustomerServiceImplTest extends BaseDbUnitTest {
47 45 @Test
48 46 public void testCreateCustomer_success() {
49 47 // 准备参数
50   - CrmCustomerCreateReqVO reqVO = randomPojo(CrmCustomerCreateReqVO.class);
  48 + CrmCustomerSaveReqVO reqVO = randomPojo(CrmCustomerSaveReqVO.class);
51 49  
52 50 // 调用
53 51 Long customerId = customerService.createCustomer(reqVO, getLoginUserId());
... ... @@ -64,7 +62,7 @@ public class CrmCustomerServiceImplTest extends BaseDbUnitTest {
64 62 CrmCustomerDO dbCustomer = randomPojo(CrmCustomerDO.class);
65 63 customerMapper.insert(dbCustomer);// @Sql: 先插入出一条存在的数据
66 64 // 准备参数
67   - CrmCustomerUpdateReqVO reqVO = randomPojo(CrmCustomerUpdateReqVO.class, o -> {
  65 + CrmCustomerSaveReqVO reqVO = randomPojo(CrmCustomerSaveReqVO.class, o -> {
68 66 o.setId(dbCustomer.getId()); // 设置更新的 ID
69 67 });
70 68  
... ... @@ -78,7 +76,7 @@ public class CrmCustomerServiceImplTest extends BaseDbUnitTest {
78 76 @Test
79 77 public void testUpdateCustomer_notExists() {
80 78 // 准备参数
81   - CrmCustomerUpdateReqVO reqVO = randomPojo(CrmCustomerUpdateReqVO.class);
  79 + CrmCustomerSaveReqVO reqVO = randomPojo(CrmCustomerSaveReqVO.class);
82 80  
83 81 // 调用, 并断言异常
84 82 assertServiceException(() -> customerService.updateCustomer(reqVO), CUSTOMER_NOT_EXISTS);
... ...
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;
2 2  
3 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 4 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
5   -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigCreateReqVO;
6 5 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigPageReqVO;
7   -import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigUpdateReqVO;
  6 +import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
8 7 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
9 8 import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerLimitConfigMapper;
10 9 import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerLimitConfigServiceImpl;
  10 +import jakarta.annotation.Resource;
11 11 import org.junit.jupiter.api.Disabled;
12 12 import org.junit.jupiter.api.Test;
13 13 import org.springframework.context.annotation.Import;
14 14  
15   -import jakarta.annotation.Resource;
16   -
17 15 import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
18 16 import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
19 17 import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
... ... @@ -40,7 +38,7 @@ public class CrmCustomerLimitConfigServiceImplTest extends BaseDbUnitTest {
40 38 @Test
41 39 public void testCreateCustomerLimitConfig_success() {
42 40 // 准备参数
43   - CrmCustomerLimitConfigCreateReqVO reqVO = randomPojo(CrmCustomerLimitConfigCreateReqVO.class);
  41 + CrmCustomerLimitConfigSaveReqVO reqVO = randomPojo(CrmCustomerLimitConfigSaveReqVO.class);
44 42  
45 43 // 调用
46 44 Long customerLimitConfigId = customerLimitConfigService.createCustomerLimitConfig(reqVO);
... ... @@ -57,7 +55,7 @@ public class CrmCustomerLimitConfigServiceImplTest extends BaseDbUnitTest {
57 55 CrmCustomerLimitConfigDO dbCustomerLimitConfig = randomPojo(CrmCustomerLimitConfigDO.class);
58 56 customerLimitConfigMapper.insert(dbCustomerLimitConfig);// @Sql: 先插入出一条存在的数据
59 57 // 准备参数
60   - CrmCustomerLimitConfigUpdateReqVO reqVO = randomPojo(CrmCustomerLimitConfigUpdateReqVO.class, o -> {
  58 + CrmCustomerLimitConfigSaveReqVO reqVO = randomPojo(CrmCustomerLimitConfigSaveReqVO.class, o -> {
61 59 o.setId(dbCustomerLimitConfig.getId()); // 设置更新的 ID
62 60 });
63 61  
... ... @@ -71,7 +69,7 @@ public class CrmCustomerLimitConfigServiceImplTest extends BaseDbUnitTest {
71 69 @Test
72 70 public void testUpdateCustomerLimitConfig_notExists() {
73 71 // 准备参数
74   - CrmCustomerLimitConfigUpdateReqVO reqVO = randomPojo(CrmCustomerLimitConfigUpdateReqVO.class);
  72 + CrmCustomerLimitConfigSaveReqVO reqVO = randomPojo(CrmCustomerLimitConfigSaveReqVO.class);
75 73  
76 74 // 调用, 并断言异常
77 75 assertServiceException(() -> customerLimitConfigService.updateCustomerLimitConfig(reqVO), CUSTOMER_LIMIT_CONFIG_NOT_EXISTS);
... ...
yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/statistics/vo/MpStatisticsGetReqVO.java
1 1 package cn.iocoder.yudao.module.mp.controller.admin.statistics.vo;
2 2  
3 3 import io.swagger.v3.oas.annotations.media.Schema;
  4 +import jakarta.validation.constraints.NotNull;
4 5 import lombok.Data;
5 6 import org.springframework.format.annotation.DateTimeFormat;
6 7  
7   -import jakarta.validation.constraints.NotNull;
8 8 import java.time.LocalDateTime;
9 9  
10 10 import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
... ... @@ -17,7 +17,7 @@ public class MpStatisticsGetReqVO {
17 17 @NotNull(message = "公众号账号的编号不能为空")
18 18 private Long accountId;
19 19  
20   - @Schema(description = "查询时间范围")
  20 + @Schema(description = "查询时间范围", example = "[2022-07-01 00:00:00, 2022-07-01 23:59:59]")
21 21 @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
22 22 @NotNull(message = "查询时间范围不能为空")
23 23 private LocalDateTime[] date;
... ...
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;
11 11 import org.mapstruct.Mapper;
12 12 import org.mapstruct.Mapping;
13 13 import org.mapstruct.Mappings;
  14 +import org.mapstruct.Named;
14 15 import org.mapstruct.factory.Mappers;
15 16  
  17 +import java.time.LocalDate;
  18 +import java.time.LocalDateTime;
  19 +import java.time.format.DateTimeFormatter;
16 20 import java.util.List;
17 21  
  22 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
  23 +
18 24 @Mapper
19 25 public interface MpStatisticsConvert {
20 26  
... ... @@ -27,7 +33,7 @@ public interface MpStatisticsConvert {
27 33 List<MpStatisticsUpstreamMessageRespVO> convertList03(List<WxDataCubeMsgResult> list);
28 34  
29 35 @Mappings({
30   - @Mapping(source = "refDate", target = "refDate", dateFormat = "yyyy-MM-dd"),
  36 + @Mapping(target = "refDate", expression = "java(dateFormat0(bean.getRefDate()))"),
31 37 @Mapping(source = "msgUser", target = "messageUser"),
32 38 @Mapping(source = "msgCount", target = "messageCount"),
33 39 })
... ... @@ -35,6 +41,12 @@ public interface MpStatisticsConvert {
35 41  
36 42 List<MpStatisticsInterfaceSummaryRespVO> convertList04(List<WxDataCubeInterfaceResult> list);
37 43  
38   - @Mapping(source = "refDate", target = "refDate", dateFormat = "yyyy-MM-dd")
  44 + @Mapping(target = "refDate", expression = "java(dateFormat0(bean.getRefDate()))")
39 45 MpStatisticsInterfaceSummaryRespVO convert(WxDataCubeInterfaceResult bean);
  46 +
  47 + @Named("dateFormat0")
  48 + default LocalDateTime dateFormat0(String date) {
  49 + return LocalDate.parse(date, DateTimeFormatter.ofPattern(FORMAT_YEAR_MONTH_DAY)).atStartOfDay();
  50 + }
  51 +
40 52 }
... ...
yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/message/MpMessageServiceImpl.java
1 1 package cn.iocoder.yudao.module.mp.service.message;
2 2  
3 3 import cn.hutool.core.lang.Assert;
  4 +import cn.hutool.core.util.ObjUtil;
4 5 import cn.hutool.core.util.StrUtil;
5 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 7 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;
17 18 import cn.iocoder.yudao.module.mp.service.material.MpMaterialService;
18 19 import cn.iocoder.yudao.module.mp.service.message.bo.MpMessageSendOutReqBO;
19 20 import cn.iocoder.yudao.module.mp.service.user.MpUserService;
  21 +import jakarta.annotation.Resource;
  22 +import jakarta.validation.Validator;
20 23 import lombok.extern.slf4j.Slf4j;
21 24 import me.chanjar.weixin.common.api.WxConsts;
22 25 import me.chanjar.weixin.common.error.WxErrorException;
... ... @@ -28,9 +31,6 @@ import org.springframework.context.annotation.Lazy;
28 31 import org.springframework.stereotype.Service;
29 32 import org.springframework.validation.annotation.Validated;
30 33  
31   -import jakarta.annotation.Resource;
32   -import jakarta.validation.Validator;
33   -
34 34 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
35 35 import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.MESSAGE_SEND_FAIL;
36 36  
... ... @@ -72,6 +72,12 @@ public class MpMessageServiceImpl implements MpMessageService {
72 72 // 获得关联信息
73 73 MpAccountDO account = mpAccountService.getAccountFromCache(appId);
74 74 Assert.notNull(account, "公众号账号({}) 不存在", appId);
  75 +
  76 + // 订阅事件不记录,因为此时公众号粉丝表中还没有此粉丝的数据
  77 + if (ObjUtil.equal(wxMessage.getEvent(), WxConsts.EventType.SUBSCRIBE)) {
  78 + return;
  79 + }
  80 +
75 81 MpUserDO user = mpUserService.getUser(appId, wxMessage.getFromUser());
76 82 Assert.notNull(user, "公众号粉丝({}/{}) 不存在", appId, wxMessage.getFromUser());
77 83  
... ...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/PostApi.java
1 1 package cn.iocoder.yudao.module.system.api.dept;
2 2  
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.map.MapUtil;
3 5 import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
4 6 import cn.iocoder.yudao.module.system.api.dept.dto.PostRespDTO;
5 7  
... ... @@ -26,6 +28,10 @@ public interface PostApi {
26 28 List<PostRespDTO> getPostList(Collection<Long> ids);
27 29  
28 30 default Map<Long, PostRespDTO> getPostMap(Collection<Long> ids) {
  31 + if (CollUtil.isEmpty(ids)) {
  32 + return MapUtil.empty();
  33 + }
  34 +
29 35 List<PostRespDTO> list = getPostList(ids);
30 36 return CollectionUtils.convertMap(list, PostRespDTO::getId);
31 37 }
... ...
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;
2 2  
3 3 import lombok.Data;
4 4  
  5 +import java.time.LocalDateTime;
  6 +
5 7 /**
6 8 * 系统操作日志 Resp DTO
7 9 *
... ... @@ -64,4 +66,9 @@ public class OperateLogV2RespDTO {
64 66 */
65 67 private String userAgent;
66 68  
  69 + /**
  70 + * 创建时间
  71 + */
  72 + private LocalDateTime createTime;
  73 +
67 74 }
... ...
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 {
35 35 return BeanUtils.toBean(operateLogPage, OperateLogV2RespDTO.class).setList(setUserInfo(operateLogPage.getList(), userList));
36 36 }
37 37  
38   - private static List<OperateLogV2RespDTO> setUserInfo(List<OperateLogV2DO> logList, List<AdminUserDO> userList) {
  38 + OperateLogV2RespDTO convert(OperateLogV2DO operateLogV2DO);
  39 +
  40 + private List<OperateLogV2RespDTO> setUserInfo(List<OperateLogV2DO> logList, List<AdminUserDO> userList) {
39 41 Map<Long, AdminUserDO> userMap = convertMap(userList, AdminUserDO::getId);
40 42 return CollectionUtils.convertList(logList, item -> {
41   - OperateLogV2RespDTO respDTO = BeanUtils.toBean(item, OperateLogV2RespDTO.class);
  43 + OperateLogV2RespDTO respDTO = convert(item);
42 44 findAndThen(userMap, item.getUserId(), user -> respDTO.setUserName(user.getNickname()));
43 45 return respDTO;
44 46 });
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/operatelog/core/DeptParseFunction.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.framework.operatelog.core;
  2 +
  3 +import cn.hutool.core.util.StrUtil;
  4 +import cn.iocoder.yudao.module.system.api.dept.DeptApi;
  5 +import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
  6 +import com.mzt.logapi.service.IParseFunction;
  7 +import jakarta.annotation.Resource;
  8 +import lombok.extern.slf4j.Slf4j;
  9 +import org.springframework.stereotype.Component;
  10 +
  11 +/**
  12 + * 管理员名字的 {@link IParseFunction} 实现类
  13 + *
  14 + * @author HUIHUI
  15 + */
  16 +@Slf4j
  17 +@Component
  18 +public class DeptParseFunction implements IParseFunction {
  19 +
  20 + @Resource
  21 + private DeptApi deptApi;
  22 +
  23 + @Override
  24 + public String functionName() {
  25 + return "getDeptById";
  26 + }
  27 +
  28 + @Override
  29 + public String apply(Object value) {
  30 + if (StrUtil.isEmptyIfStr(value)) {
  31 + return "";
  32 + }
  33 +
  34 + // 获取部门信息
  35 + DeptRespDTO dept = deptApi.getDept(Long.parseLong(value.toString()));
  36 + if (dept == null) {
  37 + log.warn("[apply][获取部门{{}}为空", value);
  38 + return "";
  39 + }
  40 + return dept.getName();
  41 + }
  42 +
  43 +}
... ...