@Override public List<TrackGps> viewTrack(String vehicleId, String startTime, String endTime) { if (vehicleId == null || vehicleId.trim().equals("") || startTime == null || endTime == null) { return null; } try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.parse(startTime.trim()); sdf.parse(endTime.trim()); } catch (ParseException e) { throw new ParamValidationServiceException( "The param [startTime,endTime] is error. [startDate,endDate] need to matche 'yyyy-MM-dd HH:mm:ss' ."); } List<GpsHistory> gpsList = dao.getGpsListByHcVehicleId( vehicleId, DateUtil.string2DateTime(startTime), DateUtil.string2DateTime(endTime)); this.calculate(RawDataProtocol.TRUCK_HS, gpsList); List<TrackGps> trackList = new ArrayList<TrackGps>(); for (int i = 0; i < gpsList.size(); i++) { GpsHistory gps = gpsList.get(i); if (!gps.getEnableGps() || gps.getLatitude() < 0.1 || gps.getLongitude() < 0.1) { continue; } TrackGps trackGps = convertEntityGpsToTrackGps(gps); if (trackGps != null) { trackList.add(trackGps); } } return trackList; }
private TrackGps convertEntityGpsToTrackGps(GpsHistory gps) { if (gps == null) { return null; } TrackGps track = new TrackGps(); track.setId(gps.getId().toString()); // gps id track.setTime( gps.getTime() != null ? DateUtil.dateTime2String(new Date(gps.getTime())) : null); // track.setVehicleId(gps.getHcVehicleId()); // if (gps.getCardNo() != null) gps.setCardNo(gps.getCardNo().replaceAll("\\u0000", "")); track.setCardNo(gps.getCardNo()); // track.setCardBalance(null); // track.setPlateNo(gps.getPlateNo()); // track.setSpeed(gps.getSpeed()); // track.setMileageDayCumulative(gps.getCurrentMileageCumulative()); // 当日累积里程 track.setOilDayCumulative(gps.getCurrentOilCumulative()); // 当日累积油耗 track.setAltitude(gps.getAltitude()); // if (gps.getCardStatus() != null) { switch (gps.getCardStatus()) { case OFF_LINE: track.setCardStatus(CardStatus.OFFLINE); break; case ON_LINE: track.setCardStatus(CardStatus.ONLINE); break; default: track.setCardStatus(null); } } if (gps.getAccStatus() != null) { switch (gps.getAccStatus()) { case IGNITION: track.setAccStatus(AccStatus.IGNITION); break; case FLAMEOUT: track.setAccStatus(AccStatus.STALL); break; default: track.setAccStatus(null); } } track.setLongitude(gps.getLongitude()); // track.setLatitude(gps.getLatitude()); // if (gps.getVehicleStatus() != null) { track.setVehicleStatus(VehicleStatus.valueOf(gps.getVehicleStatus().name())); } else if (gps.getAccStatus() != null) { switch (gps.getAccStatus()) { case IGNITION: track.setVehicleStatus(VehicleStatus.IGNITION); break; case FLAMEOUT: track.setVehicleStatus(VehicleStatus.STALL); break; default: track.setAccStatus(null); } } track.setDeviceId(gps.getDeviceId()); // HSBOX 编号 if (gps.getEnableGps() == null) { track.setTag(gps.getEnableGps() ? GpsTag.VALID : GpsTag.INVALID); // gps 是否有效A有效V无效 } track.setSatelliteNum(gps.getSatelliteNum()); // 卫星数量 track.setOilCumulative(gps.getOilCumulative()); track.setMileageCumulative( gps.getMileageCumulative() != null ? gps.getMileageCumulative() / 1000D : null); return track; }