Commit be7e31bf078ce33f261224f5b469df4ceeae1e97

Authored by 王通
1 parent c3956eea

1.加入获取不在岗的出场班次接口

src/main/java/com/bsth/server_rs/schedule/real/SchRealDataBuffer.java
1 -package com.bsth.server_rs.schedule.real;  
2 -  
3 -import com.alibaba.fastjson.JSONObject;  
4 -import com.bsth.entity.ScheduleRealInfo;  
5 -import com.google.common.collect.ArrayListMultimap;  
6 -import org.apache.commons.lang3.StringUtils;  
7 -import org.springframework.stereotype.Component;  
8 -  
9 -import java.util.Collection;  
10 -import java.util.List;  
11 -import java.util.Map;  
12 -  
13 -/**  
14 - * 实际排班缓存  
15 - * Created by panzhao on 2017/9/27.  
16 - */  
17 -@Component  
18 -public class SchRealDataBuffer {  
19 -  
20 - /**  
21 - * 进出场班次数据,定时从调度系统获取。 对各场站输出  
22 - */  
23 - private static ArrayListMultimap<String, ScheduleRealInfo> inOutMap;  
24 -  
25 - /**  
26 - * 车辆 和 当前正在执行班次对照  
27 - */  
28 - private static Map<String, JSONObject> execMap;  
29 -  
30 - public void putInOutData(List<ScheduleRealInfo> list) {  
31 - ArrayListMultimap<String, ScheduleRealInfo> inOutMapCopy = ArrayListMultimap.create();  
32 -  
33 - String type;  
34 - for (ScheduleRealInfo sch : list) {  
35 - type = sch.getBcType();  
36 - if (StringUtils.isEmpty(type))  
37 - continue;  
38 -  
39 - if (type.equals("in"))  
40 - inOutMapCopy.put(sch.getZdzCode(), sch);  
41 - else if (type.equals("out"))  
42 - inOutMapCopy.put(sch.getQdzCode(), sch);  
43 - }  
44 -  
45 - inOutMap = inOutMapCopy;  
46 - }  
47 -  
48 -  
49 - public void setExecMap(Map<String, JSONObject> map) {  
50 - if (map.size() > 0)  
51 - execMap = map;  
52 - }  
53 -  
54 - public List<ScheduleRealInfo> findByParkCode(String parkCode) {  
55 - return inOutMap.get(parkCode);  
56 - }  
57 -  
58 - /* public List<JSONObject> findExec(List<String> cars){  
59 - List<JSONObject> rs = new ArrayList<>(cars.size());  
60 -  
61 - for(String nbbm : cars){  
62 - rs.add(execMap.get(nbbm));  
63 - }  
64 - return rs;  
65 - }*/  
66 -  
67 - public JSONObject getExecPlan(String nbbm) {  
68 - return execMap.get(nbbm);  
69 - }  
70 -  
71 - public Collection<JSONObject> execs() {  
72 - return execMap.values();  
73 - }  
74 -} 1 +package com.bsth.server_rs.schedule.real;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.bsth.entity.ScheduleRealInfo;
  5 +import com.google.common.collect.ArrayListMultimap;
  6 +import org.apache.commons.lang3.StringUtils;
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +import java.util.Collection;
  10 +import java.util.List;
  11 +import java.util.Map;
  12 +
  13 +/**
  14 + * 实际排班缓存
  15 + * Created by panzhao on 2017/9/27.
  16 + */
  17 +@Component
  18 +public class SchRealDataBuffer {
  19 +
  20 + /**
  21 + * 进出场班次数据,定时从调度系统获取。 对各场站输出
  22 + */
  23 + private static ArrayListMultimap<String, ScheduleRealInfo> inOutMap;
  24 +
  25 + /**
  26 + * 车辆 和 当前正在执行班次对照
  27 + */
  28 + private static Map<String, JSONObject> execMap;
  29 +
  30 + public void putInOutData(List<ScheduleRealInfo> list) {
  31 + ArrayListMultimap<String, ScheduleRealInfo> inOutMapCopy = ArrayListMultimap.create();
  32 +
  33 + String type;
  34 + for (ScheduleRealInfo sch : list) {
  35 + type = sch.getBcType();
  36 + if (StringUtils.isEmpty(type))
  37 + continue;
  38 +
  39 + if (type.equals("in"))
  40 + inOutMapCopy.put(sch.getZdzCode(), sch);
  41 + else if (type.equals("out"))
  42 + inOutMapCopy.put(sch.getQdzCode(), sch);
  43 + }
  44 +
  45 + inOutMap = inOutMapCopy;
  46 + }
  47 +
  48 + public Collection<ScheduleRealInfo> getInOutData() {
  49 + return inOutMap.values();
  50 + }
  51 +
  52 + public void setExecMap(Map<String, JSONObject> map) {
  53 + if (map.size() > 0)
  54 + execMap = map;
  55 + }
  56 +
  57 + public List<ScheduleRealInfo> findByParkCode(String parkCode) {
  58 + return inOutMap.get(parkCode);
  59 + }
  60 +
  61 + /* public List<JSONObject> findExec(List<String> cars){
  62 + List<JSONObject> rs = new ArrayList<>(cars.size());
  63 +
  64 + for(String nbbm : cars){
  65 + rs.add(execMap.get(nbbm));
  66 + }
  67 + return rs;
  68 + }*/
  69 +
  70 + public JSONObject getExecPlan(String nbbm) {
  71 + return execMap.get(nbbm);
  72 + }
  73 +
  74 + public Collection<JSONObject> execs() {
  75 + return execMap.values();
  76 + }
  77 +}
