mirror of
https://gitee.com/freshday/radar.git
synced 2026-03-22 04:37:16 +08:00
@@ -24,6 +24,7 @@ public class MainController {
|
||||
@RequestParam @ApiParam(name="reqId",value="请求流水号",required=true) String reqId,
|
||||
@RequestParam @ApiParam(name="jsonInfo",value="事件内容(json 格式)",required=true) String jsonInfo) {
|
||||
CommonResult result = engineApi.uploadInfo(modelGuid, reqId, jsonInfo);
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -32,6 +33,7 @@ public class MainController {
|
||||
public CommonResult getScore(@RequestParam @ApiParam(name="modelGuid",value="模型Guid",required=true) String modelGuid,
|
||||
@RequestParam @ApiParam(name="reqId",value="请求流水号",required=true) String reqId) {
|
||||
CommonResult result = engineApi.getScore(modelGuid, reqId);
|
||||
result.setSuccess(true);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,19 @@
|
||||
package com.pgmmers.radar.service.impl.engine.Plugin;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.pgmmers.radar.service.engine.PluginServiceV2;
|
||||
import com.pgmmers.radar.service.engine.vo.Location;
|
||||
import com.pgmmers.radar.vo.model.PreItemVO;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -9,6 +21,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class GPS2LOCATION implements PluginServiceV2 {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GPS2LOCATION.class);
|
||||
@Override
|
||||
public Integer key() {
|
||||
return 2;
|
||||
@@ -33,6 +46,42 @@ public class GPS2LOCATION implements PluginServiceV2 {
|
||||
public Object handle(PreItemVO item, Map<String, Object> jsonInfo,
|
||||
String[] sourceField) {
|
||||
// TODO 可以参考 http://jwd.funnyapi.com/#/index , 最好是本地库。
|
||||
return null;
|
||||
Location location = new Location();
|
||||
String latitude = String.valueOf(jsonInfo.get(sourceField[0]));//纬度
|
||||
String longitude = String.valueOf(jsonInfo.get(sourceField[1]));//经度
|
||||
if ("".equals(latitude) || "".equals(longitude)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
String url ="http://106.75.35.67:60000/gis?auth_user=freevip&latitude="+latitude+"&longitude="+longitude;
|
||||
//创建httpclient对象
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
//创建GET对象
|
||||
HttpGet httpget = new HttpGet(url);
|
||||
//执行请求
|
||||
CloseableHttpResponse response = httpclient.execute(httpget);
|
||||
if(response.getStatusLine().getStatusCode()==200) {
|
||||
HttpEntity entity = response.getEntity();
|
||||
//所需内容都在entity里面,这里可以对数据操作
|
||||
String detail = EntityUtils.toString(entity,"UTF-8");
|
||||
JSONObject parseObject = JSONObject.parseObject(detail);
|
||||
//String转map
|
||||
String data = parseObject.getString("data");
|
||||
Map stringToMap = JSONObject.parseObject(data);
|
||||
|
||||
location.setCountry(String.valueOf(stringToMap.get("zh0")));
|
||||
location.setRegion(String.valueOf(stringToMap.get("zh3")));
|
||||
location.setProvince(String.valueOf(stringToMap.get("zh1")));
|
||||
location.setCity(String.valueOf(stringToMap.get("zh2")));
|
||||
|
||||
}
|
||||
response.close();
|
||||
httpclient.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("GPS2LOCATION error", e);
|
||||
}
|
||||
return location;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user