添加从浪潮获取人员标签(先判断本地有没有,然后在从浪潮人员标签查询)
This commit is contained in:
@@ -127,6 +127,48 @@ public class HttpUtils {
|
||||
return executeRequest(requestBuilder.build(), connectTimeout, readTimeout, writeTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送 GET 请求(无请求头)
|
||||
*/
|
||||
public static String doGet(String url) throws Exception {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.get()
|
||||
.build();
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
throw new IOException("GET 请求失败,状态码:" + response.code());
|
||||
}
|
||||
ResponseBody body = response.body();
|
||||
return body != null ? body.string() : "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送 GET 请求(带请求头)
|
||||
*/
|
||||
public static String doGet(String url, Map<String, String> headers) throws Exception {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
Request.Builder builder = new Request.Builder().url(url);
|
||||
|
||||
if (headers != null && !headers.isEmpty()) {
|
||||
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
||||
builder.addHeader(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
Request request = builder.get().build();
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (!response.isSuccessful()) {
|
||||
throw new IOException("GET 请求失败,状态码:" + response.code());
|
||||
}
|
||||
ResponseBody body = response.body();
|
||||
return body != null ? body.string() : "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行请求核心方法
|
||||
*/
|
||||
|
||||
@@ -76,6 +76,10 @@ public class OauthClient {
|
||||
@Value("${oauth.write-timeout:30}")
|
||||
private int writeTimeout;
|
||||
|
||||
/*====================== 浪潮-人员标签 ======================*/
|
||||
@Value("${lc.personTag}")
|
||||
public String personTagUrl;
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@@ -258,6 +262,27 @@ public class OauthClient {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据身份证获取tagName
|
||||
* @param idCard
|
||||
* @return
|
||||
*/
|
||||
public String nwLcUserTag(String idCard){
|
||||
String url=personTagUrl+"/"+idCard;
|
||||
try {
|
||||
String result = HttpUtils.doGet(url);
|
||||
JSONObject json = JSONObject.parseObject(result);
|
||||
if(json.getIntValue("code") != 200){
|
||||
return null;
|
||||
}
|
||||
JSONObject data = json.getJSONObject("data");
|
||||
return data == null ? null : data.getString("tagName");
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析List
|
||||
* @param jsonStr
|
||||
|
||||
Reference in New Issue
Block a user