Merge branch 'master' of https://gitee.com/y_project/RuoYi-Vue
Conflicts: ruoyi/src/main/java/com/ruoyi/common/constant/Constants.java ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java ruoyi/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java ruoyi/src/main/resources/application.yml ruoyi/src/main/resources/mybatis/system/SysDeptMapper.xml
This commit is contained in:
commit
661cc0afdb
|
@ -13,7 +13,12 @@ public class Constants
|
||||||
* UTF-8 字符集
|
* UTF-8 字符集
|
||||||
*/
|
*/
|
||||||
public static final String UTF8 = "UTF-8";
|
public static final String UTF8 = "UTF-8";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GBK 字符集
|
||||||
|
*/
|
||||||
|
public static final String GBK = "GBK";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用成功标识
|
* 通用成功标识
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -18,6 +18,7 @@ import javax.net.ssl.TrustManager;
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import com.ruoyi.common.constant.Constants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用http发送方法
|
* 通用http发送方法
|
||||||
|
@ -36,6 +37,19 @@ public class HttpUtils
|
||||||
* @return 所代表远程资源的响应结果
|
* @return 所代表远程资源的响应结果
|
||||||
*/
|
*/
|
||||||
public static String sendGet(String url, String param)
|
public static String sendGet(String url, String param)
|
||||||
|
{
|
||||||
|
return sendGet(url, param, Constants.UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向指定 URL 发送GET方法的请求
|
||||||
|
*
|
||||||
|
* @param url 发送请求的 URL
|
||||||
|
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
|
||||||
|
* @param contentType 编码类型
|
||||||
|
* @return 所代表远程资源的响应结果
|
||||||
|
*/
|
||||||
|
public static String sendGet(String url, String param, String contentType)
|
||||||
{
|
{
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
BufferedReader in = null;
|
BufferedReader in = null;
|
||||||
|
@ -49,7 +63,7 @@ public class HttpUtils
|
||||||
connection.setRequestProperty("connection", "Keep-Alive");
|
connection.setRequestProperty("connection", "Keep-Alive");
|
||||||
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
|
||||||
connection.connect();
|
connection.connect();
|
||||||
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
in = new BufferedReader(new InputStreamReader(connection.getInputStream(), contentType));
|
||||||
String line;
|
String line;
|
||||||
while ((line = in.readLine()) != null)
|
while ((line = in.readLine()) != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.ruoyi.common.utils.ip;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.ruoyi.common.constant.Constants;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.http.HttpUtils;
|
import com.ruoyi.common.utils.http.HttpUtils;
|
||||||
import com.ruoyi.framework.config.RuoYiConfig;
|
import com.ruoyi.framework.config.RuoYiConfig;
|
||||||
|
@ -16,11 +17,15 @@ public class AddressUtils
|
||||||
{
|
{
|
||||||
private static final Logger log = LoggerFactory.getLogger(AddressUtils.class);
|
private static final Logger log = LoggerFactory.getLogger(AddressUtils.class);
|
||||||
|
|
||||||
public static final String IP_URL = "http://ip.taobao.com/service/getIpInfo.php";
|
// IP地址查询
|
||||||
|
public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp";
|
||||||
|
|
||||||
|
// 未知地址
|
||||||
|
public static final String UNKNOWN = "XX XX";
|
||||||
|
|
||||||
public static String getRealAddressByIP(String ip)
|
public static String getRealAddressByIP(String ip)
|
||||||
{
|
{
|
||||||
String address = "XX XX";
|
String address = UNKNOWN;
|
||||||
// 内网不查询
|
// 内网不查询
|
||||||
if (IpUtils.internalIp(ip))
|
if (IpUtils.internalIp(ip))
|
||||||
{
|
{
|
||||||
|
@ -28,17 +33,23 @@ public class AddressUtils
|
||||||
}
|
}
|
||||||
if (RuoYiConfig.isAddressEnabled())
|
if (RuoYiConfig.isAddressEnabled())
|
||||||
{
|
{
|
||||||
String rspStr = HttpUtils.sendPost(IP_URL, "ip=" + ip);
|
try
|
||||||
if (StringUtils.isEmpty(rspStr))
|
{
|
||||||
|
String rspStr = HttpUtils.sendGet(IP_URL, "ip=" + ip + "&json=true", Constants.GBK);
|
||||||
|
if (StringUtils.isEmpty(rspStr))
|
||||||
|
{
|
||||||
|
log.error("获取地理位置异常 {}", ip);
|
||||||
|
return UNKNOWN;
|
||||||
|
}
|
||||||
|
JSONObject obj = JSONObject.parseObject(rspStr);
|
||||||
|
String region = obj.getString("pro");
|
||||||
|
String city = obj.getString("city");
|
||||||
|
return String.format("%s %s", region, city);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
log.error("获取地理位置异常 {}", ip);
|
log.error("获取地理位置异常 {}", ip);
|
||||||
return address;
|
|
||||||
}
|
}
|
||||||
JSONObject obj = JSONObject.parseObject(rspStr);
|
|
||||||
JSONObject data = obj.getObject("data", JSONObject.class);
|
|
||||||
String region = data.getString("region");
|
|
||||||
String city = data.getString("city");
|
|
||||||
address = region + " " + city;
|
|
||||||
}
|
}
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ ruoyi:
|
||||||
# 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
|
# 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
|
||||||
profile: D:/ruoyi/uploadPath
|
profile: D:/ruoyi/uploadPath
|
||||||
# 获取ip地址开关
|
# 获取ip地址开关
|
||||||
addressEnabled: true
|
addressEnabled: false
|
||||||
|
|
||||||
# 开发环境配置
|
# 开发环境配置
|
||||||
server:
|
server:
|
||||||
|
|
|
@ -71,7 +71,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
select * from sys_dept where find_in_set(#{deptId}, ancestors)
|
select * from sys_dept where find_in_set(#{deptId}, ancestors)
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectNormalChildrenDeptById" parameterType="Long" resultType="java.lang.Integer">
|
<select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
|
||||||
select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
|
select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue