根据P3C优化代码

This commit is contained in:
smallchill 2018-12-27 13:29:11 +08:00
parent 083b42c2fb
commit 912e0dd227
122 changed files with 5538 additions and 5212 deletions

View File

@ -24,6 +24,10 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
/**
* 配置类
* @author smallchill
*/
@Slf4j
@Configuration
@EnableConfigurationProperties({

View File

@ -33,6 +33,7 @@ import java.util.List;
/**
* WEB配置
* @author smallchill
*/
@Slf4j
@Configuration

View File

@ -27,6 +27,8 @@ import org.springframework.context.annotation.Profile;
/**
* mybatisplus 配置
*
* @author smallchill
*/
@Configuration
@MapperScan("org.springblade.**.mapper.**")

View File

@ -35,6 +35,8 @@ import java.time.Duration;
/**
* RedisTemplate 配置
*
* @author smallchill
*/
@EnableCaching
@Configuration
@ -43,6 +45,7 @@ public class RedisTemplateConfiguration {
/**
* value 序列化
*
* @return RedisSerializer
*/
@Bean

View File

@ -24,6 +24,8 @@ import org.springframework.retry.interceptor.RetryOperationsInterceptor;
/**
* 重试机制
*
* @author smallchill
*/
@Slf4j
@Configuration

View File

@ -33,6 +33,8 @@ import java.util.List;
/**
* Blade控制器封装类
*
* @author smallchill
*/
public class BladeController {

View File

@ -26,6 +26,8 @@ import java.util.Enumeration;
/**
* feign 传递Request header
*
* @author smallchill
*/
@Slf4j
public class BladeFeignRequestHeaderInterceptor implements RequestInterceptor {
@ -40,16 +42,10 @@ public class BladeFeignRequestHeaderInterceptor implements RequestInterceptor {
while (headerNames.hasMoreElements()) {
String name = headerNames.nextElement();
String value = request.getHeader(name);
/**
* 遍历请求头里面的属性字段将Authorization添加到新的请求头中转发到下游服务
* */
if ("Authorization".equals(name)) {
log.debug("添加自定义请求头key:" + name + ",value:" + value);
requestTemplate.header(name, value);
}
}
} else {
log.warn("FeignHeadConfiguration", "获取请求头失败!");
}
}
}

View File

@ -38,6 +38,8 @@ import java.util.concurrent.TimeUnit;
/**
* 自定义Feign的隔离策略
*
* @author smallchill
*/
public class FeignHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy {

View File

@ -23,6 +23,10 @@ import java.io.File;
import java.io.IOException;
import java.util.Date;
/**
* 上传文件封装
* @author smallchill
*/
public class BladeFile {
/**
* 上传文件在附件表中的id
@ -89,6 +93,7 @@ public class BladeFile {
/**
* 图片上传
*
* @param compress 是否压缩
*/
public void transfer(boolean compress) {
@ -98,6 +103,7 @@ public class BladeFile {
/**
* 图片上传
*
* @param fileFactory 文件上传工厂类
* @param compress 是否压缩
*/

View File

@ -18,12 +18,18 @@ package org.springblade.core.boot.file;
import org.springblade.core.tool.constant.SystemConstant;
import org.springblade.core.tool.date.DateUtil;
import org.springblade.core.tool.utils.ImageUtil;
import org.springblade.core.tool.utils.StringPool;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Date;
/**
* 文件代理类
*
* @author smallchill
*/
public class BladeFileProxyFactory implements IFileProxy {
@Override
@ -55,14 +61,16 @@ public class BladeFileProxyFactory implements IFileProxy {
* 获取文件后缀
*/
public static String getFileExt(String fileName) {
if (fileName.indexOf(".") == -1)
if (!fileName.contains(StringPool.DOT)) {
return ".jpg";
else
return fileName.substring(fileName.lastIndexOf('.'), fileName.length());
} else {
return fileName.substring(fileName.lastIndexOf(StringPool.DOT));
}
}
/**
* 获取文件保存地址
*
* @param saveDir
* @return
*/
@ -77,9 +85,11 @@ public class BladeFileProxyFactory implements IFileProxy {
/**
* 图片压缩
*
* @param path 文件地址
* @return
*/
@Override
public void compress(String path) {
try {
ImageUtil.zoomScale(ImageUtil.readImage(path), new FileOutputStream(new File(path)), null, SystemConstant.me().getCompressScale(), SystemConstant.me().isCompressFlag());

View File

@ -20,11 +20,21 @@ import org.springframework.web.multipart.MultipartFile;
import java.util.*;
/**
* 文件工具类
*
* @author smallchill
*/
public class BladeFileUtil {
// 定义允许上传的文件扩展名
/**
* 定义允许上传的文件扩展名
*/
private static HashMap<String, String> extMap = new HashMap<String, String>();
// 图片扩展名
/**
* 图片扩展名
*/
private static String[] fileTypes = new String[]{"gif", "jpg", "jpeg", "png", "bmp"};
static {
@ -67,7 +77,12 @@ public class BladeFileUtil {
public enum FileSort {
size, type, name;
// 文本排序转换成枚举
/**
* 文本排序转换成枚举
*
* @param sort
* @return
*/
public static FileSort of(String sort) {
try {
return FileSort.valueOf(sort);
@ -78,6 +93,7 @@ public class BladeFileUtil {
}
public static class NameComparator implements Comparator {
@Override
public int compare(Object a, Object b) {
Hashtable hashA = (Hashtable) a;
Hashtable hashB = (Hashtable) b;
@ -92,6 +108,7 @@ public class BladeFileUtil {
}
public static class SizeComparator implements Comparator {
@Override
public int compare(Object a, Object b) {
Hashtable hashA = (Hashtable) a;
Hashtable hashB = (Hashtable) b;
@ -112,6 +129,7 @@ public class BladeFileUtil {
}
public static class TypeComparator implements Comparator {
@Override
public int compare(Object a, Object b) {
Hashtable hashA = (Hashtable) a;
Hashtable hashB = (Hashtable) b;
@ -134,6 +152,7 @@ public class BladeFileUtil {
/**
* 获取BladeFile封装类
*
* @param file
* @return
*/
@ -143,6 +162,7 @@ public class BladeFileUtil {
/**
* 获取BladeFile封装类
*
* @param file
* @param dir
* @return
@ -153,6 +173,7 @@ public class BladeFileUtil {
/**
* 获取BladeFile封装类
*
* @param file
* @param dir
* @param path
@ -165,6 +186,7 @@ public class BladeFileUtil {
/**
* 获取BladeFile封装类
*
* @param files
* @return
*/
@ -174,6 +196,7 @@ public class BladeFileUtil {
/**
* 获取BladeFile封装类
*
* @param files
* @param dir
* @return
@ -184,6 +207,7 @@ public class BladeFileUtil {
/**
* 获取BladeFile封装类
*
* @param files
* @param path
* @param virtualPath

View File

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

View File

@ -17,6 +17,11 @@ package org.springblade.core.boot.file;
import java.io.File;
/**
* 文件管理类
*
* @author smallchill
*/
public class FileProxyManager {
private IFileProxy defaultFileProxyFactory = new BladeFileProxyFactory();

View File

@ -17,10 +17,16 @@ package org.springblade.core.boot.file;
import java.io.File;
/**
* 文件代理接口
*
* @author smallchill
*/
public interface IFileProxy {
/**
* 返回路径[物理路径][虚拟路径]
*
* @param file
* @param dir
* @return
@ -29,6 +35,7 @@ public interface IFileProxy {
/**
* 文件重命名策略
*
* @param file
* @param path
* @return
@ -37,6 +44,8 @@ public interface IFileProxy {
/**
* 图片压缩
*
* @param path
*/
void compress(String path);

View File

@ -40,9 +40,10 @@ public class RequestLogAspect {
/**
* AOP 环切 控制器 R 返回值
*
* @param point JoinPoint
* @throws Throwable 异常
* @return Object
* @throws Throwable 异常
*/
@Around(
"execution(!static org.springblade.core.tool.api.R<*> *(..)) && " +

View File

@ -26,6 +26,8 @@ import org.springframework.web.method.support.ModelAndViewContainer;
/**
* Token转化BladeUser
*
* @author smallchill
*/
@Slf4j
public class TokenArgumentResolver implements HandlerMethodArgumentResolver {

View File

@ -28,6 +28,8 @@ import java.util.function.Function;
/**
* 项目启动器搞定环境变量问题
*
* @author smallchill
*/
public class BladeApplication {

View File

@ -20,6 +20,8 @@ import org.springframework.stereotype.Component;
/**
* 系统启动完毕后执行
*
* @author smallchill
*/
@Component
public class BladeLineRunner implements CommandLineRunner {

View File

@ -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;
import lombok.extern.slf4j.Slf4j;
@ -11,6 +26,8 @@ import org.springframework.util.StringUtils;
/**
* 项目启动事件通知
*
* @author smallchill
*/
@Slf4j
@Configuration

View File

@ -31,6 +31,8 @@ import org.springframework.context.annotation.Configuration;
/**
* Consul自定义注册规则
*
* @author smallchill
*/
@Configuration
@ConditionalOnConsulEnabled

View File

@ -26,7 +26,11 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
/**
* 配置类
*
* @author smallchill
*/
@Configuration
@AllArgsConstructor
@Order(Ordered.HIGHEST_PRECEDENCE)

View File

@ -17,6 +17,8 @@ package org.springblade.core.launch.constant;
/**
* 系统常量
*
* @author smallchill
*/
public interface AppConstant {

View File

@ -25,6 +25,8 @@ import org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistry;
/**
* Consul自定义注册规则
*
* @author smallchill
*/
public class BladeConsulServiceRegistry extends ConsulServiceRegistry {

View File

@ -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;
import org.springblade.core.launch.constant.AppConstant;
@ -8,6 +23,8 @@ import java.util.Properties;
/**
* consul启动拓展
*
* @author smallchil
*/
public class ConsulLauncherService implements LauncherService {

View File

@ -25,6 +25,8 @@ import java.util.Map;
/**
* 配置文件
*
* @author smallchill
*/
@ConfigurationProperties("blade")
public class BladeProperties {

View File

@ -20,6 +20,8 @@ import org.springframework.cloud.commons.util.InetUtils;
/**
* 服务器信息
*
* @author smallchill
*/
public class ServerInfo {

View File

@ -19,11 +19,14 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
/**
* launcher 扩展 用于一些组件发现
*
* @author smallchill
*/
public interface LauncherService {
/**
* 启动时 处理 SpringApplicationBuilder
*
* @param builder SpringApplicationBuilder
* @param appName SpringApplicationAppName
* @param profile SpringApplicationProfile

View File

@ -20,6 +20,8 @@ import java.lang.annotation.*;
/**
* 操作日志注解
*
* @author smallchill
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)

View File

@ -25,6 +25,8 @@ import org.springblade.core.log.publisher.ApiLogPublisher;
/**
* 操作日志使用spring event异步入库
*
* @author smallchill
*/
@Slf4j
@Aspect

View File

@ -38,6 +38,8 @@ import javax.servlet.Servlet;
/**
* 统一异常处理
*
* @author smallchill
*/
@Configuration
@AllArgsConstructor

View File

@ -31,6 +31,8 @@ import org.springframework.context.annotation.Configuration;
/**
* 日志工具自动配置
*
* @author smallchill
*/
@Configuration
@AllArgsConstructor

View File

@ -17,6 +17,8 @@ package org.springblade.core.log.constant;
/**
* 事件常量
*
* @author smallchill
*/
public interface EventConstant {

View File

@ -29,6 +29,8 @@ import java.util.Map;
/**
* 全局异常处理
*
* @author smallchill
*/
@Slf4j
public class BladeErrorAttributes extends DefaultErrorAttributes {

View File

@ -30,6 +30,8 @@ import java.util.Map;
/**
* 更改html请求异常为ajax
*
* @author smallchill
*/
public class BladeErrorController extends BasicErrorController {

View File

@ -51,6 +51,8 @@ import java.util.Set;
/**
* 全局异常处理处理可预见的异常
*
* @author smallchill
*/
@Slf4j
@Configuration

View File

@ -22,6 +22,8 @@ import java.util.Map;
/**
* 系统日志事件
*
* @author smallchill
*/
public class ApiLogEvent extends ApplicationEvent {

View File

@ -38,6 +38,8 @@ import java.util.Map;
/**
* 异步监听日志事件
*
* @author smallchill
*/
@Slf4j
@Component

View File

@ -22,6 +22,8 @@ import java.util.Map;
/**
* 系统日志事件
*
* @author smallchill
*/
public class BladeLogEvent extends ApplicationEvent {

View File

@ -37,6 +37,8 @@ import java.util.Map;
/**
* 异步监听日志事件
*
* @author smallchill
*/
@Slf4j
@Component

View File

@ -22,6 +22,8 @@ import java.util.Map;
/**
* 错误日志事件
*
* @author smallchill
*/
public class ErrorLogEvent extends ApplicationEvent {

View File

@ -36,6 +36,8 @@ import java.util.Map;
/**
* 异步监听错误日志事件
*
* @author smallchill
*/
@Slf4j
@Component

View File

@ -22,6 +22,8 @@ import org.springblade.core.tool.api.ResultCode;
/**
* 业务异常
*
* @author smallchill
*/
public class ServiceException extends RuntimeException {
private static final long serialVersionUID = 2359767895161832954L;
@ -46,6 +48,7 @@ public class ServiceException extends RuntimeException {
/**
* 提高性能
*
* @return Throwable
*/
@Override

View File

@ -26,6 +26,8 @@ import org.springframework.web.bind.annotation.RequestBody;
/**
* Feign接口类
*
* @author smallchill
*/
@FeignClient(
value = AppConstant.APPLICATION_LOG_NAME

View File

@ -22,6 +22,8 @@ import org.springframework.beans.factory.annotation.Value;
/**
* 日志工具类
*
* @author smallchill
*/
@Slf4j
public class BladeLogger implements InitializingBean {

View File

@ -30,7 +30,7 @@ import java.time.LocalDateTime;
/**
* 实体类
*
* @author Blade
* @author smallchill
*/
@Data
@TableName("blade_log_api")

View File

@ -30,7 +30,7 @@ import java.time.LocalDateTime;
/**
* 实体类
*
* @author Blade
* @author smallchill
* @since 2018-10-12
*/
@Data

View File

@ -30,6 +30,8 @@ import java.time.LocalDateTime;
/**
* 服务 异常
*
* @author smallchill
*/
@Data
@TableName("blade_log_error")

View File

@ -30,6 +30,8 @@ import java.util.Map;
/**
* API日志信息事件发送
*
* @author smallchill
*/
public class ApiLogPublisher {

View File

@ -28,6 +28,8 @@ import java.util.Map;
/**
* BLADE日志信息事件发送
*
* @author smallchill
*/
public class BladeLogPublisher {

View File

@ -27,6 +27,8 @@ import java.util.Map;
/**
* 异常信息事件发送
*
* @author smallchill
*/
public class ErrorLogPublisher {
@ -47,7 +49,7 @@ public class ErrorLogPublisher {
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_REQUEST, request);
SpringUtil.publishEvent(new ErrorLogEvent(event));

View File

@ -21,6 +21,8 @@ import org.apache.ibatis.reflection.MetaObject;
/**
* mybatisplus自定义填充
*
* @author smallchill
*/
@Slf4j
public class BladeMetaObjectHandler implements MetaObjectHandler {

View File

@ -27,6 +27,11 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 基础实体类
*
* @author smallchill
*/
@Data
public class BaseEntity implements Serializable {
/**

View File

@ -20,10 +20,17 @@ import com.baomidou.mybatisplus.extension.service.IService;
import javax.validation.constraints.NotEmpty;
import java.util.List;
/**
* 基础业务接口
*
* @param <T>
* @author smallchill
*/
public interface BaseService<T> extends IService<T> {
/**
* 逻辑删除
*
* @param ids id集合(逗号分隔)
* @return
*/

View File

@ -35,6 +35,7 @@ import java.util.List;
*
* @param <M> mapper
* @param <T> model
* @author smallchill
*/
@Validated
public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> extends ServiceImpl<M, T> implements BaseService<T> {

View File

@ -23,6 +23,8 @@ import java.util.stream.Collectors;
/**
* 视图包装基类
*
* @author smallchill
*/
public abstract class BaseEntityWrapper<E, V> {

View File

@ -25,6 +25,8 @@ import java.util.Map;
/**
* 分页工具
*
* @author smallchill
*/
public class Condition {

View File

@ -21,6 +21,8 @@ import lombok.Data;
/**
* 分页工具
*
* @author smallchill
*/
@Data
@ApiModel(description = "查询条件")

View File

@ -21,6 +21,8 @@ import lombok.Data;
/**
* AuthInfo
*
* @author smallchill
*/
@Data
@ApiModel(description = "认证信息")

View File

@ -15,12 +15,15 @@
*/
package org.springblade.core.secure;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 用户实体
*
* @author smallchill
*/
@Data
public class BladeUser implements Serializable {
@ -30,23 +33,27 @@ public class BladeUser implements Serializable {
/**
* 主键
*/
@ApiModelProperty(hidden = true)
private Integer userId;
/**
* 昵称
*/
@ApiModelProperty(hidden = true)
private String userName;
/**
* 账号
*/
@ApiModelProperty(hidden = true)
private String account;
/**
* 角色id
*/
@ApiModelProperty(hidden = true)
private String roleId;
/**
* 角色名
*/
@ApiModelProperty(hidden = true)
private String roleName;
}

View File

@ -20,6 +20,7 @@ import java.lang.annotation.*;
/**
* 权限注解 用于检查权限 规定访问权限
*
* @author smallchill
* @example @PreAuth("#userVO.id<10")
* @example @PreAuth("hasRole(#test, #test1)")
* @example @PreAuth("hasPermission(#test) and @PreAuth.hasPermission(#test)")

View File

@ -39,6 +39,8 @@ import java.lang.reflect.Method;
/**
* AOP 鉴权
*
* @author smallchill
*/
@Aspect
public class AuthAspect implements ApplicationContextAware {
@ -50,6 +52,7 @@ public class AuthAspect implements ApplicationContextAware {
/**
* 方法 类上的 @PreAuth 注解
*
* @param point 切点
* @return Object
* @throws Throwable 没有权限的异常

View File

@ -23,6 +23,8 @@ import org.springblade.core.tool.utils.StringUtil;
/**
* 权限判断
*
* @author smallchill
*/
public class AuthFun {

View File

@ -24,6 +24,8 @@ import org.springframework.context.annotation.Configuration;
/**
* secure模块api放行默认配置
*
* @author smallchill
*/
@Configuration
@AutoConfigureBefore(SecureConfiguration.class)

View File

@ -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.WebMvcConfigurer;
/**
* 配置类
*
* @author smallchill
*/
@Order
@Configuration
@AllArgsConstructor

View File

@ -21,6 +21,8 @@ import org.springblade.core.tool.api.ResultCode;
/**
* Secure异常
*
* @author smallchill
*/
public class SecureException extends RuntimeException {
private static final long serialVersionUID = 2359767895161832954L;

View File

@ -32,6 +32,8 @@ import java.util.Objects;
/**
* jwt拦截器校验
*
* @author smallchill
*/
@Slf4j
public class SecureInterceptor extends HandlerInterceptorAdapter {

View File

@ -23,6 +23,8 @@ import java.util.List;
/**
* secure api放行配置
*
* @author smallchill
*/
@Data
public class SecureRegistry {

View File

@ -36,6 +36,8 @@ import java.util.Map;
/**
* Secure工具类
*
* @author smallchill
*/
public class SecureUtil {
public static final String BLADE_USER_REQUEST_ATTR = "_BLADE_USER_REQUEST_ATTR_";
@ -91,9 +93,9 @@ public class SecureUtil {
}
/**
* 获取用户id
*
* @return
*/
public static Integer getUserId() {
@ -102,6 +104,7 @@ public class SecureUtil {
/**
* 获取用户id
*
* @return
*/
public static Integer getUserId(HttpServletRequest request) {
@ -110,6 +113,7 @@ public class SecureUtil {
/**
* 获取用户账号
*
* @return
*/
public static String getUserAccount() {
@ -118,6 +122,7 @@ public class SecureUtil {
/**
* 获取用户账号
*
* @return
*/
public static String getUserAccount(HttpServletRequest request) {

View File

@ -39,6 +39,8 @@ import java.util.List;
/**
* swagger配置
*
* @author smallchill
*/
@Configuration
@EnableSwagger2

View File

@ -25,6 +25,8 @@ import java.util.List;
/**
* SwaggerProperties
*
* @author smallchill
*/
@Data
@RefreshScope

View File

@ -19,11 +19,23 @@ import java.io.Serializable;
/**
* 业务代码接口
*
* @author smallchill
*/
public interface IResultCode extends Serializable {
/**
* 消息
*
* @return
*/
String getMessage();
/**
* 状态码
*
* @return
*/
int getCode();
}

View File

@ -28,6 +28,8 @@ import java.util.Optional;
/**
* 统一API响应结果封装
*
* @author smallchill
*/
@Getter
@Setter
@ -94,6 +96,7 @@ public class R<T> implements Serializable {
/**
* 返回R
*
* @param data 数据
*/
public static <T> R<T> data(T data) {
@ -102,6 +105,7 @@ public class R<T> implements Serializable {
/**
* 返回R
*
* @param data 数据
* @param msg 消息
*/
@ -111,6 +115,7 @@ public class R<T> implements Serializable {
/**
* 返回R
*
* @param code 状态码
* @param data 数据
* @param msg 消息
@ -121,6 +126,7 @@ public class R<T> implements Serializable {
/**
* 返回R
*
* @param msg 消息
*/
public static <T> R<T> success(String msg) {
@ -129,6 +135,7 @@ public class R<T> implements Serializable {
/**
* 返回R
*
* @param resultCode 业务代码
*/
public static <T> R<T> success(IResultCode resultCode) {
@ -137,6 +144,7 @@ public class R<T> implements Serializable {
/**
* 返回R
*
* @param resultCode 业务代码
*/
public static <T> R<T> success(IResultCode resultCode, String msg) {
@ -145,6 +153,7 @@ public class R<T> implements Serializable {
/**
* 返回R
*
* @param msg 消息
*/
public static <T> R<T> failure(String msg) {
@ -154,6 +163,7 @@ public class R<T> implements Serializable {
/**
* 返回R
*
* @param code 状态码
* @param msg 消息
*/
@ -163,6 +173,7 @@ public class R<T> implements Serializable {
/**
* 返回R
*
* @param resultCode 业务代码
*/
public static <T> R<T> failure(IResultCode resultCode) {
@ -171,6 +182,7 @@ public class R<T> implements Serializable {
/**
* 返回R
*
* @param resultCode 业务代码
*/
public static <T> R<T> failure(IResultCode resultCode, String msg) {
@ -179,6 +191,7 @@ public class R<T> implements Serializable {
/**
* 返回R
*
* @param flag 成功状态
*/
public static R status(boolean flag) {

View File

@ -22,6 +22,8 @@ import javax.servlet.http.HttpServletResponse;
/**
* 业务代码枚举
*
* @author smallchill
*/
@Getter
@AllArgsConstructor

View File

@ -34,6 +34,11 @@ import java.time.ZoneId;
import java.util.Locale;
import java.util.TimeZone;
/**
* Jackson配置类
*
* @author smallchill
*/
@Configuration
@ConditionalOnClass(ObjectMapper.class)
@AutoConfigureBefore(JacksonAutoConfiguration.class)

View File

@ -33,6 +33,11 @@ import javax.servlet.DispatcherType;
import java.nio.charset.StandardCharsets;
import java.util.List;
/**
* 消息配置类
*
* @author smallchill
*/
@Configuration
@AllArgsConstructor
@Order(Ordered.HIGHEST_PRECEDENCE)

View File

@ -23,7 +23,11 @@ import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* 工具配置类
*
* @author smallchill
*/
@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ToolConfiguration implements WebMvcConfigurer {

View File

@ -17,6 +17,8 @@ package org.springblade.core.tool.constant;
/**
* 系统常量
*
* @author smallchill
*/
public interface BladeConstant {

View File

@ -17,6 +17,8 @@ package org.springblade.core.tool.constant;
/**
* 系统默认角色
*
* @author smallchill
*/
public class RoleConstant {

View File

@ -20,6 +20,8 @@ import lombok.Data;
/**
* Blade系统配置类
*
* @author smallchill
*/
@Data
public class SystemConstant {

View File

@ -168,6 +168,7 @@ public class JsonUtil {
/**
* 将json反序列化成List对象
*
* @param content content
* @param valueTypeRef class
* @param <T> T 泛型标记

View File

@ -24,7 +24,7 @@ import java.util.List;
/**
* 节点基类
*
* @author zhuangqian
* @author smallchill
*/
@Data
public class BaseNode implements INode {

View File

@ -21,12 +21,17 @@ import lombok.EqualsAndHashCode;
/**
* 森林节点类
*
* @author smallchill
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class ForestNode extends BaseNode {
private Object content;//节点内容
/**
* 节点内容
*/
private Object content;
public ForestNode(Integer id, Integer parentId, Object content) {
this.id = id;

View File

@ -21,7 +21,7 @@ import java.util.List;
/**
* 森林管理类
*
* @author zhuangqian
* @author smallchill
*/
public class ForestNodeManager<T extends INode> {

View File

@ -20,7 +20,7 @@ import java.util.List;
/**
* 森林节点归并类
*
* @author zhuangqian
* @author smallchill
*/
public class ForestNodeMerger {

View File

@ -20,7 +20,7 @@ import java.util.List;
/**
* Created by Blade.
*
* @author zhuangqian
* @author smallchill
*/
public interface INode {

View File

@ -8,7 +8,7 @@ import java.util.List;
/**
* Created by Blade.
*
* @author zhuangqian
* @author smallchill
*/
public class NodeTest {

View File

@ -20,6 +20,8 @@ import lombok.EqualsAndHashCode;
/**
* 树型节点类
*
* @author smallchill
*/
@Data
@EqualsAndHashCode(callSuper = false)

View File

@ -5,6 +5,8 @@ import lombok.Getter;
/**
* Bean属性
*
* @author smallchill
*/
@Getter
@AllArgsConstructor

View File

@ -24,6 +24,8 @@ import java.util.HashMap;
/**
* 链式map
*
* @author smallchill
*/
public class CMap extends CaseInsensitiveHashMap<String, Object> {
@ -34,6 +36,7 @@ public class CMap extends CaseInsensitiveHashMap<String, Object> {
/**
* 创建CMap
*
* @return CMap
*/
public static CMap init() {
@ -46,6 +49,7 @@ public class CMap extends CaseInsensitiveHashMap<String, Object> {
/**
* 设置列
*
* @param attr 属性
* @param value
* @return 本身
@ -57,6 +61,7 @@ public class CMap extends CaseInsensitiveHashMap<String, Object> {
/**
* 设置列当键或值为null时忽略
*
* @param attr 属性
* @param value
* @return 本身

View File

@ -17,7 +17,13 @@ package org.springblade.core.tool.support;
import java.util.*;
/**
* 大小写忽略Map拓展
*
* @param <K>
* @param <V>
* @author smallchill
*/
public class CaseInsensitiveHashMap<K, V> extends LinkedHashMap<String, Object> {
private static final long serialVersionUID = 9178606903603606031L;

View File

@ -19,6 +19,8 @@ import java.io.OutputStream;
/**
* A factory for creating MultiOutputStream objects.
*
* @author smallchill
*/
public interface IMultiOutputStream {

View File

@ -15,37 +15,62 @@
*/
package org.springblade.core.tool.support;
/**
* 图片操作类
*
* @author smallchill
*/
public class ImagePosition {
/** 图片顶部. */
/**
* 图片顶部.
*/
public static final int TOP = 32;
/** 图片中部. */
/**
* 图片中部.
*/
public static final int MIDDLE = 16;
/** 图片底部. */
/**
* 图片底部.
*/
public static final int BOTTOM = 8;
/** 图片左侧. */
/**
* 图片左侧.
*/
public static final int LEFT = 4;
/** 图片居中. */
/**
* 图片居中.
*/
public static final int CENTER = 2;
/** 图片右侧. */
/**
* 图片右侧.
*/
public static final int RIGHT = 1;
/** 横向边距,靠左或靠右时和边界的距离. */
/**
* 横向边距靠左或靠右时和边界的距离.
*/
private static final int PADDING_HORI = 6;
/** 纵向边距,靠上或靠底时和边界的距离. */
/**
* 纵向边距靠上或靠底时和边界的距离.
*/
private static final int PADDING_VERT = 6;
/** 图片中盒[左上角]的x坐标. */
/**
* 图片中盒[左上角]的x坐标.
*/
private int boxPosX;
/** 图片中盒[左上角]的y坐标. */
/**
* 图片中盒[左上角]的y坐标.
*/
private int boxPosY;
/**

View File

@ -3,6 +3,11 @@ package org.springblade.core.tool.support;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
/**
* 字符串格式化
*
* @author smallchill
*/
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 \{} for a<br>
* 转义\ format("this is \\\\{} for {}", "a", "b") = this is \a for b<br>
*
* @param strPattern 字符串模板
* @param argArray 参数列表
* @return 结果
@ -23,23 +29,44 @@ public class StrFormatter {
}
final int strPatternLength = strPattern.length();
//初始化定义好的长度以获得更好的性能
/**
* 初始化定义好的长度以获得更好的性能
*/
StringBuilder sbuf = new StringBuilder(strPatternLength + 50);
int handledPosition = 0;//记录已经处理到的位置
int delimIndex;//占位符所在位置
/**
* 记录已经处理到的位置
*/
int handledPosition = 0;
/**
* 占位符所在位置
*/
int delimIndex;
for (int argIndex = 0; argIndex < argArray.length; argIndex++) {
delimIndex = strPattern.indexOf(StringPool.EMPTY_JSON, handledPosition);
if (delimIndex == -1) {//剩余部分无占位符
if (handledPosition == 0) { //不带占位符的模板直接返回
/**
* 剩余部分无占位符
*/
if (delimIndex == -1) {
/**
* 不带占位符的模板直接返回
*/
if (handledPosition == 0) {
return strPattern;
} else { //字符串模板剩余部分不再包含占位符加入剩余部分后返回结果
} else {
sbuf.append(strPattern, handledPosition, strPatternLength);
return sbuf.toString();
}
} 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(Func.toStr(argArray[argIndex]));

View File

@ -11,12 +11,13 @@ import java.util.regex.Pattern;
/**
* 字符串切分器
* @author Looly
*
* @author Looly
*/
public class StrSpliter {
//---------------------------------------------------------------------------------------------- Split by char
/**
* 切分字符串路径仅支持Unix分界符/
*
@ -388,6 +389,7 @@ public class StrSpliter {
/**
* 通过正则切分字符串
*
* @param str 字符串
* @param separatorPattern 分隔符正则{@link Pattern}
* @param limit 限制分片数
@ -468,8 +470,10 @@ public class StrSpliter {
}
//---------------------------------------------------------------------------------------------------------- Private method start
/**
* 将字符串加入List中
*
* @param list 列表
* @param part 被加入的部分
* @param isTrim 是否去除两端空白符
@ -489,6 +493,7 @@ public class StrSpliter {
/**
* List转Array
*
* @param list List
* @return Array
*/

View File

@ -8,6 +8,8 @@ import java.util.function.Function;
/**
* Lambda 遇上受检异常
* https://segmentfault.com/a/1190000007832130
*
* @author smallchill
*/
public class Try {

View File

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

View File

@ -21,6 +21,8 @@ import java.io.IOException;
/**
* XSS过滤
*
* @author smallchill
*/
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 {
ServletRequest requestWrapper = null;
if (request instanceof HttpServletRequest) {

View File

@ -34,14 +34,24 @@ import java.util.Map;
/**
* XSS过滤处理
*
* @author smallchill
*/
public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
//没被包装过的HttpServletRequest特殊场景,需要自己过滤
/**
* 没被包装过的HttpServletRequest特殊场景,需要自己过滤
*/
HttpServletRequest orgRequest;
//html过滤
/**
* html过滤
*/
private final static HTMLFilter htmlFilter = new HTMLFilter();
// 缓存报文,支持多次读取流
/**
* 缓存报文,支持多次读取流
*/
private final byte[] body;
public XssHttpServletRequestWrapper(HttpServletRequest request) throws IOException {

View File

@ -30,7 +30,8 @@ import java.util.Arrays;
*/
public class AESUtil {
private AESUtil() {}
private AESUtil() {
}
public static String genAesKey() {
return StringUtil.random(32);

View File

@ -21,6 +21,8 @@ import java.nio.charset.UnsupportedCharsetException;
/**
* 字符集工具类
*
* @author L.cm
*/
public class Charsets {
@ -39,6 +41,7 @@ public class Charsets {
/**
* 转换为Charset对象
*
* @param charsetName 字符集为空则返回默认字符集
* @return Charsets
* @throws UnsupportedCharsetException 编码不支持

Some files were not shown because too many files have changed in this diff Show More