Commit 6315b5d47733db650ebc743973d7350077967d0a

Authored by 潘钊
1 parent 6291c006

update...

Showing 24 changed files with 735 additions and 1287 deletions
src/main/java/com/bsth/Application.java
@@ -8,14 +8,16 @@ import org.springframework.boot.builder.SpringApplicationBuilder; @@ -8,14 +8,16 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
8 import org.springframework.boot.context.web.SpringBootServletInitializer; 8 import org.springframework.boot.context.web.SpringBootServletInitializer;
9 import org.springframework.context.annotation.Bean; 9 import org.springframework.context.annotation.Bean;
10 import org.springframework.context.annotation.Primary; 10 import org.springframework.context.annotation.Primary;
  11 +import org.springframework.transaction.annotation.EnableTransactionManagement;
11 12
12 import java.util.concurrent.Executors; 13 import java.util.concurrent.Executors;
13 import java.util.concurrent.ScheduledExecutorService; 14 import java.util.concurrent.ScheduledExecutorService;
14 15
  16 +@EnableTransactionManagement
15 @SpringBootApplication 17 @SpringBootApplication
16 public class Application extends SpringBootServletInitializer { 18 public class Application extends SpringBootServletInitializer {
17 19
18 - public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(13); 20 + public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(14);
19 21
20 @Override 22 @Override
21 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 23 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
src/main/java/com/bsth/data/BasicData.java
@@ -40,7 +40,7 @@ public class BasicData implements CommandLineRunner { @@ -40,7 +40,7 @@ public class BasicData implements CommandLineRunner {
40 //车辆自编号和公司代码对照 (K: 车辆自编号 ,V:公司代码) 40 //车辆自编号和公司代码对照 (K: 车辆自编号 ,V:公司代码)
41 public static Map<String, String> nbbm2CompanyCodeMap; 41 public static Map<String, String> nbbm2CompanyCodeMap;
42 42
43 - //车辆自编号和公司代码对照 (K: 车辆自编号 ,V:牌照号) 43 + //车辆自编号和牌照号对照 (K: 车辆自编号 ,V:牌照号)
44 public static Map<String, String> nbbmCompanyPlateMap; 44 public static Map<String, String> nbbmCompanyPlateMap;
45 45
46 //站点编码和名称对照,包括停车场 (K: lineCode_updown_stationCode ,V:站点名称) 46 //站点编码和名称对照,包括停车场 (K: lineCode_updown_stationCode ,V:站点名称)
src/main/java/com/bsth/data/arrival/AnalyseData.java deleted 100644 → 0
1 -package com.bsth.data.arrival;  
2 -  
3 -import org.slf4j.Logger;  
4 -import org.slf4j.LoggerFactory;  
5 -import org.springframework.stereotype.Component;  
6 -  
7 -import java.util.ArrayList;  
8 -import java.util.Collections;  
9 -import java.util.List;  
10 -import java.util.Set;  
11 -  
12 -/**  
13 - *  
14 - * @ClassName: AnalyseArrivalData  
15 - * @Description: TODO(分析一下进出站场数据)  
16 - * @author PanZhao  
17 - * @date 2016年8月24日 上午11:09:37  
18 - *  
19 - */  
20 -@Component  
21 -public class AnalyseData {  
22 -  
23 - Logger logger = LoggerFactory.getLogger(AnalyseData.class);  
24 -  
25 - public void analyse(Set<String> cars){  
26 - try{  
27 - List<ArrivalEntity> list, clearList;  
28 - for(String car : cars){  
29 - list = ArrivalData_GPS.findByNbbm(car);  
30 - analyse(list);  
31 -  
32 - //清理掉无效的点  
33 - clearList = new ArrayList<>();  
34 - for(ArrivalEntity arr : list){  
35 - if(!arr.isEnable())  
36 - clearList.add(arr);  
37 - }  
38 - list.removeAll(clearList);  
39 - }  
40 - }catch(Exception e){  
41 - logger.error("", e);  
42 - }  
43 - }  
44 -  
45 - private final static int SHIFT_TIME = 1000 * 60 * 5,  
46 - SCH_TIME = 1000 * 60 * 10;  
47 -  
48 - static ArrivalComparator comp = new ArrivalComparator();  
49 -  
50 - public void analyse(List<ArrivalEntity> list){  
51 - if(list.size() <= 1)  
52 - return;  
53 -  
54 - //排序  
55 - Collections.sort(list, comp);  
56 - ArrivalEntity prve = list.get(0)  
57 - ,curr;  
58 - for(int i = 1; i < list.size(); i ++){  
59 - curr = list.get(i);  
60 - //如果第一个点无效  
61 - if(!effective(prve)){  
62 - prve.setEnable(false);  
63 - prve = curr;  
64 - continue;  
65 - }  
66 - //如果第二个点无效  
67 - else if(!effective(curr)){  
68 - curr.setEnable(false);  
69 - continue;  
70 - }  
71 - else if(curr.getTs() - prve.getTs() < SCH_TIME){  
72 - if(prve.getUpDown() == curr.getUpDown()){  
73 - //信号漂移,出站无效  
74 - if(curr.getStopNo().equals(prve.getStopNo())  
75 - && prve.getInOut() == 1 && curr.getInOut() == 0  
76 - && curr.getTs() - prve.getTs() < SHIFT_TIME){  
77 - prve.setEnable(false);  
78 - }  
79 -// else if(curr.getInOut()){  
80 -// //curr.getTs() - prve.getTs() < 30000  
81 -// }  
82 - }  
83 - else{  
84 - //上下行的同名站,新走向的第一个出站信号开始有效  
85 - if(prve.getStopName().equals(curr.getStopName())){  
86 - if(curr.getInOut() == 0)  
87 - curr.setEnable(false);  
88 - else  
89 - prve = curr;  
90 - }  
91 - }  
92 - }  
93 - else  
94 - prve = curr;  
95 - }  
96 - }  
97 -  
98 - private boolean effective(ArrivalEntity arr){  
99 - /*//停车场  
100 - if(BasicData.parkCodeList.contains(arr.getStopNo())){  
101 - arr.setTcc(true);  
102 - return true;  
103 - }  
104 -  
105 - Integer upDown = BasicData.lineStationUpDownMap.get(arr.getLineCode() + "_" + arr.getStopNo());  
106 -  
107 - return arr.getUpDown() == upDown || BasicData.parkCodeList.contains(arr.getStopNo());*/  
108 - return false;  
109 - }  
110 -}  
src/main/java/com/bsth/data/arrival/ArrivalData_GPS.java deleted 100644 → 0
1 -package com.bsth.data.arrival;  
2 -  
3 -import com.bsth.data.schedule.DayOfSchedule;  
4 -import com.google.common.collect.ArrayListMultimap;  
5 -import com.google.common.collect.ListMultimap;  
6 -import org.slf4j.Logger;  
7 -import org.slf4j.LoggerFactory;  
8 -import org.springframework.beans.factory.annotation.Autowired;  
9 -import org.springframework.boot.CommandLineRunner;  
10 -import org.springframework.stereotype.Component;  
11 -  
12 -import java.util.*;  
13 -  
14 -/**  
15 - *  
16 - * @ClassName: ArrivalData_GPS  
17 - * @Description: TODO(GPS到离站数据)  
18 - * @author PanZhao  
19 - * @date 2016年8月18日 下午10:05:27  
20 - *  
21 - */  
22 -@Component  
23 -public class ArrivalData_GPS implements CommandLineRunner{  
24 -  
25 - // 起终点站进出数据 K:车辆编码  
26 - private static ListMultimap<String, ArrivalEntity> startAndEndMaps;  
27 -  
28 - private static Map<String, Integer> carIndexMap;  
29 -  
30 - static{  
31 - startAndEndMaps = ArrayListMultimap.create();  
32 -  
33 - carIndexMap = new HashMap<>();  
34 - }  
35 -  
36 - @Autowired  
37 - DataLoaderThread dataLoaderThread;  
38 -  
39 - static Logger logger = LoggerFactory.getLogger(ArrivalData_GPS.class);  
40 -  
41 - @Override  
42 - public void run(String... arg0) throws Exception {  
43 - logger.info("ArrivalData_GPS,30,06");  
44 - //Application.mainServices.scheduleWithFixedDelay(dataLoaderThread, 40, 6, TimeUnit.SECONDS);  
45 - }  
46 -  
47 - @Component  
48 - public static class DataLoaderThread extends Thread {  
49 -  
50 - @Autowired  
51 - DataLoader dataLoader;  
52 -  
53 - @Autowired  
54 - DayOfSchedule dayOfSchedule;  
55 -  
56 - @Autowired  
57 - AnalyseData analyseData;  
58 -  
59 - @Override  
60 - public void run() {  
61 - /*try{  
62 - logger.info("开始加载到离站数据, " + System.currentTimeMillis());  
63 - List<ArrivalEntity> arrSets = dataLoader.load();  
64 - if(null == arrSets || arrSets.size() == 0)  
65 - return;  
66 -  
67 - //有起终点进出的车辆  
68 - Set<String> carSet = new TreeSet<>();  
69 - //按车辆起终点站过滤数据  
70 - String nbbm;  
71 - Set<String> seList;  
72 - for(ArrivalEntity arr : arrSets){  
73 - nbbm = arr.getNbbm();  
74 -  
75 - seList = dayOfSchedule.getSEStationList(nbbm);  
76 - if(seList.contains(arr.getStopNo())){  
77 - startAndEndMaps.put(nbbm, arr);  
78 - carSet.add(nbbm);  
79 - }  
80 - }  
81 - //从专业的角度分析一下数据  
82 - analyseData.analyse(carSet);  
83 -  
84 - //开始匹配  
85 - Arrival2Schedule.start(carSet);  
86 - }catch(Exception e){  
87 - logger.error("", e);  
88 - }*/  
89 - }  
90 - }  
91 -  
92 - /**  
93 - *  
94 - * @Title: clearRAMData  
95 - * @Description: TODO(清理内存数据)  
96 - */  
97 - public void clearRAMData(String lineCode){  
98 -  
99 - List<ArrivalEntity> remList = new ArrayList<>();  
100 -  
101 - //车辆映射的进出站数据,遍历删除对应线路数据。  
102 - Collection<ArrivalEntity> seList = startAndEndMaps.values();  
103 - for(ArrivalEntity arr : seList){  
104 - if(arr.getLineCode().equals(lineCode))  
105 - remList.add(arr);  
106 - }  
107 -  
108 - //删除数据  
109 - int count = 0;  
110 - for(ArrivalEntity arr : remList){  
111 - startAndEndMaps.remove(arr.getNbbm(), arr);  
112 - count ++;  
113 - }  
114 -  
115 - logger.info(lineCode + " 清除到离站数据 ," + count);  
116 - }  
117 -  
118 - public synchronized static List<ArrivalEntity> findByNbbm(String nbbm){  
119 - return startAndEndMaps.get(nbbm);  
120 - }  
121 -  
122 - public static List<ArrivalEntity> getIncrement(String nbbm){  
123 - Integer mark = null;  
124 - if (!carIndexMap.containsKey(nbbm))  
125 - mark = 0;  
126 - else  
127 - mark = carIndexMap.get(nbbm);  
128 -  
129 - List<ArrivalEntity> all = startAndEndMaps.get(nbbm);  
130 - int size = all.size();  
131 - if(size == 0)  
132 - return new ArrayList<>(0);  
133 -  
134 - List<ArrivalEntity> rs = all.subList(mark, size);  
135 - carIndexMap.put(nbbm, size);  
136 - return rs;  
137 - }  
138 -}  
139 \ No newline at end of file 0 \ No newline at end of file
src/main/java/com/bsth/data/car_out_info/CarOutInfo.java 0 → 100644
  1 +package com.bsth.data.car_out_info;
  2 +
  3 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  4 +
  5 +import java.util.List;
  6 +
  7 +/**
  8 + * Created by panzhao on 2017/5/7.
  9 + */
  10 +public interface CarOutInfo {
  11 +
  12 + void updateAll();
  13 +
  14 + void update(String lineCode);
  15 +
  16 + void update(List<ScheduleRealInfo> list) ;
  17 +}
src/main/java/com/bsth/data/car_out_info/CarOutInfoHandler.java 0 → 100644
  1 +package com.bsth.data.car_out_info;
  2 +
  3 +import com.bsth.data.BasicData;
  4 +import com.bsth.data.schedule.DayOfSchedule;
  5 +import com.bsth.data.schedule.ScheduleComparator;
  6 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  7 +import com.google.common.collect.ArrayListMultimap;
  8 +import org.apache.commons.lang3.StringUtils;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.boot.CommandLineRunner;
  13 +import org.springframework.jdbc.core.BatchPreparedStatementSetter;
  14 +import org.springframework.jdbc.core.JdbcTemplate;
  15 +import org.springframework.stereotype.Component;
  16 +import org.springframework.stereotype.Service;
  17 +import org.springframework.transaction.annotation.Transactional;
  18 +
  19 +import java.sql.PreparedStatement;
  20 +import java.sql.SQLException;
  21 +import java.util.*;
  22 +
  23 +/**
  24 + * 发车信息表处理程序
  25 + * Created by panzhao on 2017/5/5.
  26 + */
  27 +@Service
  28 +public class CarOutInfoHandler implements CommandLineRunner, CarOutInfo {
  29 +
  30 + @Autowired
  31 + DayOfSchedule dayOfSchedule;
  32 +
  33 + //班次类型对照表
  34 + Map<String, String> bcTypeMap;
  35 +
  36 + private static ScheduleComparator.FCSJ schFCSJComparator = new ScheduleComparator.FCSJ();
  37 +
  38 + @Autowired
  39 + JdbcTemplate jdbcTemplate;
  40 +
  41 + Logger logger = LoggerFactory.getLogger(this.getClass());
  42 +
  43 + /**
  44 + * 全量更新发车信息表
  45 + */
  46 + @Override
  47 + public void updateAll() {
  48 + Set<String> ks = BasicData.lineCode2NameMap.keySet();
  49 + for (String lineCode : ks) {
  50 + update(lineCode);
  51 + }
  52 + }
  53 +
  54 + @Override
  55 + public void update(String lineCode) {
  56 + try {
  57 + ArrayListMultimap<String, ScheduleRealInfo> lpScheduleMap = dayOfSchedule.getLpScheduleMap();
  58 + List<ScheduleRealInfo> list = new ArrayList<>();
  59 +
  60 + Set<String> ks = lpScheduleMap.keySet();
  61 + String prefix = lineCode + "_";
  62 + for (String k : ks) {
  63 + if (k.indexOf(prefix) != -1) {
  64 + list.addAll(lpScheduleMap.get(k));
  65 + }
  66 + }
  67 +
  68 + update(list);
  69 + } catch (Exception e) {
  70 + logger.error("", e);
  71 + }
  72 + }
  73 +
  74 + @Transactional
  75 + @Override
  76 + public void update(List<ScheduleRealInfo> list) {
  77 + if (list.size() == 0)
  78 + return;
  79 + String lineCode = list.get(0).getXlBm();
  80 + //按上下行分组
  81 + List<ScheduleRealInfo> ups = new ArrayList<>(), downs = new ArrayList<>();
  82 + for (ScheduleRealInfo sch : list) {
  83 + if (sch.getXlDir().equals("0"))
  84 + ups.add(sch);
  85 + else
  86 + downs.add(sch);
  87 + }
  88 +
  89 + ScheduleRealInfo[] upArray = nexts(ups),
  90 + downArray = nexts(downs);
  91 +
  92 + final List<ScheduleRealInfo> pstArray = mergeArray(upArray, downArray);
  93 + //删除
  94 + jdbcTemplate.update("delete from bsth_t_clfcxxb where line_code=?", lineCode);
  95 + //重新写入
  96 + jdbcTemplate.batchUpdate("insert into bsth_t_clfcxxb(rq, line_code, line_name, lp_name, lp_sn, dfsj, nbbm, cph, bc_type, end_station_name, updown, jGh, jName, remarks, sn)" +
  97 + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new BatchPreparedStatementSetter() {
  98 + @Override
  99 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  100 + ScheduleRealInfo sch = pstArray.get(i);
  101 + ps.setString(1, sch.getScheduleDateStr());
  102 + ps.setString(2, sch.getXlBm());
  103 + ps.setString(3, sch.getXlName());
  104 + ps.setString(4, sch.getLpName());
  105 + ps.setInt(5, sch.getFcno());
  106 + ps.setString(6, sch.getDfsj());
  107 + ps.setString(7, sch.getClZbh());
  108 + ps.setString(8, BasicData.nbbmCompanyPlateMap.get(sch.getClZbh()));
  109 + ps.setString(9, bcTypeMap.containsKey(sch.getBcType()) ? bcTypeMap.get(sch.getBcType()) : sch.getBcType());
  110 + ps.setString(10, sch.getZdzName());
  111 + ps.setInt(11, Integer.parseInt(sch.getXlDir()));
  112 + ps.setString(12, sch.getjGh());
  113 + ps.setString(13, sch.getjName());
  114 + ps.setString(14, sch.getRemarks());
  115 + ps.setInt(15, sch.getFcpSn());
  116 + }
  117 +
  118 + @Override
  119 + public int getBatchSize() {
  120 + return pstArray.size();
  121 + }
  122 + });
  123 + }
  124 +
  125 + private List<ScheduleRealInfo> mergeArray(ScheduleRealInfo[] upArray, ScheduleRealInfo[] downArray) {
  126 + List<ScheduleRealInfo> list = new ArrayList<>();
  127 + for (int i = 0; i < upArray.length; i++) {
  128 + if (upArray[i] != null) {
  129 + upArray[i].setFcpSn(i + 1);
  130 + list.add(upArray[i]);
  131 + }
  132 + }
  133 + for (int i = 0; i < downArray.length; i++) {
  134 + if (downArray[i] != null) {
  135 + downArray[i].setFcpSn(i + 1);
  136 + list.add(downArray[i]);
  137 + }
  138 + }
  139 + return list;
  140 + }
  141 +
  142 + /**
  143 + * 接下来要执行的3个班次
  144 + *
  145 + * @param list
  146 + * @return
  147 + */
  148 + private ScheduleRealInfo[] nexts(List<ScheduleRealInfo> list) {
  149 + ScheduleRealInfo[] array = new ScheduleRealInfo[3];
  150 + Collections.sort(list, schFCSJComparator);
  151 +
  152 + int count = 0, threshold = 1000 * 60 * 30;
  153 + long t = System.currentTimeMillis();
  154 + for (ScheduleRealInfo sch : list) {
  155 + if (count == 3)
  156 + break;
  157 +
  158 + //烂班
  159 + if (sch.isDestroy())
  160 + continue;
  161 +
  162 + //进场、出场、2点间空驶
  163 + if (sch.getBcType().equals("in")
  164 + || sch.getBcType().equals("out")
  165 + || sch.getBcType().equals("ldks"))
  166 + continue;
  167 +
  168 + //有实发实达时间的
  169 + if (StringUtils.isNotEmpty(sch.getFcsjActual())
  170 + || StringUtils.isNotEmpty(sch.getZdsjActual()))
  171 + continue;
  172 +
  173 + if (t - sch.getDfsjT() > threshold)
  174 + continue;
  175 +
  176 + array[count] = sch;
  177 + count++;
  178 + }
  179 + return array;
  180 + }
  181 +
  182 + @Autowired
  183 + UpdateInfoThread updateInfoThread;
  184 +
  185 + @Override
  186 + public void run(String... strings) throws Exception {
  187 + bcTypeMap = new HashMap<>();
  188 + bcTypeMap.put("normal", "正常班次");
  189 + bcTypeMap.put("region", "区间");
  190 + bcTypeMap.put("venting", "直放");
  191 + bcTypeMap.put("major", "放站");
  192 + bcTypeMap.put("ldks", "两点间空驶");
  193 + //Application.mainServices.scheduleWithFixedDelay(updateInfoThread, 60, 40, TimeUnit.SECONDS);
  194 + }
  195 +
  196 + @Component
  197 + private static class UpdateInfoThread extends Thread {
  198 +
  199 + @Autowired
  200 + CarOutInfo carOutInfoHandler;
  201 +
  202 + @Override
  203 + public void run() {
  204 + carOutInfoHandler.updateAll();
  205 + }
  206 + }
  207 +}
src/main/java/com/bsth/data/arrival/ArrivalComparator.java renamed to src/main/java/com/bsth/data/forecast/ArrivalComparator.java
1 -package com.bsth.data.arrival;  
2 -  
3 -import java.util.Comparator;  
4 -  
5 -public class ArrivalComparator implements Comparator<ArrivalEntity>{  
6 -  
7 - @Override  
8 - public int compare(ArrivalEntity a1, ArrivalEntity a2) {  
9 - return (int) (a1.getTs() - a2.getTs());  
10 - }  
11 -} 1 +package com.bsth.data.forecast;
  2 +
  3 +import com.bsth.data.forecast.entity.ArrivalEntity;
  4 +
  5 +import java.util.Comparator;
  6 +
  7 +public class ArrivalComparator implements Comparator<ArrivalEntity>{
  8 +
  9 + @Override
  10 + public int compare(ArrivalEntity a1, ArrivalEntity a2) {
  11 + return (int) (a1.getTs() - a2.getTs());
  12 + }
  13 +}
src/main/java/com/bsth/data/arrival/DataLoader.java renamed to src/main/java/com/bsth/data/forecast/ArrivalDataLoader.java
1 -package com.bsth.data.arrival;  
2 -  
3 -import java.sql.Connection;  
4 -import java.sql.PreparedStatement;  
5 -import java.sql.ResultSet;  
6 -import java.sql.SQLException;  
7 -import java.util.ArrayList;  
8 -import java.util.Calendar;  
9 -import java.util.Collection;  
10 -import java.util.List;  
11 -  
12 -import org.slf4j.Logger;  
13 -import org.slf4j.LoggerFactory;  
14 -import org.springframework.beans.factory.annotation.Autowired;  
15 -import org.springframework.stereotype.Component;  
16 -  
17 -import com.bsth.data.BasicData;  
18 -import com.bsth.data.LineConfigData;  
19 -import com.bsth.entity.realcontrol.LineConfig;  
20 -import com.bsth.util.db.DBUtils_MS;  
21 -  
22 -/**  
23 - *  
24 - * @ClassName: DataLoader  
25 - * @Description: TODO(从数据库加载进出站数据)  
26 - * @author PanZhao  
27 - * @date 2016年8月19日 上午9:59:21  
28 - *  
29 - */  
30 -@Component  
31 -public class DataLoader {  
32 -  
33 - private static Long prveLoadTime;  
34 -  
35 - private final static long DAY_TIME = 1000 * 60 * 60 * 24;  
36 -  
37 - private Logger logger = LoggerFactory.getLogger(this.getClass());  
38 -  
39 - @Autowired  
40 - LineConfigData lineConfigData;  
41 -  
42 - /**  
43 - *  
44 - * @Title: load  
45 - * @Description: TODO(根据上次加载时间,查询之后的增量数据)  
46 - */  
47 - public List<ArrivalEntity> load(){  
48 - List<ArrivalEntity> list = null;  
49 -  
50 - if(null == prveLoadTime)  
51 - list = recovery();  
52 - else{  
53 - Calendar cal = Calendar.getInstance();  
54 - //周数,表分区字段  
55 - int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);  
56 -  
57 - Connection conn = null;  
58 - PreparedStatement ps = null;  
59 - ResultSet rs = null;  
60 -  
61 - String sql = "select * from bsth_c_arrival_info where weeks_year=? AND create_timestamp > ? AND create_timestamp <=? AND ABS(create_timestamp - ts) < 3600000 order by create_date";  
62 - try{  
63 - long t = System.currentTimeMillis();  
64 -  
65 - conn = DBUtils_MS.getConnection();  
66 - ps = conn.prepareStatement(sql);  
67 - ps.setInt(1, weeks_year);  
68 - ps.setLong(2, prveLoadTime);  
69 - ps.setLong(3, t);  
70 - rs = ps.executeQuery();  
71 -  
72 - list = resultSet2Set(rs);  
73 -  
74 - prveLoadTime = t;  
75 - }catch(Exception e){  
76 - logger.error("", e);  
77 - }finally {  
78 - DBUtils_MS.close(rs, ps, conn);  
79 - }  
80 - }  
81 - return list;  
82 - }  
83 -  
84 - /**  
85 - *  
86 - * @Title: recovery  
87 - * @Description: TODO(从数据库恢复数据,按照线路的开始运营时间恢复)  
88 - */  
89 - public List<ArrivalEntity> recovery(){  
90 - Collection<LineConfig> confs = lineConfigData.getAll();  
91 - long t = System.currentTimeMillis()  
92 - ,st;  
93 -  
94 - List<ArrivalEntity> all = new ArrayList<>();  
95 - for(LineConfig conf : confs){  
96 - st = conf.getCurrStartTime();  
97 - if(t < st)  
98 - st = st - DAY_TIME;  
99 - try{  
100 - all.addAll(loadByLineAndTime(conf.getLine().getLineCode(), st, t));  
101 - }catch(Exception e){  
102 - logger.error("", e);  
103 - }  
104 - }  
105 -  
106 - prveLoadTime = t;  
107 - return all;  
108 - }  
109 -  
110 - /**  
111 - *  
112 - * @Title: loadByLineAndStartTime  
113 - * @Description: TODO(根据线路和时间戳加载数据)  
114 - */  
115 - public List<ArrivalEntity> loadByLineAndTime(String lineCode, long st, long et){  
116 - Calendar cal = Calendar.getInstance();  
117 - cal.setTimeInMillis(st);  
118 - int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);  
119 -  
120 - Connection conn = null;  
121 - PreparedStatement ps = null;  
122 - ResultSet rs = null;  
123 -  
124 - List<ArrivalEntity> list = new ArrayList<>();  
125 - String sql = "select * from bsth_c_arrival_info where weeks_year=? and line_id=? AND create_timestamp > ? AND create_timestamp <=? AND ABS(create_timestamp - ts) < 3600000 order by ts";  
126 - try{  
127 - conn = DBUtils_MS.getConnection();  
128 - ps = conn.prepareStatement(sql);  
129 - ps.setInt(1, weeks_year);  
130 - ps.setString(2, lineCode);  
131 - ps.setLong(3, st);  
132 - ps.setLong(4, et);  
133 - rs = ps.executeQuery();  
134 -  
135 - list = resultSet2Set(rs);  
136 - }catch(Exception e){  
137 - logger.error("", e);  
138 - }finally {  
139 - DBUtils_MS.close(rs, ps, conn);  
140 - }  
141 - return list;  
142 - }  
143 -  
144 - /**  
145 - *  
146 - * @Title: loadByLineAndStartTime  
147 - * @Description: TODO(根据线路,走向和时间戳加载数据)  
148 - */  
149 - public List<ArrivalEntity> loadByLineAndTime(String lineCode, int updown, long st, long et){  
150 - Calendar cal = Calendar.getInstance();  
151 - cal.setTimeInMillis(st);  
152 - int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);  
153 -  
154 - Connection conn = null;  
155 - PreparedStatement ps = null;  
156 - ResultSet rs = null;  
157 -  
158 - List<ArrivalEntity> list = new ArrayList<>();  
159 - String sql = "select * from bsth_c_arrival_info where weeks_year=? and line_id=? and up_down=? and in_out=0 AND create_timestamp > ? AND create_timestamp <=? AND ABS(create_timestamp - ts) < 3600000 order by ts";  
160 - try{  
161 - conn = DBUtils_MS.getConnection();  
162 - ps = conn.prepareStatement(sql);  
163 - ps.setInt(1, weeks_year);  
164 - ps.setString(2, lineCode);  
165 - ps.setInt(3, updown);  
166 - ps.setLong(4, st);  
167 - ps.setLong(5, et);  
168 - rs = ps.executeQuery();  
169 -  
170 - list = resultSet2Set(rs);  
171 - }catch(Exception e){  
172 - logger.error("", e);  
173 - }finally {  
174 - DBUtils_MS.close(rs, ps, conn);  
175 - }  
176 - return list;  
177 - }  
178 -  
179 - public List<ArrivalEntity> resultSet2Set(ResultSet rs) throws SQLException{  
180 - List<ArrivalEntity> list = new ArrayList<>();  
181 -  
182 - ArrivalEntity arr;  
183 - while(rs.next()){  
184 - arr = new ArrivalEntity();  
185 - arr.setDeviceId(rs.getString("device_id"));  
186 - arr.setNbbm(BasicData.deviceId2NbbmMap.get(arr.getDeviceId()));  
187 - if(null == arr.getNbbm()){  
188 - logger.warn("未注册的设备号," + arr.getDeviceId());  
189 - continue;  
190 - }  
191 -  
192 - arr.setTs(rs.getLong("ts"));  
193 - arr.setLineCode(rs.getString("line_id"));  
194 - arr.setUpDown(rs.getInt("up_down"));  
195 - arr.setStopNo(rs.getString("stop_no"));  
196 - arr.setStopName(BasicData.stationCode2NameMap.get(arr.getStopNo()));  
197 - arr.setInOut(rs.getInt("in_out"));  
198 - arr.setCreateDate(rs.getLong("create_timestamp"));  
199 - arr.setWeeksYear(rs.getInt("weeks_year"));  
200 - arr.setEnable(true);  
201 -  
202 - list.add(arr);  
203 - }  
204 - return list;  
205 - }  
206 -  
207 - public static void setPrveLoadTime(long t){  
208 - prveLoadTime = t;  
209 - }  
210 -} 1 +package com.bsth.data.forecast;
  2 +
  3 +import com.bsth.data.BasicData;
  4 +import com.bsth.data.LineConfigData;
  5 +import com.bsth.data.forecast.entity.ArrivalEntity;
  6 +import com.bsth.entity.realcontrol.LineConfig;
  7 +import com.bsth.util.db.DBUtils_MS;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.stereotype.Component;
  12 +
  13 +import java.sql.Connection;
  14 +import java.sql.PreparedStatement;
  15 +import java.sql.ResultSet;
  16 +import java.sql.SQLException;
  17 +import java.util.ArrayList;
  18 +import java.util.Calendar;
  19 +import java.util.Collection;
  20 +import java.util.List;
  21 +
  22 +/**
  23 + *
  24 + * @ClassName: DataLoader
  25 + * @Description: TODO(从数据库加载进出站数据)
  26 + * @author PanZhao
  27 + * @date 2016年8月19日 上午9:59:21
  28 + *
  29 + */
  30 +@Component
  31 +public class ArrivalDataLoader {
  32 +
  33 + private static Long prveLoadTime;
  34 +
  35 + private final static long DAY_TIME = 1000 * 60 * 60 * 24;
  36 +
  37 + private Logger logger = LoggerFactory.getLogger(this.getClass());
  38 +
  39 + @Autowired
  40 + LineConfigData lineConfigData;
  41 +
  42 + /**
  43 + *
  44 + * @Title: load
  45 + * @Description: TODO(根据上次加载时间,查询之后的增量数据)
  46 + */
  47 + public List<ArrivalEntity> load(){
  48 + List<ArrivalEntity> list = null;
  49 +
  50 + if(null == prveLoadTime)
  51 + list = recovery();
  52 + else{
  53 + Calendar cal = Calendar.getInstance();
  54 + //周数,表分区字段
  55 + int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);
  56 +
  57 + Connection conn = null;
  58 + PreparedStatement ps = null;
  59 + ResultSet rs = null;
  60 +
  61 + String sql = "select * from bsth_c_arrival_info where weeks_year=? AND create_timestamp > ? AND create_timestamp <=? AND ABS(create_timestamp - ts) < 3600000 order by create_date";
  62 + try{
  63 + long t = System.currentTimeMillis();
  64 +
  65 + conn = DBUtils_MS.getConnection();
  66 + ps = conn.prepareStatement(sql);
  67 + ps.setInt(1, weeks_year);
  68 + ps.setLong(2, prveLoadTime);
  69 + ps.setLong(3, t);
  70 + rs = ps.executeQuery();
  71 +
  72 + list = resultSet2Set(rs);
  73 +
  74 + prveLoadTime = t;
  75 + }catch(Exception e){
  76 + logger.error("", e);
  77 + }finally {
  78 + DBUtils_MS.close(rs, ps, conn);
  79 + }
  80 + }
  81 + return list;
  82 + }
  83 +
  84 + /**
  85 + *
  86 + * @Title: recovery
  87 + * @Description: TODO(从数据库恢复数据,按照线路的开始运营时间恢复)
  88 + */
  89 + public List<ArrivalEntity> recovery(){
  90 + Collection<LineConfig> confs = lineConfigData.getAll();
  91 + long t = System.currentTimeMillis()
  92 + ,st;
  93 +
  94 + List<ArrivalEntity> all = new ArrayList<>();
  95 + for(LineConfig conf : confs){
  96 + st = conf.getCurrStartTime();
  97 + if(t < st)
  98 + st = st - DAY_TIME;
  99 + try{
  100 + all.addAll(loadByLineAndTime(conf.getLine().getLineCode(), st, t));
  101 + }catch(Exception e){
  102 + logger.error("", e);
  103 + }
  104 + }
  105 +
  106 + prveLoadTime = t;
  107 + return all;
  108 + }
  109 +
  110 + /**
  111 + *
  112 + * @Title: loadByLineAndStartTime
  113 + * @Description: TODO(根据线路和时间戳加载数据)
  114 + */
  115 + public List<ArrivalEntity> loadByLineAndTime(String lineCode, long st, long et){
  116 + Calendar cal = Calendar.getInstance();
  117 + cal.setTimeInMillis(st);
  118 + int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);
  119 +
  120 + Connection conn = null;
  121 + PreparedStatement ps = null;
  122 + ResultSet rs = null;
  123 +
  124 + List<ArrivalEntity> list = new ArrayList<>();
  125 + String sql = "select * from bsth_c_arrival_info where weeks_year=? and line_id=? AND create_timestamp > ? AND create_timestamp <=? AND ABS(create_timestamp - ts) < 3600000 order by ts";
  126 + try{
  127 + conn = DBUtils_MS.getConnection();
  128 + ps = conn.prepareStatement(sql);
  129 + ps.setInt(1, weeks_year);
  130 + ps.setString(2, lineCode);
  131 + ps.setLong(3, st);
  132 + ps.setLong(4, et);
  133 + rs = ps.executeQuery();
  134 +
  135 + list = resultSet2Set(rs);
  136 + }catch(Exception e){
  137 + logger.error("", e);
  138 + }finally {
  139 + DBUtils_MS.close(rs, ps, conn);
  140 + }
  141 + return list;
  142 + }
  143 +
  144 + /**
  145 + *
  146 + * @Title: loadByLineAndStartTime
  147 + * @Description: TODO(根据线路,走向和时间戳加载数据)
  148 + */
  149 + public List<ArrivalEntity> loadByLineAndTime(String lineCode, int updown, long st, long et){
  150 + Calendar cal = Calendar.getInstance();
  151 + cal.setTimeInMillis(st);
  152 + int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);
  153 +
  154 + Connection conn = null;
  155 + PreparedStatement ps = null;
  156 + ResultSet rs = null;
  157 +
  158 + List<ArrivalEntity> list = new ArrayList<>();
  159 + String sql = "select * from bsth_c_arrival_info where weeks_year=? and line_id=? and up_down=? and in_out=0 AND create_timestamp > ? AND create_timestamp <=? AND ABS(create_timestamp - ts) < 3600000 order by ts";
  160 + try{
  161 + conn = DBUtils_MS.getConnection();
  162 + ps = conn.prepareStatement(sql);
  163 + ps.setInt(1, weeks_year);
  164 + ps.setString(2, lineCode);
  165 + ps.setInt(3, updown);
  166 + ps.setLong(4, st);
  167 + ps.setLong(5, et);
  168 + rs = ps.executeQuery();
  169 +
  170 + list = resultSet2Set(rs);
  171 + }catch(Exception e){
  172 + logger.error("", e);
  173 + }finally {
  174 + DBUtils_MS.close(rs, ps, conn);
  175 + }
  176 + return list;
  177 + }
  178 +
  179 + public List<ArrivalEntity> resultSet2Set(ResultSet rs) throws SQLException{
  180 + List<ArrivalEntity> list = new ArrayList<>();
  181 +
  182 + ArrivalEntity arr;
  183 + while(rs.next()){
  184 + arr = new ArrivalEntity();
  185 + arr.setDeviceId(rs.getString("device_id"));
  186 + arr.setNbbm(BasicData.deviceId2NbbmMap.get(arr.getDeviceId()));
  187 + if(null == arr.getNbbm()){
  188 + logger.warn("未注册的设备号," + arr.getDeviceId());
  189 + continue;
  190 + }
  191 +
  192 + arr.setTs(rs.getLong("ts"));
  193 + arr.setLineCode(rs.getString("line_id"));
  194 + arr.setUpDown(rs.getInt("up_down"));
  195 + arr.setStopNo(rs.getString("stop_no"));
  196 + arr.setStopName(BasicData.stationCode2NameMap.get(arr.getStopNo()));
  197 + arr.setInOut(rs.getInt("in_out"));
  198 + arr.setCreateDate(rs.getLong("create_timestamp"));
  199 + arr.setWeeksYear(rs.getInt("weeks_year"));
  200 + arr.setEnable(true);
  201 +
  202 + list.add(arr);
  203 + }
  204 + return list;
  205 + }
  206 +
  207 + public static void setPrveLoadTime(long t){
  208 + prveLoadTime = t;
  209 + }
  210 +}
