Browse Source

补充gis代码

master
zhangyuan 3 years ago
parent
commit
e2cada1953
  1. 13
      epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/RedisKeys.java
  2. 67
      epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/utils/ConvertUtils.java
  3. 68
      spring-boot-httpclient-starter/src/main/java/com/elink/esua/httpclient/HttpClientUtils.java

13
epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/redis/RedisKeys.java

@ -304,4 +304,17 @@ public class RedisKeys {
/*public static String getVaccinationAuthKey(String userId) {
return rootPrefix.concat("vaccination:auth:role:").concat(userId);
}*/
/**
* 北上诉办GIS网格坐标key
*
* @param
* @return java.lang.String
* @author zhy
* @date 2022/9/4 17:25
*/
public static String getArcGISKey() {
return rootPrefix.concat("gis:bssb");
}
}

67
epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/utils/ConvertUtils.java

@ -12,9 +12,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
/**
* 转换工具类
@ -58,4 +63,60 @@ public class ConvertUtils {
return targetList;
}
/**
* @Description entity转map
* @return
* @author wxz
* @date 2021.03.22 16:38
*/
public static Map<String, String> entityToMap(Object bean) throws IntrospectionException, InvocationTargetException, IllegalAccessException {
Class<?> type = bean.getClass();
Map<String, String> returnMap = new HashMap(16);
BeanInfo beanInfo = Introspector.getBeanInfo(type);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for(int i = 0; i < propertyDescriptors.length; ++i) {
PropertyDescriptor descriptor = propertyDescriptors[i];
String propertyName = descriptor.getName();
if (!"class".equals(propertyName)) {
Method readMethod = descriptor.getReadMethod();
Object result = readMethod.invoke(bean);
if (result != null) {
returnMap.put(propertyName, String.valueOf(result));
} else {
returnMap.put(propertyName, "");
}
}
}
return returnMap;
}
public static <T> T mapToEntity(Map<String, Object> map, Class<T> entity) {
if (null == map){
return null;
}
T t = null;
try {
t = entity.newInstance();
for(Field field : entity.getDeclaredFields()) {
if (map.containsKey(field.getName())) {
boolean flag = field.isAccessible();
field.setAccessible(true);
Object object = map.get(field.getName());
if (object!= null && field.getType().isAssignableFrom(object.getClass())) {
field.set(t, object);
}
field.setAccessible(flag);
}
}
return t;
} catch (InstantiationException e) {
logger.error("convert error ", e);
} catch (IllegalAccessException e) {
logger.error("convert error ", e);
}
return t;
}
}

68
spring-boot-httpclient-starter/src/main/java/com/elink/esua/httpclient/HttpClientUtils.java

@ -6,10 +6,12 @@ import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
@ -17,6 +19,8 @@ import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.net.URI;
@ -38,6 +42,15 @@ public class HttpClientUtils {
private CloseableHttpClient client;
private static int connectionTimeout = 5000;
// 读取数据超时时间,毫秒
private static int soTimeout = 45000;
private static String HEADER_CONTENT_TYPE = "Content-Type";
private static String HEADER_APPLICATION_JSON = "application/json;charset=utf-8";
private static String UTF8 = "utf-8";
private static String HEADER_APPLICATION_FORM_URL_ENCODED = "application/x-www-form-urlencoded;charset=utf-8";
public HttpClientUtils(HttpClientManagerFactoryBen httpClientBean) {
try {
this.client = httpClientBean.getObject();
@ -169,4 +182,59 @@ public class HttpClientUtils {
}
return formparams;
}
/**
* desc: 发送get请求
* param:url, params
* return: CallResult<String>
* date: 2019/2/21 9:16
*
* @author: jianjun liu
*/
public ResultDto sendGet(String url, Map<String, Object> params) {
try {
URIBuilder builder = new URIBuilder(url);
if (!CollectionUtils.isEmpty(params)) {
Set<String> set = params.keySet();
for (String key : set) {
builder.setParameter(key, params.get(key) == null ? "" : String.valueOf(params.get(key)));
}
}
HttpGet httpGet = new HttpGet(builder.build());
httpGet.setConfig(requestConfig);
return getResult(client.execute(httpGet));
} catch (Exception e) {
return null;
}
}
public ResultDto sendPostByJSONAndHeader(String url, String jsonStrParam,Map<String,String> headerMap) {
try {
HttpPost httppost = new HttpPost(url);
httppost.setConfig(requestConfig);
httppost.addHeader(HEADER_CONTENT_TYPE, HEADER_APPLICATION_JSON);
if (null != headerMap){
headerMap.forEach((k,v) -> {
httppost.addHeader(k,v);
});
}
if (!StringUtils.isEmpty(jsonStrParam)) {
StringEntity se = new StringEntity(jsonStrParam, UTF8);
httppost.setEntity(se);
}
return getResult(client.execute(httppost));
} catch (Exception e) {
return null;
}
}
/*** 超时设置 ****/
private static RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(soTimeout)
.setConnectTimeout(connectionTimeout)
.setConnectionRequestTimeout(soTimeout)
.build();//设置请求和传输超时时间
}

Loading…
Cancel
Save