Browse Source

日志记录获取实际ip地址,优化首页查询接口

zouxuan 1 year ago
parent
commit
c37cbc4d86

+ 3 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/IndexBaseMonthDataServiceImpl.java

@@ -119,8 +119,8 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 			dataTypes = Arrays.stream(queryInfo.getDataTypes().split(",")).collect(Collectors.toSet());
 		}
 
-		String startDate1 = startDate.toString();
-		String endDate1 = endDate.toString();
+		String startDate1 = startDate.toString() + " 00:00:00";
+		String endDate1 = endDate.toString() + " 23:59:59";;
 		List<Integer> arrayList = null;
 		if(!CollectionUtils.isEmpty(organIds)){
 			arrayList = new ArrayList<>(organIds);
@@ -133,7 +133,7 @@ public class IndexBaseMonthDataServiceImpl extends BaseServiceImpl<Long, IndexBa
 
 		Map<Date, Map<IndexDataType, Map<String, Integer>>> vipCategoryCourseListMap = new HashMap<>();
 		if(CollectionUtils.isEmpty(dataTypes)||dataTypes.contains("VIP_GROUP_COURSE")||dataTypes.contains("VIP_GROUP_ONLINE_COURSE")||dataTypes.contains("VIP_GROUP_OFFLINE_COURSE")){
-			Set<String> vipDataTypes = new HashSet<>();
+			Set<String> vipDataTypes = new HashSet<>(3);
 			vipDataTypes.add("VIP_GROUP_COURSE");
 			vipDataTypes.add("VIP_GROUP_ONLINE_COURSE");
 			vipDataTypes.add("VIP_GROUP_OFFLINE_COURSE");

+ 34 - 35
mec-biz/src/main/resources/config/mybatis/IndexBaseMonthDataMapper.xml

@@ -145,10 +145,7 @@
 				</foreach>
 			</if>
 			<if test="startMonth!=null and startMonth!=''">
-				AND month_&gt;=#{startMonth}
-			</if>
-			<if test="endMonth!=null and endMonth!=''">
-				AND month_&lt;=#{endMonth}
+				AND month_ BETWEEN #{startMonth} AND #{endMonth}
 			</if>
 		</where>
 		GROUP BY month_,data_type_
@@ -204,10 +201,7 @@
 					</foreach>
 				</if>
 				<if test="startMonth!=null and startMonth!=''">
-					AND month_&gt;=#{startMonth}
-				</if>
-				<if test="endMonth!=null and endMonth!=''">
-					AND month_&lt;=#{endMonth}
+					AND month_ BETWEEN #{startMonth} AND #{endMonth}
 				</if>
 				AND extend_info_ IS NOT NULL
 			</where>
@@ -1405,7 +1399,7 @@
 			   SUM(CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) activate_num_,
 			   SUM(CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) percent_,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_
 		FROM student_payment_order spo
-		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
+		WHERE spo.status_ = 'SUCCESS' AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
 		<if test="organIds!=null and organIds.size()>0">
 			AND spo.organ_id_ IN
 			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
@@ -1420,7 +1414,7 @@
 		o.id_ organ_id_,o.name_ organ_name_
 		FROM organization o
 		LEFT JOIN student_payment_order spo ON o.id_ = spo.organ_id_ AND o.tenant_id_ = spo.tenant_id_
-		AND spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
+		AND spo.status_ = 'SUCCESS' AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate}
 		WHERE o.tenant_id_ = #{tenantId}
 		<if test="organIds!=null and organIds.size() > 0">
 			AND o.id_ IN
@@ -1436,7 +1430,7 @@
 			   SUM(spo.actual_amount_) activate_num_,
 			   SUM(spo.actual_amount_) percent_,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_
 		FROM student_payment_order spo
-		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
+		WHERE spo.status_ = 'SUCCESS' AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
 		<if test="organIds!=null and organIds.size()>0">
 			AND spo.organ_id_ IN
 			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
@@ -1450,7 +1444,7 @@
 		SELECT SUM(spo.actual_amount_) percent_,o.id_ organ_id_,o.name_ organ_name_
 		FROM organization o
 		LEFT JOIN student_payment_order spo ON o.id_ = spo.organ_id_ AND o.tenant_id_ = spo.tenant_id_
-		AND spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
+		AND spo.status_ = 'SUCCESS' AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate}
 		WHERE o.tenant_id_ = #{tenantId}
 		<if test="organIds!=null and organIds.size()>0">
 			AND o.id_ IN
@@ -1469,7 +1463,7 @@
 			   SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
 		CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) percent_,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_
 		FROM student_payment_order spo
-		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
+		WHERE spo.status_ = 'SUCCESS' AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
 		<if test="organIds!=null and organIds.size()>0">
 			AND spo.organ_id_ IN
 			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
@@ -1485,7 +1479,7 @@
 		    			   o.id_ organ_id_,o.name_ organ_name_
 		FROM organization o
 		LEFT JOIN student_payment_order spo ON o.id_ = spo.organ_id_ AND o.tenant_id_ = spo.tenant_id_
-		AND spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
+		AND spo.status_ = 'SUCCESS' AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate}
 		WHERE o.tenant_id_ = #{tenantId}
 		<if test="organIds!=null and organIds.size()>0">
 			AND o.id_ IN
@@ -1504,7 +1498,7 @@
 			   SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
 		CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) percent_,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_
 		FROM student_payment_order spo
-		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
+		WHERE spo.status_ = 'SUCCESS' AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
 		<if test="orderType != null">
 			AND FIND_IN_SET(spo.type_,#{orderType})
 		</if>
@@ -1529,7 +1523,7 @@
 		    			   o.id_ organ_id_,o.name_ organ_name_
 		FROM organization o
 		LEFT JOIN student_payment_order spo ON o.id_ = spo.organ_id_ AND o.tenant_id_ = spo.tenant_id_
-		AND spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
+		AND spo.status_ = 'SUCCESS' AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate}
 		<if test="orderType != null">
 			AND FIND_IN_SET(spo.type_,#{orderType})
 		</if>
@@ -1560,7 +1554,7 @@
 		SELECT spo.organ_id_,SUM(CASE WHEN spod.price_ IS NULL THEN 0 ELSE spod.price_ END) total_num_,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_
 		FROM student_payment_order spo
 		LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
-		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
+		WHERE spo.status_ = 'SUCCESS' AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
 		AND spo.type_ = 'DEGREE' AND spod.type_ IN ('THEORY_COURSE','VIP')
 		<if test="organIds!=null and organIds.size()>0">
 			AND spo.organ_id_ IN
@@ -1574,7 +1568,7 @@
 		CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) total_num_
 		,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_
 		FROM student_payment_order spo
-		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
+		WHERE spo.status_ = 'SUCCESS' AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate}
 		AND spo.type_ = 'SMALL_CLASS_TO_BUY'
 		<if test="organIds!=null and organIds.size()>0">
 			AND spo.organ_id_ IN
@@ -1591,7 +1585,7 @@
 		LEFT JOIN (SELECT spo.organ_id_,SUM(CASE WHEN spod.price_ IS NULL THEN 0 ELSE spod.price_ END) total_num_
 		FROM student_payment_order spo
 		LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
-		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
+		WHERE spo.status_ = 'SUCCESS' AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
 		AND spo.type_ = 'DEGREE' AND spod.type_ IN ('THEORY_COURSE','VIP')
 		<if test="organIds!=null and organIds.size()>0">
 			AND spo.organ_id_ IN
@@ -1604,7 +1598,7 @@
 		SELECT spo.organ_id_,SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
 		CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) total_num_
 		FROM student_payment_order spo
-		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
+		WHERE spo.status_ = 'SUCCESS' AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate}
 		AND spo.type_ = 'SMALL_CLASS_TO_BUY'
 		<if test="organIds!=null and organIds.size()>0">
 			AND spo.organ_id_ IN
