Commit c39137e3322dc1ec229a84ab7790dbd1677d3370

Authored by 王通
1 parent 65970990

1./external相关接口

src/main/java/com/bsth/entity/Resource.java 0 → 100644
  1 +package com.bsth.entity;
  2 +
  3 +import javax.persistence.*;
  4 +
  5 +/**
  6 + * @Author Hill
  7 + */
  8 +@Entity
  9 +@Table(name = "interface_resources")
  10 +public class Resource {
  11 +
  12 + @Id
  13 + @GeneratedValue
  14 + private Integer id;
  15 +
  16 + private String name;
  17 +
  18 + private String url;
  19 +
  20 + private String remark;
  21 +
  22 + public Integer getId() {
  23 + return id;
  24 + }
  25 +
  26 + public void setId(Integer id) {
  27 + this.id = id;
  28 + }
  29 +
  30 + public String getName() {
  31 + return name;
  32 + }
  33 +
  34 + public void setName(String name) {
  35 + this.name = name;
  36 + }
  37 +
  38 + public String getUrl() {
  39 + return url;
  40 + }
  41 +
  42 + public void setUrl(String url) {
  43 + this.url = url;
  44 + }
  45 +
  46 + public String getRemark() {
  47 + return remark;
  48 + }
  49 +
  50 + public void setRemark(String remark) {
  51 + this.remark = remark;
  52 + }
  53 +}
