Commit 8f96f973c675e9c5383ee5cd61f24919f240044f

Authored by 娄高锋
2 parents beb6f65f b715c032

Merge branch 'pudong_jdk8' of http://101.95.0.106:8888/panzhaov5/bsth_control into pudong_jdk8

Showing 27 changed files with 2518 additions and 2080 deletions

Too many changes to show.

To preserve performance only 27 of 40 files are displayed.

@@ -34,8 +34,6 @@ @@ -34,8 +34,6 @@
34 <groupId>org.springframework.boot</groupId> 34 <groupId>org.springframework.boot</groupId>
35 <artifactId>spring-boot-starter-security</artifactId> 35 <artifactId>spring-boot-starter-security</artifactId>
36 </dependency> 36 </dependency>
37 - <!-- <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId>  
38 - </dependency> -->  
39 <dependency> 37 <dependency>
40 <groupId>org.springframework.boot</groupId> 38 <groupId>org.springframework.boot</groupId>
41 <artifactId>spring-boot-starter-data-jpa</artifactId> 39 <artifactId>spring-boot-starter-data-jpa</artifactId>
@@ -59,6 +57,10 @@ @@ -59,6 +57,10 @@
59 <optional>true</optional> 57 <optional>true</optional>
60 </dependency> 58 </dependency>
61 <dependency> 59 <dependency>
  60 + <groupId>org.springframework.kafka</groupId>
  61 + <artifactId>spring-kafka</artifactId>
  62 + </dependency>
  63 + <dependency>
62 <groupId>mysql</groupId> 64 <groupId>mysql</groupId>
63 <artifactId>mysql-connector-java</artifactId> 65 <artifactId>mysql-connector-java</artifactId>
64 <version>5.1.38</version> 66 <version>5.1.38</version>
src/main/java/com/bsth/controller/sys/UserController.java
@@ -94,6 +94,7 @@ public class UserController extends BaseController&lt;SysUser, Integer&gt; { @@ -94,6 +94,7 @@ public class UserController extends BaseController&lt;SysUser, Integer&gt; {
94 StringBuilder sb = HttpClientUtils.post(ssoConfig.getSsoAuthUrl(), mapper.writeValueAsString(param)); 94 StringBuilder sb = HttpClientUtils.post(ssoConfig.getSsoAuthUrl(), mapper.writeValueAsString(param));
95 95
96 Assert.notNull(sb, "统一登录平台验证数据不为空"); 96 Assert.notNull(sb, "统一登录平台验证数据不为空");
  97 + logger.info(String.format("统一登录平台:%s", sb.toString()));
97 param = mapper.readValue(mapper.writeValueAsString(mapper.readValue(sb.toString(), Map.class).get("data")), Map.class); 98 param = mapper.readValue(mapper.writeValueAsString(mapper.readValue(sb.toString(), Map.class).get("data")), Map.class);
98 String jobCode = (String) param.get("account"), realName = (String) param.get("userName"); 99 String jobCode = (String) param.get("account"), realName = (String) param.get("userName");
99 if (!account.equals(jobCode)) { 100 if (!account.equals(jobCode)) {
src/main/java/com/bsth/data/LineVersionsData.java
1 -package com.bsth.data;  
2 -  
3 -import com.bsth.entity.LineVersions;  
4 -import com.bsth.service.LineVersionsService;  
5 -import com.bsth.service.StationRouteService;  
6 -import org.slf4j.Logger;  
7 -import org.slf4j.LoggerFactory;  
8 -import org.springframework.beans.factory.annotation.Autowired;  
9 -import org.springframework.core.annotation.Order;  
10 -import org.springframework.stereotype.Component;  
11 -  
12 -import java.util.HashMap;  
13 -import java.util.List;  
14 -import java.util.Map;  
15 -  
16 -/**  
17 - * @ClassName: LineVersionsData  
18 - * @Description: TODO(线路版本数据管理)  
19 - */  
20 -@Component  
21 -@Order(20)  
22 -public class LineVersionsData extends Thread {  
23 -  
24 - static Logger logger = LoggerFactory.getLogger(LineVersionsData.class);  
25 -  
26 - @Autowired  
27 - LineVersionsService lineVersionsService;  
28 -  
29 - @Autowired  
30 - StationRouteService stationRouteService;  
31 -  
32 - @Override  
33 - public void run() {  
34 - try {  
35 - List<LineVersions> list = lineVersionsService.lineUpdate();  
36 - if(list.size() == 0){  
37 - logger.info("没有需要更新的线路!");  
38 - return;  
39 - }  
40 - for (LineVersions lineVersions : list) {  
41 - Integer lineId = lineVersions.getLine().getId();  
42 - // 更新线路文件  
43 - Map<String, Object> map = new HashMap<>();  
44 - map.put("lineId", lineId);  
45 - stationRouteService.usingSingle(map);  
46 - logger.info("线路版本更新成功!");  
47 - }  
48 - } catch (Exception e) {  
49 - e.printStackTrace();  
50 - logger.error("线路版本更新出现异常!", e);  
51 - }  
52 - }  
53 -} 1 +package com.bsth.data;
  2 +
  3 +import com.bsth.entity.LineVersions;
  4 +import com.bsth.service.LineVersionsService;
  5 +import com.bsth.service.StationRouteService;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.core.annotation.Order;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +import java.util.HashMap;
  13 +import java.util.List;
  14 +import java.util.Map;
  15 +
  16 +/**
  17 + * @ClassName: LineVersionsData
  18 + * @Description: TODO(线路版本数据管理)
  19 + */
  20 +@Component
  21 +@Order(20)
  22 +public class LineVersionsData extends Thread {
  23 +
  24 + static Logger logger = LoggerFactory.getLogger(LineVersionsData.class);
  25 +
  26 + @Autowired
  27 + LineVersionsService lineVersionsService;
  28 +
  29 + @Autowired
  30 + StationRouteService stationRouteService;
  31 +
  32 + @Override
  33 + public void run() {
  34 + logger.warn("线路版本更新开始");
  35 + try {
  36 + List<LineVersions> list = lineVersionsService.lineUpdate();
  37 + if(list.size() == 0){
  38 + logger.info("没有需要更新的线路!");
  39 + return;
  40 + }
  41 + for (LineVersions lineVersions : list) {
  42 + Integer lineId = lineVersions.getLine().getId();
  43 + // 更新线路文件
  44 + Map<String, Object> map = new HashMap<>();
  45 + map.put("lineId", lineId);
  46 + stationRouteService.usingSingle(map);
  47 + logger.info("线路版本更新成功!");
  48 + }
  49 + } catch (Exception e) {
  50 + e.printStackTrace();
  51 + logger.error("线路版本更新出现异常!", e);
  52 + }
  53 + logger.warn("线路版本更新结束");
  54 + }
  55 +}
src/main/java/com/bsth/data/car_out_info/CarOutInfoHandler.java
@@ -15,12 +15,8 @@ import org.slf4j.LoggerFactory; @@ -15,12 +15,8 @@ import org.slf4j.LoggerFactory;
15 import org.springframework.beans.factory.annotation.Autowired; 15 import org.springframework.beans.factory.annotation.Autowired;
16 import org.springframework.jdbc.core.BatchPreparedStatementSetter; 16 import org.springframework.jdbc.core.BatchPreparedStatementSetter;
17 import org.springframework.jdbc.core.JdbcTemplate; 17 import org.springframework.jdbc.core.JdbcTemplate;
18 -import org.springframework.jdbc.datasource.DataSourceTransactionManager;  
19 import org.springframework.stereotype.Component; 18 import org.springframework.stereotype.Component;
20 -import org.springframework.transaction.TransactionDefinition;  
21 import org.springframework.transaction.TransactionStatus; 19 import org.springframework.transaction.TransactionStatus;
22 -import org.springframework.transaction.support.DefaultTransactionDefinition;  
23 -import org.springframework.transaction.support.TransactionCallback;  
24 import org.springframework.transaction.support.TransactionCallbackWithoutResult; 20 import org.springframework.transaction.support.TransactionCallbackWithoutResult;
25 import org.springframework.transaction.support.TransactionTemplate; 21 import org.springframework.transaction.support.TransactionTemplate;
26 22
@@ -70,6 +66,7 @@ public class CarOutInfoHandler { @@ -70,6 +66,7 @@ public class CarOutInfoHandler {
70 * 全量更新发车信息表 66 * 全量更新发车信息表
71 */ 67 */
72 public void updateAll() { 68 public void updateAll() {
  69 + logger.warn("发车信息更新开始");
73 try{ 70 try{
74 //将班次按线路分组 71 //将班次按线路分组
75 List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll()); 72 List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll());
@@ -88,6 +85,7 @@ public class CarOutInfoHandler { @@ -88,6 +85,7 @@ public class CarOutInfoHandler {
88 }catch (Exception e){ 85 }catch (Exception e){
89 logger.error("", e); 86 logger.error("", e);
90 } 87 }
  88 + logger.warn("发车信息更新结束");
91 } 89 }
92 90
93 public List<ScheduleRealInfo> update(List<ScheduleRealInfo> list) { 91 public List<ScheduleRealInfo> update(List<ScheduleRealInfo> list) {
src/main/java/com/bsth/data/directive/DirectivesPstThread.java
@@ -14,11 +14,10 @@ import org.slf4j.LoggerFactory; @@ -14,11 +14,10 @@ import org.slf4j.LoggerFactory;
14 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.jdbc.core.BatchPreparedStatementSetter; 15 import org.springframework.jdbc.core.BatchPreparedStatementSetter;
16 import org.springframework.jdbc.core.JdbcTemplate; 16 import org.springframework.jdbc.core.JdbcTemplate;
17 -import org.springframework.jdbc.datasource.DataSourceTransactionManager;  
18 import org.springframework.stereotype.Component; 17 import org.springframework.stereotype.Component;
19 -import org.springframework.transaction.TransactionDefinition;  
20 import org.springframework.transaction.TransactionStatus; 18 import org.springframework.transaction.TransactionStatus;
21 -import org.springframework.transaction.support.DefaultTransactionDefinition; 19 +import org.springframework.transaction.support.TransactionCallbackWithoutResult;
  20 +import org.springframework.transaction.support.TransactionTemplate;
22 21
23 import java.sql.PreparedStatement; 22 import java.sql.PreparedStatement;
24 import java.sql.SQLException; 23 import java.sql.SQLException;
@@ -48,10 +47,14 @@ public class DirectivesPstThread extends Thread { @@ -48,10 +47,14 @@ public class DirectivesPstThread extends Thread {
48 @Autowired 47 @Autowired
49 JdbcTemplate jdbcTemplate; 48 JdbcTemplate jdbcTemplate;
50 49
  50 + @Autowired
  51 + private TransactionTemplate transactionTemplate;
  52 +
51 private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd"); 53 private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd");
52 54
53 @Override 55 @Override
54 public void run() { 56 public void run() {
  57 + logger.warn("指令持久化开始");
55 try{ 58 try{
56 ConcurrentLinkedQueue<Directive> list = DayOfDirectives.pstDirectives; 59 ConcurrentLinkedQueue<Directive> list = DayOfDirectives.pstDirectives;
57 60
@@ -99,176 +102,172 @@ public class DirectivesPstThread extends Thread { @@ -99,176 +102,172 @@ public class DirectivesPstThread extends Thread {
99 }catch (Exception e){ 102 }catch (Exception e){
100 logger.error("指令入库出现异常", e); 103 logger.error("指令入库出现异常", e);
101 } 104 }
  105 + logger.warn("指令持久化结束");
102 } 106 }
103 107
104 private void save64(final List<D64> d64s) { 108 private void save64(final List<D64> d64s) {
105 if(null == d64s || d64s.size() == 0) 109 if(null == d64s || d64s.size() == 0)
106 return; 110 return;
107 111
  112 + logger.warn("64指令保存开始");
  113 +
108 String sql = "insert into bsth_v_directive_64(device_id,error_text,http_code,oper_code,rq,sender,timestamp,city_code,line_id,txt_content,resp_ack) " + 114 String sql = "insert into bsth_v_directive_64(device_id,error_text,http_code,oper_code,rq,sender,timestamp,city_code,line_id,txt_content,resp_ack) " +
109 " values(?,?,?,?,?,?,?,?,?,?,?)"; 115 " values(?,?,?,?,?,?,?,?,?,?,?)";
110 116
111 - //编程式事务  
112 - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource());  
113 - DefaultTransactionDefinition def = new DefaultTransactionDefinition();  
114 - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);  
115 - TransactionStatus status = tran.getTransaction(def);  
116 -  
117 - try{  
118 - jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {  
119 - @Override  
120 - public void setValues(PreparedStatement ps, int i) throws SQLException {  
121 - D64 d64 = d64s.get(i);  
122 - ps.setString(1 , d64.getDeviceId());  
123 - ps.setString(2, isNvl(d64.getErrorText()));  
124 - ps.setInt(3, d64.getHttpCode());  
125 - ps.setShort(4, isNvl(d64.getOperCode()));  
126 - ps.setString(5, d64.getRq());  
127 -  
128 - ps.setString(6, isNvl(d64.getSender()));  
129 - ps.setLong(7, d64.getTimestamp());  
130 -  
131 - ps.setShort(8, isNvl(d64.getData().getCityCode()));  
132 - ps.setString(9, isNvl(d64.getData().getLineId()));  
133 - ps.setString(10, isNvl(d64.getData().getTxtContent()));  
134 - ps.setShort(11, isNvl(d64.getRespAck()));  
135 - }  
136 -  
137 - @Override  
138 - public int getBatchSize() {  
139 - return d64s.size(); 117 + transactionTemplate.execute(new TransactionCallbackWithoutResult() {
  118 +
  119 + @Override
  120 + protected void doInTransactionWithoutResult(TransactionStatus status) {
  121 + try {
  122 + jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
  123 + @Override
  124 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  125 + D64 d64 = d64s.get(i);
  126 + ps.setString(1 , d64.getDeviceId());
  127 + ps.setString(2, isNvl(d64.getErrorText()));
  128 + ps.setInt(3, d64.getHttpCode());
  129 + ps.setShort(4, isNvl(d64.getOperCode()));
  130 + ps.setString(5, d64.getRq());
  131 +
  132 + ps.setString(6, isNvl(d64.getSender()));
  133 + ps.setLong(7, d64.getTimestamp());
  134 +
  135 + ps.setShort(8, isNvl(d64.getData().getCityCode()));
  136 + ps.setString(9, isNvl(d64.getData().getLineId()));
  137 + ps.setString(10, isNvl(d64.getData().getTxtContent()));
  138 + ps.setShort(11, isNvl(d64.getRespAck()));
  139 + }
  140 +
  141 + @Override
  142 + public int getBatchSize() {
  143 + return d64s.size();
  144 + }
  145 + });
  146 + } catch (Exception e) {
  147 + logger.error(String.format("错误数据:%s", JSON.toJSONString(d64s)), e);
  148 + status.setRollbackOnly();
140 } 149 }
141 - });  
142 -  
143 - tran.commit(status);  
144 -  
145 - logger.info("64 入库成功: " + d64s.size());  
146 - }catch (Exception e){  
147 - logger.error(String.format("错误数据:%s", JSON.toJSONString(d64s)), e);  
148 - tran.rollback(status);  
149 - } 150 + }
  151 + });
  152 + logger.warn("64指令保存结束");
150 } 153 }
151 154
152 private void update60(final List<D60> d60s) { 155 private void update60(final List<D60> d60s) {
153 if(null == d60s || d60s.size() == 0) 156 if(null == d60s || d60s.size() == 0)
154 return; 157 return;
155 158
  159 + logger.warn("60指令更新开始");
156 String sql = "update bsth_v_directive_60 set reply46=?,reply46time=?,reply47=?,reply47time=? where device_id=? and timestamp=? and msg_id=?"; 160 String sql = "update bsth_v_directive_60 set reply46=?,reply46time=?,reply47=?,reply47time=? where device_id=? and timestamp=? and msg_id=?";
157 161
158 - //编程式事务  
159 - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource());  
160 - DefaultTransactionDefinition def = new DefaultTransactionDefinition();  
161 - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);  
162 - TransactionStatus status = tran.getTransaction(def);  
163 -  
164 - try{  
165 - jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {  
166 - @Override  
167 - public void setValues(PreparedStatement ps, int i) throws SQLException {  
168 - D60 d60 = d60s.get(i);  
169 - ps.setShort(1, isNvl(d60.getReply46()));  
170 - if(null == d60.getReply46Time())  
171 - ps.setNull(2, Types.BIGINT);  
172 - else  
173 - ps.setLong(2, d60.getReply46Time());  
174 -  
175 - ps.setShort(3, isNvl(d60.getReply47()));  
176 -  
177 - if(null == d60.getReply47Time())  
178 - ps.setNull(4, Types.BIGINT);  
179 - else  
180 - ps.setLong(4, d60.getReply47Time());  
181 - ps.setString(5, d60.getDeviceId());  
182 - ps.setLong(6, d60.getTimestamp());  
183 - ps.setInt(7, d60.getMsgId());  
184 - }  
185 -  
186 - @Override  
187 - public int getBatchSize() {  
188 - return d60s.size(); 162 + transactionTemplate.execute(new TransactionCallbackWithoutResult() {
  163 +
  164 + @Override
  165 + protected void doInTransactionWithoutResult(TransactionStatus status) {
  166 + try{
  167 + jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
  168 + @Override
  169 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  170 + D60 d60 = d60s.get(i);
  171 + ps.setShort(1, isNvl(d60.getReply46()));
  172 + if(null == d60.getReply46Time())
  173 + ps.setNull(2, Types.BIGINT);
  174 + else
  175 + ps.setLong(2, d60.getReply46Time());
  176 +
  177 + ps.setShort(3, isNvl(d60.getReply47()));
  178 +
  179 + if(null == d60.getReply47Time())
  180 + ps.setNull(4, Types.BIGINT);
  181 + else
  182 + ps.setLong(4, d60.getReply47Time());
  183 + ps.setString(5, d60.getDeviceId());
  184 + ps.setLong(6, d60.getTimestamp());
  185 + ps.setInt(7, d60.getMsgId());
  186 + }
  187 +
  188 + @Override
  189 + public int getBatchSize() {
  190 + return d60s.size();
  191 + }
  192 + });
  193 + }catch (Exception e){
  194 + logger.error(String.format("错误数据:%s", JSON.toJSONString(d60s)), e);
  195 + status.setRollbackOnly();
189 } 196 }
190 - });  
191 -  
192 - tran.commit(status);  
193 -  
194 - logger.info("60 更新成功: " + d60s.size());  
195 - }catch (Exception e){  
196 - logger.error(String.format("错误数据:%s", JSON.toJSONString(d60s)), e);  
197 - tran.rollback(status);  
198 - } 197 + }
  198 + });
  199 + logger.warn("60指令更新结束");
199 } 200 }
200 201
201 private void save60(final List<D60> d60s) { 202 private void save60(final List<D60> d60s) {
202 if(null == d60s || d60s.size() == 0) 203 if(null == d60s || d60s.size() == 0)
203 return; 204 return;
204 205
  206 + logger.warn("60指令保存开始");
205 String sql = "insert into bsth_v_directive_60(device_id,error_text,http_code,oper_code,rq,sender,timestamp" + 207 String sql = "insert into bsth_v_directive_60(device_id,error_text,http_code,oper_code,rq,sender,timestamp" +
206 ",alarm_time,company_code,dispatch_instruct,instruct_type,msg_id,service_state,txt_content,is_dispatch" + 208 ",alarm_time,company_code,dispatch_instruct,instruct_type,msg_id,service_state,txt_content,is_dispatch" +
207 ",line_code,reply46,reply46time,reply47,reply47time,sch) " + 209 ",line_code,reply46,reply46time,reply47,reply47time,sch) " +
208 " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; 210 " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
209 211
210 - //编程式事务  
211 - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource());  
212 - DefaultTransactionDefinition def = new DefaultTransactionDefinition();  
213 - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);  
214 - TransactionStatus status = tran.getTransaction(def);  
215 -  
216 - try{  
217 - jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {  
218 - @Override  
219 - public void setValues(PreparedStatement ps, int i) throws SQLException {  
220 - D60 d60 = d60s.get(i);  
221 - ps.setString(1, d60.getDeviceId());  
222 - ps.setString(2, isNvl(d60.getErrorText()));  
223 - ps.setInt(3, d60.getHttpCode());  
224 - ps.setShort(4, d60.getOperCode());  
225 - ps.setString(5, d60.getRq());  
226 - ps.setString(6, d60.getSender());  
227 - ps.setLong(7, d60.getTimestamp());  
228 -  
229 - ps.setLong(8, isNvl(d60.getData().getAlarmTime()));  
230 - ps.setShort(9, isNvl(d60.getData().getCompanyCode()));  
231 - ps.setShort(10, isNvl(d60.getData().getDispatchInstruct()));  
232 - ps.setInt(11, d60.getData().getInstructType());  
233 - ps.setInt(12, d60.getData().getMsgId());  
234 - ps.setLong(13, d60.getData().getServiceState());  
235 - ps.setString(14, d60.getData().getTxtContent());  
236 - ps.setBoolean(15, d60.isDispatch());  
237 -  
238 - ps.setString(16, isNvl(d60.getLineCode()));  
239 - ps.setShort(17, isNvl(d60.getReply46()));  
240 -  
241 - if(null == d60.getReply46Time())  
242 - ps.setNull(18, Types.BIGINT);  
243 - else  
244 - ps.setLong(18, d60.getReply46Time());  
245 -  
246 - ps.setShort(19, isNvl(d60.getReply47()));  
247 -  
248 - if(null == d60.getReply47Time())  
249 - ps.setNull(20, Types.BIGINT);  
250 - else  
251 - ps.setLong(20, d60.getReply47Time());  
252 -  
253 - if(d60.getSch()==null)  
254 - ps.setNull(21, Types.BIGINT);  
255 - else  
256 - ps.setLong(21, d60.getSch().getId()); 212 + transactionTemplate.execute(new TransactionCallbackWithoutResult() {
  213 +
  214 + @Override
  215 + protected void doInTransactionWithoutResult(TransactionStatus status) {
  216 + try{
  217 + jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
  218 + @Override
  219 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  220 + D60 d60 = d60s.get(i);
  221 + ps.setString(1, d60.getDeviceId());
  222 + ps.setString(2, isNvl(d60.getErrorText()));
  223 + ps.setInt(3, d60.getHttpCode());
  224 + ps.setShort(4, d60.getOperCode());
  225 + ps.setString(5, d60.getRq());
  226 + ps.setString(6, d60.getSender());
  227 + ps.setLong(7, d60.getTimestamp());
  228 +
  229 + ps.setLong(8, isNvl(d60.getData().getAlarmTime()));
  230 + ps.setShort(9, isNvl(d60.getData().getCompanyCode()));
  231 + ps.setShort(10, isNvl(d60.getData().getDispatchInstruct()));
  232 + ps.setInt(11, d60.getData().getInstructType());
  233 + ps.setInt(12, d60.getData().getMsgId());
  234 + ps.setLong(13, d60.getData().getServiceState());
  235 + ps.setString(14, d60.getData().getTxtContent());
  236 + ps.setBoolean(15, d60.isDispatch());
  237 +
  238 + ps.setString(16, isNvl(d60.getLineCode()));
  239 + ps.setShort(17, isNvl(d60.getReply46()));
  240 +
  241 + if(null == d60.getReply46Time())
  242 + ps.setNull(18, Types.BIGINT);
  243 + else
  244 + ps.setLong(18, d60.getReply46Time());
  245 +
  246 + ps.setShort(19, isNvl(d60.getReply47()));
  247 +
  248 + if(null == d60.getReply47Time())
  249 + ps.setNull(20, Types.BIGINT);
  250 + else
  251 + ps.setLong(20, d60.getReply47Time());
  252 +
  253 + if(d60.getSch()==null)
  254 + ps.setNull(21, Types.BIGINT);
  255 + else
  256 + ps.setLong(21, d60.getSch().getId());
  257 + }
  258 +
  259 + @Override
  260 + public int getBatchSize() {
  261 + return d60s.size();
  262 + }
  263 + });
  264 + }catch (Exception e){
  265 + logger.error(String.format("错误数据:%s", JSON.toJSONString(d60s)), e);
  266 + status.setRollbackOnly();
257 } 267 }
258 -  
259 - @Override  
260 - public int getBatchSize() {  
261 - return d60s.size();  
262 - }  
263 - });  
264 -  
265 - tran.commit(status);  
266 -  
267 - logger.info("60 入库成功: " + d60s.size());  
268 - }catch (Exception e){  
269 - logger.error(String.format("错误数据:%s", JSON.toJSONString(d60s)), e);  
270 - tran.rollback(status);  
271 - } 268 + }
  269 + });
  270 + logger.warn("60指令保存结束");
