Commit 294dc31b authored by wujiang's avatar wujiang

添加坐标时间戳

parent 0fba0107
......@@ -226,6 +226,6 @@ public class Car extends BaseEntity {
@TableField(exist = false)
private String iotDeviceName;
@TableField(exist = false)
private String type = "car";
// @TableField(exist = false)
// private String type = "car";
}
package com.yeejoin.equipmanage.common.utils;
public class CoordinateUtil {
// WGS84标准参考椭球中的地球长半径(单位:米)
private static final double EARH_RADIUS_WGS84 = 6378137.0/1000;
// WGS84标准参考椭球中的地球长半径(单位:米)
private static final double EARH_RADIUS_WGS84 = 6378137.0;
public static double distance(double lat1, double lng1, double lat2, double lng2) {
double radLat1 = Math.toRadians(lat1);
......@@ -13,6 +13,6 @@ public class CoordinateUtil {
double s = 2 * Math.asin(Math.sqrt(
Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
return Math.round(s * EARH_RADIUS_WGS84);
return s * EARH_RADIUS_WGS84;
}
}
......@@ -288,7 +288,7 @@ public class CarController extends AbstractBaseController {
Equipment equipment = iEquipmentService.getById(car.getEquipmentId());
car.setName(equipment != null ? equipment.getName() : null);
}
if (ObjectUtils.isEmpty(car.getBizOrgName()) && !ObjectUtils.isEmpty(car.getBizOrgCode())) {
if (!ObjectUtils.isEmpty(car.getBizOrgCode())) {
FeignClientResult<Map<String, Object>> result = Privilege.companyClient.queryByOrgcode(car.getBizOrgCode());
System.out.println("==============================" + JSONObject.toJSONString(result.getResult()));
if (result.getResult() != null&&result.getResult().containsKey("compnay")) {
......
......@@ -11,5 +11,8 @@ public class Coordinate {
private List<Double> lnglat;
//车速
private int speed;
private double speed;
//时间
private String time;
}
......@@ -3,6 +3,7 @@ package com.yeejoin.equipmanage.listener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.ParseException;
......@@ -123,24 +124,28 @@ public class CarIotListener extends EmqxListener {
// Date endTime =UTCToCST(lastObj.getString("time"));
Date endTime = new Date(jsonObject.getLong("time"));
long takeTime = endTime.getTime() - last.getStartTime().getTime();
long takeTime = (endTime.getTime()/1000*1000) - (last.getStartTime().getTime()/1000*1000) ;
last.setEndLongitude(endLongitude);
last.setEndLatitude(endLatitude);
last.setEndTime(endTime);
last.setEndName(getAddress(endLongitude, endLatitude));
last.setEndSpeed(lastObj.getIntValue("FireCar_Speed"));
last.setTakeTime(takeTime);
double travel = 0;
double travel = 0.0;
// 获取里程
for (int i = 0; i < filterList.size() - 1; i++) {
JSONObject start = JSONObject.parseObject(JSONObject.toJSONString(filterList.get(i)));
JSONObject end = JSONObject.parseObject(JSONObject.toJSONString(filterList.get(i + 1)));
travel += CoordinateUtil.distance(start.getDoubleValue("FireCar_Longitude"),
start.getDoubleValue("FireCar_Latitude"), end.getDoubleValue("FireCar_Longitude"),
end.getDoubleValue("FireCar_Latitude"));
travel += CoordinateUtil.distance(start.getDoubleValue("FireCar_Latitude"),
start.getDoubleValue("FireCar_Longitude"), end.getDoubleValue("FireCar_Latitude"),
end.getDoubleValue("FireCar_Longitude"));
}
last.setTravel(new BigDecimal(travel/1000).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue());
try {
iWlCarMileageService.updateById(last);
} catch (Exception e) {
iWlCarMileageService.updateById(last);
}
last.setTravel(travel);
iWlCarMileageService.updateById(last);
}
}
} else if (jsonObject.containsKey("FireCar_Longitude")) {
......
......@@ -923,6 +923,7 @@ public class FireFightingSystemServiceImpl extends ServiceImpl<FireFightingSyste
if (!x.getEqtype().startsWith("4") && StringUtil.isNotEmpty(x.getAmount())) {
x.setAmount(x.getAmount().split("\\.")[0]);
}
x.setType(null);
});
return list;
}
......
package com.yeejoin.equipmanage.service.impl;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
......@@ -64,6 +66,7 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
List<Object> list = result.getResult();
List<Coordinate> coordinateList = new ArrayList<Coordinate>();
if (list != null) {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
for (Object object : list) {
JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(object));
if (jsonObject.get("FireCar_Longitude") != null && jsonObject.get("FireCar_Latitude") != null) {
......@@ -72,7 +75,12 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
lnglat.add(jsonObject.getDoubleValue("FireCar_Longitude"));
lnglat.add(jsonObject.getDoubleValue("FireCar_Latitude"));
coordinate.setLnglat(lnglat);
coordinate.setSpeed(jsonObject.getIntValue("FireCar_Speed"));
coordinate.setSpeed(jsonObject.getDoubleValue("FireCar_Speed"));
try {
coordinate.setTime(String.valueOf(format.parse(jsonObject.getString("time")).getTime()));
} catch (ParseException e) {
e.printStackTrace();
}
coordinateList.add(coordinate);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment