3 Commits

Author SHA1 Message Date
imalasong
ad0732c9a5 Pre Merge pull request !384 from imalasong/pr/1 2025-03-06 03:10:14 +00:00
RuoYi
088cec8adf 菜单管理新增路由名称 2025-03-06 11:09:34 +08:00
xiaochangbai
a8cdd37871 opt:优化日志保存操作 2024-11-20 12:13:50 +08:00
3 changed files with 100 additions and 6 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
}
}

View File

@@ -130,7 +130,7 @@
</el-col>
</el-row>
<el-row>
<el-col :span="24" v-if="form.menuType != 'F'">
<el-col :span="12" v-if="form.menuType != 'F'">
<el-form-item label="菜单图标" prop="icon">
<el-popover
placement="bottom-start"
@@ -151,6 +151,11 @@
</el-popover>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="显示排序" prop="orderNum">
<el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
@@ -158,9 +163,15 @@
<el-input v-model="form.menuName" placeholder="请输入菜单名称" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="显示排序" prop="orderNum">
<el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
<el-col :span="12" v-if="form.menuType == 'C'">
<el-form-item prop="routeName">
<el-input v-model="form.routeName" placeholder="请输入路由名称" />
<span slot="label">
<el-tooltip content="默认不填则和路由地址相同:如地址为:`user`,则名称为`User`(注意:为避免名字的冲突,特殊情况下请自定义,保证唯一性)" placement="top">
<i class="el-icon-question"></i>
</el-tooltip>
路由名称
</span>
</el-form-item>
</el-col>
</el-row>