@@ -1630,7 +1624,7 @@
 							   CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) total_num_
 		   ,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_,spo.type_
 		FROM student_payment_order spo
-		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
+		WHERE spo.status_ = 'SUCCESS' AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
 		AND spo.type_ NOT IN ('APPLY','RENEW','PRACTICE_GROUP_BUY','PRACTICE_GROUP_RENEW','SMALL_CLASS_TO_BUY','DEGREE')
 		<if test="organIds!=null and organIds.size()>0">
 			AND spo.organ_id_ IN
@@ -1643,7 +1637,7 @@
 		SELECT spo.organ_id_,SUM(CASE WHEN spod.price_ IS NULL THEN 0 ELSE spod.price_ END) total_num_,DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') month_,spo.type_
 		FROM student_payment_order spo
 			   LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
-		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
+		WHERE spo.status_ = 'SUCCESS' AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate}
 		AND spo.type_ = 'DEGREE' AND spod.type_ = 'DEGREE_REGISTRATION'
 		<if test="organIds!=null and organIds.size()>0">
 			AND spo.organ_id_ IN
@@ -1656,34 +1650,38 @@
 	</select>
 
 	<select id="getOrganOtherAmountDataWithTimelyDetails" resultMap="IndexBaseMonthData">
-		SELECT o.id_ organ_id_,o.name_ organ_name_,SUM(c.total_num_) percent_ FROM organization o
+		SELECT
+		o.id_ organ_id_,o.name_ organ_name_,COALESCE(SUM(c.total_num_), 0) percent_
+		FROM organization o
 		LEFT JOIN (
-		SELECT spo.organ_id_,SUM(CASE WHEN spo.actual_amount_ IS NULL THEN 0 ELSE spo.actual_amount_ END +
-							   CASE WHEN spo.balance_payment_amount_ IS NULL THEN 0 ELSE spo.balance_payment_amount_ END) total_num_,spo.type_
+		SELECT organ_id_, type_, SUM(total_num_) total_num_
+		FROM (
+		SELECT spo.organ_id_, spo.type_, (COALESCE(spo.actual_amount_, 0) + COALESCE(spo.balance_payment_amount_, 0)) total_num_
 		FROM student_payment_order spo
-		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate} and spo.tenant_id_ = #{tenantId}
-		AND spo.type_ NOT IN ('APPLY','ADD_STUDENT','RENEW','PRACTICE_GROUP_BUY','PRACTICE_GROUP_RENEW','SMALL_CLASS_TO_BUY','DEGREE')
+		WHERE spo.status_ = 'SUCCESS' AND spo.tenant_id_ = #{tenantId}
+		AND spo.type_ NOT IN ('APPLY', 'ADD_STUDENT', 'RENEW', 'PRACTICE_GROUP_BUY', 'PRACTICE_GROUP_RENEW', 'SMALL_CLASS_TO_BUY', 'DEGREE')
 		<if test="organIds!=null and organIds.size()>0">
 			AND spo.organ_id_ IN
 			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
 				#{organId}
 			</foreach>
 		</if>
-		GROUP BY spo.organ_id_,spo.type_
+		AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate}
 		UNION ALL
-		SELECT spo.organ_id_,SUM(CASE WHEN spod.price_ IS NULL THEN 0 ELSE spod.price_ END) total_num_,spo.type_
+		SELECT spo.organ_id_, spo.type_, COALESCE(spod.price_, 0) total_num_
 		FROM student_payment_order spo
