ReView优化 符合阿里规范

v1.4.1
Parker 4 years ago
parent 747303df4a
commit 32860d0ed4

@ -43,6 +43,9 @@ public final class ValidationUtil {
/** 编码格式 */ /** 编码格式 */
private static final String CHARSET_NAME = "utf-8"; private static final String CHARSET_NAME = "utf-8";
/** NULL */
private static final String NULL = "null";
/** /**
* *
* @param obj * @param obj
@ -112,7 +115,9 @@ public final class ValidationUtil {
break; break;
// 字母,数字和下划线 // 字母,数字和下划线
case IS_GENERAL: case IS_GENERAL:
if(StringUtils.isEmpty(value) || "null".equals(value)) break; if(StringUtils.isEmpty(value) || NULL.equals(value)) {
break;
}
boolean general = Validator.isGeneral(value); boolean general = Validator.isGeneral(value);
if(!general){ if(!general){
ValidationMsg msg = ValidationMsg.EXCEPTION_IS_GENERAL; ValidationMsg msg = ValidationMsg.EXCEPTION_IS_GENERAL;
@ -122,7 +127,9 @@ public final class ValidationUtil {
break; break;
// 数字 // 数字
case IS_NUMBER: case IS_NUMBER:
if(StringUtils.isEmpty(value) || "null".equals(value)) break; if(StringUtils.isEmpty(value) || NULL.equals(value)){
break;
}
boolean number = Validator.isNumber(value); boolean number = Validator.isNumber(value);
if(!number){ if(!number){
ValidationMsg msg = ValidationMsg.EXCEPTION_IS_NUMBER; ValidationMsg msg = ValidationMsg.EXCEPTION_IS_NUMBER;
@ -132,7 +139,9 @@ public final class ValidationUtil {
break; break;
// 纯字母 // 纯字母
case IS_LETTER: case IS_LETTER:
if(StringUtils.isEmpty(value) || "null".equals(value)) break; if(StringUtils.isEmpty(value) || NULL.equals(value)){
break;
}
boolean letter = Validator.isLetter(value); boolean letter = Validator.isLetter(value);
if(!letter){ if(!letter){
ValidationMsg msg = ValidationMsg.EXCEPTION_IS_LETTER; ValidationMsg msg = ValidationMsg.EXCEPTION_IS_LETTER;
@ -142,7 +151,9 @@ public final class ValidationUtil {
break; break;
// 大写 // 大写
case IS_UPPER_CASE: case IS_UPPER_CASE:
if(StringUtils.isEmpty(value) || "null".equals(value)) break; if(StringUtils.isEmpty(value) || NULL.equals(value)){
break;
}
boolean upperCase = Validator.isUpperCase(value); boolean upperCase = Validator.isUpperCase(value);
if(!upperCase){ if(!upperCase){
ValidationMsg msg = ValidationMsg.EXCEPTION_IS_UPPER_CASE; ValidationMsg msg = ValidationMsg.EXCEPTION_IS_UPPER_CASE;
@ -152,7 +163,9 @@ public final class ValidationUtil {
break; break;
// 小写 // 小写
case IS_LOWER_CASE: case IS_LOWER_CASE:
if(StringUtils.isEmpty(value) || "null".equals(value)) break; if(StringUtils.isEmpty(value) || NULL.equals(value)){
break;
}
boolean lowerCase = Validator.isLowerCase(value); boolean lowerCase = Validator.isLowerCase(value);
if(!lowerCase){ if(!lowerCase){
ValidationMsg msg = ValidationMsg.EXCEPTION_IS_LOWER_CASE; ValidationMsg msg = ValidationMsg.EXCEPTION_IS_LOWER_CASE;
@ -162,7 +175,9 @@ public final class ValidationUtil {
break; break;
// IPV4 // IPV4
case IS_IPV4: case IS_IPV4:
if(StringUtils.isEmpty(value) || "null".equals(value)) break; if(StringUtils.isEmpty(value) || NULL.equals(value)){
break;
}
boolean ipv4 = Validator.isIpv4(value); boolean ipv4 = Validator.isIpv4(value);
if(!ipv4){ if(!ipv4){
ValidationMsg msg = ValidationMsg.EXCEPTION_IS_IPV4; ValidationMsg msg = ValidationMsg.EXCEPTION_IS_IPV4;
@ -172,7 +187,9 @@ public final class ValidationUtil {
break; break;
// 金额 // 金额
case IS_MONEY: case IS_MONEY:
if(StringUtils.isEmpty(value) || "null".equals(value)) break; if(StringUtils.isEmpty(value) || NULL.equals(value)){
break;
}
boolean money = Validator.isMoney(value); boolean money = Validator.isMoney(value);
if(!money){ if(!money){
ValidationMsg msg = ValidationMsg.EXCEPTION_IS_MONEY; ValidationMsg msg = ValidationMsg.EXCEPTION_IS_MONEY;
@ -182,7 +199,9 @@ public final class ValidationUtil {
break; break;
// 邮箱 // 邮箱
case IS_EMAIL: case IS_EMAIL:
if(StringUtils.isEmpty(value) || "null".equals(value)) break; if(StringUtils.isEmpty(value) || NULL.equals(value)){
break;
}
boolean email = Validator.isEmail(value); boolean email = Validator.isEmail(value);
if(!email){ if(!email){
ValidationMsg msg = ValidationMsg.EXCEPTION_IS_EMAIL; ValidationMsg msg = ValidationMsg.EXCEPTION_IS_EMAIL;
@ -192,7 +211,9 @@ public final class ValidationUtil {
break; break;
// 手机号 // 手机号
case IS_MOBILE: case IS_MOBILE:
if(StringUtils.isEmpty(value) || "null".equals(value)) break; if(StringUtils.isEmpty(value) || NULL.equals(value)){
break;
}
boolean mobile = Validator.isMobile(value); boolean mobile = Validator.isMobile(value);
if(!mobile){ if(!mobile){
ValidationMsg msg = ValidationMsg.EXCEPTION_IS_MOBILE; ValidationMsg msg = ValidationMsg.EXCEPTION_IS_MOBILE;
@ -202,7 +223,9 @@ public final class ValidationUtil {
break; break;
// 18位身份证 // 18位身份证
case IS_CITIZENID: case IS_CITIZENID:
if(StringUtils.isEmpty(value) || "null".equals(value)) break; if(StringUtils.isEmpty(value) || NULL.equals(value)){
break;
}
boolean citizenId = Validator.isCitizenId(value); boolean citizenId = Validator.isCitizenId(value);
if(!citizenId){ if(!citizenId){
ValidationMsg msg = ValidationMsg.EXCEPTION_IS_CITIZENID; ValidationMsg msg = ValidationMsg.EXCEPTION_IS_CITIZENID;
@ -212,7 +235,9 @@ public final class ValidationUtil {
break; break;
// 邮编 // 邮编
case IS_ZIPCODE: case IS_ZIPCODE:
if(StringUtils.isEmpty(value) || "null".equals(value)) break; if(StringUtils.isEmpty(value) || NULL.equals(value)){
break;
}
boolean zipCode = Validator.isZipCode(value); boolean zipCode = Validator.isZipCode(value);
if(!zipCode){ if(!zipCode){
ValidationMsg msg = ValidationMsg.EXCEPTION_IS_ZIPCODE; ValidationMsg msg = ValidationMsg.EXCEPTION_IS_ZIPCODE;
@ -222,7 +247,9 @@ public final class ValidationUtil {
break; break;
// URL // URL
case IS_URL: case IS_URL:
if(StringUtils.isEmpty(value) || "null".equals(value)) break; if(StringUtils.isEmpty(value) || NULL.equals(value)){
break;
}
boolean url = Validator.isUrl(value); boolean url = Validator.isUrl(value);
if(!url){ if(!url){
ValidationMsg msg = ValidationMsg.EXCEPTION_IS_URL; ValidationMsg msg = ValidationMsg.EXCEPTION_IS_URL;
@ -232,7 +259,9 @@ public final class ValidationUtil {
break; break;
// 汉字 // 汉字
case IS_CHINESE: case IS_CHINESE:
if(StringUtils.isEmpty(value) || "null".equals(value)) break; if(StringUtils.isEmpty(value) || NULL.equals(value)){
break;
}
boolean chinese = Validator.isChinese(value); boolean chinese = Validator.isChinese(value);
if(!chinese){ if(!chinese){
ValidationMsg msg = ValidationMsg.EXCEPTION_IS_CHINESE; ValidationMsg msg = ValidationMsg.EXCEPTION_IS_CHINESE;
@ -242,7 +271,9 @@ public final class ValidationUtil {
break; break;
// 汉字,字母,数字和下划线 // 汉字,字母,数字和下划线
case IS_GENERAL_WITH_CHINESE: case IS_GENERAL_WITH_CHINESE:
if(StringUtils.isEmpty(value) || "null".equals(value)) break; if(StringUtils.isEmpty(value) || NULL.equals(value)){
break;
}
boolean generalWithChinese = Validator.isGeneralWithChinese(value); boolean generalWithChinese = Validator.isGeneralWithChinese(value);
if(!generalWithChinese){ if(!generalWithChinese){
ValidationMsg msg = ValidationMsg.EXCEPTION_IS_GENERAL_WITH_CHINESE; ValidationMsg msg = ValidationMsg.EXCEPTION_IS_GENERAL_WITH_CHINESE;
@ -252,7 +283,9 @@ public final class ValidationUtil {
break; break;
// MAC地址 // MAC地址
case IS_MAC: case IS_MAC:
if(StringUtils.isEmpty(value) || "null".equals(value)) break; if(StringUtils.isEmpty(value) || NULL.equals(value)){
break;
}
boolean mac = Validator.isMac(value); boolean mac = Validator.isMac(value);
if(!mac){ if(!mac){
ValidationMsg msg = ValidationMsg.EXCEPTION_IS_MAC; ValidationMsg msg = ValidationMsg.EXCEPTION_IS_MAC;
@ -262,7 +295,9 @@ public final class ValidationUtil {
break; break;
// 中国车牌 // 中国车牌
case IS_PLATE_NUMBER: case IS_PLATE_NUMBER:
if(StringUtils.isEmpty(value) || "null".equals(value)) break; if(StringUtils.isEmpty(value) || NULL.equals(value)){
break;
}
boolean plateNumber = Validator.isPlateNumber(value); boolean plateNumber = Validator.isPlateNumber(value);
if(!plateNumber){ if(!plateNumber){
ValidationMsg msg = ValidationMsg.EXCEPTION_IS_PLATE_NUMBER; ValidationMsg msg = ValidationMsg.EXCEPTION_IS_PLATE_NUMBER;
@ -299,7 +334,7 @@ public final class ValidationUtil {
// 循环验证 // 循环验证
try { try {
String value = String.valueOf(fieldValue); String value = String.valueOf(fieldValue);
if(value != null && !"null".equals(value)){ if(value != null && !NULL.equals(value)){
// 转换为 数据库真实 长度 // 转换为 数据库真实 长度
int strLength = value.getBytes(CHARSET_NAME).length; int strLength = value.getBytes(CHARSET_NAME).length;
if(strLength > maxLength){ if(strLength > maxLength){
@ -332,7 +367,7 @@ public final class ValidationUtil {
// 循环验证 // 循环验证
try { try {
String value = String.valueOf(fieldValue); String value = String.valueOf(fieldValue);
if(value != null && !"null".equals(value)){ if(value != null && !NULL.equals(value)){
// 转换为 数据库真实 长度 // 转换为 数据库真实 长度
int strLength = value.getBytes(CHARSET_NAME).length; int strLength = value.getBytes(CHARSET_NAME).length;
if(strLength < minLength){ if(strLength < minLength){

@ -25,21 +25,21 @@ package org.opsli.common.api;
public class TokenThreadLocal { public class TokenThreadLocal {
/** 临时线程存储 token 容器 */ /** 临时线程存储 token 容器 */
private static final ThreadLocal<String> tokenData = new ThreadLocal<>(); private static final ThreadLocal<String> TOKEN_DATA = new ThreadLocal<>();
public static void put(String token) { public static void put(String token) {
if (tokenData.get() == null) { if (TOKEN_DATA.get() == null) {
tokenData.set(token); TOKEN_DATA.set(token);
} }
} }
public static String get() { public static String get() {
return tokenData.get(); return TOKEN_DATA.get();
} }
public static void remove() { public static void remove() {
try { try {
tokenData.remove(); TOKEN_DATA.remove();
}catch (Exception e){} }catch (Exception e){}
} }
} }

