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

This commit is contained in:
puhui999 2024-01-06 13:48:22 +08:00
parent 9ce50ec369
commit 3170e7fd97
9 changed files with 110 additions and 60 deletions

View File

@ -30,6 +30,22 @@ public interface LogRecordConstants {
String CRM_CUSTOMER_RECEIVE_SUB_TYPE = "{{#ownerUserName != null ? '分配客户' : '领取客户'}}";
String CRM_CUSTOMER_RECEIVE_SUCCESS = "{{#ownerUserName != null ? '将客户【' + #customer.name + '】分配给【' + #ownerUserName + '】' : '领取客户【' + #customer.name + '】'}}";
// ======================= CRM_CUSTOMER_LIMIT_CONFIG 客户限制配置 =======================
String CRM_CUSTOMER_LIMIT_CONFIG_TYPE = "CRM 客户限制配置";
String CRM_CUSTOMER_LIMIT_CONFIG_CREATE_SUB_TYPE = "创建客户限制配置";
String CRM_CUSTOMER_LIMIT_CONFIG_CREATE_SUCCESS = "创建了【{{#limitType}}】类型的客户限制配置";
String CRM_CUSTOMER_LIMIT_CONFIG_UPDATE_SUB_TYPE = "更新客户限制配置";
String CRM_CUSTOMER_LIMIT_CONFIG_UPDATE_SUCCESS = "更新了客户限制配置: {_DIFF{#updateReqVO}}";
String CRM_CUSTOMER_LIMIT_CONFIG_DELETE_SUB_TYPE = "删除客户限制配置";
String CRM_CUSTOMER_LIMIT_CONFIG_DELETE_SUCCESS = "删除了【{{#limitType}}】类型的客户限制配置";
// ======================= CRM_CUSTOMER_POOL_CONFIG 客户公海规则 =======================
String CRM_CUSTOMER_POOL_CONFIG_TYPE = "CRM 客户公海规则";
String CRM_CUSTOMER_POOL_CONFIG_SUB_TYPE = "{{#isPoolConfigUpdate ? '更新客户公海规则' : '创建客户公海规则'}}";
String CRM_CUSTOMER_POOL_CONFIG_SUCCESS = "{{#isPoolConfigUpdate ? '更新了客户公海规则' : '创建了客户公海规则'}}";
// ======================= CRM_CONTACT 联系人 =======================
String CRM_CONTACT_TYPE = "CRM 联系人";

View File

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

View File

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

View File

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

View File

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

View File

@ -2,19 +2,38 @@ package cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig;
import cn.hutool.core.util.BooleanUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mzt.logapi.starter.annotation.DiffLogField;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.util.Objects;
@Schema(description = "管理后台 - CRM 客户公海配置的保存 Request VO")
@Schema(description = "管理后台 - CRM 客户公海配置的创建/更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmCustomerPoolConfigSaveReqVO extends CrmCustomerPoolConfigBaseVO {
public class CrmCustomerPoolConfigSaveReqVO {
@Schema(description = "是否启用客户公海", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@DiffLogField(name = "是否启用客户公海")
@NotNull(message = "是否启用客户公海不能为空")
private Boolean enabled;
@Schema(description = "未跟进放入公海天数", example = "2")
@DiffLogField(name = "未跟进放入公海天数")
private Integer contactExpireDays;
@Schema(description = "未成交放入公海天数", example = "2")
@DiffLogField(name = "未成交放入公海天数")
private Integer dealExpireDays;
@Schema(description = "是否开启提前提醒", example = "true")
@DiffLogField(name = "是否开启提前提醒")
private Boolean notifyEnabled;
@Schema(description = "提前提醒天数", example = "2")
@DiffLogField(name = "提前提醒天数")
private Integer notifyDays;
@AssertTrue(message = "未成交放入公海天数不能为空")
@JsonIgnore

View File

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

View File

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

View File

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