Merge branch 'master' into deploy

pull/789/head
Zheng Jie 2022-07-04 11:47:25 +08:00
commit 924c8a06b7
7 changed files with 30 additions and 18 deletions

View File

@ -276,7 +276,8 @@ public class GenUtil {
// 主键存在字典
if (StringUtils.isNotBlank(column.getDictName())) {
genMap.put("hasDict", true);
dicts.add(column.getDictName());
if(!dicts.contains(column.getDictName()))
dicts.add(column.getDictName());
}
// 存储字段类型

View File

@ -43,8 +43,8 @@ public class AsyncTaskExecutePool implements AsyncConfigurer {
executor.setQueueCapacity(AsyncTaskProperties.queueCapacity);
//活跃时间
executor.setKeepAliveSeconds(AsyncTaskProperties.keepAliveSeconds);
//线程名字前缀
executor.setThreadNamePrefix("el-async-");
//线程工厂
executor.setThreadFactory(new TheadFactoryName("el-async"));
// setRejectedExecutionHandler当pool已经达到max size的时候如何处理新任务
// CallerRunsPolicy不在新线程中执行任务而是由调用者所在的线程来执行
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());

View File

@ -15,8 +15,8 @@
*/
package me.zhengjie.config.thread;
import me.zhengjie.utils.StringUtils;
import org.springframework.stereotype.Component;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
@ -33,24 +33,25 @@ public class TheadFactoryName implements ThreadFactory {
private final AtomicInteger threadNumber = new AtomicInteger(1);
private final String namePrefix;
private final static String DEF_NAME = "el-pool-";
public TheadFactoryName() {
this("el-pool");
this(DEF_NAME);
}
private TheadFactoryName(String name){
public TheadFactoryName(String name){
SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() :
Thread.currentThread().getThreadGroup();
//此时namePrefix就是 name + 第几个用这个工厂创建线程池的
this.namePrefix = name +
POOL_NUMBER.getAndIncrement();
this.namePrefix = (StringUtils.isNotBlank(name) ? name : DEF_NAME) + "-" + POOL_NUMBER.getAndIncrement();
}
@Override
public Thread newThread(Runnable r) {
//此时线程的名字 就是 namePrefix + -thread- + 这个线程池中第几个执行的线程
//此时线程的名字 就是 namePrefix + -exec- + 这个线程池中第几个执行的线程
Thread t = new Thread(group, r,
namePrefix + "-thread-"+threadNumber.getAndIncrement(),
namePrefix + "-exec-"+threadNumber.getAndIncrement(),
0);
if (t.isDaemon()) {
t.setDaemon(false);

View File

@ -16,6 +16,7 @@
package me.zhengjie.config.thread;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@ -26,14 +27,20 @@ import java.util.concurrent.TimeUnit;
*/
public class ThreadPoolExecutorUtil {
public static ThreadPoolExecutor getPoll(){
public static ExecutorService getPoll(){
return getPoll(null);
}
public static ExecutorService getPoll(String threadName){
return new ThreadPoolExecutor(
AsyncTaskProperties.corePoolSize,
AsyncTaskProperties.maxPoolSize,
AsyncTaskProperties.keepAliveSeconds,
TimeUnit.SECONDS,
new ArrayBlockingQueue<>(AsyncTaskProperties.queueCapacity),
new TheadFactoryName()
new TheadFactoryName(threadName),
// 队列与线程池中线程都满了时使用调用者所在的线程来执行
new ThreadPoolExecutor.CallerRunsPolicy()
);
}
}

View File

@ -19,6 +19,7 @@ import cn.hutool.extra.template.Template;
import cn.hutool.extra.template.TemplateConfig;
import cn.hutool.extra.template.TemplateEngine;
import cn.hutool.extra.template.TemplateUtil;
import me.zhengjie.config.thread.ThreadPoolExecutorUtil;
import me.zhengjie.domain.vo.EmailVo;
import me.zhengjie.modules.quartz.domain.QuartzJob;
import me.zhengjie.modules.quartz.domain.QuartzLog;
@ -32,7 +33,6 @@ import me.zhengjie.utils.ThrowableUtil;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.quartz.QuartzJobBean;
import java.util.*;
import java.util.concurrent.*;
@ -42,15 +42,15 @@ import java.util.concurrent.*;
* @author /
* @date 2019-01-07
*/
@Async
public class ExecutionJob extends QuartzJobBean {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
// 此处仅供参考,可根据任务执行情况自定义线程池参数
private final static ExecutorService executor = ThreadPoolExecutorUtil.getPoll("el-quartz-job");
@Override
public void executeInternal(JobExecutionContext context) {
// 创建单个线程
ExecutorService executor = Executors.newSingleThreadExecutor();
// 获取任务
QuartzJob quartzJob = (QuartzJob) context.getMergedJobDataMap().get(QuartzJob.JOB_KEY);
// 获取spring bean
@ -112,7 +112,6 @@ public class ExecutionJob extends QuartzJobBean {
}
} finally {
quartzLogRepository.save(log);
executor.shutdown();
}
}

View File

@ -43,7 +43,7 @@ public class DataServiceImpl implements DataService {
private final DeptService deptService;
/**
*
*
* @param user /
* @return /
*/

View File

@ -119,6 +119,10 @@ public class UserServiceImpl implements UserService {
redisUtils.del(CacheKey.MENU_USER + resources.getId());
redisUtils.del(CacheKey.ROLE_AUTH + resources.getId());
}
// 修改部门会影响 数据权限
if (!Objects.equals(resources.getDept(),user.getDept())) {
redisUtils.del(CacheKey.DATA_USER + resources.getId());
}
// 如果用户被禁用,则清除用户登录信息
if(!resources.getEnabled()){
onlineUserService.kickOutForUsername(resources.getUsername());