Commit de957a9b67bea3f3f5496fc6fdf2efb8fb658e2c

Authored by panzh
1 parent 068aa54f

update...

src/main/java/com/bsth/controller/XmlInfoPublishController.java
1   -package com.bsth.controller;
2   -
3   -import com.bsth.controller.dto.DispatchScreen;
4   -import com.bsth.data.BasicCacheData;
5   -import com.bsth.data.geo.GeoCacheData;
6   -import com.bsth.data.gps.GpsCacheData;
7   -import com.bsth.data.history.HistoryConsumeTimeDataHandler;
8   -import com.bsth.data.schedule.entity.ScheduleRealInfo;
9   -import com.bsth.entity.GpsEntity;
10   -import com.bsth.entity.Line;
11   -import com.bsth.entity.StationRoute;
12   -import org.apache.commons.lang3.StringUtils;
13   -import org.slf4j.Logger;
14   -import org.slf4j.LoggerFactory;
15   -import org.springframework.beans.factory.annotation.Autowired;
16   -import org.springframework.jdbc.core.BeanPropertyRowMapper;
17   -import org.springframework.jdbc.core.JdbcTemplate;
18   -import org.springframework.web.bind.annotation.RequestMapping;
19   -import org.springframework.web.bind.annotation.RequestParam;
20   -import org.springframework.web.bind.annotation.RestController;
21   -
22   -import java.text.DecimalFormat;
23   -import java.util.*;
24   -
25   -/**
26   - * 信息发布,xml 格式
27   - */
28   -@RestController
29   -@RequestMapping("xxfb")
30   -public class XmlInfoPublishController {
31   -
32   -
33   - @Autowired
34   - JdbcTemplate jdbcTemplate;
35   -
36   - Logger logger = LoggerFactory.getLogger(this.getClass());
37   -
38   - static DecimalFormat df = new DecimalFormat("#.00");
39   -
40   - @RequestMapping("getLineInfoByName")
41   - public String getLineInfoByName(@RequestParam String linename, @RequestParam String t) {
42   - StringBuilder sb = new StringBuilder();
43   - try {
44   - if (StringUtils.isBlank(linename))
45   - return "";
46   -
47   - Collection<Line> vs = BasicCacheData.code2LineMap.values();
48   -
49   - Line line = null;
50   - for (Line v : vs) {
51   - if (linename.equals(v.getName())) {
52   - line = v;
53   - break;
54   - }
55   - }
56   -
57   - if (null == line)
58   - return "";
59   -
60   - //to xml
61   - sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
62   - sb.append("<linedetail>");
63   -
64   - sb.append("<end_earlytime>" + line.getEndStationFirstTime() + "</end_earlytime>");
65   - sb.append("<end_latetime>" + line.getEndStationEndTime() + "</end_latetime>");
66   - sb.append("<end_stop>" + line.getEndStationName() + "</end_stop>");
67   - sb.append("<line_id>" + line.getLineCode() + "</line_id>");
68   - sb.append("<line_name>" + line.getName() + "</line_name>");
69   - sb.append("<start_earlytime>" + line.getStartStationFirstTime() + "</start_earlytime>");
70   - sb.append("<start_latetime>" + line.getStartStationEndTime() + "</start_latetime>");
71   - sb.append("<start_stop>" + line.getStartStationName() + "</start_stop>");
72   -
73   - sb.append("</linedetail>");
74   - } catch (Exception e) {
75   - logger.error("", e);
76   - }
77   - return sb.toString();
78   - }
79   -
80   - @RequestMapping("getLine")
81   - public String getLine(@RequestParam String lineid, @RequestParam String t) {
82   - StringBuilder sb = new StringBuilder();
83   - try {
84   -
85   - List<StationRoute>[] listArray = GeoCacheData.find(lineid);
86   -
87   - List<StationRoute> srs0 = listArray[0];
88   - List<StationRoute> srs1 = listArray[1];
89   -
90   - //to xml
91   -
92   - sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
93   - sb.append("<lineInfoDetails>");
94   -
95   - if (null != srs0) {
96   - //上行
97   - sb.append("<lineResults0>");
98   - sb.append("<direction>true</direction>");
99   - sb.append("<stops>");
100   - for (StationRoute s : srs0) {
101   - sb.append("<stop>");
102   - sb.append("<zdmc>" + s.getName() + "</zdmc>");
103   - sb.append("<id>" + s.getStationCode() + "</id>");
104   - sb.append("</stop>");
105   - }
106   - sb.append("</stops>");
107   - sb.append("</lineResults0>");
108   - }
109   -
110   -
111   - if (null != srs1) {
112   - //下行
113   - sb.append("<lineResults1>");
114   - sb.append("<direction>false</direction>");
115   - sb.append("<stops>");
116   - for (StationRoute s : srs1) {
117   - sb.append("<stop>");
118   - sb.append("<zdmc>" + s.getName() + "</zdmc>");
119   - sb.append("<id>" + s.getStationCode() + "</id>");
120   - sb.append("</stop>");
121   - }
122   - sb.append("</stops>");
123   - sb.append("</lineResults1>");
124   - }
125   -
126   - sb.append("</lineInfoDetails>");
127   - } catch (Exception e) {
128   - logger.error("", e);
129   - }
130   - return sb.toString();
131   - }
132   -
133   - @RequestMapping("carMonitor")
134   - public String carMonitor(@RequestParam String lineid, @RequestParam String stopid, @RequestParam String direction, String t) {
135   - StringBuilder sb = new StringBuilder();
136   -
137   - try {
138   -
139   - int upDown = Integer.parseInt(direction);
140   - List<GpsEntity> list = GpsCacheData.findList(lineid, upDown);
141   -
142   - Map<String, Double> disMap = new HashMap<>();
143   - List<StationRoute> srs = GeoCacheData.find(lineid, upDown);
144   -
145   - StationRoute es = GeoCacheData.findByCode(lineid, upDown, stopid), s = null;
146   -
147   - List<GpsEntity> vs = new ArrayList<>();
148   - ScheduleRealInfo sch = null;
149   - double sum;
150   -
151   - int serialNo = es.getSerialNo();
152   - for (GpsEntity gps : list) {
153   -
154   - s = GeoCacheData.findByCode(gps);
155   - if (null == s || s.getSerialNo() > serialNo)
156   - continue;
157   -
158   - sch = gps.getSch();
159   - if (null != sch) {//有班次
160   - if (serialNo > sch.getQdzNo() && serialNo < sch.getZdzNo())
161   - vs.add(gps);
162   - } else {
163   - vs.add(gps);
164   - }
165   -
166   - sum = 0;
167   -
168   - for (StationRoute sr : srs) {
169   - if (sr.getSerialNo() < serialNo
170   - && sr.getSerialNo() > gps.getStationNo()) {
171   - sum += sr.getLength();
172   - }
173   - }
174   -
175   - disMap.put(gps.getDeviceId(), sum);
176   - }
177   -
178   -
179   - Map<String, Integer> forecast = HistoryConsumeTimeDataHandler.forecastEnd(vs, stopid);
180   -
181   - //to xml
182   -
183   - sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
184   - sb.append("<result>");
185   - sb.append("<cars lineid=\"" + lineid + "\">");
186   -
187   - for (GpsEntity v : vs) {
188   - sb.append("<car>");
189   - sb.append("<terminal>" + BasicCacheData.device2plateMap.get(v.getDeviceId()) + "</terminal>");
190   - sb.append("<stopdis>" + df.format(v.getStopDis()) + "</stopdis>");
191   - sb.append("<distance>" + df.format((disMap.get(v.getDeviceId()) + v.getDistance())) + "</distance>");
192   - sb.append("<time>" + forecast.get(v.getDeviceId()) + "</time>");
193   - sb.append("</car>");
194   - }
195   -
196   - sb.append("</cars>");
197   - sb.append("</result>");
198   - } catch (Exception e) {
199   - logger.error("", e);
200   - }
201   - return sb.toString();
202   - }
203   -
204   - @RequestMapping("getdispatchScreen")
205   - public String getdispatchScreen(@RequestParam String lineid, @RequestParam String direction, String t) {
206   - StringBuilder sb = new StringBuilder();
207   -
208   - try {
209   - String sql = "select cph as plate,dfsj as time,line_code from bsth_t_clfcxxb where line_code='" + lineid + "' and updown=" + direction;
210   -
211   - List<DispatchScreen> list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(DispatchScreen.class));
212   -
213   - //to xml
214   -
215   - sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
216   - sb.append("<result>");
217   - sb.append("<cars lineid=\"" + lineid + "\">");
218   -
219   - char[] cs;
220   - for (DispatchScreen d : list) {
221   - cs = d.getTime().toCharArray();
222   - sb.append("<car>");
223   - sb.append("<vehicle>" + d.getPlate() + "</vehicle>");
224   - sb.append("<time>" + (cs[0] + cs[1] + ":" + cs[2] + cs[3] + ":00") + "</time>");
225   - sb.append("</car>");
226   - }
227   -
228   - sb.append("</cars>");
229   - sb.append("</result>");
230   - } catch (Exception e) {
231   - logger.error("", e);
232   - }
233   - return sb.toString();
234   - }
235   -}
  1 +package com.bsth.controller;
  2 +
  3 +import com.bsth.controller.dto.DispatchScreen;
  4 +import com.bsth.data.BasicCacheData;
  5 +import com.bsth.data.geo.GeoCacheData;
  6 +import com.bsth.data.gps.GpsCacheData;
  7 +import com.bsth.data.history.HistoryConsumeTimeDataHandler;
  8 +import com.bsth.data.schedule.entity.ScheduleRealInfo;
  9 +import com.bsth.entity.GpsEntity;
  10 +import com.bsth.entity.Line;
  11 +import com.bsth.entity.StationRoute;
  12 +import org.apache.commons.lang3.StringUtils;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.jdbc.core.BeanPropertyRowMapper;
  17 +import org.springframework.jdbc.core.JdbcTemplate;
  18 +import org.springframework.web.bind.annotation.RequestMapping;
  19 +import org.springframework.web.bind.annotation.RequestParam;
  20 +import org.springframework.web.bind.annotation.RestController;
  21 +
  22 +import java.text.DecimalFormat;
  23 +import java.util.*;
  24 +
  25 +/**
  26 + * 信息发布,xml 格式
  27 + */
  28 +@RestController
  29 +@RequestMapping("xxfb")
  30 +public class XmlInfoPublishController {
  31 +
  32 +
  33 + @Autowired
  34 + JdbcTemplate jdbcTemplate;
  35 +
  36 + Logger logger = LoggerFactory.getLogger(this.getClass());
  37 +
  38 + static DecimalFormat df = new DecimalFormat("#.00");
  39 +
  40 + @RequestMapping("getLineInfoByName")
  41 + public String getLineInfoByName(@RequestParam String linename, @RequestParam String t) {
  42 + StringBuilder sb = new StringBuilder();
  43 + try {
  44 + if (StringUtils.isBlank(linename))
  45 + return "";
  46 +
  47 + Collection<Line> vs = BasicCacheData.code2LineMap.values();
  48 +
  49 + Line line = null;
  50 + for (Line v : vs) {
  51 + if (linename.equals(v.getName())) {
  52 + line = v;
  53 + break;
  54 + }
  55 + }
  56 +
  57 + if (null == line)
  58 + return "";
  59 +
  60 + //to xml
  61 + sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  62 + sb.append("<linedetail>");
  63 +
  64 + sb.append("<end_earlytime>" + line.getEndStationFirstTime() + "</end_earlytime>");
  65 + sb.append("<end_latetime>" + line.getEndStationEndTime() + "</end_latetime>");
  66 + sb.append("<end_stop>" + line.getEndStationName() + "</end_stop>");
  67 + sb.append("<line_id>" + line.getLineCode() + "</line_id>");
  68 + sb.append("<line_name>" + line.getName() + "</line_name>");
  69 + sb.append("<start_earlytime>" + line.getStartStationFirstTime() + "</start_earlytime>");
  70 + sb.append("<start_latetime>" + line.getStartStationEndTime() + "</start_latetime>");
  71 + sb.append("<start_stop>" + line.getStartStationName() + "</start_stop>");
  72 +
  73 + sb.append("</linedetail>");
  74 + } catch (Exception e) {
  75 + logger.error("", e);
  76 + }
  77 + return sb.toString();
  78 + }
  79 +
  80 + @RequestMapping("getLine")
  81 + public String getLine(@RequestParam String lineid, @RequestParam String t) {
  82 + StringBuilder sb = new StringBuilder();
  83 + try {
  84 +
  85 + List<StationRoute>[] listArray = GeoCacheData.find(lineid);
  86 +
  87 + List<StationRoute> srs0 = listArray[0];
  88 + List<StationRoute> srs1 = listArray[1];
  89 +
  90 + //to xml
  91 +
  92 + sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  93 + sb.append("<lineInfoDetails>");
  94 +
  95 + if (null != srs0) {
  96 + //上行
  97 + sb.append("<lineResults0>");
  98 + sb.append("<direction>true</direction>");
  99 + sb.append("<stops>");
  100 + for (StationRoute s : srs0) {
  101 + sb.append("<stop>");
  102 + sb.append("<zdmc>" + s.getName() + "</zdmc>");
  103 + sb.append("<id>" + s.getStationCode() + "</id>");
  104 + sb.append("</stop>");
  105 + }
  106 + sb.append("</stops>");
  107 + sb.append("</lineResults0>");
  108 + }
  109 +
  110 +
  111 + if (null != srs1) {
  112 + //下行
  113 + sb.append("<lineResults1>");
  114 + sb.append("<direction>false</direction>");
  115 + sb.append("<stops>");
  116 + for (StationRoute s : srs1) {
  117 + sb.append("<stop>");
  118 + sb.append("<zdmc>" + s.getName() + "</zdmc>");
  119 + sb.append("<id>" + s.getStationCode() + "</id>");
  120 + sb.append("</stop>");
  121 + }
  122 + sb.append("</stops>");
  123 + sb.append("</lineResults1>");
  124 + }
  125 +
  126 + sb.append("</lineInfoDetails>");
  127 + } catch (Exception e) {
  128 + logger.error("", e);
  129 + }
  130 + return sb.toString();
  131 + }
  132 +
  133 + @RequestMapping("carMonitor")
  134 + public String carMonitor(@RequestParam String lineid, @RequestParam String stopid, @RequestParam String direction, String t) {
  135 + StringBuilder sb = new StringBuilder();
  136 +
  137 + try {
  138 +
  139 + int upDown = Integer.parseInt(direction);
  140 + List<GpsEntity> list = GpsCacheData.findList(lineid, upDown);
  141 +
  142 + Map<String, Double> disMap = new HashMap<>();
  143 + List<StationRoute> srs = GeoCacheData.find(lineid, upDown);
  144 +
  145 + StationRoute es = GeoCacheData.findByCode(lineid, upDown, stopid), s = null;
  146 +
  147 + List<GpsEntity> vs = new ArrayList<>();
  148 + ScheduleRealInfo sch = null;
  149 + double sum;
  150 +
  151 + int serialNo = es.getSerialNo();
  152 + for (GpsEntity gps : list) {
  153 +
  154 + s = GeoCacheData.findByCode(gps);
  155 + if (null == s || s.getSerialNo() > serialNo)
  156 + continue;
  157 +
  158 + sch = gps.getSch();
  159 + if (null != sch) {//有班次
  160 + if (serialNo > sch.getQdzNo() && serialNo < sch.getZdzNo())
  161 + vs.add(gps);
  162 + } else {
  163 + vs.add(gps);
  164 + }
  165 +
  166 + sum = 0;
  167 +
  168 + for (StationRoute sr : srs) {
  169 + if (sr.getSerialNo() < serialNo
  170 + && sr.getSerialNo() > gps.getStationNo()) {
  171 + sum += sr.getLength();
  172 + }
  173 + }
  174 +
  175 + disMap.put(gps.getDeviceId(), sum);
  176 + }
  177 +
  178 +
  179 + Map<String, Integer> forecast = HistoryConsumeTimeDataHandler.forecastEnd(vs, stopid);
  180 +
  181 + //to xml
  182 +
  183 + sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  184 + sb.append("<result>");
  185 + sb.append("<cars lineid=\"" + lineid + "\">");
  186 +
  187 + for (GpsEntity v : vs) {
  188 + sb.append("<car>");
  189 + sb.append("<terminal>" + BasicCacheData.device2plateMap.get(v.getDeviceId()) + "</terminal>");
  190 + sb.append("<stopdis>" + df.format(v.getStopDis()) + "</stopdis>");
  191 + sb.append("<distance>" + df.format((disMap.get(v.getDeviceId()) + v.getDistance())) + "</distance>");
  192 + sb.append("<time>" + forecast.get(v.getDeviceId()) + "</time>");
  193 + sb.append("</car>");
  194 + }
  195 +
  196 + sb.append("</cars>");
  197 + sb.append("</result>");
  198 + } catch (Exception e) {
  199 + logger.error("", e);
  200 + }
  201 + return sb.toString();
  202 + }
  203 +
  204 + @RequestMapping("getdispatchScreen")
  205 + public String getdispatchScreen(@RequestParam String lineid, @RequestParam String direction, String t) {
  206 + StringBuilder sb = new StringBuilder();
  207 +
  208 + try {
  209 + String sql = "select cph as plate,dfsj as time,line_code from bsth_t_clfcxxb where line_code='" + lineid + "' and updown=" + direction;
  210 +
  211 + List<DispatchScreen> list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(DispatchScreen.class));
  212 +
  213 + //to xml
  214 +
  215 + sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  216 + sb.append("<result>");
  217 + sb.append("<cars lineid=\"" + lineid + "\">");
  218 +
  219 + char[] cs;
  220 + for (DispatchScreen d : list) {
  221 + cs = d.getTime().toCharArray();
  222 + sb.append("<car>");
  223 + sb.append("<vehicle>" + d.getPlate() + "</vehicle>");
  224 + sb.append("<time>" + (cs[0] + cs[1] + ":" + cs[2] + cs[3] + ":00") + "</time>");
  225 + sb.append("</car>");
  226 + }
  227 +
  228 + sb.append("</cars>");
  229 + sb.append("</result>");
  230 + } catch (Exception e) {
  231 + logger.error("", e);
  232 + }
  233 + return sb.toString();
  234 + }
  235 +}
