Commit 66d81f185d0612baf22f9af30a346f59378850b8

Authored by 潘钊
1 parent eea73673

update...

src/main/java/com/bsth/controller/directive/DirectiveController.java
1 package com.bsth.controller.directive; 1 package com.bsth.controller.directive;
2 2
3 -import java.util.List;  
4 -import java.util.Map;  
5 -  
6 -import org.apache.commons.lang3.StringEscapeUtils;  
7 -import org.springframework.beans.factory.annotation.Autowired;  
8 -import org.springframework.web.bind.annotation.RequestMapping;  
9 -import org.springframework.web.bind.annotation.RequestMethod;  
10 -import org.springframework.web.bind.annotation.RequestParam;  
11 -import org.springframework.web.bind.annotation.RestController;  
12 -  
13 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
14 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
15 import com.bsth.entity.directive.D80; 5 import com.bsth.entity.directive.D80;
@@ -17,6 +7,15 @@ import com.bsth.entity.directive.DC0_A3; @@ -17,6 +7,15 @@ import com.bsth.entity.directive.DC0_A3;
17 import com.bsth.entity.sys.SysUser; 7 import com.bsth.entity.sys.SysUser;
18 import com.bsth.security.util.SecurityUtils; 8 import com.bsth.security.util.SecurityUtils;
19 import com.bsth.service.directive.DirectiveService; 9 import com.bsth.service.directive.DirectiveService;
  10 +import org.apache.commons.lang3.StringEscapeUtils;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.web.bind.annotation.RequestMapping;
  13 +import org.springframework.web.bind.annotation.RequestMethod;
  14 +import org.springframework.web.bind.annotation.RequestParam;
  15 +import org.springframework.web.bind.annotation.RestController;
  16 +
  17 +import java.util.List;
  18 +import java.util.Map;
20 19
21 /** 20 /**
22 * 21 *
@@ -109,6 +108,20 @@ public class DirectiveController { @@ -109,6 +108,20 @@ public class DirectiveController {
109 SysUser user = SecurityUtils.getCurrentUser(); 108 SysUser user = SecurityUtils.getCurrentUser();
110 return directiveService.upDownChange(nbbm, upDown, user.getUserName()); 109 return directiveService.upDownChange(nbbm, upDown, user.getUserName());
111 } 110 }
  111 +
  112 + /**
  113 + *
  114 + * @Title: upDownChange
  115 + * @Description: TODO(状态切换,营运状态 和 上下行)
  116 + * @param @param nbbm 车辆内部编码
  117 + * @param @param upDon
  118 + * @throws
  119 + */
  120 + @RequestMapping(value = "/stateChange", method = RequestMethod.POST)
  121 + public int stateChange(@RequestParam String nbbm, @RequestParam Integer upDown, @RequestParam Integer state){
  122 + SysUser user = SecurityUtils.getCurrentUser();
  123 + return directiveService.stateChange(nbbm, upDown, state, user.getUserName());
  124 + }
112 125
113 /** 126 /**
114 * 127 *
src/main/java/com/bsth/data/gpsdata/GpsRealData.java
1 package com.bsth.data.gpsdata; 1 package com.bsth.data.gpsdata;
2 2
  3 +import com.bsth.Application;
3 import com.bsth.data.BasicData; 4 import com.bsth.data.BasicData;
4 import com.bsth.data.forecast.ForecastRealServer; 5 import com.bsth.data.forecast.ForecastRealServer;
5 import com.bsth.data.gpsdata.thread.GpsDataLoaderThread; 6 import com.bsth.data.gpsdata.thread.GpsDataLoaderThread;
@@ -15,6 +16,7 @@ import org.springframework.boot.CommandLineRunner; @@ -15,6 +16,7 @@ import org.springframework.boot.CommandLineRunner;
15 import org.springframework.stereotype.Component; 16 import org.springframework.stereotype.Component;
16 17
17 import java.util.*; 18 import java.util.*;
  19 +import java.util.concurrent.TimeUnit;
18 20
19 /** 21 /**
20 * @author PanZhao 22 * @author PanZhao
@@ -56,7 +58,7 @@ public class GpsRealData implements CommandLineRunner { @@ -56,7 +58,7 @@ public class GpsRealData implements CommandLineRunner {
56 public void run(String... arg0) throws Exception { 58 public void run(String... arg0) throws Exception {
57 logger.info("gpsDataLoader,20,5"); 59 logger.info("gpsDataLoader,20,5");
58 //定时从网关获取GPS数据 60 //定时从网关获取GPS数据
59 - //Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 20, 5, TimeUnit.SECONDS); 61 + Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 20, 5, TimeUnit.SECONDS);
60 //定时扫描掉离线 62 //定时扫描掉离线
61 //Application.mainServices.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS); 63 //Application.mainServices.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);
62 } 64 }
src/main/java/com/bsth/data/gpsdata/arrival/SignalHandle.java
@@ -5,6 +5,10 @@ import com.bsth.data.gpsdata.arrival.entity.StationRoute; @@ -5,6 +5,10 @@ import com.bsth.data.gpsdata.arrival.entity.StationRoute;
5 import com.bsth.data.gpsdata.arrival.utils.CircleQueue; 5 import com.bsth.data.gpsdata.arrival.utils.CircleQueue;
6 import com.bsth.data.gpsdata.arrival.utils.GeoUtils; 6 import com.bsth.data.gpsdata.arrival.utils.GeoUtils;
7 import com.bsth.entity.realcontrol.ScheduleRealInfo; 7 import com.bsth.entity.realcontrol.ScheduleRealInfo;
  8 +import org.joda.time.format.DateTimeFormat;
  9 +import org.joda.time.format.DateTimeFormatter;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
8 12
9 import java.util.List; 13 import java.util.List;
10 14
@@ -68,6 +72,8 @@ public abstract class SignalHandle { @@ -68,6 +72,8 @@ public abstract class SignalHandle {
68 * } 72 * }
69 */ 73 */
70 74
  75 + Logger logger = LoggerFactory.getLogger(this.getClass());
  76 + private static DateTimeFormatter fmtHHmm = DateTimeFormat.forPattern("HH:mm");