0 \ No newline at end of file 54 \ No newline at end of file
src/main/java/com/bsth/server_rs/external/ExternalService.java 0 → 100644
  1 +package com.bsth.server_rs.external;
  2 +
  3 +import com.bsth.redis.ScheduleRedisService;
  4 +import com.bsth.repository.ScheduleRealInfoRepository;
  5 +import com.bsth.server_rs.AuthorizeInterceptor_IN;
  6 +import com.bsth.server_rs.base_info.car.Car;
  7 +import com.bsth.server_rs.base_info.car.buffer.CarBufferData;
  8 +import com.bsth.server_rs.base_info.line.Line;
  9 +import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
  10 +import com.bsth.server_rs.base_info.section.buffer.LD_SectionBufferData;
  11 +import com.bsth.server_rs.base_info.section.entity.LD_SectionRoute;
  12 +import com.bsth.server_rs.base_info.station.buffer.StationBufferData;
  13 +import com.bsth.server_rs.base_info.station.entity.StationRotue;
  14 +import com.bsth.server_rs.gps.buffer.BasicDataBuffer;
  15 +import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer;
  16 +import com.bsth.server_rs.gps.dao.HistoryGpsDao;
  17 +import com.bsth.server_rs.gps.entity.GpsEntity;
  18 +import org.apache.commons.lang3.StringUtils;
  19 +import org.slf4j.Logger;
  20 +import org.slf4j.LoggerFactory;
  21 +import org.springframework.beans.factory.annotation.Autowired;
  22 +import org.springframework.stereotype.Component;
  23 +
  24 +import javax.servlet.http.HttpServletRequest;
  25 +import javax.ws.rs.*;
  26 +import javax.ws.rs.core.Context;
  27 +import javax.ws.rs.core.MediaType;
  28 +import java.util.*;
  29 +
  30 +/**
  31 + * @author Hill
  32 + * @date 2021-09
  33 + */
  34 +@Component
  35 +@Path("/external")
  36 +@Produces({MediaType.APPLICATION_JSON})
  37 +public class ExternalService {
  38 +
  39 + private final static Logger log = LoggerFactory.getLogger(ExternalService.class);
  40 +
  41 + @Autowired
  42 + private LD_SectionBufferData ldSectionBufferData;
  43 +
  44 + @Autowired
  45 + private HistoryGpsDao historyGpsDao;
  46 +
  47 + @Autowired
  48 + private AuthorizeInterceptor_IN authorizeInterceptorIn;
  49 +
  50 + @Autowired
  51 + private ScheduleRealInfoRepository scheduleRealInfoRepository;
  52 +
  53 + @Autowired
  54 + private ScheduleRedisService scheduleRedisService;
  55 +
  56 + @GET
  57 + @Path("/line")
  58 + public List<Map<String, Object>> findAllLine(@Context HttpServletRequest request) {
  59 + List<Map<String, Object>> result = new ArrayList<>();
  60 + String password = request.getParameter("password");
  61 + log.error("log password: {}", password);
  62 + System.out.println("stdio password: " + password);
  63 + Set<String> limitLines = authorizeInterceptorIn.getLimitLines(password);
  64 + if (limitLines == null || limitLines.isEmpty()) {
  65 + return result;
  66 + }
  67 + for (Line line : LineBufferData.findAll()) {
  68 + String lineCode = line.getLineCode();
  69 + if (limitLines.contains(lineCode) || limitLines.contains("ALL")) {
  70 + Map<String, Object> lineMap = new HashMap<>();
  71 + Collection<LD_SectionRoute> sectionRoutes = ldSectionBufferData.findByLineCode(lineCode).get(String.format("%s_0", lineCode));
  72 + StringBuilder sb = new StringBuilder("");
  73 + if (sectionRoutes != null) {
  74 + for (LD_SectionRoute sectionRoute : sectionRoutes) {
  75 + sb.append(sectionRoute.getSection().getGsectionVector().replace("LINESTRING(", "").replace(")", "")).append(",");
  76 + }
  77 + sb.deleteCharAt(sb.length() - 1);
  78 + }
  79 + lineMap.put("company", BasicDataBuffer.getBusinessByCode(line.getCompany()));
  80 + lineMap.put("branch", BasicDataBuffer.getBusinessByCode(String.format("%s_%s", line.getCompany(), line.getBrancheCompany())));
  81 + lineMap.put("lineName", line.getName());
  82 + lineMap.put("lineCode", line.getShanghaiLinecode());
  83 + lineMap.put("lineCodeExternal", lineCode);
  84 + lineMap.put("startStation", line.getStartStationName());
  85 + lineMap.put("endStation", line.getEndStationName());
  86 + lineMap.put("lineLength", line.getTotalMileage());
  87 + lineMap.put("upSEtime", String.format("%s-%s", line.getStartStationFirstTime(), line.getStartStationEndTime()));
  88 + lineMap.put("upLinelonlat", sb.toString());
  89 + lineMap.put("downSEtime", String.format("%s-%s", line.getEndStationFirstTime(), line.getEndStationEndTime()));
  90 + lineMap.put("downLinelonlat", null);
  91 +
  92 + result.add(lineMap);
  93 + }
  94 + }
  95 +
  96 + return result;
  97 + }
  98 +
  99 + @GET
  100 + @Path("/station")
  101 + public List<Map<String, Object>> findAllStation(@Context HttpServletRequest request) {
  102 + List<Map<String, Object>> result = new ArrayList<>();
  103 + String password = request.getParameter("password");
  104 + log.error("log password: {}", password);
  105 + System.out.println("stdio password: " + password);
  106 + Set<String> limitLines = new HashSet<>(authorizeInterceptorIn.getLimitLines(password));
  107 + if (limitLines == null || limitLines.isEmpty()) {
  108 + return result;
  109 + }
  110 + if (limitLines.contains("ALL")) {
  111 + limitLines.clear();
  112 + for (Line line : LineBufferData.findAll()) {
  113 + limitLines.add(line.getLineCode());
  114 + }
  115 + }
  116 + for (String lineCode : limitLines) {
  117 + if (StringUtils.isNotEmpty(lineCode)) {
  118 + Map<String, Object> lineMap = new HashMap<>();
  119 + Line line = LineBufferData.findOne(lineCode);
  120 + lineMap.put("lineName", line.getName());
  121 + lineMap.put("lineCode", line.getShanghaiLinecode());
  122 + lineMap.put("lineCodeExternal", lineCode);
  123 +
  124 + int count = 1;
  125 + List<Map<String, Object>> upStations = new ArrayList<>(), downStations = new ArrayList<>();
  126 + Collection<StationRotue> upStationRoutes = StationBufferData.findRouteByLineCode(lineCode).get(String.format("%s_0", lineCode));
  127 + if (upStationRoutes != null) {
  128 + for (StationRotue route : upStationRoutes) {
  129 + Map<String, Object> stopMap = new HashMap<>();
  130 + stopMap.put("levelNo", count);
  131 + stopMap.put("levelName", route.getStationName());
  132 + stopMap.put("levelLonlat", String.format("%f %f", route.getStation().getLon(), route.getStation().getLat()));
  133 + stopMap.put("stationCode", route.getStationCode());
  134 + upStations.add(stopMap);
  135 + count++;
  136 + }
  137 + }
  138 + count = 1;
  139 + Collection<StationRotue> downStationRoutes = StationBufferData.findRouteByLineCode(lineCode).get(String.format("%s_1", lineCode));
  140 + if (downStationRoutes != null) {
  141 + for (StationRotue route : downStationRoutes) {
  142 + Map<String, Object> stopMap = new HashMap<>();
  143 + stopMap.put("levelNo", count);
  144 + stopMap.put("levelName", route.getStationName());
  145 + stopMap.put("levelLonlat", String.format("%f %f", route.getStation().getLon(), route.getStation().getLat()));
  146 + stopMap.put("stationCode", route.getStationCode());
  147 + downStations.add(stopMap);
  148 + count++;
  149 + }
  150 + }
  151 +
  152 + lineMap.put("upStations", upStations);
  153 + lineMap.put("downStations", downStations);
  154 + result.add(lineMap);
  155 + }
  156 + }
  157 +
  158 + return result;
  159 + }
  160 +
  161 + @GET
  162 + @Path("/vehicle")
  163 + public List<Map<String, Object>> findAllVehicle(@Context HttpServletRequest request) {
  164 + List<Map<String, Object>> result = new ArrayList<>();
  165 + Map<String, String> device2line = GpsRealDataBuffer.getDevice2Line();
  166 + String password = request.getParameter("password");
  167 + log.error("log password: {}", password);
  168 + System.out.println("stdio password: " + password);
  169 + Set<String> limitLines = authorizeInterceptorIn.getLimitLines(password);
  170 + Set<String> limitDevices = authorizeInterceptorIn.getLimitDevices(password);
  171 + if (limitLines == null || limitLines.isEmpty()) {
  172 + return result;
  173 + }
  174 + if (limitDevices == null || limitDevices.isEmpty()) {
  175 + return result;
  176 + }
  177 + for (Car car : CarBufferData.findAll()) {
  178 + if (limitDevices.contains(car.getEquipmentCode()) || limitDevices.contains("ALL")) {
  179 + Map<String, Object> carMap = new HashMap<>();
  180 + Line line = LineBufferData.findOne(device2line.get(car.getEquipmentCode()));
  181 + if (line == null || !limitLines.contains(line.getLineCode()) || !limitLines.contains("ALL")) {
  182 + continue;
  183 + }
  184 + carMap.put("lineName", line.getName());
  185 + carMap.put("lineCode", line.getShanghaiLinecode());
  186 + carMap.put("lineCodeExternal", line.getLineCode());
  187 + carMap.put("vehicleId", car.getCarPlate());
  188 + carMap.put("vehicleNo", car.getNbbm());
  189 + carMap.put("vehicleType", car.getVehicleType());
  190 + carMap.put("energyType", car.getSfdc() ? 3 : 0);
  191 +
  192 + result.add(carMap);
  193 + }
  194 + }
  195 +
  196 + return result;
  197 + }
  198 +
  199 +// @GET
  200 +// @Path("/parking")
  201 +// public List<Map<String, Object>> findAllParking(@Context HttpServletRequest request) {
  202 +// List<Map<String, Object>> result = new ArrayList<>();
  203 +// String password = request.getParameter("password");
  204 +// log.error("log password: {}", password);
  205 +// System.out.println("stdio password: " + password);
  206 +// Set<String> limitLines = authorizeInterceptorIn.getLimitLines(password);
  207 +// if (limitLines == null || limitLines.isEmpty()) {
  208 +// return result;
  209 +// }
  210 +// StringBuilder sb = new StringBuilder();
  211 +// for (Line line : LineBufferData.findAll()) {
  212 +// String lineCode = line.getLineCode();
  213 +// if (limitLines.contains(lineCode) || limitLines.contains("ALL")) {
  214 +// sb.append(line.getCarPark()).append(",");
  215 +// }
  216 +// }
  217 +// String limitParkings = sb.toString();
  218 +//
  219 +// if (limitParkings.equals("")) {
  220 +// return result;
  221 +// }
  222 +// for (Carpark carpark : CarparkBufferData.findAll()) {
  223 +// if (limitParkings.indexOf(String.format("%s,", carpark.getParkCode())) > -1) {
  224 +// Map<String, Object> parkMap = new HashMap<>();
  225 +// parkMap.put("company", BasicDataBuffer.getBusinessByCode(carpark.getCompany()));
  226 +// parkMap.put("parkName", carpark.getParkName());
  227 +// parkMap.put("parkAddress", null);
  228 +// parkMap.put("parkLonlat", carpark.getgParkPoint());
  229 +// result.add(parkMap);
  230 +// }
  231 +// }
  232 +//
  233 +// return result;
  234 +// }
  235 +
  236 + @GET
  237 + @Path("/gps/all")
  238 + public List<Map<String, Object>> findAllGps(@Context HttpServletRequest request) {
  239 + List<Map<String, Object>> result = new ArrayList<>();
  240 + String password = request.getParameter("password");
  241 + log.error("log password: {}", password);
  242 + System.out.println("stdio password: " + password);
  243 + Set<String> limitLines = authorizeInterceptorIn.getLimitLines(password);
  244 + Set<String> limitDevices = authorizeInterceptorIn.getLimitDevices(password);
  245 + if (limitLines == null || limitLines.isEmpty()) {
  246 + return result;
  247 + }
  248 + for (GpsEntity gps : GpsRealDataBuffer.all()) {
  249 + String lineCode = gps.getLineId(), deviceId = gps.getDeviceId();
  250 + if ((limitLines.contains(lineCode) || limitLines.contains("ALL")) && (limitDevices.contains(deviceId) || limitDevices.contains("ALL"))) {
  251 + Line line = LineBufferData.findOne(lineCode);
  252 + Car car = CarBufferData.findByDevice(deviceId);
  253 + if (car == null) {
  254 + continue;
  255 + }
  256 + Map<String, Object> gpsMap = new HashMap<>();
  257 + gpsMap.put("lineName", line.getName());
  258 + gpsMap.put("lineCode", line.getShanghaiLinecode());
  259 + gpsMap.put("lineCodeExternal", line.getLineCode());
  260 + gpsMap.put("vehicleId", car.getCarPlate());
  261 + gpsMap.put("gpsTime", gps.getTimestamp());
  262 + gpsMap.put("gpsLonlat", String.format("%f %f", gps.getLon(), gps.getLat()));
  263 + gpsMap.put("angle", gps.getDirection());
  264 +
  265 + result.add(gpsMap);
  266 + }
  267 + }
  268 +
  269 + return result;
  270 + }
  271 +
  272 +// @GET
  273 +// @Path("/history-arrival/{line}/{st}/{et}")
  274 +// public List<HistoryArrivalEntity> historyArrival(@PathParam("line") String line, @PathParam("st") String st, @PathParam("et") String et, @Context HttpServletRequest request) {
  275 +// List<HistoryArrivalEntity> result = new ArrayList<>();
  276 +// String password = request.getParameter("password");
  277 +// log.error("log password: {}", password);
  278 +// System.out.println("stdio password: " + password);
  279 +// Set<String> limitLines = authorizeInterceptorIn.getLimitLines(password);
  280 +// Set<String> limitDevices = authorizeInterceptorIn.getLimitDevices(password);
  281 +// if (limitLines == null || limitLines.isEmpty()) {
  282 +// return result;
  283 +// }
  284 +// if (limitDevices == null || limitDevices.isEmpty()) {
  285 +// return result;
  286 +// }
  287 +// List<HistoryArrivalEntity> arrivals = historyGpsDao.queryArrival(line, Long.parseLong(st), Long.parseLong(et));
  288 +// for (HistoryArrivalEntity arrival : arrivals) {
  289 +// String lineCode = String.valueOf(arrival.getLineId()), deviceId = arrival.getDeviceId();
  290 +// Line line1 = LineBufferData.findOne(lineCode);
  291 +// if (line1 == null) {
  292 +// continue;
  293 +// }
  294 +// arrival.setLineName(line1.getName());
  295 +// if ((limitLines.contains(lineCode) || limitLines.contains("ALL")) && (limitDevices.contains(deviceId) || limitDevices.contains("ALL"))) {
  296 +// result.add(arrival);
  297 +// }
  298 +// }
  299 +//
  300 +// return result;
  301 +// }
  302 +
  303 +// @GET
  304 +// @Path("/waybill/{company}/{rq}")
  305 +// public List<ScheduleRealInfoDTO_JK> sch_jk(@PathParam("company") String company, @PathParam("rq") String rq) {
  306 +// DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd");
  307 +// DateTime dateTime = fmt.parseDateTime(rq);
  308 +// if (!dateTime.isBefore(DateTime.now().withTimeAtStartOfDay())) {
  309 +// return new ArrayList<>();
  310 +// }
  311 +// List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.findByDateAndCompany(dateTime.toString("yyyy-MM-dd"), company);
  312 +// scheduleRedisService.calcTime(scheduleRealInfos);
  313 +// List<ScheduleRealInfoDTO_JK> result = ScheduleRealInfoDTO_JK.getMultiInstance(scheduleRealInfos);
  314 +// for (ScheduleRealInfoDTO_JK jk : result) {
  315 +// if (jk.getZdsjActualTime() == null) {
  316 +// jk.setZdsjActualTime(jk.getZdsjT());
  317 +// }
  318 +// }
  319 +//
  320 +// return result;
  321 +// }
  322 +
  323 + @GET
  324 + @Path("/limits/reload")
  325 + public void reload(@Context HttpServletRequest request) {
  326 + String password = request.getParameter("password");
  327 + log.error("log password: {}", password);
  328 + System.out.println("stdio password: " + password);
  329 + authorizeInterceptorIn.loadLimit(password);
  330 + }
  331 +}