... ...
src/main/java/com/bsth/controller/dto/DispatchScreen.java
1   -package com.bsth.controller.dto;
2   -
3   -public class DispatchScreen {
4   -
5   - private String lineCode;
6   - private String plate;
7   - private String time;
8   -
9   - public String getLineCode() {
10   - return lineCode;
11   - }
12   -
13   - public void setLineCode(String lineCode) {
14   - this.lineCode = lineCode;
15   - }
16   -
17   - public String getPlate() {
18   - return plate;
19   - }
20   -
21   - public void setPlate(String plate) {
22   - this.plate = plate;
23   - }
24   -
25   - public String getTime() {
26   - return time;
27   - }
28   -
29   - public void setTime(String time) {
30   - this.time = time;
31   - }
32   -}
  1 +package com.bsth.controller.dto;
  2 +
  3 +public class DispatchScreen {
  4 +
  5 + private String lineCode;
  6 + private String plate;
  7 + private String time;
  8 +
  9 + public String getLineCode() {
  10 + return lineCode;
  11 + }
  12 +
  13 + public void setLineCode(String lineCode) {
  14 + this.lineCode = lineCode;
  15 + }
  16 +
  17 + public String getPlate() {
  18 + return plate;
  19 + }
  20 +
  21 + public void setPlate(String plate) {
  22 + this.plate = plate;
  23 + }
  24 +
  25 + public String getTime() {
  26 + return time;
  27 + }
  28 +
  29 + public void setTime(String time) {
  30 + this.time = time;
  31 + }
  32 +}
... ...