mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-23 11:09:29 +08:00
完成部门管理
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
package xyz.playedu.api.util;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -124,45 +123,6 @@ public class HelperUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON转 Map<String, String>
|
||||
*
|
||||
* @param json 对象
|
||||
* @return Map<String, String>
|
||||
* @author fzr
|
||||
*/
|
||||
public static Map<String, String> jsonToMap(String json) {
|
||||
Type type = new TypeToken<Map<String, String>>() {
|
||||
}.getType();
|
||||
return JSON.parseObject(json, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON转 Map<String, Object>
|
||||
*
|
||||
* @param json 对象
|
||||
* @return Map<String, String>
|
||||
* @author fzr
|
||||
*/
|
||||
public static Map<String, Object> jsonToMapAsObj(String json) {
|
||||
Type type = new TypeToken<Map<String, Object>>() {
|
||||
}.getType();
|
||||
return JSON.parseObject(json, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON转Map<String, String>
|
||||
*
|
||||
* @param object 对象
|
||||
* @return Map<String, String>
|
||||
* @author fzr
|
||||
*/
|
||||
public static Map<String, String> objectToMap(Object object) {
|
||||
Type type = new TypeToken<Map<String, String>>() {
|
||||
}.getType();
|
||||
return JSON.parseObject(JSONObject.toJSONString(object), type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象类型Map合并
|
||||
*
|
||||
@@ -191,4 +151,9 @@ public class HelperUtil {
|
||||
return map2;
|
||||
}
|
||||
|
||||
public static String toJsonStr(Object obj) throws JsonProcessingException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package xyz.playedu.api.util;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Data;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -60,16 +61,23 @@ public class IpUtil {
|
||||
return "内网";
|
||||
}
|
||||
|
||||
@Data
|
||||
class Response {
|
||||
private String pro;
|
||||
private String city;
|
||||
private String region;
|
||||
private String addr;
|
||||
}
|
||||
|
||||
try {
|
||||
String rspStr = HttpUtil.sendGet(IP_URL, "ip=" + ip + "&json=true", "GBK");
|
||||
if (StringUtil.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);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Response obj = objectMapper.readValue(rspStr, Response.class);
|
||||
return String.format("%s-%s", obj.getPro(), obj.getCity());
|
||||
} catch (Exception e) {
|
||||
log.error("获取地理位置异常 {}", ip);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user