Commit 3170e7fd975044816bcf9d5fd9f9732bc240b0b5

Authored by puhui999
1 parent 9ce50ec3

CRM-客户: 简化客户公海配置 VO,完善相关操作日志

yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/LogRecordConstants.java
... ... @@ -30,6 +30,22 @@ public interface LogRecordConstants {
30 30 String CRM_CUSTOMER_RECEIVE_SUB_TYPE = "{{#ownerUserName != null ? '分配客户' : '领取客户'}}";
31 31 String CRM_CUSTOMER_RECEIVE_SUCCESS = "{{#ownerUserName != null ? '将客户【' + #customer.name + '】分配给【' + #ownerUserName + '】' : '领取客户【' + #customer.name + '】'}}";
32 32  
  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 +
33 49 // ======================= CRM_CONTACT 联系人 =======================
34 50  
35 51 String CRM_CONTACT_TYPE = "CRM 联系人";
... ...
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/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/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
... ... @@ -2,19 +2,38 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig;
2 2  
3 3 import cn.hutool.core.util.BooleanUtil;
4 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;
6 7 import jakarta.validation.constraints.AssertTrue;
  8 +import jakarta.validation.constraints.NotNull;
7 9 import lombok.Data;
8   -import lombok.EqualsAndHashCode;
9   -import lombok.ToString;
10 10  
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 {
  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;
18 37  
19 38 @AssertTrue(message = "未成交放入公海天数不能为空")
20 39 @JsonIgnore
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerLimitConfigConvert.java
... ... @@ -2,7 +2,6 @@ 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 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;
... ... @@ -24,8 +23,6 @@ public interface CrmCustomerLimitConfigConvert {
24 23  
25 24 CrmCustomerLimitConfigConvert INSTANCE = Mappers.getMapper(CrmCustomerLimitConfigConvert.class);
26 25  
27   - CrmCustomerLimitConfigDO convert(CrmCustomerLimitConfigCreateReqVO bean);
28   -
29 26 CrmCustomerLimitConfigDO convert(CrmCustomerLimitConfigSaveReqVO bean);
30 27  
31 28 CrmCustomerLimitConfigRespVO convert(CrmCustomerLimitConfigDO bean);
... ...
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerLimitConfigServiceImpl.java
... ... @@ -2,14 +2,19 @@ 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.framework.common.util.object.BeanUtils;
5 6 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigPageReqVO;
6 7 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.limitconfig.CrmCustomerLimitConfigSaveReqVO;
7 8 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerLimitConfigConvert;
8 9 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerLimitConfigDO;
9 10 import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerLimitConfigMapper;
  11 +import cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum;
10 12 import cn.iocoder.yudao.module.system.api.dept.DeptApi;
11 13 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
12 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;
13 18 import jakarta.annotation.Resource;
14 19 import org.springframework.stereotype.Service;
15 20 import org.springframework.validation.annotation.Validated;
... ... @@ -19,6 +24,7 @@ import java.util.List;
19 24  
20 25 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
21 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.*;
22 28  
23 29 /**
24 30 * 客户限制配置 Service 实现类
... ... @@ -38,34 +44,44 @@ public class CrmCustomerLimitConfigServiceImpl implements CrmCustomerLimitConfig
38 44 private AdminUserApi adminUserApi;
39 45  
40 46 @Override
41   - // TODO @puhui999:操作日志
  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)
42 48 public Long createCustomerLimitConfig(CrmCustomerLimitConfigSaveReqVO createReqVO) {
43 49 validateUserAndDept(createReqVO.getUserIds(), createReqVO.getDeptIds());
44 50 // 插入
45 51 CrmCustomerLimitConfigDO customerLimitConfig = CrmCustomerLimitConfigConvert.INSTANCE.convert(createReqVO);
46 52 customerLimitConfigMapper.insert(customerLimitConfig);
  53 +
  54 + // 记录操作日志上下文
  55 + LogRecordContext.putVariable("limitType", CrmCustomerLimitConfigTypeEnum.getNameByType(customerLimitConfig.getType()));
  56 + LogRecordContext.putVariable("limitId", customerLimitConfig.getId());
47 57 // 返回
48 58 return customerLimitConfig.getId();
49 59 }
50 60  
51 61 @Override
52   - // TODO @puhui999:操作日志
  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)
53 63 public void updateCustomerLimitConfig(CrmCustomerLimitConfigSaveReqVO updateReqVO) {
54 64 // 校验存在
55   - validateCustomerLimitConfigExists(updateReqVO.getId());
  65 + CrmCustomerLimitConfigDO oldLimitConfig = validateCustomerLimitConfigExists(updateReqVO.getId());
56 66 validateUserAndDept(updateReqVO.getUserIds(), updateReqVO.getDeptIds());
57 67 // 更新
58 68 CrmCustomerLimitConfigDO updateObj = CrmCustomerLimitConfigConvert.INSTANCE.convert(updateReqVO);
59 69 customerLimitConfigMapper.updateById(updateObj);
  70 +
  71 + // 记录操作日志上下文
  72 + LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldLimitConfig, CrmCustomerLimitConfigSaveReqVO.class));
60 73 }
61 74  
62 75 @Override
63   - // 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)
64 77 public void deleteCustomerLimitConfig(Long id) {
65 78 // 校验存在
66   - validateCustomerLimitConfigExists(id);
  79 + CrmCustomerLimitConfigDO limitConfigDO = validateCustomerLimitConfigExists(id);
67 80 // 删除
68 81 customerLimitConfigMapper.deleteById(id);
  82 +
  83 + // 记录操作日志上下文
  84 + LogRecordContext.putVariable("limitType", CrmCustomerLimitConfigTypeEnum.getNameByType(limitConfigDO.getType()));
69 85 }
70 86  
71 87 @Override
... ... @@ -78,10 +94,12 @@ public class CrmCustomerLimitConfigServiceImpl implements CrmCustomerLimitConfig
78 94 return customerLimitConfigMapper.selectPage(pageReqVO);
79 95 }
80 96  
81   - private void validateCustomerLimitConfigExists(Long id) {
82   - if (customerLimitConfigMapper.selectById(id) == null) {
  97 + private CrmCustomerLimitConfigDO validateCustomerLimitConfigExists(Long id) {
  98 + CrmCustomerLimitConfigDO limitConfigDO = customerLimitConfigMapper.selectById(id);
  99 + if (limitConfigDO == null) {
83 100 throw exception(CUSTOMER_LIMIT_CONFIG_NOT_EXISTS);
84 101 }
  102 + return limitConfigDO;
85 103 }
86 104  
87 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 }
... ...