src/main/java/com/bsth/server_rs/schedule/real/ScheduleRealService.java
@@ -14,6 +14,8 @@ import com.bsth.server_rs.base_info.car.Car; @@ -14,6 +14,8 @@ import com.bsth.server_rs.base_info.car.Car;
14 import com.bsth.server_rs.base_info.car.buffer.CarBufferData; 14 import com.bsth.server_rs.base_info.car.buffer.CarBufferData;
15 import com.bsth.server_rs.base_info.line.Line; 15 import com.bsth.server_rs.base_info.line.Line;
16 import com.bsth.server_rs.base_info.line.buffer.LineBufferData; 16 import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
  17 +import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer;
  18 +import com.bsth.server_rs.gps.entity.GpsEntity;
17 import com.bsth.server_rs.schedule.dto.ScheduleCcInfoConfig; 19 import com.bsth.server_rs.schedule.dto.ScheduleCcInfoConfig;
18 import com.bsth.server_rs.schedule.dto.ScheduleInOut; 20 import com.bsth.server_rs.schedule.dto.ScheduleInOut;
19 import com.bsth.server_rs.schedule.dto.ScheduleRealInfoDTO_JK; 21 import com.bsth.server_rs.schedule.dto.ScheduleRealInfoDTO_JK;
@@ -303,6 +305,31 @@ public class ScheduleRealService implements InitializingBean { @@ -303,6 +305,31 @@ public class ScheduleRealService implements InitializingBean {
303 return rs; 305 return rs;
304 } 306 }
305 307
  308 + /**
  309 + * 获取不在岗的班次信息
  310 + */
  311 + @GET
  312 + @Path("/notOnDuty")
  313 + public List<ScheduleRealInfo> notOnDuty() {
  314 + List<ScheduleRealInfo> result = new ArrayList<>();
  315 + Collection<ScheduleRealInfo> collection = schRealDataBuffer.getInOutData();
  316 + long now = System.currentTimeMillis();
  317 + for (ScheduleRealInfo sch : collection) {
  318 + if ("in".equals(sch.getBcType())) {
  319 + continue;
  320 + }
  321 + GpsEntity gpsEntity = GpsRealDataBuffer.get(CarBufferData.findOne(sch.getClZbh()).getEquipmentCode());
  322 + long schIntervalMillis = sch.getDfsjT() - now, gpsIntervalMillis = sch.getDfsjT() - (gpsEntity == null ? 0 : gpsEntity.getTimestamp());
  323 + boolean isSchMatch = schIntervalMillis > 0 && schIntervalMillis < 1200000, isGpsMatch = gpsIntervalMillis > 1200000;
  324 + // 当前时间往后20分钟内的出场班次 且相应车辆在待发时间20分钟内无GPS数据
  325 + if (isSchMatch && isGpsMatch) {
  326 + result.add(sch);
  327 + }
  328 + }
  329 +
  330 + return result;
  331 + }
  332 +
306 @Override 333 @Override
307 public void afterPropertiesSet() throws Exception { 334 public void afterPropertiesSet() throws Exception {
308 /*Application.mainServices.scheduleWithFixedDelay(new Runnable() { 335 /*Application.mainServices.scheduleWithFixedDelay(new Runnable() {