71 protected void transformUpdown(GpsEntity gps, ScheduleRealInfo sch) { 77 protected void transformUpdown(GpsEntity gps, ScheduleRealInfo sch) {
72 int updown = Integer.parseInt(sch.getXlDir()); 78 int updown = Integer.parseInt(sch.getXlDir());
73 //gps 切换走向 79 //gps 切换走向
@@ -78,6 +84,8 @@ public abstract class SignalHandle { @@ -78,6 +84,8 @@ public abstract class SignalHandle {
78 if (station != null) { 84 if (station != null) {
79 gps.setStopNo(station.getCode()); 85 gps.setStopNo(station.getCode());
80 } 86 }
  87 +
  88 + logger.info(fmtHHmm.print(gps.getTimestamp()) + " 车辆 :" + gps.getNbbm() + " 切换到走向 : " + updown);
81 } 89 }
82 90
83 /** 91 /**
src/main/java/com/bsth/data/gpsdata/arrival/handlers/InOutStationSignalHandle.java
@@ -7,6 +7,7 @@ import com.bsth.data.gpsdata.arrival.utils.CircleQueue; @@ -7,6 +7,7 @@ import com.bsth.data.gpsdata.arrival.utils.CircleQueue;
7 import com.bsth.data.gpsdata.arrival.utils.ScheduleSignalState; 7 import com.bsth.data.gpsdata.arrival.utils.ScheduleSignalState;
8 import com.bsth.data.gpsdata.arrival.utils.SignalSchPlanMatcher; 8 import com.bsth.data.gpsdata.arrival.utils.SignalSchPlanMatcher;
9 import com.bsth.data.schedule.DayOfSchedule; 9 import com.bsth.data.schedule.DayOfSchedule;
  10 +import com.bsth.data.schedule.ScheduleComparator;
10 import com.bsth.entity.realcontrol.LineConfig; 11 import com.bsth.entity.realcontrol.LineConfig;
11 import com.bsth.entity.realcontrol.ScheduleRealInfo; 12 import com.bsth.entity.realcontrol.ScheduleRealInfo;
12 import com.bsth.service.directive.DirectiveService; 13 import com.bsth.service.directive.DirectiveService;
@@ -17,6 +18,9 @@ import org.slf4j.LoggerFactory; @@ -17,6 +18,9 @@ import org.slf4j.LoggerFactory;
17 import org.springframework.beans.factory.annotation.Autowired; 18 import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.stereotype.Component; 19 import org.springframework.stereotype.Component;
19 20
  21 +import java.util.Collections;
  22 +import java.util.List;
  23 +
20 /** 24 /**
21 * 进出站动作处理 25 * 进出站动作处理
22 * Created by panzhao on 2016/12/27. 26 * Created by panzhao on 2016/12/27.
@@ -138,6 +142,10 @@ public class InOutStationSignalHandle extends SignalHandle{ @@ -138,6 +142,10 @@ public class InOutStationSignalHandle extends SignalHandle{
138 //持久化 142 //持久化
139 dayOfSchedule.save(sch); 143 dayOfSchedule.save(sch);
140 144
  145 + if(sch.getBcType().equals("out")){
  146 + //出场时,切换成营运状态
  147 + directiveService.send60Operation(sch.getClZbh(), 0, Integer.parseInt(sch.getXlDir()), null, "出场@系统");
  148 + }
141 //出站既出场 149 //出站既出场
142 outStationAndOutPark(sch); 150 outStationAndOutPark(sch);
143 logger.info("班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual()); 151 logger.info("班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual());
@@ -164,6 +172,11 @@ public class InOutStationSignalHandle extends SignalHandle{ @@ -164,6 +172,11 @@ public class InOutStationSignalHandle extends SignalHandle{
164 172
165 sendUtils.refreshSch(schPrev); 173 sendUtils.refreshSch(schPrev);
166 dayOfSchedule.save(schPrev); 174 dayOfSchedule.save(schPrev);
  175 +
  176 + if(schPrev.getBcType().equals("out")){
  177 + //出场时,切换成营运状态
  178 + directiveService.send60Operation(schPrev.getClZbh(), 0, Integer.parseInt(schPrev.getXlDir()), null, "出场@系统");
  179 + }
167 } 180 }
168 } 181 }
169 } 182 }
@@ -204,8 +217,14 @@ public class InOutStationSignalHandle extends SignalHandle{ @@ -204,8 +217,14 @@ public class InOutStationSignalHandle extends SignalHandle{
204 sendUtils.sendZdsj(sch, next, doneSum); 217 sendUtils.sendZdsj(sch, next, doneSum);
205 //持久化 218 //持久化
206 dayOfSchedule.save(sch); 219 dayOfSchedule.save(sch);
207 - //下发调度指令  
208 - directiveService.send60Dispatch(next, doneSum, "到站@系统"); 220 + if(next != null){
  221 + //下发调度指令
  222 + directiveService.send60Dispatch(next, doneSum, "到站@系统");
  223 + }
  224 + else if(sch.getBcType().equals("in")){
  225 + //终班进场,切换成非营运状态
  226 + directiveService.send60Operation(sch.getClZbh(), 1, Integer.parseInt(sch.getXlDir()), null, "进场@系统");
  227 + }
209 228
210 //准备执行下一个班次 229 //准备执行下一个班次
211 if (next != null) { 230 if (next != null) {
@@ -217,10 +236,59 @@ public class InOutStationSignalHandle extends SignalHandle{ @@ -217,10 +236,59 @@ public class InOutStationSignalHandle extends SignalHandle{
217 transformUpdown(gps, next); 236 transformUpdown(gps, next);
218 } 237 }
219 } 238 }
220 - else if(sch.getFcsjActual() == null){  
221 - //有进站,但班次没有实发,向前追溯一下信号  
222 - scheduleSignalState.signalRetrospect(gps, sch); 239 + else {
  240 + if(sch.getFcsjActual() == null){
  241 + //有进站,但班次没有实发,向前追溯一下信号
  242 + scheduleSignalState.signalRetrospect(gps, sch);
  243 + }
  244 +
  245 + //如果当前班次是出场,并且进的是下一个班次的终点
  246 + if(sch.getBcType().equals("out")){
  247 + ScheduleRealInfo next = dayOfSchedule.next(sch);
  248 + if(next.getZdzCode().equals(gps.getStopNo())){
  249 + List<ScheduleRealInfo> halfList = dayOfSchedule.findByNbbm(sch.getClZbh());
  250 + //和当前进站信号最匹配的一个班次
  251 + ScheduleRealInfo nearSch = nearScheduleByGpsIn(gps, halfList);
  252 +
  253 + if(nearSch != null){
  254 + //直接跳到这个班次
  255 + dayOfSchedule.addExecPlan(nearSch);
  256 + //重新进站
  257 + inStation(gps, prev);
  258 + }
  259 + }
  260 + }
  261 + }
  262 + }
  263 +
  264 + /**
  265 + * 和当前进站信号最匹配的一个班次
  266 + * @param gps
  267 + * @param halfList
  268 + * @return
  269 + */
  270 + private ScheduleRealInfo nearScheduleByGpsIn(GpsEntity gps, List<ScheduleRealInfo> halfList){
  271 + if(halfList == null || halfList.size() == 0)
  272 + return null;
  273 +
  274 + //排序
  275 + Collections.sort(halfList, new ScheduleComparator.FCSJ());
  276 + ScheduleRealInfo near = null;// = halfList.get(0);
  277 + ScheduleRealInfo sch;
  278 +
  279 + String stopId = gps.getStopNo();
  280 + for(int i = 0; i < halfList.size(); i ++){
  281 + sch = halfList.get(i);
  282 + if(!sch.getZdzCode().equals(stopId))
  283 + continue;
  284 +
  285 + if(sch.getZdsjT() < gps.getTimestamp())
  286 + near = sch;
  287 + else
  288 + break;
  289 +
223 } 290 }
  291 + return near;
224 } 292 }
225 293
226 /** 294 /**
src/main/java/com/bsth/data/gpsdata/recovery/GpsDataRecovery.java
@@ -60,7 +60,7 @@ public class GpsDataRecovery implements ApplicationContextAware { @@ -60,7 +60,7 @@ public class GpsDataRecovery implements ApplicationContextAware {
60 for (String nbbm : keys) { 60 for (String nbbm : keys) {
61 Collections.sort(listMap.get(nbbm), comp); 61 Collections.sort(listMap.get(nbbm), comp);
62 threadPool.execute(new RecoveryThread(listMap.get(nbbm), count)); 62 threadPool.execute(new RecoveryThread(listMap.get(nbbm), count));
63 - /*if(nbbm.equals("W9H-003")) 63 + /*if(nbbm.equals("SXC-YD012"))
64 new RecoveryThread(listMap.get(nbbm), count).run();*/ 64 new RecoveryThread(listMap.get(nbbm), count).run();*/
65 } 65 }
66 66
@@ -163,9 +163,8 @@ public class GpsDataRecovery implements ApplicationContextAware { @@ -163,9 +163,8 @@ public class GpsDataRecovery implements ApplicationContextAware {
163 reverseSignalHandle.handle(gps, prevs); 163 reverseSignalHandle.handle(gps, prevs);
164 //进出站动作处理 164 //进出站动作处理
165 inOutStationSignalHandle.handle(gps, prevs); 165 inOutStationSignalHandle.handle(gps, prevs);
166 - GeoCacheData.putGps(gps);  
167 166
168 - //Thread.sleep(50); 167 + GeoCacheData.putGps(gps);
169 } 168 }
170 } catch (Exception e) { 169 } catch (Exception e) {
171 logger.error("", e); 170 logger.error("", e);
src/main/java/com/bsth/service/directive/DirectiveService.java
1 package com.bsth.service.directive; 1 package com.bsth.service.directive;
2 2
3 3
4 -import java.util.List;  
5 -import java.util.Map;  
6 -  
7 import com.bsth.entity.directive.D60; 4 import com.bsth.entity.directive.D60;
8 import com.bsth.entity.directive.D64; 5 import com.bsth.entity.directive.D64;
9 import com.bsth.entity.directive.D80; 6 import com.bsth.entity.directive.D80;
@@ -11,6 +8,9 @@ import com.bsth.entity.directive.DC0_A3; @@ -11,6 +8,9 @@ import com.bsth.entity.directive.DC0_A3;
11 import com.bsth.entity.realcontrol.ScheduleRealInfo; 8 import com.bsth.entity.realcontrol.ScheduleRealInfo;
12 import com.bsth.service.BaseService; 9 import com.bsth.service.BaseService;
13 10
  11 +import java.util.List;
  12 +import java.util.Map;
  13 +
14 public interface DirectiveService extends BaseService<D60, Integer>{ 14 public interface DirectiveService extends BaseService<D60, Integer>{
15 15
16 /** 16 /**
@@ -93,4 +93,6 @@ public interface DirectiveService extends BaseService&lt;D60, Integer&gt;{ @@ -93,4 +93,6 @@ public interface DirectiveService extends BaseService&lt;D60, Integer&gt;{
93 int sendC0A5(String json); 93 int sendC0A5(String json);
94 94
95 int refreshLineFile(String deviceId); 95 int refreshLineFile(String deviceId);
  96 +
  97 + int stateChange(String nbbm, Integer upDown, Integer state, String userName);
96 } 98 }
src/main/java/com/bsth/service/directive/DirectiveServiceImpl.java
@@ -504,4 +504,9 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen @@ -504,4 +504,9 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen
504 504
505 return GatewayHttpUtils.postJson(new DirectiveCreator().createDeviceRefreshData(deviceId, gps.getLineId())); 505 return GatewayHttpUtils.postJson(new DirectiveCreator().createDeviceRefreshData(deviceId, gps.getLineId()));
506 } 506 }
  507 +
  508 + @Override
  509 + public int stateChange(String nbbm, Integer upDown, Integer state, String userName) {
  510 + return send60Operation(nbbm, state, upDown, null, userName);
  511 + }
507 } 512 }
src/main/resources/static/real_control_v2/fragments/north/nav/directive_history.html
@@ -65,9 +65,9 @@ @@ -65,9 +65,9 @@
65 {{if obj.reply46 != 0}} 65 {{if obj.reply46 != 0}}
66 <div class="uk-badge uk-badge-danger"> 设备未响应</div> 66 <div class="uk-badge uk-badge-danger"> 设备未响应</div>
67 {{else if obj.reply47 != 0}} 67 {{else if obj.reply47 != 0}}
68 - <div class="uk-badge uk-badge-warning"> 驾驶员未确认</div> 68 + <div class="uk-badge uk-badge-warning"> 设备已响应</div>
69 {{else if obj.reply46 == 0 && obj.reply47 == 0}} 69 {{else if obj.reply46 == 0 && obj.reply47 == 0}}
70 - <div class="uk-badge"> 成功</div> 70 + <div class="uk-badge"> 驾驶员已确认</div>
71 {{/if}} 71 {{/if}}
72 {{/if}} 72 {{/if}}
73 </td> 73 </td>
src/main/resources/static/real_control_v2/js/home/context_menu.js
@@ -39,6 +39,20 @@ var gb_home_context_menu = (function() { @@ -39,6 +39,20 @@ var gb_home_context_menu = (function() {
39 }); 39 });
40 }; 40 };
41 41
  42 + //营运状态和上下行切换
  43 + var stateChange = function (nbbm, updown, state) {
  44 + $.post('/directive/stateChange', {
  45 + nbbm: nbbm,
  46 + upDown: updown,
  47 + state: state
  48 + }, function(rs) {
  49 + if (rs == 0)
  50 + notify_succ('指令已发出');
  51 + else
  52 + notify_err('发送失败,原因参考【指令下发记录】');
  53 + });
  54 + };
  55 +
42 // send phrase 56 // send phrase
43 var sendPhrase = function() { 57 var sendPhrase = function() {
44 var dom = temps['home-send-phrase-temp']({ 58 var dom = temps['home-send-phrase-temp']({
@@ -139,11 +153,19 @@ var gb_home_context_menu = (function() { @@ -139,11 +153,19 @@ var gb_home_context_menu = (function() {
139 }; 153 };
140 154
141 var state_up_0 = function() { 155 var state_up_0 = function() {
142 - changeUpDown(active_car, 0); 156 + stateChange(active_car, 0, 0);
143 }; 157 };
144 158
145 var state_down_0 = function() { 159 var state_down_0 = function() {
146 - changeUpDown(active_car, 1); 160 + stateChange(active_car, 1, 0);
  161 + };
  162 +
  163 + var state_up_1 = function () {
  164 + stateChange(active_car, 0, 1);
  165 + };
  166 +
  167 + var state_down_1 = function () {
  168 + stateChange(active_car, 1, 1);
147 }; 169 };
148 170
149 var line_change = function() { 171 var line_change = function() {
@@ -179,7 +201,6 @@ var gb_home_context_menu = (function() { @@ -179,7 +201,6 @@ var gb_home_context_menu = (function() {
179 }); 201 });
180 }; 202 };
181 203
182 -  
183 var C0_A3 = function(){ 204 var C0_A3 = function(){
184 open_modal('/real_control_v2/fragments/home/c0_a3.html', {}, {center: false, bgclose: false}); 205 open_modal('/real_control_v2/fragments/home/c0_a3.html', {}, {center: false, bgclose: false});
185 }; 206 };
@@ -190,7 +211,9 @@ var gb_home_context_menu = (function() { @@ -190,7 +211,9 @@ var gb_home_context_menu = (function() {
190 state_up_0: state_up_0, 211 state_up_0: state_up_0,
191 state_down_0: state_down_0, 212 state_down_0: state_down_0,
192 line_change: line_change, 213 line_change: line_change,
193 - C0_A3: C0_A3 214 + C0_A3: C0_A3,
  215 + state_up_1: state_up_1,
  216 + state_down_1: state_down_1
194 }; 217 };
195 218
196 $.contextMenu({ 219 $.contextMenu({
@@ -210,6 +233,13 @@ var gb_home_context_menu = (function() { @@ -210,6 +233,13 @@ var gb_home_context_menu = (function() {
210 'fold_state': { 233 'fold_state': {
211 name: '状态切换', 234 name: '状态切换',
212 items: { 235 items: {
  236 + 'state_up_1': {
  237 + 'name': '上行非营运'
  238 + },
  239 + 'state_down_1': {
  240 + 'name': '下行非营运'
  241 + },
  242 + 'sep3_2': '---------',
213 'state_up_0': { 243 'state_up_0': {
214 'name': '上行营运' 244 'name': '上行营运'
215 }, 245 },