mirror of
https://github.com/chillzhuang/blade-tool
synced 2025-04-19 19:19:21 +08:00
⚡ 根据P3C优化代码
This commit is contained in:
parent
083b42c2fb
commit
912e0dd227
@ -24,6 +24,10 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置类
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableConfigurationProperties({
|
@EnableConfigurationProperties({
|
||||||
|
@ -33,6 +33,7 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* WEB配置
|
* WEB配置
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@ -27,6 +27,8 @@ import org.springframework.context.annotation.Profile;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* mybatisplus 配置
|
* mybatisplus 配置
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@MapperScan("org.springblade.**.mapper.**")
|
@MapperScan("org.springblade.**.mapper.**")
|
||||||
|
@ -35,6 +35,8 @@ import java.time.Duration;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* RedisTemplate 配置
|
* RedisTemplate 配置
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@EnableCaching
|
@EnableCaching
|
||||||
@Configuration
|
@Configuration
|
||||||
@ -43,6 +45,7 @@ public class RedisTemplateConfiguration {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* value 值 序列化
|
* value 值 序列化
|
||||||
|
*
|
||||||
* @return RedisSerializer
|
* @return RedisSerializer
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -24,6 +24,8 @@ import org.springframework.retry.interceptor.RetryOperationsInterceptor;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 重试机制
|
* 重试机制
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@ -33,6 +33,8 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Blade控制器封装类
|
* Blade控制器封装类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class BladeController {
|
public class BladeController {
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@ import java.util.Enumeration;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* feign 传递Request header
|
* feign 传递Request header
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class BladeFeignRequestHeaderInterceptor implements RequestInterceptor {
|
public class BladeFeignRequestHeaderInterceptor implements RequestInterceptor {
|
||||||
@ -40,16 +42,10 @@ public class BladeFeignRequestHeaderInterceptor implements RequestInterceptor {
|
|||||||
while (headerNames.hasMoreElements()) {
|
while (headerNames.hasMoreElements()) {
|
||||||
String name = headerNames.nextElement();
|
String name = headerNames.nextElement();
|
||||||
String value = request.getHeader(name);
|
String value = request.getHeader(name);
|
||||||
/**
|
|
||||||
* 遍历请求头里面的属性字段,将Authorization添加到新的请求头中转发到下游服务
|
|
||||||
* */
|
|
||||||
if ("Authorization".equals(name)) {
|
if ("Authorization".equals(name)) {
|
||||||
log.debug("添加自定义请求头key:" + name + ",value:" + value);
|
|
||||||
requestTemplate.header(name, value);
|
requestTemplate.header(name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
log.warn("FeignHeadConfiguration", "获取请求头失败!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,8 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义Feign的隔离策略
|
* 自定义Feign的隔离策略
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class FeignHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy {
|
public class FeignHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy {
|
||||||
|
|
||||||
|
@ -23,6 +23,10 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件封装
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
public class BladeFile {
|
public class BladeFile {
|
||||||
/**
|
/**
|
||||||
* 上传文件在附件表中的id
|
* 上传文件在附件表中的id
|
||||||
@ -89,6 +93,7 @@ public class BladeFile {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 图片上传
|
* 图片上传
|
||||||
|
*
|
||||||
* @param compress 是否压缩
|
* @param compress 是否压缩
|
||||||
*/
|
*/
|
||||||
public void transfer(boolean compress) {
|
public void transfer(boolean compress) {
|
||||||
@ -98,6 +103,7 @@ public class BladeFile {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 图片上传
|
* 图片上传
|
||||||
|
*
|
||||||
* @param fileFactory 文件上传工厂类
|
* @param fileFactory 文件上传工厂类
|
||||||
* @param compress 是否压缩
|
* @param compress 是否压缩
|
||||||
*/
|
*/
|
||||||
|
@ -18,12 +18,18 @@ package org.springblade.core.boot.file;
|
|||||||
import org.springblade.core.tool.constant.SystemConstant;
|
import org.springblade.core.tool.constant.SystemConstant;
|
||||||
import org.springblade.core.tool.date.DateUtil;
|
import org.springblade.core.tool.date.DateUtil;
|
||||||
import org.springblade.core.tool.utils.ImageUtil;
|
import org.springblade.core.tool.utils.ImageUtil;
|
||||||
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件代理类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
public class BladeFileProxyFactory implements IFileProxy {
|
public class BladeFileProxyFactory implements IFileProxy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -55,14 +61,16 @@ public class BladeFileProxyFactory implements IFileProxy {
|
|||||||
* 获取文件后缀
|
* 获取文件后缀
|
||||||
*/
|
*/
|
||||||
public static String getFileExt(String fileName) {
|
public static String getFileExt(String fileName) {
|
||||||
if (fileName.indexOf(".") == -1)
|
if (!fileName.contains(StringPool.DOT)) {
|
||||||
return ".jpg";
|
return ".jpg";
|
||||||
else
|
} else {
|
||||||
return fileName.substring(fileName.lastIndexOf('.'), fileName.length());
|
return fileName.substring(fileName.lastIndexOf(StringPool.DOT));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文件保存地址
|
* 获取文件保存地址
|
||||||
|
*
|
||||||
* @param saveDir
|
* @param saveDir
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -77,9 +85,11 @@ public class BladeFileProxyFactory implements IFileProxy {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 图片压缩
|
* 图片压缩
|
||||||
|
*
|
||||||
* @param path 文件地址
|
* @param path 文件地址
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void compress(String path) {
|
public void compress(String path) {
|
||||||
try {
|
try {
|
||||||
ImageUtil.zoomScale(ImageUtil.readImage(path), new FileOutputStream(new File(path)), null, SystemConstant.me().getCompressScale(), SystemConstant.me().isCompressFlag());
|
ImageUtil.zoomScale(ImageUtil.readImage(path), new FileOutputStream(new File(path)), null, SystemConstant.me().getCompressScale(), SystemConstant.me().isCompressFlag());
|
||||||
|
@ -20,11 +20,21 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件工具类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
public class BladeFileUtil {
|
public class BladeFileUtil {
|
||||||
|
|
||||||
// 定义允许上传的文件扩展名
|
/**
|
||||||
|
* 定义允许上传的文件扩展名
|
||||||
|
*/
|
||||||
private static HashMap<String, String> extMap = new HashMap<String, String>();
|
private static HashMap<String, String> extMap = new HashMap<String, String>();
|
||||||
// 图片扩展名
|
|
||||||
|
/**
|
||||||
|
* 图片扩展名
|
||||||
|
*/
|
||||||
private static String[] fileTypes = new String[]{"gif", "jpg", "jpeg", "png", "bmp"};
|
private static String[] fileTypes = new String[]{"gif", "jpg", "jpeg", "png", "bmp"};
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -67,7 +77,12 @@ public class BladeFileUtil {
|
|||||||
public enum FileSort {
|
public enum FileSort {
|
||||||
size, type, name;
|
size, type, name;
|
||||||
|
|
||||||
// 文本排序转换成枚举
|
/**
|
||||||
|
* 文本排序转换成枚举
|
||||||
|
*
|
||||||
|
* @param sort
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static FileSort of(String sort) {
|
public static FileSort of(String sort) {
|
||||||
try {
|
try {
|
||||||
return FileSort.valueOf(sort);
|
return FileSort.valueOf(sort);
|
||||||
@ -78,6 +93,7 @@ public class BladeFileUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class NameComparator implements Comparator {
|
public static class NameComparator implements Comparator {
|
||||||
|
@Override
|
||||||
public int compare(Object a, Object b) {
|
public int compare(Object a, Object b) {
|
||||||
Hashtable hashA = (Hashtable) a;
|
Hashtable hashA = (Hashtable) a;
|
||||||
Hashtable hashB = (Hashtable) b;
|
Hashtable hashB = (Hashtable) b;
|
||||||
@ -92,6 +108,7 @@ public class BladeFileUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class SizeComparator implements Comparator {
|
public static class SizeComparator implements Comparator {
|
||||||
|
@Override
|
||||||
public int compare(Object a, Object b) {
|
public int compare(Object a, Object b) {
|
||||||
Hashtable hashA = (Hashtable) a;
|
Hashtable hashA = (Hashtable) a;
|
||||||
Hashtable hashB = (Hashtable) b;
|
Hashtable hashB = (Hashtable) b;
|
||||||
@ -112,6 +129,7 @@ public class BladeFileUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class TypeComparator implements Comparator {
|
public static class TypeComparator implements Comparator {
|
||||||
|
@Override
|
||||||
public int compare(Object a, Object b) {
|
public int compare(Object a, Object b) {
|
||||||
Hashtable hashA = (Hashtable) a;
|
Hashtable hashA = (Hashtable) a;
|
||||||
Hashtable hashB = (Hashtable) b;
|
Hashtable hashB = (Hashtable) b;
|
||||||
@ -134,6 +152,7 @@ public class BladeFileUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取BladeFile封装类
|
* 获取BladeFile封装类
|
||||||
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -143,6 +162,7 @@ public class BladeFileUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取BladeFile封装类
|
* 获取BladeFile封装类
|
||||||
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* @param dir
|
* @param dir
|
||||||
* @return
|
* @return
|
||||||
@ -153,6 +173,7 @@ public class BladeFileUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取BladeFile封装类
|
* 获取BladeFile封装类
|
||||||
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* @param dir
|
* @param dir
|
||||||
* @param path
|
* @param path
|
||||||
@ -165,6 +186,7 @@ public class BladeFileUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取BladeFile封装类
|
* 获取BladeFile封装类
|
||||||
|
*
|
||||||
* @param files
|
* @param files
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -174,6 +196,7 @@ public class BladeFileUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取BladeFile封装类
|
* 获取BladeFile封装类
|
||||||
|
*
|
||||||
* @param files
|
* @param files
|
||||||
* @param dir
|
* @param dir
|
||||||
* @return
|
* @return
|
||||||
@ -184,6 +207,7 @@ public class BladeFileUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取BladeFile封装类
|
* 获取BladeFile封装类
|
||||||
|
*
|
||||||
* @param files
|
* @param files
|
||||||
* @param path
|
* @param path
|
||||||
* @param virtualPath
|
* @param virtualPath
|
||||||
|
@ -1,209 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
|
||||||
* <p>
|
|
||||||
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE;
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.gnu.org/licenses/lgpl.html
|
|
||||||
* <p>
|
|
||||||
* 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 org.springblade.core.boot.file;
|
|
||||||
|
|
||||||
|
|
||||||
import org.springblade.core.tool.utils.StringUtil;
|
|
||||||
import org.springblade.core.tool.utils.StringPool;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
public class FileMaker {
|
|
||||||
private static final String DEFAULT_CONTENT_TYPE = "application/octet-stream";
|
|
||||||
|
|
||||||
private File file;
|
|
||||||
|
|
||||||
private String fileName;
|
|
||||||
|
|
||||||
private HttpServletRequest request;
|
|
||||||
|
|
||||||
private HttpServletResponse response;
|
|
||||||
|
|
||||||
public static FileMaker init(HttpServletRequest request, HttpServletResponse response, File file) {
|
|
||||||
return new FileMaker(request, response, file);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static FileMaker init(HttpServletRequest request, HttpServletResponse response, File file, String fileName) {
|
|
||||||
return new FileMaker(request, response, file, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private FileMaker(HttpServletRequest request, HttpServletResponse response, File file) {
|
|
||||||
if (file == null) {
|
|
||||||
throw new IllegalArgumentException("file can not be null.");
|
|
||||||
}
|
|
||||||
this.file = file;
|
|
||||||
this.request = request;
|
|
||||||
this.response = response;
|
|
||||||
this.fileName = file.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
private FileMaker(HttpServletRequest request, HttpServletResponse response, File file, String fileName) {
|
|
||||||
if (file == null) {
|
|
||||||
throw new IllegalArgumentException("file can not be null.");
|
|
||||||
}
|
|
||||||
this.file = file;
|
|
||||||
this.request = request;
|
|
||||||
this.response = response;
|
|
||||||
this.fileName = fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start() {
|
|
||||||
if (file == null || !file.isFile()) {
|
|
||||||
throw new RuntimeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------
|
|
||||||
response.setHeader("Accept-Ranges", "bytes");
|
|
||||||
response.setHeader("Content-disposition", "attachment; filename=" + encodeFileName(fileName));
|
|
||||||
response.setContentType(DEFAULT_CONTENT_TYPE);
|
|
||||||
|
|
||||||
// ---------
|
|
||||||
if (StringUtil.isBlank(request.getHeader("Range")))
|
|
||||||
normalStart();
|
|
||||||
else
|
|
||||||
rangeStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String encodeFileName(String fileName) {
|
|
||||||
try {
|
|
||||||
return new String(fileName.getBytes(StringPool.GBK), StringPool.ISO_8859_1);
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
return fileName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void normalStart() {
|
|
||||||
response.setHeader("Content-Length", String.valueOf(file.length()));
|
|
||||||
InputStream inputStream = null;
|
|
||||||
OutputStream outputStream = null;
|
|
||||||
try {
|
|
||||||
inputStream = new BufferedInputStream(new FileInputStream(file));
|
|
||||||
outputStream = response.getOutputStream();
|
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
for (int len = -1; (len = inputStream.read(buffer)) != -1;) {
|
|
||||||
outputStream.write(buffer, 0, len);
|
|
||||||
}
|
|
||||||
outputStream.flush();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
if (inputStream != null)
|
|
||||||
try {inputStream.close();} catch (IOException e) {}
|
|
||||||
if (outputStream != null)
|
|
||||||
try {outputStream.close();} catch (IOException e) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void rangeStart() {
|
|
||||||
Long[] range = {null, null};
|
|
||||||
processRange(range);
|
|
||||||
|
|
||||||
String contentLength = String.valueOf(range[1].longValue() - range[0].longValue() + 1);
|
|
||||||
response.setHeader("Content-Length", contentLength);
|
|
||||||
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); // status = 206
|
|
||||||
|
|
||||||
// Content-Range: bytes 0-499/10000
|
|
||||||
StringBuilder contentRange = new StringBuilder("bytes ").append(String.valueOf(range[0])).append("-").append(String.valueOf(range[1])).append("/").append(String.valueOf(file.length()));
|
|
||||||
response.setHeader("Content-Range", contentRange.toString());
|
|
||||||
|
|
||||||
InputStream inputStream = null;
|
|
||||||
OutputStream outputStream = null;
|
|
||||||
try {
|
|
||||||
long start = range[0];
|
|
||||||
long end = range[1];
|
|
||||||
inputStream = new BufferedInputStream(new FileInputStream(file));
|
|
||||||
if (inputStream.skip(start) != start)
|
|
||||||
throw new RuntimeException("File skip error");
|
|
||||||
outputStream = response.getOutputStream();
|
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
long position = start;
|
|
||||||
for (int len; position <= end && (len = inputStream.read(buffer)) != -1;) {
|
|
||||||
if (position + len <= end) {
|
|
||||||
outputStream.write(buffer, 0, len);
|
|
||||||
position += len;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for (int i=0; i<len && position <= end; i++) {
|
|
||||||
outputStream.write(buffer[i]);
|
|
||||||
position++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
outputStream.flush();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
if (inputStream != null)
|
|
||||||
try {inputStream.close();} catch (IOException e) {}
|
|
||||||
if (outputStream != null)
|
|
||||||
try {outputStream.close();} catch (IOException e) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Examples of byte-ranges-specifier values (assuming an entity-body of length 10000):
|
|
||||||
* The first 500 bytes (byte offsets 0-499, inclusive): bytes=0-499
|
|
||||||
* The second 500 bytes (byte offsets 500-999, inclusive): bytes=500-999
|
|
||||||
* The final 500 bytes (byte offsets 9500-9999, inclusive): bytes=-500
|
|
||||||
* Or bytes=9500-
|
|
||||||
*/
|
|
||||||
private void processRange(Long[] range) {
|
|
||||||
String rangeStr = request.getHeader("Range");
|
|
||||||
int index = rangeStr.indexOf(',');
|
|
||||||
if (index != -1)
|
|
||||||
rangeStr = rangeStr.substring(0, index);
|
|
||||||
rangeStr = rangeStr.replace("bytes=", "");
|
|
||||||
|
|
||||||
String[] arr = rangeStr.split("-", 2);
|
|
||||||
if (arr.length < 2)
|
|
||||||
throw new RuntimeException("Range error");
|
|
||||||
|
|
||||||
long fileLength = file.length();
|
|
||||||
for (int i=0; i<range.length; i++) {
|
|
||||||
if (StringUtil.isNotBlank(arr[i])) {
|
|
||||||
range[i] = Long.parseLong(arr[i].trim());
|
|
||||||
if (range[i] >= fileLength)
|
|
||||||
range[i] = fileLength - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Range format like: 9500-
|
|
||||||
if (range[0] != null && range[1] == null) {
|
|
||||||
range[1] = fileLength - 1;
|
|
||||||
}
|
|
||||||
// Range format like: -500
|
|
||||||
else if (range[0] == null && range[1] != null) {
|
|
||||||
range[0] = fileLength - range[1];
|
|
||||||
range[1] = fileLength - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check final range
|
|
||||||
if (range[0] == null || range[1] == null || range[0].longValue() > range[1].longValue())
|
|
||||||
throw new RuntimeException("Range error");
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,6 +17,11 @@ package org.springblade.core.boot.file;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件管理类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
public class FileProxyManager {
|
public class FileProxyManager {
|
||||||
private IFileProxy defaultFileProxyFactory = new BladeFileProxyFactory();
|
private IFileProxy defaultFileProxyFactory = new BladeFileProxyFactory();
|
||||||
|
|
||||||
|
@ -17,10 +17,16 @@ package org.springblade.core.boot.file;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件代理接口
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
public interface IFileProxy {
|
public interface IFileProxy {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回路径[物理路径][虚拟路径]
|
* 返回路径[物理路径][虚拟路径]
|
||||||
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* @param dir
|
* @param dir
|
||||||
* @return
|
* @return
|
||||||
@ -29,6 +35,7 @@ public interface IFileProxy {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件重命名策略
|
* 文件重命名策略
|
||||||
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* @param path
|
* @param path
|
||||||
* @return
|
* @return
|
||||||
@ -37,6 +44,8 @@ public interface IFileProxy {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 图片压缩
|
* 图片压缩
|
||||||
|
*
|
||||||
|
* @param path
|
||||||
*/
|
*/
|
||||||
void compress(String path);
|
void compress(String path);
|
||||||
|
|
||||||
|
@ -40,9 +40,10 @@ public class RequestLogAspect {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* AOP 环切 控制器 R 返回值
|
* AOP 环切 控制器 R 返回值
|
||||||
|
*
|
||||||
* @param point JoinPoint
|
* @param point JoinPoint
|
||||||
* @throws Throwable 异常
|
|
||||||
* @return Object
|
* @return Object
|
||||||
|
* @throws Throwable 异常
|
||||||
*/
|
*/
|
||||||
@Around(
|
@Around(
|
||||||
"execution(!static org.springblade.core.tool.api.R<*> *(..)) && " +
|
"execution(!static org.springblade.core.tool.api.R<*> *(..)) && " +
|
||||||
|
@ -26,6 +26,8 @@ import org.springframework.web.method.support.ModelAndViewContainer;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Token转化BladeUser
|
* Token转化BladeUser
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class TokenArgumentResolver implements HandlerMethodArgumentResolver {
|
public class TokenArgumentResolver implements HandlerMethodArgumentResolver {
|
||||||
|
@ -28,6 +28,8 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 项目启动器,搞定环境变量问题
|
* 项目启动器,搞定环境变量问题
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class BladeApplication {
|
public class BladeApplication {
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统启动完毕后执行
|
* 系统启动完毕后执行
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class BladeLineRunner implements CommandLineRunner {
|
public class BladeLineRunner implements CommandLineRunner {
|
||||||
|
@ -1,3 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||||
|
* <p>
|
||||||
|
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE;
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.gnu.org/licenses/lgpl.html
|
||||||
|
* <p>
|
||||||
|
* 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 org.springblade.core.launch;
|
package org.springblade.core.launch;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -11,6 +26,8 @@ import org.springframework.util.StringUtils;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 项目启动事件通知
|
* 项目启动事件通知
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@ -31,6 +31,8 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Consul自定义注册规则
|
* Consul自定义注册规则
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnConsulEnabled
|
@ConditionalOnConsulEnabled
|
||||||
|
@ -26,7 +26,11 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||||
|
@ -17,6 +17,8 @@ package org.springblade.core.launch.constant;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统常量
|
* 系统常量
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public interface AppConstant {
|
public interface AppConstant {
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ import org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistry;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Consul自定义注册规则
|
* Consul自定义注册规则
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class BladeConsulServiceRegistry extends ConsulServiceRegistry {
|
public class BladeConsulServiceRegistry extends ConsulServiceRegistry {
|
||||||
|
|
||||||
|
@ -1,3 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||||
|
* <p>
|
||||||
|
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE;
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.gnu.org/licenses/lgpl.html
|
||||||
|
* <p>
|
||||||
|
* 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 org.springblade.core.launch.consul;
|
package org.springblade.core.launch.consul;
|
||||||
|
|
||||||
import org.springblade.core.launch.constant.AppConstant;
|
import org.springblade.core.launch.constant.AppConstant;
|
||||||
@ -8,6 +23,8 @@ import java.util.Properties;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* consul启动拓展
|
* consul启动拓展
|
||||||
|
*
|
||||||
|
* @author smallchil
|
||||||
*/
|
*/
|
||||||
public class ConsulLauncherService implements LauncherService {
|
public class ConsulLauncherService implements LauncherService {
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 配置文件
|
* 配置文件
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties("blade")
|
@ConfigurationProperties("blade")
|
||||||
public class BladeProperties {
|
public class BladeProperties {
|
||||||
|
@ -20,6 +20,8 @@ import org.springframework.cloud.commons.util.InetUtils;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务器信息
|
* 服务器信息
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class ServerInfo {
|
public class ServerInfo {
|
||||||
|
|
||||||
|
@ -19,11 +19,14 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* launcher 扩展 用于一些组件发现
|
* launcher 扩展 用于一些组件发现
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public interface LauncherService {
|
public interface LauncherService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动时 处理 SpringApplicationBuilder
|
* 启动时 处理 SpringApplicationBuilder
|
||||||
|
*
|
||||||
* @param builder SpringApplicationBuilder
|
* @param builder SpringApplicationBuilder
|
||||||
* @param appName SpringApplicationAppName
|
* @param appName SpringApplicationAppName
|
||||||
* @param profile SpringApplicationProfile
|
* @param profile SpringApplicationProfile
|
||||||
|
@ -20,6 +20,8 @@ import java.lang.annotation.*;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作日志注解
|
* 操作日志注解
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@ -25,6 +25,8 @@ import org.springblade.core.log.publisher.ApiLogPublisher;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作日志使用spring event异步入库
|
* 操作日志使用spring event异步入库
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Aspect
|
@Aspect
|
||||||
|
@ -38,6 +38,8 @@ import javax.servlet.Servlet;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 统一异常处理
|
* 统一异常处理
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ -31,6 +31,8 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志工具自动配置
|
* 日志工具自动配置
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ -17,6 +17,8 @@ package org.springblade.core.log.constant;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 事件常量
|
* 事件常量
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public interface EventConstant {
|
public interface EventConstant {
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局异常处理
|
* 全局异常处理
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class BladeErrorAttributes extends DefaultErrorAttributes {
|
public class BladeErrorAttributes extends DefaultErrorAttributes {
|
||||||
|
@ -30,6 +30,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 更改html请求异常为ajax
|
* 更改html请求异常为ajax
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class BladeErrorController extends BasicErrorController {
|
public class BladeErrorController extends BasicErrorController {
|
||||||
|
|
||||||
|
@ -51,6 +51,8 @@ import java.util.Set;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局异常处理,处理可预见的异常
|
* 全局异常处理,处理可预见的异常
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@ -22,6 +22,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统日志事件
|
* 系统日志事件
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class ApiLogEvent extends ApplicationEvent {
|
public class ApiLogEvent extends ApplicationEvent {
|
||||||
|
|
||||||
|
@ -38,6 +38,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步监听日志事件
|
* 异步监听日志事件
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
|
@ -22,6 +22,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统日志事件
|
* 系统日志事件
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class BladeLogEvent extends ApplicationEvent {
|
public class BladeLogEvent extends ApplicationEvent {
|
||||||
|
|
||||||
|
@ -37,6 +37,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步监听日志事件
|
* 异步监听日志事件
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
|
@ -22,6 +22,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误日志事件
|
* 错误日志事件
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class ErrorLogEvent extends ApplicationEvent {
|
public class ErrorLogEvent extends ApplicationEvent {
|
||||||
|
|
||||||
|
@ -36,6 +36,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 异步监听错误日志事件
|
* 异步监听错误日志事件
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
|
@ -22,6 +22,8 @@ import org.springblade.core.tool.api.ResultCode;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 业务异常
|
* 业务异常
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class ServiceException extends RuntimeException {
|
public class ServiceException extends RuntimeException {
|
||||||
private static final long serialVersionUID = 2359767895161832954L;
|
private static final long serialVersionUID = 2359767895161832954L;
|
||||||
@ -46,6 +48,7 @@ public class ServiceException extends RuntimeException {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 提高性能
|
* 提高性能
|
||||||
|
*
|
||||||
* @return Throwable
|
* @return Throwable
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,6 +26,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Feign接口类
|
* Feign接口类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@FeignClient(
|
@FeignClient(
|
||||||
value = AppConstant.APPLICATION_LOG_NAME
|
value = AppConstant.APPLICATION_LOG_NAME
|
||||||
|
@ -22,6 +22,8 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志工具类
|
* 日志工具类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class BladeLogger implements InitializingBean {
|
public class BladeLogger implements InitializingBean {
|
||||||
|
@ -30,7 +30,7 @@ import java.time.LocalDateTime;
|
|||||||
/**
|
/**
|
||||||
* 实体类
|
* 实体类
|
||||||
*
|
*
|
||||||
* @author Blade
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@TableName("blade_log_api")
|
@TableName("blade_log_api")
|
||||||
|
@ -30,7 +30,7 @@ import java.time.LocalDateTime;
|
|||||||
/**
|
/**
|
||||||
* 实体类
|
* 实体类
|
||||||
*
|
*
|
||||||
* @author Blade
|
* @author smallchill
|
||||||
* @since 2018-10-12
|
* @since 2018-10-12
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@ -30,6 +30,8 @@ import java.time.LocalDateTime;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务 异常
|
* 服务 异常
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@TableName("blade_log_error")
|
@TableName("blade_log_error")
|
||||||
|
@ -30,6 +30,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* API日志信息事件发送
|
* API日志信息事件发送
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class ApiLogPublisher {
|
public class ApiLogPublisher {
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* BLADE日志信息事件发送
|
* BLADE日志信息事件发送
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class BladeLogPublisher {
|
public class BladeLogPublisher {
|
||||||
|
|
||||||
|
@ -27,6 +27,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 异常信息事件发送
|
* 异常信息事件发送
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class ErrorLogPublisher {
|
public class ErrorLogPublisher {
|
||||||
|
|
||||||
@ -47,7 +49,7 @@ public class ErrorLogPublisher {
|
|||||||
logError.setLineNumber(element.getLineNumber());
|
logError.setLineNumber(element.getLineNumber());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map<String, Object> event = new HashMap<>();
|
Map<String, Object> event = new HashMap<>(16);
|
||||||
event.put(EventConstant.EVENT_LOG, logError);
|
event.put(EventConstant.EVENT_LOG, logError);
|
||||||
event.put(EventConstant.EVENT_REQUEST, request);
|
event.put(EventConstant.EVENT_REQUEST, request);
|
||||||
SpringUtil.publishEvent(new ErrorLogEvent(event));
|
SpringUtil.publishEvent(new ErrorLogEvent(event));
|
||||||
|
@ -21,6 +21,8 @@ import org.apache.ibatis.reflection.MetaObject;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* mybatisplus自定义填充
|
* mybatisplus自定义填充
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class BladeMetaObjectHandler implements MetaObjectHandler {
|
public class BladeMetaObjectHandler implements MetaObjectHandler {
|
||||||
|
@ -27,6 +27,11 @@ import org.springframework.format.annotation.DateTimeFormat;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基础实体类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class BaseEntity implements Serializable {
|
public class BaseEntity implements Serializable {
|
||||||
/**
|
/**
|
||||||
|
@ -20,10 +20,17 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基础业务接口
|
||||||
|
*
|
||||||
|
* @param <T>
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
public interface BaseService<T> extends IService<T> {
|
public interface BaseService<T> extends IService<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 逻辑删除
|
* 逻辑删除
|
||||||
|
*
|
||||||
* @param ids id集合(逗号分隔)
|
* @param ids id集合(逗号分隔)
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -35,6 +35,7 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @param <M> mapper
|
* @param <M> mapper
|
||||||
* @param <T> model
|
* @param <T> model
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Validated
|
@Validated
|
||||||
public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> extends ServiceImpl<M, T> implements BaseService<T> {
|
public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> extends ServiceImpl<M, T> implements BaseService<T> {
|
||||||
|
@ -23,6 +23,8 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 视图包装基类
|
* 视图包装基类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public abstract class BaseEntityWrapper<E, V> {
|
public abstract class BaseEntityWrapper<E, V> {
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页工具
|
* 分页工具
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class Condition {
|
public class Condition {
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@ import lombok.Data;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页工具
|
* 分页工具
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@ApiModel(description = "查询条件")
|
@ApiModel(description = "查询条件")
|
||||||
|
@ -21,6 +21,8 @@ import lombok.Data;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* AuthInfo
|
* AuthInfo
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@ApiModel(description = "认证信息")
|
@ApiModel(description = "认证信息")
|
||||||
|
@ -15,12 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.springblade.core.secure;
|
package org.springblade.core.secure;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户实体
|
* 用户实体
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class BladeUser implements Serializable {
|
public class BladeUser implements Serializable {
|
||||||
@ -30,23 +33,27 @@ public class BladeUser implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 主键
|
* 主键
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(hidden = true)
|
||||||
private Integer userId;
|
private Integer userId;
|
||||||
/**
|
/**
|
||||||
* 昵称
|
* 昵称
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(hidden = true)
|
||||||
private String userName;
|
private String userName;
|
||||||
/**
|
/**
|
||||||
* 账号
|
* 账号
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(hidden = true)
|
||||||
private String account;
|
private String account;
|
||||||
/**
|
/**
|
||||||
* 角色id
|
* 角色id
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(hidden = true)
|
||||||
private String roleId;
|
private String roleId;
|
||||||
/**
|
/**
|
||||||
* 角色名
|
* 角色名
|
||||||
*/
|
*/
|
||||||
|
@ApiModelProperty(hidden = true)
|
||||||
private String roleName;
|
private String roleName;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import java.lang.annotation.*;
|
|||||||
/**
|
/**
|
||||||
* 权限注解 用于检查权限 规定访问权限
|
* 权限注解 用于检查权限 规定访问权限
|
||||||
*
|
*
|
||||||
|
* @author smallchill
|
||||||
* @example @PreAuth("#userVO.id<10")
|
* @example @PreAuth("#userVO.id<10")
|
||||||
* @example @PreAuth("hasRole(#test, #test1)")
|
* @example @PreAuth("hasRole(#test, #test1)")
|
||||||
* @example @PreAuth("hasPermission(#test) and @PreAuth.hasPermission(#test)")
|
* @example @PreAuth("hasPermission(#test) and @PreAuth.hasPermission(#test)")
|
||||||
|
@ -39,6 +39,8 @@ import java.lang.reflect.Method;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* AOP 鉴权
|
* AOP 鉴权
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Aspect
|
@Aspect
|
||||||
public class AuthAspect implements ApplicationContextAware {
|
public class AuthAspect implements ApplicationContextAware {
|
||||||
@ -50,6 +52,7 @@ public class AuthAspect implements ApplicationContextAware {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 切 方法 和 类上的 @PreAuth 注解
|
* 切 方法 和 类上的 @PreAuth 注解
|
||||||
|
*
|
||||||
* @param point 切点
|
* @param point 切点
|
||||||
* @return Object
|
* @return Object
|
||||||
* @throws Throwable 没有权限的异常
|
* @throws Throwable 没有权限的异常
|
||||||
|
@ -23,6 +23,8 @@ import org.springblade.core.tool.utils.StringUtil;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 权限判断
|
* 权限判断
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class AuthFun {
|
public class AuthFun {
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* secure模块api放行默认配置
|
* secure模块api放行默认配置
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@AutoConfigureBefore(SecureConfiguration.class)
|
@AutoConfigureBefore(SecureConfiguration.class)
|
||||||
|
@ -26,6 +26,11 @@ import org.springframework.core.annotation.Order;
|
|||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
@Order
|
@Order
|
||||||
@Configuration
|
@Configuration
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ -21,6 +21,8 @@ import org.springblade.core.tool.api.ResultCode;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Secure异常
|
* Secure异常
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class SecureException extends RuntimeException {
|
public class SecureException extends RuntimeException {
|
||||||
private static final long serialVersionUID = 2359767895161832954L;
|
private static final long serialVersionUID = 2359767895161832954L;
|
||||||
|
@ -32,6 +32,8 @@ import java.util.Objects;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* jwt拦截器校验
|
* jwt拦截器校验
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SecureInterceptor extends HandlerInterceptorAdapter {
|
public class SecureInterceptor extends HandlerInterceptorAdapter {
|
||||||
|
@ -23,6 +23,8 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* secure api放行配置
|
* secure api放行配置
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class SecureRegistry {
|
public class SecureRegistry {
|
||||||
|
@ -36,6 +36,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Secure工具类
|
* Secure工具类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class SecureUtil {
|
public class SecureUtil {
|
||||||
public static final String BLADE_USER_REQUEST_ATTR = "_BLADE_USER_REQUEST_ATTR_";
|
public static final String BLADE_USER_REQUEST_ATTR = "_BLADE_USER_REQUEST_ATTR_";
|
||||||
@ -91,9 +93,9 @@ public class SecureUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户id
|
* 获取用户id
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Integer getUserId() {
|
public static Integer getUserId() {
|
||||||
@ -102,6 +104,7 @@ public class SecureUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户id
|
* 获取用户id
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Integer getUserId(HttpServletRequest request) {
|
public static Integer getUserId(HttpServletRequest request) {
|
||||||
@ -110,6 +113,7 @@ public class SecureUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户账号
|
* 获取用户账号
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String getUserAccount() {
|
public static String getUserAccount() {
|
||||||
@ -118,6 +122,7 @@ public class SecureUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户账号
|
* 获取用户账号
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String getUserAccount(HttpServletRequest request) {
|
public static String getUserAccount(HttpServletRequest request) {
|
||||||
|
@ -39,6 +39,8 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* swagger配置
|
* swagger配置
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableSwagger2
|
@EnableSwagger2
|
||||||
|
@ -25,6 +25,8 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* SwaggerProperties
|
* SwaggerProperties
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@RefreshScope
|
@RefreshScope
|
||||||
|
@ -19,11 +19,23 @@ import java.io.Serializable;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 业务代码接口
|
* 业务代码接口
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public interface IResultCode extends Serializable {
|
public interface IResultCode extends Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
String getMessage();
|
String getMessage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态码
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
int getCode();
|
int getCode();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@ import java.util.Optional;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 统一API响应结果封装
|
* 统一API响应结果封装
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@ -94,6 +96,7 @@ public class R<T> implements Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回R
|
* 返回R
|
||||||
|
*
|
||||||
* @param data 数据
|
* @param data 数据
|
||||||
*/
|
*/
|
||||||
public static <T> R<T> data(T data) {
|
public static <T> R<T> data(T data) {
|
||||||
@ -102,6 +105,7 @@ public class R<T> implements Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回R
|
* 返回R
|
||||||
|
*
|
||||||
* @param data 数据
|
* @param data 数据
|
||||||
* @param msg 消息
|
* @param msg 消息
|
||||||
*/
|
*/
|
||||||
@ -111,6 +115,7 @@ public class R<T> implements Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回R
|
* 返回R
|
||||||
|
*
|
||||||
* @param code 状态码
|
* @param code 状态码
|
||||||
* @param data 数据
|
* @param data 数据
|
||||||
* @param msg 消息
|
* @param msg 消息
|
||||||
@ -121,6 +126,7 @@ public class R<T> implements Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回R
|
* 返回R
|
||||||
|
*
|
||||||
* @param msg 消息
|
* @param msg 消息
|
||||||
*/
|
*/
|
||||||
public static <T> R<T> success(String msg) {
|
public static <T> R<T> success(String msg) {
|
||||||
@ -129,6 +135,7 @@ public class R<T> implements Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回R
|
* 返回R
|
||||||
|
*
|
||||||
* @param resultCode 业务代码
|
* @param resultCode 业务代码
|
||||||
*/
|
*/
|
||||||
public static <T> R<T> success(IResultCode resultCode) {
|
public static <T> R<T> success(IResultCode resultCode) {
|
||||||
@ -137,6 +144,7 @@ public class R<T> implements Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回R
|
* 返回R
|
||||||
|
*
|
||||||
* @param resultCode 业务代码
|
* @param resultCode 业务代码
|
||||||
*/
|
*/
|
||||||
public static <T> R<T> success(IResultCode resultCode, String msg) {
|
public static <T> R<T> success(IResultCode resultCode, String msg) {
|
||||||
@ -145,6 +153,7 @@ public class R<T> implements Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回R
|
* 返回R
|
||||||
|
*
|
||||||
* @param msg 消息
|
* @param msg 消息
|
||||||
*/
|
*/
|
||||||
public static <T> R<T> failure(String msg) {
|
public static <T> R<T> failure(String msg) {
|
||||||
@ -154,6 +163,7 @@ public class R<T> implements Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回R
|
* 返回R
|
||||||
|
*
|
||||||
* @param code 状态码
|
* @param code 状态码
|
||||||
* @param msg 消息
|
* @param msg 消息
|
||||||
*/
|
*/
|
||||||
@ -163,6 +173,7 @@ public class R<T> implements Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回R
|
* 返回R
|
||||||
|
*
|
||||||
* @param resultCode 业务代码
|
* @param resultCode 业务代码
|
||||||
*/
|
*/
|
||||||
public static <T> R<T> failure(IResultCode resultCode) {
|
public static <T> R<T> failure(IResultCode resultCode) {
|
||||||
@ -171,6 +182,7 @@ public class R<T> implements Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回R
|
* 返回R
|
||||||
|
*
|
||||||
* @param resultCode 业务代码
|
* @param resultCode 业务代码
|
||||||
*/
|
*/
|
||||||
public static <T> R<T> failure(IResultCode resultCode, String msg) {
|
public static <T> R<T> failure(IResultCode resultCode, String msg) {
|
||||||
@ -179,6 +191,7 @@ public class R<T> implements Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回R
|
* 返回R
|
||||||
|
*
|
||||||
* @param flag 成功状态
|
* @param flag 成功状态
|
||||||
*/
|
*/
|
||||||
public static R status(boolean flag) {
|
public static R status(boolean flag) {
|
||||||
|
@ -22,6 +22,8 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 业务代码枚举
|
* 业务代码枚举
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ -34,6 +34,11 @@ import java.time.ZoneId;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Jackson配置类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass(ObjectMapper.class)
|
@ConditionalOnClass(ObjectMapper.class)
|
||||||
@AutoConfigureBefore(JacksonAutoConfiguration.class)
|
@AutoConfigureBefore(JacksonAutoConfiguration.class)
|
||||||
|
@ -33,6 +33,11 @@ import javax.servlet.DispatcherType;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息配置类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||||
|
@ -23,7 +23,11 @@ import org.springframework.core.Ordered;
|
|||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工具配置类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||||
public class ToolConfiguration implements WebMvcConfigurer {
|
public class ToolConfiguration implements WebMvcConfigurer {
|
||||||
|
@ -17,6 +17,8 @@ package org.springblade.core.tool.constant;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统常量
|
* 系统常量
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public interface BladeConstant {
|
public interface BladeConstant {
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@ package org.springblade.core.tool.constant;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统默认角色
|
* 系统默认角色
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class RoleConstant {
|
public class RoleConstant {
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@ import lombok.Data;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Blade系统配置类
|
* Blade系统配置类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class SystemConstant {
|
public class SystemConstant {
|
||||||
|
@ -168,6 +168,7 @@ public class JsonUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 将json反序列化成List对象
|
* 将json反序列化成List对象
|
||||||
|
*
|
||||||
* @param content content
|
* @param content content
|
||||||
* @param valueTypeRef class
|
* @param valueTypeRef class
|
||||||
* @param <T> T 泛型标记
|
* @param <T> T 泛型标记
|
||||||
|
@ -24,7 +24,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* 节点基类
|
* 节点基类
|
||||||
*
|
*
|
||||||
* @author zhuangqian
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class BaseNode implements INode {
|
public class BaseNode implements INode {
|
||||||
|
@ -21,12 +21,17 @@ import lombok.EqualsAndHashCode;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 森林节点类
|
* 森林节点类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class ForestNode extends BaseNode {
|
public class ForestNode extends BaseNode {
|
||||||
|
|
||||||
private Object content;//节点内容
|
/**
|
||||||
|
* 节点内容
|
||||||
|
*/
|
||||||
|
private Object content;
|
||||||
|
|
||||||
public ForestNode(Integer id, Integer parentId, Object content) {
|
public ForestNode(Integer id, Integer parentId, Object content) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -21,7 +21,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* 森林管理类
|
* 森林管理类
|
||||||
*
|
*
|
||||||
* @author zhuangqian
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class ForestNodeManager<T extends INode> {
|
public class ForestNodeManager<T extends INode> {
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* 森林节点归并类
|
* 森林节点归并类
|
||||||
*
|
*
|
||||||
* @author zhuangqian
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class ForestNodeMerger {
|
public class ForestNodeMerger {
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* Created by Blade.
|
* Created by Blade.
|
||||||
*
|
*
|
||||||
* @author zhuangqian
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public interface INode {
|
public interface INode {
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* Created by Blade.
|
* Created by Blade.
|
||||||
*
|
*
|
||||||
* @author zhuangqian
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class NodeTest {
|
public class NodeTest {
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@ import lombok.EqualsAndHashCode;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 树型节点类
|
* 树型节点类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@ -5,6 +5,8 @@ import lombok.Getter;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Bean属性
|
* Bean属性
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ -24,6 +24,8 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 链式map
|
* 链式map
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class CMap extends CaseInsensitiveHashMap<String, Object> {
|
public class CMap extends CaseInsensitiveHashMap<String, Object> {
|
||||||
|
|
||||||
@ -34,6 +36,7 @@ public class CMap extends CaseInsensitiveHashMap<String, Object> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建CMap
|
* 创建CMap
|
||||||
|
*
|
||||||
* @return CMap
|
* @return CMap
|
||||||
*/
|
*/
|
||||||
public static CMap init() {
|
public static CMap init() {
|
||||||
@ -46,6 +49,7 @@ public class CMap extends CaseInsensitiveHashMap<String, Object> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置列
|
* 设置列
|
||||||
|
*
|
||||||
* @param attr 属性
|
* @param attr 属性
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @return 本身
|
* @return 本身
|
||||||
@ -57,6 +61,7 @@ public class CMap extends CaseInsensitiveHashMap<String, Object> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置列,当键或值为null时忽略
|
* 设置列,当键或值为null时忽略
|
||||||
|
*
|
||||||
* @param attr 属性
|
* @param attr 属性
|
||||||
* @param value 值
|
* @param value 值
|
||||||
* @return 本身
|
* @return 本身
|
||||||
|
@ -17,7 +17,13 @@ package org.springblade.core.tool.support;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 大小写忽略Map拓展
|
||||||
|
*
|
||||||
|
* @param <K>
|
||||||
|
* @param <V>
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
public class CaseInsensitiveHashMap<K, V> extends LinkedHashMap<String, Object> {
|
public class CaseInsensitiveHashMap<K, V> extends LinkedHashMap<String, Object> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 9178606903603606031L;
|
private static final long serialVersionUID = 9178606903603606031L;
|
||||||
|
@ -19,6 +19,8 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A factory for creating MultiOutputStream objects.
|
* A factory for creating MultiOutputStream objects.
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public interface IMultiOutputStream {
|
public interface IMultiOutputStream {
|
||||||
|
|
||||||
|
@ -15,37 +15,62 @@
|
|||||||
*/
|
*/
|
||||||
package org.springblade.core.tool.support;
|
package org.springblade.core.tool.support;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片操作类
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
public class ImagePosition {
|
public class ImagePosition {
|
||||||
|
|
||||||
/** 图片顶部. */
|
/**
|
||||||
|
* 图片顶部.
|
||||||
|
*/
|
||||||
public static final int TOP = 32;
|
public static final int TOP = 32;
|
||||||
|
|
||||||
/** 图片中部. */
|
/**
|
||||||
|
* 图片中部.
|
||||||
|
*/
|
||||||
public static final int MIDDLE = 16;
|
public static final int MIDDLE = 16;
|
||||||
|
|
||||||
/** 图片底部. */
|
/**
|
||||||
|
* 图片底部.
|
||||||
|
*/
|
||||||
public static final int BOTTOM = 8;
|
public static final int BOTTOM = 8;
|
||||||
|
|
||||||
/** 图片左侧. */
|
/**
|
||||||
|
* 图片左侧.
|
||||||
|
*/
|
||||||
public static final int LEFT = 4;
|
public static final int LEFT = 4;
|
||||||
|
|
||||||
/** 图片居中. */
|
/**
|
||||||
|
* 图片居中.
|
||||||
|
*/
|
||||||
public static final int CENTER = 2;
|
public static final int CENTER = 2;
|
||||||
|
|
||||||
/** 图片右侧. */
|
/**
|
||||||
|
* 图片右侧.
|
||||||
|
*/
|
||||||
public static final int RIGHT = 1;
|
public static final int RIGHT = 1;
|
||||||
|
|
||||||
/** 横向边距,靠左或靠右时和边界的距离. */
|
/**
|
||||||
|
* 横向边距,靠左或靠右时和边界的距离.
|
||||||
|
*/
|
||||||
private static final int PADDING_HORI = 6;
|
private static final int PADDING_HORI = 6;
|
||||||
|
|
||||||
/** 纵向边距,靠上或靠底时和边界的距离. */
|
/**
|
||||||
|
* 纵向边距,靠上或靠底时和边界的距离.
|
||||||
|
*/
|
||||||
private static final int PADDING_VERT = 6;
|
private static final int PADDING_VERT = 6;
|
||||||
|
|
||||||
|
|
||||||
/** 图片中盒[左上角]的x坐标. */
|
/**
|
||||||
|
* 图片中盒[左上角]的x坐标.
|
||||||
|
*/
|
||||||
private int boxPosX;
|
private int boxPosX;
|
||||||
|
|
||||||
/** 图片中盒[左上角]的y坐标. */
|
/**
|
||||||
|
* 图片中盒[左上角]的y坐标.
|
||||||
|
*/
|
||||||
private int boxPosY;
|
private int boxPosY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,11 @@ package org.springblade.core.tool.support;
|
|||||||
import org.springblade.core.tool.utils.Func;
|
import org.springblade.core.tool.utils.Func;
|
||||||
import org.springblade.core.tool.utils.StringPool;
|
import org.springblade.core.tool.utils.StringPool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符串格式化
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
public class StrFormatter {
|
public class StrFormatter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -13,6 +18,7 @@ public class StrFormatter {
|
|||||||
* 通常使用:format("this is {} for {}", "a", "b") =》 this is a for b<br>
|
* 通常使用:format("this is {} for {}", "a", "b") =》 this is a for b<br>
|
||||||
* 转义{}: format("this is \\{} for {}", "a", "b") =》 this is \{} for a<br>
|
* 转义{}: format("this is \\{} for {}", "a", "b") =》 this is \{} for a<br>
|
||||||
* 转义\: format("this is \\\\{} for {}", "a", "b") =》 this is \a for b<br>
|
* 转义\: format("this is \\\\{} for {}", "a", "b") =》 this is \a for b<br>
|
||||||
|
*
|
||||||
* @param strPattern 字符串模板
|
* @param strPattern 字符串模板
|
||||||
* @param argArray 参数列表
|
* @param argArray 参数列表
|
||||||
* @return 结果
|
* @return 结果
|
||||||
@ -23,23 +29,44 @@ public class StrFormatter {
|
|||||||
}
|
}
|
||||||
final int strPatternLength = strPattern.length();
|
final int strPatternLength = strPattern.length();
|
||||||
|
|
||||||
//初始化定义好的长度以获得更好的性能
|
/**
|
||||||
|
* 初始化定义好的长度以获得更好的性能
|
||||||
|
*/
|
||||||
StringBuilder sbuf = new StringBuilder(strPatternLength + 50);
|
StringBuilder sbuf = new StringBuilder(strPatternLength + 50);
|
||||||
|
|
||||||
int handledPosition = 0;//记录已经处理到的位置
|
/**
|
||||||
int delimIndex;//占位符所在位置
|
* 记录已经处理到的位置
|
||||||
|
*/
|
||||||
|
int handledPosition = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 占位符所在位置
|
||||||
|
*/
|
||||||
|
int delimIndex;
|
||||||
for (int argIndex = 0; argIndex < argArray.length; argIndex++) {
|
for (int argIndex = 0; argIndex < argArray.length; argIndex++) {
|
||||||
delimIndex = strPattern.indexOf(StringPool.EMPTY_JSON, handledPosition);
|
delimIndex = strPattern.indexOf(StringPool.EMPTY_JSON, handledPosition);
|
||||||
if (delimIndex == -1) {//剩余部分无占位符
|
/**
|
||||||
if (handledPosition == 0) { //不带占位符的模板直接返回
|
* 剩余部分无占位符
|
||||||
|
*/
|
||||||
|
if (delimIndex == -1) {
|
||||||
|
/**
|
||||||
|
* 不带占位符的模板直接返回
|
||||||
|
*/
|
||||||
|
if (handledPosition == 0) {
|
||||||
return strPattern;
|
return strPattern;
|
||||||
} else { //字符串模板剩余部分不再包含占位符,加入剩余部分后返回结果
|
} else {
|
||||||
sbuf.append(strPattern, handledPosition, strPatternLength);
|
sbuf.append(strPattern, handledPosition, strPatternLength);
|
||||||
return sbuf.toString();
|
return sbuf.toString();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == StringPool.BACK_SLASH) {//转义符
|
/**
|
||||||
if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == StringPool.BACK_SLASH) {//双转义符
|
* 转义符
|
||||||
|
*/
|
||||||
|
if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == StringPool.BACK_SLASH) {
|
||||||
|
/**
|
||||||
|
* 双转义符
|
||||||
|
*/
|
||||||
|
if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == StringPool.BACK_SLASH) {
|
||||||
//转义符之前还有一个转义符,占位符依旧有效
|
//转义符之前还有一个转义符,占位符依旧有效
|
||||||
sbuf.append(strPattern, handledPosition, delimIndex - 1);
|
sbuf.append(strPattern, handledPosition, delimIndex - 1);
|
||||||
sbuf.append(Func.toStr(argArray[argIndex]));
|
sbuf.append(Func.toStr(argArray[argIndex]));
|
||||||
|
@ -11,12 +11,13 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 字符串切分器
|
* 字符串切分器
|
||||||
* @author Looly
|
|
||||||
*
|
*
|
||||||
|
* @author Looly
|
||||||
*/
|
*/
|
||||||
public class StrSpliter {
|
public class StrSpliter {
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------- Split by char
|
//---------------------------------------------------------------------------------------------- Split by char
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 切分字符串路径,仅支持Unix分界符:/
|
* 切分字符串路径,仅支持Unix分界符:/
|
||||||
*
|
*
|
||||||
@ -388,6 +389,7 @@ public class StrSpliter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过正则切分字符串
|
* 通过正则切分字符串
|
||||||
|
*
|
||||||
* @param str 字符串
|
* @param str 字符串
|
||||||
* @param separatorPattern 分隔符正则{@link Pattern}
|
* @param separatorPattern 分隔符正则{@link Pattern}
|
||||||
* @param limit 限制分片数
|
* @param limit 限制分片数
|
||||||
@ -468,8 +470,10 @@ public class StrSpliter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------- Private method start
|
//---------------------------------------------------------------------------------------------------------- Private method start
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将字符串加入List中
|
* 将字符串加入List中
|
||||||
|
*
|
||||||
* @param list 列表
|
* @param list 列表
|
||||||
* @param part 被加入的部分
|
* @param part 被加入的部分
|
||||||
* @param isTrim 是否去除两端空白符
|
* @param isTrim 是否去除两端空白符
|
||||||
@ -489,6 +493,7 @@ public class StrSpliter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* List转Array
|
* List转Array
|
||||||
|
*
|
||||||
* @param list List
|
* @param list List
|
||||||
* @return Array
|
* @return Array
|
||||||
*/
|
*/
|
||||||
|
@ -8,6 +8,8 @@ import java.util.function.Function;
|
|||||||
/**
|
/**
|
||||||
* 当 Lambda 遇上受检异常
|
* 当 Lambda 遇上受检异常
|
||||||
* https://segmentfault.com/a/1190000007832130
|
* https://segmentfault.com/a/1190000007832130
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class Try {
|
public class Try {
|
||||||
|
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||||
|
* <p>
|
||||||
|
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE;
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.gnu.org/licenses/lgpl.html
|
||||||
|
* <p>
|
||||||
|
* 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 org.springblade.core.tool.support.xss;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springblade.core.tool.utils.StringUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQL过滤
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
|
*/
|
||||||
|
public class SqlFilter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQL注入过滤
|
||||||
|
*
|
||||||
|
* @param str 待验证的字符串
|
||||||
|
*/
|
||||||
|
public static String sqlInject(String str) {
|
||||||
|
if (StringUtil.isBlank(str)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
//去掉'|"|;|\字符
|
||||||
|
str = str.replace("'", "");
|
||||||
|
str = str.replace("\"", "");
|
||||||
|
str = str.replace(";", "");
|
||||||
|
str = str.replace("\\", "");
|
||||||
|
|
||||||
|
//转换成小写
|
||||||
|
str = str.toLowerCase();
|
||||||
|
|
||||||
|
//非法字符
|
||||||
|
String[] keywords = {"master", "truncate", "insert", "select", "delete", "update", "declare", "alert", "drop"};
|
||||||
|
|
||||||
|
//判断是否包含非法字符
|
||||||
|
for (String keyword : keywords) {
|
||||||
|
if (str.indexOf(keyword) != -1) {
|
||||||
|
throw new RuntimeException("包含非法字符");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,8 @@ import java.io.IOException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* XSS过滤
|
* XSS过滤
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class XssFilter implements Filter {
|
public class XssFilter implements Filter {
|
||||||
|
|
||||||
@ -29,6 +31,7 @@ public class XssFilter implements Filter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||||
ServletRequest requestWrapper = null;
|
ServletRequest requestWrapper = null;
|
||||||
if (request instanceof HttpServletRequest) {
|
if (request instanceof HttpServletRequest) {
|
||||||
|
@ -34,14 +34,24 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* XSS过滤处理
|
* XSS过滤处理
|
||||||
|
*
|
||||||
|
* @author smallchill
|
||||||
*/
|
*/
|
||||||
public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
|
public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
|
||||||
|
|
||||||
//没被包装过的HttpServletRequest(特殊场景,需要自己过滤)
|
/**
|
||||||
|
* 没被包装过的HttpServletRequest(特殊场景,需要自己过滤)
|
||||||
|
*/
|
||||||
HttpServletRequest orgRequest;
|
HttpServletRequest orgRequest;
|
||||||
//html过滤
|
|
||||||
|
/**
|
||||||
|
* html过滤
|
||||||
|
*/
|
||||||
private final static HTMLFilter htmlFilter = new HTMLFilter();
|
private final static HTMLFilter htmlFilter = new HTMLFilter();
|
||||||
// 缓存报文,支持多次读取流
|
|
||||||
|
/**
|
||||||
|
* 缓存报文,支持多次读取流
|
||||||
|
*/
|
||||||
private final byte[] body;
|
private final byte[] body;
|
||||||
|
|
||||||
public XssHttpServletRequestWrapper(HttpServletRequest request) throws IOException {
|
public XssHttpServletRequestWrapper(HttpServletRequest request) throws IOException {
|
||||||
|
@ -30,7 +30,8 @@ import java.util.Arrays;
|
|||||||
*/
|
*/
|
||||||
public class AESUtil {
|
public class AESUtil {
|
||||||
|
|
||||||
private AESUtil() {}
|
private AESUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
public static String genAesKey() {
|
public static String genAesKey() {
|
||||||
return StringUtil.random(32);
|
return StringUtil.random(32);
|
||||||
|
@ -21,6 +21,8 @@ import java.nio.charset.UnsupportedCharsetException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 字符集工具类
|
* 字符集工具类
|
||||||
|
*
|
||||||
|
* @author L.cm
|
||||||
*/
|
*/
|
||||||
public class Charsets {
|
public class Charsets {
|
||||||
|
|
||||||
@ -39,6 +41,7 @@ public class Charsets {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换为Charset对象
|
* 转换为Charset对象
|
||||||
|
*
|
||||||
* @param charsetName 字符集,为空则返回默认字符集
|
* @param charsetName 字符集,为空则返回默认字符集
|
||||||
* @return Charsets
|
* @return Charsets
|
||||||
* @throws UnsupportedCharsetException 编码不支持
|
* @throws UnsupportedCharsetException 编码不支持
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user