mirror of https://github.com/elunez/eladmin
parent
6d964982d5
commit
694099fc26
|
@ -21,6 +21,8 @@ import cn.hutool.poi.excel.BigExcelWriter;
|
||||||
import cn.hutool.poi.excel.ExcelUtil;
|
import cn.hutool.poi.excel.ExcelUtil;
|
||||||
import me.zhengjie.exception.BadRequestException;
|
import me.zhengjie.exception.BadRequestException;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
|
@ -41,7 +43,20 @@ import java.util.Map;
|
||||||
* @date 2018-12-27
|
* @date 2018-12-27
|
||||||
*/
|
*/
|
||||||
public class FileUtil extends cn.hutool.core.io.FileUtil {
|
public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(FileUtil.class);
|
||||||
|
/**
|
||||||
|
* 系统临时目录
|
||||||
|
* <br>
|
||||||
|
* windows 包含路径分割符,但Linux 不包含,
|
||||||
|
* 在windows \\==\ 前提下,
|
||||||
|
* 为安全起见 同意拼装 路径分割符,
|
||||||
|
* <pre>
|
||||||
|
* java.io.tmpdir
|
||||||
|
* windows : C:\Users/xxx\AppData\Local\Temp\
|
||||||
|
* linux: /temp
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public static final String SYS_TEM_DIR = System.getProperty("java.io.tmpdir") + File.separator;
|
||||||
/**
|
/**
|
||||||
* 定义GB的计算常量
|
* 定义GB的计算常量
|
||||||
*/
|
*/
|
||||||
|
@ -75,7 +90,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
// MultipartFile to File
|
// MultipartFile to File
|
||||||
multipartFile.transferTo(file);
|
multipartFile.transferTo(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +145,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
* inputStream 转 File
|
* inputStream 转 File
|
||||||
*/
|
*/
|
||||||
static File inputStreamToFile(InputStream ins, String name) throws Exception {
|
static File inputStreamToFile(InputStream ins, String name) throws Exception {
|
||||||
File file = new File(System.getProperty("java.io.tmpdir") + File.separator + name);
|
File file = new File(SYS_TEM_DIR + name);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
@ -170,7 +185,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
file.transferTo(dest);
|
file.transferTo(dest);
|
||||||
return dest;
|
return dest;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -179,7 +194,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
* 导出excel
|
* 导出excel
|
||||||
*/
|
*/
|
||||||
public static void downloadExcel(List<Map<String, Object>> list, HttpServletResponse response) throws IOException {
|
public static void downloadExcel(List<Map<String, Object>> list, HttpServletResponse response) throws IOException {
|
||||||
String tempPath = System.getProperty("java.io.tmpdir") + IdUtil.fastSimpleUUID() + ".xlsx";
|
String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx";
|
||||||
File file = new File(tempPath);
|
File file = new File(tempPath);
|
||||||
BigExcelWriter writer = ExcelUtil.getBigWriter(file);
|
BigExcelWriter writer = ExcelUtil.getBigWriter(file);
|
||||||
// 一次性写出内容,使用默认样式,强制输出标题
|
// 一次性写出内容,使用默认样式,强制输出标题
|
||||||
|
@ -246,10 +261,10 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
try {
|
try {
|
||||||
System.out.println(in.read(b));
|
System.out.println(in.read(b));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return b;
|
return b;
|
||||||
|
@ -272,7 +287,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
}
|
}
|
||||||
return new String(str);
|
return new String(str);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -294,7 +309,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
IOUtils.copy(fis, response.getOutputStream());
|
IOUtils.copy(fis, response.getOutputStream());
|
||||||
response.flushBuffer();
|
response.flushBuffer();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
if (fis != null) {
|
if (fis != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -303,7 +318,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
file.deleteOnExit();
|
file.deleteOnExit();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,12 +15,15 @@
|
||||||
*/
|
*/
|
||||||
package me.zhengjie.utils;
|
package me.zhengjie.utils;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.data.redis.connection.RedisConnection;
|
import org.springframework.data.redis.connection.RedisConnection;
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
import org.springframework.data.redis.core.*;
|
import org.springframework.data.redis.core.*;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -30,7 +33,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
@Component
|
@Component
|
||||||
@SuppressWarnings({"unchecked", "all"})
|
@SuppressWarnings({"unchecked", "all"})
|
||||||
public class RedisUtils {
|
public class RedisUtils {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(RedisUtils.class);
|
||||||
private RedisTemplate<Object, Object> redisTemplate;
|
private RedisTemplate<Object, Object> redisTemplate;
|
||||||
@Value("${jwt.online-key}")
|
@Value("${jwt.online-key}")
|
||||||
private String onlineKey;
|
private String onlineKey;
|
||||||
|
@ -41,6 +44,7 @@ public class RedisUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 指定缓存失效时间
|
* 指定缓存失效时间
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param time 时间(秒)
|
* @param time 时间(秒)
|
||||||
*/
|
*/
|
||||||
|
@ -50,7 +54,7 @@ public class RedisUtils {
|
||||||
redisTemplate.expire(key, time, TimeUnit.SECONDS);
|
redisTemplate.expire(key, time, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -58,6 +62,7 @@ public class RedisUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 指定缓存失效时间
|
* 指定缓存失效时间
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param time 时间(秒)
|
* @param time 时间(秒)
|
||||||
* @param timeUnit 单位
|
* @param timeUnit 单位
|
||||||
|
@ -68,7 +73,7 @@ public class RedisUtils {
|
||||||
redisTemplate.expire(key, time, timeUnit);
|
redisTemplate.expire(key, time, timeUnit);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -76,6 +81,7 @@ public class RedisUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据 key 获取过期时间
|
* 根据 key 获取过期时间
|
||||||
|
*
|
||||||
* @param key 键 不能为null
|
* @param key 键 不能为null
|
||||||
* @return 时间(秒) 返回0代表为永久有效
|
* @return 时间(秒) 返回0代表为永久有效
|
||||||
*/
|
*/
|
||||||
|
@ -85,6 +91,7 @@ public class RedisUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查找匹配key
|
* 查找匹配key
|
||||||
|
*
|
||||||
* @param pattern key
|
* @param pattern key
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
|
@ -100,13 +107,14 @@ public class RedisUtils {
|
||||||
try {
|
try {
|
||||||
RedisConnectionUtils.releaseConnection(rc, factory);
|
RedisConnectionUtils.releaseConnection(rc, factory);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询 key
|
* 分页查询 key
|
||||||
|
*
|
||||||
* @param patternKey key
|
* @param patternKey key
|
||||||
* @param page 页码
|
* @param page 页码
|
||||||
* @param size 每页数目
|
* @param size 每页数目
|
||||||
|
@ -137,13 +145,14 @@ public class RedisUtils {
|
||||||
try {
|
try {
|
||||||
RedisConnectionUtils.releaseConnection(rc, factory);
|
RedisConnectionUtils.releaseConnection(rc, factory);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断key是否存在
|
* 判断key是否存在
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @return true 存在 false不存在
|
* @return true 存在 false不存在
|
||||||
*/
|
*/
|
||||||
|
@ -151,13 +160,14 @@ public class RedisUtils {
|
||||||
try {
|
try {
|
||||||
return redisTemplate.hasKey(key);
|
return redisTemplate.hasKey(key);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除缓存
|
* 删除缓存
|
||||||
|
*
|
||||||
* @param key 可以传一个值 或多个
|
* @param key 可以传一个值 或多个
|
||||||
*/
|
*/
|
||||||
public void del(String... keys) {
|
public void del(String... keys) {
|
||||||
|
@ -185,6 +195,7 @@ public class RedisUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 普通缓存获取
|
* 普通缓存获取
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @return 值
|
* @return 值
|
||||||
*/
|
*/
|
||||||
|
@ -194,6 +205,7 @@ public class RedisUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量获取
|
* 批量获取
|
||||||
|
*
|
||||||
* @param keys
|
* @param keys
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -204,6 +216,7 @@ public class RedisUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 普通缓存放入
|
* 普通缓存放入
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @return true成功 false失败
|
* @return true成功 false失败
|
||||||
|
@ -213,13 +226,14 @@ public class RedisUtils {
|
||||||
redisTemplate.opsForValue().set(key, value);
|
redisTemplate.opsForValue().set(key, value);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 普通缓存放入并设置时间
|
* 普通缓存放入并设置时间
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
|
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
|
||||||
|
@ -234,13 +248,14 @@ public class RedisUtils {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 普通缓存放入并设置时间
|
* 普通缓存放入并设置时间
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @param time 时间
|
* @param time 时间
|
||||||
|
@ -256,7 +271,7 @@ public class RedisUtils {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -265,6 +280,7 @@ public class RedisUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HashGet
|
* HashGet
|
||||||
|
*
|
||||||
* @param key 键 不能为null
|
* @param key 键 不能为null
|
||||||
* @param item 项 不能为null
|
* @param item 项 不能为null
|
||||||
* @return 值
|
* @return 值
|
||||||
|
@ -275,6 +291,7 @@ public class RedisUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取hashKey对应的所有键值
|
* 获取hashKey对应的所有键值
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @return 对应的多个键值
|
* @return 对应的多个键值
|
||||||
*/
|
*/
|
||||||
|
@ -285,6 +302,7 @@ public class RedisUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HashSet
|
* HashSet
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param map 对应多个键值
|
* @param map 对应多个键值
|
||||||
* @return true 成功 false 失败
|
* @return true 成功 false 失败
|
||||||
|
@ -294,13 +312,14 @@ public class RedisUtils {
|
||||||
redisTemplate.opsForHash().putAll(key, map);
|
redisTemplate.opsForHash().putAll(key, map);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HashSet 并设置时间
|
* HashSet 并设置时间
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param map 对应多个键值
|
* @param map 对应多个键值
|
||||||
* @param time 时间(秒)
|
* @param time 时间(秒)
|
||||||
|
@ -314,7 +333,7 @@ public class RedisUtils {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,7 +351,7 @@ public class RedisUtils {
|
||||||
redisTemplate.opsForHash().put(key, item, value);
|
redisTemplate.opsForHash().put(key, item, value);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -354,7 +373,7 @@ public class RedisUtils {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -416,7 +435,7 @@ public class RedisUtils {
|
||||||
try {
|
try {
|
||||||
return redisTemplate.opsForSet().members(key);
|
return redisTemplate.opsForSet().members(key);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -432,7 +451,7 @@ public class RedisUtils {
|
||||||
try {
|
try {
|
||||||
return redisTemplate.opsForSet().isMember(key, value);
|
return redisTemplate.opsForSet().isMember(key, value);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -448,13 +467,14 @@ public class RedisUtils {
|
||||||
try {
|
try {
|
||||||
return redisTemplate.opsForSet().add(key, values);
|
return redisTemplate.opsForSet().add(key, values);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将set数据放入缓存
|
* 将set数据放入缓存
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param time 时间(秒)
|
* @param time 时间(秒)
|
||||||
* @param values 值 可以是多个
|
* @param values 值 可以是多个
|
||||||
|
@ -468,13 +488,14 @@ public class RedisUtils {
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取set缓存的长度
|
* 获取set缓存的长度
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -482,13 +503,14 @@ public class RedisUtils {
|
||||||
try {
|
try {
|
||||||
return redisTemplate.opsForSet().size(key);
|
return redisTemplate.opsForSet().size(key);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除值为value的
|
* 移除值为value的
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param values 值 可以是多个
|
* @param values 值 可以是多个
|
||||||
* @return 移除的个数
|
* @return 移除的个数
|
||||||
|
@ -498,7 +520,7 @@ public class RedisUtils {
|
||||||
Long count = redisTemplate.opsForSet().remove(key, values);
|
Long count = redisTemplate.opsForSet().remove(key, values);
|
||||||
return count;
|
return count;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -507,6 +529,7 @@ public class RedisUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取list缓存的内容
|
* 获取list缓存的内容
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param start 开始
|
* @param start 开始
|
||||||
* @param end 结束 0 到 -1代表所有值
|
* @param end 结束 0 到 -1代表所有值
|
||||||
|
@ -516,13 +539,14 @@ public class RedisUtils {
|
||||||
try {
|
try {
|
||||||
return redisTemplate.opsForList().range(key, start, end);
|
return redisTemplate.opsForList().range(key, start, end);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取list缓存的长度
|
* 获取list缓存的长度
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -530,13 +554,14 @@ public class RedisUtils {
|
||||||
try {
|
try {
|
||||||
return redisTemplate.opsForList().size(key);
|
return redisTemplate.opsForList().size(key);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过索引 获取list中的值
|
* 通过索引 获取list中的值
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
|
* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
|
||||||
* @return
|
* @return
|
||||||
|
@ -545,13 +570,14 @@ public class RedisUtils {
|
||||||
try {
|
try {
|
||||||
return redisTemplate.opsForList().index(key, index);
|
return redisTemplate.opsForList().index(key, index);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将list放入缓存
|
* 将list放入缓存
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @return
|
* @return
|
||||||
|
@ -561,13 +587,14 @@ public class RedisUtils {
|
||||||
redisTemplate.opsForList().rightPush(key, value);
|
redisTemplate.opsForList().rightPush(key, value);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将list放入缓存
|
* 将list放入缓存
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @param time 时间(秒)
|
* @param time 时间(秒)
|
||||||
|
@ -581,13 +608,14 @@ public class RedisUtils {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将list放入缓存
|
* 将list放入缓存
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @return
|
* @return
|
||||||
|
@ -597,13 +625,14 @@ public class RedisUtils {
|
||||||
redisTemplate.opsForList().rightPushAll(key, value);
|
redisTemplate.opsForList().rightPushAll(key, value);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将list放入缓存
|
* 将list放入缓存
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @param time 时间(秒)
|
* @param time 时间(秒)
|
||||||
|
@ -617,13 +646,14 @@ public class RedisUtils {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据索引修改list中的某条数据
|
* 根据索引修改list中的某条数据
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param index 索引
|
* @param index 索引
|
||||||
* @param value 值
|
* @param value 值
|
||||||
|
@ -634,13 +664,14 @@ public class RedisUtils {
|
||||||
redisTemplate.opsForList().set(key, index, value);
|
redisTemplate.opsForList().set(key, index, value);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除N个值为value
|
* 移除N个值为value
|
||||||
|
*
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @param count 移除多少个
|
* @param count 移除多少个
|
||||||
* @param value 值
|
* @param value 值
|
||||||
|
@ -650,13 +681,12 @@ public class RedisUtils {
|
||||||
try {
|
try {
|
||||||
return redisTemplate.opsForList().remove(key, count, value);
|
return redisTemplate.opsForList().remove(key, count, value);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param prefix 前缀
|
* @param prefix 前缀
|
||||||
* @param ids id
|
* @param ids id
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -29,9 +29,12 @@ import me.zhengjie.utils.FileUtil;
|
||||||
import me.zhengjie.utils.GenUtil;
|
import me.zhengjie.utils.GenUtil;
|
||||||
import me.zhengjie.utils.PageUtil;
|
import me.zhengjie.utils.PageUtil;
|
||||||
import me.zhengjie.utils.StringUtils;
|
import me.zhengjie.utils.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.PersistenceContext;
|
import javax.persistence.PersistenceContext;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
|
@ -51,7 +54,7 @@ import java.util.stream.Collectors;
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class GeneratorServiceImpl implements GeneratorService {
|
public class GeneratorServiceImpl implements GeneratorService {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(GeneratorServiceImpl.class);
|
||||||
@PersistenceContext
|
@PersistenceContext
|
||||||
private EntityManager em;
|
private EntityManager em;
|
||||||
|
|
||||||
|
@ -169,7 +172,7 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||||
try {
|
try {
|
||||||
GenUtil.generatorCode(columns, genConfig);
|
GenUtil.generatorCode(columns, genConfig);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
throw new BadRequestException("生成失败,请手动处理已生成的文件");
|
throw new BadRequestException("生成失败,请手动处理已生成的文件");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
package me.zhengjie.utils;
|
package me.zhengjie.utils;
|
||||||
|
|
||||||
import org.apache.commons.configuration.*;
|
import org.apache.commons.configuration.*;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sql字段转java
|
* sql字段转java
|
||||||
|
@ -24,9 +26,11 @@ import org.apache.commons.configuration.*;
|
||||||
* @date 2019-01-03
|
* @date 2019-01-03
|
||||||
*/
|
*/
|
||||||
public class ColUtil {
|
public class ColUtil {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ColUtil.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换mysql数据类型为java数据类型
|
* 转换mysql数据类型为java数据类型
|
||||||
|
*
|
||||||
* @param type 数据库字段类型
|
* @param type 数据库字段类型
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
|
@ -43,7 +47,7 @@ public class ColUtil {
|
||||||
try {
|
try {
|
||||||
return new PropertiesConfiguration("generator.properties");
|
return new PropertiesConfiguration("generator.properties");
|
||||||
} catch (ConfigurationException e) {
|
} catch (ConfigurationException e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import me.zhengjie.domain.GenConfig;
|
import me.zhengjie.domain.GenConfig;
|
||||||
import me.zhengjie.domain.ColumnInfo;
|
import me.zhengjie.domain.ColumnInfo;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -28,8 +29,11 @@ import java.io.Writer;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static me.zhengjie.utils.FileUtil.SYS_TEM_DIR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代码生成
|
* 代码生成
|
||||||
|
*
|
||||||
* @author Zheng Jie
|
* @author Zheng Jie
|
||||||
* @date 2019-01-02
|
* @date 2019-01-02
|
||||||
*/
|
*/
|
||||||
|
@ -47,6 +51,7 @@ public class GenUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取后端代码模板名称
|
* 获取后端代码模板名称
|
||||||
|
*
|
||||||
* @return List
|
* @return List
|
||||||
*/
|
*/
|
||||||
private static List<String> getAdminTemplateNames() {
|
private static List<String> getAdminTemplateNames() {
|
||||||
|
@ -64,6 +69,7 @@ public class GenUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取前端代码模板名称
|
* 获取前端代码模板名称
|
||||||
|
*
|
||||||
* @return List
|
* @return List
|
||||||
*/
|
*/
|
||||||
private static List<String> getFrontTemplateNames() {
|
private static List<String> getFrontTemplateNames() {
|
||||||
|
@ -101,8 +107,8 @@ public class GenUtil {
|
||||||
|
|
||||||
public static String download(List<ColumnInfo> columns, GenConfig genConfig) throws IOException {
|
public static String download(List<ColumnInfo> columns, GenConfig genConfig) throws IOException {
|
||||||
// 拼接的路径:/tmpeladmin-gen-temp/,这个路径在Linux下需要root用户才有权限创建,非root用户会权限错误而失败,更改为: /tmp/eladmin-gen-temp/
|
// 拼接的路径:/tmpeladmin-gen-temp/,这个路径在Linux下需要root用户才有权限创建,非root用户会权限错误而失败,更改为: /tmp/eladmin-gen-temp/
|
||||||
// String tempPath =System.getProperty("java.io.tmpdir") + "eladmin-gen-temp" + File.separator + genConfig.getTableName() + File.separator;
|
// String tempPath =SYS_TEM_DIR + "eladmin-gen-temp" + File.separator + genConfig.getTableName() + File.separator;
|
||||||
String tempPath =System.getProperty("java.io.tmpdir") + File.separator + "eladmin-gen-temp" + File.separator + genConfig.getTableName() + File.separator;
|
String tempPath = SYS_TEM_DIR + "eladmin-gen-temp" + File.separator + genConfig.getTableName() + File.separator;
|
||||||
Map<String, Object> genMap = getGenMap(columns, genConfig);
|
Map<String, Object> genMap = getGenMap(columns, genConfig);
|
||||||
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
|
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH));
|
||||||
// 生成后端代码
|
// 生成后端代码
|
||||||
|
|
|
@ -28,10 +28,13 @@ import me.zhengjie.service.mapstruct.LogSmallMapper;
|
||||||
import me.zhengjie.utils.*;
|
import me.zhengjie.utils.*;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -44,7 +47,7 @@ import java.util.*;
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class LogServiceImpl implements LogService {
|
public class LogServiceImpl implements LogService {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(LogServiceImpl.class);
|
||||||
private final LogRepository logRepository;
|
private final LogRepository logRepository;
|
||||||
private final LogErrorMapper logErrorMapper;
|
private final LogErrorMapper logErrorMapper;
|
||||||
private final LogSmallMapper logSmallMapper;
|
private final LogSmallMapper logSmallMapper;
|
||||||
|
@ -100,7 +103,7 @@ public class LogServiceImpl implements LogService {
|
||||||
try {
|
try {
|
||||||
username = new JSONObject(argValues.get(0)).get("username").toString();
|
username = new JSONObject(argValues.get(0)).get("username").toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
LogServiceImpl.log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.setAddress(StringUtils.getCityInfo(log.getRequestIp()));
|
log.setAddress(StringUtils.getCityInfo(log.getRequestIp()));
|
||||||
|
|
|
@ -187,7 +187,7 @@ public class DeployServiceImpl implements DeployService {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(second * 1000);
|
Thread.sleep(second * 1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(),e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ public class DeployServiceImpl implements DeployService {
|
||||||
try {
|
try {
|
||||||
WebSocketServer.sendInfo(new SocketMsg(msg, msgType), "deploy");
|
WebSocketServer.sendInfo(new SocketMsg(msg, msgType), "deploy");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(),e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class ExecuteShellUtil {
|
||||||
session.setConfig("StrictHostKeyChecking", "no");
|
session.setConfig("StrictHostKeyChecking", "no");
|
||||||
session.connect(3000);
|
session.connect(3000);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(),e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ public class ExecuteShellUtil {
|
||||||
System.out.println(line);
|
System.out.println(line);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(),e);
|
||||||
return -1;
|
return -1;
|
||||||
}finally {
|
}finally {
|
||||||
IoUtil.close(printWriter);
|
IoUtil.close(printWriter);
|
||||||
|
|
|
@ -135,7 +135,7 @@ public class SqlUtils {
|
||||||
try {
|
try {
|
||||||
connection.close();
|
connection.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(),e);
|
||||||
log.error("connection close error:" + e.getMessage());
|
log.error("connection close error:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ public class SqlUtils {
|
||||||
try {
|
try {
|
||||||
rs.close();
|
rs.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(),e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class WebSocketServer {
|
||||||
try {
|
try {
|
||||||
item.sendMessage(message);
|
item.sendMessage(message);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(),e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class OnlineUserService {
|
||||||
try {
|
try {
|
||||||
onlineUserDto = new OnlineUserDto(jwtUserDto.getUsername(), jwtUserDto.getUser().getNickName(), dept, browser , ip, address, EncryptUtils.desEncrypt(token), new Date());
|
onlineUserDto = new OnlineUserDto(jwtUserDto.getUsername(), jwtUserDto.getUser().getNickName(), dept, browser , ip, address, EncryptUtils.desEncrypt(token), new Date());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage(),e);
|
||||||
}
|
}
|
||||||
redisUtils.set(properties.getOnlineKey() + token, onlineUserDto, properties.getTokenValidityInSeconds()/1000);
|
redisUtils.set(properties.getOnlineKey() + token, onlineUserDto, properties.getTokenValidityInSeconds()/1000);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ spring:
|
||||||
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
||||||
url: jdbc:log4jdbc:mysql://localhost:3306/eladmin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
|
url: jdbc:log4jdbc:mysql://localhost:3306/eladmin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
|
||||||
username: root
|
username: root
|
||||||
password: 123456
|
password: 59421
|
||||||
# 初始连接数
|
# 初始连接数
|
||||||
initial-size: 5
|
initial-size: 5
|
||||||
# 最小连接数
|
# 最小连接数
|
||||||
|
|
Loading…
Reference in New Issue