272 } 271 }
273 272
274 private String isNvl(String v) { 273 private String isNvl(String v) {
src/main/java/com/bsth/data/forecast/SampleTimeDataLoader.java
1 -package com.bsth.data.forecast;  
2 -  
3 -import java.util.ArrayList;  
4 -import java.util.Collections;  
5 -import java.util.Comparator;  
6 -import java.util.Date;  
7 -import java.util.Iterator;  
8 -import java.util.List;  
9 -import java.util.Set;  
10 -  
11 -import org.joda.time.format.DateTimeFormat;  
12 -import org.joda.time.format.DateTimeFormatter;  
13 -import org.slf4j.Logger;  
14 -import org.slf4j.LoggerFactory;  
15 -import org.springframework.beans.factory.annotation.Autowired;  
16 -import org.springframework.stereotype.Component;  
17 -  
18 -import com.bsth.data.forecast.entity.SimpleRoute;  
19 -import com.bsth.data.forecast.entity.SimpleRoute.TimeRange;  
20 -import com.bsth.entity.StationRoute;  
21 -import com.bsth.entity.forecast.Sample;  
22 -import com.bsth.repository.StationRouteRepository;  
23 -import com.bsth.repository.forecast.SampleRepository;  
24 -import com.google.common.collect.ArrayListMultimap;  
25 -  
26 -/**  
27 - *  
28 - * @Title: loadData  
29 - * @Description: TODO(从数据库加载数据)  
30 - */  
31 -@Component  
32 -public class SampleTimeDataLoader extends Thread {  
33 -  
34 - @Autowired  
35 - SampleRepository sampleRepository;  
36 -  
37 - @Autowired  
38 - StationRouteRepository stationRouteRepository;  
39 -  
40 - // 当天日期  
41 - String rq;  
42 -  
43 - private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm")  
44 - ,fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd");  
45 -  
46 - Logger logger = LoggerFactory.getLogger(this.getClass());  
47 -  
48 - @Override  
49 - public void run() {  
50 - rq = fmtyyyyMMdd.print(new Date().getTime());  
51 -  
52 - Iterator<Sample> iterator = sampleRepository.findAll().iterator();  
53 - ArrayListMultimap<String, Sample> sampleMap = ArrayListMultimap.create();  
54 -  
55 - Sample sample;  
56 - String key;  
57 - while (iterator.hasNext()) {  
58 - sample = iterator.next();  
59 - key = sample.getLineCode() + "_" + sample.getUpdown() + "_" + sample.getsStation() + "_"  
60 - + sample.geteStation();  
61 - sampleMap.put(key, sample);  
62 - }  
63 -  
64 - // 加载全部路由信息  
65 - List<StationRoute> allRoutes = stationRouteRepository.findAllEffective();  
66 - // 线路和走向分组  
67 - ArrayListMultimap<String, StationRoute> groupMap = ArrayListMultimap.create();  
68 - for (StationRoute sr : allRoutes)  
69 - groupMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr);  
70 -  
71 - ArrayListMultimap<String, SimpleRoute> lineSampleMapCopy = ArrayListMultimap.create();  
72 - // 排序路由链并附加各个时区耗时信息  
73 - StationRouteComp comp = new StationRouteComp();  
74 - Set<String> kys = groupMap.keySet();  
75 - List<StationRoute> routeList;  
76 - StationRoute sRoute;  
77 -  
78 - List<Sample> sapList;  
79 - for (String k : kys) {  
80 - routeList = groupMap.get(k);  
81 - // 排序  
82 - Collections.sort(routeList, comp);  
83 -  
84 - for (int i = 1; i < routeList.size(); i++) {  
85 - sRoute = routeList.get(i);  
86 -  
87 - sapList = sampleMap.get(k + "_" +routeList.get(i - 1).getStationCode() + "_" + sRoute.getStationCode());  
88 -  
89 - lineSampleMapCopy.put(k, createSimpleRoute(sRoute, sapList));  
90 - }  
91 - }  
92 -  
93 - ForecastRealServer.lineSampleMap = lineSampleMapCopy;  
94 - logger.info("SampleTimeDataLoader.... over...");  
95 - }  
96 -  
97 - private SimpleRoute createSimpleRoute(StationRoute sRoute, List<Sample> list) {  
98 - SimpleRoute simple = new SimpleRoute();  
99 -  
100 - simple.stationCode = sRoute.getStationCode();  
101 - simple.ranges = new ArrayList<>();  
102 -  
103 - try{  
104 - TimeRange tg;  
105 - for (Sample s : list) {  
106 - tg = new TimeRange();  
107 -  
108 - tg.startTime = fmtyyyyMMddHHmm.parseMillis(rq + s.getsDate());  
109 - tg.endTime = fmtyyyyMMddHHmm.parseMillis(rq + s.geteDate());  
110 - tg.runTime = s.getRunTime();  
111 - simple.ranges.add(tg);  
112 - }  
113 -  
114 - //排序  
115 - Collections.sort(simple.ranges);  
116 - }catch(Exception e){  
117 - logger.error("", e);  
118 - }  
119 - return simple;  
120 - }  
121 -  
122 - public static class StationRouteComp implements Comparator<StationRoute> {  
123 -  
124 - @Override  
125 - public int compare(StationRoute o1, StationRoute o2) {  
126 - return o1.getStationRouteCode() - o2.getStationRouteCode();  
127 - }  
128 - }  
129 -} 1 +package com.bsth.data.forecast;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.Collections;
  5 +import java.util.Comparator;
  6 +import java.util.Date;
  7 +import java.util.Iterator;
  8 +import java.util.List;
  9 +import java.util.Set;
  10 +
  11 +import org.joda.time.format.DateTimeFormat;
  12 +import org.joda.time.format.DateTimeFormatter;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.stereotype.Component;
  17 +
  18 +import com.bsth.data.forecast.entity.SimpleRoute;
  19 +import com.bsth.data.forecast.entity.SimpleRoute.TimeRange;
  20 +import com.bsth.entity.StationRoute;
  21 +import com.bsth.entity.forecast.Sample;
  22 +import com.bsth.repository.StationRouteRepository;
  23 +import com.bsth.repository.forecast.SampleRepository;
  24 +import com.google.common.collect.ArrayListMultimap;
  25 +
  26 +/**
  27 + *
  28 + * @Title: loadData
  29 + * @Description: TODO(从数据库加载数据)
  30 + */
  31 +@Component
  32 +public class SampleTimeDataLoader extends Thread {
  33 +
  34 + @Autowired
  35 + SampleRepository sampleRepository;
  36 +
  37 + @Autowired
  38 + StationRouteRepository stationRouteRepository;
  39 +
  40 + // 当天日期
  41 + String rq;
  42 +
  43 + private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm")
  44 + ,fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd");
  45 +
  46 + Logger logger = LoggerFactory.getLogger(this.getClass());
  47 +
  48 + @Override
  49 + public void run() {
  50 + logger.warn("到离站预测样本加载开始");
  51 + rq = fmtyyyyMMdd.print(System.currentTimeMillis());
  52 +
  53 + Iterator<Sample> iterator = sampleRepository.findAll().iterator();
  54 + ArrayListMultimap<String, Sample> sampleMap = ArrayListMultimap.create();
  55 +
  56 + Sample sample;
  57 + String key;
  58 + while (iterator.hasNext()) {
  59 + sample = iterator.next();
  60 + key = sample.getLineCode() + "_" + sample.getUpdown() + "_" + sample.getsStation() + "_"
  61 + + sample.geteStation();
  62 + sampleMap.put(key, sample);
  63 + }
  64 +
  65 + // 加载全部路由信息
  66 + List<StationRoute> allRoutes = stationRouteRepository.findAllEffective();
  67 + // 线路和走向分组
  68 + ArrayListMultimap<String, StationRoute> groupMap = ArrayListMultimap.create();
  69 + for (StationRoute sr : allRoutes)
  70 + groupMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr);
  71 +
  72 + ArrayListMultimap<String, SimpleRoute> lineSampleMapCopy = ArrayListMultimap.create();
  73 + // 排序路由链并附加各个时区耗时信息
  74 + StationRouteComp comp = new StationRouteComp();
  75 + Set<String> kys = groupMap.keySet();
  76 + List<StationRoute> routeList;
  77 + StationRoute sRoute;
  78 +
  79 + List<Sample> sapList;
  80 + for (String k : kys) {
  81 + routeList = groupMap.get(k);
  82 + // 排序
  83 + Collections.sort(routeList, comp);
  84 +
  85 + for (int i = 1; i < routeList.size(); i++) {
  86 + sRoute = routeList.get(i);
  87 +
  88 + sapList = sampleMap.get(k + "_" +routeList.get(i - 1).getStationCode() + "_" + sRoute.getStationCode());
  89 +
  90 + lineSampleMapCopy.put(k, createSimpleRoute(sRoute, sapList));
  91 + }
  92 + }
  93 +
  94 + ForecastRealServer.lineSampleMap = lineSampleMapCopy;
  95 + logger.warn("到离站预测样本加载结束");
  96 + }
  97 +
  98 + private SimpleRoute createSimpleRoute(StationRoute sRoute, List<Sample> list) {
  99 + SimpleRoute simple = new SimpleRoute();
  100 +
  101 + simple.stationCode = sRoute.getStationCode();
  102 + simple.ranges = new ArrayList<>();
  103 +
  104 + try{
  105 + TimeRange tg;
  106 + for (Sample s : list) {
  107 + tg = new TimeRange();
  108 +
  109 + tg.startTime = fmtyyyyMMddHHmm.parseMillis(rq + s.getsDate());
  110 + tg.endTime = fmtyyyyMMddHHmm.parseMillis(rq + s.geteDate());
  111 + tg.runTime = s.getRunTime();
  112 + simple.ranges.add(tg);
  113 + }
  114 +
  115 + //排序
  116 + Collections.sort(simple.ranges);
  117 + }catch(Exception e){
  118 + logger.error("", e);
  119 + }
  120 + return simple;
  121 + }
  122 +
  123 + public static class StationRouteComp implements Comparator<StationRoute> {
  124 +
  125 + @Override
  126 + public int compare(StationRoute o1, StationRoute o2) {
  127 + return o1.getStationRouteCode() - o2.getStationRouteCode();
  128 + }
  129 + }
  130 +}