-			   LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
-		WHERE spo.status_ = 'SUCCESS' AND DATE_FORMAT(spo.pay_time_,'%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
-		AND spo.type_ = 'DEGREE' AND spod.type_ = 'DEGREE_REGISTRATION'
+		LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
+		WHERE spo.status_ = 'SUCCESS' AND spo.tenant_id_ = #{tenantId} AND spo.type_ = 'DEGREE' AND spod.type_ = 'DEGREE_REGISTRATION'
 		<if test="organIds!=null and organIds.size()>0">
 			AND spo.organ_id_ IN
 			<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
 				#{organId}
 			</foreach>
 		</if>
-		GROUP BY spo.organ_id_,spo.type_
-		)c ON c.organ_id_ = o.id_
+		AND spo.pay_time_ BETWEEN #{startDate} AND #{endDate}
+		) t
+		GROUP BY organ_id_, type_
+		) c ON o.id_ = c.organ_id_
 		WHERE o.tenant_id_ = #{tenantId}
 		<if test="organIds!=null and organIds.size()>0">
 			AND o.id_ IN
@@ -1691,7 +1689,8 @@
 				#{organId}
 			</foreach>
 		</if>
-		GROUP BY o.id_ ORDER BY percent_ DESC
+		GROUP BY o.id_,o.name_
+		ORDER BY percent_ DESC
 	</select>
 
 	<sql id="queryTeacherServeInfoCondition">

+ 26 - 18
mec-biz/src/main/resources/config/mybatis/StudentExtracurricularExercisesSituationMapper.xml

@@ -855,24 +855,32 @@
     <select id="countWaitCreateHomeworkNum1" resultType="java.lang.Integer">
         SELECT SUM(t.num_)
         FROM (
-                 SELECT COUNT(se.id_) num_
-                 FROM student_extracurricular_exercises_situation_ se
-                          LEFT JOIN course_schedule cs ON FIND_IN_SET(cs.id_, se.course_ids_)
-                 WHERE se.teacher_id_ = #{teacherId}
-                   AND se.expect_exercises_num_ > se.actual_exercises_num_
-                   AND DATE_FORMAT(NOW(), '%Y-%m-%d') BETWEEN se.monday_ AND se.sunday_
-                   AND se.serve_type_ = 'HOMEWORK'
-                   AND cs.group_type_ = 'MUSIC'
-                   AND cs.class_date_ = DATE_FORMAT(NOW(), '%Y-%m-%d')
-                 UNION ALL
-                 SELECT COUNT(se.id_) num_
-                 FROM student_extracurricular_exercises_situation_ se
-                          LEFT JOIN course_schedule cs ON FIND_IN_SET(cs.id_, se.course_ids_)
-                 WHERE se.teacher_id_ = #{teacherId}
-                   AND se.expect_exercises_num_ > se.actual_exercises_num_
-                   AND DATE_FORMAT(NOW(), '%Y-%m-%d') BETWEEN se.monday_ AND se.sunday_
-                   AND se.serve_type_ = 'HOMEWORK'
-                   AND cs.group_type_ != 'MUSIC' AND cs.class_date_ &lt;= DATE_FORMAT(NOW(), '%Y-%m-%d')) t
+        SELECT COUNT(se.id_) num_
+        FROM student_extracurricular_exercises_situation_ se
+        LEFT JOIN (
+        SELECT DISTINCT cs.id_
+        FROM course_schedule cs
+        WHERE cs.group_type_ = 'MUSIC' AND cs.class_date_ = DATE_FORMAT(NOW(), '%Y-%m-%d')
+        ) music_cs ON FIND_IN_SET(music_cs.id_, se.course_ids_)
+        WHERE se.teacher_id_ = #{teacherId}
+        AND se.expect_exercises_num_ > se.actual_exercises_num_
+        AND DATE_FORMAT(NOW(), '%Y-%m-%d') BETWEEN se.monday_ AND se.sunday_
+        AND se.serve_type_ = 'HOMEWORK'
+        AND music_cs.id_ IS NOT NULL
+        UNION ALL
+        SELECT COUNT(se.id_) num_
+        FROM student_extracurricular_exercises_situation_ se
+        LEFT JOIN (
+        SELECT DISTINCT cs.id_
+        FROM course_schedule cs
+        WHERE cs.group_type_ != 'MUSIC' AND cs.class_date_ &lt;= DATE_FORMAT(NOW(), '%Y-%m-%d')
+        ) non_music_cs ON FIND_IN_SET(non_music_cs.id_, se.course_ids_)
+        WHERE se.teacher_id_ = #{teacherId}
+        AND se.expect_exercises_num_ > se.actual_exercises_num_
+        AND DATE_FORMAT(NOW(), '%Y-%m-%d') BETWEEN se.monday_ AND se.sunday_
+        AND se.serve_type_ = 'HOMEWORK'
+        AND non_music_cs.id_ IS NOT NULL
+        ) t
     </select>
 
     <select id="queryTeacherPerformanceIndicator" resultMap="TeacherServeDto">