@ -27,14 +27,12 @@ import org.opsli.common.utils.Props;
*/ */
public final class MyBatisConstants { public final class MyBatisConstants {
private static final Props prop = new Props("application.yaml");
/** 逻辑删除值 */ /** 逻辑删除值 */
public static final char LOGIC_DELETE_VALUE = public static final char LOGIC_DELETE_VALUE;
prop.getChar("mybatis-plus.global-config.db-config.logic-delete-value",'1');
/** 逻辑不删除值 */ /** 逻辑不删除值 */
public static final char LOGIC_NOT_DELETE_VALUE = public static final char LOGIC_NOT_DELETE_VALUE;
prop.getChar("mybatis-plus.global-config.db-config.logic-not-delete-value",'0');
/** ID */ /** ID */
public static final String FIELD_ID = "id"; public static final String FIELD_ID = "id";
@ -55,5 +53,12 @@ public final class MyBatisConstants {
/** 多租户字段 */ /** 多租户字段 */
public static final String FIELD_TENANT = "tenantId"; public static final String FIELD_TENANT = "tenantId";
static {
Props props = new Props("application.yaml");
LOGIC_DELETE_VALUE = props.getChar("mybatis-plus.global-config.db-config.logic-delete-value",'1');
LOGIC_NOT_DELETE_VALUE = props.getChar("mybatis-plus.global-config.db-config.logic-not-delete-value",'0');
}
private MyBatisConstants(){} private MyBatisConstants(){}
} }

@ -50,10 +50,12 @@ public class NameableThreadFactory implements ThreadFactory{
Thread t = new Thread(threadGroup, r, Thread t = new Thread(threadGroup, r,
namePrefix + threadNumber.getAndIncrement(), namePrefix + threadNumber.getAndIncrement(),
0); 0);
if (t.isDaemon()) if (t.isDaemon()){
t.setDaemon(false); t.setDaemon(false);
if (t.getPriority() != Thread.NORM_PRIORITY) }
if (t.getPriority() != Thread.NORM_PRIORITY){
t.setPriority(Thread.NORM_PRIORITY); t.setPriority(Thread.NORM_PRIORITY);
}
return t; return t;
} }
} }

