update 优化 使用spring事件发布机制 重构登录日志与操作日志
parent
fd83d6bc0a
commit
4092013da5
@ -0,0 +1,40 @@
|
||||
package com.ruoyi.common.log.event;
|
||||
|
||||
import com.ruoyi.common.core.utils.BeanCopyUtils;
|
||||
import com.ruoyi.system.api.RemoteLogService;
|
||||
import com.ruoyi.system.api.domain.SysLogininfor;
|
||||
import com.ruoyi.system.api.domain.SysOperLog;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 异步调用日志服务
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class LogEventListener {
|
||||
|
||||
@DubboReference
|
||||
private RemoteLogService remoteLogService;
|
||||
|
||||
/**
|
||||
* 保存系统日志记录
|
||||
*/
|
||||
@Async
|
||||
@EventListener
|
||||
public void saveLog(OperLogEvent operLogEvent) {
|
||||
SysOperLog sysOperLog = BeanCopyUtils.copy(operLogEvent, SysOperLog.class);
|
||||
remoteLogService.saveLog(sysOperLog);
|
||||
}
|
||||
|
||||
@Async
|
||||
@EventListener
|
||||
public void saveLogininfor(LogininforEvent logininforEvent) {
|
||||
SysLogininfor sysLogininfor = BeanCopyUtils.copy(logininforEvent, SysLogininfor.class);
|
||||
remoteLogService.saveLogininfor(sysLogininfor);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.ruoyi.common.log.event;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 登录事件
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class LogininforEvent implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 登录状态 0成功 1失败
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* ip地址
|
||||
*/
|
||||
private String ipaddr;
|
||||
|
||||
/**
|
||||
* 提示消息
|
||||
*/
|
||||
private String msg;
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.ruoyi.common.log.service;
|
||||
|
||||
import com.ruoyi.system.api.RemoteLogService;
|
||||
import com.ruoyi.system.api.domain.SysOperLog;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 异步调用日志服务
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class AsyncLogService {
|
||||
|
||||
@DubboReference
|
||||
private RemoteLogService remoteLogService;
|
||||
|
||||
/**
|
||||
* 保存系统日志记录
|
||||
*/
|
||||
@Async
|
||||
public void saveSysLog(SysOperLog sysOperLog) {
|
||||
remoteLogService.saveLog(sysOperLog);
|
||||
}
|
||||
}
|
@ -1,2 +1,2 @@
|
||||
com.ruoyi.common.log.service.AsyncLogService
|
||||
com.ruoyi.common.log.event.LogEventListener
|
||||
com.ruoyi.common.log.aspect.LogAspect
|
||||
|
Loading…
Reference in New Issue