Commit d24e14ec by 谢海旭

Merge branch 'develop' into 'master'

地图切换版本代码合并

See merge request !3
2 parents 61d997a9 6b494e08
...@@ -60,7 +60,8 @@ public class FspComponent { ...@@ -60,7 +60,8 @@ public class FspComponent {
} }
int beginTimestamp = DateUtils.getEpochSecond(beginTime).intValue(); int beginTimestamp = DateUtils.getEpochSecond(beginTime).intValue();
int endTimestamp = DateUtils.getEpochSecond(endTime).intValue(); int endTimestamp = DateUtils.getEpochSecond(endTime).intValue();
FspReq fspReq = new FspReq(sn, 5, beginTimestamp, endTimestamp, locInfoType, perType, 2); // extraMapReq 0:原始坐标 1:转换高德和百度坐标 2:转换高德坐标 3:转换百度坐标
FspReq fspReq = new FspReq(sn, 5, beginTimestamp, endTimestamp, locInfoType, perType, 1);
FspResp fspResp = new FspResp(); FspResp fspResp = new FspResp();
FspRespHolder fspRespHolder = new FspRespHolder(fspResp); FspRespHolder fspRespHolder = new FspRespHolder(fspResp);
...@@ -90,7 +91,7 @@ public class FspComponent { ...@@ -90,7 +91,7 @@ public class FspComponent {
resident.setLatitude(String.valueOf(resideBaseInfo.gps.latitude)); resident.setLatitude(String.valueOf(resideBaseInfo.gps.latitude));
resident.setLongitude(String.valueOf(resideBaseInfo.gps.longitude)); resident.setLongitude(String.valueOf(resideBaseInfo.gps.longitude));
resident.setBlat(String.valueOf(resideBaseInfo.gps.blat)); resident.setBlat(String.valueOf(resideBaseInfo.gps.blat));
resident.setBlng(String.valueOf(resideBaseInfo.gps.blat)); resident.setBlng(String.valueOf(resideBaseInfo.gps.blng));
resident.setElat(String.valueOf(resideBaseInfo.gps.glat)); resident.setElat(String.valueOf(resideBaseInfo.gps.glat));
resident.setElng(String.valueOf(resideBaseInfo.gps.glng)); resident.setElng(String.valueOf(resideBaseInfo.gps.glng));
return resident; return resident;
......
...@@ -850,15 +850,11 @@ public class HdaoGpsComponent { ...@@ -850,15 +850,11 @@ public class HdaoGpsComponent {
return null; return null;
} }
wifiData[] wifiDataArr = wifiResponse.records; wifiData[] wifiDataArr = wifiResponse.records;
StringBuffer macStr = new StringBuffer(); String macStr = Arrays.stream(wifiDataArr).map(wifiData -> String.format("%s,%d,", wifiData.mac, wifiData.single)).collect(Collectors.joining("|"));
for (wifiData data : wifiDataArr) {
String mac = data.mac; log.info("sn:" + sn + "mac:" + macStr);
macStr.append(mac);
macStr.append("|");
}
log.info("sn:" + sn + "mac:" + macStr.toString());
//解析mac地址获取定位 //解析mac地址获取定位
WifiMapInfoModel wifiMapInfoModel = MapUtil.getWifiLoactionByMac(macStr.toString()); WifiMapInfoModel wifiMapInfoModel = MapUtil.getWifiLocationByMacWithBaidu(macStr);
if (wifiMapInfoModel == null || wifiMapInfoModel.getLocation() == null || wifiMapInfoModel.getType().equals("0")) { if (wifiMapInfoModel == null || wifiMapInfoModel.getLocation() == null || wifiMapInfoModel.getType().equals("0")) {
log.info("解析mac 获取地址失败。定位数据:" + JSONUtil.toJsonStr(wifiMapInfoModel)); log.info("解析mac 获取地址失败。定位数据:" + JSONUtil.toJsonStr(wifiMapInfoModel));
return null; return null;
...@@ -872,6 +868,8 @@ public class HdaoGpsComponent { ...@@ -872,6 +868,8 @@ public class HdaoGpsComponent {
gpsLocation.setLat(lngLat[1]); gpsLocation.setLat(lngLat[1]);
gpsLocation.setElng(lngLat[0]); gpsLocation.setElng(lngLat[0]);
gpsLocation.setElat(lngLat[1]); gpsLocation.setElat(lngLat[1]);
gpsLocation.setBlng(lngLat[0]);
gpsLocation.setBlat(lngLat[1]);
gpsLocation.setAddress(wifiMapInfoModel.getDesc()); gpsLocation.setAddress(wifiMapInfoModel.getDesc());
gpsLocation.setStoreTime(DateUtil.formatDateTime(date)); gpsLocation.setStoreTime(DateUtil.formatDateTime(date));
gpsLocation.setDateTime(DateUtil.formatDateTime(date)); gpsLocation.setDateTime(DateUtil.formatDateTime(date));
......
...@@ -64,7 +64,7 @@ public class StayPointConvert { ...@@ -64,7 +64,7 @@ public class StayPointConvert {
Optional.ofNullable(stayPointRecord.stayGps) Optional.ofNullable(stayPointRecord.stayGps)
.map(e -> e.blng) .map(e -> e.blng)
.map(LocationUtil::latlng) .map(LocationUtil::latlng)
.ifPresent(gpsLocation::setBlat); .ifPresent(gpsLocation::setBlng);
Optional.ofNullable(stayPointRecord.stayGps) Optional.ofNullable(stayPointRecord.stayGps)
.map(e -> e.glat) .map(e -> e.glat)
......
package cn.com.glsx.devicemonitor.modules.utils; package cn.com.glsx.devicemonitor.modules.utils;
import cn.com.glsx.devicemonitor.modules.model.WifiMapInfoModel; import cn.com.glsx.devicemonitor.modules.model.WifiMapInfoModel;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.common.utils.HttpUtils; import com.glsx.plat.common.utils.HttpUtils;
import com.glsx.plat.context.utils.PropertiesUtils; import com.glsx.plat.context.utils.PropertiesUtils;
import io.micrometer.core.instrument.util.JsonUtils; import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
...@@ -21,6 +23,132 @@ public class MapUtil { ...@@ -21,6 +23,132 @@ public class MapUtil {
* @return * @return
*/ */
public static WifiMapInfoModel getWifiLoactionByMac(String macs) { public static WifiMapInfoModel getWifiLoactionByMac(String macs) {
return getWifiLocationByMacWithAmap(macs);
}
/**
* 通过百度地图解析wifi位置信息
* "macs": "34:47:d4:bb:90:75,66,|44:97:5a:d6:fc:70,66,"
*
* @param macs
* @return
*/
public static WifiMapInfoModel getWifiLocationByMacWithBaidu(String macs) {
String key = PropertiesUtils.getProperty("baidu.map.key");
Map<String, Object> body = new HashMap<>();
body.put("key", key);
body.put("ver", "1.0");
body.put("trace", false);
body.put("prod", "test_loc_api");
body.put("src", "baidu_loc_api");
Map<String, Object> dataForLngLat = new HashMap<>();
dataForLngLat.put("output", "JSON");
dataForLngLat.put("accesstype", 1);
dataForLngLat.put("imei", "xxxxxxxxxxxxxxx");
dataForLngLat.put("macs", macs);
dataForLngLat.put("ctime", String.valueOf(System.currentTimeMillis()));
dataForLngLat.put("need_rgc", "Y");
body.put("body", Lists.newArrayList(dataForLngLat));
try {
String url = "https://api.map.baidu.com/locapi/v2";
String result = HttpUtils.post(url, JSON.toJSONString(body));
JSONObject jsonObject = JSON.parseObject(result);
int errcode = jsonObject.getIntValue("errcode");
if (errcode != 0) {
log.error("getWifiLocationByMacWithBaidu error msg:{}", jsonObject.getString("msg"));
return null;
} else {
JSONArray models = jsonObject.getJSONArray("body");
JSONObject model = models.getJSONObject(0);
WifiMapInfoModel rModel = new WifiMapInfoModel();
rModel.setType(model.getString("type"));
rModel.setLocation(model.getString("location"));
rModel.setRadius(model.getString("radius"));
rModel.setCountry(model.getString("country"));
rModel.setProvince(model.getString("province"));
rModel.setCity(model.getString("city"));
rModel.setCitycode(model.getString("citycode"));
rModel.setRoad(model.getString("road"));
String desc = rModel.getCountry() + rModel.getProvince() + rModel.getCity() + model.getString("district") + rModel.getRoad();
rModel.setDesc(desc);
return rModel;
}
} catch (Exception e) {
log.error("getWifiLocationByMacWithBaidu error", e);
return null;
}
}
/**
* 使用百度地图查询经纬度对应的位置信息
*
* @param bLng
* @param BLat
* @return
*/
public static String getAddressByLngLatWithBaiduMaps(String bLng, String BLat) {
if (StringUtils.isEmpty(bLng) || StringUtils.isEmpty(BLat)) {
return null;
}
String key = PropertiesUtils.getProperty("baidu.map.key");
StringBuilder baiduMapUrl = new StringBuilder();
baiduMapUrl.append("https://api.map.baidu.com/reverse_geocoding/v3/?output=json");
baiduMapUrl.append("&ak=").append(key);
baiduMapUrl.append("&coordtype=wgs84ll");
baiduMapUrl.append("&location=").append(BLat).append(",").append(bLng);
String resultStr = requestGeoByBaiduMapUrl(baiduMapUrl.toString());
if (StringUtils.isBlank(resultStr)) {
return null;
}
JSONObject jo = JSON.parseObject(resultStr);
JSONObject ac = jo.getJSONObject("result").getJSONObject("addressComponent");
return ac.getString("province") + ac.getString("city") + ac.getString("district") + ac.getString("town") + ac.getString("street") + ac.getString("street_number");
}
/**
* 调用百度地图接口
*
* @param baiduMapUrl
* @return
*/
public static String requestGeoByBaiduMapUrl(String baiduMapUrl) {
String result = "";
try {
result = HttpUtils.get(baiduMapUrl);
} catch (Exception e) {
log.info("Request 百度 parse address Exception, messeg:" + e.getMessage());
e.printStackTrace();
return null;
}
if (StringUtils.isEmpty(result)) {
log.info("Request 百度 parse address is empty, result:" + result);
return null;
}
JSONObject resultObj = JSON.parseObject(result);
if (!resultObj.getString("status").equals("0")) {
log.error("Request 百度 parse address wrong, status:" + resultObj.get("status") + " message:" + resultObj.get("message"));
return null;
}
return result;
}
/**
* 通过高德地图解析wifi位置信息
* "macs": "26:D7:EB:DA:30:CF|7A:91:E9:DC:F0:61|"
*
* @param macs
* @return
*/
private static WifiMapInfoModel getWifiLocationByMacWithAmap(String macs) {
String url = "http://apilocate.amap.com/position"; String url = "http://apilocate.amap.com/position";
String gaoDeKey = PropertiesUtils.getProperty("gao.de.map.key"); String gaoDeKey = PropertiesUtils.getProperty("gao.de.map.key");
if (StringUtils.isBlank(gaoDeKey)) { if (StringUtils.isBlank(gaoDeKey)) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!