rev:操作日志问题修改
This commit is contained in:
@@ -15,7 +15,7 @@ import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class DataBaseConfig implements TransactionManagementConfigurer {
|
||||
public class DataBaseConfig {
|
||||
|
||||
@Primary
|
||||
@Bean(name = "dataSource")
|
||||
@@ -24,20 +24,4 @@ public class DataBaseConfig implements TransactionManagementConfigurer {
|
||||
return new DruidDataSource();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Resource(name="transactionManager")
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
// 创建事务管理器
|
||||
@Bean(name = "transactionManager")
|
||||
public PlatformTransactionManager transactionManager(DataSource dataSource) {
|
||||
return new DataSourceTransactionManager(dataSource);
|
||||
}
|
||||
|
||||
// 实现接口 TransactionManagementConfigurer 方法,其返回值代表在拥有多个事务管理器的情况下默认使用的事务管理器
|
||||
@Override
|
||||
public PlatformTransactionManager annotationDrivenTransactionManager() {
|
||||
return transactionManager;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,9 +148,9 @@ public class StringUtils {
|
||||
*/
|
||||
public static String getIp(HttpServletRequest request) {
|
||||
// TODO 不解析IP地址
|
||||
if(true){
|
||||
return "127.0.0.1";
|
||||
}
|
||||
// if(true){
|
||||
// return "127.0.0.1";
|
||||
// }
|
||||
|
||||
String ip = request.getHeader("x-forwarded-for");
|
||||
if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.nl.common.utils.IdUtil;
|
||||
import org.nl.modules.common.utils.RequestHolder;
|
||||
import org.nl.modules.common.utils.SecurityUtils;
|
||||
import org.nl.modules.common.utils.StringUtils;
|
||||
import org.nl.modules.common.utils.ThrowableUtil;
|
||||
import org.nl.modules.logging.domain.Log;
|
||||
@@ -93,7 +94,7 @@ public class LogAspect {
|
||||
//是否把日志存到日志表
|
||||
if (logInfo.isAddLogTable()) {
|
||||
Log log = new Log("INFO", System.currentTimeMillis() - startTime);
|
||||
logService.save("", StringUtils.getBrowser(request), requestIp, joinPoint, log);
|
||||
logService.save(getUsername(), StringUtils.getBrowser(request), requestIp, joinPoint, log);
|
||||
}
|
||||
if (logInfo.isInterfaceLog()) {
|
||||
try {
|
||||
@@ -122,7 +123,7 @@ public class LogAspect {
|
||||
log.error("track_id:{},error:{}", trackId, ex.getMessage());
|
||||
Log log = new Log("ERROR", System.currentTimeMillis() - startTime);
|
||||
log.setExceptionDetail(ThrowableUtil.getStackTrace(ex).getBytes());
|
||||
logService.save("", StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log);
|
||||
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log);
|
||||
throw ex;
|
||||
}
|
||||
return result;
|
||||
@@ -158,11 +159,11 @@ public class LogAspect {
|
||||
return argList.size() == 1 ? JSONUtil.toJsonStr(argList.get(0)) : JSONUtil.toJsonStr(argList);
|
||||
}
|
||||
|
||||
// public String getUsername() {
|
||||
// try {
|
||||
// return SecurityUtils.getCurrentUsername();
|
||||
// } catch (Exception e) {
|
||||
// return "";
|
||||
// }
|
||||
// }
|
||||
public String getUsername() {
|
||||
try {
|
||||
return SecurityUtils.getCurrentUsername();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user