mirror of https://github.com/elunez/eladmin
Merge branch 'elunez:master' into master
commit
519f8ad38a
|
@ -24,6 +24,12 @@
|
|||
| github | https://github.com/elunez/eladmin | https://github.com/elunez/eladmin-web |
|
||||
| 码云 | https://gitee.com/elunez/eladmin | https://gitee.com/elunez/eladmin-web |
|
||||
|
||||
#### 赞助商 | Sponsor
|
||||
|
||||
<a href="https://www.mingdao.com/?s=utm_79&utm_source=eladmin&utm_medium=banner&utm_campaign=github&utm_content=IT赋能业务" target="_blank">
|
||||
<img src="https://eladmin.vip/images/banner/index.png" alt="明道云零代码构建平台" style="width: 400px;border-radius: 2px;">
|
||||
</a>
|
||||
|
||||
#### 主要特性
|
||||
- 使用最新技术栈,社区资源丰富。
|
||||
- 高效率开发,代码生成器可一键生成前后端代码
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<hutool.version>5.7.22</hutool.version>
|
||||
<hutool.version>5.8.19</hutool.version>
|
||||
</properties>
|
||||
|
||||
<artifactId>eladmin-common</artifactId>
|
||||
|
|
|
@ -26,7 +26,7 @@ import java.util.stream.Collectors;
|
|||
* @author Zheng Jie
|
||||
*/
|
||||
@Service(value = "el")
|
||||
public class ElPermissionConfig {
|
||||
public class AuthorityConfig {
|
||||
|
||||
public Boolean check(String ...permissions){
|
||||
// 获取当前用户的所有权限
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package me.zhengjie.config;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.utils.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @description
|
||||
* @date 2021-11-22
|
||||
**/
|
||||
@Data
|
||||
@Component
|
||||
public class ElAdminProperties {
|
||||
|
||||
public static Boolean ipLocal;
|
||||
|
||||
@Value("${ip.local-parsing}")
|
||||
public void setIpLocal(Boolean ipLocal) {
|
||||
ElAdminProperties.ipLocal = ipLocal;
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
package me.zhengjie.config;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.utils.ElAdminConstant;
|
||||
import me.zhengjie.utils.ElConstant;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
@ -42,9 +42,9 @@ public class FileProperties {
|
|||
|
||||
public ElPath getPath(){
|
||||
String os = System.getProperty("os.name");
|
||||
if(os.toLowerCase().startsWith(ElAdminConstant.WIN)) {
|
||||
if(os.toLowerCase().startsWith(ElConstant.WIN)) {
|
||||
return windows;
|
||||
} else if(os.toLowerCase().startsWith(ElAdminConstant.MAC)){
|
||||
} else if(os.toLowerCase().startsWith(ElConstant.MAC)){
|
||||
return mac;
|
||||
}
|
||||
return linux;
|
||||
|
|
|
@ -21,12 +21,7 @@ package me.zhengjie.utils;
|
|||
* @author Zheng Jie
|
||||
* @date 2018-12-26
|
||||
*/
|
||||
public class ElAdminConstant {
|
||||
|
||||
/**
|
||||
* 用于IP定位转换
|
||||
*/
|
||||
public static final String REGION = "内网IP|内网IP";
|
||||
public class ElConstant {
|
||||
/**
|
||||
* win 系统
|
||||
*/
|
||||
|
@ -36,12 +31,4 @@ public class ElAdminConstant {
|
|||
* mac 系统
|
||||
*/
|
||||
public static final String MAC = "mac";
|
||||
|
||||
/**
|
||||
* 常用接口
|
||||
*/
|
||||
public static class Url {
|
||||
// IP归属地查询
|
||||
public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp?ip=%s&json=true";
|
||||
}
|
||||
}
|
|
@ -15,11 +15,7 @@
|
|||
*/
|
||||
package me.zhengjie.utils;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhengjie.config.ElAdminProperties;
|
||||
import net.dreamlu.mica.ip2region.core.Ip2regionSearcher;
|
||||
import net.dreamlu.mica.ip2region.core.IpInfo;
|
||||
import nl.basjes.parse.useragent.UserAgent;
|
||||
|
@ -174,32 +170,11 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||
* 根据ip获取详细地址
|
||||
*/
|
||||
public static String getCityInfo(String ip) {
|
||||
if (ElAdminProperties.ipLocal) {
|
||||
return getLocalCityInfo(ip);
|
||||
} else {
|
||||
return getHttpCityInfo(ip);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ip获取详细地址
|
||||
*/
|
||||
public static String getHttpCityInfo(String ip) {
|
||||
String api = String.format(ElAdminConstant.Url.IP_URL, ip);
|
||||
JSONObject object = JSONUtil.parseObj(HttpUtil.get(api));
|
||||
return object.get("addr", String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ip获取详细地址
|
||||
*/
|
||||
public static String getLocalCityInfo(String ip) {
|
||||
IpInfo ipInfo = IP_SEARCHER.memorySearch(ip);
|
||||
if(ipInfo != null){
|
||||
return ipInfo.getAddress();
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static String getBrowser(HttpServletRequest request) {
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package me.zhengjie.config.thread;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.AsyncConfigurer;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* 异步任务线程池装配类
|
||||
* @author https://juejin.im/entry/5abb8f6951882555677e9da2
|
||||
* @date 2019年10月31日15:06:18
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class AsyncTaskExecutePool implements AsyncConfigurer {
|
||||
|
||||
@Override
|
||||
public Executor getAsyncExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
//核心线程池大小
|
||||
executor.setCorePoolSize(AsyncTaskProperties.corePoolSize);
|
||||
//最大线程数
|
||||
executor.setMaxPoolSize(AsyncTaskProperties.maxPoolSize);
|
||||
//队列容量
|
||||
executor.setQueueCapacity(AsyncTaskProperties.queueCapacity);
|
||||
//活跃时间
|
||||
executor.setKeepAliveSeconds(AsyncTaskProperties.keepAliveSeconds);
|
||||
//线程工厂
|
||||
executor.setThreadFactory(new TheadFactoryName("el-async"));
|
||||
// setRejectedExecutionHandler:当pool已经达到max size的时候,如何处理新任务
|
||||
// CallerRunsPolicy:不在新线程中执行任务,而是由调用者所在的线程来执行
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
|
||||
return (throwable, method, objects) -> {
|
||||
log.error("===="+throwable.getMessage()+"====", throwable);
|
||||
log.error("exception method:"+method.getName());
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package me.zhengjie.config.thread;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* 创建自定义的线程池
|
||||
* @author Zheng Jie
|
||||
* @description
|
||||
* @date 2023-06-08
|
||||
**/
|
||||
@Configuration
|
||||
public class CustomExecutorConfig {
|
||||
|
||||
/**
|
||||
* 自定义线程池,用法 @Async
|
||||
* @return Executor
|
||||
*/
|
||||
@Bean
|
||||
@Primary
|
||||
public Executor elAsync() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(AsyncTaskProperties.corePoolSize);
|
||||
executor.setMaxPoolSize(AsyncTaskProperties.maxPoolSize);
|
||||
executor.setQueueCapacity(AsyncTaskProperties.queueCapacity);
|
||||
executor.setThreadNamePrefix("el-async-");
|
||||
executor.setKeepAliveSeconds(AsyncTaskProperties.keepAliveSeconds);
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义线程池,用法 @Async("otherAsync")
|
||||
* @return Executor
|
||||
*/
|
||||
@Bean
|
||||
public Executor otherAsync() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(15);
|
||||
executor.setQueueCapacity(50);
|
||||
executor.setKeepAliveSeconds(AsyncTaskProperties.keepAliveSeconds);
|
||||
executor.setThreadNamePrefix("el-task-");
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* 自定义线程名称
|
||||
* @author Zheng Jie
|
||||
* @date 2019年10月31日17:49:55
|
||||
*/
|
||||
@Component
|
||||
public class TheadFactoryName implements ThreadFactory {
|
||||
|
||||
private static final AtomicInteger POOL_NUMBER = new AtomicInteger(1);
|
||||
private final ThreadGroup group;
|
||||
private final AtomicInteger threadNumber = new AtomicInteger(1);
|
||||
private final String namePrefix;
|
||||
|
||||
private final static String DEF_NAME = "el-pool-";
|
||||
|
||||
public TheadFactoryName() {
|
||||
this(DEF_NAME);
|
||||
}
|
||||
|
||||
public TheadFactoryName(String name){
|
||||
SecurityManager s = System.getSecurityManager();
|
||||
group = (s != null) ? s.getThreadGroup() :
|
||||
Thread.currentThread().getThreadGroup();
|
||||
//此时namePrefix就是 name + 第几个用这个工厂创建线程池的
|
||||
this.namePrefix = (StringUtils.isNotBlank(name) ? name : DEF_NAME) + "-" + POOL_NUMBER.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
//此时线程的名字 就是 namePrefix + -exec- + 这个线程池中第几个执行的线程
|
||||
Thread t = new Thread(group, r,
|
||||
namePrefix + "-exec-"+threadNumber.getAndIncrement(),
|
||||
0);
|
||||
if (t.isDaemon()) {
|
||||
t.setDaemon(false);
|
||||
}
|
||||
if (t.getPriority() != Thread.NORM_PRIORITY) {
|
||||
t.setPriority(Thread.NORM_PRIORITY);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* 用于获取自定义线程池
|
||||
* @author Zheng Jie
|
||||
* @date 2019年10月31日18:16:47
|
||||
*/
|
||||
public class ThreadPoolExecutorUtil {
|
||||
|
||||
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(threadName),
|
||||
// 队列与线程池中线程都满了时使用调用者所在的线程来执行
|
||||
new ThreadPoolExecutor.CallerRunsPolicy()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -19,7 +19,6 @@ 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;
|
||||
|
@ -33,21 +32,24 @@ 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.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* 参考人人开源,https://gitee.com/renrenio/renren-security
|
||||
* 参考人人开源,<a href="https://gitee.com/renrenio/renren-security">...</a>
|
||||
* @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");
|
||||
private final ThreadPoolTaskExecutor executor = SpringContextHolder.getBean("elAsync");
|
||||
|
||||
@Override
|
||||
public void executeInternal(JobExecutionContext context) {
|
||||
|
|
|
@ -18,7 +18,7 @@ package me.zhengjie.modules.system.service.impl;
|
|||
import cn.hutool.core.date.BetweenFormatter.Level;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import me.zhengjie.modules.system.service.MonitorService;
|
||||
import me.zhengjie.utils.ElAdminConstant;
|
||||
import me.zhengjie.utils.ElConstant;
|
||||
import me.zhengjie.utils.FileUtil;
|
||||
import me.zhengjie.utils.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -78,7 +78,7 @@ public class MonitorServiceImpl implements MonitorService {
|
|||
long available = 0, total = 0;
|
||||
for (OSFileStore fs : fsArray){
|
||||
// windows 需要将所有磁盘分区累加,linux 和 mac 直接累加会出现磁盘重复的问题,待修复
|
||||
if(osName.toLowerCase().startsWith(ElAdminConstant.WIN)) {
|
||||
if(osName.toLowerCase().startsWith(ElConstant.WIN)) {
|
||||
available += fs.getUsableSpace();
|
||||
total += fs.getTotalSpace();
|
||||
} else {
|
||||
|
|
|
@ -100,10 +100,6 @@ generator:
|
|||
swagger:
|
||||
enabled: true
|
||||
|
||||
# IP 本地解析
|
||||
ip:
|
||||
local-parsing: true
|
||||
|
||||
# 文件存储路径
|
||||
file:
|
||||
mac:
|
||||
|
|
|
@ -94,10 +94,6 @@ jwt:
|
|||
# 续期时间范围,默认 1小时,这里单位毫秒
|
||||
renew: 3600000
|
||||
|
||||
# IP 本地解析
|
||||
ip:
|
||||
local-parsing: true
|
||||
|
||||
#是否允许生成代码,生产环境设置为false
|
||||
generator:
|
||||
enabled: false
|
||||
|
|
3
pom.xml
3
pom.xml
|
@ -121,12 +121,11 @@
|
|||
<version>${druid.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- ip2region IP库 -->
|
||||
<!-- https://mvnrepository.com/artifact/net.dreamlu/mica-ip2region -->
|
||||
<dependency>
|
||||
<groupId>net.dreamlu</groupId>
|
||||
<artifactId>mica-ip2region</artifactId>
|
||||
<version>2.6.3</version>
|
||||
<version>2.7.12</version>
|
||||
</dependency>
|
||||
|
||||
<!--lombok插件-->
|
||||
|
|
Loading…
Reference in New Issue