+ 3 - 1
mec-common/audit-log/src/main/java/com/yonge/log/interceptor/AuditLogInterceptor.java

@@ -16,6 +16,7 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.net.InetAddress;
 import java.nio.charset.Charset;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -96,7 +97,8 @@ public class AuditLogInterceptor extends HandlerInterceptorAdapter {
         auditLog.setInterfaceUrl(servletPath);
         auditLog.setToken(request.getHeader("Authorization"));
         auditLog.setService(clientName);
-        auditLog.setUserIp(WebUtil.getRemoteIp(request));
+        String remoteAddr = request.getHeader("HTTP_X_FORWARDED_FOR");
+        auditLog.setUserIp(remoteAddr);
 
         Map<String, Object> params = WebUtil.getParameterMap(request);
         if (params == null || params.size() == 0) {

+ 42 - 2
mec-gateway/mec-gateway-web/src/main/java/com/ym/mec/gateway/web/filter/AuthFilter.java

@@ -2,12 +2,16 @@ package com.ym.mec.gateway.web.filter;
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.bouncycastle.util.IPAddress;
 import org.springframework.stereotype.Component;
 
 import com.netflix.zuul.ZuulFilter;
 import com.netflix.zuul.context.RequestContext;
 import com.netflix.zuul.exception.ZuulException;
 
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
 @Component
 public class AuthFilter extends ZuulFilter {
 
@@ -15,11 +19,47 @@ public class AuthFilter extends ZuulFilter {
 	public Object run() throws ZuulException {//过滤器核心业务方法
 		RequestContext requestContext = RequestContext.getCurrentContext();
 		HttpServletRequest request = requestContext.getRequest();
-
-
+		String remoteIp = getRealIp(request);
+		requestContext.getZuulRequestHeaders().put("HTTP_X_FORWARDED_FOR", remoteIp);
 		return null;
 	}
 
+	public static String getRealIp(HttpServletRequest request) {
+		String ipAddress = request.getHeader("X-Forwarded-For");
+		if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
+			ipAddress = request.getHeader("Proxy-Client-IP");
+		}
+		if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
+			ipAddress = request.getHeader("WL-Proxy-Client-IP");
+		}
+		if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
+			ipAddress = request.getHeader("HTTP_CLIENT_IP");
+		}
+		if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
+			ipAddress = request.getHeader("HTTP_X_FORWARDED_FOR");
+		}
+		if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
+			ipAddress = request.getRemoteAddr();
+			if (ipAddress.equals("127.0.0.1") || ipAddress.equals("0:0:0:0:0:0:0:1")) {
+				// 根据网卡取本机配置的IP
+				InetAddress inet = null;
+				try {
+					inet = InetAddress.getLocalHost();
+				} catch (UnknownHostException e) {
+					e.printStackTrace();
+				}
+				ipAddress = inet.getHostAddress();
+			}
+		}
+		if (ipAddress != null && ipAddress.length() > 15) {
+			if (ipAddress.indexOf(",") > 0) {
+				ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
+			}
+		}
+		return ipAddress;
+	}
+
+
 	@Override
 	public boolean shouldFilter() {// 返回true,必须执行过滤器;false,不执行过滤器
 		return true;

+ 2 - 0
mec-util/src/main/java/com/ym/mec/util/web/WebUtil.java

@@ -192,4 +192,6 @@ public class WebUtil {
 
 		return isFromMobile;
 	}
+
+	
 }