src/main/java/com/bsth/data/gpsdata_v2/GpsRealData.java
1 -package com.bsth.data.gpsdata_v2;  
2 -  
3 -import com.bsth.data.BasicData;  
4 -import com.bsth.data.forecast.ForecastRealServer;  
5 -import com.bsth.data.gpsdata_v2.entity.GpsEntity;  
6 -import com.bsth.data.schedule.DayOfSchedule;  
7 -import com.bsth.entity.realcontrol.ScheduleRealInfo;  
8 -import com.bsth.service.realcontrol.impl.ScheduleRealInfoServiceImpl;  
9 -import com.google.common.collect.TreeMultimap;  
10 -import org.apache.commons.lang3.StringUtils;  
11 -import org.slf4j.Logger;  
12 -import org.slf4j.LoggerFactory;  
13 -import org.springframework.beans.factory.annotation.Autowired;  
14 -import org.springframework.stereotype.Component;  
15 -  
16 -import java.util.*;  
17 -import java.util.concurrent.ConcurrentHashMap;  
18 -import java.util.concurrent.ConcurrentMap;  
19 -  
20 -/**  
21 - * @author PanZhao  
22 - * @ClassName: GpsRealData  
23 - * @Description: TODO(实时GPS数据集合)  
24 - * @date 2016年8月12日 下午2:04:41  
25 - */  
26 -@Component  
27 -public class GpsRealData {  
28 -  
29 - static Logger logger = LoggerFactory.getLogger(GpsRealData.class);  
30 -  
31 - private static ConcurrentMap<String, GpsEntity> gpsMap;  
32 -  
33 - //按线路分组设备号  
34 - private static TreeMultimap<String, String> lineCode2Devices;  
35 -  
36 - @Autowired  
37 - DayOfSchedule dayOfSchedule;  
38 -  
39 - @Autowired  
40 - ForecastRealServer forecastRealServer;  
41 -  
42 - /**  
43 - * 构造函数  
44 - */  
45 - public GpsRealData() {  
46 - gpsMap = new ConcurrentHashMap<>();  
47 - lineCode2Devices = TreeMultimap.create();  
48 - }  
49 -  
50 -  
51 - public void put(GpsEntity gps) {  
52 - String device = gps.getDeviceId();  
53 - GpsEntity old = gpsMap.get(device);  
54 -  
55 - try {  
56 - if (!StringUtils.isEmpty(gps.getStopNo())) {  
57 - //站点编码改变  
58 - if (null == old || !gps.getStopNo().equals(old.getStopNo())) {  
59 - gps.setArrTime(gps.getTimestamp());  
60 - //预测到达终点时间  
61 - forecastRealServer.forecast(gps.getNbbm(), gps);  
62 - } else {  
63 - gps.setArrTime(old.getArrTime());  
64 - //不预测, 重新计算终点时间  
65 - gps.setExpectStopTime(forecastRealServer.expectStopTime(gps.getNbbm()));  
66 - }  
67 - }  
68 -  
69 - //刷新对照  
70 - gpsMap.put(device, gps);  
71 - if (StringUtils.isNotBlank(gps.getLineId())) {  
72 - //站点名称  
73 - gps.setStationName(getStationName(gps));  
74 - lineCode2Devices.put(gps.getLineId(), device);  
75 -  
76 - if(old != null && !gps.getLineId().equals(old.getLineId()))  
77 - lineCode2Devices.remove(old.getLineId(), device);  
78 - }  
79 -  
80 - //车辆换设备了  
81 - String nbbm = gps.getNbbm();  
82 - if(old != null && StringUtils.isNotEmpty(nbbm) && !nbbm.equals(old.getNbbm())){  
83 - List<GpsEntity> list = findByNbbm(nbbm);  
84 - for(GpsEntity g : list){  
85 - if(!g.getDeviceId().equals(device))  
86 - gpsMap.remove(g.getDeviceId());  
87 - }  
88 - }  
89 - } catch (Exception e) {  
90 - logger.error("", e);  
91 - }  
92 - }  
93 -  
94 - public String getStationName(GpsEntity gps) {  
95 - return BasicData.getStationNameByCode(gps.getStopNo(), gps.getLineId() + "_" + gps.getUpDown() + "_");  
96 - }  
97 -  
98 - /**  
99 - * @Title: get @Description: TODO(设备号获取GPS)  
100 - */  
101 - public static GpsEntity get(String deviceId) {  
102 - return gpsMap.get(deviceId);  
103 - }  
104 -  
105 - public List<GpsEntity> findByNbbm(String nbbm){  
106 - Collection<GpsEntity> arr = gpsMap.values();  
107 - List<GpsEntity> rs = new ArrayList<>();  
108 - for(GpsEntity g : arr){  
109 - if(nbbm.equals(g.getNbbm()))  
110 - rs.add(g);  
111 - }  
112 - return rs;  
113 - }  
114 -  
115 - public GpsEntity getByNbbm(String nbbm){  
116 - String device = BasicData.deviceId2NbbmMap.inverse().get(nbbm);  
117 - if(StringUtils.isNotBlank(device))  
118 - return get(device);  
119 - else  
120 - return null;  
121 - }  
122 -  
123 - /**  
124 - * @Title: get @Description: TODO(线路编码获取GPS集合) @throws  
125 - */  
126 - public List<GpsEntity> getByLine(String lineCode) {  
127 - NavigableSet<String> set = lineCode2Devices.get(lineCode);//实际车载  
128 - if(null == set)  
129 - set = new TreeSet();  
130 - Set<String> nbbmSet = dayOfSchedule.findCarByLineCode(lineCode);//计划用车  
131 -  
132 - Map<String, String> nbbm2deviceMap = BasicData.deviceId2NbbmMap.inverse();  
133 - String deviceId;  
134 - for(String nbbm : nbbmSet){  
135 - deviceId = nbbm2deviceMap.get(nbbm);  
136 - if(StringUtils.isNotEmpty(deviceId))  
137 - set.add(deviceId);  
138 - }  
139 -  
140 - List<GpsEntity> rs = new ArrayList<>();  
141 - GpsEntity gps;  
142 - ScheduleRealInfo sch;  
143 - for (String device : set) {  
144 - gps = gpsMap.get(device);  
145 - //过滤异常GPS数据  
146 - if (gps == null || StringUtils.isBlank(gps.getNbbm()))  
147 - continue;  
148 -  
149 - sch = dayOfSchedule.execPlanMap().get(gps.getNbbm());  
150 - if (null != sch){  
151 - gps.setSchId(sch.getId());  
152 - if(!sch.getXlBm().equals(lineCode)){  
153 - //车辆在其他线路营运  
154 - gps.setRemark("执行 " + sch.getXlName() + " " + sch.getDfsj() + " 班次");  
155 - gps.setPlanCode(sch.getXlBm());  
156 - }  
157 - }else  
158 - gps.setRemark(null);  
159 -  
160 - gps.setDvrcode(ScheduleRealInfoServiceImpl.DIRMAP.get(BasicData.deviceId2NbbmMap.get(gps.getDeviceId())));;  
161 - rs.add(gps);  
162 - }  
163 -  
164 - return rs;  
165 - }  
166 -  
167 - public static Set<String> findDevices(String lineCode){  
168 - return lineCode2Devices.get(lineCode);  
169 - }  
170 -  
171 - public List<GpsEntity> get(List<String> pArray) {  
172 - List<GpsEntity> list = new ArrayList<>();  
173 -  
174 - for (String code : pArray)  
175 - list.addAll(getByLine(code));  
176 - return list;  
177 - }  
178 -  
179 - public Set<String> allDevices() {  
180 - return gpsMap.keySet();  
181 - }  
182 -  
183 - public Collection<GpsEntity> all() {  
184 - return gpsMap.values();  
185 - }  
186 -  
187 - public void remove(String device) {  
188 - gpsMap.remove(device);  
189 - } 1 +package com.bsth.data.gpsdata_v2;
  2 +
  3 +import com.bsth.data.BasicData;
  4 +import com.bsth.data.forecast.ForecastRealServer;
  5 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  6 +import com.bsth.data.schedule.DayOfSchedule;
  7 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  8 +import com.bsth.message.buffer.CarEnergyBuffer;
  9 +import com.bsth.service.realcontrol.impl.ScheduleRealInfoServiceImpl;
  10 +import com.google.common.collect.TreeMultimap;
  11 +import org.apache.commons.lang3.StringUtils;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +import java.util.*;
  18 +import java.util.concurrent.ConcurrentHashMap;
  19 +import java.util.concurrent.ConcurrentMap;
  20 +
  21 +/**
  22 + * @author PanZhao
  23 + * @ClassName: GpsRealData
  24 + * @Description: TODO(实时GPS数据集合)
  25 + * @date 2016年8月12日 下午2:04:41
  26 + */
  27 +@Component
  28 +public class GpsRealData {
  29 +
  30 + static Logger logger = LoggerFactory.getLogger(GpsRealData.class);
  31 +
  32 + private static ConcurrentMap<String, GpsEntity> gpsMap;
  33 +
  34 + //按线路分组设备号
  35 + private static TreeMultimap<String, String> lineCode2Devices;
  36 +
  37 + @Autowired
  38 + DayOfSchedule dayOfSchedule;
  39 +
  40 + @Autowired
  41 + ForecastRealServer forecastRealServer;
  42 +
  43 + /**
  44 + * 构造函数
  45 + */
  46 + public GpsRealData() {
  47 + gpsMap = new ConcurrentHashMap<>();
  48 + lineCode2Devices = TreeMultimap.create();
  49 + }
  50 +
  51 +
  52 + public void put(GpsEntity gps) {
  53 + String device = gps.getDeviceId();
  54 + GpsEntity old = gpsMap.get(device);
  55 +
  56 + try {
  57 + if (!StringUtils.isEmpty(gps.getStopNo())) {
  58 + //站点编码改变
  59 + if (null == old || !gps.getStopNo().equals(old.getStopNo())) {
  60 + gps.setArrTime(gps.getTimestamp());
  61 + //预测到达终点时间
  62 + forecastRealServer.forecast(gps.getNbbm(), gps);
  63 + } else {
  64 + gps.setArrTime(old.getArrTime());
  65 + //不预测, 重新计算终点时间
  66 + gps.setExpectStopTime(forecastRealServer.expectStopTime(gps.getNbbm()));
  67 + }
  68 + }
  69 +
  70 + //刷新对照
  71 + gpsMap.put(device, gps);
  72 + if (StringUtils.isNotBlank(gps.getLineId())) {
  73 + //站点名称
  74 + gps.setStationName(getStationName(gps));
  75 + lineCode2Devices.put(gps.getLineId(), device);
  76 +
  77 + if(old != null && !gps.getLineId().equals(old.getLineId()))
  78 + lineCode2Devices.remove(old.getLineId(), device);
  79 + }
  80 +
  81 + //车辆换设备了
  82 + String nbbm = gps.getNbbm();
  83 + if(old != null && StringUtils.isNotEmpty(nbbm) && !nbbm.equals(old.getNbbm())){
  84 + List<GpsEntity> list = findByNbbm(nbbm);
  85 + for(GpsEntity g : list){
  86 + if(!g.getDeviceId().equals(device))
  87 + gpsMap.remove(g.getDeviceId());
  88 + }
  89 + }
  90 +
  91 + // 设置车辆的电量
  92 + gps.setEnergy(CarEnergyBuffer.getCarEnergy(gps.getNbbm()));
  93 + } catch (Exception e) {
  94 + logger.error("", e);
  95 + }
  96 + }
  97 +
  98 + public String getStationName(GpsEntity gps) {
  99 + return BasicData.getStationNameByCode(gps.getStopNo(), gps.getLineId() + "_" + gps.getUpDown() + "_");
  100 + }
  101 +
  102 + /**
  103 + * @Title: get @Description: TODO(设备号获取GPS)
  104 + */
  105 + public static GpsEntity get(String deviceId) {
  106 + return gpsMap.get(deviceId);
  107 + }
  108 +
  109 + public List<GpsEntity> findByNbbm(String nbbm){
  110 + Collection<GpsEntity> arr = gpsMap.values();
  111 + List<GpsEntity> rs = new ArrayList<>();
  112 + for(GpsEntity g : arr){
  113 + if(nbbm.equals(g.getNbbm()))
  114 + rs.add(g);
  115 + }
  116 + return rs;
  117 + }
  118 +
  119 + public GpsEntity getByNbbm(String nbbm){
  120 + String device = BasicData.deviceId2NbbmMap.inverse().get(nbbm);
  121 + if(StringUtils.isNotBlank(device))
  122 + return get(device);
  123 + else
  124 + return null;
  125 + }
  126 +
  127 + /**
  128 + * @Title: get @Description: TODO(线路编码获取GPS集合) @throws
  129 + */
  130 + public List<GpsEntity> getByLine(String lineCode) {
  131 + NavigableSet<String> set = lineCode2Devices.get(lineCode);//实际车载
  132 + if(null == set)
  133 + set = new TreeSet();
  134 + Set<String> nbbmSet = dayOfSchedule.findCarByLineCode(lineCode);//计划用车
  135 +
  136 + Map<String, String> nbbm2deviceMap = BasicData.deviceId2NbbmMap.inverse();
  137 + String deviceId;
  138 + for(String nbbm : nbbmSet){
  139 + deviceId = nbbm2deviceMap.get(nbbm);
  140 + if(StringUtils.isNotEmpty(deviceId))
  141 + set.add(deviceId);
  142 + }
  143 +
  144 + List<GpsEntity> rs = new ArrayList<>();
  145 + GpsEntity gps;
  146 + ScheduleRealInfo sch;
  147 + for (String device : set) {
  148 + gps = gpsMap.get(device);
  149 + //过滤异常GPS数据
  150 + if (gps == null || StringUtils.isBlank(gps.getNbbm()))
  151 + continue;
  152 +
  153 + sch = dayOfSchedule.execPlanMap().get(gps.getNbbm());
  154 + if (null != sch){
  155 + gps.setSchId(sch.getId());
  156 + if(!sch.getXlBm().equals(lineCode)){
  157 + //车辆在其他线路营运
  158 + gps.setRemark("执行 " + sch.getXlName() + " " + sch.getDfsj() + " 班次");
  159 + gps.setPlanCode(sch.getXlBm());
  160 + }
  161 + }else
  162 + gps.setRemark(null);
  163 +
  164 + gps.setDvrcode(ScheduleRealInfoServiceImpl.DIRMAP.get(BasicData.deviceId2NbbmMap.get(gps.getDeviceId())));;
  165 + rs.add(gps);
  166 + }
  167 +
  168 + return rs;
  169 + }
  170 +
  171 + public static Set<String> findDevices(String lineCode){
  172 + return lineCode2Devices.get(lineCode);
  173 + }
  174 +
  175 + public List<GpsEntity> get(List<String> pArray) {
  176 + List<GpsEntity> list = new ArrayList<>();
  177 +
  178 + for (String code : pArray)
  179 + list.addAll(getByLine(code));
  180 + return list;
  181 + }
  182 +
  183 + public Set<String> allDevices() {
  184 + return gpsMap.keySet();
  185 + }
  186 +
  187 + public Collection<GpsEntity> all() {
  188 + return gpsMap.values();
  189 + }
  190 +
  191 + public void remove(String device) {
  192 + gpsMap.remove(device);
  193 + }
190 } 194 }
191 \ No newline at end of file 195 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata_v2/entity/GpsEntity.java
1 -package com.bsth.data.gpsdata_v2.entity;  
2 -  
3 -import com.fasterxml.jackson.annotation.JsonIgnore;  
4 -  
5 -/**  
6 - *  
7 - * @ClassName: GpsRealData  
8 - * @Description: TODO(HTTP接口的实时GPS数据)  
9 - * @author PanZhao  
10 - * @date 2016年5月11日 下午4:32:07  
11 - *  
12 - */  
13 -public class GpsEntity implements Cloneable{  
14 -  
15 - /** 公司代码 */  
16 - @JsonIgnore  
17 - private Short companyCode;  
18 -  
19 - /** 线路编码 */  
20 - private String lineId;  
21 -  
22 - /** 设备编码 */  
23 - private String deviceId;  
24 -  
25 - /** 停车场编码 */  
26 - private String carparkNo;  
27 -  
28 - /** 站点编码 */  
29 - private String stopNo;  
30 -  
31 - /** 站点名称 */  
32 - private String stationName;  
33 -  
34 - /** 到站时间 */  
35 - @JsonIgnore  
36 - private long arrTime;  
37 -  
38 - /** 经度 */  
39 - private Float lon;  
40 -  
41 - /** 纬度 */  
42 - private Float lat;  
43 -  
44 - /** GPS发送时间戳 */  
45 - private Long timestamp;  
46 -  
47 - /** 网关收到时间 */  
48 - private Long serverTimestamp;  
49 -  
50 - /** 速度 */  
51 - private Float speed;  
52 -  
53 - /** 方向(角度) */  
54 - private float direction;  
55 -  
56 - /** 营运状态( 0 营运 ,1 非营运, -1 无效) */  
57 - private Integer state;  
58 -  
59 - /** 上下行(0 上行 , 1 下行 , -1 无效) */  
60 - private Byte upDown;  
61 -  
62 - /**  
63 - * 设备原始走向_营运状态  
64 - * 当设备状态和系统不一致时,该字段有值  
65 - */  
66 - private String origStateStr;  
67 -  
68 - /** 车辆内部编码 */  
69 - private String nbbm;  
70 -  
71 - /** 预计到达终点时间 */  
72 - private Float expectStopTime;  
73 -  
74 - /** 当前执行班次ID */  
75 - private Long schId;  
76 -  
77 - private int version;  
78 -  
79 - /** 0: 站外 1:站内 2:场内 */  
80 - private int instation;  
81 -  
82 - /** 站点信息,站内时有值 */  
83 - @JsonIgnore  
84 - private StationRoute station;  
85 -  
86 - /**  
87 - * 前置约束 -站点编码  
88 - */  
89 - @JsonIgnore  
90 - private String premiseCode;  
91 -  
92 - /** 状态 */  
93 - private String signalState = "normal";  
94 -  
95 - /** 异常状态 */  
96 - private String abnormalStatus;  
97 -  
98 - /** 越界距离 */  
99 - private double outOfBoundDistance;  
100 -  
101 - /** gps是否有效 设备端发送的状态 */  
102 - private int valid;  
103 -  
104 - /**  
105 - * 数据来源  
106 - * 1:网关  
107 - * 0:转发  
108 - */  
109 - private int source = -1;  
110 -  
111 - private String remark;  
112 - private String planCode;  
113 -  
114 - private String dvrcode;  
115 -  
116 - public Object clone() {  
117 - try {  
118 - return super.clone();  
119 - } catch (CloneNotSupportedException e) {  
120 - return null;  
121 - }  
122 - }  
123 -  
124 - public String getDvrcode() {  
125 - return dvrcode;  
126 - }  
127 -  
128 - public void setDvrcode(String dvrcode) {  
129 - this.dvrcode = dvrcode;  
130 - }  
131 -  
132 - public String getDeviceId() {  
133 - return deviceId;  
134 - }  
135 -  
136 - public void setDeviceId(String deviceId) {  
137 - this.deviceId = deviceId;  
138 - }  
139 -  
140 - public String getCarparkNo() {  
141 - return carparkNo;  
142 - }  
143 -  
144 - public void setCarparkNo(String carparkNo) {  
145 - this.carparkNo = carparkNo;  
146 - }  
147 -  
148 - public String getStopNo() {  
149 - return stopNo;  
150 - }  
151 -  
152 - public void setStopNo(String stopNo) {  
153 - this.stopNo = stopNo;  
154 - }  
155 -  
156 - public Float getLon() {  
157 - return lon;  
158 - }  
159 -  
160 - public void setLon(Float lon) {  
161 - this.lon = lon;  
162 - }  
163 -  
164 - public Float getLat() {  
165 - return lat;  
166 - }  
167 -  
168 - public void setLat(Float lat) {  
169 - this.lat = lat;  
170 - }  
171 -  
172 - public Long getTimestamp() {  
173 - return timestamp;  
174 - }  
175 -  
176 - public void setTimestamp(Long timestamp) {  
177 - this.timestamp = timestamp;  
178 - }  
179 -  
180 -  
181 - public Integer getState() {  
182 - return state;  
183 - }  
184 -  
185 - public void setState(Integer state) {  
186 - this.state = state;  
187 - }  
188 -  
189 - public String getNbbm() {  
190 - return nbbm;  
191 - }  
192 -  
193 - public void setNbbm(String nbbm) {  
194 - this.nbbm = nbbm;  
195 - }  
196 -  
197 - public String getStationName() {  
198 - return stationName;  
199 - }  
200 -  
201 - public void setStationName(String stationName) {  
202 - this.stationName = stationName;  
203 - }  
204 -  
205 - public long getArrTime() {  
206 - return arrTime;  
207 - }  
208 -  
209 - public void setArrTime(long arrTime) {  
210 - this.arrTime = arrTime;  
211 - }  
212 -  
213 - public Float getExpectStopTime() {  
214 - return expectStopTime;  
215 - }  
216 -  
217 - public void setExpectStopTime(Float expectStopTime) {  
218 - this.expectStopTime = expectStopTime;  
219 - }  
220 -  
221 - public String getLineId() {  
222 - return lineId;  
223 - }  
224 -  
225 - public void setLineId(String lineId) {  
226 - this.lineId = lineId;  
227 - }  
228 -  
229 - public Long getSchId() {  
230 - return schId;  
231 - }  
232 -  
233 - public void setSchId(Long schId) {  
234 - this.schId = schId;  
235 - }  
236 -  
237 -  
238 - public int getVersion() {  
239 - return version;  
240 - }  
241 -  
242 - public void setVersion(int version) {  
243 - this.version = version;  
244 - }  
245 -  
246 - public StationRoute getStation() {  
247 - return station;  
248 - }  
249 -  
250 - public void setStation(StationRoute station) {  
251 - this.station = station;  
252 - }  
253 -  
254 - public String getSignalState() {  
255 - return signalState;  
256 - }  
257 -  
258 - public void setSignalState(String signalState) {  
259 - this.signalState = signalState;  
260 - }  
261 -  
262 - public int getInstation() {  
263 - return instation;  
264 - }  
265 -  
266 - public void setInstation(int instation) {  
267 - this.instation = instation;  
268 - }  
269 -  
270 - public String getAbnormalStatus() {  
271 - return abnormalStatus;  
272 - }  
273 -  
274 - public void setAbnormalStatus(String abnormalStatus) {  
275 - this.abnormalStatus = abnormalStatus;  
276 - }  
277 -  
278 - public double getOutOfBoundDistance() {  
279 - return outOfBoundDistance;  
280 - }  
281 -  
282 - public void setOutOfBoundDistance(double outOfBoundDistance) {  
283 - this.outOfBoundDistance = outOfBoundDistance;  
284 - }  
285 -  
286 - public int getValid() {  
287 - return valid;  
288 - }  
289 -  
290 - public void setValid(int valid) {  
291 - this.valid = valid;  
292 - }  
293 -  
294 -  
295 -  
296 - public short getCompanyCode() {  
297 - return companyCode;  
298 - }  
299 -  
300 - public void setCompanyCode(short companyCode) {  
301 - this.companyCode = companyCode;  
302 - }  
303 -  
304 - public Byte getUpDown() {  
305 - return upDown;  
306 - }  
307 -  
308 - public void setUpDown(Byte upDown) {  
309 - this.upDown = upDown;  
310 - }  
311 -  
312 -  
313 - public float getDirection() {  
314 - return direction;  
315 - }  
316 -  
317 - public void setDirection(float direction) {  
318 - this.direction = direction;  
319 - }  
320 -  
321 - public Float getSpeed() {  
322 - return speed;  
323 - }  
324 -  
325 - public void setSpeed(Float speed) {  
326 - this.speed = speed;  
327 - }  
328 -  
329 - public int getSource() {  
330 - return source;  
331 - }  
332 -  
333 - public void setSource(int source) {  
334 - this.source = source;  
335 - }  
336 -  
337 - public void offline(){  
338 - this.setAbnormalStatus("offline");  
339 - }  
340 -  
341 -/* public boolean isOnline(){  
342 - if(isOffline())  
343 - return false;  
344 -  
345 - long t = System.currentTimeMillis();  
346 -  
347 - if((t - this.getServerTimestamp()) > 1000 * 60 * 2){  
348 - return false;  
349 - }  
350 -  
351 - if((this.getServerTimestamp() - t) > 1000 * 60 * 3){  
352 - return false;  
353 - }  
354 - return true;  
355 - }*/  
356 -  
357 - /**  
358 - * 是否营运  
359 - * @return  
360 - */  
361 - public boolean isService(){  
362 - return state!=null && state==0;  
363 - }  
364 -  
365 - public boolean isOffline(){  
366 - return this.getAbnormalStatus() != null && this.getAbnormalStatus().equals("offline");  
367 - }  
368 -  
369 - public Long getServerTimestamp() {  
370 - return serverTimestamp;  
371 - }  
372 -  
373 - public void setServerTimestamp(Long serverTimestamp) {  
374 - this.serverTimestamp = serverTimestamp;  
375 - }  
376 -  
377 - public String getPremiseCode() {  
378 - return premiseCode;  
379 - }  
380 -  
381 - public void setPremiseCode(String premiseCode) {  
382 - this.premiseCode = premiseCode;  
383 - }  
384 -  
385 - public String getRemark() {  
386 - return remark;  
387 - }  
388 -  
389 - public void setRemark(String remark) {  
390 - this.remark = remark;  
391 - }  
392 -  
393 - public String getPlanCode() {  
394 - return planCode;  
395 - }  
396 -  
397 - public void setPlanCode(String planCode) {  
398 - this.planCode = planCode;  
399 - }  
400 -  
401 - public String getOrigStateStr() {  
402 - return origStateStr;  
403 - }  
404 -  
405 - public void setOrigStateStr(String origStateStr) {  
406 - this.origStateStr = origStateStr;  
407 - }  
408 -} 1 +package com.bsth.data.gpsdata_v2.entity;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonIgnore;
  4 +
  5 +/**
  6 + *
  7 + * @ClassName: GpsRealData
  8 + * @Description: TODO(HTTP接口的实时GPS数据)
  9 + * @author PanZhao
  10 + * @date 2016年5月11日 下午4:32:07
  11 + *
  12 + */
  13 +public class GpsEntity implements Cloneable{
  14 +
  15 + /** 公司代码 */
  16 + @JsonIgnore
  17 + private Short companyCode;
  18 +
  19 + /** 线路编码 */
  20 + private String lineId;
  21 +
  22 + /** 设备编码 */
  23 + private String deviceId;
  24 +
  25 + /** 停车场编码 */
  26 + private String carparkNo;
  27 +
  28 + /** 站点编码 */
  29 + private String stopNo;
  30 +
  31 + /** 站点名称 */
  32 + private String stationName;
  33 +
  34 + /** 到站时间 */
  35 + @JsonIgnore
  36 + private long arrTime;
  37 +
  38 + /** 经度 */
  39 + private Float lon;
  40 +
  41 + /** 纬度 */
  42 + private Float lat;
  43 +
  44 + /** GPS发送时间戳 */
  45 + private Long timestamp;
  46 +
  47 + /** 网关收到时间 */
  48 + private Long serverTimestamp;
  49 +
  50 + /** 速度 */
  51 + private Float speed;
  52 +
  53 + /** 方向(角度) */
  54 + private float direction;
  55 +
  56 + /** 营运状态( 0 营运 ,1 非营运, -1 无效) */
  57 + private Integer state;
  58 +
  59 + /** 上下行(0 上行 , 1 下行 , -1 无效) */
  60 + private Byte upDown;
  61 +
  62 + /**
  63 + * 设备原始走向_营运状态
  64 + * 当设备状态和系统不一致时,该字段有值
  65 + */
  66 + private String origStateStr;
  67 +
  68 + /** 车辆内部编码 */
  69 + private String nbbm;
  70 +
  71 + /** 预计到达终点时间 */
  72 + private Float expectStopTime;
  73 +
  74 + /** 当前执行班次ID */
  75 + private Long schId;
  76 +
  77 + private int version;
  78 +
  79 + /** 0: 站外 1:站内 2:场内 */
  80 + private int instation;
  81 +
  82 + /** 站点信息,站内时有值 */
  83 + @JsonIgnore
  84 + private StationRoute station;
  85 +
  86 + /**
  87 + * 前置约束 -站点编码
  88 + */
  89 + @JsonIgnore
  90 + private String premiseCode;
  91 +
  92 + /** 状态 */
  93 + private String signalState = "normal";
  94 +
  95 + /** 异常状态 */
  96 + private String abnormalStatus;
  97 +
  98 + /** 越界距离 */
  99 + private double outOfBoundDistance;
  100 +
  101 + /** gps是否有效 设备端发送的状态 */
  102 + private int valid;
  103 +
  104 + /**
  105 + * 数据来源
  106 + * 1:网关
  107 + * 0:转发
  108 + */
  109 + private int source = -1;
  110 +
  111 + private String remark;
  112 + private String planCode;
  113 +
  114 + private String dvrcode;
  115 +
  116 + /**
  117 + * 电量 单位:%
  118 + */
  119 + private int energy = -1;
  120 +
  121 + public Object clone() {
  122 + try {
  123 + return super.clone();
  124 + } catch (CloneNotSupportedException e) {
  125 + return null;
  126 + }
  127 + }
  128 +
  129 + public String getDvrcode() {
  130 + return dvrcode;
  131 + }
  132 +
  133 + public void setDvrcode(String dvrcode) {
  134 + this.dvrcode = dvrcode;
  135 + }
  136 +
  137 + public String getDeviceId() {
  138 + return deviceId;
  139 + }
  140 +
  141 + public void setDeviceId(String deviceId) {
  142 + this.deviceId = deviceId;
  143 + }
  144 +
  145 + public String getCarparkNo() {
  146 + return carparkNo;
  147 + }
  148 +
  149 + public void setCarparkNo(String carparkNo) {
  150 + this.carparkNo = carparkNo;
  151 + }
  152 +
  153 + public String getStopNo() {
  154 + return stopNo;
  155 + }
  156 +
  157 + public void setStopNo(String stopNo) {
  158 + this.stopNo = stopNo;
  159 + }
  160 +
  161 + public Float getLon() {
  162 + return lon;
  163 + }
  164 +
  165 + public void setLon(Float lon) {
  166 + this.lon = lon;
  167 + }
  168 +
  169 + public Float getLat() {
  170 + return lat;
  171 + }
  172 +
  173 + public void setLat(Float lat) {
  174 + this.lat = lat;
  175 + }
  176 +
  177 + public Long getTimestamp() {
  178 + return timestamp;
  179 + }
  180 +
  181 + public void setTimestamp(Long timestamp) {
  182 + this.timestamp = timestamp;
  183 + }
  184 +
  185 +
  186 + public Integer getState() {
  187 + return state;
  188 + }
  189 +
  190 + public void setState(Integer state) {
  191 + this.state = state;
  192 + }
  193 +
  194 + public String getNbbm() {
  195 + return nbbm;
  196 + }
  197 +
  198 + public void setNbbm(String nbbm) {
  199 + this.nbbm = nbbm;
  200 + }
  201 +
  202 + public String getStationName() {
  203 + return stationName;
  204 + }
  205 +
  206 + public void setStationName(String stationName) {
  207 + this.stationName = stationName;
  208 + }
  209 +
  210 + public long getArrTime() {
  211 + return arrTime;
  212 + }
  213 +
  214 + public void setArrTime(long arrTime) {
  215 + this.arrTime = arrTime;
  216 + }
  217 +
  218 + public Float getExpectStopTime() {
  219 + return expectStopTime;
  220 + }
  221 +
  222 + public void setExpectStopTime(Float expectStopTime) {
  223 + this.expectStopTime = expectStopTime;
  224 + }
  225 +
  226 + public String getLineId() {
  227 + return lineId;
  228 + }
  229 +
  230 + public void setLineId(String lineId) {
  231 + this.lineId = lineId;
  232 + }
  233 +
  234 + public Long getSchId() {
  235 + return schId;
  236 + }
  237 +
  238 + public void setSchId(Long schId) {
  239 + this.schId = schId;
  240 + }
  241 +
  242 +
  243 + public int getVersion() {
  244 + return version;
  245 + }
  246 +
  247 + public void setVersion(int version) {
  248 + this.version = version;
  249 + }
  250 +
  251 + public StationRoute getStation() {
  252 + return station;
  253 + }
  254 +
  255 + public void setStation(StationRoute station) {
  256 + this.station = station;
  257 + }
  258 +
  259 + public String getSignalState() {
  260 + return signalState;
  261 + }
  262 +
  263 + public void setSignalState(String signalState) {
  264 + this.signalState = signalState;
  265 + }
  266 +
  267 + public int getInstation() {
  268 + return instation;
  269 + }
  270 +
  271 + public void setInstation(int instation) {
  272 + this.instation = instation;
  273 + }
  274 +
  275 + public String getAbnormalStatus() {
  276 + return abnormalStatus;
  277 + }
  278 +
  279 + public void setAbnormalStatus(String abnormalStatus) {
  280 + this.abnormalStatus = abnormalStatus;
  281 + }
  282 +
  283 + public double getOutOfBoundDistance() {
  284 + return outOfBoundDistance;
  285 + }
  286 +
  287 + public void setOutOfBoundDistance(double outOfBoundDistance) {
  288 + this.outOfBoundDistance = outOfBoundDistance;
  289 + }
  290 +
  291 + public int getValid() {
  292 + return valid;
  293 + }
  294 +
  295 + public void setValid(int valid) {
  296 + this.valid = valid;
  297 + }
  298 +
  299 +
  300 +
  301 + public short getCompanyCode() {
  302 + return companyCode;
  303 + }
  304 +
  305 + public void setCompanyCode(short companyCode) {
  306 + this.companyCode = companyCode;
  307 + }
  308 +
  309 + public Byte getUpDown() {
  310 + return upDown;
  311 + }
  312 +
  313 + public void setUpDown(Byte upDown) {
  314 + this.upDown = upDown;
  315 + }
  316 +
  317 +
  318 + public float getDirection() {
  319 + return direction;
  320 + }
  321 +
  322 + public void setDirection(float direction) {
  323 + this.direction = direction;
  324 + }
  325 +
  326 + public Float getSpeed() {
  327 + return speed;
  328 + }
  329 +
  330 + public void setSpeed(Float speed) {
  331 + this.speed = speed;
  332 + }
  333 +
  334 + public int getSource() {
  335 + return source;
  336 + }
  337 +
  338 + public void setSource(int source) {
  339 + this.source = source;
  340 + }
  341 +
  342 + public void offline(){
  343 + this.setAbnormalStatus("offline");
  344 + }
  345 +
  346 +/* public boolean isOnline(){
  347 + if(isOffline())
  348 + return false;
  349 +
  350 + long t = System.currentTimeMillis();
  351 +
  352 + if((t - this.getServerTimestamp()) > 1000 * 60 * 2){
  353 + return false;
  354 + }
  355 +
  356 + if((this.getServerTimestamp() - t) > 1000 * 60 * 3){
  357 + return false;
  358 + }
  359 + return true;
  360 + }*/
  361 +
  362 + /**
  363 + * 是否营运
  364 + * @return
  365 + */
  366 + public boolean isService(){
  367 + return state!=null && state==0;
  368 + }
  369 +
  370 + public boolean isOffline(){
  371 + return this.getAbnormalStatus() != null && this.getAbnormalStatus().equals("offline");
  372 + }
  373 +
  374 + public Long getServerTimestamp() {
  375 + return serverTimestamp;
  376 + }
  377 +
  378 + public void setServerTimestamp(Long serverTimestamp) {
  379 + this.serverTimestamp = serverTimestamp;
  380 + }
  381 +
  382 + public String getPremiseCode() {
  383 + return premiseCode;
  384 + }
  385 +
  386 + public void setPremiseCode(String premiseCode) {
  387 + this.premiseCode = premiseCode;
  388 + }
  389 +
  390 + public String getRemark() {
  391 + return remark;
  392 + }
  393 +
  394 + public void setRemark(String remark) {
  395 + this.remark = remark;
  396 + }
  397 +
  398 + public String getPlanCode() {
  399 + return planCode;
  400 + }
  401 +
  402 + public void setPlanCode(String planCode) {
  403 + this.planCode = planCode;
  404 + }
  405 +
  406 + public String getOrigStateStr() {
  407 + return origStateStr;
  408 + }
  409 +
  410 + public void setOrigStateStr(String origStateStr) {
  411 + this.origStateStr = origStateStr;
  412 + }
  413 +
  414 + public int getEnergy() {
  415 + return energy;
  416 + }
  417 +
  418 + public void setEnergy(int energy) {
  419 + this.energy = energy;
  420 + }
  421 +}
src/main/java/com/bsth/data/gpsdata_v2/thread/GpsDataLoaderThread.java
1 -package com.bsth.data.gpsdata_v2.thread;  
2 -  
3 -import com.bsth.data.gpsdata_v2.DataHandleProcess;  
4 -import com.bsth.data.gpsdata_v2.entity.GpsEntity;  
5 -import com.bsth.data.gpsdata_v2.load.GatewayHttpLoader;  
6 -import com.bsth.data.gpsdata_v2.load.SocketClientLoader;  
7 -import org.slf4j.Logger;  
8 -import org.slf4j.LoggerFactory;  
9 -import org.springframework.beans.factory.annotation.Autowired;  
10 -import org.springframework.stereotype.Component;  
11 -  
12 -import java.util.List;  
13 -  
14 -/**  
15 - * Created by panzhao on 2017/1/11.  
16 - */  
17 -@Component  
18 -public class GpsDataLoaderThread extends Thread {  
19 -  
20 - Logger logger = LoggerFactory.getLogger(this.getClass());  
21 -  
22 - //0:从GPS客户端内存获取 -1:从网关获取  
23 - private static int flag = 0;  
24 -  
25 - public static void setFlag(int v) {  
26 - flag = v;  
27 - }  
28 -  
29 - @Autowired  
30 - DataHandleProcess handleProcess;  
31 -  
32 - @Override  
33 - public void run() {  
34 - try {  
35 - List<GpsEntity> list;  
36 - if (flag == 0)  
37 - list = SocketClientLoader.load();  
38 - else  
39 - list = GatewayHttpLoader.load();  
40 -  
41 - if(null != list && list.size() > 0)  
42 - handleProcess.handle(list);  
43 - } catch (Exception e) {  
44 - logger.error("", e);  
45 - }  
46 - } 1 +package com.bsth.data.gpsdata_v2.thread;
  2 +
  3 +import com.bsth.data.gpsdata_v2.DataHandleProcess;
  4 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  5 +import com.bsth.data.gpsdata_v2.load.GatewayHttpLoader;
  6 +import com.bsth.data.gpsdata_v2.load.SocketClientLoader;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +import java.util.List;
  13 +
  14 +/**
  15 + * Created by panzhao on 2017/1/11.
  16 + */
  17 +@Component
  18 +public class GpsDataLoaderThread extends Thread {
  19 +
  20 + Logger logger = LoggerFactory.getLogger(this.getClass());
  21 +
  22 + //0:从GPS客户端内存获取 -1:从网关获取
  23 + private static int flag = 0;
  24 +
  25 + public static void setFlag(int v) {
  26 + flag = v;
  27 + }
  28 +
  29 + @Autowired
  30 + DataHandleProcess handleProcess;
  31 +
  32 + @Override
  33 + public void run() {
  34 + logger.warn("GPS获取数据开始");
  35 + try {
  36 + List<GpsEntity> list;
  37 + if (flag == 0)
  38 + list = SocketClientLoader.load();
  39 + else
  40 + list = GatewayHttpLoader.load();
  41 +
  42 + if(null != list && list.size() > 0)
  43 + handleProcess.handle(list);
  44 + } catch (Exception e) {
  45 + logger.error("", e);
  46 + }
  47 + logger.warn("GPS获取数据结束");
  48 + }
47 } 49 }
48 \ No newline at end of file 50 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata_v2/thread/OfflineMonitorThread.java
1 -package com.bsth.data.gpsdata_v2.thread;  
2 -  
3 -import com.bsth.data.gpsdata_v2.GpsRealData;  
4 -import com.bsth.data.gpsdata_v2.entity.GpsEntity;  
5 -import com.bsth.data.gpsdata_v2.handlers.overspeed.OverspeedProcess;  
6 -import com.bsth.websocket.handler.SendUtils;  
7 -import org.slf4j.Logger;  
8 -import org.slf4j.LoggerFactory;  
9 -import org.springframework.beans.factory.annotation.Autowired;  
10 -import org.springframework.stereotype.Component;  
11 -  
12 -import java.util.Collection;  
13 -  
14 -/**  
15 - * GPS掉离线监控  
16 - * Created by panzhao on 2017/1/11.  
17 - */  
18 -@Component  
19 -public class OfflineMonitorThread extends Thread{  
20 -  
21 - @Autowired  
22 - GpsRealData gpsRealData;  
23 -  
24 - //掉线阈值  
25 - private final static int LOSE_TIME = 1000 * 60 * 10;  
26 -  
27 - Logger logger = LoggerFactory.getLogger(this.getClass());  
28 -  
29 - @Autowired  
30 - SendUtils sendUtils;  
31 -  
32 - @Autowired  
33 - OverspeedProcess overspeedProcess;  
34 -  
35 - //无任务时 离线阈值  
36 - //private final static int OFFLINE_TIME = 1000 * 60 * 10;  
37 -  
38 - @Override  
39 - public void run() {  
40 - try{  
41 - long t = System.currentTimeMillis();  
42 - Collection<GpsEntity> list = gpsRealData.all();  
43 -  
44 - String state;  
45 - for(GpsEntity gps : list){  
46 - state = gps.getAbnormalStatus();  
47 -  
48 - if(state != null && state.equals("offline"))  
49 - continue;  
50 -  
51 - if (t - gps.getTimestamp() > LOSE_TIME){  
52 - gps.offline();  
53 -  
54 - //结束超速  
55 - overspeedProcess.offline(gps.getDeviceId());  
56 - //通知页面有设备掉线  
57 - sendUtils.deviceOffline(gps);  
58 - }  
59 - }  
60 - }catch (Exception e){  
61 - logger.error("", e);  
62 - }  
63 - }  
64 -} 1 +package com.bsth.data.gpsdata_v2.thread;
  2 +
  3 +import com.bsth.data.gpsdata_v2.GpsRealData;
  4 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  5 +import com.bsth.data.gpsdata_v2.handlers.overspeed.OverspeedProcess;
  6 +import com.bsth.websocket.handler.SendUtils;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +import java.util.Collection;
  13 +
  14 +/**
  15 + * GPS掉离线监控
  16 + * Created by panzhao on 2017/1/11.
  17 + */
  18 +@Component
  19 +public class OfflineMonitorThread extends Thread{
  20 +
  21 + @Autowired
  22 + GpsRealData gpsRealData;
  23 +
  24 + //掉线阈值
  25 + private final static int LOSE_TIME = 1000 * 60 * 10;
  26 +
  27 + Logger logger = LoggerFactory.getLogger(this.getClass());
  28 +
  29 + @Autowired
  30 + SendUtils sendUtils;
  31 +
  32 + @Autowired
  33 + OverspeedProcess overspeedProcess;
  34 +
  35 + //无任务时 离线阈值
  36 + //private final static int OFFLINE_TIME = 1000 * 60 * 10;
  37 +
  38 + @Override
  39 + public void run() {
  40 + logger.warn("GPS离线检查开始");
  41 + try{
  42 + long t = System.currentTimeMillis();
  43 + Collection<GpsEntity> list = gpsRealData.all();
  44 +
  45 + String state;
  46 + for(GpsEntity gps : list){
  47 + state = gps.getAbnormalStatus();
  48 +
  49 + if(state != null && state.equals("offline"))
  50 + continue;
  51 +
  52 + if (t - gps.getTimestamp() > LOSE_TIME){
  53 + gps.offline();
  54 +
  55 + //结束超速
  56 + overspeedProcess.offline(gps.getDeviceId());
  57 + //通知页面有设备掉线
  58 + sendUtils.deviceOffline(gps);
  59 + }
  60 + }
  61 + }catch (Exception e){
  62 + logger.error("", e);
  63 + }
  64 + logger.warn("GPS离线检查结束");
  65 + }
  66 +}
src/main/java/com/bsth/data/maintenance_plan/MtPlanDataLoadThread.java
1 package com.bsth.data.maintenance_plan; 1 package com.bsth.data.maintenance_plan;
2 2
3 -import com.alibaba.fastjson.JSON;  
4 import com.fasterxml.jackson.databind.ObjectMapper; 3 import com.fasterxml.jackson.databind.ObjectMapper;
5 import org.apache.http.HttpEntity; 4 import org.apache.http.HttpEntity;
6 import org.apache.http.client.config.RequestConfig; 5 import org.apache.http.client.config.RequestConfig;
@@ -27,6 +26,7 @@ import java.util.Map; @@ -27,6 +26,7 @@ import java.util.Map;
27 26
28 /** 27 /**
29 * 维修保养计划 28 * 维修保养计划
  29 + * @author Hill
30 */ 30 */
31 @Component 31 @Component
32 public class MtPlanDataLoadThread extends Thread implements InitializingBean { 32 public class MtPlanDataLoadThread extends Thread implements InitializingBean {
@@ -57,6 +57,7 @@ public class MtPlanDataLoadThread extends Thread implements InitializingBean { @@ -57,6 +57,7 @@ public class MtPlanDataLoadThread extends Thread implements InitializingBean {
57 57
58 @Override 58 @Override
59 public void run() { 59 public void run() {
  60 + logger.warn("维修保养计划获取数据开始");
60 List<MaintenancePlan> list; 61 List<MaintenancePlan> list;
61 StringBuilder sb = new StringBuilder(url); 62 StringBuilder sb = new StringBuilder(url);
62 try { 63 try {
@@ -92,6 +93,7 @@ public class MtPlanDataLoadThread extends Thread implements InitializingBean { @@ -92,6 +93,7 @@ public class MtPlanDataLoadThread extends Thread implements InitializingBean {
92 } catch (Exception e) { 93 } catch (Exception e) {
93 logger.error("维修保养计划接口报错了", e); 94 logger.error("维修保养计划接口报错了", e);
94 } 95 }
  96 + logger.warn("维修保养计划获取数据结束");
95 } 97 }
96 98
97 @Override 99 @Override
src/main/java/com/bsth/data/safe_driv/SafeDrivDataLoadThread.java
1 -package com.bsth.data.safe_driv;  
2 -  
3 -import com.alibaba.fastjson.JSON;  
4 -import org.apache.http.HttpEntity;  
5 -import org.apache.http.client.config.RequestConfig;  
6 -import org.apache.http.client.methods.CloseableHttpResponse;  
7 -import org.apache.http.client.methods.HttpGet;  
8 -import org.apache.http.impl.client.CloseableHttpClient;  
9 -import org.apache.http.impl.client.HttpClients;  
10 -import org.slf4j.Logger;  
11 -import org.slf4j.LoggerFactory;  
12 -import org.springframework.stereotype.Component;  
13 -  
14 -import java.io.BufferedReader;  
15 -import java.io.InputStreamReader;  
16 -import java.util.List;  
17 -  
18 -/**  
19 - * 安全驾驶数据加载线程  
20 - * Created by panzhao on 2017/4/6.  
21 - */  
22 -@Component  
23 -public class SafeDrivDataLoadThread extends Thread {  
24 -  
25 - Logger logger = LoggerFactory.getLogger(this.getClass());  
26 -  
27 - static String url;  
28 - static CloseableHttpClient httpClient;  
29 - static HttpGet get;  
30 - static RequestConfig requestConfig;  
31 - static CloseableHttpResponse response;  
32 - static HttpEntity entity;  
33 - static BufferedReader br;  
34 -  
35 - static {  
36 - url = "http://211.95.61.66:9008/safedriving/realtimeInterface";  
37 - httpClient = HttpClients.createDefault();  
38 - get = new HttpGet(url);  
39 - requestConfig = RequestConfig.custom()  
40 - .setConnectTimeout(5500).setConnectionRequestTimeout(5000)  
41 - .setSocketTimeout(5500).build();  
42 - get.setConfig(requestConfig);  
43 - }  
44 -  
45 - @Override  
46 - public void run() {  
47 - List<SafeDriv> list;  
48 - try {  
49 -  
50 - response = httpClient.execute(get);  
51 -  
52 - int statusCode = response.getStatusLine().getStatusCode();  
53 - if(statusCode != 200){  
54 - logger.error("http client status code: " + statusCode);  
55 - }  
56 -  
57 - entity = response.getEntity();  
58 - if (null != entity) {  
59 - br = new BufferedReader(new InputStreamReader(entity.getContent()));  
60 - StringBuffer stringBuffer = new StringBuffer();  
61 - String str = "";  
62 - while ((str = br.readLine()) != null)  
63 - stringBuffer.append(str);  
64 -  
65 -  
66 - list = JSON.parseArray(stringBuffer.toString(), SafeDriv.class);  
67 -  
68 - for (SafeDriv sd : list) {  
69 - SafeDrivCenter.put(sd);  
70 - }  
71 - }  
72 -  
73 - if (null != response)  
74 - response.close();  
75 - } catch (Exception e) {  
76 - logger.error("安全驾驶接口报错了", e);  
77 - }  
78 - }  
79 -} 1 +package com.bsth.data.safe_driv;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import org.apache.http.HttpEntity;
  5 +import org.apache.http.client.config.RequestConfig;
  6 +import org.apache.http.client.methods.CloseableHttpResponse;
  7 +import org.apache.http.client.methods.HttpGet;
  8 +import org.apache.http.impl.client.CloseableHttpClient;
  9 +import org.apache.http.impl.client.HttpClients;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.stereotype.Component;
  13 +
  14 +import java.io.BufferedReader;
  15 +import java.io.InputStreamReader;
  16 +import java.util.List;
  17 +
  18 +/**
  19 + * 安全驾驶数据加载线程
  20 + * Created by panzhao on 2017/4/6.
  21 + */
  22 +@Component
  23 +public class SafeDrivDataLoadThread extends Thread {
  24 +
  25 + Logger logger = LoggerFactory.getLogger(this.getClass());
  26 +
  27 + static String url;
  28 + static CloseableHttpClient httpClient;
  29 + static HttpGet get;
  30 + static RequestConfig requestConfig;
  31 + static CloseableHttpResponse response;
  32 + static HttpEntity entity;
  33 + static BufferedReader br;
  34 +
  35 + static {
  36 + url = "http://211.95.61.66:9008/safedriving/realtimeInterface";
  37 + httpClient = HttpClients.createDefault();
  38 + get = new HttpGet(url);
  39 + requestConfig = RequestConfig.custom()
  40 + .setConnectTimeout(5500).setConnectionRequestTimeout(5000)
  41 + .setSocketTimeout(5500).build();
  42 + get.setConfig(requestConfig);
  43 + }
  44 +
  45 + @Override
  46 + public void run() {
  47 + logger.warn("安全驾驶获取数据开始");
  48 + List<SafeDriv> list;
  49 + try {
  50 +
  51 + response = httpClient.execute(get);
  52 +
  53 + int statusCode = response.getStatusLine().getStatusCode();
  54 + if(statusCode != 200){
  55 + logger.error("http client status code: " + statusCode);
  56 + }
  57 +
  58 + entity = response.getEntity();
  59 + if (null != entity) {
  60 + br = new BufferedReader(new InputStreamReader(entity.getContent()));
  61 + StringBuffer stringBuffer = new StringBuffer();
  62 + String str = "";
  63 + while ((str = br.readLine()) != null)
  64 + stringBuffer.append(str);
  65 +
  66 +
  67 + list = JSON.parseArray(stringBuffer.toString(), SafeDriv.class);
  68 +
  69 + for (SafeDriv sd : list) {
  70 + SafeDrivCenter.put(sd);
  71 + }
  72 + }
  73 +
  74 + if (null != response)
  75 + response.close();
  76 + } catch (Exception e) {
  77 + logger.error("安全驾驶接口报错了", e);
  78 + }
  79 + logger.warn("安全驾驶获取数据结束");
  80 + }
  81 +}
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
@@ -15,6 +15,8 @@ import com.bsth.entity.schedule.SchedulePlanInfo; @@ -15,6 +15,8 @@ import com.bsth.entity.schedule.SchedulePlanInfo;
15 import com.bsth.repository.realcontrol.ScheduleRealInfoRepository; 15 import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
16 import com.bsth.service.schedule.SchedulePlanInfoService; 16 import com.bsth.service.schedule.SchedulePlanInfoService;
17 import com.bsth.websocket.handler.SendUtils; 17 import com.bsth.websocket.handler.SendUtils;
  18 +import com.fasterxml.jackson.core.JsonProcessingException;
  19 +import com.fasterxml.jackson.databind.ObjectMapper;
18 import com.google.common.collect.ArrayListMultimap; 20 import com.google.common.collect.ArrayListMultimap;
19 import com.google.common.collect.HashMultimap; 21 import com.google.common.collect.HashMultimap;
20 import com.google.common.collect.ListMultimap; 22 import com.google.common.collect.ListMultimap;
@@ -29,11 +31,10 @@ import org.springframework.beans.factory.annotation.Value; @@ -29,11 +31,10 @@ import org.springframework.beans.factory.annotation.Value;
29 import org.springframework.dao.DataIntegrityViolationException; 31 import org.springframework.dao.DataIntegrityViolationException;
30 import org.springframework.jdbc.core.BatchPreparedStatementSetter; 32 import org.springframework.jdbc.core.BatchPreparedStatementSetter;
31 import org.springframework.jdbc.core.JdbcTemplate; 33 import org.springframework.jdbc.core.JdbcTemplate;
32 -import org.springframework.jdbc.datasource.DataSourceTransactionManager;  
33 import org.springframework.stereotype.Component; 34 import org.springframework.stereotype.Component;
34 -import org.springframework.transaction.TransactionDefinition;  
35 import org.springframework.transaction.TransactionStatus; 35 import org.springframework.transaction.TransactionStatus;
36 -import org.springframework.transaction.support.DefaultTransactionDefinition; 36 +import org.springframework.transaction.support.TransactionCallbackWithoutResult;
  37 +import org.springframework.transaction.support.TransactionTemplate;
37 38
38 import java.sql.PreparedStatement; 39 import java.sql.PreparedStatement;
39 import java.sql.SQLException; 40 import java.sql.SQLException;
@@ -440,85 +441,84 @@ public class DayOfSchedule { @@ -440,85 +441,84 @@ public class DayOfSchedule {
440 item.setScheduleDateStr(sdfyyyyMMdd.format(item.getScheduleDate())); 441 item.setScheduleDateStr(sdfyyyyMMdd.format(item.getScheduleDate()));
441 } 442 }
442 443
443 - //编程式事务  
444 - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource());  
445 - DefaultTransactionDefinition def = new DefaultTransactionDefinition();  
446 - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);  
447 - TransactionStatus status = tran.getTransaction(def);  
448 -  
449 - try{  
450 - final List<ScheduleRealInfo> pstList = list;  
451 - //写入  
452 - jdbcTemplate.batchUpdate("insert into bsth_c_s_sp_info_real(id,bc_type,bcs,bcsj,cl_zbh,create_date,dfsj,directive_state,fcno,fcsj,fcsj_actual,j_gh,j_name,jhlc,lp_name,qdz_code,qdz_name,real_exec_date,remarks,s_gh,s_name,schedule_date,schedule_date_str,sflj,sp_id,status,update_date,xl_bm,xl_dir,xl_name,zdsj,zdsj_actual,zdz_code,zdz_name,ccno,df_auto,fgs_bm,fgs_name,gs_bm,gs_name,online,adjust_exps,reissue,jhlc_orig,sigin_compate,drift_status,cc_service,major_station_name,rfid_state,first_rfid_state)" +  
453 - " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() {  
454 - @Override  
455 - public void setValues(PreparedStatement ps, int i) throws SQLException {  
456 - ScheduleRealInfo sch = pstList.get(i);  
457 - ps.setLong(1, sch.getId());  
458 - ps.setString(2, sch.getBcType());  
459 - ps.setInt(3, sch.getBcs()==null?0:sch.getBcs());  
460 - ps.setInt(4, sch.getBcsj()==null?0:sch.getBcsj());  
461 - ps.setString(5, sch.getClZbh());  
462 - ps.setTimestamp(6, new java.sql.Timestamp(sch.getCreateDate().getTime()));  
463 - ps.setString(7, sch.getDfsj());  
464 - ps.setInt(8, sch.getDirectiveState());  
465 - ps.setInt(9, sch.getFcno()==null?0:sch.getFcno());  
466 - ps.setString(10, sch.getFcsj());  
467 - ps.setString(11, sch.getFcsjActual());  
468 - ps.setString(12, sch.getjGh());  
469 - ps.setString(13, sch.getjName());  
470 - ps.setDouble(14, sch.getJhlc());  
471 - ps.setString(15, sch.getLpName());  
472 - ps.setString(16, sch.getQdzCode());  
473 - ps.setString(17, sch.getQdzName());  
474 - ps.setString(18, sch.getRealExecDate());  
475 - ps.setString(19, sch.getRemarks());  
476 - ps.setString(20, sch.getsGh());  
477 - ps.setString(21, sch.getsName());  
478 - ps.setTimestamp(22, new java.sql.Timestamp(sch.getScheduleDate().getTime()));  
479 - ps.setString(23, sch.getScheduleDateStr());  
480 - ps.setBoolean(24, sch.isSflj());  
481 - ps.setLong(25, sch.getSpId());  
482 - ps.setInt(26, sch.getStatus());  
483 - ps.setTimestamp(27, new java.sql.Timestamp(sch.getUpdateDate().getTime()));  
484 - ps.setString(28, sch.getXlBm());  
485 - ps.setString(29, sch.getXlDir());  
486 - ps.setString(30, sch.getXlName());  
487 - ps.setString(31, sch.getZdsj());  
488 - ps.setString(32, sch.getZdsjActual());  
489 - ps.setString(33, sch.getZdzCode());  
490 - ps.setString(34, sch.getZdzName());  
491 - ps.setInt(35, sch.getCcno()==null?0:sch.getCcno());  
492 - ps.setBoolean(36, sch.isDfAuto());  
493 - ps.setString(37, sch.getFgsBm());  
494 - ps.setString(38, sch.getFgsName());  
495 - ps.setString(39, sch.getGsBm());  
496 - ps.setString(40, sch.getGsName());  
497 - ps.setBoolean(41, sch.isOnline());  
498 - ps.setString(42, sch.getAdjustExps());  
499 - ps.setBoolean(43, sch.isReissue());  
500 - ps.setDouble(44, sch.getJhlcOrig());  
501 - ps.setInt(45, sch.getSiginCompate());  
502 - ps.setInt(46, sch.getDriftStatus());  
503 - ps.setBoolean(47, sch.isCcService());  
504 - ps.setString(48, sch.getMajorStationName());  
505 - ps.setInt(49, sch.getRfidState());  
506 - ps.setInt(50, sch.getFirstRfidState());  
507 - }  
508 -  
509 - @Override  
510 - public int getBatchSize() {  
511 - return pstList.size(); 444 + transactionTemplate.execute(new TransactionCallbackWithoutResult() {
  445 + @Override
  446 + protected void doInTransactionWithoutResult(TransactionStatus status) {
  447 + try{
  448 + final List<ScheduleRealInfo> pstList = list;
  449 + //写入
  450 + jdbcTemplate.batchUpdate("insert into bsth_c_s_sp_info_real(id,bc_type,bcs,bcsj,cl_zbh,create_date,dfsj,directive_state,fcno,fcsj,fcsj_actual,j_gh,j_name,jhlc,lp_name,qdz_code,qdz_name,real_exec_date,remarks,s_gh,s_name,schedule_date,schedule_date_str,sflj,sp_id,status,update_date,xl_bm,xl_dir,xl_name,zdsj,zdsj_actual,zdz_code,zdz_name,ccno,df_auto,fgs_bm,fgs_name,gs_bm,gs_name,online,adjust_exps,reissue,jhlc_orig,sigin_compate,drift_status,cc_service,major_station_name,rfid_state,first_rfid_state)" +
  451 + " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() {
  452 + @Override
  453 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  454 + ScheduleRealInfo sch = pstList.get(i);
  455 + ps.setLong(1, sch.getId());
  456 + ps.setString(2, sch.getBcType());
  457 + ps.setInt(3, sch.getBcs()==null?0:sch.getBcs());
  458 + ps.setInt(4, sch.getBcsj()==null?0:sch.getBcsj());
  459 + ps.setString(5, sch.getClZbh());
  460 + ps.setTimestamp(6, new java.sql.Timestamp(sch.getCreateDate().getTime()));
  461 + ps.setString(7, sch.getDfsj());
  462 + ps.setInt(8, sch.getDirectiveState());
  463 + ps.setInt(9, sch.getFcno()==null?0:sch.getFcno());
  464 + ps.setString(10, sch.getFcsj());
  465 + ps.setString(11, sch.getFcsjActual());
  466 + ps.setString(12, sch.getjGh());
  467 + ps.setString(13, sch.getjName());
  468 + ps.setDouble(14, sch.getJhlc());
  469 + ps.setString(15, sch.getLpName());
  470 + ps.setString(16, sch.getQdzCode());
  471 + ps.setString(17, sch.getQdzName());
  472 + ps.setString(18, sch.getRealExecDate());
  473 + ps.setString(19, sch.getRemarks());
  474 + ps.setString(20, sch.getsGh());
  475 + ps.setString(21, sch.getsName());
  476 + ps.setTimestamp(22, new java.sql.Timestamp(sch.getScheduleDate().getTime()));
  477 + ps.setString(23, sch.getScheduleDateStr());
  478 + ps.setBoolean(24, sch.isSflj());
  479 + ps.setLong(25, sch.getSpId());
  480 + ps.setInt(26, sch.getStatus());
  481 + ps.setTimestamp(27, new java.sql.Timestamp(sch.getUpdateDate().getTime()));
  482 + ps.setString(28, sch.getXlBm());
  483 + ps.setString(29, sch.getXlDir());
  484 + ps.setString(30, sch.getXlName());
  485 + ps.setString(31, sch.getZdsj());
  486 + ps.setString(32, sch.getZdsjActual());
  487 + ps.setString(33, sch.getZdzCode());
  488 + ps.setString(34, sch.getZdzName());
  489 + ps.setInt(35, sch.getCcno()==null?0:sch.getCcno());
  490 + ps.setBoolean(36, sch.isDfAuto());
  491 + ps.setString(37, sch.getFgsBm());
  492 + ps.setString(38, sch.getFgsName());
  493 + ps.setString(39, sch.getGsBm());
  494 + ps.setString(40, sch.getGsName());
  495 + ps.setBoolean(41, sch.isOnline());
  496 + ps.setString(42, sch.getAdjustExps());
  497 + ps.setBoolean(43, sch.isReissue());
  498 + ps.setDouble(44, sch.getJhlcOrig());
  499 + ps.setInt(45, sch.getSiginCompate());
  500 + ps.setInt(46, sch.getDriftStatus());
  501 + ps.setBoolean(47, sch.isCcService());
  502 + ps.setString(48, sch.getMajorStationName());
  503 + ps.setInt(49, sch.getRfidState());
  504 + ps.setInt(50, sch.getFirstRfidState());
  505 + }
  506 +
  507 + @Override
  508 + public int getBatchSize() {
  509 + return pstList.size();
  510 + }
  511 + });
  512 + }catch (Exception e){
  513 + status.setRollbackOnly();
  514 + try {
  515 + logger.error(String.format("翻班实际排班数据批量保存异常: %s", mapper.writeValueAsString(list)), e);
  516 + } catch (JsonProcessingException jsonProcessingException) {
  517 + jsonProcessingException.printStackTrace();
  518 + }
512 } 519 }
513 - });  
514 -  
515 - tran.commit(status);  
516 - }catch (Exception e){  
517 - tran.rollback(status);  
518 - logger.error("real schedule batchSave error...", e);  
519 - }  
520 - // 入库  
521 - //new BatchSaveUtils<ScheduleRealInfo>().saveList(list, ScheduleRealInfo.class); 520 + }
  521 + });
522 } 522 }
523 523
524 public List<SchedulePlanInfo> cleanSchPlanItr(Iterator<SchedulePlanInfo> itrab) { 524 public List<SchedulePlanInfo> cleanSchPlanItr(Iterator<SchedulePlanInfo> itrab) {
@@ -993,6 +993,12 @@ public class DayOfSchedule { @@ -993,6 +993,12 @@ public class DayOfSchedule {
993 @Autowired 993 @Autowired
994 JdbcTemplate jdbcTemplate; 994 JdbcTemplate jdbcTemplate;
995 995
  996 + @Autowired
  997 + private TransactionTemplate transactionTemplate;
  998 +
  999 + @Autowired
  1000 + private ObjectMapper mapper;
  1001 +
996 /** 1002 /**
997 * 删除实际排班 1003 * 删除实际排班
998 * 1004 *
src/main/java/com/bsth/data/schedule/auto_exec/AutoExecScanThread.java
1 -package com.bsth.data.schedule.auto_exec;  
2 -  
3 -import com.bsth.data.LineConfigData;  
4 -import com.bsth.data.schedule.DayOfSchedule;  
5 -import com.bsth.entity.realcontrol.LineConfig;  
6 -import com.bsth.entity.realcontrol.ScheduleRealInfo;  
7 -import org.slf4j.Logger;  
8 -import org.slf4j.LoggerFactory;  
9 -import org.springframework.beans.factory.annotation.Autowired;  
10 -import org.springframework.stereotype.Component;  
11 -  
12 -import java.util.ArrayList;  
13 -import java.util.Collection;  
14 -import java.util.List;  
15 -  
16 -/**  
17 - * 班次自动执行扫描线程  
18 - * Created by panzhao on 2017/10/31.  
19 - */  
20 -@Component  
21 -public class AutoExecScanThread extends Thread{  
22 -  
23 -  
24 - @Autowired  
25 - LineConfigData lineConfigData;  
26 -  
27 - @Autowired  
28 - DayOfSchedule dayOfSchedule;  
29 -  
30 - @Autowired  
31 - RealScheduleAutoExecHandler realScheduleAutoExecHandler;  
32 -  
33 - Logger logger = LoggerFactory.getLogger(this.getClass());  
34 -  
35 - @Override  
36 - public void run() {  
37 - try{  
38 - //要自动执行的线路  
39 - List<String> autos = new ArrayList<>();  
40 - Collection<LineConfig> lcs = lineConfigData.getAll();  
41 -  
42 - for(LineConfig config : lcs){  
43 - if(config.isAutoExec()){  
44 - autos.add(config.getLine().getLineCode());  
45 - }  
46 - }  
47 -  
48 - if(autos.size()==0)  
49 - return;  
50 - List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll());  
51 - for(ScheduleRealInfo sch : all){  
52 - if(autos.contains(sch.getXlBm())){  
53 - realScheduleAutoExecHandler.exec(sch);  
54 - }  
55 - }  
56 - }catch (Exception e){  
57 - logger.error("", e);  
58 - }  
59 - }  
60 -} 1 +package com.bsth.data.schedule.auto_exec;
  2 +
  3 +import com.bsth.data.LineConfigData;
  4 +import com.bsth.data.schedule.DayOfSchedule;
  5 +import com.bsth.entity.realcontrol.LineConfig;
  6 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +import java.util.ArrayList;
  13 +import java.util.Collection;
  14 +import java.util.List;
  15 +
  16 +/**
  17 + * 班次自动执行扫描线程
  18 + * Created by panzhao on 2017/10/31.
  19 + */
  20 +@Component
  21 +public class AutoExecScanThread extends Thread{
  22 +
  23 +
  24 + @Autowired
  25 + LineConfigData lineConfigData;
  26 +
  27 + @Autowired
  28 + DayOfSchedule dayOfSchedule;
  29 +
  30 + @Autowired
  31 + RealScheduleAutoExecHandler realScheduleAutoExecHandler;
  32 +
  33 + Logger logger = LoggerFactory.getLogger(this.getClass());
  34 +
  35 + @Override
  36 + public void run() {
  37 + logger.warn("班次自动执行扫描开始");
  38 + try{
  39 + //要自动执行的线路
  40 + List<String> autos = new ArrayList<>();
  41 + Collection<LineConfig> lcs = lineConfigData.getAll();
  42 +
  43 + for(LineConfig config : lcs){
  44 + if(config.isAutoExec()){
  45 + autos.add(config.getLine().getLineCode());
  46 + }
  47 + }
  48 +
  49 + if(autos.size()==0)
  50 + return;
  51 + List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll());
  52 + for(ScheduleRealInfo sch : all){
  53 + if(autos.contains(sch.getXlBm())){
  54 + realScheduleAutoExecHandler.exec(sch);
  55 + }
  56 + }
  57 + }catch (Exception e){
  58 + logger.error("", e);
  59 + }
  60 + logger.warn("班次自动执行扫描结束");
  61 + }
  62 +}
src/main/java/com/bsth/data/schedule/e_state_check/thread/FixedCheckStationCodeThread.java
1 -package com.bsth.data.schedule.e_state_check.thread;  
2 -  
3 -import com.bsth.data.schedule.e_state_check.ScheduleStationCodeChecker;  
4 -import org.slf4j.Logger;  
5 -import org.slf4j.LoggerFactory;  
6 -import org.springframework.beans.factory.annotation.Autowired;  
7 -import org.springframework.stereotype.Component;  
8 -  
9 -/**  
10 - * 定时检查班次站点编码线程  
11 - * Created by panzhao on 2018/4/2.  
12 - */  
13 -@Component  
14 -public class FixedCheckStationCodeThread extends Thread {  
15 -  
16 - @Autowired  
17 - ScheduleStationCodeChecker scheduleStationCodeChecker;  
18 -  
19 - Logger logger = LoggerFactory.getLogger(this.getClass());  
20 -  
21 - @Override  
22 - public void run() {  
23 - try {  
24 - scheduleStationCodeChecker.checkAll();  
25 - } catch (Exception e) {  
26 - logger.error("", e);  
27 - }  
28 - }  
29 -} 1 +package com.bsth.data.schedule.e_state_check.thread;
  2 +
  3 +import com.bsth.data.schedule.e_state_check.ScheduleStationCodeChecker;
  4 +import org.slf4j.Logger;
  5 +import org.slf4j.LoggerFactory;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +/**
  10 + * 定时检查班次站点编码线程
  11 + * Created by panzhao on 2018/4/2.
  12 + */
  13 +@Component
  14 +public class FixedCheckStationCodeThread extends Thread {
  15 +
  16 + @Autowired
  17 + ScheduleStationCodeChecker scheduleStationCodeChecker;
  18 +
  19 + Logger logger = LoggerFactory.getLogger(this.getClass());
  20 +
  21 + @Override
  22 + public void run() {
  23 + logger.warn("班次站点编码检查开始");
  24 + try {
  25 + scheduleStationCodeChecker.checkAll();
  26 + } catch (Exception e) {
  27 + logger.error("", e);
  28 + }
  29 + logger.warn("班次站点编码检查结束");
  30 + }
  31 +}
src/main/java/com/bsth/data/schedule/edit_logs/SeiPstThread.java
@@ -28,6 +28,7 @@ public class SeiPstThread extends Thread{ @@ -28,6 +28,7 @@ public class SeiPstThread extends Thread{
28 28
29 @Override 29 @Override
30 public void run() { 30 public void run() {
  31 + log.warn("班次修正日志保存开始");
31 try{ 32 try{
32 List<SchEditInfo> pstList = new ArrayList<>(); 33 List<SchEditInfo> pstList = new ArrayList<>();
33 LinkedList<SchEditInfo> list = ScheduleModifyLogger.list; 34 LinkedList<SchEditInfo> list = ScheduleModifyLogger.list;
@@ -48,5 +49,6 @@ public class SeiPstThread extends Thread{ @@ -48,5 +49,6 @@ public class SeiPstThread extends Thread{
48 }catch (Exception e){ 49 }catch (Exception e){
49 log.error("", e); 50 log.error("", e);
50 } 51 }
  52 + log.warn("班次修正日志保存结束");
51 } 53 }
52 } 54 }
53 \ No newline at end of file 55 \ No newline at end of file
src/main/java/com/bsth/data/schedule/late_adjust/LateAdjustHandle.java
1 -  
2 -package com.bsth.data.schedule.late_adjust;  
3 -  
4 -import com.bsth.data.LineConfigData;  
5 -import com.bsth.data.gpsdata_v2.entity.GpsEntity;  
6 -import com.bsth.entity.realcontrol.LineConfig;  
7 -import com.bsth.entity.realcontrol.ScheduleRealInfo;  
8 -import com.bsth.util.Arith;  
9 -import com.bsth.websocket.handler.SendUtils;  
10 -import org.slf4j.Logger;  
11 -import org.slf4j.LoggerFactory;  
12 -import org.springframework.beans.BeansException;  
13 -import org.springframework.context.ApplicationContext;  
14 -import org.springframework.context.ApplicationContextAware;  
15 -import org.springframework.stereotype.Component;  
16 -  
17 -import java.util.Collection;  
18 -import java.util.concurrent.ConcurrentHashMap;  
19 -import java.util.concurrent.ConcurrentMap;  
20 -  
21 -/**  
22 - * 误点自动调整待发 处理程序  
23 - * <p>  
24 - * 注意 :这里的误点是指应发未到  
25 - * Created by panzhao on 2017/4/16.  
26 - */  
27 -@Component  
28 -public class LateAdjustHandle implements ApplicationContextAware {  
29 -  
30 - static LineConfigData lineConfigData;  
31 - static SendUtils sendUtils;  
32 -  
33 - static Logger logger = LoggerFactory.getLogger(LateAdjustHandle.class);  
34 -  
35 - /**  
36 - * 应发未到的班次 key : id  
37 - */  
38 - private static ConcurrentMap<Long, ScheduleRealInfo> lateSchMap = new ConcurrentHashMap<>();  
39 -  
40 -  
41 - /**  
42 - * 新增一个误点班次  
43 - *  
44 - * @param sch  
45 - */  
46 - public static void putLate(ScheduleRealInfo sch) {  
47 - try {  
48 - //线路配置  
49 - LineConfig config = lineConfigData.get(sch.getXlBm());  
50 - if (sch.getLateMinute() == 0) {  
51 - if (!config.isEnableYjtk())  
52 - return;  
53 -  
54 - sch.setLateMinute(sch.getXlDir().equals("0") ? config.getUpStopMinute() : config.getDownStopMinute());  
55 - }  
56 -  
57 - if (sch.getDfsj().compareTo(config.getYjtkStart()) > 0  
58 - && sch.getDfsj().compareTo(config.getYjtkEnd()) <= 0) {  
59 -  
60 - //班次压入  
61 - if (!lateSchMap.containsKey(sch.getId())) {  
62 - logger.info("29【应发未到 班次 " + sch.getClZbh() + " -" + sch.getDfsj() + " -id: " + sch.getId() + " -加入误点调整!");  
63 -  
64 - sch.setLate2(true);  
65 - lateSchMap.put(sch.getId(), sch);  
66 - //通知客户端  
67 - sendUtils.sendAutoWdtz(sch, null);  
68 - }  
69 - }  
70 -  
71 - } catch (Exception e) {  
72 - logger.error("", e);  
73 - }  
74 - }  
75 -  
76 -  
77 - /**  
78 - * 获取所有应发未到的班次  
79 - *  
80 - * @return  
81 - */  
82 - public static Collection<ScheduleRealInfo> allLateSch() {  
83 - return lateSchMap.values();  
84 - }  
85 -  
86 - public static void remove(ScheduleRealInfo sch) {  
87 - try {  
88 - if (lateSchMap.containsKey(sch.getId())) {  
89 - lateSchMap.remove(sch.getId());  
90 -  
91 - sch.setLate2(false);  
92 - sch.setLateMinute(0);  
93 - sch.setDfAuto(false);  
94 -  
95 - logger.info("移除误点调整 -" + sch.getClZbh() + " -time: " + sch.getDfsj() + " -id: " + sch.getId());  
96 - }  
97 - } catch (Exception e) {  
98 - logger.error("", e);  
99 - }  
100 - }  
101 -  
102 - /**  
103 - * 车辆到站 进站 进 的哪个班次,就调该车辆的下一个班次  
104 - *  
105 - * @param gps  
106 - */  
107 - public static void carArrive(GpsEntity gps, ScheduleRealInfo sch) {  
108 - try {  
109 - if (gps.getInstation() <= 0 || null == sch)  
110 - return;  
111 -  
112 - if (!lateSchMap.containsKey(sch.getId())) {  
113 - //班次是否误点(可能处于误点线程扫描的空隙,所以再判定一次)  
114 - if (sch.getDfsjT() <= gps.getTimestamp()) {  
115 - putLate(sch);  
116 -  
117 - if (!lateSchMap.containsKey(sch.getId()))  
118 - return;  
119 -  
120 - logger.info("线程空隙漏掉的误点,id: " + sch.getId());  
121 - } else  
122 - return;  
123 - }  
124 -  
125 -  
126 - //可能是延迟信号,gps时间没有误点  
127 - if (gps.getTimestamp() <= sch.getDfsjT()) {  
128 - sch.setLate2(false);  
129 - lateSchMap.remove(sch.getId());  
130 - return;  
131 - }  
132 -  
133 -  
134 - //自动调整待发 到达时间 + 停靠时间  
135 - long dt = Arith.addLong(gps.getTimestamp(), (sch.getLateMinute() * 60 * 1000));  
136 -  
137 - sch.setDfsjAll(dt);  
138 - sch.setDfAuto(true);  
139 - //取消应发未到标记  
140 - sch.setLate2(false);  
141 -  
142 - lateSchMap.remove(sch.getId());  
143 - logger.info("【应发未到】车辆到站 " + sch.getClZbh() + " -" + sch.getDfsj() + " -到站时间:" + gps.getTimestamp() + " -停靠时间:" + sch.getLateMinute() + " -自动设置的待发时间:" + dt + " -id:" + sch.getId());  
144 - } catch (Exception e) {  
145 - e.printStackTrace();  
146 - logger.error("late2 car arrive", e);  
147 - }  
148 - }  
149 -  
150 -  
151 - @Override  
152 - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {  
153 - lineConfigData = applicationContext.getBean(LineConfigData.class);  
154 - sendUtils = applicationContext.getBean(SendUtils.class);  
155 - } 1 +
  2 +package com.bsth.data.schedule.late_adjust;
  3 +
  4 +import com.bsth.data.LineConfigData;
  5 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  6 +import com.bsth.entity.realcontrol.LineConfig;
  7 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  8 +import com.bsth.util.Arith;
  9 +import com.bsth.websocket.handler.SendUtils;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.BeansException;
  13 +import org.springframework.context.ApplicationContext;
  14 +import org.springframework.context.ApplicationContextAware;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +import java.util.Collection;
  18 +import java.util.concurrent.ConcurrentHashMap;
  19 +import java.util.concurrent.ConcurrentMap;
  20 +
  21 +/**
  22 + * 误点自动调整待发 处理程序
  23 + * <p>
  24 + * 注意 :这里的误点是指应发未到
  25 + * Created by panzhao on 2017/4/16.
  26 + */
  27 +@Component
  28 +public class LateAdjustHandle implements ApplicationContextAware {
  29 +
  30 + static LineConfigData lineConfigData;
  31 + static SendUtils sendUtils;
  32 +
  33 + static Logger logger = LoggerFactory.getLogger(LateAdjustHandle.class);
  34 +
  35 + /**
  36 + * 应发未到的班次 key : id
  37 + */
  38 + private static ConcurrentMap<Long, ScheduleRealInfo> lateSchMap = new ConcurrentHashMap<>();
  39 +
  40 +
  41 + /**
  42 + * 新增一个误点班次
  43 + *
  44 + * @param sch
  45 + */
  46 + public static void putLate(ScheduleRealInfo sch) {
  47 + try {
  48 + //线路配置
  49 + LineConfig config = lineConfigData.get(sch.getXlBm());
  50 + if (sch.getLateMinute() == 0) {
  51 + if (!config.isEnableYjtk())
  52 + return;
  53 +
  54 + sch.setLateMinute(sch.getXlDir().equals("0") ? config.getUpStopMinute() : config.getDownStopMinute());
  55 + }
  56 +
  57 + if (sch.getDfsj().compareTo(config.getYjtkStart()) > 0
  58 + && sch.getDfsj().compareTo(config.getYjtkEnd()) <= 0) {
  59 +
  60 + //班次压入
  61 + if (!lateSchMap.containsKey(sch.getId())) {
  62 + logger.info("【应发未到】 班次 " + sch.getClZbh() + " -" + sch.getDfsj() + " -id: " + sch.getId() + " -加入误点调整!");
  63 +
  64 + sch.setLate2(true);
  65 + lateSchMap.put(sch.getId(), sch);
  66 + //通知客户端
  67 + sendUtils.sendAutoWdtz(sch, null);
  68 + }
  69 + }
  70 +
  71 + } catch (Exception e) {
  72 + logger.error("", e);
  73 + }
  74 + }
  75 +
  76 +
  77 + /**
  78 + * 获取所有应发未到的班次
  79 + *
  80 + * @return
  81 + */
  82 + public static Collection<ScheduleRealInfo> allLateSch() {
  83 + return lateSchMap.values();
  84 + }
  85 +
  86 + public static void remove(ScheduleRealInfo sch) {
  87 + try {
  88 + if (lateSchMap.containsKey(sch.getId())) {
  89 + lateSchMap.remove(sch.getId());
  90 +
  91 + sch.setLate2(false);
  92 + sch.setLateMinute(0);
  93 + sch.setDfAuto(false);
  94 +
  95 + logger.info("移除误点调整 -" + sch.getClZbh() + " -time: " + sch.getDfsj() + " -id: " + sch.getId());
  96 + }
  97 + } catch (Exception e) {
  98 + logger.error("", e);
  99 + }
  100 + }
  101 +
  102 + /**
  103 + * 车辆到站 进站 进 的哪个班次,就调该车辆的下一个班次
  104 + *
  105 + * @param gps
  106 + */
  107 + public static void carArrive(GpsEntity gps, ScheduleRealInfo sch) {
  108 + try {
  109 + if (gps.getInstation() <= 0 || null == sch)
  110 + return;
  111 +
  112 + if (!lateSchMap.containsKey(sch.getId())) {
  113 + //班次是否误点(可能处于误点线程扫描的空隙,所以再判定一次)
  114 + if (sch.getDfsjT() <= gps.getTimestamp()) {
  115 + putLate(sch);
  116 +
  117 + if (!lateSchMap.containsKey(sch.getId()))
  118 + return;
  119 +
  120 + logger.info("线程空隙漏掉的误点,id: " + sch.getId());
  121 + } else
  122 + return;
  123 + }
  124 +
  125 +
  126 + //可能是延迟信号,gps时间没有误点
  127 + if (gps.getTimestamp() <= sch.getDfsjT()) {
  128 + sch.setLate2(false);
  129 + lateSchMap.remove(sch.getId());
  130 + return;
  131 + }
  132 +
  133 +
  134 + //自动调整待发 到达时间 + 停靠时间
  135 + long dt = Arith.addLong(gps.getTimestamp(), (sch.getLateMinute() * 60 * 1000));
  136 +
  137 + sch.setDfsjAll(dt);
  138 + sch.setDfAuto(true);
  139 + //取消应发未到标记
  140 + sch.setLate2(false);
  141 +
  142 + lateSchMap.remove(sch.getId());
  143 + logger.info("【应发未到】车辆到站 " + sch.getClZbh() + " -" + sch.getDfsj() + " -到站时间:" + gps.getTimestamp() + " -停靠时间:" + sch.getLateMinute() + " -自动设置的待发时间:" + dt + " -id:" + sch.getId());
  144 + } catch (Exception e) {
  145 + e.printStackTrace();
  146 + logger.error("late2 car arrive", e);
  147 + }
  148 + }
  149 +
  150 +
  151 + @Override
  152 + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  153 + lineConfigData = applicationContext.getBean(LineConfigData.class);
  154 + sendUtils = applicationContext.getBean(SendUtils.class);
  155 + }
156 } 156 }
157 \ No newline at end of file 157 \ No newline at end of file
src/main/java/com/bsth/data/schedule/late_adjust/ScheduleLateThread.java
1 -package com.bsth.data.schedule.late_adjust;  
2 -  
3 -  
4 -import com.bsth.data.schedule.DayOfSchedule;  
5 -import com.bsth.data.schedule.ScheduleComparator;  
6 -import com.bsth.entity.realcontrol.ScheduleRealInfo;  
7 -import com.bsth.websocket.handler.SendUtils;  
8 -import org.apache.commons.lang3.StringUtils;  
9 -import org.slf4j.Logger;  
10 -import org.slf4j.LoggerFactory;  
11 -import org.springframework.beans.factory.annotation.Autowired;  
12 -import org.springframework.stereotype.Component;  
13 -  
14 -import java.util.ArrayList;  
15 -import java.util.Collections;  
16 -import java.util.Comparator;  
17 -import java.util.List;  
18 -  
19 -/**  
20 - *  
21 - * @ClassName: ScheduleLateThread  
22 - * @Description: TODO(班次误点扫描线程)  
23 - * @author PanZhao  
24 - * @date 2016年8月31日 下午3:09:02  
25 - *  
26 - */  
27 -@Component  
28 -public class ScheduleLateThread extends Thread{  
29 -  
30 - @Autowired  
31 - DayOfSchedule dayOfSchedule;  
32 -  
33 - @Autowired  
34 - SendUtils sendUtils;  
35 -  
36 - Logger logger = LoggerFactory.getLogger(this.getClass());  
37 -  
38 - private static Comparator<ScheduleRealInfo> cpm = new ScheduleComparator.DFSJ2();  
39 -  
40 - @Override  
41 - public void run() {  
42 - try{  
43 - List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll());  
44 - Collections.sort(all, cpm);  
45 -  
46 - long t = System.currentTimeMillis();  
47 - int size = all.size();  
48 -  
49 - ScheduleRealInfo sch;  
50 - for(int i = 0; i < size; i ++){  
51 - sch = all.get(i);  
52 - if(sch.getDfsjT() > t)  
53 - break;  
54 -  
55 - if(sch.isLate())  
56 - continue;  
57 -  
58 - if(sch.getStatus() == 0  
59 - && StringUtils.isEmpty(sch.getFcsjActual())){  
60 -  
61 - //检查应发未到 当前班次无起点到达时间  
62 - if(StringUtils.isEmpty(sch.getQdzArrDatesj())){  
63 - ScheduleRealInfo prev = dayOfSchedule.prev(sch);  
64 - //上一个班次也没有实际终点到达时间  
65 - if(prev != null && StringUtils.isEmpty(prev.getZdsjActual())){  
66 - //进入误点调整程序  
67 - LateAdjustHandle.putLate(sch);  
68 - }  
69 - }  
70 -  
71 - //应发未发  
72 - sch.setLate(true);  
73 - //通知客户端  
74 - sendUtils.refreshSch(sch);  
75 - }  
76 - }  
77 - }catch (Exception e){  
78 - logger.error("", e);  
79 - }  
80 - } 1 +package com.bsth.data.schedule.late_adjust;
  2 +
  3 +
  4 +import com.bsth.data.schedule.DayOfSchedule;
  5 +import com.bsth.data.schedule.ScheduleComparator;
  6 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  7 +import com.bsth.websocket.handler.SendUtils;
  8 +import org.apache.commons.lang3.StringUtils;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.stereotype.Component;
  13 +
  14 +import java.util.ArrayList;
  15 +import java.util.Collections;
  16 +import java.util.Comparator;
  17 +import java.util.List;
  18 +
  19 +/**
  20 + *
  21 + * @ClassName: ScheduleLateThread
  22 + * @Description: TODO(班次误点扫描线程)
  23 + * @author PanZhao
  24 + * @date 2016年8月31日 下午3:09:02
  25 + *
  26 + */
  27 +@Component
  28 +public class ScheduleLateThread extends Thread{
  29 +
  30 + @Autowired
  31 + DayOfSchedule dayOfSchedule;
  32 +
  33 + @Autowired
  34 + SendUtils sendUtils;
  35 +
  36 + Logger logger = LoggerFactory.getLogger(this.getClass());
  37 +
  38 + private static Comparator<ScheduleRealInfo> cpm = new ScheduleComparator.DFSJ2();
  39 +
  40 + @Override
  41 + public void run() {
  42 + logger.warn("班次误点扫描开始");
  43 + try{
  44 + List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll());
  45 + Collections.sort(all, cpm);
  46 +
  47 + long t = System.currentTimeMillis();
  48 + int size = all.size();
  49 +
  50 + ScheduleRealInfo sch;
  51 + for(int i = 0; i < size; i ++){
  52 + sch = all.get(i);
  53 + if(sch.getDfsjT() > t)
  54 + break;
  55 +
  56 + if(sch.isLate())
  57 + continue;
  58 +
  59 + if(sch.getStatus() == 0
  60 + && StringUtils.isEmpty(sch.getFcsjActual())){
  61 +
  62 + //检查应发未到 当前班次无起点到达时间
  63 + if(StringUtils.isEmpty(sch.getQdzArrDatesj())){
  64 + ScheduleRealInfo prev = dayOfSchedule.prev(sch);
  65 + //上一个班次也没有实际终点到达时间
  66 + if(prev != null && StringUtils.isEmpty(prev.getZdsjActual())){
  67 + //进入误点调整程序
  68 + LateAdjustHandle.putLate(sch);
  69 + }
  70 + }
  71 +
  72 + //应发未发
  73 + sch.setLate(true);
  74 + //通知客户端
  75 + sendUtils.refreshSch(sch);
  76 + }
  77 + }
  78 + }catch (Exception e){
  79 + logger.error("", e);
  80 + }
  81 + logger.warn("班次误点扫描结束");
  82 + }
81 } 83 }
82 \ No newline at end of file 84 \ No newline at end of file
src/main/java/com/bsth/data/schedule/thread/SchedulePstThread.java
@@ -54,7 +54,7 @@ public class SchedulePstThread extends Thread { @@ -54,7 +54,7 @@ public class SchedulePstThread extends Thread {
54 54
55 @Override 55 @Override
56 public void run() { 56 public void run() {
57 - 57 + logger.warn("班次批量保存开始");
58 try{ 58 try{
59 ScheduleRealInfo schedule; 59 ScheduleRealInfo schedule;
60 for (int i = 0; i < 500; i++) { 60 for (int i = 0; i < 500; i++) {
@@ -75,6 +75,7 @@ public class SchedulePstThread extends Thread { @@ -75,6 +75,7 @@ public class SchedulePstThread extends Thread {
75 }catch (Exception e){ 75 }catch (Exception e){
76 logger.error("", e); 76 logger.error("", e);
77 } 77 }
  78 + logger.warn("班次批量保存结束");
78 } 79 }
79 80
80 private void save(){ 81 private void save(){
src/main/java/com/bsth/data/schedule/thread/ScheduleRefreshThread.java
1 -package com.bsth.data.schedule.thread;  
2 -  
3 -import com.bsth.data.LineConfigData;  
4 -import com.bsth.data.directive.DayOfDirectives;  
5 -import com.bsth.data.gpsdata_v2.cache.GpsCacheData;  
6 -import com.bsth.data.pilot80.PilotReport;  
7 -import com.bsth.data.schedule.DayOfSchedule;  
8 -import com.bsth.data.schedule.f_a_l.FirstAndLastHandler;  
9 -import com.bsth.entity.realcontrol.LineConfig;  
10 -import org.slf4j.Logger;  
11 -import org.slf4j.LoggerFactory;  
12 -import org.springframework.beans.factory.annotation.Autowired;  
13 -import org.springframework.stereotype.Component;  
14 -  
15 -import java.util.Collection;  
16 -import java.util.Set;  
17 -  
18 -/**  
19 - *  
20 - * @ClassName: ScheduleRefreshThread  
21 - * @Description: TODO(班次刷新线程,用于在营运开始时间切换到当日排班)  
22 - * @author PanZhao  
23 - * @date 2016年8月17日 下午1:23:34  
24 - *  
25 - */  
26 -@Component  
27 -public class ScheduleRefreshThread extends Thread{  
28 -  
29 - @Autowired  
30 - DayOfSchedule dayOfSchedule;  
31 -  
32 - @Autowired  
33 - LineConfigData lineConfs;  
34 -  
35 - @Autowired  
36 - DayOfDirectives dayOfDirectives;  
37 -  
38 - @Autowired  
39 - PilotReport pilotReport;  
40 -  
41 - Logger logger = LoggerFactory.getLogger(ScheduleRefreshThread.class);  
42 -  
43 - @Override  
44 - public void run() {  
45 - try {  
46 - Collection<LineConfig> confs = lineConfs.getAll();  
47 -  
48 - String currSchDate, oldSchDate;  
49 - String lineCode = null;  
50 - for(LineConfig conf : confs){  
51 - try{  
52 - lineCode = conf.getLine().getLineCode();  
53 - oldSchDate = dayOfSchedule.getCurrSchDate().get(lineCode);  
54 - currSchDate = dayOfSchedule.calcSchDate(lineCode);  
55 -  
56 - if(oldSchDate == null || !oldSchDate.equals(currSchDate)){  
57 -  
58 - try{  
59 - Set<String> cars = dayOfSchedule.findCarByLineCode(lineCode);  
60 - for(String car : cars){  
61 - GpsCacheData.remove(car);  
62 - dayOfSchedule.resetRepairReport(car);  
63 - }  
64 - //清除驾驶员上报数据  
65 - pilotReport.clear(lineCode);  
66 - //清除指令数据 指令数据,直接定时全部清空  
67 - //dayOfDirectives.clear(lineCode);  
68 - }catch (Exception e){  
69 - logger.error("清理 60 和 80出现问题", e);  
70 - }  
71 -  
72 - //重载排班数据  
73 - dayOfSchedule.reloadSch(lineCode, currSchDate, false);  
74 - logger.info(lineCode + "翻班完成, " + currSchDate + " -班次数量:" + dayOfSchedule.findByLineCode(lineCode).size());  
75 - }  
76 - }catch (Exception e){  
77 - logger.error("班次更新失败!! -" + lineCode, e);  
78 - }  
79 - }  
80 -  
81 - //按公司编码索引数据  
82 - dayOfSchedule.groupByGsbm();  
83 -  
84 - //首末班入库(给网关用的数据)  
85 - FirstAndLastHandler.saveAll();  
86 - } catch (Exception e) {  
87 - logger.error("", e);  
88 - }  
89 - }  
90 -} 1 +package com.bsth.data.schedule.thread;
  2 +
  3 +import com.bsth.data.LineConfigData;
  4 +import com.bsth.data.directive.DayOfDirectives;
  5 +import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
  6 +import com.bsth.data.pilot80.PilotReport;
  7 +import com.bsth.data.schedule.DayOfSchedule;
  8 +import com.bsth.data.schedule.f_a_l.FirstAndLastHandler;
  9 +import com.bsth.entity.realcontrol.LineConfig;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.stereotype.Component;
  14 +
  15 +import java.util.Collection;
  16 +import java.util.Set;
  17 +
  18 +/**
  19 + *
  20 + * @ClassName: ScheduleRefreshThread
  21 + * @Description: TODO(班次刷新线程,用于在营运开始时间切换到当日排班)
  22 + * @author PanZhao
  23 + * @date 2016年8月17日 下午1:23:34
  24 + *
  25 + */
  26 +@Component
  27 +public class ScheduleRefreshThread extends Thread{
  28 +
  29 + @Autowired
  30 + DayOfSchedule dayOfSchedule;
  31 +
  32 + @Autowired
  33 + LineConfigData lineConfs;
  34 +
  35 + @Autowired
  36 + DayOfDirectives dayOfDirectives;
  37 +
  38 + @Autowired
  39 + PilotReport pilotReport;
  40 +
  41 + Logger logger = LoggerFactory.getLogger(ScheduleRefreshThread.class);
  42 +
  43 + @Override
  44 + public void run() {
  45 + logger.warn("班次刷新开始");
  46 + try {
  47 + Collection<LineConfig> confs = lineConfs.getAll();
  48 +
  49 + String currSchDate, oldSchDate;
  50 + String lineCode = null;
  51 + for(LineConfig conf : confs){
  52 + try{
  53 + lineCode = conf.getLine().getLineCode();
  54 + oldSchDate = dayOfSchedule.getCurrSchDate().get(lineCode);
  55 + currSchDate = dayOfSchedule.calcSchDate(lineCode);
  56 +
  57 + if(oldSchDate == null || !oldSchDate.equals(currSchDate)){
  58 +
  59 + try{
  60 + Set<String> cars = dayOfSchedule.findCarByLineCode(lineCode);
  61 + for(String car : cars){
  62 + GpsCacheData.remove(car);
  63 + dayOfSchedule.resetRepairReport(car);
  64 + }
  65 + //清除驾驶员上报数据
  66 + pilotReport.clear(lineCode);
  67 + //清除指令数据 指令数据,直接定时全部清空
  68 + //dayOfDirectives.clear(lineCode);
  69 + }catch (Exception e){
  70 + logger.error("清理 60 和 80出现问题", e);
  71 + }
  72 +
  73 + //重载排班数据
  74 + dayOfSchedule.reloadSch(lineCode, currSchDate, false);
  75 + logger.info(lineCode + "翻班完成, " + currSchDate + " -班次数量:" + dayOfSchedule.findByLineCode(lineCode).size());
  76 + }
  77 + }catch (Exception e){
  78 + logger.error("班次更新失败!! -" + lineCode, e);
  79 + }
  80 + }
  81 +
  82 + //按公司编码索引数据
  83 + dayOfSchedule.groupByGsbm();
  84 +
  85 + //首末班入库(给网关用的数据)
  86 + FirstAndLastHandler.saveAll();
  87 + } catch (Exception e) {
  88 + logger.error("", e);
  89 + }
  90 + logger.warn("班次刷新结束");
  91 + }
  92 +}
src/main/java/com/bsth/message/buffer/CarEnergyBuffer.java 0 → 100644
  1 +package com.bsth.message.buffer;
  2 +
  3 +import com.bsth.message.entity.CarEnergy;
  4 +
  5 +import java.util.Map;
  6 +import java.util.concurrent.ConcurrentHashMap;
  7 +
  8 +/**
  9 + * @author Hill
  10 + */
  11 +public class CarEnergyBuffer {
  12 +
  13 + private static Map<String, CarEnergy> code2energy = new ConcurrentHashMap<>();
  14 +
  15 + public static void put(CarEnergy carEnergy) {
  16 + code2energy.put(carEnergy.getNbbm(), carEnergy);
  17 + }
  18 +
  19 + public static int getCarEnergy(String carCode) {
  20 + CarEnergy carEnergy = code2energy.get(carCode);
  21 +
  22 + return carEnergy == null ? -1 : (int) (carEnergy.getEnergy() * 100);
  23 + }
  24 +}
src/main/java/com/bsth/message/entity/CarEnergy.java 0 → 100644
  1 +package com.bsth.message.entity;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
  4 +import com.fasterxml.jackson.annotation.JsonProperty;
  5 +
  6 +/**
  7 + * @author Hill
  8 + */
  9 +@JsonIgnoreProperties(ignoreUnknown = true)
  10 +public class CarEnergy {
  11 +
  12 + /**
  13 + * 车辆内部编码
  14 + */
  15 + @JsonProperty("carCode")
  16 + private String nbbm;
  17 +
  18 + /**
  19 + * 剩余电量
  20 + */
  21 + private double energy;
  22 +
  23 + /**
  24 + * 最后更新时间戳
  25 + */
  26 + private long updateTimestamp;
  27 +
  28 + public String getNbbm() {
  29 + return nbbm;
  30 + }
  31 +
  32 + public void setNbbm(String nbbm) {
  33 + this.nbbm = nbbm;
  34 + }
  35 +
  36 + public double getEnergy() {
  37 + return energy;
  38 + }
  39 +
  40 + public void setEnergy(double energy) {
  41 + this.energy = energy;
  42 + }
  43 +
  44 + public long getUpdateTimestamp() {
  45 + return updateTimestamp;
  46 + }
  47 +
  48 + public void setUpdateTimestamp(long updateTimestamp) {
  49 + this.updateTimestamp = updateTimestamp;
  50 + }
  51 +}
src/main/java/com/bsth/message/entity/CarErrorStop.java 0 → 100644
  1 +package com.bsth.message.entity;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
  4 +
  5 +/**
  6 + * 企业信息化运行监控中心
  7 + * 车辆异常停车(理论上超过5分钟)
  8 + * @author Hill
  9 + */
  10 +@JsonIgnoreProperties(ignoreUnknown = true)
  11 +public class CarErrorStop {
  12 +
  13 + /**
  14 + * ID
  15 + */
  16 + private int id;
  17 +
  18 + /**
  19 + * 日期
  20 + */
  21 + private String rq;
  22 +
  23 + /**
  24 + * 公司编码
  25 + */
  26 + private String company;
  27 +
  28 + /**
  29 + * 分公司名称
  30 + */
  31 + private String branchCompany;
  32 +
  33 + /**
  34 + * 线路名称
  35 + */
  36 + private String line;
  37 +
  38 + /**
  39 + * 线路代码
  40 + */
  41 + private String lineId;
  42 +
  43 + /**
  44 + * 车辆内部编码
  45 + */
  46 + private String nbbm;
  47 +
  48 + private String carCode;
  49 +
  50 + private String driver;
  51 +
  52 + private double lat;
  53 +
  54 + private double lon;
  55 +
  56 + /**
  57 + * 发生地址
  58 + */
  59 + private String address;
  60 +
  61 + /**
  62 + * 异常停车起始时间
  63 + */
  64 + private String startTime;
  65 +
  66 + private long startTimestamp;
  67 +
  68 + /**
  69 + * 异常停车结束时间
  70 + */
  71 + private String endTime;
  72 +
  73 + private long endTimestamp;
  74 +
  75 + /**
  76 + * 上下行
  77 + */
  78 + private int upDown;
  79 +
  80 + /**
  81 + * 备注
  82 + */
  83 + private String remark;
  84 +
  85 + public int getId() {
  86 + return id;
  87 + }
  88 +
  89 + public void setId(int id) {
  90 + this.id = id;
  91 + }
  92 +
  93 + public String getRq() {
  94 + return rq;
  95 + }
  96 +
  97 + public void setRq(String rq) {
  98 + this.rq = rq;
  99 + }
  100 +
  101 + public String getCompany() {
  102 + return company;
  103 + }
  104 +
  105 + public void setCompany(String company) {
  106 + this.company = company;
  107 + }
  108 +
  109 + public String getBranchCompany() {
  110 + return branchCompany;
  111 + }
  112 +
  113 + public void setBranchCompany(String branchCompany) {
  114 + this.branchCompany = branchCompany;
  115 + }
  116 +
  117 + public String getLine() {
  118 + return line;
  119 + }
  120 +
  121 + public void setLine(String line) {
  122 + this.line = line;
  123 + }
  124 +
  125 + public String getLineId() {
  126 + return lineId;
  127 + }
  128 +
  129 + public void setLineId(String lineId) {
  130 + this.lineId = lineId;
  131 + }
  132 +
  133 + public String getNbbm() {
  134 + return nbbm;
  135 + }
  136 +
  137 + public void setNbbm(String nbbm) {
  138 + this.nbbm = nbbm;
  139 + }
  140 +
  141 + public String getCarCode() {
  142 + return carCode;
  143 + }
  144 +
  145 + public void setCarCode(String carCode) {
  146 + this.carCode = carCode;
  147 + }
  148 +
  149 + public String getDriver() {
  150 + return driver;
  151 + }
  152 +
  153 + public void setDriver(String driver) {
  154 + this.driver = driver;
  155 + }
  156 +
  157 + public double getLat() {
  158 + return lat;
  159 + }
  160 +
  161 + public void setLat(double lat) {
  162 + this.lat = lat;
  163 + }
  164 +
  165 + public double getLon() {
  166 + return lon;
  167 + }
  168 +
  169 + public void setLon(double lon) {
  170 + this.lon = lon;
  171 + }
  172 +
  173 + public String getAddress() {
  174 + return address;
  175 + }
  176 +
  177 + public void setAddress(String address) {
  178 + this.address = address;
  179 + }
  180 +
  181 + public String getStartTime() {
  182 + return startTime;
  183 + }
  184 +
  185 + public void setStartTime(String startTime) {
  186 + this.startTime = startTime;
  187 + }
  188 +
  189 + public long getStartTimestamp() {
  190 + return startTimestamp;
  191 + }
  192 +
  193 + public void setStartTimestamp(long startTimestamp) {
  194 + this.startTimestamp = startTimestamp;
  195 + }
  196 +
  197 + public String getEndTime() {
  198 + return endTime;
  199 + }
  200 +
  201 + public void setEndTime(String endTime) {
  202 + this.endTime = endTime;
  203 + }
  204 +
  205 + public long getEndTimestamp() {
  206 + return endTimestamp;
  207 + }
  208 +
  209 + public void setEndTimestamp(long endTimestamp) {
  210 + this.endTimestamp = endTimestamp;
  211 + }
  212 +
  213 + public int getUpDown() {
  214 + return upDown;
  215 + }
  216 +
  217 + public void setUpDown(int upDown) {
  218 + this.upDown = upDown;
  219 + }
  220 +
  221 + public String getRemark() {
  222 + return remark;
  223 + }
  224 +
  225 + public void setRemark(String remark) {
  226 + this.remark = remark;
  227 + }
  228 +
  229 + @Override
  230 + public boolean equals(Object o) {
  231 + return this.id == ((CarErrorStop) o).id;
  232 + }
  233 +
  234 + @Override
  235 + public int hashCode() {
  236 + return this.id;
  237 + }
  238 +}
src/main/java/com/bsth/message/handler/MessageHandler.java 0 → 100644
  1 +package com.bsth.message.handler;
  2 +
  3 +import com.bsth.message.buffer.CarEnergyBuffer;
  4 +import com.bsth.message.entity.CarEnergy;
  5 +import com.bsth.message.entity.CarErrorStop;
  6 +import com.bsth.websocket.handler.SendUtils;
  7 +import com.fasterxml.jackson.databind.ObjectMapper;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  10 +import org.springframework.kafka.annotation.KafkaListener;
  11 +import org.springframework.messaging.Message;
  12 +import org.springframework.stereotype.Component;
  13 +
  14 +import java.io.IOException;
  15 +import java.util.List;
  16 +
  17 +/**
  18 + * @author Hill
  19 + */
  20 +@Component
  21 +@ConditionalOnProperty("kafka.use")
  22 +public class MessageHandler {
  23 +
  24 + @Autowired
  25 + private SendUtils sendUtils;
  26 +
  27 + @Autowired
  28 + private ObjectMapper mapper;
  29 +
  30 + @KafkaListener(topics="schedule-mainsys-carerrorstop")
  31 + public void receivedCarErrorStop(Message<String> message) {
  32 + try {
  33 + List<CarErrorStop> carErrorStopList = mapper.readValue(message.getPayload(), mapper.getTypeFactory().constructParametricType(List.class, CarErrorStop.class));
  34 + for (CarErrorStop carErrorStop : carErrorStopList) {
  35 + sendUtils.sendCarErrorStop(carErrorStop);
  36 + }
  37 + } catch (IOException e) {
  38 + e.printStackTrace();
  39 + }
  40 + }
  41 +
  42 + @KafkaListener(topics="schedule-mainsys-carenergy")
  43 + public void receivedCarEnergy(Message<String> message) {
  44 + try {
  45 + List<CarEnergy> carEnergyList = mapper.readValue(message.getPayload(), mapper.getTypeFactory().constructParametricType(List.class, CarEnergy.class));
  46 + for (CarEnergy carEnergy : carEnergyList) {
  47 + CarEnergyBuffer.put(carEnergy);
  48 + }
  49 + } catch (IOException e) {
  50 + e.printStackTrace();
  51 + }
  52 + }
  53 +}
src/main/java/com/bsth/service/geo_data/impl/GeoDataServiceImpl.java
@@ -12,8 +12,8 @@ import com.bsth.service.geo_data.impl.dto.CascadeSaveRoad; @@ -12,8 +12,8 @@ import com.bsth.service.geo_data.impl.dto.CascadeSaveRoad;
12 import com.bsth.service.geo_data.impl.dto.CascadeSaveStation; 12 import com.bsth.service.geo_data.impl.dto.CascadeSaveStation;
13 import com.bsth.service.geo_data.impl.dto.SaveRoadRouteDTO; 13 import com.bsth.service.geo_data.impl.dto.SaveRoadRouteDTO;
14 import com.bsth.service.geo_data.impl.dto.SaveStationRouteDTO; 14 import com.bsth.service.geo_data.impl.dto.SaveStationRouteDTO;
15 -import com.bsth.util.GetUIDAndCode;  
16 import com.bsth.util.TransGPS; 15 import com.bsth.util.TransGPS;
  16 +import com.fasterxml.jackson.databind.ObjectMapper;
17 import com.google.common.base.Splitter; 17 import com.google.common.base.Splitter;
18 import org.slf4j.Logger; 18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory; 19 import org.slf4j.LoggerFactory;
@@ -21,11 +21,10 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -21,11 +21,10 @@ import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.jdbc.core.BatchPreparedStatementSetter; 21 import org.springframework.jdbc.core.BatchPreparedStatementSetter;
22 import org.springframework.jdbc.core.BeanPropertyRowMapper; 22 import org.springframework.jdbc.core.BeanPropertyRowMapper;
23 import org.springframework.jdbc.core.JdbcTemplate; 23 import org.springframework.jdbc.core.JdbcTemplate;
24 -import org.springframework.jdbc.datasource.DataSourceTransactionManager;  
25 import org.springframework.stereotype.Service; 24 import org.springframework.stereotype.Service;
26 -import org.springframework.transaction.TransactionDefinition;  
27 import org.springframework.transaction.TransactionStatus; 25 import org.springframework.transaction.TransactionStatus;
28 -import org.springframework.transaction.support.DefaultTransactionDefinition; 26 +import org.springframework.transaction.support.TransactionCallback;
  27 +import org.springframework.transaction.support.TransactionTemplate;
29 28
30 import java.sql.PreparedStatement; 29 import java.sql.PreparedStatement;
31 import java.sql.SQLException; 30 import java.sql.SQLException;
@@ -47,6 +46,12 @@ public class GeoDataServiceImpl implements GeoDataService { @@ -47,6 +46,12 @@ public class GeoDataServiceImpl implements GeoDataService {
47 @Autowired 46 @Autowired
48 StationRepository stationRepository; 47 StationRepository stationRepository;
49 48
  49 + @Autowired
  50 + private TransactionTemplate transactionTemplate;
  51 +
  52 + @Autowired
  53 + private ObjectMapper mapper;
  54 +
50 Logger logger = LoggerFactory.getLogger(this.getClass()); 55 Logger logger = LoggerFactory.getLogger(this.getClass());
51 56
52 @Override 57 @Override
@@ -172,141 +177,138 @@ public class GeoDataServiceImpl implements GeoDataService { @@ -172,141 +177,138 @@ public class GeoDataServiceImpl implements GeoDataService {
172 public Map<String, Object> updateStationName(Map<String, Object> map) { 177 public Map<String, Object> updateStationName(Map<String, Object> map) {
173 Map<String, Object> rs = new HashMap<>(); 178 Map<String, Object> rs = new HashMap<>();
174 179
175 - //编程式事务  
176 - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource());  
177 - DefaultTransactionDefinition def = new DefaultTransactionDefinition();  
178 - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);  
179 - TransactionStatus status = tran.getTransaction(def);  
180 - try {  
181 -  
182 - int id = Integer.parseInt(map.get("id").toString());  
183 - String name = map.get("stationName").toString();  
184 - String code = map.get("stationCode").toString();  
185 - String lineCode = map.get("lineCode").toString();  
186 - String versions = map.get("versions").toString();  
187 -  
188 - //更新历史站点路由  
189 - jdbcTemplate.update("update bsth_c_ls_stationroute set station_name=? where id=?", name, id);  
190 - //更新站点  
191 - jdbcTemplate.update("update bsth_c_station set station_name=? where station_cod=?", name, code);  
192 -  
193 - //写一条走向变更记录  
194 - jdbcTemplate.update("insert into logger_route_synchro(t, line_code, version) values(?, ?, ?)", System.currentTimeMillis(), lineCode, versions);  
195 -  
196 - tran.commit(status);  
197 -  
198 - rs.put("station", findOne(id));  
199 - rs.put("status", ResponseCode.SUCCESS);  
200 - } catch (Exception e) {  
201 - tran.rollback(status);  
202 - logger.error("", e);  
203 - rs.put("status", ResponseCode.ERROR);  
204 - rs.put("msg", "服务器出现异常");  
205 - }  
206 - return rs; 180 + return transactionTemplate.execute(new TransactionCallback<Map<String, Object>>() {
  181 + @Override
  182 + public Map<String, Object> doInTransaction(TransactionStatus status) {
  183 + try {
  184 +
  185 + int id = Integer.parseInt(map.get("id").toString());
  186 + String name = map.get("stationName").toString();
  187 + String code = map.get("stationCode").toString();
  188 + String lineCode = map.get("lineCode").toString();
  189 + String versions = map.get("versions").toString();
  190 +
  191 + //更新历史站点路由
  192 + jdbcTemplate.update("update bsth_c_ls_stationroute set station_name=? where id=?", name, id);
  193 + //更新站点
  194 + jdbcTemplate.update("update bsth_c_station set station_name=? where station_cod=?", name, code);
  195 +
  196 + //写一条走向变更记录
  197 + jdbcTemplate.update("insert into logger_route_synchro(t, line_code, version) values(?, ?, ?)", System.currentTimeMillis(), lineCode, versions);
  198 +
  199 + rs.put("station", findOne(id));
  200 + rs.put("status", ResponseCode.SUCCESS);
  201 + } catch (Exception e) {
  202 + status.setRollbackOnly();
  203 + logger.error("", e);
  204 + rs.put("status", ResponseCode.ERROR);
  205 + rs.put("msg", "服务器出现异常");
  206 + }
  207 + return rs;
  208 + }
  209 + });
207 } 210 }
208 211
209 @Override 212 @Override
210 public Map<String, Object> addNewRoadRoute(String lineCode, int upDown, int versions, String sectionName, String crosesRoad, String coords, int prevRouteId) { 213 public Map<String, Object> addNewRoadRoute(String lineCode, int upDown, int versions, String sectionName, String crosesRoad, String coords, int prevRouteId) {
211 Map<String, Object> rs = new HashMap<>(); 214 Map<String, Object> rs = new HashMap<>();
212 215
213 - //编程式事务  
214 - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource());  
215 - DefaultTransactionDefinition def = new DefaultTransactionDefinition();  
216 - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);  
217 - TransactionStatus status = tran.getTransaction(def);  
218 - try {  
219 - //根据线路编码,查询线路ID  
220 - int lineId = jdbcTemplate.queryForObject("select id from bsth_c_line where line_code=" + lineCode, Integer.class);  
221 -  
222 - String sql = "select * from bsth_c_ls_sectionroute where line_code='" + lineCode + "' and line=" + lineId + " and directions=" + upDown + " and destroy=0 and versions=" + versions;  
223 - List<SaveRoadRouteDTO> routes = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(SaveRoadRouteDTO.class));  
224 -  
225 - Collections.sort(routes, new RoadRouteComp());  
226 -  
227 - long sCode = sectionRepository.sectionMaxId() + 1;  
228 - //转wgs  
229 - String wgsCoord = "LINESTRING(" + bdPolygon2Wgs(coords) + ")";  
230 - String bdCooed = "LINESTRING(" + coords + ")";  
231 - //insert 路段  
232 - sql = "insert into bsth_c_section(id, section_code, section_name, croses_road, bsection_vector, gsection_vector, create_date, update_date, versions) " +  
233 - " values(?,?,?,?,ST_GeomFromText('" + bdCooed + "'),ST_GeomFromText('" + wgsCoord + "'),sysdate(),sysdate(),?)";  
234 -  
235 - jdbcTemplate.update(sql, sCode, sCode, sectionName, crosesRoad, 1);  
236 - 216 + return transactionTemplate.execute(new TransactionCallback<Map<String, Object>>() {
237 217
238 - SaveRoadRouteDTO srr;  
239 - int currentNo = -1,  
240 - no = 100, step = 100;  
241 -  
242 - if (prevRouteId == -1) {  
243 - //起点站  
244 - currentNo = no;  
245 - no += step;  
246 - }  
247 - //重新排序路由  
248 - for (int i = 0, size = routes.size(); i < size; i++) {  
249 - srr = routes.get(i);  
250 - srr.setSectionrouteCode(no += step);  
251 - if (srr.getId().intValue() == prevRouteId) {  
252 - no += step;  
253 - currentNo = no; 218 + @Override
  219 + public Map<String, Object> doInTransaction(TransactionStatus status) {
  220 + try {
  221 + //根据线路编码,查询线路ID
  222 + int lineId = jdbcTemplate.queryForObject("select id from bsth_c_line where line_code=" + lineCode, Integer.class);
  223 +
  224 + String sql = "select * from bsth_c_ls_sectionroute where line_code='" + lineCode + "' and line=" + lineId + " and directions=" + upDown + " and destroy=0 and versions=" + versions;
  225 + List<SaveRoadRouteDTO> routes = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(SaveRoadRouteDTO.class));
  226 +
  227 + Collections.sort(routes, new RoadRouteComp());
  228 +
  229 + long sCode = sectionRepository.sectionMaxId() + 1;
  230 + //转wgs
  231 + String wgsCoord = "LINESTRING(" + bdPolygon2Wgs(coords) + ")";
  232 + String bdCooed = "LINESTRING(" + coords + ")";
  233 + //insert 路段
  234 + sql = "insert into bsth_c_section(id, section_code, section_name, croses_road, bsection_vector, gsection_vector, create_date, update_date, versions) " +
  235 + " values(?,?,?,?,ST_GeomFromText('" + bdCooed + "'),ST_GeomFromText('" + wgsCoord + "'),sysdate(),sysdate(),?)";
  236 +
  237 + jdbcTemplate.update(sql, sCode, sCode, sectionName, crosesRoad, 1);
  238 +
  239 +
  240 + SaveRoadRouteDTO srr;
  241 + int currentNo = -1,
  242 + no = 100, step = 100;
  243 +
  244 + if (prevRouteId == -1) {
  245 + //起点站
  246 + currentNo = no;
  247 + no += step;
  248 + }
  249 + //重新排序路由
  250 + for (int i = 0, size = routes.size(); i < size; i++) {
  251 + srr = routes.get(i);
  252 + srr.setSectionrouteCode(no += step);
  253 + if (srr.getId().intValue() == prevRouteId) {
  254 + no += step;
  255 + currentNo = no;
  256 + }
  257 + }
  258 +
  259 + srr = new SaveRoadRouteDTO();
  260 + srr.setLine(lineId);
  261 + srr.setLineCode(lineCode);
  262 + srr.setDirections(upDown);
  263 + srr.setVersions(versions);
  264 +
  265 + srr.setSectionrouteCode(currentNo);
  266 + srr.setSection(sCode);
  267 + srr.setSectionCode(sCode + "");
  268 + srr.setIsRoadeSpeed(0);
  269 + srr.setDestroy(0);
  270 + Date d = new Date();
  271 + srr.setCreateDate(d);
  272 + srr.setUpdateDate(d);
  273 +
  274 + final List<SaveRoadRouteDTO> saveList = routes;
  275 + //insert 新路由 (ID自增)
  276 + jdbcTemplate.update("insert into bsth_c_ls_sectionroute(line_code, section_code, sectionroute_code, directions, line, section, create_date,update_date,versions,destroy,is_roade_speed)" +
  277 + " values(?,?,?,?,?,?,?,?,?,?,?)", srr.getLineCode(), srr.getSectionCode(), srr.getSectionrouteCode(), srr.getDirections(), srr.getLine(), srr.getSection(), srr.getCreateDate(), srr.getUpdateDate(), versions, srr.getDestroy(), srr.getIsRoadeSpeed());
  278 +
  279 + // update 原路由
  280 + jdbcTemplate.batchUpdate("update bsth_c_ls_sectionroute set sectionroute_code=? where id=?"
  281 + , new BatchPreparedStatementSetter() {
  282 + @Override
  283 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  284 + SaveRoadRouteDTO srr = saveList.get(i);
  285 + ps.setInt(1, srr.getSectionrouteCode());
  286 + ps.setInt(2, srr.getId());
  287 + }
  288 +
  289 + @Override
  290 + public int getBatchSize() {
  291 + return saveList.size();
  292 + }
  293 + });
  294 +
  295 +
  296 + //写一条走向变更记录
  297 + jdbcTemplate.update("insert into logger_route_synchro(t, line_code, version) values(?, ?, ?)", System.currentTimeMillis(), lineCode, versions);
  298 +
  299 + //返回更新之后的数据
  300 + List<GeoRoad> list = findRoadByUpdown(lineCode, upDown, versions);
  301 + rs.put("list", list);
  302 + rs.put("status", ResponseCode.SUCCESS);
  303 + } catch (Exception e) {
  304 + status.setRollbackOnly();
  305 + logger.error("", e);
  306 + rs.put("status", ResponseCode.ERROR);
  307 + rs.put("msg", "服务器出现异常");
254 } 308 }
  309 + return rs;
255 } 310 }
256 -  
257 - srr = new SaveRoadRouteDTO();  
258 - srr.setLine(lineId);  
259 - srr.setLineCode(lineCode);  
260 - srr.setDirections(upDown);  
261 - srr.setVersions(versions);  
262 -  
263 - srr.setSectionrouteCode(currentNo);  
264 - srr.setSection(sCode);  
265 - srr.setSectionCode(sCode + "");  
266 - srr.setIsRoadeSpeed(0);  
267 - srr.setDestroy(0);  
268 - Date d = new Date();  
269 - srr.setCreateDate(d);  
270 - srr.setUpdateDate(d);  
271 -  
272 - final List<SaveRoadRouteDTO> saveList = routes;  
273 - //insert 新路由 (ID自增)  
274 - jdbcTemplate.update("insert into bsth_c_ls_sectionroute(line_code, section_code, sectionroute_code, directions, line, section, create_date,update_date,versions,destroy,is_roade_speed)" +  
275 - " values(?,?,?,?,?,?,?,?,?,?,?)", srr.getLineCode(), srr.getSectionCode(), srr.getSectionrouteCode(), srr.getDirections(), srr.getLine(), srr.getSection(), srr.getCreateDate(), srr.getUpdateDate(), versions, srr.getDestroy(), srr.getIsRoadeSpeed());  
276 -  
277 - // update 原路由  
278 - jdbcTemplate.batchUpdate("update bsth_c_ls_sectionroute set sectionroute_code=? where id=?"  
279 - , new BatchPreparedStatementSetter() {  
280 - @Override  
281 - public void setValues(PreparedStatement ps, int i) throws SQLException {  
282 - SaveRoadRouteDTO srr = saveList.get(i);  
283 - ps.setInt(1, srr.getSectionrouteCode());  
284 - ps.setInt(2, srr.getId());  
285 - }  
286 -  
287 - @Override  
288 - public int getBatchSize() {  
289 - return saveList.size();  
290 - }  
291 - });  
292 -  
293 -  
294 - //写一条走向变更记录  
295 - jdbcTemplate.update("insert into logger_route_synchro(t, line_code, version) values(?, ?, ?)", System.currentTimeMillis(), lineCode, versions);  
296 -  
297 - tran.commit(status);  
298 -  
299 - //返回更新之后的数据  
300 - List<GeoRoad> list = findRoadByUpdown(lineCode, upDown, versions);  
301 - rs.put("list", list);  
302 - rs.put("status", ResponseCode.SUCCESS);  
303 - } catch (Exception e) {  
304 - tran.rollback(status);  
305 - logger.error("", e);  
306 - rs.put("status", ResponseCode.ERROR);  
307 - rs.put("msg", "服务器出现异常");  
308 - }  
309 - return rs; 311 + });
310 } 312 }
311 313
312 /** 314 /**
@@ -339,99 +341,100 @@ public class GeoDataServiceImpl implements GeoDataService { @@ -339,99 +341,100 @@ public class GeoDataServiceImpl implements GeoDataService {
339 public Map<String, Object> addNewLineVersion(Map<String, Object> map) { 341 public Map<String, Object> addNewLineVersion(Map<String, Object> map) {
340 Map<String, Object> rs = new HashMap<>(); 342 Map<String, Object> rs = new HashMap<>();
341 343
342 - //编程式事务  
343 - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource());  
344 - DefaultTransactionDefinition def = new DefaultTransactionDefinition();  
345 - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);  
346 - TransactionStatus status = tran.getTransaction(def);  
347 - try {  
348 -  
349 - String lineCode = map.get("lineCode").toString();  
350 - String remark = map.get("remark").toString();  
351 - String name = map.get("name").toString();  
352 - Date startDate = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(map.get("startDate").toString());  
353 - int extendsVersion = Integer.parseInt(map.get("extendsVersion").toString()); 344 + return transactionTemplate.execute(new TransactionCallback<Map<String, Object>>() {
354 345
355 - if(startDate.getTime() - System.currentTimeMillis() < 1000 * 60 * 3){  
356 - rs.put("status", ResponseCode.ERROR);  
357 - rs.put("msg", "启用时间最少需要晚于当前服务器时间3分钟!");  
358 - return rs;  
359 - }  
360 -  
361 - int nameCount = jdbcTemplate.queryForObject("select count(*) from bsth_c_line_versions where line_code=" + lineCode + " and name='"+name+"'", Integer.class);  
362 - if(nameCount > 0){  
363 - rs.put("status", ResponseCode.ERROR);  
364 - rs.put("msg", "你不能使用一个已经存在的版本名称!!");  
365 - return rs;  
366 - }  
367 -  
368 - //当前最大的版本号  
369 - int maxVersion = jdbcTemplate.queryForObject("select max(versions) as versions from bsth_c_line_versions where line_code=" + lineCode, Integer.class);  
370 - Date d = new Date();  
371 -  
372 - //根据线路编码,查询线路ID  
373 - int lineId = jdbcTemplate.queryForObject("select id from bsth_c_line where line_code=" + lineCode, Integer.class);  
374 -  
375 - maxVersion += 1;  
376 - LineVersions lVersion = new LineVersions();  
377 - lVersion.setName(name);  
378 - lVersion.setVersions(maxVersion);  
379 - lVersion.setRemark(remark);  
380 - lVersion.setStartDate(startDate);  
381 - lVersion.setStatus(2);  
382 - lVersion.setCreateDate(d);  
383 - lVersion.setUpdateDate(d);  
384 - lVersion.setLineCode(lineCode);  
385 -  
386 - //如果有待启用的版本,设置为历史版本  
387 - jdbcTemplate.update("update bsth_c_line_versions set `status`=2, start_date=null,end_date=null where line_code='"+lineCode+"' and `status`=0");  
388 -  
389 - //入库线路版本  
390 - jdbcTemplate.update("insert into bsth_c_line_versions(name, line, line_code, versions, start_date, create_date, update_date, remark,status, isupdate) " +  
391 - " values(?,?,?,?,?,?,?,?,?,?)", lVersion.getName(), lineId, lVersion.getLineCode()  
392 - , lVersion.getVersions(), lVersion.getStartDate(), lVersion.getCreateDate(), lVersion.getUpdateDate(), lVersion.getRemark(), lVersion.getStatus(), lVersion.getIsupdate());  
393 -  
394 - if (extendsVersion != -1) {  
395 - //复制站点信息  
396 - String sql = "SELECT t1.id AS route_id,t1.line,t1.directions,t1.station,t1.station_name,t1.station_route_code,t1.line_code,t1.station_code,t1.station_mark,t1.distances,t1.to_time,t2.id AS station_id,t2.db_type,t2.b_jwpoints,t2.g_lonx,t2.g_laty,t2.radius,ST_AsText(t2.g_polygon_grid) as g_polygon_grid,t2.shapes_type FROM bsth_c_ls_stationroute t1 LEFT JOIN bsth_c_station t2 ON t1.station_code = t2.station_cod where t1.destroy=0 and t1.line_code='" + lineCode + "' and t1.versions="+extendsVersion+" order by t1.directions, t1.station_route_code";  
397 - List<CascadeSaveStation> cssList = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(CascadeSaveStation.class));  
398 -  
399 - //新的站点编码  
400 - long sCode;  
401 - for (CascadeSaveStation ss : cssList) {  
402 - sCode = stationRepository.stationMaxId() + 1;  
403 - ss.setRouteId(null);  
404 - ss.setStationCode(sCode + "");  
405 - ss.setStation((int) sCode);  
406 - }  
407 - //入库新版本的站点 和 路由  
408 - batchInsertStation(cssList, maxVersion);  
409 -  
410 - //复制路段信息  
411 - sql = "SELECT t1.id AS route_id,t1.line,t1.line_code,t1.directions,t1.section,t1.section_code,t1.sectionroute_code,t1.versions,t2.section_name,t2.croses_road,ST_AsText(t2.gsection_vector) as gsection_vector,t2.db_type,t2.speed_limit FROM bsth_c_ls_sectionroute t1 LEFT JOIN bsth_c_section t2 ON t1.section_code = t2.section_code WHERE t1.destroy = 0 AND t1.line_code = '"+lineCode+"' and t1.versions="+ extendsVersion +" ORDER BY t1.directions,t1.sectionroute_code";  
412 - List<CascadeSaveRoad> csrList = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(CascadeSaveRoad.class));  
413 - //新的路段编码  
414 - long cCode;  
415 - for(CascadeSaveRoad csr : csrList){  
416 - cCode = sectionRepository.sectionMaxId() + 1;  
417 - csr.setRouteId(null);  
418 - csr.setSection((int) cCode);  
419 - csr.setSectionCode(cCode + ""); 346 + @Override
  347 + public Map<String, Object> doInTransaction(TransactionStatus status) {
  348 + try {
  349 +
  350 + String lineCode = map.get("lineCode").toString();
  351 + String remark = map.get("remark").toString();
  352 + String name = map.get("name").toString();
  353 + Date startDate = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(map.get("startDate").toString());
  354 + int extendsVersion = Integer.parseInt(map.get("extendsVersion").toString());
  355 +
  356 + if(startDate.getTime() - System.currentTimeMillis() < 1000 * 60 * 3){
  357 + rs.put("status", ResponseCode.ERROR);
  358 + rs.put("msg", "启用时间最少需要晚于当前服务器时间3分钟!");
  359 + return rs;
  360 + }
  361 +
  362 + int nameCount = jdbcTemplate.queryForObject("select count(*) from bsth_c_line_versions where line_code=" + lineCode + " and name='"+name+"'", Integer.class);
  363 + if(nameCount > 0){
  364 + rs.put("status", ResponseCode.ERROR);
  365 + rs.put("msg", "你不能使用一个已经存在的版本名称!!");
  366 + return rs;
  367 + }
  368 +
  369 + //当前最大的版本号
  370 + int maxVersion = jdbcTemplate.queryForObject("select max(versions) as versions from bsth_c_line_versions where line_code=" + lineCode, Integer.class);
  371 + Date d = new Date();
  372 +
  373 + //根据线路编码,查询线路ID
  374 + int lineId = jdbcTemplate.queryForObject("select id from bsth_c_line where line_code=" + lineCode, Integer.class);
  375 +
  376 + maxVersion += 1;
  377 + LineVersions lVersion = new LineVersions();
  378 + lVersion.setName(name);
  379 + lVersion.setVersions(maxVersion);
  380 + lVersion.setRemark(remark);
  381 + lVersion.setStartDate(startDate);
  382 + lVersion.setStatus(2);
  383 + lVersion.setCreateDate(d);
  384 + lVersion.setUpdateDate(d);
  385 + lVersion.setLineCode(lineCode);
  386 +
  387 + //如果有待启用的版本,设置为历史版本
  388 + jdbcTemplate.update("update bsth_c_line_versions set `status`=2, start_date=null,end_date=null where line_code='"+lineCode+"' and `status`=0");
  389 +
  390 + //入库线路版本
  391 + jdbcTemplate.update("insert into bsth_c_line_versions(name, line, line_code, versions, start_date, create_date, update_date, remark,status, isupdate) " +
  392 + " values(?,?,?,?,?,?,?,?,?,?)", lVersion.getName(), lineId, lVersion.getLineCode()
  393 + , lVersion.getVersions(), lVersion.getStartDate(), lVersion.getCreateDate(), lVersion.getUpdateDate(), lVersion.getRemark(), lVersion.getStatus(), lVersion.getIsupdate());
  394 +
  395 + if (extendsVersion != -1) {
  396 + //复制站点信息
  397 + String sql = "SELECT t1.id AS route_id,t1.line,t1.directions,t1.station,t1.station_name,t1.station_route_code,t1.line_code,t1.station_code,t1.station_mark,t1.distances,t1.to_time,t2.id AS station_id,t2.db_type,t2.b_jwpoints,t2.g_lonx,t2.g_laty,t2.radius,ST_AsText(t2.g_polygon_grid) as g_polygon_grid,t2.shapes_type FROM bsth_c_ls_stationroute t1 LEFT JOIN bsth_c_station t2 ON t1.station_code = t2.station_cod where t1.destroy=0 and t1.line_code='" + lineCode + "' and t1.versions="+extendsVersion+" order by t1.directions, t1.station_route_code";
  398 + List<CascadeSaveStation> cssList = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(CascadeSaveStation.class));
  399 +
  400 + //新的站点编码
  401 + long sCode;
  402 + for (CascadeSaveStation ss : cssList) {
  403 + sCode = stationRepository.stationMaxId() + 1;
  404 + ss.setRouteId(null);
  405 + ss.setStationCode(sCode + "");
  406 + ss.setStation((int) sCode);
  407 + }
  408 + //入库新版本的站点 和 路由
  409 + batchInsertStation(cssList, maxVersion);
  410 +
  411 + //复制路段信息
  412 + sql = "SELECT t1.id AS route_id,t1.line,t1.line_code,t1.directions,t1.section,t1.section_code,t1.sectionroute_code,t1.versions,t2.section_name,t2.croses_road,ST_AsText(t2.gsection_vector) as gsection_vector,t2.db_type,t2.speed_limit FROM bsth_c_ls_sectionroute t1 LEFT JOIN bsth_c_section t2 ON t1.section_code = t2.section_code WHERE t1.destroy = 0 AND t1.line_code = '"+lineCode+"' and t1.versions="+ extendsVersion +" ORDER BY t1.directions,t1.sectionroute_code";
  413 + List<CascadeSaveRoad> csrList = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(CascadeSaveRoad.class));
  414 + //新的路段编码
  415 + long cCode;
  416 + for(CascadeSaveRoad csr : csrList){
  417 + cCode = sectionRepository.sectionMaxId() + 1;
  418 + csr.setRouteId(null);
  419 + csr.setSection((int) cCode);
  420 + csr.setSectionCode(cCode + "");
  421 + }
  422 + //入库新版本的路段 和 路段路由
  423 + batchInsertRoad(csrList, maxVersion);
  424 + }
  425 +
  426 + rs.put("newVersion", maxVersion);
  427 + rs.put("status", ResponseCode.SUCCESS);
  428 + } catch (Exception e) {
  429 + status.setRollbackOnly();
  430 + logger.error("", e);
  431 + rs.put("status", ResponseCode.ERROR);
  432 + rs.put("msg", "服务器出现异常");
420 } 433 }
421 - //入库新版本的路段 和 路段路由  
422 - batchInsertRoad(csrList, maxVersion); 434 + return rs;
423 } 435 }
  436 + });
424 437
425 - tran.commit(status);  
426 - rs.put("newVersion", maxVersion);  
427 - rs.put("status", ResponseCode.SUCCESS);  
428 - } catch (Exception e) {  
429 - tran.rollback(status);  
430 - logger.error("", e);  
431 - rs.put("status", ResponseCode.ERROR);  
432 - rs.put("msg", "服务器出现异常");  
433 - }  
434 - return rs;  
435 } 438 }
436 439
437 /** 440 /**
@@ -444,19 +447,17 @@ public class GeoDataServiceImpl implements GeoDataService { @@ -444,19 +447,17 @@ public class GeoDataServiceImpl implements GeoDataService {
444 public Map<String, Object> deleteLineVersion(String lineCode, int version) { 447 public Map<String, Object> deleteLineVersion(String lineCode, int version) {
445 Map<String, Object> rs = new HashMap<>(); 448 Map<String, Object> rs = new HashMap<>();
446 449
447 - //编程式事务  
448 - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource());  
449 - DefaultTransactionDefinition def = new DefaultTransactionDefinition();  
450 - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);  
451 - TransactionStatus status = tran.getTransaction(def);  
452 - try{  
453 - int enableVersion = jdbcTemplate.queryForObject("select versions from bsth_c_line_versions where line_code='"+lineCode+"' and `status`=1", Integer.class);  
454 -  
455 - if(enableVersion==version){  
456 - rs.put("status", ResponseCode.ERROR);  
457 - rs.put("msg", "你不能删除当前正在启用的走向版本!");  
458 - return rs;  
459 - } 450 + return transactionTemplate.execute(new TransactionCallback<Map<String, Object>>() {
  451 + @Override
  452 + public Map<String, Object> doInTransaction(TransactionStatus status) {
  453 + try{
  454 + int enableVersion = jdbcTemplate.queryForObject("select versions from bsth_c_line_versions where line_code='"+lineCode+"' and `status`=1", Integer.class);
  455 +
  456 + if(enableVersion==version){
  457 + rs.put("status", ResponseCode.ERROR);
  458 + rs.put("msg", "你不能删除当前正在启用的走向版本!");
  459 + return rs;
  460 + }
460 /*int versionCount = jdbcTemplate.queryForObject("select count(*) from bsth_c_line_versions where line_code='"+lineCode+"'", Integer.class); 461 /*int versionCount = jdbcTemplate.queryForObject("select count(*) from bsth_c_line_versions where line_code='"+lineCode+"'", Integer.class);
461 if(versionCount == 1){ 462 if(versionCount == 1){
462 rs.put("status", ResponseCode.ERROR); 463 rs.put("status", ResponseCode.ERROR);
@@ -472,27 +473,29 @@ public class GeoDataServiceImpl implements GeoDataService { @@ -472,27 +473,29 @@ public class GeoDataServiceImpl implements GeoDataService {
472 473
473 List<Integer> stationRemoves = jdbcTemplate.queryForList(sql, Integer.class);*/ 474 List<Integer> stationRemoves = jdbcTemplate.queryForList(sql, Integer.class);*/
474 475
475 - //删除站点路由  
476 - String sql = "delete from bsth_c_ls_stationroute where line_code='"+lineCode+"' and versions=" + version;  
477 - jdbcTemplate.update(sql); 476 + //删除站点路由
  477 + String sql = "delete from bsth_c_ls_stationroute where line_code='"+lineCode+"' and versions=" + version;
  478 + jdbcTemplate.update(sql);
478 479
479 - //删除路段路由  
480 - sql = "delete from bsth_c_ls_sectionroute where line_code='"+lineCode+"' and versions=" + version;  
481 - jdbcTemplate.update(sql); 480 + //删除路段路由
  481 + sql = "delete from bsth_c_ls_sectionroute where line_code='"+lineCode+"' and versions=" + version;
  482 + jdbcTemplate.update(sql);
482 483
483 - //删除版本信息  
484 - sql = "delete from bsth_c_line_versions where line_code='"+lineCode+"' and versions=" + version;  
485 - jdbcTemplate.update(sql); 484 + //删除版本信息
  485 + sql = "delete from bsth_c_line_versions where line_code='"+lineCode+"' and versions=" + version;
  486 + jdbcTemplate.update(sql);
  487 +
  488 + rs.put("status", ResponseCode.SUCCESS);
  489 + }catch (Exception e){
  490 + status.setRollbackOnly();
  491 + logger.error("", e);
  492 + rs.put("status", ResponseCode.ERROR);
  493 + rs.put("msg", "服务器出现异常");
  494 + }
  495 + return rs;
  496 + }
  497 + });
486 498
487 - tran.commit(status);  
488 - rs.put("status", ResponseCode.SUCCESS);  
489 - }catch (Exception e){  
490 - tran.rollback(status);  
491 - logger.error("", e);  
492 - rs.put("status", ResponseCode.ERROR);  
493 - rs.put("msg", "服务器出现异常");  
494 - }  
495 - return rs;  
496 } 499 }
497 500
498 /** 501 /**
@@ -541,7 +544,7 @@ public class GeoDataServiceImpl implements GeoDataService { @@ -541,7 +544,7 @@ public class GeoDataServiceImpl implements GeoDataService {
541 544
542 /** 545 /**
543 * 批量入库路段 546 * 批量入库路段
544 - * @param cssList 547 + * @param csrList
545 * @param version 548 * @param version
546 */ 549 */
547 private void batchInsertRoad(final List<CascadeSaveRoad> csrList, final int version){ 550 private void batchInsertRoad(final List<CascadeSaveRoad> csrList, final int version){
@@ -659,145 +662,144 @@ public class GeoDataServiceImpl implements GeoDataService { @@ -659,145 +662,144 @@ public class GeoDataServiceImpl implements GeoDataService {
659 public Map<String, Object> addNewStationRoute(String lineCode, int upDown, int versions, String stationName, Float lat, Float lng, int prevRouteId) { 662 public Map<String, Object> addNewStationRoute(String lineCode, int upDown, int versions, String stationName, Float lat, Float lng, int prevRouteId) {
660 Map<String, Object> rs = new HashMap<>(); 663 Map<String, Object> rs = new HashMap<>();
661 664
662 - //编程式事务  
663 - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource());  
664 - DefaultTransactionDefinition def = new DefaultTransactionDefinition();  
665 - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);  
666 - TransactionStatus status = tran.getTransaction(def);  
667 - try {  
668 - //根据线路编码,查询线路ID  
669 - int lineId = jdbcTemplate.queryForObject("select id from bsth_c_line where line_code=" + lineCode, Integer.class); 665 + return transactionTemplate.execute(new TransactionCallback<Map<String, Object>>() {
  666 + @Override
  667 + public Map<String, Object> doInTransaction(TransactionStatus status) {
  668 + try {
  669 + //根据线路编码,查询线路ID
  670 + int lineId = jdbcTemplate.queryForObject("select id from bsth_c_line where line_code=" + lineCode, Integer.class);
670 671
671 - String sql = "select * from bsth_c_ls_stationroute where line_code='" + lineCode + "' and line=" + lineId + " and directions=" + upDown + " and destroy=0 and versions=" + versions;  
672 - List<SaveStationRouteDTO> routes = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(SaveStationRouteDTO.class)); 672 + String sql = "select * from bsth_c_ls_stationroute where line_code='" + lineCode + "' and line=" + lineId + " and directions=" + upDown + " and destroy=0 and versions=" + versions;
  673 + List<SaveStationRouteDTO> routes = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(SaveStationRouteDTO.class));
673 674
674 - for (SaveStationRouteDTO s : routes) {  
675 - if (s.getStationName().equals(stationName)) { 675 + for (SaveStationRouteDTO s : routes) {
  676 + if (s.getStationName().equals(stationName)) {
676 677
  678 + rs.put("status", ResponseCode.ERROR);
  679 + rs.put("msg", "重复的站点路由名称!");
  680 + return rs;
  681 + }
  682 + }
  683 + //按路由顺序排列
  684 + Collections.sort(routes, new StationRouteComp());
  685 +
  686 + //转WGS
  687 + TransGPS.Location wgsLoc = TransGPS.transformFromGCJToWGS(TransGPS.bd_decrypt(TransGPS.LocationMake(Double.parseDouble(String.valueOf(lng)), Double.parseDouble(String.valueOf(lat)))));
  688 +
  689 + //insert 站点
  690 + long sCode = stationRepository.stationMaxId() + 1;
  691 + jdbcTemplate.update("insert into bsth_c_station(id, station_cod, station_name, db_type, b_jwpoints, g_lonx, g_laty, destroy, radius, shapes_type, versions) " +
  692 + " values(?,?,?,?,?,?,?,?,?,?,?)", sCode, sCode, stationName, "b", lng + " " + lat, wgsLoc.getLng(), wgsLoc.getLat(), 0, 88, "r", 1);
  693 +
  694 +
  695 + SaveStationRouteDTO sr;
  696 + int currentNo = -1,
  697 + no = 100, step = 100;
  698 +
  699 + if (prevRouteId == -1) {
  700 + //起点站
  701 + currentNo = no;
  702 + no += step;
  703 + }
  704 + //重新排序路由
  705 + for (int i = 0, size = routes.size(); i < size; i++) {
  706 + sr = routes.get(i);
  707 + sr.setStationRouteCode(no);
  708 + no += step;
  709 + if (sr.getId().intValue() == prevRouteId) {
  710 + currentNo = no;
  711 + no += step;
  712 + }
  713 + }
  714 +
  715 + SaveStationRouteDTO nsr = new SaveStationRouteDTO();
  716 + nsr.setLine(lineId);
  717 + nsr.setLineCode(lineCode);
  718 + nsr.setDirections(upDown);
  719 + nsr.setVersions(versions);
  720 + nsr.setStationRouteCode(currentNo);
  721 + nsr.setStation(sCode);
  722 + nsr.setStationCode(sCode + "");
  723 + nsr.setStationName(stationName);
  724 + nsr.setDistances(0d);
  725 + nsr.setToTime(0d);
  726 + Date d = new Date();
  727 + nsr.setCreateDate(d);
  728 + nsr.setUpdateDate(d);
  729 + nsr.setDestroy(0);
  730 + if (prevRouteId == -1)
  731 + nsr.setStationMark("B");
  732 + else if(routes.size()==1)
  733 + nsr.setStationMark("E");
  734 +
  735 + //routes.add(sr);
  736 +
  737 + //重新标记mark
  738 + Collections.sort(routes, new StationRouteComp());
  739 + for (int i = 0, size = routes.size(); i < size; i++) {
  740 + routes.get(i).setStationMark("Z");
  741 + }
  742 + if(routes.size() > 0 && prevRouteId!=-1)
  743 + routes.get(0).setStationMark("B");
  744 + if(routes.size() > 1)
  745 + routes.get(routes.size() - 1).setStationMark("E");
  746 +
  747 + final List<SaveStationRouteDTO> saveList = routes;
  748 + //insert 新路由 (ID自增)
  749 + jdbcTemplate.update("insert into bsth_c_ls_stationroute(line, station, station_name, station_route_code, line_code, station_code, station_mark, distances, to_time, destroy, versions, create_date, update_date,directions) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
  750 + , nsr.getLine(), nsr.getStation(), nsr.getStationName(), nsr.getStationRouteCode(), nsr.getLineCode(), nsr.getStationCode(), nsr.getStationMark()
  751 + , nsr.getDistances(), nsr.getToTime(), nsr.getDestroy(), nsr.getVersions(), nsr.getCreateDate(), nsr.getUpdateDate(), nsr.getDirections());
  752 +
  753 + // update 原路由
  754 + jdbcTemplate.batchUpdate("update bsth_c_ls_stationroute set line=?,station=?,station_name=?,station_route_code=?," +
  755 + "line_code=?,station_code=?,station_mark=?,distances=?,to_time=?,destroy=?,versions=?,create_date=?,update_date=?,directions=?" +
  756 + " where id=?"
  757 + , new BatchPreparedStatementSetter() {
  758 + @Override
  759 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  760 + SaveStationRouteDTO sr = saveList.get(i);
  761 + ps.setInt(1, sr.getLine());
  762 + ps.setLong(2, sr.getStation());
  763 + ps.setString(3, sr.getStationName());
  764 + ps.setInt(4, sr.getStationRouteCode());
  765 + ps.setString(5, sr.getLineCode());
  766 + ps.setString(6, sr.getStationCode());
  767 + ps.setString(7, sr.getStationMark());
  768 + ps.setDouble(8, sr.getDistances());
  769 + ps.setDouble(9, sr.getToTime());
  770 + ps.setInt(10, sr.getDestroy());
  771 + ps.setInt(11, sr.getVersions());
  772 + ps.setTimestamp(12, new java.sql.Timestamp(sr.getCreateDate().getTime()));
  773 + ps.setTimestamp(13, new java.sql.Timestamp(sr.getUpdateDate().getTime()));
  774 + ps.setInt(14, sr.getDirections());
  775 + ps.setInt(15, sr.getId());
  776 + }
  777 +
  778 + @Override
  779 + public int getBatchSize() {
  780 + return saveList.size();
  781 + }
  782 + });
  783 +
  784 + //写一条走向变更记录
  785 + jdbcTemplate.update("insert into logger_route_synchro(t, line_code, version) values(?, ?, ?)", System.currentTimeMillis(), lineCode, versions);
  786 +
  787 + //返回更新之后的数据
  788 + List<GeoStation> list = findByUpdown(lineCode, upDown, versions);
  789 +
  790 + rs.put("list", list);
  791 + rs.put("newStationRouteCode", currentNo);
  792 + rs.put("status", ResponseCode.SUCCESS);
  793 + } catch (Exception e) {
  794 + status.setRollbackOnly();
  795 + logger.error("", e);
677 rs.put("status", ResponseCode.ERROR); 796 rs.put("status", ResponseCode.ERROR);
678 - rs.put("msg", "重复的站点路由名称!");  
679 - return rs; 797 + rs.put("msg", "服务器出现异常");
680 } 798 }
  799 + return rs;
681 } 800 }
682 - //按路由顺序排列  
683 - Collections.sort(routes, new StationRouteComp());  
684 -  
685 - //转WGS  
686 - TransGPS.Location wgsLoc = TransGPS.transformFromGCJToWGS(TransGPS.bd_decrypt(TransGPS.LocationMake(Double.parseDouble(String.valueOf(lng)), Double.parseDouble(String.valueOf(lat)))));  
687 -  
688 - //insert 站点  
689 - long sCode = stationRepository.stationMaxId() + 1;  
690 - jdbcTemplate.update("insert into bsth_c_station(id, station_cod, station_name, db_type, b_jwpoints, g_lonx, g_laty, destroy, radius, shapes_type, versions) " +  
691 - " values(?,?,?,?,?,?,?,?,?,?,?)", sCode, sCode, stationName, "b", lng + " " + lat, wgsLoc.getLng(), wgsLoc.getLat(), 0, 88, "r", 1);  
692 -  
693 -  
694 - SaveStationRouteDTO sr;  
695 - int currentNo = -1,  
696 - no = 100, step = 100;  
697 -  
698 - if (prevRouteId == -1) {  
699 - //起点站  
700 - currentNo = no;  
701 - no += step;  
702 - }  
703 - //重新排序路由  
704 - for (int i = 0, size = routes.size(); i < size; i++) {  
705 - sr = routes.get(i);  
706 - sr.setStationRouteCode(no);  
707 - no += step;  
708 - if (sr.getId().intValue() == prevRouteId) {  
709 - currentNo = no;  
710 - no += step;  
711 - }  
712 - }  
713 -  
714 - SaveStationRouteDTO nsr = new SaveStationRouteDTO();  
715 - nsr.setLine(lineId);  
716 - nsr.setLineCode(lineCode);  
717 - nsr.setDirections(upDown);  
718 - nsr.setVersions(versions);  
719 - nsr.setStationRouteCode(currentNo);  
720 - nsr.setStation(sCode);  
721 - nsr.setStationCode(sCode + "");  
722 - nsr.setStationName(stationName);  
723 - nsr.setDistances(0d);  
724 - nsr.setToTime(0d);  
725 - Date d = new Date();  
726 - nsr.setCreateDate(d);  
727 - nsr.setUpdateDate(d);  
728 - nsr.setDestroy(0);  
729 - if (prevRouteId == -1)  
730 - nsr.setStationMark("B");  
731 - else if(routes.size()==1)  
732 - nsr.setStationMark("E");  
733 -  
734 - //routes.add(sr);  
735 -  
736 - //重新标记mark  
737 - Collections.sort(routes, new StationRouteComp());  
738 - for (int i = 0, size = routes.size(); i < size; i++) {  
739 - routes.get(i).setStationMark("Z");  
740 - }  
741 - if(routes.size() > 0 && prevRouteId!=-1)  
742 - routes.get(0).setStationMark("B");  
743 - if(routes.size() > 1)  
744 - routes.get(routes.size() - 1).setStationMark("E");  
745 -  
746 - final List<SaveStationRouteDTO> saveList = routes;  
747 - //insert 新路由 (ID自增)  
748 - jdbcTemplate.update("insert into bsth_c_ls_stationroute(line, station, station_name, station_route_code, line_code, station_code, station_mark, distances, to_time, destroy, versions, create_date, update_date,directions) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"  
749 - , nsr.getLine(), nsr.getStation(), nsr.getStationName(), nsr.getStationRouteCode(), nsr.getLineCode(), nsr.getStationCode(), nsr.getStationMark()  
750 - , nsr.getDistances(), nsr.getToTime(), nsr.getDestroy(), nsr.getVersions(), nsr.getCreateDate(), nsr.getUpdateDate(), nsr.getDirections());  
751 -  
752 - // update 原路由  
753 - jdbcTemplate.batchUpdate("update bsth_c_ls_stationroute set line=?,station=?,station_name=?,station_route_code=?," +  
754 - "line_code=?,station_code=?,station_mark=?,distances=?,to_time=?,destroy=?,versions=?,create_date=?,update_date=?,directions=?" +  
755 - " where id=?"  
756 - , new BatchPreparedStatementSetter() {  
757 - @Override  
758 - public void setValues(PreparedStatement ps, int i) throws SQLException {  
759 - SaveStationRouteDTO sr = saveList.get(i);  
760 - ps.setInt(1, sr.getLine());  
761 - ps.setLong(2, sr.getStation());  
762 - ps.setString(3, sr.getStationName());  
763 - ps.setInt(4, sr.getStationRouteCode());  
764 - ps.setString(5, sr.getLineCode());  
765 - ps.setString(6, sr.getStationCode());  
766 - ps.setString(7, sr.getStationMark());  
767 - ps.setDouble(8, sr.getDistances());  
768 - ps.setDouble(9, sr.getToTime());  
769 - ps.setInt(10, sr.getDestroy());  
770 - ps.setInt(11, sr.getVersions());  
771 - ps.setTimestamp(12, new java.sql.Timestamp(sr.getCreateDate().getTime()));  
772 - ps.setTimestamp(13, new java.sql.Timestamp(sr.getUpdateDate().getTime()));  
773 - ps.setInt(14, sr.getDirections());  
774 - ps.setInt(15, sr.getId());  
775 - }  
776 -  
777 - @Override  
778 - public int getBatchSize() {  
779 - return saveList.size();  
780 - }  
781 - });  
782 -  
783 - //写一条走向变更记录  
784 - jdbcTemplate.update("insert into logger_route_synchro(t, line_code, version) values(?, ?, ?)", System.currentTimeMillis(), lineCode, versions);  
785 -  
786 - tran.commit(status);  
787 -  
788 - //返回更新之后的数据  
789 - List<GeoStation> list = findByUpdown(lineCode, upDown, versions); 801 + });
790 802
791 - rs.put("list", list);  
792 - rs.put("newStationRouteCode", currentNo);  
793 - rs.put("status", ResponseCode.SUCCESS);  
794 - } catch (Exception e) {  
795 - tran.rollback(status);  
796 - logger.error("", e);  
797 - rs.put("status", ResponseCode.ERROR);  
798 - rs.put("msg", "服务器出现异常");  
799 - }  
800 - return rs;  
801 } 803 }
802 804
803 private List<GeoStation> findByUpdown(String lineCode, int upDown, int versions) { 805 private List<GeoStation> findByUpdown(String lineCode, int upDown, int versions) {
@@ -827,87 +829,86 @@ public class GeoDataServiceImpl implements GeoDataService { @@ -827,87 +829,86 @@ public class GeoDataServiceImpl implements GeoDataService {
827 public Map<String, Object> destroyStation(GeoStation station) { 829 public Map<String, Object> destroyStation(GeoStation station) {
828 Map<String, Object> rs = new HashMap<>(); 830 Map<String, Object> rs = new HashMap<>();
829 831
830 - //编程式事务  
831 - DataSourceTransactionManager tran = new DataSourceTransactionManager(jdbcTemplate.getDataSource());  
832 - DefaultTransactionDefinition def = new DefaultTransactionDefinition();  
833 - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);  
834 - TransactionStatus status = tran.getTransaction(def);  
835 - try {  
836 - String sql = "update bsth_c_ls_stationroute set destroy=1 where id=?";  
837 - jdbcTemplate.update(sql, station.getId());  
838 -  
839 - /**  
840 - * ########## 重新排序路由,标记mark #########  
841 - */  
842 - sql = "select * from bsth_c_ls_stationroute where line_code='" + station.getLineCode() + "' and directions=" + station.getDirections() + " and destroy=0 and versions=" + station.getVersions();  
843 - List<SaveStationRouteDTO> routes = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(SaveStationRouteDTO.class));  
844 - Collections.sort(routes, new StationRouteComp());  
845 -  
846 - int no = 0,  
847 - step = 100;  
848 - SaveStationRouteDTO sr;  
849 - //重新排序路由  
850 - for (int i = 0, size = routes.size(); i < size; i++) {  
851 - sr = routes.get(i);  
852 - sr.setStationRouteCode(no += step);  
853 - }  
854 -  
855 - for (int i = 0, size = routes.size(); i < size; i++) {  
856 - routes.get(i).setStationMark("Z"); 832 + return transactionTemplate.execute(new TransactionCallback<Map<String, Object>>() {
  833 + @Override
  834 + public Map<String, Object> doInTransaction(TransactionStatus status) {
  835 + try {
  836 + String sql = "update bsth_c_ls_stationroute set destroy=1 where id=?";
  837 + jdbcTemplate.update(sql, station.getId());
  838 +
  839 + /**
  840 + * ########## 重新排序路由,标记mark #########
  841 + */
  842 + sql = "select * from bsth_c_ls_stationroute where line_code='" + station.getLineCode() + "' and directions=" + station.getDirections() + " and destroy=0 and versions=" + station.getVersions();
  843 + List<SaveStationRouteDTO> routes = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(SaveStationRouteDTO.class));
  844 + Collections.sort(routes, new StationRouteComp());
  845 +
  846 + int no = 0,
  847 + step = 100;
  848 + SaveStationRouteDTO sr;
  849 + //重新排序路由
  850 + for (int i = 0, size = routes.size(); i < size; i++) {
  851 + sr = routes.get(i);
  852 + sr.setStationRouteCode(no += step);
  853 + }
  854 +
  855 + for (int i = 0, size = routes.size(); i < size; i++) {
  856 + routes.get(i).setStationMark("Z");
  857 + }
  858 + if(routes.size() > 0)
  859 + routes.get(0).setStationMark("B");
  860 + if(routes.size() > 1)
  861 + routes.get(routes.size() - 1).setStationMark("E");
  862 +
  863 + final List<SaveStationRouteDTO> saveList = routes;
  864 + // update 原路由
  865 + jdbcTemplate.batchUpdate("update bsth_c_ls_stationroute set line=?,station=?,station_name=?,station_route_code=?," +
  866 + "line_code=?,station_code=?,station_mark=?,distances=?,to_time=?,destroy=?,versions=?,create_date=?,update_date=?,directions=?" +
  867 + " where id=?"
  868 + , new BatchPreparedStatementSetter() {
  869 + @Override
  870 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  871 + SaveStationRouteDTO sr = saveList.get(i);
  872 + ps.setInt(1, sr.getLine());
  873 + ps.setLong(2, sr.getStation());
  874 + ps.setString(3, sr.getStationName());
  875 + ps.setInt(4, sr.getStationRouteCode());
  876 + ps.setString(5, sr.getLineCode());
  877 + ps.setString(6, sr.getStationCode());
  878 + ps.setString(7, sr.getStationMark());
  879 + ps.setDouble(8, sr.getDistances());
  880 + ps.setDouble(9, sr.getToTime());
  881 + ps.setInt(10, sr.getDestroy());
  882 + ps.setInt(11, sr.getVersions());
  883 + ps.setTimestamp(12, new java.sql.Timestamp(sr.getCreateDate().getTime()));
  884 + ps.setTimestamp(13, new java.sql.Timestamp(sr.getUpdateDate().getTime()));
  885 + ps.setInt(14, sr.getDirections());
  886 + ps.setInt(15, sr.getId());
  887 + }
  888 +
  889 + @Override
  890 + public int getBatchSize() {
  891 + return saveList.size();
  892 + }
  893 + });
  894 +
  895 + //写一条走向变更记录
  896 + jdbcTemplate.update("insert into logger_route_synchro(t, line_code, version) values(?, ?, ?)", System.currentTimeMillis(), station.getLineCode(), station.getVersions());
  897 +
  898 + //返回更新之后的数据
  899 + List<GeoStation> list = findByUpdown(station.getLineCode(), station.getDirections(), station.getVersions());
  900 + rs.put("list", list);
  901 + rs.put("status", ResponseCode.SUCCESS);
  902 + } catch (Exception e) {
  903 + status.setRollbackOnly();
  904 + logger.error("", e);
  905 + rs.put("status", ResponseCode.ERROR);
  906 + rs.put("msg", "服务器出现异常");
  907 + }
  908 + return rs;
857 } 909 }
858 - if(routes.size() > 0)  
859 - routes.get(0).setStationMark("B");  
860 - if(routes.size() > 1)  
861 - routes.get(routes.size() - 1).setStationMark("E");  
862 -  
863 - final List<SaveStationRouteDTO> saveList = routes;  
864 - // update 原路由  
865 - jdbcTemplate.batchUpdate("update bsth_c_ls_stationroute set line=?,station=?,station_name=?,station_route_code=?," +  
866 - "line_code=?,station_code=?,station_mark=?,distances=?,to_time=?,destroy=?,versions=?,create_date=?,update_date=?,directions=?" +  
867 - " where id=?"  
868 - , new BatchPreparedStatementSetter() {  
869 - @Override  
870 - public void setValues(PreparedStatement ps, int i) throws SQLException {  
871 - SaveStationRouteDTO sr = saveList.get(i);  
872 - ps.setInt(1, sr.getLine());  
873 - ps.setLong(2, sr.getStation());  
874 - ps.setString(3, sr.getStationName());  
875 - ps.setInt(4, sr.getStationRouteCode());  
876 - ps.setString(5, sr.getLineCode());  
877 - ps.setString(6, sr.getStationCode());  
878 - ps.setString(7, sr.getStationMark());  
879 - ps.setDouble(8, sr.getDistances());  
880 - ps.setDouble(9, sr.getToTime());  
881 - ps.setInt(10, sr.getDestroy());  
882 - ps.setInt(11, sr.getVersions());  
883 - ps.setTimestamp(12, new java.sql.Timestamp(sr.getCreateDate().getTime()));  
884 - ps.setTimestamp(13, new java.sql.Timestamp(sr.getUpdateDate().getTime()));  
885 - ps.setInt(14, sr.getDirections());  
886 - ps.setInt(15, sr.getId());  
887 - }  
888 -  
889 - @Override  
890 - public int getBatchSize() {  
891 - return saveList.size();  
892 - }  
893 - });  
894 -  
895 - //写一条走向变更记录  
896 - jdbcTemplate.update("insert into logger_route_synchro(t, line_code, version) values(?, ?, ?)", System.currentTimeMillis(), station.getLineCode(), station.getVersions());  
897 -  
898 - tran.commit(status); 910 + });
899 911
900 - //返回更新之后的数据  
901 - List<GeoStation> list = findByUpdown(station.getLineCode(), station.getDirections(), station.getVersions());  
902 - rs.put("list", list);  
903 - rs.put("status", ResponseCode.SUCCESS);  
904 - } catch (Exception e) {  
905 - tran.rollback(status);  
906 - logger.error("", e);  
907 - rs.put("status", ResponseCode.ERROR);  
908 - rs.put("msg", "服务器出现异常");  
909 - }  
910 - return rs;  
911 } 912 }
912 913
913 @Override 914 @Override
src/main/java/com/bsth/websocket/handler/SendUtils.java
@@ -8,6 +8,7 @@ import com.bsth.data.maintenance_plan.MaintenancePlan; @@ -8,6 +8,7 @@ import com.bsth.data.maintenance_plan.MaintenancePlan;
8 import com.bsth.data.safe_driv.SafeDriv; 8 import com.bsth.data.safe_driv.SafeDriv;
9 import com.bsth.entity.directive.D80; 9 import com.bsth.entity.directive.D80;
10 import com.bsth.entity.realcontrol.ScheduleRealInfo; 10 import com.bsth.entity.realcontrol.ScheduleRealInfo;
  11 +import com.bsth.message.entity.CarErrorStop;
