CRM-客户:日志表达式调整

This commit is contained in:
puhui999 2024-01-05 17:40:21 +08:00
parent d8bb55fc0b
commit a1c17b9b00
5 changed files with 47 additions and 17 deletions

View File

@ -18,17 +18,17 @@ public interface LogRecordConstants {
String CRM_CUSTOMER_CREATE_SUB_TYPE = "创建客户"; String CRM_CUSTOMER_CREATE_SUB_TYPE = "创建客户";
String CRM_CUSTOMER_CREATE_SUCCESS = "创建了客户{{#customer.name}}"; String CRM_CUSTOMER_CREATE_SUCCESS = "创建了客户{{#customer.name}}";
String CRM_CUSTOMER_UPDATE_SUB_TYPE = "更新客户"; String CRM_CUSTOMER_UPDATE_SUB_TYPE = "更新客户";
String CRM_CUSTOMER_UPDATE_SUCCESS = "更新了客户【{{#customerName}}】{_DIFF{#updateReqVO}}"; String CRM_CUSTOMER_UPDATE_SUCCESS = "更新了客户【{{#customerName}}】: {_DIFF{#updateReqVO}}";
String CRM_CUSTOMER_DELETE_SUB_TYPE = "删除客户"; String CRM_CUSTOMER_DELETE_SUB_TYPE = "删除客户";
String CRM_CUSTOMER_DELETE_SUCCESS = "删除了客户【{{#customerName}}】"; String CRM_CUSTOMER_DELETE_SUCCESS = "删除了客户【{{#customerName}}】";
String CRM_CUSTOMER_TRANSFER_SUB_TYPE = "转移客户"; String CRM_CUSTOMER_TRANSFER_SUB_TYPE = "转移客户";
String CRM_CUSTOMER_TRANSFER_SUCCESS = "将客户【{{#crmCustomer.name}}】的负责人从【{getAdminUserById{#crmCustomer.ownerUserId}}】变更为了【{getAdminUserById{#reqVO.newOwnerUserId}}】"; String CRM_CUSTOMER_TRANSFER_SUCCESS = "将客户【{{#crmCustomer.name}}】的负责人从【{getAdminUserById{#crmCustomer.ownerUserId}}】变更为了【{getAdminUserById{#reqVO.newOwnerUserId}}】";
String CRM_CUSTOMER_LOCK_SUB_TYPE = "{{#crmCustomer.lockStatus ? '锁定客户' : '解锁客户'}}"; String CRM_CUSTOMER_LOCK_SUB_TYPE = "{{#crmCustomer.lockStatus ? '锁定客户' : '解锁客户'}}";
String CRM_CUSTOMER_LOCK_SUCCESS = "{{#crmCustomer.lockStatus ? '将客户【#crmCustomer.name】锁定' : '将客户【#crmCustomer.name】解锁'}}"; String CRM_CUSTOMER_LOCK_SUCCESS = "{{#crmCustomer.lockStatus ? '将客户【' + #crmCustomer.name + '】锁定' : '将客户【' + #crmCustomer.name + '】解锁'}}";
String CRM_CUSTOMER_POOL_SUB_TYPE = "客户放入公海"; String CRM_CUSTOMER_POOL_SUB_TYPE = "客户放入公海";
String CRM_CUSTOMER_POOL_SUCCESS = "将客户【{{#customerName}}】放入了公海"; String CRM_CUSTOMER_POOL_SUCCESS = "将客户【{{#customerName}}】放入了公海";
String CRM_CUSTOMER_RECEIVE_SUB_TYPE = "{{#ownerUserName != null ? '分配客户' : '领取客户'}}"; String CRM_CUSTOMER_RECEIVE_SUB_TYPE = "{{#ownerUserName != null ? '分配客户' : '领取客户'}}";
String CRM_CUSTOMER_RECEIVE_SUCCESS = "{{#ownerUserName != null ? '将客户【#customer.name】分配给【#ownerUserName】' : '领取客户【#customer.name】'}}"; String CRM_CUSTOMER_RECEIVE_SUCCESS = "{{#ownerUserName != null ? '将客户【' + #customer.name + '】分配给【' + #ownerUserName + '】' : '领取客户【' + #customer.name + '】'}}";
// ======================= CRM_CONTACT 联系人 ======================= // ======================= CRM_CONTACT 联系人 =======================

View File

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

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.crm.service.customer;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@ -247,13 +248,15 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
user = adminUserApi.getUser(ownerUserId); user = adminUserApi.getUser(ownerUserId);
} }
for (CrmCustomerDO customer : customers) { for (CrmCustomerDO customer : customers) {
receiveCustomerLog(customer, user == null ? null : user.getNickname()); getSelf().receiveCustomerLog(customer, user == null ? null : user.getNickname());
} }
} }
@LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_RECEIVE_SUB_TYPE, bizNo = "{{#customer.id}}", success = CRM_CUSTOMER_RECEIVE_SUCCESS) @LogRecord(type = CRM_CUSTOMER_TYPE, subType = CRM_CUSTOMER_RECEIVE_SUB_TYPE, bizNo = "{{#customer.id}}", success = CRM_CUSTOMER_RECEIVE_SUCCESS)
public void receiveCustomerLog(CrmCustomerDO customer, String ownerUserName) { public void receiveCustomerLog(CrmCustomerDO customer, String ownerUserName) {
// 记录操作日志上下文
LogRecordContext.putVariable("customer", customer);
LogRecordContext.putVariable("ownerUserName", ownerUserName);
} }
//======================= 查询相关 ======================= //======================= 查询相关 =======================
@ -364,4 +367,14 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
} }
} }
/**
* 获得自身的代理对象解决 AOP 生效问题
*
* @return 自己
*/
private CrmCustomerServiceImpl getSelf() {
return SpringUtil.getBean(getClass());
}
} }

View File

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

View File

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