ZhouChenglin 7 vuotta sitten
vanhempi
commit
f1de0ae3d6

+ 2 - 6
src/main/java/net/chenlin/dp/common/aspect/SysLogAspect.java

@@ -3,6 +3,7 @@ package net.chenlin.dp.common.aspect;
 import java.lang.reflect.Method;
 import javax.servlet.http.HttpServletRequest;
 
+import net.chenlin.dp.common.utils.*;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Aspect;
@@ -12,11 +13,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import net.chenlin.dp.common.annotation.SysLog;
-import net.chenlin.dp.common.utils.CommonUtils;
-import net.chenlin.dp.common.utils.HttpContextUtils;
-import net.chenlin.dp.common.utils.IPUtils;
-import net.chenlin.dp.common.utils.JSONUtils;
-import net.chenlin.dp.common.utils.ShiroUtils;
 import net.chenlin.dp.modules.sys.entity.SysLogEntity;
 import net.chenlin.dp.modules.sys.entity.SysUserEntity;
 import net.chenlin.dp.modules.sys.manager.SysLogManager;
@@ -78,7 +74,7 @@ public class SysLogAspect {
 		//获取request
 		HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
 		//设置IP地址
-		sysLog.setIp(IPUtils.getIpAddr(request));
+		sysLog.setIp(IpUtils.getIpAddr(request));
 		//用户名
 		SysUserEntity currUser = ShiroUtils.getUserEntity();
 		if(CommonUtils.isNullOrEmpty(currUser)) {

+ 3 - 3
src/main/java/net/chenlin/dp/common/constant/SystemConstant.java

@@ -78,7 +78,7 @@ public class SystemConstant {
 
         private int value;
 
-        private ScheduleStatus(int value) {
+        ScheduleStatus(int value) {
             this.value = value;
         }
         
@@ -109,7 +109,7 @@ public class SystemConstant {
     	
     	private int value;
     	
-    	private MacroType(int value) {
+    	MacroType(int value) {
             this.value = value;
         }
         
@@ -151,7 +151,7 @@ public class SystemConstant {
     	
     	private int value;
     	
-    	private StatusType(int value) {
+    	StatusType(int value) {
             this.value = value;
         }
         

+ 11 - 6
src/main/java/net/chenlin/dp/common/entity/Query.java

@@ -26,8 +26,9 @@ public class Query extends HashMap<String, Object> {
 	
 	public Double getAsDouble(String name) {
         Object value = this.get(name);
-        if (value != null)
+        if (value != null) {
             return Double.valueOf(value.toString());
+        }
         return null;
     }
 
@@ -37,29 +38,33 @@ public class Query extends HashMap<String, Object> {
 
     public Long getAsLong(String name) {
         Object value = this.get(name);
-        if (value != null)
+        if (value != null) {
             return Long.valueOf(value.toString());
+        }
         return null;
     }
 
     public Integer getAsInt(String name) {
         Object value = this.get(name);
-        if (value != null)
+        if (value != null) {
             return Integer.valueOf(value.toString());
+        }
         return null;
     }
 
     public Boolean getAsBoolean(String name) {
         Object value = this.get(name);
-        if (value != null)
+        if (value != null) {
             return Boolean.valueOf(value.toString());
+        }
         return null;
     }
 
     public java.util.Date getAsDate(String name) {
     	Object value = this.get(name);
-        if (value != null)
-        	return Date.valueOf(value.toString());
+        if (value != null) {
+            return Date.valueOf(value.toString());
+        }
         return null;
     }
 

+ 1 - 0
src/main/java/net/chenlin/dp/common/entity/R.java

@@ -50,6 +50,7 @@ public class R extends HashMap<String, Object> {
 		return new R();
 	}
 
+	@Override
 	public R put(String key, Object value) {
 		super.put(key, value);
 		return this;

+ 3 - 0
src/main/java/net/chenlin/dp/common/support/orm/plugins/PaginationResultSetHandlerInterceptor.java

@@ -36,6 +36,7 @@ public class PaginationResultSetHandlerInterceptor implements Interceptor {
     private static final ObjectWrapperFactory DEFAULT_OBJECT_WRAPPER_FACTORY = new DefaultObjectWrapperFactory();
     private static final ReflectorFactory  DEFAULT_REFLECTOR_FACTORY = new DefaultReflectorFactory();
     
+    @Override
     public Object intercept(Invocation invocation) throws Throwable {
         DefaultResultSetHandler resultSetHandler = (DefaultResultSetHandler) invocation.getTarget();
         MetaObject metaStatementHandler = MetaObject.forObject(resultSetHandler, DEFAULT_OBJECT_FACTORY, DEFAULT_OBJECT_WRAPPER_FACTORY, DEFAULT_REFLECTOR_FACTORY);
@@ -49,10 +50,12 @@ public class PaginationResultSetHandlerInterceptor implements Interceptor {
         return result;
     }
 
+    @Override
     public Object plugin(Object target) {
         return Plugin.wrap(target, this);
     }
 
+    @Override
     public void setProperties(Properties properties) {
     }
 

+ 3 - 5
src/main/java/net/chenlin/dp/common/support/orm/plugins/PaginationStatementHandlerInterceptor.java

@@ -46,6 +46,7 @@ public class PaginationStatementHandlerInterceptor implements Interceptor {
     private static final ObjectWrapperFactory DEFAULT_OBJECT_WRAPPER_FACTORY = new DefaultObjectWrapperFactory();
     private static final ReflectorFactory  DEFAULT_REFLECTOR_FACTORY = new DefaultReflectorFactory();
 
+    @Override
     public Object intercept(Invocation invocation) throws Throwable {
         StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
         ParameterHandler parameterHandler = statementHandler.getParameterHandler();
@@ -79,10 +80,12 @@ public class PaginationStatementHandlerInterceptor implements Interceptor {
         return invocation.proceed();
     }
 
+    @Override
     public Object plugin(Object target) {
         return Plugin.wrap(target, this);
     }
 
+    @Override
     public void setProperties(Properties properties) {
     }
 
@@ -96,11 +99,6 @@ public class PaginationStatementHandlerInterceptor implements Interceptor {
      * @throws Exception
      */
     private int getTotal(ParameterHandler parameterHandler, Connection connection, String countSql) throws Exception {
-        // MetaObject metaStatementHandler =
-        // MetaObject.forObject(parameterHandler);
-        // Object parameterObject =
-        // metaStatementHandler.getValue("parameterObject");
-        // TODO 缓存具有相同SQL语句和参数的总数
         PreparedStatement prepareStatement = connection.prepareStatement(countSql);
         parameterHandler.setParameters(prepareStatement);
         ResultSet rs = prepareStatement.executeQuery();

+ 24 - 13
src/main/java/net/chenlin/dp/common/utils/IPUtils.java → src/main/java/net/chenlin/dp/common/utils/IpUtils.java

@@ -14,47 +14,58 @@ import javax.servlet.http.HttpServletRequest;
  * @url www.chenlintech.com
  * @date 2017年8月8日 下午12:02:56
  */
-public class IPUtils {
+public class IpUtils {
 
-	private static Logger logger = LoggerFactory.getLogger(IPUtils.class);
+	private static Logger LOG = LoggerFactory.getLogger(IpUtils.class);
 
 	/**
 	 * 获取IP地址
-	 * 
+	 *
 	 * 使用Nginx等反向代理软件, 则不能通过request.getRemoteAddr()获取IP地址
 	 * 如果使用了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP地址,X-Forwarded-For中第一个非unknown的有效IP字符串,则为真实IP地址
 	 */
 	public static String getIpAddr(HttpServletRequest request) {
-		String ip = null;
+		String ip = null, unknown = "unknown", seperator = ",";
+		int maxLength = 15;
 		try {
 			ip = request.getHeader("x-forwarded-for");
-			if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
+			if (StringUtils.isEmpty(ip) || unknown.equalsIgnoreCase(ip)) {
 				ip = request.getHeader("Proxy-Client-IP");
 			}
-			if (StringUtils.isEmpty(ip) || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+			if (StringUtils.isEmpty(ip) || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
 				ip = request.getHeader("WL-Proxy-Client-IP");
 			}
-			if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
+			if (StringUtils.isEmpty(ip) || unknown.equalsIgnoreCase(ip)) {
 				ip = request.getHeader("HTTP_CLIENT_IP");
 			}
-			if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
+			if (StringUtils.isEmpty(ip) || unknown.equalsIgnoreCase(ip)) {
 				ip = request.getHeader("HTTP_X_FORWARDED_FOR");
 			}
-			if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
+			if (StringUtils.isEmpty(ip) || unknown.equalsIgnoreCase(ip)) {
 				ip = request.getRemoteAddr();
 			}
 		} catch (Exception e) {
-			logger.error("IPUtils ERROR ", e);
+			LOG.error("IpUtils ERROR ", e);
 		}
 
 		// 使用代理,则获取第一个IP地址
-		if (StringUtils.isEmpty(ip) && ip.length() > 15) {
-			if (ip.indexOf(",") > 0) {
-				ip = ip.substring(0, ip.indexOf(","));
+		if (StringUtils.isEmpty(ip) && ip.length() > maxLength) {
+			int idx = ip.indexOf(seperator);
+			if (idx > 0) {
+				ip = ip.substring(0, idx);
 			}
 		}
 
 		return ip;
 	}
 
+	/**
+	 * 获取ip地址
+	 * @return
+	 */
+	public static String getIpAddr() {
+		HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
+		return getIpAddr(request);
+	}
+
 }

+ 3 - 2
src/main/java/net/chenlin/dp/common/utils/MD5Utils.java

@@ -21,7 +21,7 @@ public class MD5Utils {
 
 	/**
 	 * 使用md5生成加密后的密码
-	 * @param user
+	 * @param pswd
 	 * @return
 	 */
 	public static String encrypt(String pswd) {
@@ -31,7 +31,8 @@ public class MD5Utils {
 	
 	/**
 	 * 使用md5生成加密后的密码
-	 * @param user
+	 * @param username
+	 * @param pswd
 	 * @return
 	 */
 	public static String encrypt(String username, String pswd) {

+ 4 - 3
src/main/java/net/chenlin/dp/common/utils/WebUtils.java

@@ -21,10 +21,11 @@ public class WebUtils {
 	 * @return
 	 */
 	public static boolean isAjax(HttpServletRequest request){
+		String header = "x-requested-with", httpRequest = "XMLHttpRequest";
 		//如果是ajax请求响应头会有,x-requested-with
-		 if (request.getHeader("x-requested-with") != null    
-				 && request.getHeader("x-requested-with")    
-				 .equalsIgnoreCase("XMLHttpRequest")) { 
+		 if (request.getHeader(header) != null
+				 && request.getHeader(header)
+				 .equalsIgnoreCase(httpRequest)) {
 			 return true;
 		 }
 		 return false;