src/main/java/com/bsth/data/arrival/ArrivalEntity.java renamed to src/main/java/com/bsth/data/forecast/entity/ArrivalEntity.java
1 -package com.bsth.data.arrival;  
2 -  
3 -import java.text.SimpleDateFormat;  
4 -import java.util.Date;  
5 -  
6 -import com.bsth.data.BasicData;  
7 -  
8 -/**  
9 - *  
10 - * @ClassName: ArrivalEntity  
11 - * @Description: TODO(进出站实体)  
12 - * @author PanZhao  
13 - * @date 2016年8月19日 上午9:32:20  
14 - *  
15 - */  
16 -public class ArrivalEntity {  
17 -  
18 - /** 设备号*/  
19 - private String deviceId;  
20 -  
21 - private String nbbm;  
22 -  
23 - /** 站点名称 */  
24 - private String stopName;  
25 -  
26 - /** 时间戳*/  
27 - private Long ts;  
28 -  
29 - /** 线路编码*/  
30 - private String lineCode;  
31 -  
32 - /** 上下行*/  
33 - private Integer upDown;  
34 -  
35 - /**站点编码*/  
36 - private String stopNo;  
37 -  
38 - /** 0: 进 1:出*/  
39 - private Integer inOut;  
40 -  
41 - private Long createDate;  
42 -  
43 - /** 是否有效 */  
44 - private boolean enable;  
45 -  
46 - /**分区字段,当年的第几周*/  
47 - private Integer weeksYear;  
48 -  
49 - private boolean tcc;  
50 -  
51 - //是否被纠正  
52 - private boolean correct;  
53 -  
54 - private String correctText;  
55 -  
56 - /** -1 则信号有效,但程序标记为不使用 */  
57 - private int flag = 0;  
58 -  
59 - public ArrivalEntity(){}  
60 -  
61 - public ArrivalEntity(String deviceId, long ts, String lineCode, int upDown, String stopNo, int inOut, long createDate,  
62 - int weeksYear, String stopName) {  
63 -  
64 - this.deviceId = deviceId;  
65 - this.ts = ts;  
66 - this.lineCode = lineCode;  
67 - this.upDown = upDown;  
68 - this.stopNo = stopNo;  
69 - this.stopName = stopName;  
70 - this.inOut = inOut;  
71 - this.createDate = createDate;  
72 - }  
73 -  
74 -/* @Override  
75 - public boolean equals(Object obj) {  
76 - ArrivalEntity a2 = (ArrivalEntity)obj;  
77 -  
78 - return this.toString().equals(a2.toString())  
79 - && Math.abs(this.ts - a2.ts) < EQ_RANGE;  
80 - }  
81 -  
82 - @Override  
83 - public int hashCode() {  
84 - return this.toString().hashCode();  
85 - }*/  
86 -  
87 -  
88 - @Override  
89 - public String toString() {  
90 - try {  
91 - SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");  
92 - return "["+BasicData.deviceId2NbbmMap.get(this.deviceId)+", "+sdfHHmm.format(new Date(this.ts))  
93 - +","+(this.getUpDown()==0?"上行":"下行")+","+(this.inOut==0?"进":"出")+","+this.stopNo+" ("+this.stopName+")]";  
94 - } catch (Exception e) {  
95 - return "";  
96 - }  
97 - }  
98 -  
99 - public String getLineCode() {  
100 - return lineCode;  
101 - }  
102 -  
103 - public void setLineCode(String lineCode) {  
104 - this.lineCode = lineCode;  
105 - }  
106 -  
107 - public Integer getUpDown() {  
108 - return upDown;  
109 - }  
110 -  
111 - public void setUpDown(Integer upDown) {  
112 - this.upDown = upDown;  
113 - }  
114 -  
115 - public String getStopNo() {  
116 - return stopNo;  
117 - }  
118 -  
119 - public void setStopNo(String stopNo) {  
120 - this.stopNo = stopNo;  
121 - }  
122 -  
123 - public Integer getInOut() {  
124 - return inOut;  
125 - }  
126 -  
127 - public void setInOut(Integer inOut) {  
128 - this.inOut = inOut;  
129 - }  
130 -  
131 - public Long getCreateDate() {  
132 - return createDate;  
133 - }  
134 -  
135 - public void setCreateDate(Long createDate) {  
136 - this.createDate = createDate;  
137 - }  
138 -  
139 - public Integer getWeeksYear() {  
140 - return weeksYear;  
141 - }  
142 -  
143 - public void setWeeksYear(Integer weeksYear) {  
144 - this.weeksYear = weeksYear;  
145 - }  
146 -  
147 - public String getDeviceId() {  
148 - return deviceId;  
149 - }  
150 -  
151 - public void setDeviceId(String deviceId) {  
152 - this.deviceId = deviceId;  
153 - }  
154 -  
155 - public Long getTs() {  
156 - return ts;  
157 - }  
158 -  
159 - public void setTs(Long ts) {  
160 - this.ts = ts;  
161 - }  
162 -  
163 - public String getStopName() {  
164 - return stopName;  
165 - }  
166 -  
167 - public void setStopName(String stopName) {  
168 - this.stopName = stopName;  
169 - }  
170 -  
171 - public String getId(){  
172 - return this.deviceId + "_" + this.ts;  
173 - }  
174 -  
175 - public String getNbbm() {  
176 - return nbbm;  
177 - }  
178 -  
179 - public void setNbbm(String nbbm) {  
180 - this.nbbm = nbbm;  
181 - }  
182 -  
183 - public boolean isEnable() {  
184 - return enable;  
185 - }  
186 -  
187 - public void setEnable(boolean enable) {  
188 - this.enable = enable;  
189 - }  
190 -  
191 - public boolean isTcc() {  
192 - return tcc;  
193 - }  
194 -  
195 - public void setTcc(boolean tcc) {  
196 - this.tcc = tcc;  
197 - }  
198 -  
199 - public boolean isOutTcc() {  
200 - return isTcc() && inOut == 1;  
201 - }  
202 -  
203 - public boolean isCorrect() {  
204 - return correct;  
205 - }  
206 -  
207 - public void setCorrect(boolean correct) {  
208 - this.correct = correct;  
209 - }  
210 -  
211 - public String getCorrectText() {  
212 - return correctText;  
213 - }  
214 -  
215 - public void setCorrectText(String correctText) {  
216 - this.correctText = correctText;  
217 - }  
218 -  
219 - public Integer getFlag() {  
220 - return flag;  
221 - }  
222 -  
223 - public void setFlag(Integer flag) {  
224 - this.flag = flag;  
225 - }  
226 -} 1 +package com.bsth.data.forecast.entity;
  2 +
  3 +import com.bsth.data.BasicData;
  4 +
  5 +import java.text.SimpleDateFormat;
  6 +import java.util.Date;
  7 +
  8 +/**
  9 + *
  10 + * @ClassName: ArrivalEntity
  11 + * @Description: TODO(进出站实体)
  12 + * @author PanZhao
  13 + * @date 2016年8月19日 上午9:32:20
  14 + *
  15 + */
  16 +public class ArrivalEntity {
  17 +
  18 + /** 设备号*/
  19 + private String deviceId;
  20 +
  21 + private String nbbm;
  22 +
  23 + /** 站点名称 */
  24 + private String stopName;
  25 +
  26 + /** 时间戳*/
  27 + private Long ts;
  28 +
  29 + /** 线路编码*/
  30 + private String lineCode;
  31 +
  32 + /** 上下行*/
  33 + private Integer upDown;
  34 +
  35 + /**站点编码*/
  36 + private String stopNo;
  37 +
  38 + /** 0: 进 1:出*/
  39 + private Integer inOut;
  40 +
  41 + private Long createDate;
  42 +
  43 + /** 是否有效 */
  44 + private boolean enable;
  45 +
  46 + /**分区字段,当年的第几周*/
  47 + private Integer weeksYear;
  48 +
  49 + private boolean tcc;
  50 +
  51 + //是否被纠正
  52 + private boolean correct;
  53 +
  54 + private String correctText;
  55 +
  56 + /** -1 则信号有效,但程序标记为不使用 */
  57 + private int flag = 0;
  58 +
  59 + public ArrivalEntity(){}
  60 +
  61 + public ArrivalEntity(String deviceId, long ts, String lineCode, int upDown, String stopNo, int inOut, long createDate,
  62 + int weeksYear, String stopName) {
  63 +
  64 + this.deviceId = deviceId;
  65 + this.ts = ts;
  66 + this.lineCode = lineCode;
  67 + this.upDown = upDown;
  68 + this.stopNo = stopNo;
  69 + this.stopName = stopName;
  70 + this.inOut = inOut;
  71 + this.createDate = createDate;
  72 + }
  73 +
  74 +/* @Override
  75 + public boolean equals(Object obj) {
  76 + ArrivalEntity a2 = (ArrivalEntity)obj;
  77 +
  78 + return this.toString().equals(a2.toString())
  79 + && Math.abs(this.ts - a2.ts) < EQ_RANGE;
  80 + }
  81 +
  82 + @Override
  83 + public int hashCode() {
  84 + return this.toString().hashCode();
  85 + }*/
  86 +
  87 +
  88 + @Override
  89 + public String toString() {
  90 + try {
  91 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
  92 + return "["+BasicData.deviceId2NbbmMap.get(this.deviceId)+", "+sdfHHmm.format(new Date(this.ts))
  93 + +","+(this.getUpDown()==0?"上行":"下行")+","+(this.inOut==0?"进":"出")+","+this.stopNo+" ("+this.stopName+")]";
  94 + } catch (Exception e) {
  95 + return "";
  96 + }
  97 + }
  98 +
  99 + public String getLineCode() {
  100 + return lineCode;
  101 + }
  102 +
  103 + public void setLineCode(String lineCode) {
  104 + this.lineCode = lineCode;
  105 + }
  106 +
  107 + public Integer getUpDown() {
  108 + return upDown;
  109 + }
  110 +
  111 + public void setUpDown(Integer upDown) {
  112 + this.upDown = upDown;
  113 + }
  114 +
  115 + public String getStopNo() {
  116 + return stopNo;
  117 + }
  118 +
  119 + public void setStopNo(String stopNo) {
  120 + this.stopNo = stopNo;
  121 + }
  122 +
  123 + public Integer getInOut() {
  124 + return inOut;
  125 + }
  126 +
  127 + public void setInOut(Integer inOut) {
  128 + this.inOut = inOut;
  129 + }
  130 +
  131 + public Long getCreateDate() {
  132 + return createDate;
  133 + }
  134 +
  135 + public void setCreateDate(Long createDate) {
  136 + this.createDate = createDate;
  137 + }
  138 +
  139 + public Integer getWeeksYear() {
  140 + return weeksYear;
  141 + }
  142 +
  143 + public void setWeeksYear(Integer weeksYear) {
  144 + this.weeksYear = weeksYear;
  145 + }
  146 +
  147 + public String getDeviceId() {
  148 + return deviceId;
  149 + }
  150 +
  151 + public void setDeviceId(String deviceId) {
  152 + this.deviceId = deviceId;
  153 + }
  154 +
  155 + public Long getTs() {
  156 + return ts;
  157 + }
  158 +
  159 + public void setTs(Long ts) {
  160 + this.ts = ts;
  161 + }
  162 +
  163 + public String getStopName() {
  164 + return stopName;
  165 + }
  166 +
  167 + public void setStopName(String stopName) {
  168 + this.stopName = stopName;
  169 + }
  170 +
  171 + public String getId(){
  172 + return this.deviceId + "_" + this.ts;
  173 + }
  174 +
  175 + public String getNbbm() {
  176 + return nbbm;
  177 + }
  178 +
  179 + public void setNbbm(String nbbm) {
  180 + this.nbbm = nbbm;
  181 + }
  182 +
  183 + public boolean isEnable() {
  184 + return enable;
  185 + }
  186 +
  187 + public void setEnable(boolean enable) {
  188 + this.enable = enable;
  189 + }
  190 +
  191 + public boolean isTcc() {
  192 + return tcc;
  193 + }
  194 +
  195 + public void setTcc(boolean tcc) {
  196 + this.tcc = tcc;
  197 + }
  198 +
  199 + public boolean isOutTcc() {
  200 + return isTcc() && inOut == 1;
  201 + }
  202 +
  203 + public boolean isCorrect() {
  204 + return correct;
  205 + }
  206 +
  207 + public void setCorrect(boolean correct) {
  208 + this.correct = correct;
  209 + }
  210 +
  211 + public String getCorrectText() {
  212 + return correctText;
  213 + }
  214 +
  215 + public void setCorrectText(String correctText) {
  216 + this.correctText = correctText;
  217 + }
  218 +
  219 + public Integer getFlag() {
  220 + return flag;
  221 + }
  222 +
  223 + public void setFlag(Integer flag) {
  224 + this.flag = flag;
  225 + }
  226 +}
src/main/java/com/bsth/data/gpsdata/GpsRealData.java
1 package com.bsth.data.gpsdata; 1 package com.bsth.data.gpsdata;
2 2
  3 +import com.bsth.Application;
3 import com.bsth.data.BasicData; 4 import com.bsth.data.BasicData;
4 import com.bsth.data.forecast.ForecastRealServer; 5 import com.bsth.data.forecast.ForecastRealServer;
5 import com.bsth.data.gpsdata.client.ClientApp; 6 import com.bsth.data.gpsdata.client.ClientApp;
@@ -16,6 +17,7 @@ import org.springframework.boot.CommandLineRunner; @@ -16,6 +17,7 @@ import org.springframework.boot.CommandLineRunner;
16 import org.springframework.stereotype.Component; 17 import org.springframework.stereotype.Component;
17 18
18 import java.util.*; 19 import java.util.*;
  20 +import java.util.concurrent.TimeUnit;
19 21
20 /** 22 /**
21 * @author PanZhao 23 * @author PanZhao
@@ -61,7 +63,7 @@ public class GpsRealData implements CommandLineRunner { @@ -61,7 +63,7 @@ public class GpsRealData implements CommandLineRunner {
61 //定时从网关http形式获取GPS数据 --- 已弃用,现socket客户端接入数据 63 //定时从网关http形式获取GPS数据 --- 已弃用,现socket客户端接入数据
62 //Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 20, 3, TimeUnit.SECONDS); 64 //Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 20, 3, TimeUnit.SECONDS);
63 //定时扫描掉离线 65 //定时扫描掉离线
64 - //Application.mainServices.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS); 66 + Application.mainServices.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);
65 67
66 //gps 客户端 68 //gps 客户端
67 //clientApp.init(); 69 //clientApp.init();
src/main/java/com/bsth/data/gpsdata/client/ClientApp.java
@@ -15,12 +15,12 @@ import org.apache.mina.filter.codec.ProtocolCodecFilter; @@ -15,12 +15,12 @@ import org.apache.mina.filter.codec.ProtocolCodecFilter;
15 import org.apache.mina.filter.logging.LogLevel; 15 import org.apache.mina.filter.logging.LogLevel;
16 import org.apache.mina.filter.logging.LoggingFilter; 16 import org.apache.mina.filter.logging.LoggingFilter;
17 import org.apache.mina.transport.socket.nio.NioSocketConnector; 17 import org.apache.mina.transport.socket.nio.NioSocketConnector;
  18 +import org.slf4j.Logger;
  19 +import org.slf4j.LoggerFactory;
18 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.stereotype.Component; 21 import org.springframework.stereotype.Component;
20 22
21 import java.net.InetSocketAddress; 23 import java.net.InetSocketAddress;
22 -import java.util.concurrent.ExecutorService;  
23 -import java.util.concurrent.Executors;  
24 24
25 /** 25 /**
26 * Created by panzhao on 2017/5/4. 26 * Created by panzhao on 2017/5/4.
@@ -30,7 +30,6 @@ public class ClientApp { @@ -30,7 +30,6 @@ public class ClientApp {
30 30
31 private static NioSocketConnector pdDataConnector; 31 private static NioSocketConnector pdDataConnector;
32 private static NioSocketConnector pfDataConnector; 32 private static NioSocketConnector pfDataConnector;
33 - private static ExecutorService exec;  
34 33
35 @Autowired 34 @Autowired
36 private PdClientHandler pdClient; 35 private PdClientHandler pdClient;
@@ -39,6 +38,8 @@ public class ClientApp { @@ -39,6 +38,8 @@ public class ClientApp {
39 @Autowired 38 @Autowired
40 GpsBeforeBuffer gpsBeforeBuffer; 39 GpsBeforeBuffer gpsBeforeBuffer;
41 40
  41 + static Logger logger = LoggerFactory.getLogger(ClientApp.class);
  42 +
42 public static boolean dconnect(String device) { 43 public static boolean dconnect(String device) {
43 boolean flag = false; 44 boolean flag = false;
44 try { 45 try {
@@ -59,6 +60,8 @@ public class ClientApp { @@ -59,6 +60,8 @@ public class ClientApp {
59 WriteFuture write = session.write(bytes); 60 WriteFuture write = session.write(bytes);
60 write.awaitUninterruptibly(); 61 write.awaitUninterruptibly();
61 flag = true; 62 flag = true;
  63 +
  64 + logger.info("dconnect...");
62 //SessionManager.getInstance().register(device, session); 65 //SessionManager.getInstance().register(device, session);
63 } catch (Exception e) { 66 } catch (Exception e) {
64 e.printStackTrace(); 67 e.printStackTrace();
@@ -74,6 +77,8 @@ public class ClientApp { @@ -74,6 +77,8 @@ public class ClientApp {
74 IoSession session = con.getSession(); 77 IoSession session = con.getSession();
75 session.setAttribute("deviceId", device); 78 session.setAttribute("deviceId", device);
76 flag = true; 79 flag = true;
  80 +
  81 + logger.info("fconnect...");
77 } catch (Exception e) { 82 } catch (Exception e) {
78 e.printStackTrace(); 83 e.printStackTrace();
79 } 84 }
@@ -81,7 +86,7 @@ public class ClientApp { @@ -81,7 +86,7 @@ public class ClientApp {
81 } 86 }
82 87
83 public void init() { 88 public void init() {
84 - exec = Executors.newFixedThreadPool(4); 89 + //exec = Executors.newFixedThreadPool(4);
85 //sexec.scheduleAtFixedRate(new SessionChecker(), 1, 1, TimeUnit.MINUTES); 90 //sexec.scheduleAtFixedRate(new SessionChecker(), 1, 1, TimeUnit.MINUTES);
86 /*******************************浦东********************************/ 91 /*******************************浦东********************************/
87 pdDataConnector = new NioSocketConnector(); 92 pdDataConnector = new NioSocketConnector();
src/main/java/com/bsth/data/gpsdata/client/GpsBeforeBuffer.java
@@ -63,7 +63,7 @@ public class GpsBeforeBuffer { @@ -63,7 +63,7 @@ public class GpsBeforeBuffer {
63 } 63 }
64 64
65 public void init(){ 65 public void init(){
66 - Application.mainServices.scheduleWithFixedDelay(gpsHandleThread, 20, 2, TimeUnit.SECONDS); 66 + Application.mainServices.scheduleWithFixedDelay(gpsHandleThread, 20 * 1000, 1100, TimeUnit.MILLISECONDS);
67 } 67 }
68 68
69 @Component 69 @Component
src/main/java/com/bsth/data/match/Arrival2Schedule.java deleted 100644 → 0
1 -package com.bsth.data.match;  
2 -  
3 -import java.util.ArrayList;  
4 -import java.util.Collections;  
5 -import java.util.List;  
6 -import java.util.Set;  
7 -  
8 -import org.joda.time.format.DateTimeFormat;  
9 -import org.joda.time.format.DateTimeFormatter;  
10 -import org.slf4j.Logger;  
11 -import org.slf4j.LoggerFactory;  
12 -import org.springframework.beans.BeansException;  
13 -import org.springframework.context.ApplicationContext;  
14 -import org.springframework.context.ApplicationContextAware;  
15 -import org.springframework.stereotype.Component;  
16 -  
17 -import com.bsth.data.LineConfigData;  
18 -import com.bsth.data.arrival.ArrivalComparator;  
19 -import com.bsth.data.arrival.ArrivalData_GPS;  
20 -import com.bsth.data.arrival.ArrivalEntity;  
21 -import com.bsth.data.schedule.DayOfSchedule;  
22 -import com.bsth.data.schedule.ScheduleComparator;  
23 -import com.bsth.entity.realcontrol.LineConfig;  
24 -import com.bsth.entity.realcontrol.ScheduleRealInfo;  
25 -import com.bsth.service.directive.DirectiveService;  
26 -import com.bsth.websocket.handler.SendUtils;  
27 -import com.google.common.collect.ArrayListMultimap;  
28 -  
29 -/**  
30 - *  
31 - * @ClassName: Arrival2Schedule  
32 - * @Description: TODO(到离站数据 和 计划班次进行匹配 注意线程安全!!!!)  
33 - * @author PanZhao  
34 - * @date 2016年8月28日 上午1:13:02  
35 - *  
36 - */  
37 -@Component  
38 -public class Arrival2Schedule implements ApplicationContextAware {  
39 -  
40 - private static DayOfSchedule dayOfSchedule;  
41 - private static SendUtils sendUtils;  
42 - private static DirectiveService directiveService;  
43 - private static LineConfigData lineConfigData;  
44 - private final static int ONE_MINUTE = 1000 * 60;  
45 - //定一个4小时的范围,基本能对正常班次进行容错。主要防止早上停车场GPS飘导致完成晚上的进场班次  
46 - private final static int FOUR_HOURS = 1000 * 60 * 60 * 4;  
47 -  
48 - private static Logger logger = LoggerFactory.getLogger(Arrival2Schedule.class);  
49 -  
50 - private static ArrayListMultimap<String, ExpectArrivalEnd> expectMap = ArrayListMultimap.create();  
51 -  
52 - /**  
53 - *  
54 - * @Title: start  
55 - * @Description: TODO(开始)  
56 - * @param @param cars 需要匹配的车辆集合  
57 - */  
58 - public static void start(Set<String> cars){  
59 -  
60 - for(String car : cars){  
61 - new SchMatchThread(car).start();  
62 - }  
63 - }  
64 -  
65 - public static class SchMatchThread extends Thread{  
66 - String nbbm;  
67 - LineConfig conf;  
68 -  
69 - public SchMatchThread(String nbbm){  
70 - this.nbbm = nbbm;  
71 - }  
72 -  
73 - //排序器  
74 - private ScheduleComparator.FCSJ schComparator = new ScheduleComparator.FCSJ();  
75 - private ArrivalComparator arrComparator = new ArrivalComparator();  
76 - private MatchResultComparator mrComparator = new MatchResultComparator();  
77 -  
78 - private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm");  
79 -  
80 - @Override  
81 - public void run() {  
82 - //班次列表  
83 - List<ScheduleRealInfo> schList = dayOfSchedule.findByNbbm(nbbm);  
84 - //进出起终点数据  
85 - List<ArrivalEntity> arrList = ArrivalData_GPS.findByNbbm(nbbm);  
86 -  
87 - if(schList.size() == 0 || arrList.size() == 0)  
88 - return;  
89 -  
90 - conf = lineConfigData.get(schList.get(0).getXlBm());  
91 - //排序  
92 - Collections.sort(schList, schComparator);  
93 - Collections.sort(arrList, arrComparator);  
94 - //过滤班次  
95 - schList = matchFilter(schList);  
96 -  
97 - //检查并修正首班出场终点信号,可能会出现走向异常  
98 - correctFirstSignal(schList, arrList);  
99 -  
100 -  
101 - //用实际来匹配计划  
102 - for(ArrivalEntity arr : arrList){  
103 - match(arr, schList);  
104 - }  
105 - }  
106 -  
107 - private void match(ArrivalEntity arr, List<ScheduleRealInfo> schList) {  
108 -  
109 - if(arr.getInOut() == 1)  
110 - matchOut(arr, schList);  
111 - else if(arr.getInOut() == 0)  
112 - matchIn(arr, schList);  
113 - }  
114 -  
115 - private List<ScheduleRealInfo> matchFilter(List<ScheduleRealInfo> schList) {  
116 - List<ScheduleRealInfo> list = new ArrayList<>();  
117 - for(ScheduleRealInfo sch : schList){  
118 - //烂班不匹配  
119 - if(sch.isDestroy())  
120 - continue;  
121 -  
122 - //线路配置出站既出场,并且没有里程的不匹配  
123 - if(conf.getOutConfig()==2 && sch.getBcsj() == null && sch.getJhlc() == null)  
124 - continue;  
125 -  
126 - list.add(sch);  
127 - }  
128 - return list;  
129 - }  
130 -  
131 - private void matchOut(ArrivalEntity arr, List<ScheduleRealInfo> schList){  
132 - if(arr.getFlag() == -1)  
133 - return;  
134 -  
135 - List<MatchResult> mrs = new ArrayList<>();  
136 - ScheduleRealInfo sch;  
137 - MatchResult mr;  
138 - for(int i = 0; i < schList.size(); i ++){  
139 - sch = schList.get(i);  
140 - if(!arr.isTcc() && arr.getUpDown() != Integer.parseInt(sch.getXlDir()))  
141 - continue;  
142 -  
143 - if(!arr.getStopNo().equals(sch.getQdzCode()))  
144 - continue;  
145 -  
146 - //班次有实发时间  
147 - if(sch.getFcsjActualTime() != null){  
148 - //实际发车已经被引用  
149 - if(Math.abs(arr.getTs() - sch.getFcsjActualTime()) < ONE_MINUTE)  
150 - return;  
151 - else  
152 - continue;  
153 - }  
154 - //添加一个匹配结果  
155 - mr = new MatchResult();  
156 - mr.sch = sch;  
157 - mr.ts = arr.getTs();  
158 - mr.diff = arr.getTs() - sch.getFcsjT();  
159 - mr.success = dayOfSchedule.validStartTime(sch, arr.getTs());  
160 -  
161 - if(Math.abs(mr.diff) < FOUR_HOURS && mr.success)  
162 - mrs.add(mr);  
163 - }  
164 -  
165 - if(mrs.size() > 0){  
166 - //排序后的第一个 就是最合适的匹配  
167 - Collections.sort(mrs, mrComparator);  
168 - mr = mrs.get(0);  
169 -  
170 - //漂移判定  
171 - if(driftCheck(mr, arr)){  
172 - carOut(mr);  
173 - }  
174 - }  
175 - }  
176 -  
177 - private void matchIn(ArrivalEntity inArr, List<ScheduleRealInfo> schList){  
178 -  
179 - List<MatchResult> mrs = new ArrayList<>();  
180 - ScheduleRealInfo sch;  
181 - MatchResult mr;  
182 - for(int i = 0; i < schList.size(); i ++){  
183 - sch = schList.get(i);  
184 - if(!inArr.isTcc() && inArr.getUpDown() != Integer.parseInt(sch.getXlDir()))  
185 - continue;  
186 -  
187 - if(!inArr.getStopNo().equals(sch.getZdzCode()))  
188 - continue;  
189 -  
190 - //班次有实达时间  
191 - if(sch.getZdsjActualTime() != null){  
192 - //实际到达已经被引用  
193 - if(Math.abs(inArr.getTs() - sch.getZdsjActualTime()) < ONE_MINUTE)  
194 - return;  
195 - else  
196 - continue;  
197 - }  
198 -  
199 - //添加一个匹配结果  
200 - mr = new MatchResult();  
201 - mr.sch = sch;  
202 - mr.ts = inArr.getTs();  
203 - //班次没有里程和运送时间的  
204 - if(sch.getZdsj() == null){  
205 - if(i < schList.size()-1)  
206 - mr.diff = inArr.getTs() - schList.get(i + 1).getDfsjT();  
207 - else  
208 - mr.diff = inArr.getTs() - sch.getDfsjT();  
209 - }  
210 - else  
211 - mr.diff = inArr.getTs() - sch.getZdsjT();  
212 - mr.success = dayOfSchedule.validEndTime(sch, inArr.getTs());  
213 - if(Math.abs(mr.diff) < FOUR_HOURS && mr.success)  
214 - mrs.add(mr);  
215 - }  
216 -  
217 - if(mrs.size() > 0){  
218 - //排序后的第一个 就是最合适的匹配  
219 - Collections.sort(mrs, mrComparator);  
220 - mr = mrs.get(0);  
221 - carInStop(mr);  
222 - }  
223 - }  
224 -  
225 - /**  
226 - *  
227 - * @Title: carOut  
228 - * @Description: TODO(车辆发出)  
229 - */  
230 - public void carOut(MatchResult mr){  
231 - ScheduleRealInfo sch = mr.sch;  
232 -  
233 - if(!isExpectOut(mr))  
234 - return;  
235 - //设置发车时间  
236 - sch.setFcsjActualAll(mr.ts);  
237 - //通知客户端  
238 - sendUtils.sendFcsj(sch);  
239 - //持久化  
240 - dayOfSchedule.save(sch);  
241 - //车辆当前执行班次  
242 - dayOfSchedule.addExecPlan(sch);  
243 -  
244 - //期望车辆到达的终点  
245 - if(sch.getZdsj() != null)  
246 - expectMap.put(nbbm, ExpectArrivalEnd.getEndInstance(sch, mr.ts));  
247 - }  
248 -  
249 - /**  
250 - *  
251 - * @Title: isExpectOut  
252 - * @Description: TODO(是否是一个期望的出站匹配结果)  
253 - */  
254 - private boolean isExpectOut(MatchResult mr){  
255 - ScheduleRealInfo sch = mr.sch;  
256 - String nbbm = sch.getClZbh();  
257 - if(expectMap.containsKey(nbbm)){  
258 - List<ExpectArrivalEnd> eads = expectMap.get(nbbm);  
259 - for(ExpectArrivalEnd ead : eads){  
260 - if(sch.getQdzCode().equals(ead.getEndStation())  
261 - || mr.ts > ead.getEndTime()){  
262 - expectMap.removeAll(nbbm);  
263 - return true;  
264 - }  
265 - }  
266 - return false;  
267 - }  
268 - return true;  
269 - }  
270 -  
271 - /**  
272 - *  
273 - * @Title: carInStop  
274 - * @Description: TODO(车辆进入终点站)  
275 - */  
276 - public void carInStop(MatchResult mr){  
277 - ScheduleRealInfo sch = mr.sch;  
278 - String nbbm=sch.getClZbh();  
279 - if(!isExpectIn(mr))  
280 - return;  
281 -  
282 - //如果是进停车场,并且实达时间差值大于 30 分钟,并且之前还有未完成班次。  
283 - if(sch.getBcType().equals("in") && Math.abs(mr.diff) > (1000 * 60 * 30)){  
284 - int prve_nen = dayOfSchedule.prveNotExecNum(sch);  
285 - if(prve_nen > 0)  
286 - return;  
287 - }  
288 -  
289 - sch.setZdsjActualAll(mr.ts);  
290 - int doneSum = dayOfSchedule.doneSum(nbbm);  
291 - ScheduleRealInfo next = dayOfSchedule.next(sch);  
292 - if(null != next){  
293 - next.setQdzArrDateSJ(sch.getZdsjActual());  
294 - //下发调度指令  
295 - directiveService.send60Dispatch(next, doneSum, "到站@系统");  
296 -  
297 - //完成“起点既停车场”的进场班次  
298 - if(next.getBcType().equals("in") && next.getJhlc() == null)  
299 - next.setFcsjActualAll(mr.ts);  
300 -  
301 - //套跑 -下发线路切换指令  
302 - if(!next.getXlBm().equals(sch.getXlBm()))  
303 - directiveService.lineChange(nbbm, next.getXlBm(), "套跑@系统");  
304 - }  
305 - else//下发文本指令(已结束运营)  
306 - directiveService.send60Phrase(nbbm, "到达终点 " + sch.getZdzName() + ",已完成当日所有排班。", "系统");  
307 - //通知客户端  
308 - sendUtils.sendZdsj(sch, next, doneSum);  
309 - //持久化  
310 - dayOfSchedule.save(sch);  
311 - logger.info(sch.getClZbh() + "移除正在执行班次," + sch.getFcsj());  
312 - //移除车辆正在执行班次索引  
313 - dayOfSchedule.removeExecPlan(nbbm);  
314 - }  
315 -  
316 - /**  
317 - *  
318 - * @Title: isExpectOut  
319 - * @Description: TODO(是否是一个期望的进站匹配结果)  
320 - */  
321 - private boolean isExpectIn(MatchResult mr){  
322 - ScheduleRealInfo sch = mr.sch;  
323 - String nbbm = sch.getClZbh();  
324 - if(expectMap.containsKey(nbbm)){  
325 - List<ExpectArrivalEnd> eads = expectMap.get(nbbm);  
326 - for(ExpectArrivalEnd ead : eads){  
327 - if(sch.getZdzCode().equals(ead.getEndStation())  
328 - || mr.ts > ead.getEndTime()){  
329 - expectMap.removeAll(nbbm);  
330 - return true;  
331 - }  
332 - }  
333 - return false;  
334 - }  
335 - return true;  
336 - }  
337 -  
338 - /**  
339 - *  
340 - * @Title: correctFirstSignal  
341 - * @Description: TODO(检查并纠正首班出场到离站)  
342 - */  
343 - private final static long TEN_MINUTES = 1000 * 60 * 10;  
344 - private void correctFirstSignal(List<ScheduleRealInfo> schList, List<ArrivalEntity> arrList) {  
345 - ScheduleRealInfo sch = schList.get(0);  
346 - ArrivalEntity arr = arrList.get(0);  
347 -  
348 - //有里程的出场班次才需要纠正  
349 - if(arr.isCorrect() || !sch.getBcType().equals("out") || sch.getJhlc() == null || sch.getBcsj() == null)  
350 - return;  
351 -  
352 - //如果首个进出站信号是出场  
353 - if(arr.isOutTcc() && arrList.size() >= 2)  
354 - arr = arrList.get(1);  
355 - else  
356 - return;  
357 -  
358 - //出场任务 “进终点” 信号才需要纠正  
359 - if(arr.getInOut() != 0)  
360 - return;  
361 -  
362 - //在计划终点之前到达,或者之后10分钟内到达  
363 - if(arr.getTs() < sch.getZdsjT()  
364 - || arr.getTs() - sch.getZdsjT() < TEN_MINUTES){  
365 -  
366 - int upDown = Integer.parseInt(sch.getXlDir());  
367 - //走向不一致,相信班次的走向。纠正进站信号  
368 - if(arr.getUpDown() != upDown  
369 - && arr.getStopName().equals(sch.getZdzName())){  
370 -  
371 -  
372 - String old = arr.toString();  
373 - arr.setUpDown(upDown);  
374 - arr.setStopNo(sch.getZdzCode());  
375 - arr.setCorrect(true);  
376 - arr.setCorrectText(old + " | " + arr.toString());  
377 -  
378 - logger.info("被纠正的信号:" + arr.getCorrectText());  
379 - }  
380 - }  
381 - }  
382 -  
383 - /**  
384 - *  
385 - * @Title: driftCheck  
386 - * @Description: TODO(漂移判定)  
387 - */  
388 - public boolean driftCheck(MatchResult mr, ArrivalEntity arr){  
389 - try{  
390 - //上行发车,和到达时间比较一下。起点一般不会立即发出  
391 - if(mr.sch.getXlDir().equals("0")  
392 - && null != mr.sch.getQdzArrDateSJ()){  
393 -  
394 -  
395 - long dt = fmtyyyyMMddHHmm.parseMillis(mr.sch.getRealExecDate() + mr.sch.getQdzArrDateSJ());  
396 -  
397 - //停站时间少于 计划的3分之1,标记为漂移信号  
398 - if((mr.ts - dt < (mr.sch.getDfsjT() - dt) / 3)){  
399 - arr.setCorrect(true);  
400 - arr.setCorrectText("停站时间太短,标记为信号漂移");  
401 - arr.setFlag(-1);  
402 -  
403 - logger.info("漂移判定:" + arr);  
404 - return false;  
405 - }  
406 - }  
407 - }catch(Exception e){  
408 - logger.error("", e);  
409 - }  
410 - return true;  
411 - }  
412 - }  
413 -  
414 - @Override  
415 - public void setApplicationContext(ApplicationContext arg0) throws BeansException {  
416 - sendUtils = arg0.getBean(SendUtils.class);  
417 - dayOfSchedule = arg0.getBean(DayOfSchedule.class);  
418 - directiveService = arg0.getBean(DirectiveService.class);  
419 - lineConfigData = arg0.getBean(LineConfigData.class);  
420 - }  
421 -  
422 - /**  
423 - *  
424 - * @Title: removeExpect  
425 - * @Description: TODO(清除预期站点)  
426 - * @param @param nbbm  
427 - */  
428 - public void removeExpect(String nbbm){  
429 - expectMap.removeAll(nbbm);  
430 - }  
431 -  
432 - public static void addExpect(String nbbm, ExpectArrivalEnd eae){  
433 - expectMap.put(nbbm, eae);  
434 - }  
435 -}  
src/main/java/com/bsth/data/match/ExpectArrivalEnd.java deleted 100644 → 0
1 -package com.bsth.data.match;  
2 -  
3 -import com.bsth.entity.realcontrol.ScheduleRealInfo;  
4 -  
5 -/**  
6 - *  
7 - * @ClassName: ExpectArrivalEnd  
8 - * @Description: TODO(期望车辆在某个时间段到达某个终点或 发出某个起点........)  
9 - * @author PanZhao  
10 - * @date 2016年11月2日 下午8:04:43  
11 - *  
12 - */  
13 -public class ExpectArrivalEnd {  
14 -  
15 - private String nbbm;  
16 -  
17 - private String endStation;  
18 -  
19 - private Long endTime;  
20 -  
21 - public static ExpectArrivalEnd getEndInstance(ScheduleRealInfo sch, long t){  
22 - ExpectArrivalEnd ead = new ExpectArrivalEnd();  
23 - ead.setNbbm(sch.getClZbh());  
24 - ead.setEndStation(sch.getZdzCode());  
25 - if(sch.getBcType().equals("out"))  
26 - ead.setEndTime(sch.getZdsjT());  
27 - else{  
28 - ead.setEndTime(sch.getZdsjT() - (sch.getDfsjT() - t));  
29 - }  
30 - return ead;  
31 - }  
32 -  
33 -  
34 - public String getNbbm() {  
35 - return nbbm;  
36 - }  
37 -  
38 - public void setNbbm(String nbbm) {  
39 - this.nbbm = nbbm;  
40 - }  
41 -  
42 - public String getEndStation() {  
43 - return endStation;  
44 - }  
45 -  
46 - public void setEndStation(String endStation) {  
47 - this.endStation = endStation;  
48 - }  
49 -  
50 - public Long getEndTime() {  
51 - return endTime;  
52 - }  
53 -  
54 - public void setEndTime(Long endTime) {  
55 - this.endTime = endTime;  
56 - }  
57 -}  
src/main/java/com/bsth/data/match/MatchResult.java deleted 100644 → 0
1 -package com.bsth.data.match;  
2 -  
3 -import com.bsth.entity.realcontrol.ScheduleRealInfo;  
4 -  
5 -/**  
6 - *  
7 - * @ClassName: MatchResult  
8 - * @Description: TODO(实际和计划匹配结果)  
9 - * @author PanZhao  
10 - * @date 2016年8月10日 下午3:55:48  
11 - *  
12 - */  
13 -public class MatchResult {  
14 -  
15 - /** 班次 */  
16 - public ScheduleRealInfo sch;  
17 -  
18 - /** 时间差 */  
19 - public long diff;  
20 -  
21 - /** 0 进 1 出 */  
22 - public int inOut;  
23 -  
24 - public long ts;  
25 -  
26 - /** 交配成功 */  
27 - public boolean success;  
28 -}  
src/main/java/com/bsth/data/match/MatchResultComparator.java deleted 100644 → 0
1 -package com.bsth.data.match;  
2 -  
3 -import java.util.Comparator;  
4 -  
5 -public class MatchResultComparator implements Comparator<MatchResult>{  
6 -  
7 - @Override  
8 - public int compare(MatchResult o1, MatchResult o2) {  
9 - return (int) (Math.abs(o1.diff) - Math.abs(o2.diff));  
10 - }  
11 -}  
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
@@ -1023,4 +1023,8 @@ public class DayOfSchedule implements CommandLineRunner { @@ -1023,4 +1023,8 @@ public class DayOfSchedule implements CommandLineRunner {
1023 Collections.sort(list, schFCSJComparator); 1023 Collections.sort(list, schFCSJComparator);
1024 return next(list, sch); 1024 return next(list, sch);
1025 } 1025 }
  1026 +
  1027 + public ArrayListMultimap<String, ScheduleRealInfo> getLpScheduleMap(){
  1028 + return lpScheduleMap;
  1029 + }
1026 } 1030 }
1027 \ No newline at end of file 1031 \ No newline at end of file
src/main/java/com/bsth/entity/forecast/Sample.java
1 package com.bsth.entity.forecast; 1 package com.bsth.entity.forecast;
2 2
3 3
4 -import java.text.SimpleDateFormat;  
5 -import java.util.Date;  
6 -  
7 -import javax.persistence.Entity;  
8 -import javax.persistence.GeneratedValue;  
9 -import javax.persistence.Id;  
10 -import javax.persistence.Table;  
11 -import javax.persistence.Transient;  
12 - 4 +import com.bsth.data.forecast.entity.ArrivalEntity;
13 import org.slf4j.Logger; 5 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory; 6 import org.slf4j.LoggerFactory;
15 7
16 -import com.bsth.data.arrival.ArrivalEntity; 8 +import javax.persistence.*;
17 9
18 /** 10 /**
19 * 11 *
src/main/java/com/bsth/entity/realcontrol/ScheduleRealInfo.java
@@ -200,6 +200,10 @@ public class ScheduleRealInfo { @@ -200,6 +200,10 @@ public class ScheduleRealInfo {
200 /** 是否有补发GPS信号 */ 200 /** 是否有补发GPS信号 */
201 private boolean reissue; 201 private boolean reissue;
202 202
  203 + /** 发车屏 发车顺序号,不持久化,会动态变化 */
  204 + @Transient
  205 + private int fcpSn;
  206 +
