代码ReView

v1.4.1
Parker 4 years ago
parent 014d97a7f8
commit 9e092bc790

@ -70,9 +70,9 @@ public enum ValidationMsg implements BaseMsg {
; ;
private static final String PREFIX = "参数验证错误: "; private static final String PREFIX = "参数验证错误: ";
private int code; private final int code;
private final String message;
private String fieldName; private String fieldName;
private String message;
ValidationMsg(int code, String message){ ValidationMsg(int code, String message){
this.code = code; this.code = code;

@ -56,11 +56,10 @@ public final class ValidationUtil {
} }
Field[] fields = ReflectUtil.getFields(obj.getClass()); Field[] fields = ReflectUtil.getFields(obj.getClass());
for (int i = 0; i < fields.length; i++) { for (Field field : fields) {
Field field = fields[i];
// 获得 统一验证 注解 // 获得 统一验证 注解
ValidationArgs validationArgs = field.getAnnotation(ValidationArgs.class); ValidationArgs validationArgs = field.getAnnotation(ValidationArgs.class);
if(validationArgs != null){ if (validationArgs != null) {
ValiArgsType[] types = validationArgs.value(); ValiArgsType[] types = validationArgs.value();
Object fieldValue = ReflectUtil.getFieldValue(obj, field); Object fieldValue = ReflectUtil.getFieldValue(obj, field);
ValidationUtil.check(field, types, fieldValue); ValidationUtil.check(field, types, fieldValue);
@ -68,7 +67,7 @@ public final class ValidationUtil {
// 获得 最大长度 注解 // 获得 最大长度 注解
ValidationArgsLenMax validationArgsMax = field.getAnnotation(ValidationArgsLenMax.class); ValidationArgsLenMax validationArgsMax = field.getAnnotation(ValidationArgsLenMax.class);
if(validationArgsMax != null){ if (validationArgsMax != null) {
int maxLength = validationArgsMax.value(); int maxLength = validationArgsMax.value();
Object fieldValue = ReflectUtil.getFieldValue(obj, field); Object fieldValue = ReflectUtil.getFieldValue(obj, field);
ValidationUtil.checkMax(field, maxLength, fieldValue); ValidationUtil.checkMax(field, maxLength, fieldValue);
@ -76,7 +75,7 @@ public final class ValidationUtil {
// 获得 最小长度 注解 // 获得 最小长度 注解
ValidationArgsLenMin validationArgsMin = field.getAnnotation(ValidationArgsLenMin.class); ValidationArgsLenMin validationArgsMin = field.getAnnotation(ValidationArgsLenMin.class);
if(validationArgsMin != null){ if (validationArgsMin != null) {
int minLength = validationArgsMin.value(); int minLength = validationArgsMin.value();
Object fieldValue = ReflectUtil.getFieldValue(obj, field); Object fieldValue = ReflectUtil.getFieldValue(obj, field);
ValidationUtil.checkMin(field, minLength, fieldValue); ValidationUtil.checkMin(field, minLength, fieldValue);

@ -40,6 +40,6 @@ public class TokenThreadLocal {
public static void remove() { public static void remove() {
try { try {
TOKEN_DATA.remove(); TOKEN_DATA.remove();
}catch (Exception e){} }catch (Exception ignored){}
} }
} }

@ -14,7 +14,7 @@ public enum DictType {
; ;
private String code; private final String code;
DictType(String code){ DictType(String code){
this.code = code; this.code = code;

@ -29,7 +29,7 @@ public enum SystemInfo {
/** 实例 */ /** 实例 */
INSTANCE; INSTANCE;
private String systemID; private final String systemID;
SystemInfo(){ SystemInfo(){
// 生成系统ID // 生成系统ID

@ -34,8 +34,8 @@ public enum CommonMsg implements BaseMsg {
; ;
private int code; private final int code;
private String message; private final String message;
CommonMsg(int code, String message){ CommonMsg(int code, String message){
this.code = code; this.code = code;

@ -91,16 +91,14 @@ public class ZipUtils {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
List<Map<String, String>> list = new ArrayList<>(); List<Map<String, String>> list = new ArrayList<>();
OutputStream outputStream = new FileOutputStream(new File("/Users/system/Documents/脚本/opsli/test.zip")); OutputStream outputStream = new FileOutputStream(new File("/Users/system/Documents/脚本/opsli/test.zip"));
Map<String,String> m1 = new HashMap(){{put("path","/f1/f2/f3/");put("name","1.txt");put("data","abcdefg");}}; Map<String,String> m1 = new HashMap<String,String>(){{put("path","/f1/f2/f3/");put("name","1.txt");put("data","abcdefg");}};
Map<String,String> m2 = new HashMap(){{put("path","/f1/f2/f3/f4/");put("name","2.txt");put("data","abcdefg");}}; Map<String,String> m2 = new HashMap<String,String>(){{put("path","/f1/f2/f3/f4/");put("name","2.txt");put("data","abcdefg");}};
Map<String,String> m3 = new HashMap(){{put("path","");put("name","3.txt");put("data","abcdefg");}}; Map<String,String> m3 = new HashMap<String,String>(){{put("path","");put("name","3.txt");put("data","abcdefg");}};
list.add(m1); list.add(m1);
list.add(m2); list.add(m2);
list.add(m3); list.add(m3);
toZip(list, outputStream); toZip(list, outputStream);
if (outputStream != null) { outputStream.close();
outputStream.close();
}
} }
} }

@ -66,7 +66,7 @@ public class ShiroConfig {
/** /**
* filer * filer
* @param securityManager * @param securityManager
* @return * @return
*/ */
@Bean("shiroFilter") @Bean("shiroFilter")

@ -60,13 +60,13 @@ public class StartPrint {
// 睡一秒打印 // 睡一秒打印
ThreadUtil.sleep(1, TimeUnit.SECONDS); ThreadUtil.sleep(1, TimeUnit.SECONDS);
String basePath = getBasePath(); String basePath = getBasePath();
StringBuilder printStr = new StringBuilder(); String printStr =
printStr.append("\n----------------------------------------------------------\n") "\n----------------------------------------------------------\n" +
.append("OPSLI 快速开发平台 框架启动成功! 相关URLs:\n") "OPSLI 快速开发平台 框架启动成功! 相关URLs:\n" +
.append("项目地址: \t\thttp://" + basePath + "/\n") "项目地址: \t\thttp://" + basePath + "/\n" +
.append("Doc文档: \t\thttp://" + basePath + "/doc.html\n") "Doc文档: \t\thttp://" + basePath + "/doc.html\n" +
.append("----------------------------------------------------------\n"); "----------------------------------------------------------\n";
Console.log(printStr.toString()); Console.log(printStr);
} }
/** /**
@ -76,11 +76,11 @@ public class StartPrint {
public void errorPrint(){ public void errorPrint(){
// 睡一秒打印 // 睡一秒打印
ThreadUtil.sleep(1, TimeUnit.SECONDS); ThreadUtil.sleep(1, TimeUnit.SECONDS);
StringBuilder printStr = new StringBuilder(); String printStr =
printStr.append("\n----------------------------------------------------------\n") "\n----------------------------------------------------------\n" +
.append("OPSLI 快速开发平台 框架启动失败! 请检查相关配置!\n") "OPSLI 快速开发平台 框架启动失败! 请检查相关配置!\n" +
.append("----------------------------------------------------------\n"); "----------------------------------------------------------\n";
Console.log(printStr.toString()); Console.log(printStr);
} }

@ -15,8 +15,10 @@ import org.springframework.stereotype.Component;
@Component @Component
@Slf4j @Slf4j
public class ApplicationFailedEventListener implements ApplicationListener<ApplicationFailedEvent> { public class ApplicationFailedEventListener implements ApplicationListener<ApplicationFailedEvent> {
@Override @Override
public void onApplicationEvent(ApplicationFailedEvent event) { public void onApplicationEvent(ApplicationFailedEvent event) {
StartPrint.INSTANCE.errorPrint(); StartPrint.INSTANCE.errorPrint();
} }
}
}

@ -14,10 +14,12 @@ import org.springframework.stereotype.Component;
*/ */
@Component @Component
@Slf4j @Slf4j
public class ApplicationReadyEventListene implements ApplicationListener<ApplicationReadyEvent> { public class ApplicationReadyEventListener implements ApplicationListener<ApplicationReadyEvent> {
@Override @Override
public void onApplicationEvent(ApplicationReadyEvent event) { public void onApplicationEvent(ApplicationReadyEvent event) {
event.getApplicationContext(); event.getApplicationContext();
StartPrint.INSTANCE.successPrint(); StartPrint.INSTANCE.successPrint();
} }
} }

@ -68,8 +68,8 @@ public enum CoreMsg implements BaseMsg {
; ;
private int code; private final int code;
private String message; private final String message;
CoreMsg(int code,String message){ CoreMsg(int code,String message){
this.code = code; this.code = code;

@ -34,8 +34,8 @@ public enum JwtMsg implements BaseMsg {
; ;
private int code; private final int code;
private String message; private final String message;
JwtMsg(int code, String message){ JwtMsg(int code, String message){
this.code = code; this.code = code;

@ -53,8 +53,8 @@ public enum TokenMsg implements BaseMsg {
EXCEPTION_NOT_AUTH(12202, "无权访问该方法"), EXCEPTION_NOT_AUTH(12202, "无权访问该方法"),
; ;
private int code; private final int code;
private String message; private final String message;
TokenMsg(int code, String message){ TokenMsg(int code, String message){
this.code = code; this.code = code;

@ -70,19 +70,6 @@ public class Page<T extends BaseEntity,E extends ApiWrapper> extends PageSeriali
this.queryWrapper = queryWrapper; this.queryWrapper = queryWrapper;
} }
/**
*
* @param pageNo
* @param pageSize
*/
public Page(int pageNo, int pageSize, String orderBy) {
super();
this.pageNo = pageNo;
this.pageSize = pageSize;
}
/** /**
* *
*/ */

@ -37,8 +37,7 @@ public class GenQueryBuilder<T extends BaseEntity> implements QueryBuilder<T> {
@Override @Override
public QueryWrapper<T> build() { public QueryWrapper<T> build() {
QueryWrapper<T> queryWrapper = new QueryWrapper<>(); return new QueryWrapper<>();
return queryWrapper;
} }
} }

@ -47,11 +47,11 @@ public class WebQueryBuilder<T extends BaseEntity> implements QueryBuilder<T>{
private static final String ORDER_DESC = "DESC"; private static final String ORDER_DESC = "DESC";
/** 参数 */ /** 参数 */
private Map<String, String[]> parameterMap; private final Map<String, String[]> parameterMap;
/** Entity Clazz */ /** Entity Clazz */
private Class<? extends BaseEntity> entityClazz; private final Class<? extends BaseEntity> entityClazz;
/** 默认排序字段 */ /** 默认排序字段 */
private String defaultOrderField; private final String defaultOrderField;
/** /**
* *
@ -152,27 +152,33 @@ public class WebQueryBuilder<T extends BaseEntity> implements QueryBuilder<T>{
} }
// 转换驼峰 为 数据库下划线字段 // 转换驼峰 为 数据库下划线字段
key = HumpUtil.humpToUnderline(key); key = HumpUtil.humpToUnderline(key);
if (EQ.equals(handle)) { switch (handle) {
// 全值匹配 case EQ:
queryWrapper.eq(key,value); // 全值匹配
} else if (LIKE.equals(handle)) { queryWrapper.eq(key, value);
// 模糊匹配 break;
queryWrapper.like(key,value); case LIKE:
} else if (BEGIN.equals(handle)) { // 模糊匹配
// 大于等于 queryWrapper.like(key, value);
queryWrapper.ge(key,value); break;
} else if (END.equals(handle)) { case BEGIN:
// 小于等于 // 大于等于
queryWrapper.le(key,value); queryWrapper.ge(key, value);
} else if (ORDER.equals(handle)) { break;
// 排序 case END:
if(ORDER_ASC.equals(value)){ // 小于等于
queryWrapper.orderByAsc(key); queryWrapper.le(key, value);
} else if(ORDER_DESC.equals(value)){ break;
queryWrapper.orderByDesc(key); case ORDER:
} else{ // 排序
queryWrapper.orderByAsc(key); if (ORDER_ASC.equals(value)) {
} queryWrapper.orderByAsc(key);
} else if (ORDER_DESC.equals(value)) {
queryWrapper.orderByDesc(key);
} else {
queryWrapper.orderByAsc(key);
}
break;
} }
} }
@ -208,9 +214,8 @@ public class WebQueryBuilder<T extends BaseEntity> implements QueryBuilder<T>{
return true; return true;
} else if (END.equals(handle)) { } else if (END.equals(handle)) {
return true; return true;
} else if (ORDER.equals(handle)) { } else {
return true; return ORDER.equals(handle);
} }
return false;
} }
} }

@ -1,8 +1,7 @@
package org.opsli.core.utils; package org.opsli.core.utils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
@ -17,12 +16,11 @@ import org.springframework.stereotype.Component;
*/ */
@Component @Component
@Lazy(false) @Lazy(false)
@Slf4j
public class SpringContextHolder implements ApplicationContextAware, DisposableBean { public class SpringContextHolder implements ApplicationContextAware, DisposableBean {
private static ApplicationContext applicationContext = null; private static ApplicationContext applicationContext = null;
private static Logger logger = LoggerFactory.getLogger(SpringContextHolder.class);
/** /**
* applicationContextBean, . * applicationContextBean, .
@ -45,8 +43,8 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB
* SpringContextHolderApplicationContextNull. * SpringContextHolderApplicationContextNull.
*/ */
public static void clearHolder() { public static void clearHolder() {
if (logger.isDebugEnabled()){ if (log.isDebugEnabled()){
logger.debug("清除SpringContextHolder中的ApplicationContext:" + applicationContext); log.debug("清除SpringContextHolder中的ApplicationContext:" + applicationContext);
} }
applicationContext = null; applicationContext = null;
} }

@ -159,7 +159,7 @@ public class UserTokenUtil {
String userId = ""; String userId = "";
try { try {
userId = JwtUtil.getClaim(token, SignConstants.USER_ID); userId = JwtUtil.getClaim(token, SignConstants.USER_ID);
}catch (Exception e){} }catch (Exception ignored){}
return userId; return userId;
} }

@ -16,7 +16,6 @@
package org.opsli.core.waf.filter; package org.opsli.core.waf.filter;
import org.opsli.common.exception.TokenException;
import org.opsli.core.waf.servlet.WafHttpServletRequestWrapper; import org.opsli.core.waf.servlet.WafHttpServletRequestWrapper;
import javax.servlet.*; import javax.servlet.*;

@ -78,8 +78,8 @@ public enum SystemMsg implements BaseMsg {
; ;
private int code; private final int code;
private String message; private final String message;
SystemMsg(int code, String message){ SystemMsg(int code, String message){
this.code = code; this.code = code;

@ -37,8 +37,8 @@ public enum EhCacheMsg implements BaseMsg {
; ;
private int code; private final int code;
private String message; private final String message;
EhCacheMsg(int code, String message){ EhCacheMsg(int code, String message){
this.code = code; this.code = code;

@ -32,7 +32,7 @@ public class ExcelListener extends AnalysisEventListener {
private static final String SERIAL_VERSION_UID = "serialVersionUID"; private static final String SERIAL_VERSION_UID = "serialVersionUID";
private List<Object> dataList = new ArrayList<>(); private final List<Object> dataList = new ArrayList<>();
/** /**
* AnalysisContext sheet * AnalysisContext sheet

@ -32,8 +32,8 @@ public enum ExcelMsg implements BaseMsg {
; ;
private int code; private final int code;
private String message; private final String message;
ExcelMsg(int code, String message){ ExcelMsg(int code, String message){
this.code = code; this.code = code;

@ -31,8 +31,8 @@ public enum MailMsg implements BaseMsg {
; ;
private int code; private final int code;
private String message; private final String message;
MailMsg(int code,String message){ MailMsg(int code,String message){
this.code = code; this.code = code;

Loading…
Cancel
Save