@ -32,8 +32,8 @@ public class BigDecimalUtil {
* @return * @return
*/ */
public static double add(double value1,double value2){ public static double add(double value1,double value2){
BigDecimal b1 = new BigDecimal(Double.toString(value1)); BigDecimal b1 = BigDecimal.valueOf(value1);
BigDecimal b2 = new BigDecimal(Double.toString(value2)); BigDecimal b2 = BigDecimal.valueOf(value2);
return b1.add(b2).doubleValue(); return b1.add(b2).doubleValue();
} }
@ -44,8 +44,8 @@ public class BigDecimalUtil {
* @return * @return
*/ */
public static double sub(double value1,double value2){ public static double sub(double value1,double value2){
BigDecimal b1 = new BigDecimal(Double.toString(value1)); BigDecimal b1 = BigDecimal.valueOf(value1);
BigDecimal b2 = new BigDecimal(Double.toString(value2)); BigDecimal b2 = BigDecimal.valueOf(value2);
return b1.subtract(b2).doubleValue(); return b1.subtract(b2).doubleValue();
} }
@ -56,8 +56,8 @@ public class BigDecimalUtil {
* @return * @return
*/ */
public static double mul(double value1,double value2){ public static double mul(double value1,double value2){
BigDecimal b1 = new BigDecimal(Double.toString(value1)); BigDecimal b1 = BigDecimal.valueOf(value1);
BigDecimal b2 = new BigDecimal(Double.toString(value2)); BigDecimal b2 = BigDecimal.valueOf(value2);
return b1.multiply(b2).doubleValue(); return b1.multiply(b2).doubleValue();
} }
@ -83,8 +83,8 @@ public class BigDecimalUtil {
if(scale<0){ if(scale<0){
throw new IllegalAccessException("精确度不能小于0"); throw new IllegalAccessException("精确度不能小于0");
} }
BigDecimal b1 = new BigDecimal(Double.toString(value1)); BigDecimal b1 = BigDecimal.valueOf(value1);
BigDecimal b2 = new BigDecimal(Double.toString(value2)); BigDecimal b2 = BigDecimal.valueOf(value2);
return b1.divide(b2, scale, model).doubleValue(); return b1.divide(b2, scale, model).doubleValue();
} }
public static double div(double value1,double value2,int scale) throws IllegalAccessException{ public static double div(double value1,double value2,int scale) throws IllegalAccessException{
@ -92,8 +92,8 @@ public class BigDecimalUtil {
if(scale<0){ if(scale<0){
throw new IllegalAccessException("精确度不能小于0"); throw new IllegalAccessException("精确度不能小于0");
} }
BigDecimal b1 = new BigDecimal(Double.toString(value1)); BigDecimal b1 = BigDecimal.valueOf(value1);
BigDecimal b2 = new BigDecimal(Double.toString(value2)); BigDecimal b2 = BigDecimal.valueOf(value2);
return b1.divide(b2, scale,4).doubleValue(); return b1.divide(b2, scale,4).doubleValue();
} }
} }

@ -39,7 +39,7 @@ public final class HumpUtil {
public static String underlineToHump(String para) { public static String underlineToHump(String para) {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
String a[] = para.split(UNDERLINE); String[] a = para.split(UNDERLINE);
for (String s : a) { for (String s : a) {
if (!para.contains(UNDERLINE)) { if (!para.contains(UNDERLINE)) {
result.append(s); result.append(s);

@ -26,6 +26,8 @@ import javax.servlet.http.HttpServletRequest;
*/ */
public final class IPUtil { public final class IPUtil {
private static final String UNKNOWN = "unknown";
/** /**
* ip(穿) * ip(穿)
* *
@ -34,19 +36,19 @@ public final class IPUtil {
*/ */
public static String getRemoteAddr(HttpServletRequest request) { public static String getRemoteAddr(HttpServletRequest request) {
String ip = request.getHeader("X-Forwarded-For"); String ip = request.getHeader("X-Forwarded-For");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP"); ip = request.getHeader("Proxy-Client-IP");
} }
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP"); ip = request.getHeader("WL-Proxy-Client-IP");
} }
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP"); ip = request.getHeader("HTTP_CLIENT_IP");
} }
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR"); ip = request.getHeader("HTTP_X_FORWARDED_FOR");
} }
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr(); ip = request.getRemoteAddr();
} }
return ip; return ip;
@ -73,7 +75,7 @@ public final class IPUtil {
public static String getClientIpAddress(HttpServletRequest request) { public static String getClientIpAddress(HttpServletRequest request) {
for (String header : HEADERS_TO_TRY) { for (String header : HEADERS_TO_TRY) {
String ip = request.getHeader(header); String ip = request.getHeader(header);
if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) { if (ip != null && ip.length() != 0 && !UNKNOWN.equalsIgnoreCase(ip)) {
return ip; return ip;
} }
} }
@ -86,37 +88,37 @@ public final class IPUtil {
*/ */
public static String getClientIpAddr(HttpServletRequest request) { public static String getClientIpAddr(HttpServletRequest request) {
String ip = request.getHeader("X-Forwarded-For"); String ip = request.getHeader("X-Forwarded-For");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP"); ip = request.getHeader("Proxy-Client-IP");
} }
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP"); ip = request.getHeader("WL-Proxy-Client-IP");
} }
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR"); ip = request.getHeader("HTTP_X_FORWARDED_FOR");
} }
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED"); ip = request.getHeader("HTTP_X_FORWARDED");
} }
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_CLUSTER_CLIENT_IP"); ip = request.getHeader("HTTP_X_CLUSTER_CLIENT_IP");
} }
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP"); ip = request.getHeader("HTTP_CLIENT_IP");
} }
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_FORWARDED_FOR"); ip = request.getHeader("HTTP_FORWARDED_FOR");
} }
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_FORWARDED"); ip = request.getHeader("HTTP_FORWARDED");
} }
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_VIA"); ip = request.getHeader("HTTP_VIA");
} }
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("REMOTE_ADDR"); ip = request.getHeader("REMOTE_ADDR");
} }
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr(); ip = request.getRemoteAddr();
} }
return ip; return ip;
@ -124,12 +126,12 @@ public final class IPUtil {
public static String getIpAddr(HttpServletRequest request) { public static String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("X-Real-IP"); String ip = request.getHeader("X-Real-IP");
if (null != ip && !"".equals(ip.trim()) if (null != ip && !"".equals(ip.trim())
&& !"unknown".equalsIgnoreCase(ip)) { && !UNKNOWN.equalsIgnoreCase(ip)) {
return ip; return ip;
} }
ip = request.getHeader("X-Forwarded-For"); ip = request.getHeader("X-Forwarded-For");
if (null != ip && !"".equals(ip.trim()) if (null != ip && !"".equals(ip.trim())
&& !"unknown".equalsIgnoreCase(ip)) { && !UNKNOWN.equalsIgnoreCase(ip)) {
// get first ip from proxy ip // get first ip from proxy ip
int index = ip.indexOf(','); int index = ip.indexOf(',');
if (index != -1) { if (index != -1) {
@ -143,5 +145,6 @@ public final class IPUtil {
// =============== // ===============
private IPUtil(){} private IPUtil(){}
} }

@ -190,7 +190,9 @@ public class CacheDataAop {
try { try {
// 获得方法 // 获得方法
Method objMethod = this.getMethod(point); Method objMethod = this.getMethod(point);
if(objMethod == null) return null; if(objMethod == null) {
return null;
}
// 获取注解参数 // 获取注解参数
HotDataPut aCache= objMethod.getAnnotation(HotDataPut.class); HotDataPut aCache= objMethod.getAnnotation(HotDataPut.class);
@ -239,7 +241,9 @@ public class CacheDataAop {
try { try {
// 获得方法 // 获得方法
Method objMethod = this.getMethod(point); Method objMethod = this.getMethod(point);
if(objMethod == null) return null; if(objMethod == null) {
return null;
}
// 获取注解参数 // 获取注解参数
HotDataDel aCache= objMethod.getAnnotation(HotDataDel.class); HotDataDel aCache= objMethod.getAnnotation(HotDataDel.class);

@ -45,6 +45,8 @@ import static org.opsli.common.constants.OrderConstants.PARAM_VALIDATE_AOP_SORT;
@Component @Component
public class ValitaionArgsAop { public class ValitaionArgsAop {
/** post请求 */
private static final String POST_TYPE = "POST";
@Pointcut("execution(public * org.opsli.modulars*..*.*Controller*.*(..))") @Pointcut("execution(public * org.opsli.modulars*..*.*Controller*.*(..))")
public void requestMapping() { public void requestMapping() {
@ -60,12 +62,14 @@ public class ValitaionArgsAop {
try { try {
RequestAttributes ra = RequestContextHolder.getRequestAttributes(); RequestAttributes ra = RequestContextHolder.getRequestAttributes();
ServletRequestAttributes sra = (ServletRequestAttributes) ra; ServletRequestAttributes sra = (ServletRequestAttributes) ra;
if(sra == null) return; if(sra == null){
return;
}
HttpServletRequest request = sra.getRequest(); HttpServletRequest request = sra.getRequest();
String method = request.getMethod(); String method = request.getMethod();
// 只有 post 请求 才会去验证数据 // 只有 post 请求 才会去验证数据
if("POST".equals(method)){ if(POST_TYPE.equals(method)){
for (Object arg : args) { for (Object arg : args) {
// 参数校验 // 参数校验
if(arg instanceof ApiWrapper){ if(arg instanceof ApiWrapper){

@ -79,11 +79,11 @@ public abstract class BaseRestController <T extends BaseEntity, E extends ApiWra
/** Entity Clazz 类 */ /** Entity Clazz 类 */
protected Class<T> entityClazz; protected Class<T> entityClazz;
/** Entity 泛型游标 */ /** Entity 泛型游标 */
private static final int entityIndex = 0; private static final int ENTITY_INDEX = 0;
/** Model Clazz 类 */ /** Model Clazz 类 */
protected Class<E> modelClazz; protected Class<E> modelClazz;
/** Model 泛型游标 */ /** Model 泛型游标 */
private static final int modelIndex = 1; private static final int MODEL_INDEX = 1;
@Autowired(required = false) @Autowired(required = false)
protected S IService; protected S IService;
@ -326,7 +326,7 @@ public abstract class BaseRestController <T extends BaseEntity, E extends ApiWra
*/ */
private Class<E> getModelClass(){ private Class<E> getModelClass(){
Class<E> tClass = null; Class<E> tClass = null;
Type typeArgument = TypeUtil.getTypeArgument(getClass().getGenericSuperclass(), modelIndex); Type typeArgument = TypeUtil.getTypeArgument(getClass().getGenericSuperclass(), MODEL_INDEX);
if(typeArgument != null){ if(typeArgument != null){
tClass = (Class<E>) typeArgument; tClass = (Class<E>) typeArgument;
} }
@ -339,7 +339,7 @@ public abstract class BaseRestController <T extends BaseEntity, E extends ApiWra
*/ */
private Class<T> getEntityClass(){ private Class<T> getEntityClass(){
Class<T> tClass = null; Class<T> tClass = null;
Type typeArgument = TypeUtil.getTypeArgument(getClass().getGenericSuperclass(), entityIndex); Type typeArgument = TypeUtil.getTypeArgument(getClass().getGenericSuperclass(), ENTITY_INDEX);
if(typeArgument != null){ if(typeArgument != null){
tClass = (Class<T>) typeArgument; tClass = (Class<T>) typeArgument;
} }

@ -66,11 +66,11 @@ public abstract class CrudServiceImpl<M extends BaseMapper<T>, T extends BaseEnt
/** Entity Clazz 类 */ /** Entity Clazz 类 */
protected Class<T> entityClazz; protected Class<T> entityClazz;
/** Entity 泛型游标 */ /** Entity 泛型游标 */
private static final int entityIndex = 1; private static final int ENTITY_INDEX = 1;
/** Model Clazz 类 */ /** Model Clazz 类 */
protected Class<E> modelClazz; protected Class<E> modelClazz;
/** Model 泛型游标 */ /** Model 泛型游标 */
private static final int modelIndex = 2; private static final int MODEL_INDEX = 2;
@Override @Override
public E get(String id) { public E get(String id) {
@ -81,7 +81,9 @@ public abstract class CrudServiceImpl<M extends BaseMapper<T>, T extends BaseEnt
@Override @Override
public E get(E model) { public E get(E model) {
if(model == null) return null; if(model == null){
return null;
}
return transformT2M( return transformT2M(
super.getById(model.getId()) super.getById(model.getId())
); );
@ -90,7 +92,9 @@ public abstract class CrudServiceImpl<M extends BaseMapper<T>, T extends BaseEnt
@Override @Override
@Transactional(readOnly = false) @Transactional(readOnly = false)
public E insert(E model) { public E insert(E model) {
if(model == null) return null; if(model == null){
return null;
}
// 默认清空 创建人和修改人 // 默认清空 创建人和修改人
if(model.getIzManual() != null && !model.getIzManual()){ if(model.getIzManual() != null && !model.getIzManual()){
@ -111,7 +115,9 @@ public abstract class CrudServiceImpl<M extends BaseMapper<T>, T extends BaseEnt
@Override @Override
@Transactional(readOnly = false) @Transactional(readOnly = false)
public boolean insertBatch(List<E> models) { public boolean insertBatch(List<E> models) {
if(models == null || models.size() == 0) return false; if(models == null || models.size() == 0){
return false;
}
for (E model : models) { for (E model : models) {
// 默认清空 创建人和修改人 // 默认清空 创建人和修改人
@ -131,7 +137,9 @@ public abstract class CrudServiceImpl<M extends BaseMapper<T>, T extends BaseEnt
@Override @Override
@Transactional(readOnly = false) @Transactional(readOnly = false)
public E update(E model) { public E update(E model) {
if(model == null) return null; if(model == null){
return null;
}
// 默认清空 创建人和修改人 // 默认清空 创建人和修改人
if(model.getIzManual() != null && !model.getIzManual()){ if(model.getIzManual() != null && !model.getIzManual()){
@ -150,7 +158,9 @@ public abstract class CrudServiceImpl<M extends BaseMapper<T>, T extends BaseEnt
@Override @Override
@Transactional(readOnly = false) @Transactional(readOnly = false)
public E save(E model) { public E save(E model) {
if(model == null) return null; if(model == null){
return null;
}
// 修改 // 修改
if(StringUtils.isNotBlank(model.getId())){ if(StringUtils.isNotBlank(model.getId())){
@ -171,14 +181,18 @@ public abstract class CrudServiceImpl<M extends BaseMapper<T>, T extends BaseEnt
@Override @Override
@Transactional(readOnly = false) @Transactional(readOnly = false)
public boolean delete(E model) { public boolean delete(E model) {
if(model == null) return false; if(model == null){
return false;
}
return super.removeById(model.getId()); return super.removeById(model.getId());
} }
@Override @Override
@Transactional(readOnly = false) @Transactional(readOnly = false)
public boolean deleteAll(String[] ids) { public boolean deleteAll(String[] ids) {
if(ids == null) return false; if(ids == null){
return false;
}
List<String> idList = Convert.toList(String.class, ids); List<String> idList = Convert.toList(String.class, ids);
return super.removeByIds(idList); return super.removeByIds(idList);
} }
@ -186,7 +200,9 @@ public abstract class CrudServiceImpl<M extends BaseMapper<T>, T extends BaseEnt
@Override @Override
@Transactional(readOnly = false) @Transactional(readOnly = false)
public boolean deleteAll(Collection<E> models) { public boolean deleteAll(Collection<E> models) {
if(models == null || models.isEmpty()) return false; if(models == null || models.isEmpty()){
return false;
}
List<String> idList = Lists.newArrayListWithCapacity(models.size()); List<String> idList = Lists.newArrayListWithCapacity(models.size());
for (E entity : models) { for (E entity : models) {
idList.add(entity.getId()); idList.add(entity.getId());
@ -287,7 +303,7 @@ public abstract class CrudServiceImpl<M extends BaseMapper<T>, T extends BaseEnt
*/ */
private Class<E> getModelClazz(){ private Class<E> getModelClazz(){
Class<E> tClass = null; Class<E> tClass = null;
Type typeArgument = TypeUtil.getTypeArgument(getClass().getGenericSuperclass(), modelIndex); Type typeArgument = TypeUtil.getTypeArgument(getClass().getGenericSuperclass(), MODEL_INDEX);
if(typeArgument != null){ if(typeArgument != null){
tClass = (Class<E>) typeArgument; tClass = (Class<E>) typeArgument;
} }
@ -300,7 +316,7 @@ public abstract class CrudServiceImpl<M extends BaseMapper<T>, T extends BaseEnt
*/ */
private Class<T> getEntityClazz(){ private Class<T> getEntityClazz(){
Class<T> tClass = null; Class<T> tClass = null;
Type typeArgument = TypeUtil.getTypeArgument(getClass().getGenericSuperclass(), entityIndex); Type typeArgument = TypeUtil.getTypeArgument(getClass().getGenericSuperclass(), ENTITY_INDEX);
if(typeArgument != null){ if(typeArgument != null){
tClass = (Class<T>) typeArgument; tClass = (Class<T>) typeArgument;
} }

@ -57,14 +57,18 @@ public class DictHandler implements RedisPushSubHandler{
Collection<Object> dicts = (Collection<Object>) msgJson.get(MsgArgsType.DICT_MODELS.toString()); Collection<Object> dicts = (Collection<Object>) msgJson.get(MsgArgsType.DICT_MODELS.toString());
for (Object dictObj : dicts) { for (Object dictObj : dicts) {
JSONObject jsonObject = msgJson.getJSONObject(MsgArgsType.DICT_MODEL.toString()); JSONObject jsonObject = msgJson.getJSONObject(MsgArgsType.DICT_MODEL.toString());
if(jsonObject == null) continue; if(jsonObject == null){
continue;
}
DictWrapper dictWrapperModel = jsonObject.toJavaObject(DictWrapper.class); DictWrapper dictWrapperModel = jsonObject.toJavaObject(DictWrapper.class);
this.handler(dictWrapperModel, type); this.handler(dictWrapperModel, type);
} }
} else if(DictModelType.OBJECT == dictModelType){ } else if(DictModelType.OBJECT == dictModelType){
JSONObject jsonObject = msgJson.getJSONObject(MsgArgsType.DICT_MODEL.toString()); JSONObject jsonObject = msgJson.getJSONObject(MsgArgsType.DICT_MODEL.toString());
if(jsonObject == null) return; if(jsonObject == null){
return;
}
DictWrapper dictWrapperModel = jsonObject.toJavaObject(DictWrapper.class); DictWrapper dictWrapperModel = jsonObject.toJavaObject(DictWrapper.class);
this.handler(dictWrapperModel, type); this.handler(dictWrapperModel, type);

@ -57,7 +57,9 @@ public class MenuHandler implements RedisPushSubHandler{
private void menuHandler(JSONObject msgJson){ private void menuHandler(JSONObject msgJson){
JSONObject data = msgJson.getJSONObject(MsgArgsType.MENU_MODEL_DATA.toString()); JSONObject data = msgJson.getJSONObject(MsgArgsType.MENU_MODEL_DATA.toString());
// 数据为空则不执行 // 数据为空则不执行
if(data == null) return; if(data == null){
return;
}
// 获得菜单编号 // 获得菜单编号
String menuCode = (String) msgJson.get(MsgArgsType.MENU_CODE.toString()); String menuCode = (String) msgJson.get(MsgArgsType.MENU_CODE.toString());

@ -58,7 +58,9 @@ public class OrgHandler implements RedisPushSubHandler{
private void orgHandler(JSONObject msgJson){ private void orgHandler(JSONObject msgJson){
JSONObject data = msgJson.getJSONObject(MsgArgsType.ORG_USER_DATA.toString()); JSONObject data = msgJson.getJSONObject(MsgArgsType.ORG_USER_DATA.toString());
// 数据为空则不执行 // 数据为空则不执行
if(data == null) return; if(data == null){
return;
}
// 获得用户ID // 获得用户ID
String userId = (String) msgJson.get(MsgArgsType.ORG_USER_ID.toString()); String userId = (String) msgJson.get(MsgArgsType.ORG_USER_ID.toString());

@ -77,7 +77,9 @@ public class UserHandler implements RedisPushSubHandler{
private void userHandler(JSONObject msgJson){ private void userHandler(JSONObject msgJson){
JSONObject data = msgJson.getJSONObject(MsgArgsType.USER_MODEL_DATA.toString()); JSONObject data = msgJson.getJSONObject(MsgArgsType.USER_MODEL_DATA.toString());
// 数据为空则不执行 // 数据为空则不执行
if(data == null) return; if(data == null){
return;
}
// 获得用户ID 和 用户名 // 获得用户ID 和 用户名
String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString()); String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString());
@ -101,7 +103,9 @@ public class UserHandler implements RedisPushSubHandler{
private void userRolesHandler(JSONObject msgJson){ private void userRolesHandler(JSONObject msgJson){
JSONArray dataArray = msgJson.getJSONArray(MsgArgsType.USER_MODEL_DATA.toString()); JSONArray dataArray = msgJson.getJSONArray(MsgArgsType.USER_MODEL_DATA.toString());
// 数据为空则不执行 // 数据为空则不执行
if(dataArray == null || dataArray.isEmpty()) return; if(dataArray == null || dataArray.isEmpty()){
return;
}
// 获得用户ID // 获得用户ID
String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString()); String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString());
@ -122,7 +126,9 @@ public class UserHandler implements RedisPushSubHandler{
private void userPermsHandler(JSONObject msgJson){ private void userPermsHandler(JSONObject msgJson){
JSONArray dataArray = msgJson.getJSONArray(MsgArgsType.USER_MODEL_DATA.toString()); JSONArray dataArray = msgJson.getJSONArray(MsgArgsType.USER_MODEL_DATA.toString());
// 数据为空则不执行 // 数据为空则不执行
if(dataArray == null || dataArray.isEmpty()) return; if(dataArray == null || dataArray.isEmpty()){
return;
}
// 获得用户ID // 获得用户ID
String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString()); String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString());
@ -143,7 +149,9 @@ public class UserHandler implements RedisPushSubHandler{
private void userMenusHandler(JSONObject msgJson){ private void userMenusHandler(JSONObject msgJson){
JSONArray dataArray = msgJson.getJSONArray(MsgArgsType.USER_MODEL_DATA.toString()); JSONArray dataArray = msgJson.getJSONArray(MsgArgsType.USER_MODEL_DATA.toString());
// 数据为空则不执行 // 数据为空则不执行
if(dataArray == null || dataArray.isEmpty()) return; if(dataArray == null || dataArray.isEmpty()){
return;
}
// 获得用户ID // 获得用户ID
String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString()); String userId = (String) msgJson.get(MsgArgsType.USER_ID.toString());

@ -16,6 +16,7 @@
package org.opsli.core.conf; package org.opsli.core.conf;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import com.google.common.collect.Maps;
import org.apache.shiro.mgt.SecurityManager; import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.session.mgt.SessionManager; import org.apache.shiro.session.mgt.SessionManager;
import org.apache.shiro.spring.LifecycleBeanPostProcessor; import org.apache.shiro.spring.LifecycleBeanPostProcessor;
@ -71,11 +72,11 @@ public class ShiroConfig {
shiroFilter.setSecurityManager(securityManager); shiroFilter.setSecurityManager(securityManager);
//oauth过滤 //oauth过滤
Map<String, Filter> filters = new HashMap<>(); Map<String, Filter> filters = Maps.newHashMapWithExpectedSize(1);
filters.put("oauth2", new OAuth2Filter()); filters.put("oauth2", new OAuth2Filter());
shiroFilter.setFilters(filters); shiroFilter.setFilters(filters);
Map<String, String> filterMap = new LinkedHashMap<>(); Map<String, String> filterMap = Maps.newLinkedHashMap();
filterMap.put("/webjars/**", "anon"); filterMap.put("/webjars/**", "anon");
filterMap.put("/druid/**", "anon"); filterMap.put("/druid/**", "anon");
filterMap.put("/app/**", "anon"); filterMap.put("/app/**", "anon");

@ -51,6 +51,8 @@ import java.util.*;
@Intercepts(@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})) @Intercepts(@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class}))
public class AutoFillInterceptor implements Interceptor { public class AutoFillInterceptor implements Interceptor {
private static final String ET = "et";
@Override @Override
public Object intercept(Invocation invocation) throws IllegalAccessException, InvocationTargetException { public Object intercept(Invocation invocation) throws IllegalAccessException, InvocationTargetException {
fillField(invocation); fillField(invocation);
@ -69,11 +71,12 @@ public class AutoFillInterceptor implements Interceptor {
//String className = arg.getClass().getName(); //String className = arg.getClass().getName();
//log.info(i + " 参数类型:" + className); //log.info(i + " 参数类型:" + className);
//第一个参数处理。根据它判断是否给“操作属性”赋值。 //第一个参数处理。根据它判断是否给“操作属性”赋值。
if (arg instanceof MappedStatement) {//如果是第一个参数 MappedStatement //如果是第一个参数 MappedStatement
if (arg instanceof MappedStatement) {
MappedStatement ms = (MappedStatement) arg; MappedStatement ms = (MappedStatement) arg;
sqlCommandType = ms.getSqlCommandType(); sqlCommandType = ms.getSqlCommandType();
//log.info("操作类型:" + sqlCommandType); //如果是“增加”或“更新”操作,则继续进行默认操作信息赋值。否则,则退出
if (sqlCommandType == SqlCommandType.INSERT || sqlCommandType == SqlCommandType.UPDATE) {//如果是“增加”或“更新”操作,则继续进行默认操作信息赋值。否则,则退出 if (sqlCommandType == SqlCommandType.INSERT || sqlCommandType == SqlCommandType.UPDATE) {
continue; continue;
} else { } else {
break; break;
@ -96,7 +99,9 @@ public class AutoFillInterceptor implements Interceptor {
* @param arg * @param arg
*/ */
public void insertFill(Object arg) { public void insertFill(Object arg) {
if(arg == null ) return; if(arg == null ){
return;
}
Field[] fields = ReflectUtil.getFields(arg.getClass()); Field[] fields = ReflectUtil.getFields(arg.getClass());
for (Field f : fields) { for (Field f : fields) {
@ -162,14 +167,16 @@ public class AutoFillInterceptor implements Interceptor {
* @param arg * @param arg
*/ */
public void updateFill(Object arg) { public void updateFill(Object arg) {
if(arg == null ) return; if(arg == null ){
return;
}
// 2020-09-19 // 2020-09-19
// 修改这儿 有可能会拿到一个 MapperMethod需要特殊处理 // 修改这儿 有可能会拿到一个 MapperMethod需要特殊处理
Field[] fields; Field[] fields;
if (arg instanceof MapperMethod.ParamMap) { if (arg instanceof MapperMethod.ParamMap) {
MapperMethod.ParamMap<?> paramMap = (MapperMethod.ParamMap<?>) arg; MapperMethod.ParamMap<?> paramMap = (MapperMethod.ParamMap<?>) arg;
if (paramMap.containsKey("et")) { if (paramMap.containsKey(ET)) {
arg = paramMap.get("et"); arg = paramMap.get("et");
} else { } else {
arg = paramMap.get("param1"); arg = paramMap.get("param1");

@ -43,6 +43,8 @@ import static org.opsli.common.constants.OrderConstants.EXCEPTION_HANDLER_ORDER;
@Order(EXCEPTION_HANDLER_ORDER) @Order(EXCEPTION_HANDLER_ORDER)
public class GlobalExceptionHandler { public class GlobalExceptionHandler {
private static final String SQL_EXCEPTION = "doesn't have a default value";
/* /*
ArithmeticException ArithmeticException
NullPointerException NullPointerException
@ -197,7 +199,7 @@ public class GlobalExceptionHandler {
public ResultVo<?> sqlException(SQLException e) { public ResultVo<?> sqlException(SQLException e) {
//log.error("数据异常:{}",e.getMessage(),e); //log.error("数据异常:{}",e.getMessage(),e);
// 默认值异常 // 默认值异常
if(StringUtils.contains(e.getMessage(),"doesn't have a default value")){ if(StringUtils.contains(e.getMessage(),SQL_EXCEPTION)){
String Field = e.getMessage().replaceAll("Field '","") String Field = e.getMessage().replaceAll("Field '","")
.replaceAll("' doesn't have a default value",""); .replaceAll("' doesn't have a default value","");
String msg = StrFormatter.format(CoreMsg.SQL_EXCEPTION_NOT_HAVE_DEFAULT_VALUE.getMessage(), Field); String msg = StrFormatter.format(CoreMsg.SQL_EXCEPTION_NOT_HAVE_DEFAULT_VALUE.getMessage(), Field);

@ -26,6 +26,7 @@ import org.opsli.common.base.msg.BaseMsg;
*/ */
public enum JwtMsg implements BaseMsg { public enum JwtMsg implements BaseMsg {
/** 异常消息 */
EXCEPTION_TOKEN(11000,"认证解密异常: {}"), EXCEPTION_TOKEN(11000,"认证解密异常: {}"),
EXCEPTION_DECODE(10101,"解密异常: {}"), EXCEPTION_DECODE(10101,"解密异常: {}"),
EXCEPTION_ENCODE(10102,"加密异常: {}"), EXCEPTION_ENCODE(10102,"加密异常: {}"),

@ -113,7 +113,7 @@ public class Page<T extends BaseEntity,E extends ApiWrapper> extends PageSeriali
* @return map * @return map
*/ */
public Map<String, Object> getBootstrapData(){ public Map<String, Object> getBootstrapData(){
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>(2);
map.put("rows", this.getList()); map.put("rows", this.getList());
map.put("total", this.getTotal()); map.put("total", this.getTotal());
return map; return map;

@ -25,6 +25,9 @@ import java.util.List;
@Component @Component
public class OAuth2Realm extends AuthorizingRealm { public class OAuth2Realm extends AuthorizingRealm {
/** 账号锁定状态 */
private static final char LOCK_VAL = '1';
@Override @Override
public boolean supports(AuthenticationToken token) { public boolean supports(AuthenticationToken token) {
return token instanceof OAuth2Token; return token instanceof OAuth2Token;
@ -73,7 +76,7 @@ public class OAuth2Realm extends AuthorizingRealm {
UserModel user = UserUtil.getUser(userId); UserModel user = UserUtil.getUser(userId);
// 3. 校验账户是否锁定 // 3. 校验账户是否锁定
if(user == null || user.getLocked().equals('1')){ if(user == null || user.getLocked().equals(LOCK_VAL)){
// 账号已被锁定,请联系管理员 // 账号已被锁定,请联系管理员
// token失效请重新登录 // token失效请重新登录
throw new TokenException( throw new TokenException(

@ -24,7 +24,7 @@ import org.opsli.api.wrapper.system.user.UserModel;
/** /**
* Shiro * Shiro
* *
* @author * @author
* @date 20161112 9:49:19 * @date 20161112 9:49:19
@ -32,12 +32,12 @@ import org.opsli.api.wrapper.system.user.UserModel;
public class ShiroUtils { public class ShiroUtils {
/** 加密算法 */ /** 加密算法 */
public final static String hashAlgorithmName = "MD5"; public final static String HASH_ALGORITHM_NAME = "MD5";
/** 循环次数 */ /** 循环次数 */
public final static int hashIterations = 1; public final static int HASH_ITERATIONS = 1;
public static String sha256(String password, String salt) { public static String sha256(String password, String salt) {
return new SimpleHash(hashAlgorithmName, password, salt, hashIterations).toString(); return new SimpleHash(HASH_ALGORITHM_NAME, password, salt, HASH_ITERATIONS).toString();
} }
public static Session getSession() { public static Session getSession() {
@ -55,7 +55,7 @@ public class ShiroUtils {
public static String getUserId() { public static String getUserId() {
return getUser().getId(); return getUser().getId();
} }
public static void setSessionAttribute(Object key, Object value) { public static void setSessionAttribute(Object key, Object value) {
getSession().setAttribute(key, value); getSession().setAttribute(key, value);
} }
@ -71,7 +71,7 @@ public class ShiroUtils {
public static void logout() { public static void logout() {
SecurityUtils.getSubject().logout(); SecurityUtils.getSubject().logout();
} }
public static String getKaptcha(String key) throws RuntimeException { public static String getKaptcha(String key) throws RuntimeException {
Object kaptcha = getSessionAttribute(key); Object kaptcha = getSessionAttribute(key);
if(kaptcha == null){ if(kaptcha == null){

@ -90,7 +90,9 @@ public class CaptchaUtil{
* @return * @return
*/ */
public static boolean validate(String uuid, String code) { public static boolean validate(String uuid, String code) {
if(StringUtils.isEmpty(uuid)) return false; if(StringUtils.isEmpty(uuid)){
return false;
}
// 验证码 // 验证码
String codeTemp = (String) redisPlugin.get(PREFIX_NAME + PREFIX + uuid); String codeTemp = (String) redisPlugin.get(PREFIX_NAME + PREFIX + uuid);
@ -112,7 +114,9 @@ public class CaptchaUtil{
* @return * @return
*/ */
public static boolean delCaptcha(String uuid) { public static boolean delCaptcha(String uuid) {
if(StringUtils.isEmpty(uuid)) return false; if(StringUtils.isEmpty(uuid)){
return false;
}
//删除验证码 //删除验证码
return redisPlugin.del(PREFIX_NAME + PREFIX + uuid); return redisPlugin.del(PREFIX_NAME + PREFIX + uuid);

@ -81,7 +81,9 @@ public class DictUtil {
if (cacheModel != null){ if (cacheModel != null){
dictName = cacheModel.getDictName(); dictName = cacheModel.getDictName();
} }
if (StringUtils.isNotEmpty(dictName)) return dictName; if (StringUtils.isNotEmpty(dictName)){
return dictName;
}
// 防止缓存穿透判断 // 防止缓存穿透判断
@ -112,7 +114,9 @@ public class DictUtil {
if (cacheModel != null){ if (cacheModel != null){
dictName = cacheModel.getDictName(); dictName = cacheModel.getDictName();
} }
if (StringUtils.isNotEmpty(dictName)) return dictName; if (StringUtils.isNotEmpty(dictName)){
return dictName;
}
// 查询数据库 并保存到缓存内 // 查询数据库 并保存到缓存内
ResultVo<List<DictDetailModel>> resultVo = dictDetailApi.findListByTypeCode(typeCode); ResultVo<List<DictDetailModel>> resultVo = dictDetailApi.findListByTypeCode(typeCode);
@ -168,7 +172,9 @@ public class DictUtil {
if (cacheModel != null){ if (cacheModel != null){
dictValue = cacheModel.getDictValue(); dictValue = cacheModel.getDictValue();
} }
if (StringUtils.isNotEmpty(dictValue)) return dictValue; if (StringUtils.isNotEmpty(dictValue)){
return dictValue;
}
// 防止缓存穿透判断 // 防止缓存穿透判断
boolean hasNilFlag = CacheUtil.hasNilFlag(DictConstants.CACHE_PREFIX_NAME + typeCode + ":" + dictName); boolean hasNilFlag = CacheUtil.hasNilFlag(DictConstants.CACHE_PREFIX_NAME + typeCode + ":" + dictName);
@ -196,7 +202,9 @@ public class DictUtil {
if (cacheModel != null){ if (cacheModel != null){
dictValue = cacheModel.getDictValue(); dictValue = cacheModel.getDictValue();
} }
if (StringUtils.isNotEmpty(dictValue)) return dictValue; if (StringUtils.isNotEmpty(dictValue)){
return dictValue;
}
// 查询数据库 并保存到缓存内 // 查询数据库 并保存到缓存内
ResultVo<List<DictDetailModel>> resultVo = dictDetailApi.findListByTypeCode(typeCode); ResultVo<List<DictDetailModel>> resultVo = dictDetailApi.findListByTypeCode(typeCode);

@ -177,7 +177,9 @@ public class ExcelUtil extends ExcelPlugin {
String typeCode = entry.getValue(); String typeCode = entry.getValue();
List<DictWrapper> dictWrapperList = DictUtil.getDictList(typeCode); List<DictWrapper> dictWrapperList = DictUtil.getDictList(typeCode);
// 如果字典 List 为空 则走下一个 // 如果字典 List 为空 则走下一个
if(dictWrapperList == null || dictWrapperList.size() == 0) continue; if(dictWrapperList == null || dictWrapperList.size() == 0){
continue;
}
typeCodeAndValue.put(typeCode, dictWrapperList); typeCodeAndValue.put(typeCode, dictWrapperList);
} }
return typeCodeAndValue; return typeCodeAndValue;

@ -32,7 +32,7 @@ public final class JwtUtil {
/** /**
* JWT(Base64) * JWT(Base64)
*/ */
private static final String encryptJWTKey="a30ade6452725123436288ccae58570738ee"; private static final String ENCRYPT_JWT_KEY = "a30ade6452725123436288ccae58570738ee";
static { static {
Props props = new Props("application.yaml"); Props props = new Props("application.yaml");
@ -48,7 +48,7 @@ public final class JwtUtil {
*/ */
public static boolean verify(String token) { public static boolean verify(String token) {
try { try {
String secret = getClaim(token, SignConstants.ACCOUNT) + Base64ConvertUtil.decode(encryptJWTKey); String secret = getClaim(token, SignConstants.ACCOUNT) + Base64ConvertUtil.decode(ENCRYPT_JWT_KEY);
Algorithm algorithm = Algorithm.HMAC256(secret); Algorithm algorithm = Algorithm.HMAC256(secret);
JWTVerifier verifier = JWT.require(algorithm).build(); JWTVerifier verifier = JWT.require(algorithm).build();
verifier.verify(token); verifier.verify(token);
@ -85,7 +85,7 @@ public final class JwtUtil {
public static String sign(String account, String userId) { public static String sign(String account, String userId) {
try { try {
// 帐号加JWT私钥加密 // 帐号加JWT私钥加密
String secret = account + Base64ConvertUtil.decode(encryptJWTKey); String secret = account + Base64ConvertUtil.decode(ENCRYPT_JWT_KEY);
// 此处过期时间是以毫秒为单位所以乘以1000 // 此处过期时间是以毫秒为单位所以乘以1000
Date date = new Date(System.currentTimeMillis() + EXPIRE); Date date = new Date(System.currentTimeMillis() + EXPIRE);
Algorithm algorithm = Algorithm.HMAC256(secret); Algorithm algorithm = Algorithm.HMAC256(secret);
@ -114,5 +114,6 @@ public final class JwtUtil {
} }
// ================== // ==================
private JwtUtil(){} private JwtUtil(){}
} }

@ -61,7 +61,9 @@ public final class LogUtil {
RequestAttributes ra = RequestContextHolder.getRequestAttributes(); RequestAttributes ra = RequestContextHolder.getRequestAttributes();
ServletRequestAttributes sra = (ServletRequestAttributes) ra; ServletRequestAttributes sra = (ServletRequestAttributes) ra;
if(sra == null) return; if(sra == null){
return;
}
HttpServletRequest request = sra.getRequest(); HttpServletRequest request = sra.getRequest();
// EnableLog 如果不被 EnableLog修饰 则直接退出 // EnableLog 如果不被 EnableLog修饰 则直接退出

@ -35,7 +35,7 @@ public final class TokenGenerator {
return generateValue(UUID.randomUUID().toString()); return generateValue(UUID.randomUUID().toString());
} }
private static final char[] hexCode = "0123456789abcdef".toCharArray(); private static final char[] HEX_CODE = "0123456789abcdef".toCharArray();
/** /**
@ -64,13 +64,14 @@ public final class TokenGenerator {
} }
StringBuilder r = new StringBuilder(data.length*2); StringBuilder r = new StringBuilder(data.length*2);
for ( byte b : data) { for ( byte b : data) {
r.append(hexCode[(b >> 4) & 0xF]); r.append(HEX_CODE[(b >> 4) & 0xF]);
r.append(hexCode[(b & 0xF)]); r.append(HEX_CODE[(b & 0xF)]);
} }
return r.toString(); return r.toString();
} }
// ========================= // =========================
private TokenGenerator(){} private TokenGenerator(){}
} }

@ -153,7 +153,9 @@ public class UserTokenUtil {
* @return * @return
*/ */
public static String getUserIdByToken(String token) { public static String getUserIdByToken(String token) {
if(StringUtils.isEmpty(token)) return null; if(StringUtils.isEmpty(token)){
return null;
}
String userId = ""; String userId = "";
try { try {
userId = JwtUtil.getClaim(token, SignConstants.USER_ID); userId = JwtUtil.getClaim(token, SignConstants.USER_ID);
@ -167,7 +169,9 @@ public class UserTokenUtil {
* @return * @return
*/ */
public static String getUserNameByToken(String token) { public static String getUserNameByToken(String token) {
if(StringUtils.isEmpty(token)) return null; if(StringUtils.isEmpty(token)){
return null;
}
String username = ""; String username = "";
try { try {
username = JwtUtil.getClaim(token, SignConstants.ACCOUNT); username = JwtUtil.getClaim(token, SignConstants.ACCOUNT);
@ -182,7 +186,9 @@ public class UserTokenUtil {
* @param token * @param token
*/ */
public static void logout(String token) { public static void logout(String token) {
if(StringUtils.isEmpty(token)) return; if(StringUtils.isEmpty(token)){
return;
}
try { try {
// 生成MD5 16进制码 用于缩减存储 // 生成MD5 16进制码 用于缩减存储
String signTokenHex = new Md5Hash(token).toHex(); String signTokenHex = new Md5Hash(token).toHex();
@ -207,7 +213,9 @@ public class UserTokenUtil {
* @param token * @param token
*/ */
public static boolean verify(String token) { public static boolean verify(String token) {
if(StringUtils.isEmpty(token)) return false; if(StringUtils.isEmpty(token)){
return false;
}
try { try {
// 1. 校验是否是有效的 token // 1. 校验是否是有效的 token

@ -27,6 +27,34 @@ import java.util.regex.Pattern;
* */ * */
public final class XSSFilterKit { public final class XSSFilterKit {
private static final Pattern SCRIPT_ALL_PATTERN;
private static final Pattern SCRIPT_INNER_PATTERN;
private static final Pattern SCRIPT_PATTERN;
private static final Pattern EVAL_PATTERN;
private static final Pattern EXPRESSION_PATTERN;
private static final Pattern JAVASCRIPT_PATTERN;
private static final Pattern VBSCRIPT_PATTERN;
private static final Pattern ONLOAD_PATTERN;
static {
SCRIPT_ALL_PATTERN = Pattern.compile("<script>(.*?)</script>", Pattern.CASE_INSENSITIVE);
SCRIPT_INNER_PATTERN = Pattern.compile("<script(.*?)>", Pattern.CASE_INSENSITIVE
| Pattern.MULTILINE | Pattern.DOTALL);
SCRIPT_PATTERN = Pattern.compile("</script>", Pattern.CASE_INSENSITIVE);
EVAL_PATTERN = Pattern.compile("eval\\((.*?)\\)", Pattern.CASE_INSENSITIVE
| Pattern.MULTILINE | Pattern.DOTALL);
EXPRESSION_PATTERN = Pattern.compile("expression\\((.*?)\\)", Pattern.CASE_INSENSITIVE
| Pattern.MULTILINE | Pattern.DOTALL);
JAVASCRIPT_PATTERN = Pattern.compile("javascript:", Pattern.CASE_INSENSITIVE);
VBSCRIPT_PATTERN = Pattern.compile("vbscript:", Pattern.CASE_INSENSITIVE);
ONLOAD_PATTERN = Pattern.compile("onload(.*?)=", Pattern.CASE_INSENSITIVE
| Pattern.MULTILINE | Pattern.DOTALL);
}
/** /**
* @Description XSS * @Description XSS
* @param value * @param value
@ -43,8 +71,7 @@ public final class XSSFilterKit {
rlt = value.replaceAll("", ""); rlt = value.replaceAll("", "");
// Avoid anything between script tags // Avoid anything between script tags
Pattern scriptPattern = Pattern.compile("<script>(.*?)</script>", Pattern.CASE_INSENSITIVE); rlt = SCRIPT_ALL_PATTERN.matcher(rlt).replaceAll("");
rlt = scriptPattern.matcher(rlt).replaceAll("");
// Avoid anything in a src='...' type of expression // Avoid anything in a src='...' type of expression
/*scriptPattern = Pattern.compile("src[\r\n]*=[\r\n]*\\\'(.*?)\\\'", Pattern.CASE_INSENSITIVE /*scriptPattern = Pattern.compile("src[\r\n]*=[\r\n]*\\\'(.*?)\\\'", Pattern.CASE_INSENSITIVE
@ -56,36 +83,25 @@ public final class XSSFilterKit {
rlt = scriptPattern.matcher(rlt).replaceAll("");*/ rlt = scriptPattern.matcher(rlt).replaceAll("");*/
// Remove any lonesome </script> tag // Remove any lonesome </script> tag
scriptPattern = Pattern.compile("</script>", Pattern.CASE_INSENSITIVE); rlt = SCRIPT_PATTERN.matcher(rlt).replaceAll("");
rlt = scriptPattern.matcher(rlt).replaceAll("");
// Remove any lonesome <script ...> tag // Remove any lonesome <script ...> tag
scriptPattern = Pattern.compile("<script(.*?)>", Pattern.CASE_INSENSITIVE rlt = SCRIPT_INNER_PATTERN.matcher(rlt).replaceAll("");
| Pattern.MULTILINE | Pattern.DOTALL);
rlt = scriptPattern.matcher(rlt).replaceAll("");
// Avoid eval(...) expressions // Avoid eval(...) expressions
scriptPattern = Pattern.compile("eval\\((.*?)\\)", Pattern.CASE_INSENSITIVE rlt = EVAL_PATTERN.matcher(rlt).replaceAll("");
| Pattern.MULTILINE | Pattern.DOTALL);
rlt = scriptPattern.matcher(rlt).replaceAll("");
// Avoid expression(...) expressions // Avoid expression(...) expressions
scriptPattern = Pattern.compile("expression\\((.*?)\\)", Pattern.CASE_INSENSITIVE rlt = EXPRESSION_PATTERN.matcher(rlt).replaceAll("");
| Pattern.MULTILINE | Pattern.DOTALL);
rlt = scriptPattern.matcher(rlt).replaceAll("");
// Avoid javascript:... expressions // Avoid javascript:... expressions
scriptPattern = Pattern.compile("javascript:", Pattern.CASE_INSENSITIVE); rlt = JAVASCRIPT_PATTERN.matcher(rlt).replaceAll("");
rlt = scriptPattern.matcher(rlt).replaceAll("");
// Avoid vbscript:... expressions // Avoid vbscript:... expressions
scriptPattern = Pattern.compile("vbscript:", Pattern.CASE_INSENSITIVE); rlt = VBSCRIPT_PATTERN.matcher(rlt).replaceAll("");
rlt = scriptPattern.matcher(rlt).replaceAll("");
// Avoid onload= expressions // Avoid onload= expressions
scriptPattern = Pattern.compile("onload(.*?)=", Pattern.CASE_INSENSITIVE rlt = ONLOAD_PATTERN.matcher(rlt).replaceAll("");
| Pattern.MULTILINE | Pattern.DOTALL);
rlt = scriptPattern.matcher(rlt).replaceAll("");
} }
return rlt; return rlt;

@ -52,6 +52,7 @@ import java.util.Map;
*/ */
public enum CodeBuilder { public enum CodeBuilder {
/** 实例对象 */
INSTANCE; INSTANCE;
/** 排除字段 */ /** 排除字段 */
@ -74,7 +75,9 @@ public enum CodeBuilder {
* *
*/ */
public void build(CreaterBuilderModel builderModel, HttpServletResponse response){ public void build(CreaterBuilderModel builderModel, HttpServletResponse response){
if(builderModel == null) return; if(builderModel == null){
return;
}
String dataStr = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss"); String dataStr = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");

@ -41,6 +41,7 @@ import java.util.Map;
*/ */
public enum JavaCodeBuilder { public enum JavaCodeBuilder {
/** 实例对象 */
INSTANCE; INSTANCE;
/** /**

@ -41,6 +41,7 @@ import java.util.*;
*/ */
public enum VueCodeBuilder { public enum VueCodeBuilder {
/** 实例对象 */
INSTANCE; INSTANCE;
/** 虚拟根路径 */ /** 虚拟根路径 */

@ -39,6 +39,7 @@ import java.util.Map;
*/ */
public enum ReadMeBuilder { public enum ReadMeBuilder {
/** 实例对象 */
INSTANCE; INSTANCE;
/** /**

@ -77,7 +77,9 @@ public class MySQLSyncBuilder implements SyncStrategy {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void execute(CreaterTableAndColumnModel model) { public void execute(CreaterTableAndColumnModel model) {
if(model == null) return; if(model == null){
return;
}
CreaterTableModel currTable = iTableService.get(model.getId()); CreaterTableModel currTable = iTableService.get(model.getId());
if(currTable == null){ if(currTable == null){

@ -31,39 +31,40 @@ import java.util.Map;
*/ */
public enum MySQLSyncColumnType { public enum MySQLSyncColumnType {
/** 实例对象 */
INSTANCE; INSTANCE;
private static final Map<String, FieldTypeAttribute> fieldTypeMap = new HashMap<>(); private static final Map<String, FieldTypeAttribute> FIELD_TYPE_MAP = new HashMap<>();
static { static {
fieldTypeMap.put("tinyint", new FieldTypeAttribute(true, false)); FIELD_TYPE_MAP.put("tinyint", new FieldTypeAttribute(true, false));
fieldTypeMap.put("smallint", new FieldTypeAttribute(true, false)); FIELD_TYPE_MAP.put("smallint", new FieldTypeAttribute(true, false));
fieldTypeMap.put("mediumint", new FieldTypeAttribute(true, false)); FIELD_TYPE_MAP.put("mediumint", new FieldTypeAttribute(true, false));
fieldTypeMap.put("int", new FieldTypeAttribute(true, false)); FIELD_TYPE_MAP.put("int", new FieldTypeAttribute(true, false));
fieldTypeMap.put("integer", new FieldTypeAttribute(true, false)); FIELD_TYPE_MAP.put("integer", new FieldTypeAttribute(true, false));
fieldTypeMap.put("bigint", new FieldTypeAttribute(true, false)); FIELD_TYPE_MAP.put("bigint", new FieldTypeAttribute(true, false));
fieldTypeMap.put("real", new FieldTypeAttribute(true, true)); FIELD_TYPE_MAP.put("real", new FieldTypeAttribute(true, true));
fieldTypeMap.put("float", new FieldTypeAttribute(true, true)); FIELD_TYPE_MAP.put("float", new FieldTypeAttribute(true, true));
fieldTypeMap.put("double", new FieldTypeAttribute(true, true)); FIELD_TYPE_MAP.put("double", new FieldTypeAttribute(true, true));
fieldTypeMap.put("decimal", new FieldTypeAttribute(true, true)); FIELD_TYPE_MAP.put("decimal", new FieldTypeAttribute(true, true));
fieldTypeMap.put("numeric", new FieldTypeAttribute(true, true)); FIELD_TYPE_MAP.put("numeric", new FieldTypeAttribute(true, true));
fieldTypeMap.put("char", new FieldTypeAttribute(true, false)); FIELD_TYPE_MAP.put("char", new FieldTypeAttribute(true, false));
fieldTypeMap.put("varchar", new FieldTypeAttribute(true, false)); FIELD_TYPE_MAP.put("varchar", new FieldTypeAttribute(true, false));
fieldTypeMap.put("date", new FieldTypeAttribute(false, false)); FIELD_TYPE_MAP.put("date", new FieldTypeAttribute(false, false));
fieldTypeMap.put("time", new FieldTypeAttribute(false, false)); FIELD_TYPE_MAP.put("time", new FieldTypeAttribute(false, false));
fieldTypeMap.put("timestamp", new FieldTypeAttribute(false, false)); FIELD_TYPE_MAP.put("timestamp", new FieldTypeAttribute(false, false));
fieldTypeMap.put("datetime", new FieldTypeAttribute(false, false)); FIELD_TYPE_MAP.put("datetime", new FieldTypeAttribute(false, false));
fieldTypeMap.put("blob", new FieldTypeAttribute(false, false)); FIELD_TYPE_MAP.put("blob", new FieldTypeAttribute(false, false));
fieldTypeMap.put("mediumblob", new FieldTypeAttribute(false, false)); FIELD_TYPE_MAP.put("mediumblob", new FieldTypeAttribute(false, false));
fieldTypeMap.put("longblob", new FieldTypeAttribute(false, false)); FIELD_TYPE_MAP.put("longblob", new FieldTypeAttribute(false, false));
fieldTypeMap.put("tinytext", new FieldTypeAttribute(false, false)); FIELD_TYPE_MAP.put("tinytext", new FieldTypeAttribute(false, false));
fieldTypeMap.put("text", new FieldTypeAttribute(false, false)); FIELD_TYPE_MAP.put("text", new FieldTypeAttribute(false, false));
fieldTypeMap.put("mediumtext", new FieldTypeAttribute(false, false)); FIELD_TYPE_MAP.put("mediumtext", new FieldTypeAttribute(false, false));
fieldTypeMap.put("longtext", new FieldTypeAttribute(false, false)); FIELD_TYPE_MAP.put("longtext", new FieldTypeAttribute(false, false));
} }
public FieldTypeAttribute getAttr(String fieldType){ public FieldTypeAttribute getAttr(String fieldType){
return fieldTypeMap.get(fieldType); return FIELD_TYPE_MAP.get(fieldType);
} }
} }

@ -70,7 +70,9 @@ public class SQLSyncUtil {
* @param model * @param model
*/ */
public static void execute(CreaterTableAndColumnModel model){ public static void execute(CreaterTableAndColumnModel model){
if(model == null) return; if(model == null){
return;
}
SyncStrategy syncStrategy = HANDLER_MAP.get(model.getJdbcType()); SyncStrategy syncStrategy = HANDLER_MAP.get(model.getJdbcType());
if(syncStrategy != null){ if(syncStrategy != null){

@ -54,7 +54,9 @@ public class TableColumnServiceImpl extends CrudServiceImpl<TableColumnMapper, C
// 验证对象 // 验证对象
ValidationUtil.verify(model); ValidationUtil.verify(model);
if(model == null) return null; if(model == null){
return null;
}
CreaterTableColumn entity = super.transformM2T(model); CreaterTableColumn entity = super.transformM2T(model);
// 唯一验证 // 唯一验证
@ -76,7 +78,9 @@ public class TableColumnServiceImpl extends CrudServiceImpl<TableColumnMapper, C
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean insertBatch(List<CreaterTableColumnModel> models) { public boolean insertBatch(List<CreaterTableColumnModel> models) {
if(models == null || models.size() == 0) return false; if(models == null || models.size() == 0){
return false;
}
for (CreaterTableColumnModel model : models) { for (CreaterTableColumnModel model : models) {
@ -113,7 +117,9 @@ public class TableColumnServiceImpl extends CrudServiceImpl<TableColumnMapper, C
// 验证对象 // 验证对象
ValidationUtil.verify(model); ValidationUtil.verify(model);
if(model == null) return null; if(model == null){
return null;
}
CreaterTableColumn entity = super.transformM2T(model); CreaterTableColumn entity = super.transformM2T(model);
// 唯一验证 // 唯一验证

@ -62,7 +62,9 @@ public class TableServiceImpl extends CrudServiceImpl<TableMapper, CreaterTable,
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public CreaterTableModel insert(CreaterTableModel model) { public CreaterTableModel insert(CreaterTableModel model) {
if(model == null) return null; if(model == null){
return null;
}
CreaterTable entity = super.transformM2T(model); CreaterTable entity = super.transformM2T(model);
// 唯一验证 // 唯一验证
@ -87,7 +89,9 @@ public class TableServiceImpl extends CrudServiceImpl<TableMapper, CreaterTable,
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public CreaterTableModel update(CreaterTableModel model) { public CreaterTableModel update(CreaterTableModel model) {
if(model == null) return null; if(model == null){
return null;
}
CreaterTable entity = super.transformM2T(model); CreaterTable entity = super.transformM2T(model);
// 唯一验证 // 唯一验证

@ -57,7 +57,9 @@ public class SysAreaServiceImpl extends CrudServiceImpl<SysAreaMapper, SysArea,
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public SysAreaModel insert(SysAreaModel model) { public SysAreaModel insert(SysAreaModel model) {
if(model == null) return null; if(model == null){
return null;
}
SysArea entity = super.transformM2T(model); SysArea entity = super.transformM2T(model);
// 唯一验证 // 唯一验证
@ -78,7 +80,9 @@ public class SysAreaServiceImpl extends CrudServiceImpl<SysAreaMapper, SysArea,
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public SysAreaModel update(SysAreaModel model) { public SysAreaModel update(SysAreaModel model) {
if(model == null) return null; if(model == null){
return null;
}
SysArea entity = super.transformM2T(model); SysArea entity = super.transformM2T(model);
// 唯一验证 // 唯一验证

@ -317,7 +317,9 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public boolean delByParent(String parentId) { public boolean delByParent(String parentId) {
if(StringUtils.isEmpty(parentId)) return false; if(StringUtils.isEmpty(parentId)){
return false;
}
String key = HumpUtil.humpToUnderline("typeId"); String key = HumpUtil.humpToUnderline("typeId");
QueryBuilder<SysDictDetail> queryBuilder = new GenQueryBuilder<>(); QueryBuilder<SysDictDetail> queryBuilder = new GenQueryBuilder<>();
@ -355,7 +357,9 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
*/ */
@Override @Override
public List<DictDetailModel> findListByTypeCode(String typeCode) { public List<DictDetailModel> findListByTypeCode(String typeCode) {
if(StringUtils.isEmpty(typeCode)) return null; if(StringUtils.isEmpty(typeCode)){
return null;
}
String key = HumpUtil.humpToUnderline("typeCode"); String key = HumpUtil.humpToUnderline("typeCode");
String deleted = HumpUtil.humpToUnderline("deleted"); String deleted = HumpUtil.humpToUnderline("deleted");

@ -50,7 +50,9 @@ public class DictServiceImpl extends CrudServiceImpl<DictMapper, SysDict, DictMo
@Override @Override
public DictModel insert(DictModel model) { public DictModel insert(DictModel model) {
if(model == null) return null; if(model == null){
return null;
}
SysDict entity = super.transformM2T(model); SysDict entity = super.transformM2T(model);
// 唯一验证 // 唯一验证
@ -66,7 +68,9 @@ public class DictServiceImpl extends CrudServiceImpl<DictMapper, SysDict, DictMo
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public DictModel update(DictModel model) { public DictModel update(DictModel model) {
if(model == null) return null; if(model == null){
return null;
}
SysDict entity = super.transformM2T(model); SysDict entity = super.transformM2T(model);
// 唯一验证 // 唯一验证
@ -123,7 +127,9 @@ public class DictServiceImpl extends CrudServiceImpl<DictMapper, SysDict, DictMo
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public boolean deleteAll(String[] ids) { public boolean deleteAll(String[] ids) {
if(ids == null) return false; if(ids == null){
return false;
}
// 删除字典明细表 // 删除字典明细表
for (String id : ids) { for (String id : ids) {
@ -136,7 +142,9 @@ public class DictServiceImpl extends CrudServiceImpl<DictMapper, SysDict, DictMo
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public boolean deleteAll(Collection<DictModel> models) { public boolean deleteAll(Collection<DictModel> models) {
if(models == null || models.isEmpty()) return false; if(models == null || models.isEmpty()){
return false;
}
// 删除字典明细表 // 删除字典明细表
for (DictModel model : models) { for (DictModel model : models) {

@ -38,6 +38,9 @@ import java.util.Date;
@Service @Service
public class LogsServiceImpl extends CrudServiceImpl<LogsMapper, SysLogs, LogsModel> implements ILogsService { public class LogsServiceImpl extends CrudServiceImpl<LogsMapper, SysLogs, LogsModel> implements ILogsService {
/** Log 存储量阈值 */
private static final int LOG_BIG_COUNT = 10_0000;
@Autowired(required = false) @Autowired(required = false)
private LogsMapper mapper; private LogsMapper mapper;
@ -46,7 +49,7 @@ public class LogsServiceImpl extends CrudServiceImpl<LogsMapper, SysLogs, LogsMo
public LogsModel insert(LogsModel model) { public LogsModel insert(LogsModel model) {
int count = super.count(); int count = super.count();
// 如果日志存储量为10万 则自动清空上月前数据 // 如果日志存储量为10万 则自动清空上月前数据
if(count > 10_0000){ if(count > LOG_BIG_COUNT){
this.emptyByOneMonth(); this.emptyByOneMonth();
} }
return super.insert(model); return super.insert(model);

@ -70,7 +70,9 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public MenuModel insert(MenuModel model) { public MenuModel insert(MenuModel model) {
if(model == null) return null; if(model == null){
return null;
}
SysMenu entity = super.transformM2T(model); SysMenu entity = super.transformM2T(model);
// 唯一验证 // 唯一验证
@ -91,7 +93,9 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public MenuModel update(MenuModel model) { public MenuModel update(MenuModel model) {
if(model == null) return null; if(model == null){
return null;
}
SysMenu entity = super.transformM2T(model); SysMenu entity = super.transformM2T(model);
// 唯一验证 // 唯一验证

@ -60,6 +60,10 @@ import java.util.Map;
@ApiRestController("/sys/menu") @ApiRestController("/sys/menu")
public class MenuRestController extends BaseRestController<SysMenu, MenuModel, IMenuService> public class MenuRestController extends BaseRestController<SysMenu, MenuModel, IMenuService>
implements MenuApi { implements MenuApi {
/** 外部链接值 */
private static final String EXTERNAL_LINKS_VAL = "3";
/** /**
* - * -
* @return ResultVo * @return ResultVo
@ -116,7 +120,7 @@ public class MenuRestController extends BaseRestController<SysMenu, MenuModel, I
tree.setName(treeNode.getMenuName()); tree.setName(treeNode.getMenuName());
// 扩展属性 ... // 扩展属性 ...
// 不是外链 则处理组件 // 不是外链 则处理组件
if(!"3".equals(treeNode.getType())){ if(!EXTERNAL_LINKS_VAL.equals(treeNode.getType())){
tree.putExtra("component", treeNode.getComponent()); tree.putExtra("component", treeNode.getComponent());
} }
tree.putExtra("type", treeNode.getType()); tree.putExtra("type", treeNode.getType());
@ -127,7 +131,7 @@ public class MenuRestController extends BaseRestController<SysMenu, MenuModel, I
metaMap.put("title", treeNode.getMenuName()); metaMap.put("title", treeNode.getMenuName());
metaMap.put("icon", treeNode.getIcon()); metaMap.put("icon", treeNode.getIcon());
// 外链处理 // 外链处理
if("3".equals(treeNode.getType())){ if(EXTERNAL_LINKS_VAL.equals(treeNode.getType())){
metaMap.put("target", "_blank"); metaMap.put("target", "_blank");
metaMap.put("badge", "New"); metaMap.put("badge", "New");
} }
@ -179,7 +183,7 @@ public class MenuRestController extends BaseRestController<SysMenu, MenuModel, I
tree.setName(treeNode.getMenuCode()); tree.setName(treeNode.getMenuCode());
// 扩展属性 ... // 扩展属性 ...
// 不是外链 则处理组件 // 不是外链 则处理组件
if(!"3".equals(treeNode.getType())){ if(!EXTERNAL_LINKS_VAL.equals(treeNode.getType())){
tree.putExtra("component", treeNode.getComponent()); tree.putExtra("component", treeNode.getComponent());
}else{ }else{
// 如果是外链 则判断是否存在 BASE_PATH // 如果是外链 则判断是否存在 BASE_PATH
@ -198,7 +202,7 @@ public class MenuRestController extends BaseRestController<SysMenu, MenuModel, I
metaMap.put("title", treeNode.getMenuName()); metaMap.put("title", treeNode.getMenuName());
metaMap.put("icon", treeNode.getIcon()); metaMap.put("icon", treeNode.getIcon());
// 外链处理 // 外链处理
if("3".equals(treeNode.getType())){ if(EXTERNAL_LINKS_VAL.equals(treeNode.getType())){
metaMap.put("target", "_blank"); metaMap.put("target", "_blank");
} }
tree.putExtra("meta", metaMap); tree.putExtra("meta", metaMap);

@ -60,7 +60,9 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public SysOrgModel insert(SysOrgModel model) { public SysOrgModel insert(SysOrgModel model) {
if(model == null) return null; if(model == null){
return null;
}
SysOrg entity = super.transformM2T(model); SysOrg entity = super.transformM2T(model);
// 唯一验证 // 唯一验证
@ -81,7 +83,9 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public SysOrgModel update(SysOrgModel model) { public SysOrgModel update(SysOrgModel model) {
if(model == null) return null; if(model == null){
return null;
}
SysOrg entity = super.transformM2T(model); SysOrg entity = super.transformM2T(model);
// 唯一验证 // 唯一验证

@ -60,6 +60,8 @@ import java.util.Set;
public class SysOrgRestController extends BaseRestController<SysOrg, SysOrgModel, ISysOrgService> public class SysOrgRestController extends BaseRestController<SysOrg, SysOrgModel, ISysOrgService>
implements SysOrgRestApi { implements SysOrgRestApi {
/** 父节点ID */
private static final String PARENT_ID = "0";
/** 显示全部 */ /** 显示全部 */
public static final String ORG_ALL = "all"; public static final String ORG_ALL = "all";
/** 未分组 */ /** 未分组 */
@ -81,7 +83,7 @@ public class SysOrgRestController extends BaseRestController<SysOrg, SysOrgModel
List<SysOrg> dataList = IService.findList(wrapper); List<SysOrg> dataList = IService.findList(wrapper);
List<SysOrgModel> orgModelList = WrapperUtil.transformInstance(dataList, SysOrgModel.class); List<SysOrgModel> orgModelList = WrapperUtil.transformInstance(dataList, SysOrgModel.class);
// 0 为初始值 // 0 为初始值
if("0".equals(parentId)){ if(PARENT_ID.equals(parentId)){
// 显示全部 // 显示全部
SysOrgModel orgAll = new SysOrgModel(); SysOrgModel orgAll = new SysOrgModel();
orgAll.setId(ORG_ALL); orgAll.setId(ORG_ALL);

@ -47,7 +47,9 @@ public class RoleServiceImpl extends CrudServiceImpl<RoleMapper, SysRole, RoleMo
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public RoleModel insert(RoleModel model) { public RoleModel insert(RoleModel model) {
if(model == null) return null; if(model == null){
return null;
}
SysRole entity = super.transformM2T(model); SysRole entity = super.transformM2T(model);
// 唯一验证 // 唯一验证
@ -63,7 +65,9 @@ public class RoleServiceImpl extends CrudServiceImpl<RoleMapper, SysRole, RoleMo
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public RoleModel update(RoleModel model) { public RoleModel update(RoleModel model) {
if(model == null) return null; if(model == null){
return null;
}
SysRole entity = super.transformM2T(model); SysRole entity = super.transformM2T(model);
// 唯一验证 // 唯一验证

@ -109,7 +109,9 @@ public class RoleMenuRefRestController implements RoleMenuRefApi {
// 演示模式 不允许操作 // 演示模式 不允许操作
this.demoError(); this.demoError();
if(model == null) return ResultVo.error("设置权限失败"); if(model == null){
return ResultVo.error("设置权限失败");
}
RoleModel roleModel = iRoleService.get(model.getRoleId()); RoleModel roleModel = iRoleService.get(model.getRoleId());
// 内置数据 只有超级管理员可以修改 // 内置数据 只有超级管理员可以修改

@ -43,7 +43,9 @@ public class TenantServiceImpl extends CrudServiceImpl<TenantMapper, SysTenant,
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public TenantModel insert(TenantModel model) { public TenantModel insert(TenantModel model) {
if(model == null) return null; if(model == null){
return null;
}
SysTenant entity = super.transformM2T(model); SysTenant entity = super.transformM2T(model);
// 唯一验证 // 唯一验证
@ -59,7 +61,9 @@ public class TenantServiceImpl extends CrudServiceImpl<TenantMapper, SysTenant,
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public TenantModel update(TenantModel model) { public TenantModel update(TenantModel model) {
if(model == null) return null; if(model == null){
return null;
}
SysTenant entity = super.transformM2T(model); SysTenant entity = super.transformM2T(model);
// 唯一验证 // 唯一验证

@ -65,7 +65,9 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public UserModel insert(UserModel model) { public UserModel insert(UserModel model) {
if(model == null) return null; if(model == null){
return null;
}
SysUser entity = super.transformM2T(model); SysUser entity = super.transformM2T(model);
// 唯一验证 // 唯一验证
@ -104,7 +106,9 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public UserModel update(UserModel model) { public UserModel update(UserModel model) {
if(model == null) return null; if(model == null){
return null;
}
SysUser entity = super.transformM2T(model); SysUser entity = super.transformM2T(model);
// 唯一验证 - 用户名 // 唯一验证 - 用户名
@ -272,6 +276,7 @@ public class UserServiceImpl extends CrudServiceImpl<UserMapper, SysUser, UserMo
return mapper.findList(qWrapper); return mapper.findList(qWrapper);
} }
@Override
public Page<SysUserAndOrg,UserAndOrgModel> findPageByCus(Page<SysUserAndOrg,UserAndOrgModel> page) { public Page<SysUserAndOrg,UserAndOrgModel> findPageByCus(Page<SysUserAndOrg,UserAndOrgModel> page) {
page.pageHelperBegin(); page.pageHelperBegin();
try{ try{

Loading…
Cancel
Save