bug修复
This commit is contained in:
parent
3d2ac88b86
commit
58be0d1ea5
@ -139,10 +139,12 @@ public class MechanicalEquipmentPositionDataController {
|
||||
@ApiImplicitParam(name = "projectSn", value = "项目sn", paramType = "body", required = true, dataType = "String"),
|
||||
})
|
||||
@PostMapping(value = "/jxzhgAddData")
|
||||
public Result jxzhgAddData(@ApiIgnore @RequestBody HashMap<String, Object> paramMap) {
|
||||
log.info("机械指挥官添加机械设备定位-实时数据信息:{}", JSON.toJSONString(paramMap));
|
||||
public Result jxzhgAddData(@ApiIgnore @RequestBody List<HashMap<String, Object>> list) {
|
||||
log.info("机械指挥官添加机械设备定位-实时数据信息:{}", JSON.toJSONString(list));
|
||||
try {
|
||||
mechanicalEquipmentPositionDataService.jxzhgAddData(paramMap);
|
||||
for (HashMap<String, Object> map : list) {
|
||||
mechanicalEquipmentPositionDataService.jxzhgAddData(map);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return Result.ok(e.getMessage());
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import com.zhgd.xmgl.modules.mechanicalequipmentposition.mapper.MechanicalEquipm
|
||||
import com.zhgd.xmgl.modules.mechanicalequipmentposition.mapper.MechanicalEquipmentPositionDevMapper;
|
||||
import com.zhgd.xmgl.modules.mechanicalequipmentposition.mapper.MechanicalEquipmentPositionFenceMapper;
|
||||
import com.zhgd.xmgl.modules.mechanicalequipmentposition.service.IMechanicalEquipmentPositionDataService;
|
||||
import com.zhgd.xmgl.util.CoordinateTransformUtil;
|
||||
import com.zhgd.xmgl.util.PageUtil;
|
||||
import com.zhgd.xmgl.util.RefUtil;
|
||||
import com.zhgd.xmgl.util.RegionUtil;
|
||||
@ -191,8 +192,11 @@ public class MechanicalEquipmentPositionDataServiceImpl extends ServiceImpl<Mech
|
||||
Map stateInfo = MapUtils.getMap(paramMap, "state_info");
|
||||
MechanicalEquipmentPositionData data = new MechanicalEquipmentPositionData();
|
||||
data.setDevSn(MapUtils.getString(machineInfo, "machine_uuid"));
|
||||
data.setLatitude(MapUtils.getDouble(locationInfo, "latitude"));
|
||||
data.setLongitude(MapUtils.getDouble(locationInfo, "longitude"));
|
||||
Double latitude = MapUtils.getDouble(locationInfo, "latitude");
|
||||
Double longitude = MapUtils.getDouble(locationInfo, "longitude");
|
||||
double[] pointArr = CoordinateTransformUtil.transformWGS84ToGCJ02(longitude, latitude);
|
||||
data.setLatitude(pointArr[1]);
|
||||
data.setLongitude(pointArr[0]);
|
||||
data.setUploadTime(new Date(MapUtils.getLong(stateInfo, "state_update_time") * 1000L));
|
||||
data.setSpeed(MapUtils.getDouble(locationInfo, "speed"));
|
||||
data.setWorkStatus(getWorkStatusJzhg(MapUtils.getString(stateInfo, "machine_state")));
|
||||
|
||||
@ -278,6 +278,7 @@ public class AqiUtil {
|
||||
param.put("cityid", cityid);
|
||||
}
|
||||
String r = HttpUtil.get(tianqiUrl + "/free/week", param);
|
||||
log.info("tianqi-getWeatherData:rs:{}", r);
|
||||
JSONObject jsonObject = JSONObject.parseObject(r);
|
||||
com.gexin.fastjson.JSONArray sevenDataArr = jsonObject.getJSONArray("data");
|
||||
for (Object o : sevenDataArr) {
|
||||
|
||||
181
src/main/java/com/zhgd/xmgl/util/CoordinateTransformUtil.java
Normal file
181
src/main/java/com/zhgd/xmgl/util/CoordinateTransformUtil.java
Normal file
@ -0,0 +1,181 @@
|
||||
package com.zhgd.xmgl.util;
|
||||
|
||||
/**
|
||||
* 提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换
|
||||
*
|
||||
* @author Daniel
|
||||
* @since 2016/7/27 0027
|
||||
*/
|
||||
public class CoordinateTransformUtil {
|
||||
private static final double x_PI = 3.14159265358979324 * 3000.0 / 180.0;
|
||||
private static final double PI = 3.1415926535897932384626;
|
||||
private static final double a = 6378245.0;
|
||||
private static final double ee = 0.00669342162296594323;
|
||||
|
||||
/**
|
||||
* 百度坐标(BD09)转 GCJ02
|
||||
*
|
||||
* @param lng 百度经度
|
||||
* @param lat 百度纬度
|
||||
* @return GCJ02 坐标:[经度,纬度]
|
||||
*/
|
||||
public static double[] transformBD09ToGCJ02(double lng, double lat) {
|
||||
double x = lng - 0.0065;
|
||||
double y = lat - 0.006;
|
||||
double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_PI);
|
||||
double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_PI);
|
||||
double gcj_lng = z * Math.cos(theta);
|
||||
double gcj_lat = z * Math.sin(theta);
|
||||
return new double[]{gcj_lng, gcj_lat};
|
||||
}
|
||||
|
||||
/**
|
||||
* GCJ02 转百度坐标
|
||||
*
|
||||
* @param lng GCJ02 经度
|
||||
* @param lat GCJ02 纬度
|
||||
* @return 百度坐标:[经度,纬度]
|
||||
*/
|
||||
public static double[] transformGCJ02ToBD09(double lng, double lat) {
|
||||
double z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
|
||||
double theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
|
||||
double bd_lng = z * Math.cos(theta) + 0.0065;
|
||||
double bd_lat = z * Math.sin(theta) + 0.006;
|
||||
return new double[]{bd_lng, bd_lat};
|
||||
}
|
||||
|
||||
/**
|
||||
* GCJ02 转 WGS84
|
||||
*
|
||||
* @param lng 经度
|
||||
* @param lat 纬度
|
||||
* @return WGS84坐标:[经度,纬度]
|
||||
*/
|
||||
public static double[] transformGCJ02ToWGS84(double lng, double lat) {
|
||||
if (outOfChina(lng, lat)) {
|
||||
return new double[]{lng, lat};
|
||||
} else {
|
||||
double dLat = transformLat(lng - 105.0, lat - 35.0);
|
||||
double dLng = transformLng(lng - 105.0, lat - 35.0);
|
||||
double radLat = lat / 180.0 * PI;
|
||||
double magic = Math.sin(radLat);
|
||||
magic = 1 - ee * magic * magic;
|
||||
double sqrtMagic = Math.sqrt(magic);
|
||||
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * PI);
|
||||
dLng = (dLng * 180.0) / (a / sqrtMagic * Math.cos(radLat) * PI);
|
||||
double mgLat = lat + dLat;
|
||||
double mgLng = lng + dLng;
|
||||
return new double[]{lng * 2 - mgLng, lat * 2 - mgLat};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* WGS84 坐标 转 GCJ02
|
||||
*
|
||||
* @param lng 经度
|
||||
* @param lat 纬度
|
||||
* @return GCJ02 坐标:[经度,纬度]
|
||||
*/
|
||||
public static double[] transformWGS84ToGCJ02(double lng, double lat) {
|
||||
if (outOfChina(lng, lat)) {
|
||||
return new double[]{lng, lat};
|
||||
} else {
|
||||
double dLat = transformLat(lng - 105.0, lat - 35.0);
|
||||
double dLng = transformLng(lng - 105.0, lat - 35.0);
|
||||
double redLat = lat / 180.0 * PI;
|
||||
double magic = Math.sin(redLat);
|
||||
magic = 1 - ee * magic * magic;
|
||||
double sqrtMagic = Math.sqrt(magic);
|
||||
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * PI);
|
||||
dLng = (dLng * 180.0) / (a / sqrtMagic * Math.cos(redLat) * PI);
|
||||
double mgLat = lat + dLat;
|
||||
double mgLng = lng + dLng;
|
||||
return new double[]{mgLng, mgLat};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 百度坐标BD09 转 WGS84
|
||||
*
|
||||
* @param lng 经度
|
||||
* @param lat 纬度
|
||||
* @return WGS84 坐标:[经度,纬度]
|
||||
*/
|
||||
public static double[] transformBD09ToWGS84(double lng, double lat) {
|
||||
double[] lngLat = transformBD09ToGCJ02(lng, lat);
|
||||
|
||||
return transformGCJ02ToWGS84(lngLat[0], lngLat[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* WGS84 转 百度坐标BD09
|
||||
*
|
||||
* @param lng 经度
|
||||
* @param lat 纬度
|
||||
* @return BD09 坐标:[经度,纬度]
|
||||
*/
|
||||
public static double[] transformWGS84ToBD09(double lng, double lat) {
|
||||
double[] lngLat = transformWGS84ToGCJ02(lng, lat);
|
||||
|
||||
return transformGCJ02ToBD09(lngLat[0], lngLat[1]);
|
||||
}
|
||||
|
||||
private static double transformLat(double lng, double lat) {
|
||||
double ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
|
||||
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
|
||||
ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
|
||||
ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
private static double transformLng(double lng, double lat) {
|
||||
double ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
|
||||
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
|
||||
ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
|
||||
ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* 判断坐标是否不在国内
|
||||
*
|
||||
* @param lng 经度
|
||||
* @param lat 纬度
|
||||
* @return 坐标是否在国内
|
||||
*/
|
||||
public static boolean outOfChina(double lng, double lat) {
|
||||
return (lng < 72.004 || lng > 137.8347) || (lat < 0.8293 || lat > 55.8271);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
//百度地图 BD09 坐标 转 WGS84
|
||||
double[] lngLat_wgs84 = CoordinateTransformUtil.transformBD09ToWGS84(120.644049, 31.285887);
|
||||
System.out.println("lng :" + lngLat_wgs84[0] + ",lat :" + lngLat_wgs84[1]);
|
||||
|
||||
//WGS84 坐标 转 百度地图 BD09
|
||||
double[] lngLat_bd09 = CoordinateTransformUtil.transformWGS84ToBD09(lngLat_wgs84[0], lngLat_wgs84[1]);
|
||||
System.out.println("lng :" + lngLat_bd09[0] + ",lat :" + lngLat_bd09[1]);
|
||||
|
||||
//火星坐标(GCJ02) 坐标 转 WGS84
|
||||
lngLat_wgs84 = CoordinateTransformUtil.transformGCJ02ToWGS84(120.644049, 31.285887);
|
||||
System.out.println("lng :" + lngLat_wgs84[0] + ",lat :" + lngLat_wgs84[1]);
|
||||
|
||||
//WGS84 转 火星坐标(GCJ02)
|
||||
double[] lngLat_gcj02 = CoordinateTransformUtil.transformWGS84ToGCJ02(lngLat_wgs84[0], lngLat_wgs84[1]);
|
||||
System.out.println("lng :" + lngLat_gcj02[0] + ",lat :" + lngLat_gcj02[1]);
|
||||
|
||||
//百度地图 BD09 坐标 转 火星坐标(GCJ02)
|
||||
lngLat_gcj02 = CoordinateTransformUtil.transformBD09ToGCJ02(120.644049, 31.285887);
|
||||
System.out.println("lng :" + lngLat_gcj02[0] + ",lat :" + lngLat_gcj02[1]);
|
||||
|
||||
//火星坐标(GCJ02) 坐标 转 百度地图 BD09
|
||||
lngLat_bd09 = CoordinateTransformUtil.transformGCJ02ToBD09(lngLat_gcj02[0], lngLat_gcj02[1]);
|
||||
System.out.println("lng :" + lngLat_bd09[0] + ",lat :" + lngLat_bd09[1]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -100,6 +100,7 @@ public class RegionUtil {
|
||||
*/
|
||||
public static boolean isInCircle(double lng1, double lat1, double lng2, double lat2, double radius) {
|
||||
double distance = getDistance(lat1, lng1, lat2, lng2);
|
||||
System.out.println(distance);
|
||||
if (distance > radius) {
|
||||
return false;
|
||||
} else {
|
||||
@ -109,7 +110,9 @@ public class RegionUtil {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
//22.673095871193226, 113.81110145767245
|
||||
System.out.println(isInCircle(113.80851580839209, 22.67406603863524, 113.81110145767245, 22.673095871193226, 300));
|
||||
//114.02932,22.609876
|
||||
//System.out.println(isInCircle(114.03558208687168, 22.615270318249834, 114.028883, 22.607773, 1000));
|
||||
//114.029295,22.609551
|
||||
System.out.println(isInCircle(114.029295, 22.609551, 114.028883, 22.607773, 1000));
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,8 +148,8 @@ is-license=false
|
||||
#天气url
|
||||
tianqiUrl=http://v1.yiketianqi.com
|
||||
#天气appid
|
||||
tianqiAppid=41289558
|
||||
tianqiAppid=21845649
|
||||
#天气appsecret
|
||||
tianqiAppsecret=45CS7niV
|
||||
tianqiAppsecret=uX7zXSJA
|
||||
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
|
||||
spring.jackson.time-zone=GMT+8
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user