203 public boolean isDfAuto() { 207 public boolean isDfAuto() {
204 return dfAuto; 208 return dfAuto;
205 } 209 }
@@ -912,4 +916,12 @@ public class ScheduleRealInfo { @@ -912,4 +916,12 @@ public class ScheduleRealInfo {
912 public void setLate2(boolean late2) { 916 public void setLate2(boolean late2) {
913 this.late2 = late2; 917 this.late2 = late2;
914 } 918 }
  919 +
  920 + public int getFcpSn() {
  921 + return fcpSn;
  922 + }
  923 +
  924 + public void setFcpSn(int fcpSn) {
  925 + this.fcpSn = fcpSn;
  926 + }
915 } 927 }
src/main/java/com/bsth/service/forecast/SampleServiceImpl.java
1 package com.bsth.service.forecast; 1 package com.bsth.service.forecast;
2 2
3 -import java.text.SimpleDateFormat;  
4 -import java.util.ArrayList;  
5 -import java.util.Collections;  
6 -import java.util.Comparator;  
7 -import java.util.HashMap;  
8 -import java.util.Iterator;  
9 -import java.util.List;  
10 -import java.util.Map;  
11 -  
12 -import javax.transaction.Transactional;  
13 -  
14 -import org.slf4j.Logger;  
15 -import org.slf4j.LoggerFactory;  
16 -import org.springframework.beans.factory.annotation.Autowired;  
17 -import org.springframework.stereotype.Service;  
18 -  
19 import com.bsth.common.ResponseCode; 3 import com.bsth.common.ResponseCode;
20 import com.bsth.controller.forecast.dto.CreateSampleParam; 4 import com.bsth.controller.forecast.dto.CreateSampleParam;
21 import com.bsth.data.BasicData; 5 import com.bsth.data.BasicData;
22 -import com.bsth.data.arrival.ArrivalEntity;  
23 -import com.bsth.data.arrival.DataLoader; 6 +import com.bsth.data.forecast.ArrivalDataLoader;
  7 +import com.bsth.data.forecast.entity.ArrivalEntity;