11 import com.bsth.websocket.dto.WsScheduleRealInfo; 12 import com.bsth.websocket.dto.WsScheduleRealInfo;
12 import com.fasterxml.jackson.core.JsonProcessingException; 13 import com.fasterxml.jackson.core.JsonProcessingException;
13 import com.fasterxml.jackson.databind.ObjectMapper; 14 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -268,4 +269,22 @@ public class SendUtils{ @@ -268,4 +269,22 @@ public class SendUtils{
268 logger.error("sendMaintenancePlan", e); 269 logger.error("sendMaintenancePlan", e);
269 } 270 }
270 } 271 }
  272 +
  273 + /**
  274 + * 将车辆异常停车发送至线调页面
  275 + */
  276 + public void sendCarErrorStop(CarErrorStop carErrorStop) {
  277 + Map<String, Object> map = new HashMap<>();
  278 + map.put("fn", "carErrorStop");
  279 + map.put("data", carErrorStop);
  280 + ObjectMapper mapper = new ObjectMapper();
  281 +
  282 + try {
  283 + if (carErrorStop.getLineId() != null) {
  284 + socketHandler.sendMessageToLine(carErrorStop.getLineId(), mapper.writeValueAsString(map));
  285 + }
  286 + } catch (JsonProcessingException e) {
  287 + logger.error("sendCarErrorStop", e);
  288 + }
  289 + }
