Commit 66d81f185d0612baf22f9af30a346f59378850b8

Authored by 潘钊
1 parent eea73673

update...

src/main/java/com/bsth/controller/directive/DirectiveController.java
1 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 3 import com.alibaba.fastjson.JSON;
14 4 import com.alibaba.fastjson.JSONObject;
15 5 import com.bsth.entity.directive.D80;
... ... @@ -17,6 +7,15 @@ import com.bsth.entity.directive.DC0_A3;
17 7 import com.bsth.entity.sys.SysUser;
18 8 import com.bsth.security.util.SecurityUtils;
19 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 108 SysUser user = SecurityUtils.getCurrentUser();
110 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 1 package com.bsth.data.gpsdata;
2 2  
  3 +import com.bsth.Application;
3 4 import com.bsth.data.BasicData;
4 5 import com.bsth.data.forecast.ForecastRealServer;
5 6 import com.bsth.data.gpsdata.thread.GpsDataLoaderThread;
... ... @@ -15,6 +16,7 @@ import org.springframework.boot.CommandLineRunner;
15 16 import org.springframework.stereotype.Component;
16 17  
17 18 import java.util.*;
  19 +import java.util.concurrent.TimeUnit;
18 20  
19 21 /**
20 22 * @author PanZhao
... ... @@ -56,7 +58,7 @@ public class GpsRealData implements CommandLineRunner {
56 58 public void run(String... arg0) throws Exception {
57 59 logger.info("gpsDataLoader,20,5");
58 60 //定时从网关获取GPS数据
59   - //Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 20, 5, TimeUnit.SECONDS);
  61 + Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 20, 5, TimeUnit.SECONDS);
60 62 //定时扫描掉离线
61 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 5 import com.bsth.data.gpsdata.arrival.utils.CircleQueue;
6 6 import com.bsth.data.gpsdata.arrival.utils.GeoUtils;
7 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 13 import java.util.List;
10 14  
... ... @@ -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 77 protected void transformUpdown(GpsEntity gps, ScheduleRealInfo sch) {
72 78 int updown = Integer.parseInt(sch.getXlDir());
73 79 //gps 切换走向
... ... @@ -78,6 +84,8 @@ public abstract class SignalHandle {
78 84 if (station != null) {
79 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 7 import com.bsth.data.gpsdata.arrival.utils.ScheduleSignalState;
8 8 import com.bsth.data.gpsdata.arrival.utils.SignalSchPlanMatcher;
9 9 import com.bsth.data.schedule.DayOfSchedule;
  10 +import com.bsth.data.schedule.ScheduleComparator;
10 11 import com.bsth.entity.realcontrol.LineConfig;
11 12 import com.bsth.entity.realcontrol.ScheduleRealInfo;
12 13 import com.bsth.service.directive.DirectiveService;
... ... @@ -17,6 +18,9 @@ import org.slf4j.LoggerFactory;
17 18 import org.springframework.beans.factory.annotation.Autowired;
18 19 import org.springframework.stereotype.Component;
19 20  
  21 +import java.util.Collections;
  22 +import java.util.List;
  23 +
20 24 /**
21 25 * 进出站动作处理
22 26 * Created by panzhao on 2016/12/27.
... ... @@ -138,6 +142,10 @@ public class InOutStationSignalHandle extends SignalHandle{
138 142 //持久化
139 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 150 outStationAndOutPark(sch);
143 151 logger.info("班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual());
... ... @@ -164,6 +172,11 @@ public class InOutStationSignalHandle extends SignalHandle{
164 172  
165 173 sendUtils.refreshSch(schPrev);
166 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 217 sendUtils.sendZdsj(sch, next, doneSum);
205 218 //持久化
206 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 230 if (next != null) {
... ... @@ -217,10 +236,59 @@ public class InOutStationSignalHandle extends SignalHandle{
217 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 60 for (String nbbm : keys) {
61 61 Collections.sort(listMap.get(nbbm), comp);
62 62 threadPool.execute(new RecoveryThread(listMap.get(nbbm), count));
63   - /*if(nbbm.equals("W9H-003"))
  63 + /*if(nbbm.equals("SXC-YD012"))
64 64 new RecoveryThread(listMap.get(nbbm), count).run();*/
65 65 }
66 66  
... ... @@ -163,9 +163,8 @@ public class GpsDataRecovery implements ApplicationContextAware {
163 163 reverseSignalHandle.handle(gps, prevs);
164 164 //进出站动作处理
165 165 inOutStationSignalHandle.handle(gps, prevs);
166   - GeoCacheData.putGps(gps);
167 166  
168   - //Thread.sleep(50);
  167 + GeoCacheData.putGps(gps);
169 168 }
170 169 } catch (Exception e) {
171 170 logger.error("", e);
... ...
src/main/java/com/bsth/service/directive/DirectiveService.java
1 1 package com.bsth.service.directive;
2 2  
3 3  
4   -import java.util.List;
5   -import java.util.Map;
6   -
7 4 import com.bsth.entity.directive.D60;
8 5 import com.bsth.entity.directive.D64;
9 6 import com.bsth.entity.directive.D80;
... ... @@ -11,6 +8,9 @@ import com.bsth.entity.directive.DC0_A3;
11 8 import com.bsth.entity.realcontrol.ScheduleRealInfo;
12 9 import com.bsth.service.BaseService;
13 10  
  11 +import java.util.List;
  12 +import java.util.Map;
  13 +
14 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 93 int sendC0A5(String json);
94 94  
95 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 504  
505 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 65 {{if obj.reply46 != 0}}
66 66 <div class="uk-badge uk-badge-danger"> 设备未响应</div>
67 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 69 {{else if obj.reply46 == 0 && obj.reply47 == 0}}
70   - <div class="uk-badge"> 成功</div>
  70 + <div class="uk-badge"> 驾驶员已确认</div>
71 71 {{/if}}
72 72 {{/if}}
73 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 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 56 // send phrase
43 57 var sendPhrase = function() {
44 58 var dom = temps['home-send-phrase-temp']({
... ... @@ -139,11 +153,19 @@ var gb_home_context_menu = (function() {
139 153 };
140 154  
141 155 var state_up_0 = function() {
142   - changeUpDown(active_car, 0);
  156 + stateChange(active_car, 0, 0);
143 157 };
144 158  
145 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 171 var line_change = function() {
... ... @@ -179,7 +201,6 @@ var gb_home_context_menu = (function() {
179 201 });
180 202 };
181 203  
182   -
183 204 var C0_A3 = function(){
184 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 211 state_up_0: state_up_0,
191 212 state_down_0: state_down_0,
192 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 219 $.contextMenu({
... ... @@ -210,6 +233,13 @@ var gb_home_context_menu = (function() {
210 233 'fold_state': {
211 234 name: '状态切换',
212 235 items: {
  236 + 'state_up_1': {
  237 + 'name': '上行非营运'
  238 + },
  239 + 'state_down_1': {
  240 + 'name': '下行非营运'
  241 + },
  242 + 'sep3_2': '---------',
213 243 'state_up_0': {
214 244 'name': '上行营运'
215 245 },
... ...