24 import com.bsth.entity.forecast.Sample; 8 import com.bsth.entity.forecast.Sample;
25 import com.bsth.repository.forecast.SampleRepository; 9 import com.bsth.repository.forecast.SampleRepository;
26 import com.bsth.service.forecast.util.CreateByArrivalData; 10 import com.bsth.service.forecast.util.CreateByArrivalData;
27 import com.bsth.service.impl.BaseServiceImpl; 11 import com.bsth.service.impl.BaseServiceImpl;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.stereotype.Service;
  16 +
  17 +import javax.transaction.Transactional;
  18 +import java.text.SimpleDateFormat;
  19 +import java.util.*;
28 20
29 @Service 21 @Service
30 public class SampleServiceImpl extends BaseServiceImpl<Sample, Long> implements SampleService{ 22 public class SampleServiceImpl extends BaseServiceImpl<Sample, Long> implements SampleService{
@@ -80,7 +72,7 @@ public class SampleServiceImpl extends BaseServiceImpl&lt;Sample, Long&gt; implements @@ -80,7 +72,7 @@ public class SampleServiceImpl extends BaseServiceImpl&lt;Sample, Long&gt; implements
80 sampleRepository.deleteByLineAndUpdown(param.getLineCode(), param.getUpdown()); 72 sampleRepository.deleteByLineAndUpdown(param.getLineCode(), param.getUpdown());
81 73
82 //查询到离站数据 74 //查询到离站数据
83 - DataLoader loader = new DataLoader(); 75 + ArrivalDataLoader loader = new ArrivalDataLoader();
84 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 76 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
85 77
86 long st = sdf.parse(param.getStartDate()).getTime() 78 long st = sdf.parse(param.getStartDate()).getTime()
src/main/java/com/bsth/service/forecast/util/CreateByArrivalData.java
1 package com.bsth.service.forecast.util; 1 package com.bsth.service.forecast.util;
2 2
3 -import java.text.DecimalFormat;  
4 -import java.text.ParseException;  
5 -import java.text.SimpleDateFormat;  
6 -import java.util.ArrayList;  
7 -import java.util.Collections;  
8 -import java.util.Comparator;  
9 -import java.util.Date;  
10 -import java.util.HashMap;  
11 -import java.util.List;  
12 -import java.util.Map;  
13 -import java.util.Set;  
14 -  
15 -import org.slf4j.Logger;  
16 -import org.slf4j.LoggerFactory;  
17 -import org.springframework.beans.factory.annotation.Autowired;  
18 -import org.springframework.context.annotation.Scope;  
19 -import org.springframework.stereotype.Component;  
20 -  
21 import com.bsth.controller.forecast.dto.CreateSampleParam; 3 import com.bsth.controller.forecast.dto.CreateSampleParam;
22 import com.bsth.controller.forecast.dto.CreateSampleParam.TimeRange; 4 import com.bsth.controller.forecast.dto.CreateSampleParam.TimeRange;
23 -import com.bsth.data.arrival.ArrivalComparator;  
24 -import com.bsth.data.arrival.ArrivalEntity; 5 +import com.bsth.data.forecast.ArrivalComparator;
  6 +import com.bsth.data.forecast.entity.ArrivalEntity;
25 import com.bsth.entity.StationRoute; 7 import com.bsth.entity.StationRoute;
26 import com.bsth.entity.forecast.Sample; 8 import com.bsth.entity.forecast.Sample;
27 import com.bsth.repository.StationRouteRepository; 9 import com.bsth.repository.StationRouteRepository;
28 import com.google.common.collect.ArrayListMultimap; 10 import com.google.common.collect.ArrayListMultimap;
  11 +import org.slf4j.Logger;
  12 +import org.slf4j.LoggerFactory;
  13 +import org.springframework.beans.factory.annotation.Autowired;
  14 +import org.springframework.context.annotation.Scope;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +import java.text.DecimalFormat;
  18 +import java.text.ParseException;
  19 +import java.text.SimpleDateFormat;
  20 +import java.util.*;
29 21
30 /** 22 /**
31 * 23 *
src/main/java/com/bsth/service/gps/GpsServiceImpl.java
@@ -2,7 +2,7 @@ package com.bsth.service.gps; @@ -2,7 +2,7 @@ package com.bsth.service.gps;
2 2
3 import com.bsth.common.ResponseCode; 3 import com.bsth.common.ResponseCode;
4 import com.bsth.data.BasicData; 4 import com.bsth.data.BasicData;
5 -import com.bsth.data.arrival.ArrivalEntity; 5 +import com.bsth.data.forecast.entity.ArrivalEntity;
6 import com.bsth.data.gpsdata.GpsEntity; 6 import com.bsth.data.gpsdata.GpsEntity;
7 import com.bsth.data.gpsdata.GpsRealData; 7 import com.bsth.data.gpsdata.GpsRealData;
8 import com.bsth.data.gpsdata.arrival.utils.GeoUtils; 8 import com.bsth.data.gpsdata.arrival.utils.GeoUtils;
src/main/java/com/bsth/service/gps/entity/HistoryGps_DTO.java
@@ -2,7 +2,7 @@ package com.bsth.service.gps.entity; @@ -2,7 +2,7 @@ package com.bsth.service.gps.entity;
2 2
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
5 -import com.bsth.data.arrival.ArrivalEntity; 5 +import com.bsth.data.forecast.entity.ArrivalEntity;
6 import com.fasterxml.jackson.annotation.JsonIgnore; 6 import com.fasterxml.jackson.annotation.JsonIgnore;
7 import com.vividsolutions.jts.geom.Coordinate; 7 import com.vividsolutions.jts.geom.Coordinate;
8 import com.vividsolutions.jts.geom.GeometryFactory; 8 import com.vividsolutions.jts.geom.GeometryFactory;
src/main/resources/static/real_control_v2/js/main.js
@@ -169,8 +169,8 @@ var disabled_submit_btn = function (form) { @@ -169,8 +169,8 @@ var disabled_submit_btn = function (form) {
169 function showUpdateDescription() { 169 function showUpdateDescription() {
170 //更新说明 170 //更新说明
171 var updateDescription = { 171 var updateDescription = {
172 - date: '2017-05-04',  
173 - text: '<h5>修复了一个问题,该问题导致在应急停靠时间设置为0的时候,待发时间不会自动调整。</h5>' 172 + date: '2017-05-07',
  173 + text: '<h5>修复了一个问题,该问题导致在某些特定情况下,报出的发车时间比实际的要晚1~3分钟。</h5>'
174 }; 174 };
175 175
176 var storage = window.localStorage 176 var storage = window.localStorage