mirror of
https://gitee.com/y_project/RuoYi-Cloud.git
synced 2026-01-27 20:21:56 +08:00
Compare commits
3 Commits
ad0732c9a5
...
cab8834e3d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cab8834e3d | ||
|
|
8c096cba8d | ||
|
|
a8cdd37871 |
@@ -8,6 +8,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.annotation.Excel.ColumnType;
|
||||
import com.ruoyi.common.core.annotation.Excel.Type;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.core.annotation.Excels;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import com.ruoyi.common.core.xss.Xss;
|
||||
@@ -116,7 +117,7 @@ public class SysUser extends BaseEntity
|
||||
|
||||
public static boolean isAdmin(Long userId)
|
||||
{
|
||||
return userId != null && 1L == userId;
|
||||
return UserConstants.isAdmin(userId);
|
||||
}
|
||||
|
||||
public Long getDeptId()
|
||||
|
||||
@@ -80,4 +80,9 @@ public class UserConstants
|
||||
public static final int PASSWORD_MIN_LENGTH = 5;
|
||||
|
||||
public static final int PASSWORD_MAX_LENGTH = 20;
|
||||
|
||||
public static boolean isAdmin(Long userId)
|
||||
{
|
||||
return userId != null && 1L == userId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.ruoyi.common.core.executor;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* 线程工厂
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class ThreadFactoryImpl implements ThreadFactory {
|
||||
private final AtomicLong threadIndex = new AtomicLong(0);
|
||||
private final String threadNamePrefix;
|
||||
private final boolean daemon;
|
||||
|
||||
public ThreadFactoryImpl(final String threadNamePrefix) {
|
||||
this(threadNamePrefix, false);
|
||||
}
|
||||
|
||||
public ThreadFactoryImpl(final String threadNamePrefix, boolean daemon) {
|
||||
this.threadNamePrefix = threadNamePrefix;
|
||||
this.daemon = daemon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread thread = new Thread(r, threadNamePrefix + this.threadIndex.incrementAndGet());
|
||||
thread.setDaemon(daemon);
|
||||
return thread;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.ruoyi.common.log.service;
|
||||
|
||||
import com.ruoyi.common.core.executor.ThreadFactoryImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -7,6 +10,8 @@ import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.system.api.RemoteLogService;
|
||||
import com.ruoyi.system.api.domain.SysOperLog;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* 异步调用日志服务
|
||||
*
|
||||
@@ -15,15 +20,62 @@ import com.ruoyi.system.api.domain.SysOperLog;
|
||||
@Service
|
||||
public class AsyncLogService
|
||||
{
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AsyncLogService.class);
|
||||
|
||||
private final static ExecutorService logSaveExecutorService = new ThreadPoolExecutor(2,10,10, TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<>(1000),new ThreadFactoryImpl("AsyncLogServiceExecutorService",true),
|
||||
new RejectedExecutionHandler() {
|
||||
//丢弃任务
|
||||
@Override
|
||||
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
|
||||
if (r instanceof AsyncLogService.RunData) {
|
||||
SysOperLog msg = ((AsyncLogService.RunData) r).getData();
|
||||
log.error("保存日志繁忙,丢弃日志:{}",msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@Autowired
|
||||
private RemoteLogService remoteLogService;
|
||||
|
||||
/**
|
||||
* 保存系统日志记录
|
||||
*/
|
||||
@Async
|
||||
public void saveSysLog(SysOperLog sysOperLog) throws Exception
|
||||
{
|
||||
remoteLogService.saveLog(sysOperLog, SecurityConstants.INNER);
|
||||
RunData runData = new RunData();
|
||||
runData.setData(sysOperLog);
|
||||
runData.setRunnable(()->{
|
||||
try {
|
||||
remoteLogService.saveLog(sysOperLog, SecurityConstants.INNER);
|
||||
} catch (Exception e) {
|
||||
log.error("保存日志异常:{}", e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
logSaveExecutorService.execute(runData);
|
||||
}
|
||||
|
||||
|
||||
static class RunData implements Runnable {
|
||||
SysOperLog data = null;
|
||||
Runnable runnable;
|
||||
@Override
|
||||
public void run() {
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
public SysOperLog getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(SysOperLog data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void setRunnable(Runnable runnable) {
|
||||
this.runnable = runnable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- RuoYi Common Security -->
|
||||
<!-- RuoYi Common Core -->
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common-security</artifactId>
|
||||
<artifactId>ruoyi-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -8,10 +8,10 @@ import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.core.context.SecurityContextHolder;
|
||||
import com.ruoyi.common.sensitive.annotation.Sensitive;
|
||||
import com.ruoyi.common.sensitive.enums.DesensitizedType;
|
||||
import com.ruoyi.system.api.model.LoginUser;
|
||||
|
||||
/**
|
||||
* 数据脱敏序列化过滤
|
||||
@@ -55,9 +55,9 @@ public class SensitiveJsonSerializer extends JsonSerializer<String> implements C
|
||||
{
|
||||
try
|
||||
{
|
||||
LoginUser securityUser = SecurityUtils.getLoginUser();
|
||||
Long userId = SecurityContextHolder.getUserId();
|
||||
// 管理员不脱敏
|
||||
return !securityUser.getSysUser().isAdmin();
|
||||
return !UserConstants.isAdmin(userId);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user