系统操作日志:集成 mzt-biz-log
parent
72cebfca14
commit
c5cc818a49
@ -0,0 +1,18 @@
|
|||||||
|
package cn.iocoder.yudao.module.crm.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CRM 操作日志枚举
|
||||||
|
*
|
||||||
|
* @author HUIHUI
|
||||||
|
*/
|
||||||
|
public interface LogRecordConstants {
|
||||||
|
|
||||||
|
String WHO = "【{getAdminUserById{#userId}}】";
|
||||||
|
|
||||||
|
//======================= 客户转移操作日志 =======================
|
||||||
|
|
||||||
|
String TRANSFER_CUSTOMER_LOG_TYPE = "客户转移";
|
||||||
|
String TRANSFER_CUSTOMER_LOG_SUCCESS = WHO + "把客户【{{#crmCustomer.name}}】负责人【{getAdminUserById{#crmCustomer.ownerUserId}}】转移给了【{getAdminUserById{#reqVO.newOwnerUserId}}】";
|
||||||
|
String TRANSFER_CUSTOMER_LOG_FAIL = "";
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,6 +1,13 @@
|
|||||||
### 请求 /update
|
### 请求 /transfer
|
||||||
GET {{baseUrl}}/crm/customer/page?pageNo=1&pageSize=10&name="张三"
|
PUT {{baseUrl}}/crm/customer/transfer
|
||||||
|
Content-Type: application/json
|
||||||
Authorization: Bearer {{token}}
|
Authorization: Bearer {{token}}
|
||||||
tenant-id: {{adminTenentId}}
|
tenant-id: {{adminTenentId}}
|
||||||
|
|
||||||
|
{
|
||||||
|
"id": 11,
|
||||||
|
"newOwnerUserId": 127,
|
||||||
|
"oldOwnerPermissionLevel": 2
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,31 @@
|
|||||||
|
package cn.iocoder.yudao.module.system.dal.mysql.logger;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
|
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogV2DO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface OperateLogV2Mapper extends BaseMapperX<OperateLogV2DO> {
|
||||||
|
|
||||||
|
default PageResult<OperateLogV2DO> selectPage(OperateLogPageReqVO reqVO, Collection<Long> userIds) {
|
||||||
|
LambdaQueryWrapperX<OperateLogV2DO> query = new LambdaQueryWrapperX<OperateLogV2DO>()
|
||||||
|
.likeIfPresent(OperateLogV2DO::getModule, reqVO.getModule())
|
||||||
|
.inIfPresent(OperateLogV2DO::getUserId, userIds)
|
||||||
|
.eqIfPresent(OperateLogV2DO::getType, reqVO.getType())
|
||||||
|
.betweenIfPresent(OperateLogV2DO::getStartTime, reqVO.getStartTime());
|
||||||
|
if (Boolean.TRUE.equals(reqVO.getSuccess())) {
|
||||||
|
query.eq(OperateLogV2DO::getResultCode, GlobalErrorCodeConstants.SUCCESS.getCode());
|
||||||
|
} else if (Boolean.FALSE.equals(reqVO.getSuccess())) {
|
||||||
|
query.gt(OperateLogV2DO::getResultCode, GlobalErrorCodeConstants.SUCCESS.getCode());
|
||||||
|
}
|
||||||
|
query.orderByDesc(OperateLogV2DO::getId); // 降序
|
||||||
|
return selectPage(reqVO, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
package cn.iocoder.yudao.module.system.framework.bizlog.config;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
|
||||||
|
import cn.iocoder.yudao.module.system.api.logger.OperateLogApi;
|
||||||
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||||
|
import cn.iocoder.yudao.module.system.framework.bizlog.service.AdminUserParseFunction;
|
||||||
|
import cn.iocoder.yudao.module.system.framework.bizlog.service.ILogRecordServiceImpl;
|
||||||
|
import com.mzt.logapi.beans.Operator;
|
||||||
|
import com.mzt.logapi.service.IOperatorGetService;
|
||||||
|
import com.mzt.logapi.starter.annotation.EnableLogRecord;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用 @Configuration 是因为 mzt-biz-log 的配置类是 @Configuration 的
|
||||||
|
*
|
||||||
|
* @author HUIHUI
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@EnableLogRecord(tenant = "${yudao.info.base-package}")
|
||||||
|
@Slf4j
|
||||||
|
public class YudaoOperateLogV2Configuration {
|
||||||
|
|
||||||
|
//======================= mzt-biz-log =======================
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ILogRecordServiceImpl iLogRecordServiceImpl(OperateLogApi operateLogApi) {
|
||||||
|
log.info("ILogRecordServiceImpl 初始化");
|
||||||
|
return new ILogRecordServiceImpl(operateLogApi);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public IOperatorGetService operatorGetLoginUserIdService() {
|
||||||
|
// 获取操作用户编号
|
||||||
|
return () -> Optional.of(WebFrameworkUtils.getLoginUserId())
|
||||||
|
.map(a -> {
|
||||||
|
Operator operator = new Operator();
|
||||||
|
operator.setOperatorId(a.toString());
|
||||||
|
return operator;
|
||||||
|
})
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("user is null"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public AdminUserParseFunction adminUserParseFunction(AdminUserApi adminUserApi) {
|
||||||
|
return new AdminUserParseFunction(adminUserApi);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
package cn.iocoder.yudao.module.system.framework.bizlog;
|
||||||
@ -0,0 +1,56 @@
|
|||||||
|
package cn.iocoder.yudao.module.system.framework.bizlog.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||||
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||||
|
import com.mzt.logapi.service.IParseFunction;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义函数-通过用户编号获取用户信息
|
||||||
|
*
|
||||||
|
* @author HUIHUI
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class AdminUserParseFunction implements IParseFunction {
|
||||||
|
|
||||||
|
private final AdminUserApi adminUserApi;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean executeBefore() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String functionName() {
|
||||||
|
return "getAdminUserById";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apply(Object value) {
|
||||||
|
if (value == null) {
|
||||||
|
log.warn("(getAdminUserById) 解析异常参数为 null");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (StrUtil.isEmpty(value.toString())) {
|
||||||
|
log.warn("(getAdminUserById) 解析异常参数为空");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取用户信息
|
||||||
|
AdminUserRespDTO user = adminUserApi.getUser(Long.parseLong(value.toString()));
|
||||||
|
if (user == null) {
|
||||||
|
log.warn("(getAdminUserById) 获取用户信息失败,参数为:{}", value);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
// 返回格式 芋道源码(13888888888)
|
||||||
|
String nickname = user.getNickname();
|
||||||
|
if (ObjUtil.isNotEmpty(user.getMobile())) {
|
||||||
|
return nickname.concat("(").concat(user.getMobile()).concat(")");
|
||||||
|
}
|
||||||
|
return nickname;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue