|
@@ -1,16 +1,18 @@
|
|
|
package com.jpsoft.bus.modules.bus.service.impl;
|
|
|
|
|
|
-import com.jpsoft.bus.modules.bus.service.GpsDataInfoService;
|
|
|
+import com.jpsoft.bus.modules.bus.dto.StationStatusDTO;
|
|
|
+import com.jpsoft.bus.modules.bus.entity.*;
|
|
|
+import com.jpsoft.bus.modules.bus.service.*;
|
|
|
+import com.jpsoft.bus.modules.common.utils.CommonUtil;
|
|
|
import com.jpsoft.gps.utils.GPSUtil;
|
|
|
import com.jpsoft.bus.config.GpsParamConfig;
|
|
|
import com.jpsoft.bus.modules.bus.dao.VehicleInfoDAO;
|
|
|
-import com.jpsoft.bus.modules.bus.entity.GpsDataInfo;
|
|
|
-import com.jpsoft.bus.modules.bus.entity.VehicleInfo;
|
|
|
-import com.jpsoft.bus.modules.bus.service.GpsService;
|
|
|
import com.jpsoft.bus.modules.common.dto.Sort;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
|
+import org.gavaghan.geodesy.Ellipsoid;
|
|
|
+import org.gavaghan.geodesy.GlobalCoordinates;
|
|
|
import org.joda.time.DateTime;
|
|
|
import org.joda.time.Minutes;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -25,20 +27,32 @@ import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@Mapper
|
|
|
-@Component(value="gpsService")
|
|
|
+@Component(value = "gpsService")
|
|
|
@Slf4j
|
|
|
public class GpsServiceImpl implements GpsService {
|
|
|
- @Resource(name="vehicleInfoDAO")
|
|
|
+ @Resource(name = "vehicleInfoDAO")
|
|
|
private VehicleInfoDAO vehicleInfoDAO;
|
|
|
|
|
|
@Autowired
|
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private VehicleInfoService vehicleInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RouteInfoService routeInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StationInfoService stationInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ShiftInfoService shiftInfoService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private GpsParamConfig gpsParamConfig;
|
|
|
|
|
|
@Autowired
|
|
|
- private ValueOperations<String,Object> valueOperations;
|
|
|
+ private ValueOperations<String, Object> valueOperations;
|
|
|
|
|
|
@Autowired
|
|
|
private GpsDataInfoService gpsDataInfoService;
|
|
@@ -48,7 +62,7 @@ public class GpsServiceImpl implements GpsService {
|
|
|
* @param vList 车辆实体列表
|
|
|
* */
|
|
|
@Override
|
|
|
- public List<Map<String,String>> queryLatestVehicleGps(List<VehicleInfo> vList) {
|
|
|
+ public List<Map<String, String>> queryLatestVehicleGps(List<VehicleInfo> vList) {
|
|
|
// TODO Auto-generated method stub
|
|
|
List<Map<String, String>> coordinateList = new ArrayList<Map<String, String>>();
|
|
|
|
|
@@ -69,13 +83,13 @@ public class GpsServiceImpl implements GpsService {
|
|
|
|
|
|
String address = "";
|
|
|
|
|
|
- if(Double.valueOf(longitude)>0 && Double.valueOf(latitude)>0) {
|
|
|
+ if (Double.valueOf(longitude) > 0 && Double.valueOf(latitude) > 0) {
|
|
|
String key = "lbs_" + longitude + "," + latitude;
|
|
|
|
|
|
address = (String) valueOperations.get(key);
|
|
|
|
|
|
if (StringUtils.isEmpty(address)) {
|
|
|
- address = GPSUtil.regeo(longitude, latitude , gpsParamConfig.getKey());
|
|
|
+ address = GPSUtil.regeo(longitude, latitude, gpsParamConfig.getKey());
|
|
|
valueOperations.set(key, address, 1, TimeUnit.DAYS);
|
|
|
}
|
|
|
|
|
@@ -93,43 +107,43 @@ public class GpsServiceImpl implements GpsService {
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- * 获取车辆轨迹
|
|
|
- * @param v 车辆实体
|
|
|
- * @param st 开始时间
|
|
|
- * @param et 结束时间
|
|
|
- * */
|
|
|
+ * 获取车辆轨迹
|
|
|
+ * @param v 车辆实体
|
|
|
+ * @param st 开始时间
|
|
|
+ * @param et 结束时间
|
|
|
+ * */
|
|
|
@Override
|
|
|
- public List<Map<String,String>> getVehicleGpsList(VehicleInfo v,Date st,Date et) {
|
|
|
+ public List<Map<String, String>> getVehicleGpsList(VehicleInfo v, Date st, Date et) {
|
|
|
// TODO Auto-generated method stub
|
|
|
//开始时间不得大于结束时间,并且查询天数不得大于7天。
|
|
|
- List<Map<String,String>> gpsList = new ArrayList<Map<String,String>>();
|
|
|
+ List<Map<String, String>> gpsList = new ArrayList<Map<String, String>>();
|
|
|
long day1 = st.getTime();
|
|
|
long day2 = et.getTime();
|
|
|
|
|
|
- if(day1>day2){
|
|
|
+ if (day1 > day2) {
|
|
|
log.warn("查询车辆轨迹时开始时间大于结束时间");
|
|
|
return null;
|
|
|
}
|
|
|
- if(day2-day1>=7*1000*3600*24){
|
|
|
+ if (day2 - day1 >= 7 * 1000 * 3600 * 24) {
|
|
|
log.warn("查询车辆轨迹时天数超过7天");
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- Map<String,Object> searchParams = new HashMap<>();
|
|
|
+ Map<String, Object> searchParams = new HashMap<>();
|
|
|
searchParams.put("deviceNo", v.getGpsDeviceNo());
|
|
|
searchParams.put("startTime", st);
|
|
|
searchParams.put("endTime", et);
|
|
|
|
|
|
List<Sort> sortList = new ArrayList<>();
|
|
|
- sortList.add(new Sort("create_time","asc"));
|
|
|
+ sortList.add(new Sort("create_time", "asc"));
|
|
|
|
|
|
- List<GpsDataInfo> dataList = gpsDataInfoService.pageSearch(searchParams,1,1000,false,sortList);
|
|
|
+ List<GpsDataInfo> dataList = gpsDataInfoService.pageSearch(searchParams, 1, 1000, false, sortList);
|
|
|
|
|
|
for (GpsDataInfo data : dataList) {
|
|
|
- Map<String,String> map=new HashMap<String,String>();
|
|
|
+ Map<String, String> map = new HashMap<String, String>();
|
|
|
|
|
|
- map.put("lat",data.getLatitude());//纬度
|
|
|
- map.put("lng",data.getLongitude());//经度
|
|
|
+ map.put("lat", data.getLatitude());//纬度
|
|
|
+ map.put("lng", data.getLongitude());//经度
|
|
|
|
|
|
gpsList.add(map);
|
|
|
}
|
|
@@ -142,40 +156,39 @@ public class GpsServiceImpl implements GpsService {
|
|
|
* @param v 车辆实体
|
|
|
* */
|
|
|
@Override
|
|
|
- public boolean isVehicleOnline(VehicleInfo v){
|
|
|
+ public boolean isVehicleOnline(VehicleInfo v) {
|
|
|
//最后一次上传经纬度时间是否超过5分钟
|
|
|
GpsDataInfo gpsDataInfo = gpsDataInfoService.findLast(v.getGpsDeviceNo());
|
|
|
|
|
|
- if(gpsDataInfo!=null) {
|
|
|
+ if (gpsDataInfo != null) {
|
|
|
DateTime lastTime = new DateTime(gpsDataInfo.getCreateTime());
|
|
|
|
|
|
long minutes = Minutes.minutesBetween(lastTime, DateTime.now()).getMinutes();
|
|
|
|
|
|
return minutes < 5;
|
|
|
- }
|
|
|
- else{
|
|
|
+ } else {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Map<String,String>> queryVehicleOnlineInfo(List<VehicleInfo> vList) {
|
|
|
+ public List<Map<String, String>> queryVehicleOnlineInfo(List<VehicleInfo> vList) {
|
|
|
// TODO Auto-generated method stub
|
|
|
//单次查询,车牌号查询
|
|
|
- List<Map<String,String>> onlineList = new ArrayList<>();
|
|
|
+ List<Map<String, String>> onlineList = new ArrayList<>();
|
|
|
|
|
|
- for(VehicleInfo v : vList){
|
|
|
- Map<String,String> olmap = new HashMap<String,String>();
|
|
|
+ for (VehicleInfo v : vList) {
|
|
|
+ Map<String, String> olmap = new HashMap<String, String>();
|
|
|
|
|
|
boolean online = isVehicleOnline(v);
|
|
|
|
|
|
- if(online){
|
|
|
- olmap.put("online","1");
|
|
|
- }else{
|
|
|
- olmap.put("online","0");
|
|
|
+ if (online) {
|
|
|
+ olmap.put("online", "1");
|
|
|
+ } else {
|
|
|
+ olmap.put("online", "0");
|
|
|
}
|
|
|
|
|
|
- olmap.put("licensePlateNumber",v.getLicensePlateNumber());//车牌号
|
|
|
+ olmap.put("licensePlateNumber", v.getLicensePlateNumber());//车牌号
|
|
|
onlineList.add(olmap);
|
|
|
}
|
|
|
|
|
@@ -187,33 +200,129 @@ public class GpsServiceImpl implements GpsService {
|
|
|
* @param vList 车辆实体列表
|
|
|
* */
|
|
|
@Override
|
|
|
- public List<Map<String,String>> queryVehicleAccInfo(List<VehicleInfo> vList) {
|
|
|
+ public List<Map<String, String>> queryVehicleAccInfo(List<VehicleInfo> vList) {
|
|
|
// TODO Auto-generated method stub
|
|
|
- List<Map<String,String>> accList = new ArrayList<Map<String,String>>();
|
|
|
+ List<Map<String, String>> accList = new ArrayList<Map<String, String>>();
|
|
|
|
|
|
- for(VehicleInfo v : vList){
|
|
|
- Map<String,String> olmap = new HashMap<String,String>();
|
|
|
+ for (VehicleInfo v : vList) {
|
|
|
+ Map<String, String> olmap = new HashMap<String, String>();
|
|
|
|
|
|
boolean online = isVehicleOnline(v);
|
|
|
|
|
|
- if(online){
|
|
|
- olmap.put("acc","1");
|
|
|
- }else{
|
|
|
- olmap.put("acc","0");
|
|
|
+ if (online) {
|
|
|
+ olmap.put("acc", "1");
|
|
|
+ } else {
|
|
|
+ olmap.put("acc", "0");
|
|
|
}
|
|
|
|
|
|
- olmap.put("licensePlateNumber",v.getLicensePlateNumber());//车牌号
|
|
|
+ olmap.put("licensePlateNumber", v.getLicensePlateNumber());//车牌号
|
|
|
accList.add(olmap);
|
|
|
}
|
|
|
|
|
|
return accList;
|
|
|
}
|
|
|
|
|
|
- public String encode(String text){
|
|
|
- try {
|
|
|
- text=URLEncoder.encode(text,"UTF-8");
|
|
|
+ @Override
|
|
|
+ public StationStatusDTO queryStation(String id) throws Exception {
|
|
|
+
|
|
|
+ StationStatusDTO stationStatusDTO = new StationStatusDTO();
|
|
|
+ VehicleInfo vehicleInfo = vehicleInfoService.get(id);
|
|
|
+ if (vehicleInfo == null) {
|
|
|
+ throw new Exception("车辆不存在");
|
|
|
}
|
|
|
- catch(NumberFormatException | UnsupportedEncodingException e) {
|
|
|
+ List<ShiftInfo> shiftInfoList = shiftInfoService.findByVehicleIdAndStatus(id, "1");
|
|
|
+ if (shiftInfoList.size() == 0) {
|
|
|
+ throw new Exception("此车辆无正在运行的班次");
|
|
|
+ }
|
|
|
+ ShiftInfo shiftInfo = shiftInfoList.get(0);
|
|
|
+
|
|
|
+ RouteInfo routeInfo = routeInfoService.get(shiftInfo.getRouteId());
|
|
|
+
|
|
|
+ List<StationInfo> stationInfoList = stationInfoService.findByRouteId(routeInfo.getId());
|
|
|
+
|
|
|
+ //线路中的当前站点
|
|
|
+ StationInfo currentStation = stationInfoService.get(shiftInfo.getCurrentStationId());
|
|
|
+
|
|
|
+ //下一站站点
|
|
|
+ StationInfo nextStation = null;
|
|
|
+
|
|
|
+ Integer index = stationInfoList.indexOf(currentStation);
|
|
|
+
|
|
|
+ Integer nextIndex = index+1;
|
|
|
+ if (!stationInfoList.get(0).getId().equals(shiftInfo.getStartStationId())){
|
|
|
+ nextIndex = index-1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (nextIndex > stationInfoList.size()-1 || nextIndex<0){
|
|
|
+ nextStation = currentStation;
|
|
|
+ }else {
|
|
|
+ nextStation = stationInfoList.get(nextIndex);
|
|
|
+ }
|
|
|
+
|
|
|
+ //车辆离当前站点的距离
|
|
|
+ GlobalCoordinates source = new GlobalCoordinates(Double.valueOf(vehicleInfo.getLatitude()), Double.valueOf(vehicleInfo.getLongitude()));
|
|
|
+ GlobalCoordinates target = new GlobalCoordinates(Double.valueOf(currentStation.getLatitude()), Double.valueOf(currentStation.getLongitude()));
|
|
|
+
|
|
|
+ double meter1 = CommonUtil.getDistanceMeter(source, target, Ellipsoid.Sphere);
|
|
|
+ if (meter1 <= Double.valueOf(50)){
|
|
|
+ stationStatusDTO.setNowStationStatus("1");
|
|
|
+ }else {
|
|
|
+ stationStatusDTO.setNowStationStatus("2");
|
|
|
+ }
|
|
|
+
|
|
|
+ stationStatusDTO.setNowStationId(currentStation.getId());
|
|
|
+ stationStatusDTO.setNowStationName(currentStation.getName());
|
|
|
+ stationStatusDTO.setNextStationId(nextStation.getId());
|
|
|
+ stationStatusDTO.setNextStationName(nextStation.getName());
|
|
|
+
|
|
|
+ if (nextStation.equals(currentStation)){
|
|
|
+ stationStatusDTO.setNextStationStatus(stationStatusDTO.getNowStationStatus());
|
|
|
+ }else {
|
|
|
+ stationStatusDTO.setNextStationStatus("3");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return stationStatusDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getLatelyStation(String id) throws Exception {
|
|
|
+ VehicleInfo vehicleInfo = vehicleInfoService.get(id);
|
|
|
+ if (vehicleInfo == null) {
|
|
|
+ throw new Exception("车辆不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ String currentStationId = null;
|
|
|
+ List<ShiftInfo> shiftInfoList = shiftInfoService.findByVehicleIdAndStatus(id, "1");
|
|
|
+ if (shiftInfoList.size() > 0) {
|
|
|
+
|
|
|
+
|
|
|
+ ShiftInfo shiftInfo = shiftInfoList.get(0);
|
|
|
+
|
|
|
+ RouteInfo routeInfo = routeInfoService.get(shiftInfo.getRouteId());
|
|
|
+
|
|
|
+ List<StationInfo> stationInfoList = stationInfoService.findByRouteId(routeInfo.getId());
|
|
|
+ currentStationId = shiftInfo.getStartStationId();
|
|
|
+ if (stationInfoList.size() > 0) {
|
|
|
+ for (StationInfo stationInfo : stationInfoList) {
|
|
|
+ GlobalCoordinates source = new GlobalCoordinates(Double.valueOf(vehicleInfo.getLatitude()), Double.valueOf(vehicleInfo.getLongitude()));
|
|
|
+ GlobalCoordinates target = new GlobalCoordinates(Double.valueOf(stationInfo.getLatitude()), Double.valueOf(stationInfo.getLongitude()));
|
|
|
+
|
|
|
+ double meter1 = CommonUtil.getDistanceMeter(source, target, Ellipsoid.Sphere);
|
|
|
+ if (meter1 <= Double.valueOf(50)) {
|
|
|
+ currentStationId = stationInfo.getId();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return currentStationId;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String encode(String text) {
|
|
|
+ try {
|
|
|
+ text = URLEncoder.encode(text, "UTF-8");
|
|
|
+ } catch (NumberFormatException | UnsupportedEncodingException e) {
|
|
|
System.out.println(e);
|
|
|
}
|
|
|
|
|
@@ -226,11 +335,11 @@ public class GpsServiceImpl implements GpsService {
|
|
|
System.out.println(Integer.toBinaryString(s1));
|
|
|
|
|
|
int pos = 2;
|
|
|
- int value = 1 << (pos-1);
|
|
|
+ int value = 1 << (pos - 1);
|
|
|
|
|
|
System.out.println(value);
|
|
|
|
|
|
- if((s1 & value)==value){
|
|
|
+ if ((s1 & value) == value) {
|
|
|
System.out.println("ACC开启");
|
|
|
}
|
|
|
}
|