系统操作日志:集成 mzt-biz-log 2

This commit is contained in:
puhui999 2023-12-12 22:42:50 +08:00
parent c5cc818a49
commit 13d6c42a48
4 changed files with 13 additions and 46 deletions

View File

@ -135,7 +135,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
public void transferCustomer(CrmCustomerTransferReqVO reqVO, Long userId) {
// 1. 校验客户是否存在
validateCustomer(reqVO.getId());
// 添加 crmCustomer 到日志上下文
LogRecordContext.putVariable("crmCustomer", customerMapper.selectById(reqVO.getId()));
// 2.1 数据权限转移
crmPermissionService.transferPermission(

View File

@ -1,53 +1,16 @@
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);
}
}

View File

@ -1,12 +1,13 @@
package cn.iocoder.yudao.module.system.framework.bizlog.service;
package cn.iocoder.yudao.module.system.framework.bizlog.function;
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 jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 自定义函数-通过用户编号获取用户信息
@ -14,10 +15,11 @@ import lombok.extern.slf4j.Slf4j;
* @author HUIHUI
*/
@Slf4j
@RequiredArgsConstructor
@Component
public class AdminUserParseFunction implements IParseFunction {
private final AdminUserApi adminUserApi;
@Resource
private AdminUserApi adminUserApi;
@Override
public boolean executeBefore() {

View File

@ -3,8 +3,9 @@ package cn.iocoder.yudao.module.system.framework.bizlog.service;
import cn.iocoder.yudao.module.system.api.logger.OperateLogApi;
import com.mzt.logapi.beans.LogRecord;
import com.mzt.logapi.service.ILogRecordService;
import lombok.RequiredArgsConstructor;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
@ -17,10 +18,11 @@ import java.util.List;
* @author HUIHUI
*/
@Slf4j
@RequiredArgsConstructor
@Service
public class ILogRecordServiceImpl implements ILogRecordService {
private final OperateLogApi operateLogApi;
@Resource
private OperateLogApi operateLogApi;
@Override
public void record(LogRecord logRecord) {