Commit 88ee64c43f273bf10bde46f033cc9618d4c936f8
Merge branch 'minhang' into pudong
# Conflicts: # src/main/resources/ms-jdbc.properties
Showing
35 changed files
with
1618 additions
and
202 deletions
Too many changes to show.
To preserve performance only 35 of 57 files are displayed.
.gitignore
src/main/java/com/bsth/controller/directive/DirectiveController.java
| ... | ... | @@ -31,7 +31,7 @@ public class DirectiveController { |
| 31 | 31 | |
| 32 | 32 | @Autowired |
| 33 | 33 | DirectiveService directiveService; |
| 34 | - | |
| 34 | + | |
| 35 | 35 | /** |
| 36 | 36 | * |
| 37 | 37 | * @Title: send60 |
| ... | ... | @@ -106,7 +106,7 @@ public class DirectiveController { |
| 106 | 106 | @RequestMapping(value = "/upDownChange", method = RequestMethod.POST) |
| 107 | 107 | public int upDownChange(@RequestParam String nbbm, @RequestParam Integer upDown){ |
| 108 | 108 | SysUser user = SecurityUtils.getCurrentUser(); |
| 109 | - return directiveService.upDownChange(nbbm, upDown, user.getUserName()); | |
| 109 | + return directiveService.send60Operation(nbbm, 0, upDown, user.getUserName()); | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
| ... | ... | @@ -120,7 +120,7 @@ public class DirectiveController { |
| 120 | 120 | @RequestMapping(value = "/stateChange", method = RequestMethod.POST) |
| 121 | 121 | public int stateChange(@RequestParam String nbbm, @RequestParam Integer upDown, @RequestParam Integer state){ |
| 122 | 122 | SysUser user = SecurityUtils.getCurrentUser(); |
| 123 | - return directiveService.stateChange(nbbm, upDown, state, user.getUserName()); | |
| 123 | + return directiveService.send60Operation(nbbm, state, upDown, user.getUserName()); | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** | ... | ... |
src/main/java/com/bsth/controller/gps/GpsController.java
| ... | ... | @@ -3,8 +3,10 @@ package com.bsth.controller.gps; |
| 3 | 3 | import com.bsth.data.BasicData; |
| 4 | 4 | import com.bsth.data.gpsdata.GpsEntity; |
| 5 | 5 | import com.bsth.data.gpsdata.GpsRealData; |
| 6 | +import com.bsth.entity.excep.Speeding; | |
| 6 | 7 | import com.bsth.service.gps.GpsService; |
| 7 | 8 | import com.bsth.service.gps.entity.GpsSpeed; |
| 9 | +import com.bsth.util.PageObject; | |
| 8 | 10 | import com.google.common.base.Splitter; |
| 9 | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | 12 | import org.springframework.web.bind.annotation.*; |
| ... | ... | @@ -192,4 +194,13 @@ public class GpsController { |
| 192 | 194 | return listGpsSpeed; |
| 193 | 195 | } |
| 194 | 196 | |
| 197 | + @RequestMapping(value = "/pagequery",method = RequestMethod.GET) | |
| 198 | + public PageObject<GpsSpeed> pagequery(@RequestParam Map<String, Object> map){ | |
| 199 | + PageObject<GpsSpeed> pageObject = null; | |
| 200 | + map.put("curPage", map.get("page").toString()); | |
| 201 | + map.put("pageData","10"); | |
| 202 | + pageObject=gpsService.Pagequery(map); | |
| 203 | + return pageObject; | |
| 204 | + } | |
| 205 | + | |
| 195 | 206 | } | ... | ... |
src/main/java/com/bsth/controller/schedule/core/TTInfoController.java
| ... | ... | @@ -6,10 +6,7 @@ import com.bsth.entity.schedule.TTInfo; |
| 6 | 6 | import com.bsth.service.schedule.TTInfoService; |
| 7 | 7 | import com.bsth.service.schedule.exception.ScheduleException; |
| 8 | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 9 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 10 | -import org.springframework.web.bind.annotation.RequestMethod; | |
| 11 | -import org.springframework.web.bind.annotation.RequestParam; | |
| 12 | -import org.springframework.web.bind.annotation.RestController; | |
| 9 | +import org.springframework.web.bind.annotation.*; | |
| 13 | 10 | |
| 14 | 11 | import java.util.HashMap; |
| 15 | 12 | import java.util.Map; |
| ... | ... | @@ -87,4 +84,18 @@ public class TTInfoController extends BController<TTInfo, Long> { |
| 87 | 84 | return rtn; |
| 88 | 85 | } |
| 89 | 86 | |
| 87 | + @RequestMapping(value = "/backup/{ttinfo}", method = RequestMethod.GET) | |
| 88 | + public Map<String, Object> backup(@PathVariable(value = "ttinfo") Long ttInfoId) { | |
| 89 | + Map<String, Object> rtn = new HashMap<>(); | |
| 90 | + try { | |
| 91 | + // 备份时刻表 | |
| 92 | + this.ttInfoService.backUp(ttInfoId); | |
| 93 | + } catch (ScheduleException exp) { | |
| 94 | + rtn.put("status", ResponseCode.ERROR); | |
| 95 | + rtn.put("msg", exp.getMessage()); | |
| 96 | + } | |
| 97 | + | |
| 98 | + return rtn; | |
| 99 | + } | |
| 100 | + | |
| 90 | 101 | } |
| 91 | 102 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/data/directive/DayOfDirectives.java
| ... | ... | @@ -166,7 +166,8 @@ public class DayOfDirectives { |
| 166 | 166 | if(null != d60Map.remove(d60.getMsgId())) |
| 167 | 167 | c60 ++; |
| 168 | 168 | } |
| 169 | - logger.info("清除60数据 ," + c60); | |
| 169 | + if(c60 > 0) | |
| 170 | + logger.info("清除60数据 ," + c60); | |
| 170 | 171 | |
| 171 | 172 | //找到该设备的64数据 |
| 172 | 173 | Collection<D64> d64s = d64Map.values(); |
| ... | ... | @@ -184,8 +185,9 @@ public class DayOfDirectives { |
| 184 | 185 | if(null != d64Map.remove(d64.getKey())) |
| 185 | 186 | c64 ++; |
| 186 | 187 | } |
| 187 | - | |
| 188 | - logger.info("清除64数据 ," + c64); | |
| 188 | + | |
| 189 | + if(c64 > 0) | |
| 190 | + logger.info("清除64数据 ," + c64); | |
| 189 | 191 | } |
| 190 | 192 | |
| 191 | 193 | public Collection<D60> all60(){ | ... | ... |
src/main/java/com/bsth/data/gpsdata/GpsEntity.java
| ... | ... | @@ -40,9 +40,12 @@ public class GpsEntity { |
| 40 | 40 | /** 纬度 */ |
| 41 | 41 | private Float lat; |
| 42 | 42 | |
| 43 | - /** 发送时间戳 */ | |
| 43 | + /** GPS发送时间戳 */ | |
| 44 | 44 | private Long timestamp; |
| 45 | 45 | |
| 46 | + /** 网关收到时间 */ | |
| 47 | + private Long serverTimestamp; | |
| 48 | + | |
| 46 | 49 | /** 速度 */ |
| 47 | 50 | private Float speed; |
| 48 | 51 | |
| ... | ... | @@ -318,17 +321,33 @@ public class GpsEntity { |
| 318 | 321 | |
| 319 | 322 | long t = System.currentTimeMillis(); |
| 320 | 323 | |
| 321 | - if((t - this.getTimestamp()) > 1000 * 60){ | |
| 324 | + if((t - this.getServerTimestamp()) > 1000 * 60 * 2){ | |
| 322 | 325 | return false; |
| 323 | 326 | } |
| 324 | 327 | |
| 325 | - if((this.getTimestamp() - t) > 1000 * 60 * 3){ | |
| 328 | + if((this.getServerTimestamp() - t) > 1000 * 60 * 3){ | |
| 326 | 329 | return false; |
| 327 | 330 | } |
| 328 | 331 | return true; |
| 329 | 332 | } |
| 330 | 333 | |
| 334 | + /** | |
| 335 | + * 是否营运 | |
| 336 | + * @return | |
| 337 | + */ | |
| 338 | + public boolean isService(){ | |
| 339 | + return state!=null && state==0; | |
| 340 | + } | |
| 341 | + | |
| 331 | 342 | public boolean isOffline(){ |
| 332 | 343 | return this.getAbnormalStatus() != null && this.getAbnormalStatus().equals("offline"); |
| 333 | 344 | } |
| 345 | + | |
| 346 | + public Long getServerTimestamp() { | |
| 347 | + return serverTimestamp; | |
| 348 | + } | |
| 349 | + | |
| 350 | + public void setServerTimestamp(Long serverTimestamp) { | |
| 351 | + this.serverTimestamp = serverTimestamp; | |
| 352 | + } | |
| 334 | 353 | } | ... | ... |
src/main/java/com/bsth/data/gpsdata/GpsRealData.java
| ... | ... | @@ -110,6 +110,14 @@ public class GpsRealData { |
| 110 | 110 | return rs; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | + public GpsEntity getByNbbm(String nbbm){ | |
| 114 | + String device = BasicData.deviceId2NbbmMap.inverse().get(nbbm); | |
| 115 | + if(StringUtils.isNotBlank(device)) | |
| 116 | + return get(device); | |
| 117 | + else | |
| 118 | + return null; | |
| 119 | + } | |
| 120 | + | |
| 113 | 121 | /** |
| 114 | 122 | * @Title: get @Description: TODO(线路编码获取GPS集合) @throws |
| 115 | 123 | */ | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/handlers/CorrectSignalHandle.java
| ... | ... | @@ -3,8 +3,8 @@ package com.bsth.data.gpsdata.arrival.handlers; |
| 3 | 3 | import com.bsth.data.gpsdata.GpsEntity; |
| 4 | 4 | import com.bsth.data.gpsdata.arrival.SignalHandle; |
| 5 | 5 | import com.bsth.data.gpsdata.arrival.utils.CircleQueue; |
| 6 | +import com.bsth.data.gpsdata.status_manager.GpsStatusManager; | |
| 6 | 7 | import com.bsth.data.schedule.DayOfSchedule; |
| 7 | -import com.bsth.entity.realcontrol.ChildTaskPlan; | |
| 8 | 8 | import com.bsth.entity.realcontrol.ScheduleRealInfo; |
| 9 | 9 | import com.bsth.service.directive.DirectiveService; |
| 10 | 10 | import org.slf4j.Logger; |
| ... | ... | @@ -24,28 +24,45 @@ public class CorrectSignalHandle extends SignalHandle { |
| 24 | 24 | @Autowired |
| 25 | 25 | DirectiveService directiveService; |
| 26 | 26 | |
| 27 | + @Autowired | |
| 28 | + GpsStatusManager gpsStatusManager; | |
| 29 | + | |
| 27 | 30 | Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 28 | 31 | |
| 29 | 32 | @Override |
| 30 | 33 | public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) { |
| 31 | - Object task = dayOfSchedule.executeCurr(gps.getNbbm()); | |
| 34 | + ScheduleRealInfo task = dayOfSchedule.executeCurr(gps.getNbbm()); | |
| 32 | 35 | if(task == null) |
| 33 | 36 | return false; |
| 34 | - ScheduleRealInfo sch; | |
| 37 | + //ScheduleRealInfo sch; | |
| 35 | 38 | |
| 36 | 39 | //子任务 |
| 37 | - if(task.getClass().isAssignableFrom(ChildTaskPlan.class)){ | |
| 40 | + /*if(task.getClass().isAssignableFrom(ChildTaskPlan.class)){ | |
| 38 | 41 | ChildTaskPlan childTask = (ChildTaskPlan) task; |
| 39 | 42 | sch = childTask.getSchedule(); |
| 40 | 43 | } |
| 41 | 44 | else |
| 42 | - sch = (ScheduleRealInfo) task; | |
| 45 | + sch = (ScheduleRealInfo) task;*/ | |
| 43 | 46 | |
| 44 | - byte updown = Byte.parseByte(sch.getXlDir()); | |
| 47 | + byte updown = Byte.parseByte(task.getXlDir()); | |
| 45 | 48 | //走向 |
| 46 | 49 | if(gps.getUpDown() != updown){ |
| 47 | 50 | gps.setUpDown(updown); |
| 48 | - gps.setState(0); | |
| 51 | + //gps.setState(0); | |
| 52 | + } | |
| 53 | + | |
| 54 | + //(转发的数据不管) | |
| 55 | + if(gps.getSource() != 0){ | |
| 56 | + //gps=非营运 && 班次=非空驶 ;切换到营运状态 | |
| 57 | + if(!gps.isService() && | |
| 58 | + !dayOfSchedule.emptyService(task)){ | |
| 59 | + gpsStatusManager.changeServiceState(gps.getNbbm(), updown, 0, null); | |
| 60 | + } | |
| 61 | + | |
| 62 | + //需要切换线路 | |
| 63 | + if(!task.getXlBm().equals(gps.getLineId())){ | |
| 64 | + gpsStatusManager.changeLine(gps.getNbbm(), task.getXlBm(), null); | |
| 65 | + } | |
| 49 | 66 | } |
| 50 | 67 | |
| 51 | 68 | return true; | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/handlers/InOutStationSignalHandle.java
| ... | ... | @@ -6,6 +6,7 @@ import com.bsth.data.gpsdata.arrival.SignalHandle; |
| 6 | 6 | 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 | +import com.bsth.data.gpsdata.status_manager.GpsStatusManager; | |
| 9 | 10 | import com.bsth.data.msg_queue.DirectivePushQueue; |
| 10 | 11 | import com.bsth.data.schedule.DayOfSchedule; |
| 11 | 12 | import com.bsth.data.schedule.ScheduleComparator; |
| ... | ... | @@ -46,6 +47,9 @@ public class InOutStationSignalHandle extends SignalHandle{ |
| 46 | 47 | @Autowired |
| 47 | 48 | SignalSchPlanMatcher signalSchPlanMatcher; |
| 48 | 49 | |
| 50 | + @Autowired | |
| 51 | + GpsStatusManager gpsStatusManager; | |
| 52 | + | |
| 49 | 53 | private final static int MAX_BEFORE_TIME = 1000 * 60 * 120; |
| 50 | 54 | |
| 51 | 55 | //最大的班次时间差,防止异常的GPS时间打乱数据 |
| ... | ... | @@ -57,10 +61,11 @@ public class InOutStationSignalHandle extends SignalHandle{ |
| 57 | 61 | if(isGpsOffline(gps)) |
| 58 | 62 | return false; |
| 59 | 63 | |
| 60 | - //从异常状态恢复的第一个信号 | |
| 64 | + /*//从异常状态恢复的第一个信号*/ | |
| 61 | 65 | if(abnormalRecovery(gps, prevs)){ |
| 62 | 66 | //回溯一下之前的轨迹 |
| 63 | - scheduleSignalState.signalRetrospect(gps); | |
| 67 | + //scheduleSignalState.signalRetrospect(gps); | |
| 68 | + return false; | |
| 64 | 69 | } |
| 65 | 70 | |
| 66 | 71 | if(isNotEmpty(prevs)){ |
| ... | ... | @@ -154,10 +159,9 @@ public class InOutStationSignalHandle extends SignalHandle{ |
| 154 | 159 | //清理应发未发标记 |
| 155 | 160 | LateAdjustHandle.remove(sch); |
| 156 | 161 | |
| 157 | - if(sch.getBcType().equals("out")){ | |
| 158 | - //出场时,切换成营运状态 | |
| 159 | - DirectivePushQueue.put6003(sch.getClZbh(), 0, Integer.parseInt(sch.getXlDir()), null, "出场@系统"); | |
| 160 | - //directiveService.send60Operation(sch.getClZbh(), 0, Integer.parseInt(sch.getXlDir()), null, "出场@系统"); | |
| 162 | + if(!gps.isService()){ | |
| 163 | + //切换成营运状态 | |
| 164 | + gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 0, "发车@系统"); | |
| 161 | 165 | } |
| 162 | 166 | //出站既出场 |
| 163 | 167 | outStationAndOutPark(sch); |
| ... | ... | @@ -232,11 +236,13 @@ public class InOutStationSignalHandle extends SignalHandle{ |
| 232 | 236 | sendUtils.refreshSch(schPrev); |
| 233 | 237 | dayOfSchedule.save(schPrev); |
| 234 | 238 | |
| 235 | - if(schPrev.getBcType().equals("out")){ | |
| 239 | + /*if(schPrev.getBcType().equals("out")){ | |
| 236 | 240 | //出场时,切换成营运状态 |
| 237 | - DirectivePushQueue.put6003(schPrev.getClZbh(), 0, Integer.parseInt(schPrev.getXlDir()), null, "出场@系统"); | |
| 241 | + String deviceId = BasicData.deviceId2NbbmMap.inverse().get(sch.getClZbh()); | |
| 242 | + gpsStatusManager.changeServiceState(deviceId, schPrev.getXlDir(), 0, "出场@系统"); | |
| 243 | + //DirectivePushQueue.put6003(schPrev.getClZbh(), 0, Integer.parseInt(schPrev.getXlDir()), "出场@系统"); | |
| 238 | 244 | //directiveService.send60Operation(schPrev.getClZbh(), 0, Integer.parseInt(schPrev.getXlDir()), null, "出场@系统"); |
| 239 | - } | |
| 245 | + }*/ | |
| 240 | 246 | } |
| 241 | 247 | } |
| 242 | 248 | } |
| ... | ... | @@ -265,6 +271,15 @@ public class InOutStationSignalHandle extends SignalHandle{ |
| 265 | 271 | if(Math.abs(diff) > MAX_NORMAL_DIFF) |
| 266 | 272 | return; |
| 267 | 273 | |
| 274 | + //环线或内外圈 ,飘出去再回来 | |
| 275 | + if(sch.getQdzCode().equals(sch.getZdzCode()) | |
| 276 | + && StringUtils.isNotEmpty(sch.getFcsjActual()) | |
| 277 | + && gps.getTimestamp() - sch.getFcsjActualTime() < 1000 * 60 * 3){ | |
| 278 | + sch.clearFcsjActual(); | |
| 279 | + sendUtils.refreshSch(sch); | |
| 280 | + return; | |
| 281 | + } | |
| 282 | + | |
| 268 | 283 | //实达时间不覆盖 |
| 269 | 284 | if(StringUtils.isNotEmpty(sch.getZdsjActual())) |
| 270 | 285 | return; |
| ... | ... | @@ -304,26 +319,23 @@ public class InOutStationSignalHandle extends SignalHandle{ |
| 304 | 319 | transformUpdown(gps, next); |
| 305 | 320 | //下发调度指令 |
| 306 | 321 | DirectivePushQueue.put6002(next, doneSum, "到站@系统"); |
| 307 | - //directiveService.send60Dispatch(next, doneSum, "到站@系统"); | |
| 308 | 322 | |
| 309 | 323 | //套跑 -下发线路切换指令 |
| 310 | 324 | if(!next.getXlBm().equals(sch.getXlBm())){ |
| 311 | - DirectivePushQueue.put64(next.getClZbh(), next.getXlBm(), "套跑@系统"); | |
| 312 | - //directiveService.lineChange(next.getClZbh(), next.getXlBm(), "套跑@系统"); | |
| 325 | + gpsStatusManager.changeLine(next.getClZbh(), next.getXlBm(), "套跑@系统"); | |
| 313 | 326 | } |
| 314 | 327 | } |
| 315 | 328 | else if(sch.getBcType().equals("in")){ |
| 316 | - //终班进场,切换成非营运状态 | |
| 317 | - DirectivePushQueue.put6003(sch.getClZbh(), 1, Integer.parseInt(sch.getXlDir()), null, "进场@系统"); | |
| 318 | - //directiveService.send60Operation(sch.getClZbh(), 1, Integer.parseInt(sch.getXlDir()), null, "进场@系统"); | |
| 329 | + //进场,切换成非营运状态 | |
| 330 | + gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 1, "进场@系统"); | |
| 319 | 331 | } |
| 320 | 332 | } |
| 321 | 333 | else { |
| 322 | - if(sch.getFcsjActual() == null){ | |
| 334 | + /*if(sch.getFcsjActual() == null){ | |
| 323 | 335 | //有进站,但班次没有实发,向前追溯一下信号 |
| 324 | 336 | scheduleSignalState.signalRetrospect(gps, sch); |
| 325 | 337 | } |
| 326 | - | |
| 338 | +*/ | |
| 327 | 339 | //如果当前班次是出场,并且进的是下一个班次的终点 |
| 328 | 340 | if(sch.getBcType().equals("out")){ |
| 329 | 341 | ScheduleRealInfo next = dayOfSchedule.next(sch); |
| ... | ... | @@ -397,6 +409,9 @@ public class InOutStationSignalHandle extends SignalHandle{ |
| 397 | 409 | next = dayOfSchedule.next(next); |
| 398 | 410 | if(next != null) |
| 399 | 411 | dayOfSchedule.addExecPlan(next); |
| 412 | + | |
| 413 | + //进场,切换成非营运状态 | |
| 414 | + gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 1, "进场@系统"); | |
| 400 | 415 | } |
| 401 | 416 | } |
| 402 | 417 | ... | ... |
src/main/java/com/bsth/data/gpsdata/arrival/handlers/OfflineSignalHandle.java
| ... | ... | @@ -23,7 +23,7 @@ public class OfflineSignalHandle extends SignalHandle{ |
| 23 | 23 | public boolean handle(GpsEntity gps, CircleQueue<GpsEntity> prevs) { |
| 24 | 24 | //掉线信号不管 |
| 25 | 25 | if(isGpsOffline(gps)){ |
| 26 | - gps.setSignalState("drift"); | |
| 26 | + gps.setSignalState("gps-offline"); | |
| 27 | 27 | gps.setAbnormalStatus("gps-offline"); |
| 28 | 28 | return true; |
| 29 | 29 | } | ... | ... |
src/main/java/com/bsth/data/gpsdata/recovery/GpsDataRecovery.java
| ... | ... | @@ -84,7 +84,7 @@ public class GpsDataRecovery implements ApplicationContextAware { |
| 84 | 84 | Calendar calendar = Calendar.getInstance(); |
| 85 | 85 | int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR); |
| 86 | 86 | |
| 87 | - String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE from bsth_c_gps_info where days_year=" + dayOfYear; | |
| 87 | + String sql = "select DEVICE_ID,LAT,LON,TS,SPEED_GPS,LINE_ID,SERVICE_STATE from bsth_c_gps_info where days_year=194";// + dayOfYear; | |
| 88 | 88 | JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource()); |
| 89 | 89 | |
| 90 | 90 | List<GpsEntity> list = | ... | ... |
src/main/java/com/bsth/data/gpsdata/status_manager/GpsStatusManager.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.status_manager; | |
| 2 | + | |
| 3 | +import com.bsth.Application; | |
| 4 | +import com.bsth.data.gpsdata.status_manager.gps_line_state.LineStateHandle; | |
| 5 | +import com.bsth.data.gpsdata.status_manager.gps_service_state.ServiceStateHandle; | |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | +import org.springframework.boot.CommandLineRunner; | |
| 8 | +import org.springframework.stereotype.Component; | |
| 9 | + | |
| 10 | +import java.util.concurrent.TimeUnit; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * GPS 状态管理 | |
| 14 | + * Created by panzhao on 2017/7/13. | |
| 15 | + */ | |
| 16 | +@Component | |
| 17 | +public class GpsStatusManager implements CommandLineRunner { | |
| 18 | + | |
| 19 | + @Autowired | |
| 20 | + StatusCheckThread checkThread; | |
| 21 | + | |
| 22 | + @Autowired | |
| 23 | + LineStateHandle lineStateHandle; | |
| 24 | + | |
| 25 | + @Autowired | |
| 26 | + ServiceStateHandle serviceStateHandle; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 切换线路 | |
| 30 | + * @param nbbm | |
| 31 | + * @param lineCode | |
| 32 | + * @param sender | |
| 33 | + */ | |
| 34 | + public void changeLine(String nbbm, String lineCode, String sender){ | |
| 35 | + lineStateHandle.changeLine(nbbm, lineCode, sender); | |
| 36 | + } | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * 切换营运状态 | |
| 40 | + * @param nbbm | |
| 41 | + * @param state 0 营运, 1:非营运 | |
| 42 | + * @param sender | |
| 43 | + */ | |
| 44 | + public void changeServiceState(String nbbm, String upDown,int state, String sender){ | |
| 45 | + changeServiceState(nbbm, Integer.parseInt(upDown), state, sender); | |
| 46 | + } | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * 切换营运状态 | |
| 50 | + * @param nbbm | |
| 51 | + * @param state 0 营运, 1:非营运 | |
| 52 | + * @param sender | |
| 53 | + */ | |
| 54 | + public void changeServiceState(String nbbm, int upDown,int state, String sender){ | |
| 55 | + serviceStateHandle.changeState(nbbm, upDown, state, sender); | |
| 56 | + } | |
| 57 | + | |
| 58 | + @Override | |
| 59 | + public void run(String... strings) throws Exception { | |
| 60 | + Application.mainServices.scheduleWithFixedDelay(checkThread, 120, 120, TimeUnit.SECONDS); | |
| 61 | + } | |
| 62 | + | |
| 63 | + @Component | |
| 64 | + public static class StatusCheckThread extends Thread{ | |
| 65 | + | |
| 66 | + @Autowired | |
| 67 | + LineStateHandle lineStateHandle; | |
| 68 | + | |
| 69 | + @Autowired | |
| 70 | + ServiceStateHandle serviceStateHandle; | |
| 71 | + | |
| 72 | + @Override | |
| 73 | + public void run() { | |
| 74 | + /** 检查线路切换结果 */ | |
| 75 | + lineStateHandle.checkResultAll(); | |
| 76 | + /** 检查营运状态切换结果 */ | |
| 77 | + serviceStateHandle.checkResultAll(); | |
| 78 | + } | |
| 79 | + } | |
| 80 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/status_manager/gps_line_state/ChangeBean.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.status_manager.gps_line_state; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Created by panzhao on 2017/7/13. | |
| 5 | + */ | |
| 6 | +public class ChangeBean { | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * 车辆自编号 | |
| 10 | + */ | |
| 11 | + private String nbbm; | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 要切换到的线路 | |
| 15 | + */ | |
| 16 | + private String lineCode; | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 指令发送次数 | |
| 20 | + */ | |
| 21 | + private int sendCount; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 上次指令时间 | |
| 25 | + */ | |
| 26 | + private long st; | |
| 27 | + | |
| 28 | + /**发送人 */ | |
| 29 | + private String sender; | |
| 30 | + | |
| 31 | + public static ChangeBean getInstance(String nbbm, String lineCode, String sender){ | |
| 32 | + ChangeBean cb = new ChangeBean(); | |
| 33 | + cb.setNbbm(nbbm); | |
| 34 | + cb.setLineCode(lineCode); | |
| 35 | + cb.setSendCount(0); | |
| 36 | + cb.setSender(sender); | |
| 37 | + return cb; | |
| 38 | + } | |
| 39 | + | |
| 40 | + public void countPlus(){ | |
| 41 | + sendCount ++; | |
| 42 | + } | |
| 43 | + | |
| 44 | + public String getLineCode() { | |
| 45 | + return lineCode; | |
| 46 | + } | |
| 47 | + | |
| 48 | + public void setLineCode(String lineCode) { | |
| 49 | + this.lineCode = lineCode; | |
| 50 | + } | |
| 51 | + | |
| 52 | + public int getSendCount() { | |
| 53 | + return sendCount; | |
| 54 | + } | |
| 55 | + | |
| 56 | + public void setSendCount(int sendCount) { | |
| 57 | + this.sendCount = sendCount; | |
| 58 | + } | |
| 59 | + | |
| 60 | + public long getSt() { | |
| 61 | + return st; | |
| 62 | + } | |
| 63 | + | |
| 64 | + public void setSt(long st) { | |
| 65 | + this.st = st; | |
| 66 | + } | |
| 67 | + | |
| 68 | + public String getSender() { | |
| 69 | + return sender; | |
| 70 | + } | |
| 71 | + | |
| 72 | + public void setSender(String sender) { | |
| 73 | + this.sender = sender; | |
| 74 | + } | |
| 75 | + | |
| 76 | + public String getNbbm() { | |
| 77 | + return nbbm; | |
| 78 | + } | |
| 79 | + | |
| 80 | + public void setNbbm(String nbbm) { | |
| 81 | + this.nbbm = nbbm; | |
| 82 | + } | |
| 83 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/status_manager/gps_line_state/LineStateHandle.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.status_manager.gps_line_state; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | +import com.bsth.data.gpsdata.GpsRealData; | |
| 5 | +import com.bsth.data.msg_queue.DirectivePushQueue; | |
| 6 | +import com.bsth.service.directive.DirectiveService; | |
| 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 | +import java.util.concurrent.ConcurrentHashMap; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * 设备线路状态处理 | |
| 17 | + * Created by panzhao on 2017/7/13. | |
| 18 | + */ | |
| 19 | +@Component | |
| 20 | +public class LineStateHandle { | |
| 21 | + | |
| 22 | + private static ConcurrentHashMap<String, ChangeBean> map; | |
| 23 | + | |
| 24 | + @Autowired | |
| 25 | + DirectiveService directiveService; | |
| 26 | + @Autowired | |
| 27 | + GpsRealData gpsRealData; | |
| 28 | + | |
| 29 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 30 | + | |
| 31 | + /** 重发次数 */ | |
| 32 | + private final static int MAX_SEND_COUNT=3; | |
| 33 | + /** 重发间隔 */ | |
| 34 | + private final static int SEND_SPACE=1000 * 60 * 5; | |
| 35 | + /** 最大有效时间 */ | |
| 36 | + private final static int MAX_AVAIL_TIME=1000 * 60 * 60 * 2; | |
| 37 | + | |
| 38 | + static{ | |
| 39 | + map = new ConcurrentHashMap(); | |
| 40 | + } | |
| 41 | + | |
| 42 | + public void changeLine(String nbbm, String lineCode, String sender){ | |
| 43 | + ChangeBean cb = map.get(nbbm); | |
| 44 | + if(cb != null && cb.getLineCode().equals(lineCode)){ | |
| 45 | + return; | |
| 46 | + } | |
| 47 | + | |
| 48 | + cb = ChangeBean.getInstance(nbbm, lineCode, sender); | |
| 49 | + map.put(nbbm, cb); | |
| 50 | + | |
| 51 | + changeLine(cb); | |
| 52 | + } | |
| 53 | + | |
| 54 | + private void changeLine(ChangeBean cb){ | |
| 55 | + cb.setSt(System.currentTimeMillis()); | |
| 56 | + cb.countPlus(); | |
| 57 | + DirectivePushQueue.put64(cb.getNbbm(), cb.getLineCode(), cb.getSender()); | |
| 58 | + } | |
| 59 | + | |
| 60 | + | |
| 61 | + public void checkResultAll(){ | |
| 62 | + Collection<ChangeBean> cbs = map.values(); | |
| 63 | + for(ChangeBean cb : cbs){ | |
| 64 | + checkResult(cb); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + | |
| 68 | + private void checkResult(ChangeBean cb){ | |
| 69 | + try{ | |
| 70 | + GpsEntity gps = gpsRealData.getByNbbm(cb.getNbbm()); | |
| 71 | + if(gps == null) | |
| 72 | + return; | |
| 73 | + | |
| 74 | + if(cb.getLineCode().equals(gps.getLineId())){ | |
| 75 | + map.remove(cb.getNbbm()); | |
| 76 | + logger.info("线路切换成功," + cb.getNbbm() + "、" + cb.getLineCode()); | |
| 77 | + } | |
| 78 | + else{ | |
| 79 | + reSend(cb); | |
| 80 | + } | |
| 81 | + }catch (Exception e){ | |
| 82 | + logger.error("", e); | |
| 83 | + } | |
| 84 | + } | |
| 85 | + | |
| 86 | + private void reSend(ChangeBean cb){ | |
| 87 | + if(cb.getSendCount() >= MAX_SEND_COUNT){ | |
| 88 | + map.remove(cb.getNbbm()); | |
| 89 | + logger.info("超过重发次数," + cb.getNbbm() + "、" + cb.getLineCode()); | |
| 90 | + return; | |
| 91 | + } | |
| 92 | + | |
| 93 | + long diff = System.currentTimeMillis() - cb.getSt(); | |
| 94 | + if(diff >= MAX_AVAIL_TIME){ | |
| 95 | + map.remove(cb.getNbbm()); | |
| 96 | + logger.info("超过有效时间," + cb.getNbbm() + "、" + cb.getLineCode() + "、" + cb.getSt()); | |
| 97 | + return; | |
| 98 | + } | |
| 99 | + | |
| 100 | + if(diff >= SEND_SPACE){ | |
| 101 | + cb.setSender("补发@系统"); | |
| 102 | + changeLine(cb); | |
| 103 | + logger.info("重发线路切换指令," + cb.getNbbm() + "、" + cb.getLineCode()); | |
| 104 | + return; | |
| 105 | + } | |
| 106 | + } | |
| 107 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/status_manager/gps_service_state/ServiceStateHandle.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.status_manager.gps_service_state; | |
| 2 | + | |
| 3 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 4 | +import com.bsth.data.gpsdata.GpsRealData; | |
| 5 | +import com.bsth.data.msg_queue.DirectivePushQueue; | |
| 6 | +import com.bsth.service.directive.DirectiveService; | |
| 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 | +import java.util.concurrent.ConcurrentHashMap; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * 设备营运状态处理 | |
| 17 | + * Created by panzhao on 2017/7/13. | |
| 18 | + */ | |
| 19 | +@Component | |
| 20 | +public class ServiceStateHandle { | |
| 21 | + | |
| 22 | + private static ConcurrentHashMap<String, StateBean> map; | |
| 23 | + | |
| 24 | + @Autowired | |
| 25 | + DirectiveService directiveService; | |
| 26 | + @Autowired | |
| 27 | + GpsRealData gpsRealData; | |
| 28 | + | |
| 29 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 30 | + | |
| 31 | + /** 重发次数 */ | |
| 32 | + private final static int MAX_SEND_COUNT=3; | |
| 33 | + /** 重发间隔 */ | |
| 34 | + private final static int SEND_SPACE=1000 * 60 * 4; | |
| 35 | + /** 最大有效时间 */ | |
| 36 | + private final static int MAX_AVAIL_TIME=1000 * 60 * 60; | |
| 37 | + | |
| 38 | + static{ | |
| 39 | + map = new ConcurrentHashMap(); | |
| 40 | + } | |
| 41 | + | |
| 42 | + public void changeState(String nbbm, int upDown ,int state, String sender){ | |
| 43 | + if(map.containsKey(nbbm)){ | |
| 44 | + return; | |
| 45 | + } | |
| 46 | + StateBean sb = StateBean.getInstance(nbbm, upDown, state, sender); | |
| 47 | + map.put(nbbm, sb); | |
| 48 | + changeState(sb); | |
| 49 | + } | |
| 50 | + | |
| 51 | + private void changeState(StateBean sb){ | |
| 52 | + sb.setSt(System.currentTimeMillis()); | |
| 53 | + sb.countPlus(); | |
| 54 | + DirectivePushQueue.put6003(sb.getNbbm(), sb.getState(), sb.getUpDown(), sb.getSender()); | |
| 55 | + } | |
| 56 | + | |
| 57 | + public void checkResultAll(){ | |
| 58 | + Collection<StateBean> sbs = map.values(); | |
| 59 | + for(StateBean sb : sbs){ | |
| 60 | + checkResult(sb); | |
| 61 | + } | |
| 62 | + } | |
| 63 | + | |
| 64 | + private void checkResult(StateBean sb){ | |
| 65 | + try{ | |
| 66 | + GpsEntity gps = gpsRealData.getByNbbm(sb.getNbbm()); | |
| 67 | + if(gps == null) | |
| 68 | + return; | |
| 69 | + | |
| 70 | + if(gps.getState().equals(sb.getState())){ | |
| 71 | + map.remove(sb.getNbbm()); | |
| 72 | + logger.info("营运状态切换成功," + sb.getNbbm() + "、" + sb.getState()); | |
| 73 | + } | |
| 74 | + else | |
| 75 | + reSend(sb); | |
| 76 | + }catch (Exception e){ | |
| 77 | + logger.error("", e); | |
| 78 | + } | |
| 79 | + } | |
| 80 | + | |
| 81 | + private void reSend(StateBean sb){ | |
| 82 | + if(sb.getSendCount() >= MAX_SEND_COUNT){ | |
| 83 | + map.remove(sb.getNbbm()); | |
| 84 | + logger.info("超过重发次数," + sb.getNbbm() + "、" + sb.getState()); | |
| 85 | + return; | |
| 86 | + } | |
| 87 | + | |
| 88 | + long diff = System.currentTimeMillis() - sb.getSt(); | |
| 89 | + if(diff >= MAX_AVAIL_TIME){ | |
| 90 | + map.remove(sb.getNbbm()); | |
| 91 | + logger.info("营运状态切换超过有效时间," + sb.getNbbm() + "、" + sb.getState() + "、" + sb.getSt()); | |
| 92 | + return; | |
| 93 | + } | |
| 94 | + | |
| 95 | + if(diff >= SEND_SPACE){ | |
| 96 | + sb.setSender("补发@系统"); | |
| 97 | + changeState(sb); | |
| 98 | + logger.info("重发营运状态切换指令," + sb.getNbbm() + "、" + sb.getState()); | |
| 99 | + return; | |
| 100 | + } | |
| 101 | + } | |
| 102 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/status_manager/gps_service_state/StateBean.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata.status_manager.gps_service_state; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Created by panzhao on 2017/7/13. | |
| 5 | + */ | |
| 6 | +public class StateBean { | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * 车辆自编号 | |
| 10 | + */ | |
| 11 | + private String nbbm; | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * 要切换到营运状态 | |
| 15 | + */ | |
| 16 | + private int state; | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 要切换到的上下行 | |
| 20 | + */ | |
| 21 | + private int upDown; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 指令发送次数 | |
| 25 | + */ | |
| 26 | + private int sendCount; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 上次指令时间 | |
| 30 | + */ | |
| 31 | + private long st; | |
| 32 | + | |
| 33 | + /**发送人 */ | |
| 34 | + private String sender; | |
| 35 | + | |
| 36 | + public static StateBean getInstance(String nbbm, int upDown, int state, String sender){ | |
| 37 | + StateBean sb = new StateBean(); | |
| 38 | + sb.setNbbm(nbbm); | |
| 39 | + sb.setState(state); | |
| 40 | + sb.setSendCount(0); | |
| 41 | + sb.setSender(sender); | |
| 42 | + sb.setUpDown(upDown); | |
| 43 | + return sb; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public int getState() { | |
| 47 | + return state; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public void setState(int state) { | |
| 51 | + this.state = state; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public int getSendCount() { | |
| 55 | + return sendCount; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public void setSendCount(int sendCount) { | |
| 59 | + this.sendCount = sendCount; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public long getSt() { | |
| 63 | + return st; | |
| 64 | + } | |
| 65 | + | |
| 66 | + public void setSt(long st) { | |
| 67 | + this.st = st; | |
| 68 | + } | |
| 69 | + | |
| 70 | + public String getSender() { | |
| 71 | + return sender; | |
| 72 | + } | |
| 73 | + | |
| 74 | + public void setSender(String sender) { | |
| 75 | + this.sender = sender; | |
| 76 | + } | |
| 77 | + | |
| 78 | + public void countPlus(){ | |
| 79 | + sendCount ++; | |
| 80 | + } | |
| 81 | + | |
| 82 | + public int getUpDown() { | |
| 83 | + return upDown; | |
| 84 | + } | |
| 85 | + | |
| 86 | + public void setUpDown(int upDown) { | |
| 87 | + this.upDown = upDown; | |
| 88 | + } | |
| 89 | + | |
| 90 | + public String getNbbm() { | |
| 91 | + return nbbm; | |
| 92 | + } | |
| 93 | + | |
| 94 | + public void setNbbm(String nbbm) { | |
| 95 | + this.nbbm = nbbm; | |
| 96 | + } | |
| 97 | +} | ... | ... |
src/main/java/com/bsth/data/msg_queue/DirectivePushQueue.java
| ... | ... | @@ -39,12 +39,12 @@ public class DirectivePushQueue implements CommandLineRunner, ApplicationContext |
| 39 | 39 | linkedList.add(qd6002); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public static void put6003(String nbbm, int state, int upDown, ScheduleRealInfo sch, String sender){ | |
| 42 | + public static void put6003(String nbbm, int state, int upDown, String sender){ | |
| 43 | 43 | QueueData_Directive qd6003 = new QueueData_Directive(); |
| 44 | 44 | qd6003.setNbbm(nbbm); |
| 45 | 45 | qd6003.setState(state); |
| 46 | 46 | qd6003.setUpDown(upDown); |
| 47 | - qd6003.setSch(sch); | |
| 47 | + //qd6003.setSch(sch); | |
| 48 | 48 | qd6003.setSender(sender); |
| 49 | 49 | |
| 50 | 50 | qd6003.setCode("60_03"); |
| ... | ... | @@ -111,7 +111,7 @@ public class DirectivePushQueue implements CommandLineRunner, ApplicationContext |
| 111 | 111 | log.info("directive 60_02 sch id: " + qd.getSch().getId()); |
| 112 | 112 | } |
| 113 | 113 | else if(code.equals("60_03")){ |
| 114 | - directiveService.send60Operation(qd.getNbbm(), qd.getState(), qd.getUpDown(), null, qd.getSender()); | |
| 114 | + directiveService.send60Operation(qd.getNbbm(), qd.getState(), qd.getUpDown(), qd.getSender()); | |
| 115 | 115 | log.info("directive 60_03 nbbm: " + qd.getNbbm()); |
| 116 | 116 | } |
| 117 | 117 | else if(code.equals("64")){ | ... | ... |
src/main/java/com/bsth/data/pilot80/PilotReport.java
| ... | ... | @@ -2,7 +2,9 @@ package com.bsth.data.pilot80; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.data.BasicData; |
| 4 | 4 | import com.bsth.data.LineConfigData; |
| 5 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 5 | 6 | import com.bsth.data.gpsdata.GpsRealData; |
| 7 | +import com.bsth.data.gpsdata.status_manager.GpsStatusManager; | |
| 6 | 8 | import com.bsth.data.msg_queue.DirectivePushQueue; |
| 7 | 9 | import com.bsth.data.schedule.DayOfSchedule; |
| 8 | 10 | import com.bsth.entity.Line; |
| ... | ... | @@ -51,6 +53,9 @@ public class PilotReport { |
| 51 | 53 | @Autowired |
| 52 | 54 | DC0A4Repository dc0A4Repository; |
| 53 | 55 | |
| 56 | + @Autowired | |
| 57 | + GpsStatusManager gpsStatusManager; | |
| 58 | + | |
| 54 | 59 | //private static ArrayListMultimap<String, D80> d80MultiMap; |
| 55 | 60 | |
| 56 | 61 | private static ConcurrentHashMap<Integer, D80> d80Maps; |
| ... | ... | @@ -80,14 +85,26 @@ public class PilotReport { |
| 80 | 85 | ScheduleRealInfo outSch = dayOfSchedule.searchNearByBcType(nbbm, "out"); |
| 81 | 86 | //如果有对应出场班次 |
| 82 | 87 | if (outSch != null) { |
| 83 | - //没有计划里程的出场班次,出场既是首发站,发送下一班次的营运指令 | |
| 88 | + //没有计划里程的出场班次,出场既是首发站,发送下一班次的调度指令 | |
| 84 | 89 | if (outSch.getJhlc() == null) |
| 85 | 90 | outSch = dayOfSchedule.next(outSch); |
| 86 | 91 | |
| 87 | 92 | //下发调度指令 |
| 93 | + String deviceId = d80.getDeviceId(); | |
| 88 | 94 | DirectivePushQueue.put6002(outSch, dayOfSchedule.doneSum(nbbm), "请出@系统"); |
| 95 | + | |
| 89 | 96 | //下发线路切换指令 |
| 90 | 97 | DirectivePushQueue.put64(outSch.getClZbh(), outSch.getXlBm(), "请出@系统"); |
| 98 | + | |
| 99 | + try { | |
| 100 | + GpsEntity gps = gpsRealData.get(deviceId); | |
| 101 | + if(gps != null && !gps.isService()){ | |
| 102 | + //切换到营运状态 | |
| 103 | + gpsStatusManager.changeServiceState(nbbm, outSch.getXlDir() ,0, "请出@系统"); | |
| 104 | + } | |
| 105 | + }catch (Exception e){ | |
| 106 | + logger.error("请出切换营运状态异常", e); | |
| 107 | + } | |
| 91 | 108 | } |
| 92 | 109 | break; |
| 93 | 110 | } | ... | ... |
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
| ... | ... | @@ -4,12 +4,9 @@ import com.alibaba.fastjson.JSON; |
| 4 | 4 | import com.alibaba.fastjson.JSONArray; |
| 5 | 5 | import com.bsth.common.Constants; |
| 6 | 6 | import com.bsth.common.ResponseCode; |
| 7 | -import com.bsth.data.BasicData; | |
| 8 | 7 | import com.bsth.data.LineConfigData; |
| 9 | -import com.bsth.data.gpsdata.GpsEntity; | |
| 10 | 8 | import com.bsth.data.gpsdata.GpsRealData; |
| 11 | 9 | import com.bsth.data.gpsdata.recovery.GpsDataRecovery; |
| 12 | -import com.bsth.data.msg_queue.DirectivePushQueue; | |
| 13 | 10 | import com.bsth.entity.realcontrol.LineConfig; |
| 14 | 11 | import com.bsth.entity.realcontrol.ScheduleRealInfo; |
| 15 | 12 | import com.bsth.entity.schedule.SchedulePlanInfo; |
| ... | ... | @@ -181,7 +178,7 @@ public class DayOfSchedule { |
| 181 | 178 | |
| 182 | 179 | |
| 183 | 180 | Set<String> lps = searchAllLP(list); |
| 184 | - for(String lp : lps){ | |
| 181 | + for (String lp : lps) { | |
| 185 | 182 | //计算“起点站应到”时间 |
| 186 | 183 | schAttrCalculator.calcQdzTimePlan(lpScheduleMap.get(lineCode + "_" + lp)); |
| 187 | 184 | } |
| ... | ... | @@ -201,14 +198,14 @@ public class DayOfSchedule { |
| 201 | 198 | return 0; |
| 202 | 199 | } |
| 203 | 200 | |
| 204 | - public int reloadSch(String lineCode){ | |
| 201 | + public int reloadSch(String lineCode) { | |
| 205 | 202 | return reloadSch(lineCode, calcSchDate(lineCode), true); |
| 206 | 203 | } |
| 207 | 204 | |
| 208 | 205 | /** |
| 209 | 206 | * @Title: searchAllCars |
| 210 | 207 | * @Description: TODO(搜索班次集合中的车辆) |
| 211 | - */ | |
| 208 | + */ | |
| 212 | 209 | private Set<String> searchAllCars(List<ScheduleRealInfo> list) { |
| 213 | 210 | Set<String> cars = new HashSet<>(); |
| 214 | 211 | for (ScheduleRealInfo sch : list) |
| ... | ... | @@ -277,12 +274,12 @@ public class DayOfSchedule { |
| 277 | 274 | //清理路牌对照 |
| 278 | 275 | List<String> lprms = new ArrayList<>(); |
| 279 | 276 | Set<String> lps = lpScheduleMap.keySet(); |
| 280 | - for(String lp : lps){ | |
| 281 | - if(lp.indexOf(lineCode + "_") != -1) | |
| 277 | + for (String lp : lps) { | |
| 278 | + if (lp.indexOf(lineCode + "_") != -1) | |
| 282 | 279 | lprms.add(lp); |
| 283 | 280 | } |
| 284 | 281 | |
| 285 | - for(String lp : lprms) | |
| 282 | + for (String lp : lprms) | |
| 286 | 283 | lpScheduleMap.removeAll(lp); |
| 287 | 284 | |
| 288 | 285 | logger.info(lineCode + "排班清理 " + count); |
| ... | ... | @@ -336,10 +333,10 @@ public class DayOfSchedule { |
| 336 | 333 | if (StringUtils.isEmpty(sch.getFcsj())) |
| 337 | 334 | sch.setFcsj("00:00"); |
| 338 | 335 | |
| 339 | - if(sch.getFcsj().equals("24:00")) | |
| 336 | + if (sch.getFcsj().equals("24:00")) | |
| 340 | 337 | sch.setFcsj("23:59"); |
| 341 | 338 | |
| 342 | - if(sch.getFcsj().substring(0, 2).equals("24")){ | |
| 339 | + if (sch.getFcsj().substring(0, 2).equals("24")) { | |
| 343 | 340 | sch.setFcsj("00" + sch.getFcsj().substring(2)); |
| 344 | 341 | } |
| 345 | 342 | |
| ... | ... | @@ -364,13 +361,13 @@ public class DayOfSchedule { |
| 364 | 361 | } |
| 365 | 362 | |
| 366 | 363 | //售票员为空设置为""字符串 |
| 367 | - if(StringUtils.isEmpty(sch.getsGh())){ | |
| 364 | + if (StringUtils.isEmpty(sch.getsGh())) { | |
| 368 | 365 | sch.setsGh(""); |
| 369 | 366 | sch.setsName(""); |
| 370 | 367 | } |
| 371 | 368 | sch.setJhlcOrig(sch.getJhlc()); |
| 372 | 369 | //保留备注 |
| 373 | - if(StringUtils.isNotEmpty(sch.getRemark())) | |
| 370 | + if (StringUtils.isNotEmpty(sch.getRemark())) | |
| 374 | 371 | sch.setRemarks(sch.getRemark()); |
| 375 | 372 | } |
| 376 | 373 | } catch (Exception e) { |
| ... | ... | @@ -440,7 +437,7 @@ public class DayOfSchedule { |
| 440 | 437 | |
| 441 | 438 | Collection<ScheduleRealInfo> schs = id2SchedulMap.values(); |
| 442 | 439 | for (ScheduleRealInfo sch : schs) { |
| 443 | - if(lineList.contains(sch.getXlBm())){ | |
| 440 | + if (lineList.contains(sch.getXlBm())) { | |
| 444 | 441 | mMap.put(sch.getXlBm(), sch); |
| 445 | 442 | } |
| 446 | 443 | } |
| ... | ... | @@ -497,12 +494,13 @@ public class DayOfSchedule { |
| 497 | 494 | |
| 498 | 495 | /** |
| 499 | 496 | * 下一个相同走向的班次 |
| 497 | + * | |
| 500 | 498 | * @param sch |
| 501 | 499 | * @return |
| 502 | 500 | */ |
| 503 | - public ScheduleRealInfo nextSame(final ScheduleRealInfo sch){ | |
| 501 | + public ScheduleRealInfo nextSame(final ScheduleRealInfo sch) { | |
| 504 | 502 | List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh()); |
| 505 | - Collection<ScheduleRealInfo> subList = Collections2.filter(list, new Predicate<ScheduleRealInfo>(){ | |
| 503 | + Collection<ScheduleRealInfo> subList = Collections2.filter(list, new Predicate<ScheduleRealInfo>() { | |
| 506 | 504 | |
| 507 | 505 | @Override |
| 508 | 506 | public boolean apply(ScheduleRealInfo item) { |
| ... | ... | @@ -544,11 +542,12 @@ public class DayOfSchedule { |
| 544 | 542 | |
| 545 | 543 | /** |
| 546 | 544 | * 下一个班次 |
| 545 | + * | |
| 547 | 546 | * @param list 班次集合 |
| 548 | - * @param sch 当前班次 | |
| 547 | + * @param sch 当前班次 | |
| 549 | 548 | * @return |
| 550 | 549 | */ |
| 551 | - private ScheduleRealInfo next(Collection<ScheduleRealInfo> list , ScheduleRealInfo sch){ | |
| 550 | + private ScheduleRealInfo next(Collection<ScheduleRealInfo> list, ScheduleRealInfo sch) { | |
| 552 | 551 | int outConfig = -1; |
| 553 | 552 | LineConfig config = lineConfigData.get(sch.getXlBm()); |
| 554 | 553 | if (config != null) |
| ... | ... | @@ -583,11 +582,12 @@ public class DayOfSchedule { |
| 583 | 582 | |
| 584 | 583 | /** |
| 585 | 584 | * 下一个班次 |
| 585 | + * | |
| 586 | 586 | * @param list 班次集合 |
| 587 | - * @param sch 当前班次 | |
| 587 | + * @param sch 当前班次 | |
| 588 | 588 | * @return |
| 589 | 589 | */ |
| 590 | - private ScheduleRealInfo next2(Collection<ScheduleRealInfo> list , ScheduleRealInfo sch){ | |
| 590 | + private ScheduleRealInfo next2(Collection<ScheduleRealInfo> list, ScheduleRealInfo sch) { | |
| 591 | 591 | int outConfig = -1; |
| 592 | 592 | LineConfig config = lineConfigData.get(sch.getXlBm()); |
| 593 | 593 | if (config != null) |
| ... | ... | @@ -639,13 +639,14 @@ public class DayOfSchedule { |
| 639 | 639 | |
| 640 | 640 | /** |
| 641 | 641 | * 是否是首班出场 |
| 642 | + * | |
| 642 | 643 | * @param sch |
| 643 | 644 | * @return |
| 644 | 645 | */ |
| 645 | - public boolean isFirstOut(ScheduleRealInfo sch){ | |
| 646 | + public boolean isFirstOut(ScheduleRealInfo sch) { | |
| 646 | 647 | List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh()); |
| 647 | 648 | try { |
| 648 | - if(list.get(0) == sch && sch.getBcType().equals("out")) | |
| 649 | + if (list.get(0) == sch && sch.getBcType().equals("out")) | |
| 649 | 650 | return true; |
| 650 | 651 | } catch (IndexOutOfBoundsException e) { |
| 651 | 652 | logger.error("小小的数组越界,无伤大雅!"); |
| ... | ... | @@ -671,7 +672,7 @@ public class DayOfSchedule { |
| 671 | 672 | save(sch); |
| 672 | 673 | } |
| 673 | 674 | |
| 674 | - public void addLPMapp(ScheduleRealInfo sch){ | |
| 675 | + public void addLPMapp(ScheduleRealInfo sch) { | |
| 675 | 676 | lpScheduleMap.put(sch.getXlBm() + "_" + sch.getLpName(), sch); |
| 676 | 677 | } |
| 677 | 678 | |
| ... | ... | @@ -685,7 +686,7 @@ public class DayOfSchedule { |
| 685 | 686 | lpScheduleMap.remove(sch.getXlBm() + "_" + sch.getLpName(), sch); |
| 686 | 687 | |
| 687 | 688 | //如果正在执行该班次 |
| 688 | - if(carExecutePlanMap.get(sch.getClZbh()) == sch){ | |
| 689 | + if (carExecutePlanMap.get(sch.getClZbh()) == sch) { | |
| 689 | 690 | //重新计算车辆当前执行班次 |
| 690 | 691 | reCalcExecPlan(sch.getClZbh()); |
| 691 | 692 | } |
| ... | ... | @@ -823,12 +824,12 @@ public class DayOfSchedule { |
| 823 | 824 | Collections.sort(list, schFCSJComparator); |
| 824 | 825 | |
| 825 | 826 | boolean flag = false; |
| 826 | - for(ScheduleRealInfo temp : list){ | |
| 827 | + for (ScheduleRealInfo temp : list) { | |
| 827 | 828 | |
| 828 | - if(flag && temp.getBcType().equals(bcType)) | |
| 829 | + if (flag && temp.getBcType().equals(bcType)) | |
| 829 | 830 | return temp; |
| 830 | 831 | |
| 831 | - if(temp == sch){ | |
| 832 | + if (temp == sch) { | |
| 832 | 833 | flag = true; |
| 833 | 834 | } |
| 834 | 835 | } |
| ... | ... | @@ -837,21 +838,22 @@ public class DayOfSchedule { |
| 837 | 838 | |
| 838 | 839 | /** |
| 839 | 840 | * 搜索离当前时间最近的一个指定类型的班次 |
| 841 | + * | |
| 840 | 842 | * @param nbbm |
| 841 | 843 | * @param bcType |
| 842 | 844 | * @return |
| 843 | 845 | */ |
| 844 | - public ScheduleRealInfo searchNearByBcType(String nbbm, String bcType){ | |
| 846 | + public ScheduleRealInfo searchNearByBcType(String nbbm, String bcType) { | |
| 845 | 847 | List<ScheduleRealInfo> list = findByBcType(nbbm, bcType); |
| 846 | 848 | Collections.sort(list, schFCSJComparator); |
| 847 | 849 | |
| 848 | 850 | long t = System.currentTimeMillis(); |
| 849 | - int distance=-1, diff; | |
| 851 | + int distance = -1, diff; | |
| 850 | 852 | |
| 851 | 853 | ScheduleRealInfo sch = null; |
| 852 | - for(ScheduleRealInfo temp : list){ | |
| 854 | + for (ScheduleRealInfo temp : list) { | |
| 853 | 855 | diff = (int) Math.abs(temp.getDfsjT() - t); |
| 854 | - if(diff < distance || distance == -1){ | |
| 856 | + if (diff < distance || distance == -1) { | |
| 855 | 857 | sch = temp; |
| 856 | 858 | distance = diff; |
| 857 | 859 | } |
| ... | ... | @@ -878,7 +880,7 @@ public class DayOfSchedule { |
| 878 | 880 | } |
| 879 | 881 | |
| 880 | 882 | public void addExecPlan(ScheduleRealInfo sch) { |
| 881 | - if(sch != null) | |
| 883 | + if (sch != null) | |
| 882 | 884 | carExecutePlanMap.put(sch.getClZbh(), sch); |
| 883 | 885 | else |
| 884 | 886 | carExecutePlanMap.remove(sch.getClZbh()); |
| ... | ... | @@ -915,7 +917,7 @@ public class DayOfSchedule { |
| 915 | 917 | nbbmScheduleMap.remove(sch.getClZbh(), sch); |
| 916 | 918 | |
| 917 | 919 | sch.setClZbh(newClZbh); |
| 918 | - if(!nbbmScheduleMap.containsEntry(newClZbh, sch)){ | |
| 920 | + if (!nbbmScheduleMap.containsEntry(newClZbh, sch)) { | |
| 919 | 921 | nbbmScheduleMap.put(newClZbh, sch); |
| 920 | 922 | } |
| 921 | 923 | |
| ... | ... | @@ -929,52 +931,90 @@ public class DayOfSchedule { |
| 929 | 931 | return ups; |
| 930 | 932 | } |
| 931 | 933 | |
| 932 | - public void removeNbbm2SchMapp(ScheduleRealInfo sch, String nbbm){ | |
| 934 | + public void removeNbbm2SchMapp(ScheduleRealInfo sch, String nbbm) { | |
| 933 | 935 | nbbmScheduleMap.remove(nbbm, sch); |
| 934 | 936 | } |
| 935 | 937 | |
| 936 | - public void addNbbm2SchMapp(ScheduleRealInfo sch, String nbbm){ | |
| 938 | + public void addNbbm2SchMapp(ScheduleRealInfo sch, String nbbm) { | |
| 937 | 939 | nbbmScheduleMap.put(nbbm, sch); |
| 938 | 940 | } |
| 939 | 941 | |
| 940 | - public void reCalcExecPlan(String nbbm){ | |
| 942 | + public void reCalcExecPlan(String nbbm) { | |
| 941 | 943 | List<ScheduleRealInfo> list = nbbmScheduleMap.get(nbbm); |
| 942 | 944 | Collections.sort(list, schFCSJComparator); |
| 943 | 945 | |
| 944 | 946 | ScheduleRealInfo sch = schAttrCalculator.calcCurrentExecSch(list); |
| 945 | 947 | carExecutePlanMap.put(nbbm, sch); |
| 946 | 948 | |
| 947 | - if(sch==null){ | |
| 948 | - logger.info("车辆" + nbbm + "无可执行任务,切换至非营运状态"); | |
| 949 | - DirectivePushQueue.put6003(nbbm, 1, Integer.parseInt(sch.getXlDir()), null, "系统"); | |
| 950 | - return; | |
| 951 | - } | |
| 952 | - try { | |
| 949 | + | |
| 950 | + /* try{ | |
| 953 | 951 | GpsEntity gps = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm)); |
| 954 | - if(gps != null && gps.isOnline()){ | |
| 955 | - if(StringUtils.isNotEmpty(gps.getLineId()) && !gps.getLineId().equals(sch.getXlBm())){ | |
| 956 | - //下发线路切换指令 | |
| 957 | - DirectivePushQueue.put64(nbbm, sch.getXlBm(), "系统"); | |
| 958 | - logger.info("车辆" + nbbm + "切换至" + sch.getXlBm() + " -原" + gps.getLineId() + " --重新计算当前执行班次!"); | |
| 952 | + if (gps == null || !gps.isOnline()) | |
| 953 | + return;//设备不在线 | |
| 954 | + | |
| 955 | + *//*if(sch == null && gps.isService()) | |
| 956 | + DirectivePushQueue.put6003(nbbm, 1, 0, null, "系统");//无任务*//* | |
| 957 | + | |
| 958 | + //String bcType = sch.getBcType(); | |
| 959 | + *//*if(bcType.equals("normal") | |
| 960 | + || bcType.equals("region") | |
| 961 | + || bcType.equals("major")){ | |
| 962 | + //全程、区间、放站,切换到营运状态 | |
| 963 | + if(!gps.isService()){ | |
| 964 | + DirectivePushQueue.put6003(nbbm, 0, Integer.parseInt(sch.getXlDir()), sch, "系统"); | |
| 959 | 965 | } |
| 960 | 966 | } |
| 967 | + else if(gps.isService()){ | |
| 968 | + DirectivePushQueue.put6003(nbbm, 1, 0, null, "系统");//空驶任务 | |
| 969 | + }*//* | |
| 961 | 970 | }catch (Exception e){ |
| 962 | 971 | logger.error("", e); |
| 963 | 972 | } |
| 973 | + *//*try { | |
| 974 | + //切换设备状态 | |
| 975 | + GpsEntity gps = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm)); | |
| 976 | + if (gps == null || !gps.isOnline()) | |
| 977 | + return; | |
| 978 | + if (sch == null) { | |
| 979 | + logger.info("车辆" + nbbm + "无可执行任务,切换至非营运状态"); | |
| 980 | + DirectivePushQueue.put6003(nbbm, 1, 0, null, "系统"); | |
| 981 | + return; | |
| 982 | + } | |
| 983 | + | |
| 984 | + if (StringUtils.isNotEmpty(gps.getLineId()) && !gps.getLineId().equals(sch.getXlBm())) { | |
| 985 | + //下发线路切换指令 | |
| 986 | + DirectivePushQueue.put64(nbbm, sch.getXlBm(), "系统"); | |
| 987 | + logger.info("车辆" + nbbm + "切换至" + sch.getXlBm() + " -原" + gps.getLineId() + " --重新计算当前执行班次!"); | |
| 988 | + } | |
| 989 | + } catch (Exception e) { | |
| 990 | + logger.error("", e); | |
| 991 | + }*/ | |
| 992 | + } | |
| 993 | + | |
| 994 | + /** | |
| 995 | + * 空驶任务? | |
| 996 | + * 出场、进场、直放、两点间空驶 | |
| 997 | + * @param sch | |
| 998 | + * @return | |
| 999 | + */ | |
| 1000 | + public static boolean emptyService(ScheduleRealInfo sch){ | |
| 1001 | + String type = sch.getBcType(); | |
| 1002 | + return type.equals("out") || type.equals("in") || type.equals("venting") || type.equals("ldks"); | |
| 964 | 1003 | } |
| 965 | 1004 | |
| 966 | 1005 | /** |
| 967 | 1006 | * 是否在执行首班出场 |
| 1007 | + * | |
| 968 | 1008 | * @param nbbm |
| 969 | 1009 | * @return |
| 970 | - */ | |
| 971 | - public boolean isExecFirstOut(String nbbm, long time){ | |
| 1010 | + | |
| 1011 | + public boolean isExecFirstOut(String nbbm, long time) { | |
| 972 | 1012 | try { |
| 973 | 1013 | List<ScheduleRealInfo> list = nbbmScheduleMap.get(nbbm); |
| 974 | 1014 | ScheduleRealInfo second = list.get(2), |
| 975 | 1015 | first = executeCurr(nbbm); |
| 976 | 1016 | |
| 977 | - if(first.getBcType().equals("out") | |
| 1017 | + if (first.getBcType().equals("out") | |
| 978 | 1018 | && first.getDfsjT() < second.getDfsjT() |
| 979 | 1019 | && doneSum(nbbm) == 0 && second.getDfsjT() > time) |
| 980 | 1020 | return true; |
| ... | ... | @@ -983,13 +1023,15 @@ public class DayOfSchedule { |
| 983 | 1023 | } |
| 984 | 1024 | |
| 985 | 1025 | return false; |
| 986 | - } | |
| 1026 | + }*/ | |
| 987 | 1027 | |
| 988 | 1028 | |
| 989 | 1029 | @Autowired |
| 990 | 1030 | JdbcTemplate jdbcTemplate; |
| 1031 | + | |
| 991 | 1032 | /** |
| 992 | 1033 | * 删除实际排班 |
| 1034 | + * | |
| 993 | 1035 | * @param lineCode |
| 994 | 1036 | * @return |
| 995 | 1037 | */ |
| ... | ... | @@ -998,16 +1040,16 @@ public class DayOfSchedule { |
| 998 | 1040 | |
| 999 | 1041 | try { |
| 1000 | 1042 | String rq = currSchDateMap.get(lineCode); |
| 1001 | - if(StringUtils.isNotEmpty(rq)){ | |
| 1043 | + if (StringUtils.isNotEmpty(rq)) { | |
| 1002 | 1044 | List<ScheduleRealInfo> all = findByLineCode(lineCode); |
| 1003 | 1045 | //解除gps 和班次之间的关联 |
| 1004 | 1046 | List<ScheduleRealInfo> unions = calcUnion(all, carExecutePlanMap.values()); |
| 1005 | - for(ScheduleRealInfo sch : unions){ | |
| 1047 | + for (ScheduleRealInfo sch : unions) { | |
| 1006 | 1048 | removeExecPlan(sch.getClZbh()); |
| 1007 | 1049 | } |
| 1008 | 1050 | //解除调度指令和班次的外键约束 |
| 1009 | 1051 | StringBuilder inStr = new StringBuilder("("); |
| 1010 | - for(ScheduleRealInfo sch : all){ | |
| 1052 | + for (ScheduleRealInfo sch : all) { | |
| 1011 | 1053 | inStr.append(sch.getId() + ","); |
| 1012 | 1054 | } |
| 1013 | 1055 | inStr.deleteCharAt(inStr.length() - 1).append(")"); |
| ... | ... | @@ -1019,10 +1061,10 @@ public class DayOfSchedule { |
| 1019 | 1061 | |
| 1020 | 1062 | } |
| 1021 | 1063 | rs.put("status", ResponseCode.SUCCESS); |
| 1022 | - }catch (Exception e){ | |
| 1064 | + } catch (Exception e) { | |
| 1023 | 1065 | logger.error("", e); |
| 1024 | 1066 | rs.put("status", ResponseCode.ERROR); |
| 1025 | - if(e instanceof DataIntegrityViolationException) | |
| 1067 | + if (e instanceof DataIntegrityViolationException) | |
| 1026 | 1068 | rs.put("msg", "失败,违反数据约束!!"); |
| 1027 | 1069 | else |
| 1028 | 1070 | rs.put("msg", e.getMessage()); |
| ... | ... | @@ -1042,7 +1084,7 @@ public class DayOfSchedule { |
| 1042 | 1084 | List<ScheduleRealInfo> rs = new ArrayList<>(); |
| 1043 | 1085 | |
| 1044 | 1086 | for (ScheduleRealInfo sch : c1) { |
| 1045 | - if(c2.contains(sch)){ | |
| 1087 | + if (c2.contains(sch)) { | |
| 1046 | 1088 | rs.add(sch); |
| 1047 | 1089 | } |
| 1048 | 1090 | } |
| ... | ... | @@ -1051,16 +1093,18 @@ public class DayOfSchedule { |
| 1051 | 1093 | |
| 1052 | 1094 | /** |
| 1053 | 1095 | * 覆盖一辆车的所有班次 |
| 1096 | + * | |
| 1054 | 1097 | * @param nbbm |
| 1055 | 1098 | * @param sets |
| 1056 | 1099 | */ |
| 1057 | - public void replaceByNbbm(String nbbm, Collection<ScheduleRealInfo> sets){ | |
| 1100 | + public void replaceByNbbm(String nbbm, Collection<ScheduleRealInfo> sets) { | |
| 1058 | 1101 | nbbmScheduleMap.removeAll(nbbm); |
| 1059 | 1102 | nbbmScheduleMap.putAll(nbbm, sets); |
| 1060 | 1103 | } |
| 1061 | 1104 | |
| 1062 | 1105 | /** |
| 1063 | 1106 | * 获取该班次所在路牌的下一个班次 |
| 1107 | + * | |
| 1064 | 1108 | * @param sch |
| 1065 | 1109 | * @return |
| 1066 | 1110 | */ |
| ... | ... | @@ -1072,6 +1116,7 @@ public class DayOfSchedule { |
| 1072 | 1116 | |
| 1073 | 1117 | /** |
| 1074 | 1118 | * 获取该班次所在路牌的下一个班次,不考虑场既是站 |
| 1119 | + * | |
| 1075 | 1120 | * @param sch |
| 1076 | 1121 | * @return |
| 1077 | 1122 | */ |
| ... | ... | @@ -1081,7 +1126,7 @@ public class DayOfSchedule { |
| 1081 | 1126 | return next2(list, sch); |
| 1082 | 1127 | } |
| 1083 | 1128 | |
| 1084 | - public ArrayListMultimap<String, ScheduleRealInfo> getLpScheduleMap(){ | |
| 1129 | + public ArrayListMultimap<String, ScheduleRealInfo> getLpScheduleMap() { | |
| 1085 | 1130 | return lpScheduleMap; |
| 1086 | 1131 | } |
| 1087 | 1132 | } |
| 1088 | 1133 | \ No newline at end of file | ... | ... |
src/main/java/com/bsth/entity/realcontrol/ScheduleType.java deleted
100644 → 0
src/main/java/com/bsth/entity/schedule/TTInfo.java
| 1 | 1 | package com.bsth.entity.schedule; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.Line; |
| 4 | +import com.bsth.service.schedule.utils.TimeTableProto; | |
| 4 | 5 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
| 5 | 6 | |
| 6 | 7 | import javax.persistence.*; |
| ... | ... | @@ -63,6 +64,9 @@ public class TTInfo extends BEntity { |
| 63 | 64 | /** 特殊有效日期(格式:2001-01-01,多个用逗号隔开) */ |
| 64 | 65 | private String special_days; |
| 65 | 66 | |
| 67 | + /** 最近备份日期 */ | |
| 68 | + private Date lastBackUpDate; | |
| 69 | + | |
| 66 | 70 | public TTInfo() {} |
| 67 | 71 | public TTInfo(Object id, Object xlid, Object name, Object nds, Object sds) { |
| 68 | 72 | if (id != null) { |
| ... | ... | @@ -83,6 +87,32 @@ public class TTInfo extends BEntity { |
| 83 | 87 | } |
| 84 | 88 | } |
| 85 | 89 | |
| 90 | + /** | |
| 91 | + * 输出proto生成的builder | |
| 92 | + * @return | |
| 93 | + */ | |
| 94 | + public TimeTableProto.TTInfo.Builder toProtoBuilder() { | |
| 95 | + // 注意部份空值处理,必须覆默认值,否则报nullexceptio | |
| 96 | + return TimeTableProto.TTInfo.newBuilder() | |
| 97 | + .setId(id) | |
| 98 | + .setName(name) | |
| 99 | + .setXl(xl.getId()) | |
| 100 | + .setXlName(xl.getName()) | |
| 101 | + .setXlDir(xlDir) | |
| 102 | + .setQyrq(qyrq.getTime()) | |
| 103 | + .setIsEnableDisTemplate(isEnableDisTemplate) | |
| 104 | + .setIsCancel(isCancel) | |
| 105 | + .setRuleDays(rule_days) | |
| 106 | + .setSpecialDays(special_days) | |
| 107 | + .setCreateUser(getCreateBy() == null ? 0 : getCreateBy().getId()) | |
| 108 | + .setCreateUserName(getCreateBy() == null ? "" : getCreateBy().getUserName()) | |
| 109 | + .setUpdateUser(getUpdateBy() == null ? 0 : getUpdateBy().getId()) | |
| 110 | + .setUpdateUserName(getUpdateBy() == null ? "" : getUpdateBy().getUserName()) | |
| 111 | + .setCreateDate(getCreateDate() == null ? 0l : getCreateDate().getTime()) | |
| 112 | + .setUpdateDate(getUpdateDate() == null ? 0l : getUpdateDate().getTime()); | |
| 113 | + | |
| 114 | + } | |
| 115 | + | |
| 86 | 116 | public Long getId() { |
| 87 | 117 | return id; |
| 88 | 118 | } |
| ... | ... | @@ -178,4 +208,12 @@ public class TTInfo extends BEntity { |
| 178 | 208 | public void setIsCancel(Boolean isCancel) { |
| 179 | 209 | this.isCancel = isCancel; |
| 180 | 210 | } |
| 211 | + | |
| 212 | + public Date getLastBackUpDate() { | |
| 213 | + return lastBackUpDate; | |
| 214 | + } | |
| 215 | + | |
| 216 | + public void setLastBackUpDate(Date lastBackUpDate) { | |
| 217 | + this.lastBackUpDate = lastBackUpDate; | |
| 218 | + } | |
| 181 | 219 | } | ... | ... |
src/main/java/com/bsth/entity/schedule/TTInfoBackup.java
0 → 100644
| 1 | +package com.bsth.entity.schedule; | |
| 2 | + | |
| 3 | +import javax.persistence.*; | |
| 4 | +import java.util.Date; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * 时刻表信息备份。 | |
| 8 | + * --不做关联信息,保存相应的关联id | |
| 9 | + */ | |
| 10 | +@Entity | |
| 11 | +@Table(name="bsth_c_s_ttinfo_bak") | |
| 12 | +public class TTInfoBackup { | |
| 13 | + | |
| 14 | + /** 主键Id */ | |
| 15 | + @Id | |
| 16 | + @GeneratedValue | |
| 17 | + private Long id; | |
| 18 | + | |
| 19 | + /** 关联 bsth_c_line 主键,不做mapping */ | |
| 20 | + @Column(nullable = false) | |
| 21 | + private Integer xl; | |
| 22 | + /** 线路名称 */ | |
| 23 | + @Column(nullable = false) | |
| 24 | + private String xlName; | |
| 25 | + | |
| 26 | + /** 关联 bsth_c_s_ttinfo 主键,不做mapping */ | |
| 27 | + @Column(nullable = false) | |
| 28 | + private Long ttInfo; | |
| 29 | + /** 关联的时刻表名字 */ | |
| 30 | + private String ttInfoName; | |
| 31 | + | |
| 32 | + /** 备份日期 */ | |
| 33 | + @Column(nullable = false) | |
| 34 | + private Date backUpDate; | |
| 35 | + /** 备份的二进制内容(google protobuf格式) */ | |
| 36 | + @Lob | |
| 37 | + private byte[] backUpInfo; | |
| 38 | + | |
| 39 | + public Long getId() { | |
| 40 | + return id; | |
| 41 | + } | |
| 42 | + | |
| 43 | + public void setId(Long id) { | |
| 44 | + this.id = id; | |
| 45 | + } | |
| 46 | + | |
| 47 | + public Integer getXl() { | |
| 48 | + return xl; | |
| 49 | + } | |
| 50 | + | |
| 51 | + public void setXl(Integer xl) { | |
| 52 | + this.xl = xl; | |
| 53 | + } | |
| 54 | + | |
| 55 | + public String getXlName() { | |
| 56 | + return xlName; | |
| 57 | + } | |
| 58 | + | |
| 59 | + public void setXlName(String xlName) { | |
| 60 | + this.xlName = xlName; | |
| 61 | + } | |
| 62 | + | |
| 63 | + public Long getTtInfo() { | |
| 64 | + return ttInfo; | |
| 65 | + } | |
| 66 | + | |
| 67 | + public void setTtInfo(Long ttInfo) { | |
| 68 | + this.ttInfo = ttInfo; | |
| 69 | + } | |
| 70 | + | |
| 71 | + public String getTtInfoName() { | |
| 72 | + return ttInfoName; | |
| 73 | + } | |
| 74 | + | |
| 75 | + public void setTtInfoName(String ttInfoName) { | |
| 76 | + this.ttInfoName = ttInfoName; | |
| 77 | + } | |
| 78 | + | |
| 79 | + public Date getBackUpDate() { | |
| 80 | + return backUpDate; | |
| 81 | + } | |
| 82 | + | |
| 83 | + public void setBackUpDate(Date backUpDate) { | |
| 84 | + this.backUpDate = backUpDate; | |
| 85 | + } | |
| 86 | + | |
| 87 | + public byte[] getBackUpInfo() { | |
| 88 | + return backUpInfo; | |
| 89 | + } | |
| 90 | + | |
| 91 | + public void setBackUpInfo(byte[] backUpInfo) { | |
| 92 | + this.backUpInfo = backUpInfo; | |
| 93 | + } | |
| 94 | +} | ... | ... |
src/main/java/com/bsth/entity/schedule/TTInfoDetail.java
| ... | ... | @@ -3,6 +3,7 @@ package com.bsth.entity.schedule; |
| 3 | 3 | import com.bsth.entity.CarPark; |
| 4 | 4 | import com.bsth.entity.Line; |
| 5 | 5 | import com.bsth.entity.Station; |
| 6 | +import com.bsth.service.schedule.utils.TimeTableProto; | |
| 6 | 7 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
| 7 | 8 | |
| 8 | 9 | import javax.persistence.*; |
| ... | ... | @@ -99,6 +100,35 @@ public class TTInfoDetail extends BEntity { |
| 99 | 100 | /** 备注 */ |
| 100 | 101 | private String remark; |
| 101 | 102 | |
| 103 | + /** | |
| 104 | + * 输出proto生成的builder | |
| 105 | + * @return | |
| 106 | + */ | |
| 107 | + public TimeTableProto.TTInfoDetail.Builder toProtoBuilder() { | |
| 108 | + // 注意部份空值处理,必须覆默认值,否则报nullexception | |
| 109 | + return TimeTableProto.TTInfoDetail.newBuilder() | |
| 110 | + .setId(id) | |
| 111 | + .setXl(xl.getId()) | |
| 112 | + .setXlName(xl.getName()) | |
| 113 | + .setLp(lp.getId()) | |
| 114 | + .setLpName(lp.getLpName()) | |
| 115 | + .setFcno(fcno) | |
| 116 | + .setXlDir(xlDir) | |
| 117 | + .setQdzCode(qdzCode) | |
| 118 | + .setQdzName(qdzName) | |
| 119 | + .setZdzCode(zdzCode) | |
| 120 | + .setZdzName(zdzName) | |
| 121 | + .setFcsj(fcsj) | |
| 122 | + .setBcs(bcs) | |
| 123 | + .setJhlc(jhlc) | |
| 124 | + .setBcsj(bcsj) | |
| 125 | + .setBcType(bcType) | |
| 126 | + .setIsFB(isFB == null ? false : isFB) | |
| 127 | + .setIsTS(isTS == null ? false : isTS) | |
| 128 | + .setRemark(remark == null ? "" : remark) | |
| 129 | + ; | |
| 130 | + } | |
| 131 | + | |
| 102 | 132 | public Long getId() { |
| 103 | 133 | return id; |
| 104 | 134 | } | ... | ... |
src/main/java/com/bsth/repository/schedule/TTInfoBackupRepository.java
0 → 100644
| 1 | +package com.bsth.repository.schedule; | |
| 2 | + | |
| 3 | +import com.bsth.entity.schedule.TTInfoBackup; | |
| 4 | +import com.bsth.repository.BaseRepository; | |
| 5 | +import org.springframework.stereotype.Repository; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * Created by xu on 17/7/13. | |
| 9 | + */ | |
| 10 | +@Repository | |
| 11 | +public interface TTInfoBackupRepository extends BaseRepository<TTInfoBackup, Long> { | |
| 12 | +} | ... | ... |
src/main/java/com/bsth/service/directive/DirectiveService.java
| ... | ... | @@ -44,7 +44,7 @@ public interface DirectiveService extends BaseService<D60, Integer>{ |
| 44 | 44 | int send60Dispatch(Long id, String sender); |
| 45 | 45 | |
| 46 | 46 | //60营运指令 |
| 47 | - int send60Operation(String nbbm, int state, int upDown, ScheduleRealInfo sch, String sender); | |
| 47 | + int send60Operation(String nbbm, int state, int upDown, String sender); | |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * |
| ... | ... | @@ -66,7 +66,7 @@ public interface DirectiveService extends BaseService<D60, Integer>{ |
| 66 | 66 | * @param @param upDonw 上下行 0 上行 1 下行 |
| 67 | 67 | * @throws |
| 68 | 68 | */ |
| 69 | - int upDownChange(String nbbm, Integer upDown, String sender); | |
| 69 | + //int upDownChange(String nbbm, Integer upDown, String sender); | |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * |
| ... | ... | @@ -94,7 +94,7 @@ public interface DirectiveService extends BaseService<D60, Integer>{ |
| 94 | 94 | |
| 95 | 95 | int refreshLineFile(String deviceId); |
| 96 | 96 | |
| 97 | - int stateChange(String nbbm, Integer upDown, Integer state, String userName); | |
| 97 | + //int stateChange(String nbbm, Integer upDown, Integer state, String userName); | |
| 98 | 98 | |
| 99 | 99 | Map<String,Object> deviceCofigList(Map<String, String> map, int page, int size); |
| 100 | 100 | } | ... | ... |
src/main/java/com/bsth/service/directive/DirectiveServiceImpl.java
| ... | ... | @@ -188,7 +188,7 @@ public class DirectiveServiceImpl extends BaseServiceImpl<D60, Integer> implemen |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | @Override |
| 191 | - public int send60Operation(String nbbm, int state, int upDown, ScheduleRealInfo sch, String sender) { | |
| 191 | + public int send60Operation(String nbbm, int state, int upDown, String sender) { | |
| 192 | 192 | logger.info("切换运营状态, nbbm: " + nbbm + " ,state: " + state + " ,upDown:" + upDown); |
| 193 | 193 | |
| 194 | 194 | String text = "切换为 " + (upDown == 0 ? "上行" : "下行") + (state == 0 ? "营运" : "未营运"); |
| ... | ... | @@ -204,9 +204,10 @@ public class DirectiveServiceImpl extends BaseServiceImpl<D60, Integer> implemen |
| 204 | 204 | int code = GatewayHttpUtils.postJson(JSON.toJSONString(d60)); |
| 205 | 205 | // 添加到缓存,等待入库 |
| 206 | 206 | d60.setHttpCode(code); |
| 207 | - if (null != sch) | |
| 207 | + /*if (null != sch){ | |
| 208 | 208 | d60.setSch(sch); |
| 209 | - | |
| 209 | + d60.setLineCode(sch.getXlBm()); | |
| 210 | + }*/ | |
| 210 | 211 | |
| 211 | 212 | if (code == 0) { |
| 212 | 213 | dayOfDirectives.put60(d60, true); |
| ... | ... | @@ -294,10 +295,10 @@ public class DirectiveServiceImpl extends BaseServiceImpl<D60, Integer> implemen |
| 294 | 295 | return new DirectiveCreator().createD60(nbbm, text, dispatchInstruct, upDown, state, lineCode); |
| 295 | 296 | } |
| 296 | 297 | |
| 297 | - @Override | |
| 298 | +/* @Override | |
| 298 | 299 | public int upDownChange(String nbbm, Integer upDown, String sender) { |
| 299 | - return send60Operation(nbbm, 0, upDown, null, sender); | |
| 300 | - } | |
| 300 | + return send60Operation(nbbm, 0, upDown, sender); | |
| 301 | + }*/ | |
| 301 | 302 | |
| 302 | 303 | |
| 303 | 304 | @Override |
| ... | ... | @@ -540,10 +541,10 @@ public class DirectiveServiceImpl extends BaseServiceImpl<D60, Integer> implemen |
| 540 | 541 | return GatewayHttpUtils.postJson(new DirectiveCreator().createDeviceRefreshData(deviceId, gps.getLineId())); |
| 541 | 542 | } |
| 542 | 543 | |
| 543 | - @Override | |
| 544 | +/* @Override | |
| 544 | 545 | public int stateChange(String nbbm, Integer upDown, Integer state, String userName) { |
| 545 | - return send60Operation(nbbm, state, upDown, null, userName); | |
| 546 | - } | |
| 546 | + return send60Operation(nbbm, state, upDown, userName); | |
| 547 | + }*/ | |
| 547 | 548 | |
| 548 | 549 | @Override |
| 549 | 550 | public Map<String, Object> deviceCofigList(Map<String, String> map, int page, int size) { | ... | ... |
src/main/java/com/bsth/service/excep/impl/SpeedingServiceImpl.java
| ... | ... | @@ -14,13 +14,11 @@ import java.util.List; |
| 14 | 14 | import java.util.Map; |
| 15 | 15 | |
| 16 | 16 | import org.springframework.jdbc.core.JdbcTemplate; |
| 17 | -import org.springframework.jdbc.core.RowMapper; | |
| 18 | 17 | import org.springframework.stereotype.Service; |
| 19 | 18 | import org.springframework.beans.factory.annotation.Autowired; |
| 20 | 19 | |
| 21 | 20 | import com.bsth.data.BasicData; |
| 22 | 21 | import com.bsth.entity.excep.Speeding; |
| 23 | -import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 24 | 22 | import com.bsth.service.excep.SpeedingService; |
| 25 | 23 | import com.bsth.util.EchartConver; |
| 26 | 24 | import com.bsth.util.PageHelper; |
| ... | ... | @@ -42,7 +40,7 @@ public class SpeedingServiceImpl implements SpeedingService { |
| 42 | 40 | ResultSet rs = null; |
| 43 | 41 | int page=Integer.parseInt(map.get("page").toString()); |
| 44 | 42 | List<Speeding> list=new ArrayList<Speeding>(); |
| 45 | - String sql="select * from bsth_c_speeding where speed > 60 "; | |
| 43 | + String sql="select * from bsth_c_speeding where 1=1 "; | |
| 46 | 44 | Object line=map.get("line"); |
| 47 | 45 | Object nbbm=map.get("nbbm"); |
| 48 | 46 | Object updown=map.get("updown"); |
| ... | ... | @@ -204,22 +202,40 @@ public class SpeedingServiceImpl implements SpeedingService { |
| 204 | 202 | int totalPage;//总页数 |
| 205 | 203 | int totalData = 0; |
| 206 | 204 | if(list.size()>1){ |
| 207 | - Speeding speedingNow;//下标为i的车 | |
| 208 | - Speeding speedingLast;//下标为i-1的车 | |
| 205 | + Speeding speedingNow;//下标为i的车辆行驶记录 | |
| 206 | + Speeding speedingLast;//下标为i-1的车辆行驶记录 | |
| 207 | + Speeding spped = null;//整合后的车辆行驶记录 | |
| 209 | 208 | String strNow; |
| 210 | 209 | String strLast; |
| 210 | + boolean Flag = false;//判断是否有连续超速记录,默认没有 | |
| 211 | 211 | for(int i = 1;i<list.size();i++){ |
| 212 | 212 | speedingNow = list.get(i); |
| 213 | 213 | speedingLast = list.get(i-1); |
| 214 | - strNow = speedingNow.getVehicle()+speedingNow.getLine()+speedingNow.getUpDown();//同一车辆同一线路同一方向 | |
| 214 | + strNow = speedingNow.getVehicle()+speedingNow.getLine()+speedingNow.getUpDown(); | |
| 215 | 215 | strLast = speedingLast.getVehicle()+speedingLast.getLine()+speedingLast.getUpDown(); |
| 216 | - //同一车辆同一线路同一方向并且该记录的超速的开始时间减去上一条超速记录的结束时间小于等于10s,证明该车超速。//PS:祛除数据库中的重复发送数据 | |
| 217 | - if(strNow.equals(strLast) && Math.abs(speedingNow.getTimestamp()-speedingLast.getTimestamp())<=10*1000 && (speedingNow.getTimestamp()-speedingLast.getTimestamp()!=0)){ | |
| 218 | - speedingLast.setEndtimestamp(speedingNow.getTimestamp());//设置结束时间时间戳 | |
| 219 | - speedingLast.setEndtimestampDate(sdf.format(new Date(speedingNow.getTimestamp())));//设置结束时间 | |
| 220 | - speedingLast.setEndlon(speedingNow.getLon());//设置结束时的经度 | |
| 221 | - speedingLast.setEndlat(speedingNow.getLat());//设置结束时的纬度 | |
| 222 | - listResult.add(speedingLast); | |
| 216 | + if(speedingNow.getSpeed()>60 && speedingLast.getSpeed()>60 && strNow.equals(strLast)){//如果两条连续的记录都是超速且属于同一辆车。 | |
| 217 | + if(Flag==false){// | |
| 218 | + spped = new Speeding(); | |
| 219 | + spped.setId(speedingLast.getId());//设置连续超速记录Id | |
| 220 | + spped.setLine(speedingLast.getLine());//设置连续超速记录线路 | |
| 221 | + spped.setLineName(speedingLast.getLineName());//设置连续超速记录线路名称 | |
| 222 | + spped.setVehicle(speedingLast.getVehicle());//设置连续超速记录的车辆编号 | |
| 223 | + spped.setUpDown(speedingLast.getUpDown());//设置上下行 | |
| 224 | + spped.setLon(speedingLast.getLon());//设置开始时经度 | |
| 225 | + spped.setLat(speedingLast.getLat());//设置开始时纬度 | |
| 226 | + spped.setTimestamp(speedingLast.getTimestamp());//设置连续超速记录的开始时间 | |
| 227 | + spped.setTimestampDate(speedingLast.getTimestampDate());//设置连续超速记录的开始时间戳 | |
| 228 | + } | |
| 229 | + spped.setEndtimestamp(speedingNow.getTimestamp());//设置结束时间戳 | |
| 230 | + spped.setEndtimestampDate(sdf.format(new Date(speedingNow.getTimestamp())));//设置结束时间 | |
| 231 | + spped.setEndlon(speedingNow.getLon());//设置结束时的经度 | |
| 232 | + spped.setEndlat(speedingNow.getLat());//设置结束时的纬度 | |
| 233 | + Flag = true; | |
| 234 | + }else{ | |
| 235 | + if(Flag){//如果上一条记录超速。 | |
| 236 | + listResult.add(spped); | |
| 237 | + Flag = false; | |
| 238 | + } | |
| 223 | 239 | } |
| 224 | 240 | } |
| 225 | 241 | Iterator<Speeding> speedIt = listResult.iterator(); | ... | ... |
src/main/java/com/bsth/service/forms/impl/FormsServiceImpl.java
| ... | ... | @@ -1020,19 +1020,19 @@ public class FormsServiceImpl implements FormsService { |
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | 1022 | }); |
| 1023 | - sql = "select name from bsth_c_line where sfyy = 0"; | |
| 1023 | + sql = "select line_code from bsth_c_line where sfyy = 0"; | |
| 1024 | 1024 | List<String> strList = new ArrayList<>(); |
| 1025 | 1025 | strList = jdbcTemplate.query(sql, |
| 1026 | 1026 | new RowMapper<String>(){ |
| 1027 | 1027 | @Override |
| 1028 | 1028 | public String mapRow(ResultSet rs, int rowNum) throws SQLException { |
| 1029 | - return rs.getString("name"); | |
| 1029 | + return rs.getString("line_code"); | |
| 1030 | 1030 | } |
| 1031 | 1031 | }); |
| 1032 | 1032 | lineSet.addAll(strList); |
| 1033 | 1033 | |
| 1034 | 1034 | for(Line line1 : lineList){ |
| 1035 | - if(lineSet.contains(line1.getName())){ | |
| 1035 | + if(lineSet.contains(line1.getLineCode())){ | |
| 1036 | 1036 | continue; |
| 1037 | 1037 | } |
| 1038 | 1038 | if(line.trim().length() == 0 || line1.getLineCode().equals(line)){ | ... | ... |
src/main/java/com/bsth/service/gps/GpsService.java
| ... | ... | @@ -4,6 +4,7 @@ import com.bsth.data.gpsdata.GpsEntity; |
| 4 | 4 | import com.bsth.service.gps.entity.GpsOutbound_DTO; |
| 5 | 5 | import com.bsth.service.gps.entity.GpsSpeed; |
| 6 | 6 | import com.bsth.service.gps.entity.GpsSpeed_DTO; |
| 7 | +import com.bsth.util.PageObject; | |
| 7 | 8 | |
| 8 | 9 | import javax.servlet.http.HttpServletResponse; |
| 9 | 10 | |
| ... | ... | @@ -45,4 +46,6 @@ public interface GpsService { |
| 45 | 46 | |
| 46 | 47 | List<GpsSpeed> findPosition(String deviceid, String startdate, |
| 47 | 48 | String enddate) throws ParseException; |
| 49 | + | |
| 50 | + PageObject<GpsSpeed> Pagequery(Map<String, Object> map); | |
| 48 | 51 | } | ... | ... |
src/main/java/com/bsth/service/gps/GpsServiceImpl.java
| ... | ... | @@ -16,6 +16,8 @@ import com.bsth.repository.StationRepository; |
| 16 | 16 | import com.bsth.repository.realcontrol.ScheduleRealInfoRepository; |
| 17 | 17 | import com.bsth.service.gps.entity.*; |
| 18 | 18 | import com.bsth.util.DateUtils; |
| 19 | +import com.bsth.util.PageHelper; | |
| 20 | +import com.bsth.util.PageObject; | |
| 19 | 21 | import com.bsth.util.TransGPS; |
| 20 | 22 | import com.bsth.util.TransGPS.Location; |
| 21 | 23 | import com.bsth.util.db.DBUtils_MS; |
| ... | ... | @@ -44,6 +46,7 @@ import java.net.URLEncoder; |
| 44 | 46 | import java.sql.Connection; |
| 45 | 47 | import java.sql.PreparedStatement; |
| 46 | 48 | import java.sql.ResultSet; |
| 49 | +import java.sql.SQLException; | |
| 47 | 50 | import java.text.DecimalFormat; |
| 48 | 51 | import java.text.ParseException; |
| 49 | 52 | import java.text.SimpleDateFormat; |
| ... | ... | @@ -152,6 +155,17 @@ public class GpsServiceImpl implements GpsService { |
| 152 | 155 | return (byte) (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0); |
| 153 | 156 | } |
| 154 | 157 | |
| 158 | + /** | |
| 159 | + * 获取运营状态 | |
| 160 | + * | |
| 161 | + * @return -1无效 0运营 1未运营 | |
| 162 | + */ | |
| 163 | + public static byte getService(long serviceState) { | |
| 164 | + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000) | |
| 165 | + return -1; | |
| 166 | + return (byte) (((serviceState & 0x02000000) == 0x02000000) ? 1 : 0); | |
| 167 | + } | |
| 168 | + | |
| 155 | 169 | @Override |
| 156 | 170 | public List<Map<String, Object>> history(String[] nbbmArray, Long st, Long et) { |
| 157 | 171 | List<Map<String, Object>> list = new ArrayList<>(); |
| ... | ... | @@ -239,10 +253,11 @@ public class GpsServiceImpl implements GpsService { |
| 239 | 253 | rs = ps.executeQuery(); |
| 240 | 254 | Float lon, lat; |
| 241 | 255 | Location bdLoc, gdLoc; |
| 242 | - int upDown, inOutStop; | |
| 256 | + int inOutStop; | |
| 257 | + long serviceState; | |
| 243 | 258 | ArrivalEntity arrival; |
| 244 | 259 | while (rs.next()) { |
| 245 | - upDown = getUpOrDown(rs.getLong("SERVICE_STATE")); | |
| 260 | + serviceState = rs.getLong("SERVICE_STATE"); | |
| 246 | 261 | map = new HashMap<>(); |
| 247 | 262 | |
| 248 | 263 | lon = rs.getFloat("LON"); |
| ... | ... | @@ -278,9 +293,9 @@ public class GpsServiceImpl implements GpsService { |
| 278 | 293 | } |
| 279 | 294 | |
| 280 | 295 | map.put("nbbm", BasicData.deviceId2NbbmMap.get(rs.getString("DEVICE_ID"))); |
| 281 | - map.put("state", 0); | |
| 296 | + map.put("state", getService(serviceState)); | |
| 282 | 297 | // 上下行 |
| 283 | - map.put("upDown", upDown); | |
| 298 | + map.put("upDown", getUpOrDown(serviceState)); | |
| 284 | 299 | //路段编码 |
| 285 | 300 | map.put("section_code", rs.getString("SECTION_CODE")); |
| 286 | 301 | list.add(map); |
| ... | ... | @@ -806,7 +821,7 @@ public class GpsServiceImpl implements GpsService { |
| 806 | 821 | @Override |
| 807 | 822 | public List<GpsSpeed_DTO> speeds(String nbbm, long st, long et) { |
| 808 | 823 | String deviceId = BasicData.deviceId2NbbmMap.inverse().get(nbbm); |
| 809 | - String sql = "select vehicle, line, up_down, lon, lat, speed,timestamp from bsth_c_speeding where vehicle=? and timestamp>? and timestamp<?"; | |
| 824 | + String sql = "select vehicle, line, up_down, lon, lat, speed,timestamp from bsth_c_GpsSpeed where vehicle=? and timestamp>? and timestamp<?"; | |
| 810 | 825 | |
| 811 | 826 | return GpsSpeed_DTO.create(new JdbcTemplate(DBUtils_MS.getDataSource()).queryForList(sql, deviceId, st * 1000, et * 1000)); |
| 812 | 827 | } |
| ... | ... | @@ -1036,4 +1051,182 @@ public class GpsServiceImpl implements GpsService { |
| 1036 | 1051 | return listResult; |
| 1037 | 1052 | |
| 1038 | 1053 | } |
| 1054 | + | |
| 1055 | + @Override | |
| 1056 | + public PageObject<GpsSpeed> Pagequery(Map<String, Object> map) { | |
| 1057 | + | |
| 1058 | + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 1059 | + List<GpsSpeed> list=findAll(map); | |
| 1060 | + List<GpsSpeed> listResult = new ArrayList<GpsSpeed>(); | |
| 1061 | + int curPage;//页码 | |
| 1062 | + int pageData;//每页的记录条数 | |
| 1063 | + int start;//起始数据下标 | |
| 1064 | + int totalPage;//总页数 | |
| 1065 | + int totalData = 0; | |
| 1066 | + if(list.size()>1){ | |
| 1067 | + GpsSpeed GpsSpeedNow;//下标为i的车辆行驶记录 | |
| 1068 | + GpsSpeed GpsSpeedLast;//下标为i-1的车辆行驶记录 | |
| 1069 | + GpsSpeed spped = null;//整合后的车辆行驶记录 | |
| 1070 | + String strNow; | |
| 1071 | + String strLast; | |
| 1072 | + boolean Flag = false;//判断是否有连续超速记录,默认没有 | |
| 1073 | + for(int i = 1;i<list.size();i++){ | |
| 1074 | + GpsSpeedNow = list.get(i); | |
| 1075 | + GpsSpeedLast = list.get(i-1); | |
| 1076 | + strNow = GpsSpeedNow.getVehicle()+GpsSpeedNow.getLine()+GpsSpeedNow.getUp_down(); | |
| 1077 | + strLast = GpsSpeedLast.getVehicle()+GpsSpeedLast.getLine()+GpsSpeedLast.getUp_down(); | |
| 1078 | + if(GpsSpeedNow.getSpeed()>60 && GpsSpeedLast.getSpeed()>60 && strNow.equals(strLast)){//如果两条连续的记录都是超速且属于同一辆车。 | |
| 1079 | + if(Flag==false){// | |
| 1080 | + spped = new GpsSpeed(); | |
| 1081 | + spped.setLine(GpsSpeedLast.getLine());//设置连续超速记录线路 | |
| 1082 | + spped.setLineName(GpsSpeedLast.getLineName());//设置连续超速记录线路名称 | |
| 1083 | + spped.setVehicle(GpsSpeedLast.getVehicle());//设置连续超速记录的车辆编号 | |
| 1084 | + spped.setUp_down(GpsSpeedLast.getUp_down());//设置上下行 | |
| 1085 | + spped.setLon(GpsSpeedLast.getLon());//设置开始时经度 | |
| 1086 | + spped.setLat(GpsSpeedLast.getLat());//设置开始时纬度 | |
| 1087 | + spped.setTimestamp(GpsSpeedLast.getTimestamp());//设置连续超速记录的开始时间 | |
| 1088 | + spped.setTimestampDate(GpsSpeedLast.getTimestampDate());//设置连续超速记录的开始时间戳 | |
| 1089 | + } | |
| 1090 | + spped.setEndtimestamp(GpsSpeedNow.getTimestamp());//设置结束时间戳 | |
| 1091 | + spped.setEndtimestampDate(sdf.format(new Date(GpsSpeedNow.getTimestamp())));//设置结束时间 | |
| 1092 | + spped.setEndlon(GpsSpeedNow.getLon());//设置结束时的经度 | |
| 1093 | + spped.setEndlat(GpsSpeedNow.getLat());//设置结束时的纬度 | |
| 1094 | + Flag = true; | |
| 1095 | + }else{ | |
| 1096 | + if(Flag){//如果上一条记录超速。 | |
| 1097 | + listResult.add(spped); | |
| 1098 | + Flag = false; | |
| 1099 | + } | |
| 1100 | + } | |
| 1101 | + } | |
| 1102 | + Iterator<GpsSpeed> speedIt = listResult.iterator(); | |
| 1103 | + while(speedIt.hasNext()){ | |
| 1104 | + GpsSpeed GpsSpeed = speedIt.next(); | |
| 1105 | + if(GpsSpeed.getEndtimestamp()-GpsSpeed.getTimestamp()<=1000){ | |
| 1106 | + speedIt.remove(); | |
| 1107 | + } | |
| 1108 | + } | |
| 1109 | + | |
| 1110 | + totalData = listResult.size();//总记录条数。 | |
| 1111 | + if(map.get("curPage") == null || map.get("curPage").equals("0")){ | |
| 1112 | + curPage = 0; | |
| 1113 | + }else{ | |
| 1114 | + curPage = Integer.parseInt((String) map.get("curPage")); | |
| 1115 | + } | |
| 1116 | + pageData = Integer.parseInt((String) map.get("pageData"));//每页的记录条数 | |
| 1117 | + start = (curPage - 0) * pageData; //起始记录下标。 | |
| 1118 | + totalPage = totalData % pageData == 0 ? totalData / pageData : totalData / pageData +1;//总页数 | |
| 1119 | + if(curPage == totalPage-1){//如果当前页等于总页数。 | |
| 1120 | + listResult = listResult.subList(start, totalData); | |
| 1121 | + }else{ | |
| 1122 | + listResult = listResult.subList(start, start+pageData); | |
| 1123 | + } | |
| 1124 | + }else{ | |
| 1125 | + curPage = 1; | |
| 1126 | + pageData = Integer.parseInt((String) map.get("pageData"));//每页的记录条数 | |
| 1127 | + totalPage =1; | |
| 1128 | + } | |
| 1129 | + Map<String,Object> paramMap = new HashMap<String,Object>(); | |
| 1130 | + paramMap.put("totalPage", totalPage); | |
| 1131 | + paramMap.put("curPage", curPage); | |
| 1132 | + paramMap.put("pageData", pageData); | |
| 1133 | + PageHelper pageHelper = new PageHelper(totalData, paramMap); | |
| 1134 | + pageHelper.getMap(); | |
| 1135 | + PageObject<GpsSpeed> pageObject = pageHelper.getPageObject(); | |
| 1136 | + pageObject.setDataList(listResult); | |
| 1137 | + return pageObject; | |
| 1138 | + } | |
| 1139 | + | |
| 1140 | + static List<GpsSpeed> findAll(Map<String, Object> map) { | |
| 1141 | + Connection conn = null; | |
| 1142 | + PreparedStatement ps = null; | |
| 1143 | + ResultSet rs = null; | |
| 1144 | + int page=Integer.parseInt(map.get("page").toString()); | |
| 1145 | + List<GpsSpeed> list=new ArrayList<GpsSpeed>(); | |
| 1146 | + String sql="select * from bsth_c_gps_info where 1=1 "; | |
| 1147 | + Object line=map.get("line"); | |
| 1148 | + Object nbbm=map.get("nbbm"); | |
| 1149 | + Object updown=map.get("updown"); | |
| 1150 | + Object startDate=map.get("startDate"); | |
| 1151 | + Object endDate=map.get("endDate"); | |
| 1152 | + | |
| 1153 | + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 1154 | + if(line!=null){ | |
| 1155 | + sql +=" and line_id like'%"+line.toString().trim()+"%'"; | |
| 1156 | + } | |
| 1157 | + | |
| 1158 | + if(nbbm!=null){ | |
| 1159 | + nbbm=BasicData.deviceId2NbbmMap.inverse().get(nbbm); | |
| 1160 | + if(nbbm!=null) | |
| 1161 | + sql +=" and vehicle like '%"+nbbm.toString()+"%'"; | |
| 1162 | + } | |
| 1163 | + | |
| 1164 | + if(updown!=null){ | |
| 1165 | + sql +="and industry_code like '%"+updown.toString()+"%'"; | |
| 1166 | + } | |
| 1167 | + if(startDate!=null){ | |
| 1168 | + if (startDate.toString().length()>0) { | |
| 1169 | + try { | |
| 1170 | + Long t1=sdf.parse(startDate.toString()+" 00:00:00").getTime(); | |
| 1171 | + sql += " and ts >="+t1; | |
| 1172 | + } catch (ParseException e) { | |
| 1173 | + e.printStackTrace(); | |
| 1174 | + } | |
| 1175 | + } | |
| 1176 | + | |
| 1177 | + } | |
| 1178 | + if(endDate!=null){ | |
| 1179 | + if (endDate.toString().length()>0) { | |
| 1180 | + try { | |
| 1181 | + Long t2=sdf.parse(endDate.toString()+" 23:59:59").getTime(); | |
| 1182 | + sql += " and ts <="+t2; | |
| 1183 | + } catch (ParseException e) { | |
| 1184 | + e.printStackTrace(); | |
| 1185 | + } | |
| 1186 | + } | |
| 1187 | + | |
| 1188 | + } | |
| 1189 | + | |
| 1190 | + try { | |
| 1191 | + conn = DBUtils_MS.getConnection(); | |
| 1192 | + ps = conn.prepareStatement(sql); | |
| 1193 | + rs = ps.executeQuery(); | |
| 1194 | + list = resultSet2Set(rs); | |
| 1195 | + } catch (SQLException e) { | |
| 1196 | + e.printStackTrace(); | |
| 1197 | + }finally { | |
| 1198 | + DBUtils_MS.close(rs, ps, conn); | |
| 1199 | + } | |
| 1200 | + | |
| 1201 | + return list; | |
| 1202 | + } | |
| 1203 | + | |
| 1204 | + static List<GpsSpeed> resultSet2Set(ResultSet rs) throws SQLException{ | |
| 1205 | + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 1206 | + List<GpsSpeed> list=new ArrayList<GpsSpeed>(); | |
| 1207 | + GpsSpeed GpsSpeed; | |
| 1208 | + Float lon, lat; | |
| 1209 | + Location location; | |
| 1210 | + while(rs.next()){ | |
| 1211 | + lon = rs.getFloat("lon"); | |
| 1212 | + lat = rs.getFloat("lat"); | |
| 1213 | + location = TransGPS.LocationMake(lon, lat); | |
| 1214 | + location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location)); | |
| 1215 | + GpsSpeed=new GpsSpeed(); | |
| 1216 | + GpsSpeed.setLon((float)location.getLng()); | |
| 1217 | + GpsSpeed.setLat((float)location.getLat()); | |
| 1218 | + GpsSpeed.setLine(rs.getObject("line_id").toString()); | |
| 1219 | + //run 时注解 | |
| 1220 | + GpsSpeed.setLineName(BasicData.lineCode2NameMap.get(GpsSpeed.getLine().toString())); | |
| 1221 | + GpsSpeed.setSpeed(Float.valueOf(rs.getObject("speed_gps").toString())); | |
| 1222 | + GpsSpeed.setTimestamp((Long.valueOf(rs.getObject("ts").toString()))); | |
| 1223 | + GpsSpeed.setTimestampDate(sdf.format(new Date(GpsSpeed.getTimestamp()))); | |
| 1224 | + GpsSpeed.setUp_down(((Integer.valueOf(rs.getObject("service_state").toString())) & 0x10000000)==0?0:1); | |
| 1225 | + GpsSpeed.setVehicle(BasicData.deviceId2NbbmMap.get(rs.getObject("device_id").toString())); | |
| 1226 | + list.add(GpsSpeed); | |
| 1227 | + } | |
| 1228 | + return list; | |
| 1229 | + } | |
| 1230 | + | |
| 1039 | 1231 | } |
| 1232 | + | ... | ... |
src/main/java/com/bsth/service/gps/entity/GpsSpeed.java
| 1 | 1 | package com.bsth.service.gps.entity; |
| 2 | 2 | |
| 3 | +import javax.persistence.Transient; | |
| 4 | + | |
| 3 | 5 | /** |
| 4 | 6 | * 超速异常 -ms数据库格式 |
| 5 | 7 | * Created by panzhao on 2017/4/7. |
| ... | ... | @@ -15,11 +17,59 @@ public class GpsSpeed { |
| 15 | 17 | private float lon; |
| 16 | 18 | |
| 17 | 19 | private float lat; |
| 20 | + | |
| 21 | + private String lineName; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 超速结束时的纬度 | |
| 25 | + */ | |
| 26 | + @Transient | |
| 27 | + private Float endlat; | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * 超速结束时的经度 | |
| 31 | + */ | |
| 32 | + @Transient | |
| 33 | + private Float endlon; | |
| 18 | 34 | |
| 19 | 35 | private float speed; |
| 20 | - | |
| 36 | + | |
| 21 | 37 | private long timestamp; |
| 22 | - | |
| 38 | + | |
| 39 | + @Transient | |
| 40 | + private String timestampDate; | |
| 41 | + | |
| 42 | + public String getTimestampDate() { | |
| 43 | + return timestampDate; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public void setTimestampDate(String timestampDate) { | |
| 47 | + this.timestampDate = timestampDate; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public Long getEndtimestamp() { | |
| 51 | + return endtimestamp; | |
| 52 | + } | |
| 53 | + | |
| 54 | + public void setEndtimestamp(Long endtimestamp) { | |
| 55 | + this.endtimestamp = endtimestamp; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public String getEndtimestampDate() { | |
| 59 | + return endtimestampDate; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public void setEndtimestampDate(String endtimestampDate) { | |
| 63 | + this.endtimestampDate = endtimestampDate; | |
| 64 | + } | |
| 65 | + | |
| 66 | + //结束时间,单位:秒/s | |
| 67 | + @Transient | |
| 68 | + private Long endtimestamp; | |
| 69 | + | |
| 70 | + @Transient | |
| 71 | + private String endtimestampDate; | |
| 72 | + | |
| 23 | 73 | public String getVehicle() { |
| 24 | 74 | return vehicle; |
| 25 | 75 | } |
| ... | ... | @@ -75,4 +125,28 @@ public class GpsSpeed { |
| 75 | 125 | public void setTimestamp(long timestamp) { |
| 76 | 126 | this.timestamp = timestamp; |
| 77 | 127 | } |
| 128 | + | |
| 129 | + public Float getEndlon() { | |
| 130 | + return endlon; | |
| 131 | + } | |
| 132 | + | |
| 133 | + public void setEndlon(Float endlon) { | |
| 134 | + this.endlon = endlon; | |
| 135 | + } | |
| 136 | + | |
| 137 | + public Float getEndlat() { | |
| 138 | + return endlat; | |
| 139 | + } | |
| 140 | + | |
| 141 | + public void setEndlat(Float endlat) { | |
| 142 | + this.endlat = endlat; | |
| 143 | + } | |
| 144 | + | |
| 145 | + public String getLineName() { | |
| 146 | + return lineName; | |
| 147 | + } | |
| 148 | + | |
| 149 | + public void setLineName(String lineName) { | |
| 150 | + this.lineName = lineName; | |
| 151 | + } | |
| 78 | 152 | } | ... | ... |
src/main/java/com/bsth/service/report/impl/CulateMileageServiceImpl.java
| ... | ... | @@ -738,6 +738,7 @@ public class CulateMileageServiceImpl implements CulateMileageService{ |
| 738 | 738 | // TODO Auto-generated method stub |
| 739 | 739 | double ljjcc=0.0; |
| 740 | 740 | double ljyy=0.0; |
| 741 | + double ljkfks=0.0; | |
| 741 | 742 | for (int i = 0; i < lists.size(); i++) { |
| 742 | 743 | ScheduleRealInfo t=lists.get(i); |
| 743 | 744 | if(t.isSflj()){ |
| ... | ... | @@ -760,6 +761,24 @@ public class CulateMileageServiceImpl implements CulateMileageService{ |
| 760 | 761 | }*/ |
| 761 | 762 | } |
| 762 | 763 | |
| 764 | + if(t.getBcType().equals("ldks")){ | |
| 765 | + Set<ChildTaskPlan> childTaskPlans = t.getcTasks(); | |
| 766 | + if(childTaskPlans.isEmpty()){ | |
| 767 | + if(!t.isDestroy()){ | |
| 768 | + ljkfks =Arith.add(ljkfks, t.getJhlc()); | |
| 769 | + } | |
| 770 | + | |
| 771 | + } | |
| 772 | + /*else{ | |
| 773 | + //临加进出场子任务 待统计 | |
| 774 | + Iterator<ChildTaskPlan> it = childTaskPlans.iterator(); | |
| 775 | + double zrwlc=0.0; | |
| 776 | + boolean fage=false; | |
| 777 | + while (it.hasNext()) { | |
| 778 | + ChildTaskPlan childTaskPlan = it.next(); | |
| 779 | + } | |
| 780 | + }*/ | |
| 781 | + } | |
| 763 | 782 | if(!isInOut(t)){ |
| 764 | 783 | Set<ChildTaskPlan> childTaskPlans = t.getcTasks(); |
| 765 | 784 | if(childTaskPlans.isEmpty()){ |
| ... | ... | @@ -774,6 +793,14 @@ public class CulateMileageServiceImpl implements CulateMileageService{ |
| 774 | 793 | if(childTaskPlan.getMileageType().equals("service")){ |
| 775 | 794 | ljyy =Arith.add(ljyy,childTaskPlan.getMileage()); |
| 776 | 795 | } |
| 796 | + if(childTaskPlan.getMileageType().equals("empty")){ | |
| 797 | + if(childTaskPlan.getType2().equals("2")||childTaskPlan.getType2().equals("3")){ | |
| 798 | + ljjcc =Arith.add(ljjcc, childTaskPlan.getMileage()); | |
| 799 | + } | |
| 800 | + if(childTaskPlan.getType2().equals("1")){ | |
| 801 | + ljkfks =Arith.add(ljkfks, childTaskPlan.getMileage()); | |
| 802 | + } | |
| 803 | + } | |
| 777 | 804 | } |
| 778 | 805 | } |
| 779 | 806 | } |
| ... | ... | @@ -784,6 +811,7 @@ public class CulateMileageServiceImpl implements CulateMileageService{ |
| 784 | 811 | Map<String, Double> map=new HashMap<String,Double>(); |
| 785 | 812 | map.put("ljjcc", ljjcc); |
| 786 | 813 | map.put("ljyy", ljyy); |
| 814 | + map.put("ljkfks", ljkfks); | |
| 787 | 815 | return map; |
| 788 | 816 | } |
| 789 | 817 | |
| ... | ... | @@ -858,20 +886,32 @@ public class CulateMileageServiceImpl implements CulateMileageService{ |
| 858 | 886 | double zrwjcclc=0.0; |
| 859 | 887 | for (int i = 0; i < lists.size(); i++) { |
| 860 | 888 | ScheduleRealInfo t=lists.get(i); |
| 861 | - if(!isInOut(t)){ | |
| 862 | - Set<ChildTaskPlan> childTaskPlans = t.getcTasks(); | |
| 863 | - if(!childTaskPlans.isEmpty()){ | |
| 864 | - Iterator<ChildTaskPlan> it = childTaskPlans.iterator(); | |
| 865 | - while (it.hasNext()) { | |
| 866 | - ChildTaskPlan childTaskPlan = it.next(); | |
| 867 | - if(childTaskPlan.getType2().equals("2")||childTaskPlan.getType2().equals("3")){ | |
| 868 | - if (childTaskPlan.isDestroy()) { | |
| 869 | - if(childTaskPlan.getReason().equals(item)){ | |
| 870 | - zrwjcclc=Arith.add(zrwjcclc,childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage()); | |
| 871 | - } | |
| 872 | - } | |
| 873 | - } | |
| 874 | - } | |
| 889 | + if(!t.isSflj()){ | |
| 890 | + if(!isInOut(t)){ | |
| 891 | + Set<ChildTaskPlan> childTaskPlans = t.getcTasks(); | |
| 892 | + if(!childTaskPlans.isEmpty()){ | |
| 893 | + Iterator<ChildTaskPlan> it = childTaskPlans.iterator(); | |
| 894 | + while (it.hasNext()) { | |
| 895 | + ChildTaskPlan childTaskPlan = it.next(); | |
| 896 | + if(item.equals("空放")){ | |
| 897 | + if(childTaskPlan.getType2().equals("1")){ | |
| 898 | + if (!childTaskPlan.isDestroy()) { | |
| 899 | + if(childTaskPlan.getReason().equals(item)){ | |
| 900 | + zrwjcclc=Arith.add(zrwjcclc,childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage()); | |
| 901 | + } | |
| 902 | + } | |
| 903 | + } | |
| 904 | + }else{ | |
| 905 | + if(childTaskPlan.getType2().equals("2")||childTaskPlan.getType2().equals("3")){ | |
| 906 | + if (!childTaskPlan.isDestroy()) { | |
| 907 | + if(childTaskPlan.getReason().equals(item)){ | |
| 908 | + zrwjcclc=Arith.add(zrwjcclc,childTaskPlan.getMileage()==null?0:childTaskPlan.getMileage()); | |
| 909 | + } | |
| 910 | + } | |
| 911 | + } | |
| 912 | + } | |
| 913 | + } | |
| 914 | + } | |
| 875 | 915 | } |
| 876 | 916 | } |
| 877 | 917 | } | ... | ... |
src/main/java/com/bsth/service/report/impl/ReportServiceImpl.java
| ... | ... | @@ -37,6 +37,10 @@ import java.util.*; |
| 37 | 37 | @Service |
| 38 | 38 | public class ReportServiceImpl implements ReportService{ |
| 39 | 39 | |
| 40 | + private static long zgf1 = 6 * 60 + 31, | |
| 41 | + zgf2 = 8 * 60 + 30, | |
| 42 | + wgf1 = 16 * 60 + 1, | |
| 43 | + wgf2 = 18 * 60; | |
| 40 | 44 | |
| 41 | 45 | private Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 42 | 46 | |
| ... | ... | @@ -466,38 +470,35 @@ public class ReportServiceImpl implements ReportService{ |
| 466 | 470 | System.out.println(609360/60); |
| 467 | 471 | System.out.println(609360%60); |
| 468 | 472 | } |
| 469 | - @Override | |
| 473 | +/* @Override | |
| 470 | 474 | public List<Map<String, Object>> tbodyTime3(String line, String ttinfo) { |
| 471 | 475 | // TODO Auto-generated method stub |
| 472 | 476 | List<Map<String, Object>> list=new ArrayList<Map<String,Object>>(); |
| 473 | 477 | |
| 474 | 478 | |
| 475 | 479 | |
| 476 | - String sqlZd=" select t.*,x.station_name as qdz_name from (" | |
| 477 | - + " select qdz,count(lp) as cls,lx from ( select qdz,lp, 'zqc' as lx " | |
| 478 | - + " from bsth_c_s_ttinfo_detail where " | |
| 479 | - + " bc_type='normal' and ttinfo ='"+ttinfo+"' " | |
| 480 | - + " and fcsj>'06:31' and fcsj<'08:00' group by qdz,lp) t1" | |
| 481 | - + " group by qdz " | |
| 480 | + String sqlZd="select a.qdz_name,COUNT(a.cl_zbh) as cls,'zqc' AS lx from (" | |
| 481 | + + " select cl_zbh,qdz_name from bsth_c_s_sp_info where tt_info ='"+ttinfo+"' " | |
| 482 | + + " and bc_type ='normal'" | |
| 483 | + + " and ((fcsj >'06:31' and fcsj<'08:30') or ( fcsj>'6:31' and fcsj<'8:30'))" | |
| 484 | + + " group by cl_zbh,qdz_name) a group by a.qdz_name" | |
| 482 | 485 | + " union " |
| 483 | - + " select qdz,count(lp) as cls,lx from ( select qdz,lp, 'wqc' as lx " | |
| 484 | - + " from bsth_c_s_ttinfo_detail where " | |
| 485 | - + " bc_type='normal' and ttinfo ='"+ttinfo+"' " | |
| 486 | - + " and fcsj>'16:01' and fcsj<'18:00' group by qdz,lp) t2" | |
| 487 | - + " group by qdz " | |
| 486 | + + " select a.qdz_name,COUNT(a.cl_zbh) as cls,'wqc' AS lx from (" | |
| 487 | + + " select cl_zbh,qdz_name from bsth_c_s_sp_info where tt_info ='"+ttinfo+"'" | |
| 488 | + + " and bc_type ='normal' " | |
| 489 | + + " and fcsj >'16:01' and fcsj<'18:00' group by cl_zbh,qdz_name " | |
| 490 | + + " ) a group by a.qdz_name " | |
| 488 | 491 | + " union " |
| 489 | - + " select qdz,count(lp) as cls,lx from ( select qdz,lp, 'zqj' as lx " | |
| 490 | - + " from bsth_c_s_ttinfo_detail where " | |
| 491 | - + " bc_type='region' and ttinfo ='"+ttinfo+"' " | |
| 492 | - + " and fcsj>'06:31' and fcsj<'08:00' group by qdz,lp) t3" | |
| 493 | - + " group by qdz " | |
| 492 | + + " select a.qdz_name,COUNT(a.cl_zbh) as cls,'zqj' AS lx from (" | |
| 493 | + + " select cl_zbh,qdz_name from bsth_c_s_sp_info where tt_info ='"+ttinfo+"'" | |
| 494 | + + " and bc_type ='region' " | |
| 495 | + + " and ((fcsj >'06:31' and fcsj<'08:30') or ( fcsj>'6:31' and fcsj<'8:30'))" | |
| 496 | + + " group by cl_zbh,qdz_name) a group by a.qdz_name" | |
| 494 | 497 | + " union " |
| 495 | - + " select qdz,count(lp) as cls,lx from ( select qdz,lp, 'wqj' as lx " | |
| 496 | - + " from bsth_c_s_ttinfo_detail where " | |
| 497 | - + " bc_type='region' and ttinfo ='"+ttinfo+"' " | |
| 498 | - + " and fcsj>'16:01' and fcsj<'18:00' group by qdz,lp) t4" | |
| 499 | - + " group by qdz ) t left join bsth_c_station x on t.qdz=x.id"; | |
| 500 | - | |
| 498 | + + " select a.qdz_name,COUNT(a.cl_zbh) as cls,'wqj' AS lx from (" | |
| 499 | + + " select cl_zbh,qdz_name from bsth_c_s_sp_info where tt_info ='"+ttinfo+"'" | |
| 500 | + + " and bc_type ='region' and fcsj >'16:01' and fcsj<'18:00'" | |
| 501 | + + " group by cl_zbh,qdz_name) a group by a.qdz_name"; | |
| 501 | 502 | List<Map<String, Object>> lists= jdbcTemplate.query(sqlZd, |
| 502 | 503 | new RowMapper<Map<String, Object>>(){ |
| 503 | 504 | @Override |
| ... | ... | @@ -556,6 +557,208 @@ public class ReportServiceImpl implements ReportService{ |
| 556 | 557 | |
| 557 | 558 | } |
| 558 | 559 | return list; |
| 560 | + }*/ | |
| 561 | + @Override | |
| 562 | + public List<Map<String, Object>> tbodyTime3(String line, String ttinfo) { | |
| 563 | + // TODO Auto-generated method stub | |
| 564 | + List<Map<String, Object>> list=new ArrayList<Map<String,Object>>(); | |
| 565 | + List<Map<String, Object>> list_s=new ArrayList<Map<String,Object>>(); | |
| 566 | + | |
| 567 | + | |
| 568 | + /*String sqlZd="select a.qdz_name,COUNT(a.cl_zbh) as cls,'zqc' AS lx from (" | |
| 569 | + + " select cl_zbh,qdz_name from bsth_c_s_sp_info where tt_info ='"+ttinfo+"' " | |
| 570 | + + " and bc_type ='normal'" | |
| 571 | + + " and ((fcsj >'06:31' and fcsj<'08:30') or ( fcsj>'6:31' and fcsj<'8:30'))" | |
| 572 | + + " group by cl_zbh,qdz_name) a group by a.qdz_name" | |
| 573 | + + " union " | |
| 574 | + + " select a.qdz_name,COUNT(a.cl_zbh) as cls,'wqc' AS lx from (" | |
| 575 | + + " select cl_zbh,qdz_name from bsth_c_s_sp_info where tt_info ='"+ttinfo+"'" | |
| 576 | + + " and bc_type ='normal' " | |
| 577 | + + " and fcsj >'16:01' and fcsj<'18:00' group by cl_zbh,qdz_name " | |
| 578 | + + " ) a group by a.qdz_name " | |
| 579 | + + " union " | |
| 580 | + + " select a.qdz_name,COUNT(a.cl_zbh) as cls,'zqj' AS lx from (" | |
| 581 | + + " select cl_zbh,qdz_name from bsth_c_s_sp_info where tt_info ='"+ttinfo+"'" | |
| 582 | + + " and bc_type ='region' " | |
| 583 | + + " and ((fcsj >'06:31' and fcsj<'08:30') or ( fcsj>'6:31' and fcsj<'8:30'))" | |
| 584 | + + " group by cl_zbh,qdz_name) a group by a.qdz_name" | |
| 585 | + + " union " | |
| 586 | + + " select a.qdz_name,COUNT(a.cl_zbh) as cls,'wqj' AS lx from (" | |
| 587 | + + " select cl_zbh,qdz_name from bsth_c_s_sp_info where tt_info ='"+ttinfo+"'" | |
| 588 | + + " and bc_type ='region' and fcsj >'16:01' and fcsj<'18:00'" | |
| 589 | + + " group by cl_zbh,qdz_name) a group by a.qdz_name";*/ | |
| 590 | + | |
| 591 | + String sqlCl="SELECT cl_zbh,qdz_name,bc_type,fcsj,bcsj FROM" | |
| 592 | + + " bsth_c_s_sp_info WHERE tt_info = '"+ttinfo+"' " | |
| 593 | + + " AND bc_type = 'normal' order by qdz_name"; | |
| 594 | + | |
| 595 | + List<Map<String, Object>> listj= jdbcTemplate.query(sqlCl, | |
| 596 | + new RowMapper<Map<String, Object>>(){ | |
| 597 | + @Override | |
| 598 | + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { | |
| 599 | + Map<String, Object> m=new HashMap<String,Object>(); | |
| 600 | + m.put("cl_zbh", rs.getString("cl_zbh")); | |
| 601 | + m.put("qdz_name", rs.getString("qdz_name")); | |
| 602 | + m.put("bcType", rs.getString("bc_type")); | |
| 603 | + m.put("fcsj", rs.getString("fcsj")); | |
| 604 | + m.put("bcsj", rs.getString("bcsj")); | |
| 605 | + return m; | |
| 606 | + } | |
| 607 | + }); | |
| 608 | + | |
| 609 | + String sqlZd="select qdz_name ,bc_type from bsth_c_s_sp_info WHERE tt_info = '"+ttinfo+"' " | |
| 610 | + + " AND (bc_type = 'normal' or bc_type='region') group by qdz_name ,bc_type " | |
| 611 | + + " order by qdz_name"; | |
| 612 | + List<Map<String, Object>> lists= jdbcTemplate.query(sqlZd, | |
| 613 | + new RowMapper<Map<String, Object>>(){ | |
| 614 | + @Override | |
| 615 | + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { | |
| 616 | + Map<String, Object> m=new HashMap<String,Object>(); | |
| 617 | + m.put("zdm", rs.getString("qdz_name")); | |
| 618 | + m.put("bcType", rs.getString("bc_type")); | |
| 619 | + return m; | |
| 620 | + } | |
| 621 | + }); | |
| 622 | + | |
| 623 | + for (int i = 0; i < lists.size(); i++) { | |
| 624 | + Map<String, Object> z=new HashMap<String,Object>(); | |
| 625 | + Map<String, Object> w=new HashMap<String,Object>(); | |
| 626 | + Map<String, Object> p=lists.get(i); | |
| 627 | + int zbcs=0; | |
| 628 | + int wbcs=0; | |
| 629 | + if(p.get("bcType").toString().equals("normal")){ | |
| 630 | + for (int j = 0; j < listj.size(); j++) { | |
| 631 | + if(listj.get(j).get("qdz_name").toString().equals(p.get("zdm").toString()) && | |
| 632 | + listj.get(j).get("bcType").toString().equals("normal")){ | |
| 633 | + String time=listj.get(j).get("fcsj").toString(); | |
| 634 | + long bcsj= Long.parseLong(listj.get(j).get("bcsj").toString()); | |
| 635 | + String clZbh=listj.get(j).get("cl_zbh").toString(); | |
| 636 | + String[] fcsjStr = time.split(":"); | |
| 637 | + long fcsj= Long.parseLong(fcsjStr[0])*60+Long.parseLong(fcsjStr[1]); | |
| 638 | + long ddsj=fcsj+bcsj; | |
| 639 | + if((fcsj>=zgf1 && fcsj<=zgf2) || (ddsj>=zgf1&&ddsj<=zgf2) | |
| 640 | + || (fcsj<zgf1&&ddsj>zgf2)){ | |
| 641 | + if(p.get("z"+clZbh)==null){ | |
| 642 | + zbcs++; | |
| 643 | + p.put("z"+clZbh, clZbh); | |
| 644 | + } | |
| 645 | + } | |
| 646 | + | |
| 647 | + if((fcsj>=wgf1 && fcsj<=wgf2) || (ddsj>=wgf1&&ddsj<=wgf2) | |
| 648 | + || (fcsj<wgf1&&ddsj>wgf2)){ | |
| 649 | + if(p.get("w"+clZbh)==null){ | |
| 650 | + wbcs++; | |
| 651 | + p.put("w"+clZbh, clZbh); | |
| 652 | + } | |
| 653 | + } | |
| 654 | + } | |
| 655 | + | |
| 656 | + } | |
| 657 | + if(zbcs>0){ | |
| 658 | + z.put("zdm", p.get("zdm")); | |
| 659 | + z.put("cls", zbcs); | |
| 660 | + z.put("lx", "zqc"); | |
| 661 | + list_s.add(z); | |
| 662 | + } | |
| 663 | + if(wbcs>0){ | |
| 664 | + w.put("zdm", p.get("zdm")); | |
| 665 | + w.put("cls", zbcs); | |
| 666 | + w.put("lx", "wqc"); | |
| 667 | + list_s.add(w); | |
| 668 | + } | |
| 669 | + | |
| 670 | + } | |
| 671 | + | |
| 672 | + if(p.get("bcType").equals("region")){ | |
| 673 | + for (int j = 0; j < listj.size(); j++) { | |
| 674 | + if(listj.get(j).get("qdz_name").toString().equals(p.get("zdm").toString()) && | |
| 675 | + listj.get(j).get("bcType").toString().equals("region")){ | |
| 676 | + String time=listj.get(j).get("fcsj").toString(); | |
| 677 | + long bcsj= Long.parseLong(listj.get(j).get("bcsj").toString()); | |
| 678 | + String clZbh=listj.get(j).get("cl_zbh").toString(); | |
| 679 | + String[] fcsjStr = time.split(":"); | |
| 680 | + long fcsj= Long.parseLong(fcsjStr[0])*60+Long.parseLong(fcsjStr[1]); | |
| 681 | + long ddsj=fcsj+bcsj; | |
| 682 | + if((fcsj>=zgf1 && fcsj<=zgf2) || (ddsj>=zgf1&&ddsj<=zgf2) | |
| 683 | + || (fcsj<zgf1&&ddsj>zgf2)){ | |
| 684 | + if(p.get("z"+clZbh)==null){ | |
| 685 | + zbcs++; | |
| 686 | + p.put("z"+clZbh, clZbh); | |
| 687 | + } | |
| 688 | + } | |
| 689 | + | |
| 690 | + if((fcsj>=wgf1 && fcsj<=wgf2) || (ddsj>=wgf1&&ddsj<=wgf2) | |
| 691 | + || (fcsj<wgf1&&ddsj>wgf2)){ | |
| 692 | + if(p.get("w"+clZbh)==null){ | |
| 693 | + wbcs++; | |
| 694 | + p.put("w"+clZbh, clZbh); | |
| 695 | + } | |
| 696 | + } | |
| 697 | + } | |
| 698 | + | |
| 699 | + } | |
| 700 | + if(zbcs>0){ | |
| 701 | + z.put("zdm", p.get("zdm")); | |
| 702 | + z.put("cls", zbcs); | |
| 703 | + z.put("lx", "zqj"); | |
| 704 | + list_s.add(z); | |
| 705 | + } | |
| 706 | + if(wbcs>0){ | |
| 707 | + w.put("zdm", p.get("zdm")); | |
| 708 | + w.put("cls", zbcs); | |
| 709 | + w.put("lx", "wqj"); | |
| 710 | + list_s.add(w); | |
| 711 | + } | |
| 712 | + } | |
| 713 | + | |
| 714 | + } | |
| 715 | + int a=0; | |
| 716 | + int b=0; | |
| 717 | + int c=0; | |
| 718 | + int d=0; | |
| 719 | + for(int i=0;i<list_s.size();i++){ | |
| 720 | + boolean fage=true; | |
| 721 | + Map<String, Object> newMap= new HashMap<String, Object>(); | |
| 722 | + list.add(newMap); | |
| 723 | + Map<String, Object> maps=list_s.get(i); | |
| 724 | + if(maps.get("lx").equals("zqc")){ | |
| 725 | + list.get(a).put("zqcZm", maps.get("zdm")); | |
| 726 | + list.get(a).put("zqcCls", maps.get("cls")); | |
| 727 | + a++; | |
| 728 | + fage=false; | |
| 729 | + }else if(maps.get("lx").equals("wqc")){ | |
| 730 | + list.get(b).put("wqcZm", maps.get("zdm")); | |
| 731 | + list.get(b).put("wqcCls", maps.get("cls")); | |
| 732 | + b++; | |
| 733 | + fage=false; | |
| 734 | + }else if(maps.get("lx").equals("zqj")){ | |
| 735 | + list.get(c).put("zqjZm", maps.get("zdm")); | |
| 736 | + list.get(c).put("zqjCls", maps.get("cls")); | |
| 737 | + c++; | |
| 738 | + fage=false; | |
| 739 | + }else if(maps.get("lx").equals("wqj")){ | |
| 740 | + list.get(d).put("wqjZm", maps.get("zdm")); | |
| 741 | + list.get(d).put("wqjCls", maps.get("cls")); | |
| 742 | + d++; | |
| 743 | + fage=false; | |
| 744 | + } | |
| 745 | + if(fage){ | |
| 746 | + break; | |
| 747 | + } | |
| 748 | + } | |
| 749 | + boolean status=true; | |
| 750 | + while (status) { | |
| 751 | + for (int i = 0; i < list.size(); i++) { | |
| 752 | + if(list.get(i).isEmpty()){ | |
| 753 | + list.remove(i); | |
| 754 | + status=true; | |
| 755 | + }else{ | |
| 756 | + status=false; | |
| 757 | + } | |
| 758 | + } | |
| 759 | + | |
| 760 | + } | |
| 761 | + return list; | |
| 559 | 762 | } |
| 560 | 763 | |
| 561 | 764 | @Override |
| ... | ... | @@ -1501,11 +1704,18 @@ public class ReportServiceImpl implements ReportService{ |
| 1501 | 1704 | Map<String, Object> m = new HashMap<String, Object>(); |
| 1502 | 1705 | m.put("date", date); |
| 1503 | 1706 | m.put("date1", date2); |
| 1707 | + String by=map.get("by").toString(); | |
| 1708 | + String xls=""; | |
| 1709 | + if(by.equals("sj")){ | |
| 1710 | + xls="countByLine.xls"; | |
| 1711 | + }else{ | |
| 1712 | + xls="countByLines.xls"; | |
| 1713 | + } | |
| 1504 | 1714 | ReportUtils ee = new ReportUtils(); |
| 1505 | 1715 | try { |
| 1506 | 1716 | listI.add(lMap.iterator()); |
| 1507 | 1717 | String path = this.getClass().getResource("/").getPath() + "static/pages/forms/"; |
| 1508 | - ee.excelReplace(listI, new Object[]{m}, path + "mould/countByLine.xls", | |
| 1718 | + ee.excelReplace(listI, new Object[]{m}, path + "mould/"+xls, | |
| 1509 | 1719 | path + "export/线路公里统计表.xls"); |
| 1510 | 1720 | } catch (Exception e) { |
| 1511 | 1721 | // TODO: handle exception |
| ... | ... | @@ -1572,9 +1782,12 @@ public class ReportServiceImpl implements ReportService{ |
| 1572 | 1782 | Map<String, Double> culateLjMile=culateService.culateLjMile(lists); |
| 1573 | 1783 | double ljyy=culateLjMile.get("ljyy"); |
| 1574 | 1784 | double ljjcc=culateLjMile.get("ljjcc"); |
| 1785 | + double ljkfks=culateLjMile.get("ljkfks"); | |
| 1575 | 1786 | map.put("ljyy", ljyy); |
| 1576 | 1787 | map.put("ljjcc", ljjcc); |
| 1577 | - double ljlc=Arith.add(ljyy, ljjcc); | |
| 1788 | + map.put("ljkfks", ljkfks); | |
| 1789 | + | |
| 1790 | + double ljlc=Arith.add(Arith.add(ljyy, ljjcc),ljkfks); | |
| 1578 | 1791 | |
| 1579 | 1792 | double lbss=culateService.culateSsMile(list);//烂班少驶 |
| 1580 | 1793 | map.put("lbss", lbss); |
| ... | ... | @@ -1594,18 +1807,18 @@ public class ReportServiceImpl implements ReportService{ |
| 1594 | 1807 | double zrwjcclc=culateService.culateZrwJccLc(list, "故障"); |
| 1595 | 1808 | double zrwjcclc1=culateService.culateZrwJccLc(list, "肇事"); |
| 1596 | 1809 | double zrwjcclc2=culateService.culateZrwJccLc(list, "纠纷"); |
| 1810 | + double zrwjcclcqt=culateService.culateZrwJccLc(list, "其他"); | |
| 1811 | + map.put("jhwjcclc_z", Arith.add(jhwjcclc,zrwjcclcqt)); | |
| 1597 | 1812 | map.put("zrwjcclc", zrwjcclc); |
| 1598 | 1813 | map.put("zrwjcclc1", zrwjcclc1); |
| 1599 | 1814 | map.put("zrwjcclc2", zrwjcclc2); |
| 1600 | - double zrwjcc=Arith.add(Arith.add(zrwjcclc, zrwjcclc1), zrwjcclc2); | |
| 1601 | - double kfks=culateService.culateKfksLc(lists); | |
| 1815 | + map.put("zrwjcclcqt", zrwjcclcqt); | |
| 1816 | + double zrwjcc=Arith.add(Arith.add(Arith.add(zrwjcclc, zrwjcclc1), zrwjcclc2),zrwjcclcqt); | |
| 1817 | + double kfks=Arith.add(culateService.culateKfksLc(lists),culateService.culateZrwJccLc(list, "空放")); | |
| 1602 | 1818 | map.put("kfks", kfks); |
| 1603 | 1819 | double zlc=Arith.add(Arith.add(Arith.add(zrwjcc, ljlc), |
| 1604 | 1820 | Arith.add(zjcclc, zyylc)),kfks); |
| 1605 | - | |
| 1606 | - | |
| 1607 | 1821 | map.put("zlc", zlc); |
| 1608 | - | |
| 1609 | 1822 | } |
| 1610 | 1823 | return map; |
| 1611 | 1824 | } |
| ... | ... | @@ -1830,10 +2043,22 @@ public class ReportServiceImpl implements ReportService{ |
| 1830 | 2043 | m.put("date", date); |
| 1831 | 2044 | m.put("date1", date2); |
| 1832 | 2045 | String xls=""; |
| 2046 | + String by=map.get("by").toString(); | |
| 2047 | + | |
| 2048 | + | |
| 1833 | 2049 | if(zt.equals("zbh")){ |
| 1834 | - xls="countByBus1.xls"; | |
| 2050 | + if(by.equals("sj")){ | |
| 2051 | + xls="countByBus1.xls"; | |
| 2052 | + }else{ | |
| 2053 | + xls="countByBus1s.xls"; | |
| 2054 | + } | |
| 1835 | 2055 | }else{ |
| 1836 | - xls="countByBus2.xls"; | |
| 2056 | + | |
| 2057 | + if(by.equals("sj")){ | |
| 2058 | + xls="countByBus2.xls"; | |
| 2059 | + }else{ | |
| 2060 | + xls="countByBus2s.xls"; | |
| 2061 | + } | |
| 1837 | 2062 | } |
| 1838 | 2063 | ReportUtils ee = new ReportUtils(); |
| 1839 | 2064 | try { |
| ... | ... | @@ -1896,7 +2121,8 @@ public class ReportServiceImpl implements ReportService{ |
| 1896 | 2121 | String jGh= m.get("jGh")==null?"":m.get("jGh").toString(); |
| 1897 | 2122 | String sGh= m.get("sGh")==null?"":m.get("sGh").toString(); |
| 1898 | 2123 | double jhzlc = 0.0,jhlc= 0.0,jcclc= 0.0,zlc= 0.0,jhnlc= 0.0,jhwlc= 0.0, |
| 1899 | - jhnjcclc= 0.0,jhwjcclc= 0.0,zrwjcclc= 0.0,lbss= 0.0,ssgl_lz= 0.0, | |
| 2124 | + jhnjcclc= 0.0,jhwjcclc= 0.0,jhwjcclc_z=0.0,zrwjcclc= 0.0,zrwjcclc1= 0.0,zrwjcclc2= 0.0, | |
| 2125 | + zrwjcclcqt=0.0,lbss= 0.0,ssgl_lz= 0.0, | |
| 1900 | 2126 | ssgl_dm= 0.0,ssgl_gz= 0.0,ssgl_jf= 0.0,ssgl_zs= 0.0,ssgl_qr= 0.0,ssgl_qc= 0.0, |
| 1901 | 2127 | ssgl_kx= 0.0,ssgl_qh= 0.0,ssgl_yw= 0.0,ssgl_other= 0.0,ljyy=0.0,ljjcc=0.0, |
| 1902 | 2128 | kfks=0.0,yhl=0.0,jzl=0.0,hyl=0.0,dhl=0.0,cdl=0.0; |
| ... | ... | @@ -1915,7 +2141,11 @@ public class ReportServiceImpl implements ReportService{ |
| 1915 | 2141 | jhwlc=Arith.add(jhwlc, map.get("jhwlc")); |
| 1916 | 2142 | jhnjcclc=Arith.add(jhnjcclc, map.get("jhnjcclc")); |
| 1917 | 2143 | jhwjcclc=Arith.add(jhwjcclc, map.get("jhwjcclc")); |
| 2144 | + jhwjcclc_z=Arith.add(jhwjcclc_z, map.get("jhwjcclc_z")); | |
| 1918 | 2145 | zrwjcclc=Arith.add(zrwjcclc, map.get("zrwjcclc")); |
| 2146 | + zrwjcclc1=Arith.add(zrwjcclc1, map.get("zrwjcclc1")); | |
| 2147 | + zrwjcclc2=Arith.add(zrwjcclc2, map.get("zrwjcclc2")); | |
| 2148 | + zrwjcclcqt=Arith.add(zrwjcclcqt, map.get("zrwjcclcqt")); | |
| 1919 | 2149 | lbss=Arith.add(lbss, map.get("lbss")); |
| 1920 | 2150 | ssgl_lz=Arith.add(ssgl_lz, map.get("ssgl_lz")); |
| 1921 | 2151 | ssgl_dm=Arith.add(ssgl_dm, map.get("ssgl_dm")); |
| ... | ... | @@ -1962,7 +2192,11 @@ public class ReportServiceImpl implements ReportService{ |
| 1962 | 2192 | newMap.put("jhwlc", jhwlc); |
| 1963 | 2193 | newMap.put("jhnjcclc", jhnjcclc); |
| 1964 | 2194 | newMap.put("jhwjcclc", jhwjcclc); |
| 2195 | + newMap.put("jhwjcclc_z", jhwjcclc_z); | |
| 1965 | 2196 | newMap.put("zrwjcclc", zrwjcclc); |
| 2197 | + newMap.put("zrwjcclc1", zrwjcclc1); | |
| 2198 | + newMap.put("zrwjcclc2", zrwjcclc2); | |
| 2199 | + newMap.put("zrwjcclcqt", zrwjcclcqt); | |
| 1966 | 2200 | newMap.put("lbss", lbss); |
| 1967 | 2201 | newMap.put("ssgl_lz", ssgl_lz); |
| 1968 | 2202 | newMap.put("ssgl_dm",ssgl_dm); | ... | ... |
src/main/java/com/bsth/service/schedule/TTInfoService.java
| ... | ... | @@ -12,4 +12,6 @@ public interface TTInfoService extends BService<TTInfo, Long> { |
| 12 | 12 | void validate_s_d(TTInfo ttInfo) throws ScheduleException; |
| 13 | 13 | void toggleCancel(Long id) throws ScheduleException; |
| 14 | 14 | |
| 15 | + void backUp(Long ttInfoId) throws ScheduleException; | |
| 16 | + | |
| 15 | 17 | } | ... | ... |
src/main/java/com/bsth/service/schedule/impl/TTInfoServiceImpl.java
| 1 | 1 | package com.bsth.service.schedule.impl; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.schedule.TTInfo; |
| 4 | -import com.bsth.service.schedule.exception.ScheduleException; | |
| 4 | +import com.bsth.entity.schedule.TTInfoBackup; | |
| 5 | +import com.bsth.entity.schedule.TTInfoDetail; | |
| 6 | +import com.bsth.repository.schedule.TTInfoBackupRepository; | |
| 7 | +import com.bsth.repository.schedule.TTInfoDetailRepository; | |
| 8 | +import com.bsth.repository.schedule.TTInfoRepository; | |
| 5 | 9 | import com.bsth.service.schedule.TTInfoService; |
| 10 | +import com.bsth.service.schedule.exception.ScheduleException; | |
| 11 | +import com.bsth.service.schedule.utils.TimeTableProto; | |
| 6 | 12 | import org.apache.commons.lang3.StringUtils; |
| 13 | +import org.slf4j.Logger; | |
| 14 | +import org.slf4j.LoggerFactory; | |
| 15 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | 16 | import org.springframework.stereotype.Service; |
| 17 | +import org.springframework.transaction.annotation.Isolation; | |
| 18 | +import org.springframework.transaction.annotation.Propagation; | |
| 8 | 19 | import org.springframework.transaction.annotation.Transactional; |
| 9 | 20 | import org.springframework.util.CollectionUtils; |
| 10 | 21 | |
| 22 | +import java.io.PrintWriter; | |
| 23 | +import java.io.StringWriter; | |
| 24 | +import java.util.Date; | |
| 11 | 25 | import java.util.HashMap; |
| 12 | 26 | import java.util.List; |
| 13 | 27 | import java.util.Map; |
| ... | ... | @@ -17,6 +31,15 @@ import java.util.Map; |
| 17 | 31 | */ |
| 18 | 32 | @Service |
| 19 | 33 | public class TTInfoServiceImpl extends BServiceImpl<TTInfo, Long> implements TTInfoService { |
| 34 | + /** 日志记录器 */ | |
| 35 | + private static final Logger LOG = LoggerFactory.getLogger(TTInfoServiceImpl.class); | |
| 36 | + | |
| 37 | + @Autowired | |
| 38 | + private TTInfoRepository ttInfoRepository; | |
| 39 | + @Autowired | |
| 40 | + private TTInfoDetailRepository ttInfoDetailRepository; | |
| 41 | + @Autowired | |
| 42 | + private TTInfoBackupRepository ttInfoBackupRepository; | |
| 20 | 43 | |
| 21 | 44 | @Override |
| 22 | 45 | public void validate_name(TTInfo ttInfo) throws ScheduleException { |
| ... | ... | @@ -112,4 +135,60 @@ public class TTInfoServiceImpl extends BServiceImpl<TTInfo, Long> implements TTI |
| 112 | 135 | ttInfo.setIsCancel(true); |
| 113 | 136 | } |
| 114 | 137 | } |
| 138 | + | |
| 139 | + @Override | |
| 140 | + @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED) | |
| 141 | + public void backUp(Long ttInfoId) throws ScheduleException { | |
| 142 | + LOG.info(">>>>>>开始备份时刻表<<<<<<"); | |
| 143 | + | |
| 144 | + try { | |
| 145 | + // 获取原始数据 | |
| 146 | + TTInfo ttInfo = ttInfoRepository.findOne(ttInfoId); | |
| 147 | + List<TTInfoDetail> ttInfoDetails = ttInfoDetailRepository.findByTtinfoId(ttInfoId); | |
| 148 | + | |
| 149 | + // protobuf序列化成二进制数据 | |
| 150 | + TimeTableProto.TTInfo.Builder tb = ttInfo.toProtoBuilder(); | |
| 151 | + for (TTInfoDetail ttInfoDetail : ttInfoDetails) { | |
| 152 | + tb.addBcInfo(ttInfoDetail.toProtoBuilder()); | |
| 153 | + } | |
| 154 | + byte[] backupbytes = tb.build().toByteArray(); | |
| 155 | + LOG.info("......时刻表={}", ttInfo.getName()); | |
| 156 | + LOG.info("......时刻表protoBuf字节数={}", backupbytes.length); | |
| 157 | + | |
| 158 | + // 更新备份日期 | |
| 159 | + Date backupdate = new Date(); | |
| 160 | + ttInfo.setLastBackUpDate(backupdate); | |
| 161 | + | |
| 162 | + // 保存备份数据 | |
| 163 | + TTInfoBackup ttInfoBackup = new TTInfoBackup(); | |
| 164 | + ttInfoBackup.setXl(ttInfo.getXl().getId()); | |
| 165 | + ttInfoBackup.setXlName(ttInfo.getXl().getName()); | |
| 166 | + ttInfoBackup.setTtInfo(ttInfoId); | |
| 167 | + ttInfoBackup.setTtInfoName(ttInfo.getName()); | |
| 168 | + ttInfoBackup.setBackUpDate(backupdate); | |
| 169 | + ttInfoBackup.setBackUpInfo(backupbytes); | |
| 170 | + | |
| 171 | + ttInfoBackupRepository.save(ttInfoBackup); | |
| 172 | +// System.out.println(backupbytes.length); | |
| 173 | +// try { | |
| 174 | +// | |
| 175 | +// TimeTableProto.TTInfo tt1 = TimeTableProto.TTInfo.parseFrom(backupbytes); | |
| 176 | +// System.out.println(tt1.getName()); | |
| 177 | +// System.out.println(tt1.getBcInfoCount()); | |
| 178 | +// } catch (Exception exp) { | |
| 179 | +// exp.printStackTrace(); | |
| 180 | +// } | |
| 181 | + | |
| 182 | + LOG.info(">>>>>>备份时刻表success<<<<<<"); | |
| 183 | + } catch (Exception exp) { | |
| 184 | + StringWriter stringWriter = new StringWriter(); | |
| 185 | + PrintWriter printWriter = new PrintWriter(stringWriter); | |
| 186 | + exp.printStackTrace(printWriter); | |
| 187 | + LOG.info("......异常stack->{}", stringWriter.toString()); | |
| 188 | + LOG.info(">>>>>>备份时刻表failed<<<<<<"); | |
| 189 | + throw new ScheduleException(exp); | |
| 190 | + } | |
| 191 | + | |
| 192 | + | |
| 193 | + } | |
| 115 | 194 | } | ... | ... |