update 替换BeanCopyUtil用法使用mapstruct

This commit is contained in:
Yjoioooo
2023-04-26 17:11:20 +08:00
parent 5777e8c5ad
commit 49a8e2fd8f
12 changed files with 183 additions and 16 deletions

View File

@@ -0,0 +1,25 @@
package org.dromara.common.log.domain.convert;
import org.dromara.common.log.event.OperLogEvent;
import org.dromara.system.api.domain.bo.RemoteOperLogBo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
/**
* 操作日志转换器
* @author zhujie
*/
@Mapper
public interface OperLogEventConvert {
OperLogEventConvert INSTANCE = Mappers.getMapper(OperLogEventConvert.class);
/**
* OperLogEventToRemoteOperLogBo
* @param operLogEvent 待转换对象
* @return 转换后对象
*/
@Mapping(target = "params", ignore = true)
RemoteOperLogBo convert(OperLogEvent operLogEvent);
}

View File

@@ -5,10 +5,10 @@ import cn.hutool.http.useragent.UserAgentUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.common.core.constant.Constants;
import org.dromara.common.core.utils.BeanCopyUtils;
import org.dromara.common.core.utils.ServletUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.core.utils.ip.AddressUtils;
import org.dromara.common.log.domain.convert.OperLogEventConvert;
import org.dromara.system.api.RemoteLogService;
import org.dromara.system.api.domain.bo.RemoteLogininforBo;
import org.dromara.system.api.domain.bo.RemoteOperLogBo;
@@ -36,7 +36,7 @@ public class LogEventListener {
@Async
@EventListener
public void saveLog(OperLogEvent operLogEvent) {
RemoteOperLogBo sysOperLog = BeanCopyUtils.copy(operLogEvent, RemoteOperLogBo.class);
RemoteOperLogBo sysOperLog = OperLogEventConvert.INSTANCE.convert(operLogEvent);
remoteLogService.saveLog(sysOperLog);
}