Commit 10c1aff07aeb6191c0728b44a1369a6da6d99ac0
1 parent
686b7f69
1./external相关接口
Showing
1 changed file
with
141 additions
and
132 deletions
src/main/java/com/bsth/server_rs/gps/GpsRestService.java
| 1 | -package com.bsth.server_rs.gps; | ||
| 2 | - | ||
| 3 | -import java.text.ParseException; | ||
| 4 | -import java.util.ArrayList; | ||
| 5 | -import java.util.Collection; | ||
| 6 | -import java.util.Date; | ||
| 7 | -import java.util.HashMap; | ||
| 8 | -import java.util.List; | ||
| 9 | -import java.util.Map; | ||
| 10 | -import java.util.Set; | ||
| 11 | - | ||
| 12 | -import javax.ws.rs.GET; | ||
| 13 | -import javax.ws.rs.Path; | ||
| 14 | -import javax.ws.rs.PathParam; | ||
| 15 | -import javax.ws.rs.Produces; | ||
| 16 | -import javax.ws.rs.core.MediaType; | ||
| 17 | - | ||
| 18 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 19 | -import org.springframework.stereotype.Component; | ||
| 20 | - | ||
| 21 | -import com.bsth.server_rs.gps.buffer.BasicDataBuffer; | ||
| 22 | -import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer; | ||
| 23 | -import com.bsth.server_rs.gps.dao.HistoryGpsDao; | ||
| 24 | -import com.bsth.server_rs.gps.entity.GpsEntity; | ||
| 25 | -import com.bsth.server_rs.gps.entity.LineInfo; | ||
| 26 | -import com.bsth.server_rs.gps.entity.StopInfo; | ||
| 27 | -import com.bsth.util.ThreadLocalDateUtil; | ||
| 28 | - | ||
| 29 | -/** | ||
| 30 | - * Created by panzhao on 2017/3/28. | ||
| 31 | - */ | ||
| 32 | -@Component | ||
| 33 | -@Path("/gps") | ||
| 34 | -@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) | ||
| 35 | -public class GpsRestService { | ||
| 36 | - | ||
| 37 | - @Autowired | ||
| 38 | - HistoryGpsDao historyGpsDao; | ||
| 39 | - | ||
| 40 | - @GET | ||
| 41 | - @Path("/{deviceId}") | ||
| 42 | - public GpsEntity findOne(@PathParam("deviceId") String deviceId) { | ||
| 43 | - return GpsRealDataBuffer.get(deviceId); | ||
| 44 | - } | ||
| 45 | - | ||
| 46 | - @GET | ||
| 47 | - @Path("/all") | ||
| 48 | - public Collection<GpsEntity> findAll() { | ||
| 49 | - return GpsRealDataBuffer.all(); | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - @GET | ||
| 53 | - @Path("/history/{nbbm}/{st}/{et}") | ||
| 54 | - public Collection<Map<String, Object>> history(@PathParam("nbbm") String nbbm | ||
| 55 | - , @PathParam("st") String st | ||
| 56 | - , @PathParam("et") String et) { | ||
| 57 | - return historyGpsDao.query(nbbm, Long.parseLong(st), Long.parseLong(et)); | ||
| 58 | - } | ||
| 59 | - | ||
| 60 | - @GET | ||
| 61 | - @Path("/gpsReport") | ||
| 62 | - public List<Map<String, Object>> gpsReport() { | ||
| 63 | - List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); | ||
| 64 | - Collection<GpsEntity> gpss = GpsRealDataBuffer.all(); | ||
| 65 | - Set<Integer> lines = BasicDataBuffer.getAllLine(); | ||
| 66 | - for (GpsEntity gps : gpss) { | ||
| 67 | - String device = gps.getDeviceId(); | ||
| 68 | - if (lines.contains(Integer.parseInt(gps.getLineId()))) { | ||
| 69 | - Map<String, Object> map = new HashMap<String, Object>(); | ||
| 70 | - map.put("vehicleNumberPlate", BasicDataBuffer.getPlateByDevice(device)); | ||
| 71 | - try { | ||
| 72 | - map.put("gpsDateTime", ThreadLocalDateUtil.formatDate(new Date(gps.getTimestamp()))); | ||
| 73 | - } catch (ParseException e) { | ||
| 74 | - // TODO Auto-generated catch block | ||
| 75 | - e.printStackTrace(); | ||
| 76 | - } | ||
| 77 | - map.put("gpsLongitude", gps.getLon()); | ||
| 78 | - map.put("gpsLatitude", gps.getLat()); | ||
| 79 | - map.put("gpsDirection", gps.getDirection()); | ||
| 80 | - map.put("gpsSpeed", gps.getSpeed()); | ||
| 81 | - map.put("gpsIsValid", gps.getValid()); | ||
| 82 | - map.put("lineId", gps.getLineId()); | ||
| 83 | - map.put("lineVersion", 0); | ||
| 84 | - map.put("upDownMark", gps.getUpDown()); | ||
| 85 | - map.put("stationOrder", getCurrStop(gps)); | ||
| 86 | - map.put("inOutStationState", gps.getInOrOutStation()); | ||
| 87 | - map.put("operationalState", gps.getState()); | ||
| 88 | - | ||
| 89 | - result.add(map); | ||
| 90 | - } | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | - return result; | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | - private static int getCurrStop(GpsEntity gps) { | ||
| 97 | - int res = 0; | ||
| 98 | - | ||
| 99 | - LineInfo line = BasicDataBuffer.getLineById(Integer.parseInt(gps.getLineId())); | ||
| 100 | - if (line != null) { | ||
| 101 | - List<StopInfo> upStops = new ArrayList<>(line.getStopsUp()), downStops = new ArrayList<>(line.getStopsDown()); | ||
| 102 | - int updown = gps.getUpDown(); | ||
| 103 | - // 环线、内外换的线路 | ||
| 104 | - boolean isRing = line.getLinePlayType() == 1; | ||
| 105 | - if (isRing) { | ||
| 106 | - updown = 0; | ||
| 107 | - downStops.clear(); | ||
| 108 | - } | ||
| 109 | - List<StopInfo> stops = new ArrayList<StopInfo>(); | ||
| 110 | - stops.addAll(upStops); | ||
| 111 | - stops.addAll(downStops); | ||
| 112 | - | ||
| 113 | - int idx = 1; | ||
| 114 | - if (updown == 0) { | ||
| 115 | - for (StopInfo stop : upStops) { | ||
| 116 | - if (gps.getStopNo().trim().equals(stop.getStationCod())) break; | ||
| 117 | - idx++; | ||
| 118 | - } | ||
| 119 | - } else { | ||
| 120 | - for (StopInfo stop : downStops) { | ||
| 121 | - if (gps.getStopNo().trim().equals(stop.getStationCod())) break; | ||
| 122 | - idx++; | ||
| 123 | - } | ||
| 124 | - } | ||
| 125 | - if (idx <= stops.size()) { | ||
| 126 | - res = idx; | ||
| 127 | - } | ||
| 128 | - } | ||
| 129 | - | ||
| 130 | - return res; | ||
| 131 | - } | ||
| 132 | -} | 1 | +package com.bsth.server_rs.gps; |
| 2 | + | ||
| 3 | +import java.text.ParseException; | ||
| 4 | +import java.util.ArrayList; | ||
| 5 | +import java.util.Collection; | ||
| 6 | +import java.util.Date; | ||
| 7 | +import java.util.HashMap; | ||
| 8 | +import java.util.List; | ||
| 9 | +import java.util.Map; | ||
| 10 | +import java.util.Set; | ||
| 11 | + | ||
| 12 | +import javax.ws.rs.GET; | ||
| 13 | +import javax.ws.rs.Path; | ||
| 14 | +import javax.ws.rs.PathParam; | ||
| 15 | +import javax.ws.rs.Produces; | ||
| 16 | +import javax.ws.rs.core.MediaType; | ||
| 17 | + | ||
| 18 | +import com.bsth.server_rs.gps.entity.HistoryArrivalEntity; | ||
| 19 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 20 | +import org.springframework.stereotype.Component; | ||
| 21 | + | ||
| 22 | +import com.bsth.server_rs.gps.buffer.BasicDataBuffer; | ||
| 23 | +import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer; | ||
| 24 | +import com.bsth.server_rs.gps.dao.HistoryGpsDao; | ||
| 25 | +import com.bsth.server_rs.gps.entity.GpsEntity; | ||
| 26 | +import com.bsth.server_rs.gps.entity.LineInfo; | ||
| 27 | +import com.bsth.server_rs.gps.entity.StopInfo; | ||
| 28 | +import com.bsth.util.ThreadLocalDateUtil; | ||
| 29 | + | ||
| 30 | +/** | ||
| 31 | + * Created by panzhao on 2017/3/28. | ||
| 32 | + */ | ||
| 33 | +@Component | ||
| 34 | +@Path("/gps") | ||
| 35 | +@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) | ||
| 36 | +public class GpsRestService { | ||
| 37 | + | ||
| 38 | + @Autowired | ||
| 39 | + HistoryGpsDao historyGpsDao; | ||
| 40 | + | ||
| 41 | + @GET | ||
| 42 | + @Path("/{deviceId}") | ||
| 43 | + public GpsEntity findOne(@PathParam("deviceId") String deviceId) { | ||
| 44 | + return GpsRealDataBuffer.get(deviceId); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @GET | ||
| 48 | + @Path("/all") | ||
| 49 | + public Collection<GpsEntity> findAll() { | ||
| 50 | + return GpsRealDataBuffer.all(); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + @GET | ||
| 54 | + @Path("/history/{nbbm}/{st}/{et}") | ||
| 55 | + public Collection<Map<String, Object>> history(@PathParam("nbbm") String nbbm | ||
| 56 | + , @PathParam("st") String st | ||
| 57 | + , @PathParam("et") String et) { | ||
| 58 | + return historyGpsDao.query(nbbm, Long.parseLong(st), Long.parseLong(et)); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + @GET | ||
| 62 | + @Path("/history-arrival/{line}/{st}/{et}") | ||
| 63 | + public List<HistoryArrivalEntity> historyArrival(@PathParam("line") String line | ||
| 64 | + , @PathParam("st") String st | ||
| 65 | + , @PathParam("et") String et) { | ||
| 66 | + return historyGpsDao.queryArrival(line, Long.parseLong(st), Long.parseLong(et)); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + @GET | ||
| 70 | + @Path("/gpsReport") | ||
| 71 | + public List<Map<String, Object>> gpsReport() { | ||
| 72 | + List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); | ||
| 73 | + Collection<GpsEntity> gpss = GpsRealDataBuffer.all(); | ||
| 74 | + Set<Integer> lines = BasicDataBuffer.getAllLine(); | ||
| 75 | + for (GpsEntity gps : gpss) { | ||
| 76 | + String device = gps.getDeviceId(); | ||
| 77 | + if (lines.contains(Integer.parseInt(gps.getLineId()))) { | ||
| 78 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
| 79 | + map.put("vehicleNumberPlate", BasicDataBuffer.getPlateByDevice(device)); | ||
| 80 | + try { | ||
| 81 | + map.put("gpsDateTime", ThreadLocalDateUtil.formatDate(new Date(gps.getTimestamp()))); | ||
| 82 | + } catch (ParseException e) { | ||
| 83 | + // TODO Auto-generated catch block | ||
| 84 | + e.printStackTrace(); | ||
| 85 | + } | ||
| 86 | + map.put("gpsLongitude", gps.getLon()); | ||
| 87 | + map.put("gpsLatitude", gps.getLat()); | ||
| 88 | + map.put("gpsDirection", gps.getDirection()); | ||
| 89 | + map.put("gpsSpeed", gps.getSpeed()); | ||
| 90 | + map.put("gpsIsValid", gps.getValid()); | ||
| 91 | + map.put("lineId", gps.getLineId()); | ||
| 92 | + map.put("lineVersion", 0); | ||
| 93 | + map.put("upDownMark", gps.getUpDown()); | ||
| 94 | + map.put("stationOrder", getCurrStop(gps)); | ||
| 95 | + map.put("inOutStationState", gps.getInOrOutStation()); | ||
| 96 | + map.put("operationalState", gps.getState()); | ||
| 97 | + | ||
| 98 | + result.add(map); | ||
| 99 | + } | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + return result; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + private static int getCurrStop(GpsEntity gps) { | ||
| 106 | + int res = 0; | ||
| 107 | + | ||
| 108 | + LineInfo line = BasicDataBuffer.getLineById(Integer.parseInt(gps.getLineId())); | ||
| 109 | + if (line != null) { | ||
| 110 | + List<StopInfo> upStops = new ArrayList<>(line.getStopsUp()), downStops = new ArrayList<>(line.getStopsDown()); | ||
| 111 | + int updown = gps.getUpDown(); | ||
| 112 | + // 环线、内外换的线路 | ||
| 113 | + boolean isRing = line.getLinePlayType() == 1; | ||
| 114 | + if (isRing) { | ||
| 115 | + updown = 0; | ||
| 116 | + downStops.clear(); | ||
| 117 | + } | ||
| 118 | + List<StopInfo> stops = new ArrayList<StopInfo>(); | ||
| 119 | + stops.addAll(upStops); | ||
| 120 | + stops.addAll(downStops); | ||
| 121 | + | ||
| 122 | + int idx = 1; | ||
| 123 | + if (updown == 0) { | ||
| 124 | + for (StopInfo stop : upStops) { | ||
| 125 | + if (gps.getStopNo().trim().equals(stop.getStationCod())) break; | ||
| 126 | + idx++; | ||
| 127 | + } | ||
| 128 | + } else { | ||
| 129 | + for (StopInfo stop : downStops) { | ||
| 130 | + if (gps.getStopNo().trim().equals(stop.getStationCod())) break; | ||
| 131 | + idx++; | ||
| 132 | + } | ||
| 133 | + } | ||
| 134 | + if (idx <= stops.size()) { | ||
| 135 | + res = idx; | ||
| 136 | + } | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + return res; | ||
| 140 | + } | ||
| 141 | +} |