Просмотр исходного кода

个人中心登陆地一样bug修复

fangqing 6 месяцев назад
Родитель
Сommit
0c20082e71

+ 7 - 4
ruoyi-common/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java

@@ -1,5 +1,6 @@
 package com.ruoyi.common.utils.ip;
 
+import com.ruoyi.common.utils.SecurityUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import com.alibaba.fastjson2.JSON;
@@ -9,6 +10,7 @@ import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.http.HttpUtils;
 
+import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 
 /**
@@ -56,10 +58,11 @@ public class AddressUtils
         return UNKNOWN;
     }
 
-    public static String getAddress() throws ExecutionException, InterruptedException {
-
-        //IP地址从当前登录用户的表里拿
-        String ipAddr = IpUtils.getIpAddr();
+    public static String getAddress(String ipAddr) throws ExecutionException, InterruptedException {
+        if (Objects.isNull(ipAddr)) {
+            //IP地址从当前登录用户的表里拿
+            ipAddr = IpUtils.getIpAddr();
+        }
         String address = "未知";
         String  realAddressByIP = getRealAddressByIP(ipAddr);
         if (realAddressByIP.isEmpty() || realAddressByIP.equals("内网IP")){

+ 1 - 1
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityCommentController.java

@@ -245,7 +245,7 @@ public class CommunityCommentController extends BaseController {
             communityCommentReply.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
             String address = null;
             try {
-                address = AddressUtils.getAddress();
+                address = AddressUtils.getAddress(null);
             } catch (ExecutionException e) {
                 throw new RuntimeException(e);
             } catch (InterruptedException e) {

+ 3 - 3
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleServiceImpl.java

@@ -353,7 +353,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
 
         String address = null;
         try {
-            address = AddressUtils.getAddress();
+            address = AddressUtils.getAddress(null);
         } catch (ExecutionException e) {
             throw new RuntimeException(e);
         } catch (InterruptedException e) {
@@ -449,7 +449,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         communityArticleComment.setDelete(false);
         String address = null;
         try {
-            address = AddressUtils.getAddress();
+            address = AddressUtils.getAddress(null);
         } catch (ExecutionException e) {
             throw new RuntimeException(e);
         } catch (InterruptedException e) {
@@ -654,7 +654,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
 
         String address = null;
         try {
-            address = AddressUtils.getAddress();
+            address = AddressUtils.getAddress(sysUser.getLoginIp());
         } catch (ExecutionException e) {
             throw new RuntimeException(e);
         } catch (InterruptedException e) {