271 } 290 }
src/main/resources/application-cloud.properties
@@ -30,6 +30,13 @@ spring.datasource.hikari.connection-test-query= SELECT 1 @@ -30,6 +30,13 @@ spring.datasource.hikari.connection-test-query= SELECT 1
30 spring.datasource.hikari.validation-timeout= 3000 30 spring.datasource.hikari.validation-timeout= 3000
31 spring.datasource.hikari.register-mbeans=true 31 spring.datasource.hikari.register-mbeans=true
32 32
  33 +kafka.use= true
  34 +spring.kafka.consumer.bootstrap-servers= 192.170.100.114:9092,192.170.100.114:9093,192.170.100.114:9094
  35 +spring.kafka.consumer.group-id= schedule-system
  36 +spring.kafka.consumer.auto-offset-reset= latest
  37 +spring.kafka.consumer.key-deserializer= org.apache.kafka.common.serialization.StringDeserializer
  38 +spring.kafka.consumer.value-deserializer= org.apache.kafka.common.serialization.StringDeserializer
  39 +
33 ## gps client data 40 ## gps client data
34 http.gps.real.cache.url= http://10.10.150.24:12580/realGps/all 41 http.gps.real.cache.url= http://10.10.150.24:12580/realGps/all
35 ## gateway real data 42 ## gateway real data
@@ -57,8 +64,8 @@ admin.mail= 3090342880@qq.com @@ -57,8 +64,8 @@ admin.mail= 3090342880@qq.com
57 ## enabled 64 ## enabled
58 enabled.whiteip= true 65 enabled.whiteip= true
59 66
60 -sso.enabled= false  
61 -sso.systemcode = SYS0019  
62 -sso.http.url.login= http://180.169.154.251:28090/portal/index.html#/login  
63 -sso.http.url.logout= http://180.169.154.251:18080/information/api/v1/logout  
64 -sso.http.url.auth= http://180.169.154.251:18080/information/authenticate/authorityAuthentication  
65 \ No newline at end of file 67 \ No newline at end of file
  68 +sso.enabled= true
  69 +sso.systemcode = SYS0023
  70 +sso.http.url.login= https://112.64.45.51/portal/index.html#/login
  71 +sso.http.url.logout= https://112.64.45.51/information/api/v1/logout
  72 +sso.http.url.auth= https://112.64.45.51/information/authenticate/authorityAuthentication
66 \ No newline at end of file 73 \ No newline at end of file