Commit 9546557304b17c129855993cb112a99ebc39d1e0

Authored by 潘钊
2 parents 3bddd74e d343d965

update...

Too many changes to show.

To preserve performance only 11 of 16 files are displayed.

src/main/java/com/bsth/controller/oil/DlbController.java
@@ -21,6 +21,7 @@ import com.bsth.controller.BaseController; @@ -21,6 +21,7 @@ import com.bsth.controller.BaseController;
21 import com.bsth.entity.oil.Dlb; 21 import com.bsth.entity.oil.Dlb;
22 import com.bsth.entity.oil.Ylb; 22 import com.bsth.entity.oil.Ylb;
23 import com.bsth.service.oil.DlbService; 23 import com.bsth.service.oil.DlbService;
  24 +import com.bsth.util.Arith;
24 import com.bsth.util.ReportUtils; 25 import com.bsth.util.ReportUtils;
25 import com.google.common.base.Splitter; 26 import com.google.common.base.Splitter;
26 27
@@ -164,10 +165,10 @@ public class DlbController extends BaseController<Dlb, Integer>{ @@ -164,10 +165,10 @@ public class DlbController extends BaseController<Dlb, Integer>{
164 String shyy ="无"; 165 String shyy ="无";
165 if(y.getShyy()!=null){ 166 if(y.getShyy()!=null){
166 shyy=y.getShyy(); 167 shyy=y.getShyy();
167 - if(shyy.equals("1")){shyy="票务用油";}  
168 - else if(shyy.equals("2")){shyy="保养用油";}  
169 - else if(shyy.equals("3")){shyy="报废车用油";}  
170 - else if(shyy.equals("4")){shyy="其它用油";} 168 + if(shyy.equals("1")){shyy="票务用电";}
  169 + else if(shyy.equals("2")){shyy="保养用电";}
  170 + else if(shyy.equals("3")){shyy="报废车用电";}
  171 + else if(shyy.equals("4")){shyy="其它用电";}
171 else if(shyy.equals("5")){shyy="人保部";} 172 else if(shyy.equals("5")){shyy="人保部";}
172 else if(shyy.equals("6")){shyy="车队";} 173 else if(shyy.equals("6")){shyy="车队";}
173 else if(shyy.equals("7")){shyy="车间(高保)";} 174 else if(shyy.equals("7")){shyy="车间(高保)";}
@@ -180,6 +181,7 @@ public class DlbController extends BaseController<Dlb, Integer>{ @@ -180,6 +181,7 @@ public class DlbController extends BaseController<Dlb, Integer>{
180 m.put("zlc", y.getZlc()<=0?"0":y.getZlc()); 181 m.put("zlc", y.getZlc()<=0?"0":y.getZlc());
181 m.put("rdlx", ""); 182 m.put("rdlx", "");
182 m.put("bglyh", y.getBglyh()); 183 m.put("bglyh", y.getBglyh());
  184 + m.put("zdh", Arith.add(y.getSh(), y.getHd()));
183 resList.add(m); 185 resList.add(m);
184 } 186 }
185 try { 187 try {
src/main/java/com/bsth/controller/oil/YlbController.java
@@ -27,6 +27,7 @@ import com.bsth.entity.oil.Ylb; @@ -27,6 +27,7 @@ import com.bsth.entity.oil.Ylb;
27 import com.bsth.entity.sys.SysUser; 27 import com.bsth.entity.sys.SysUser;
28 import com.bsth.security.util.SecurityUtils; 28 import com.bsth.security.util.SecurityUtils;
29 import com.bsth.service.oil.YlbService; 29 import com.bsth.service.oil.YlbService;
  30 +import com.bsth.util.Arith;
30 import com.bsth.util.ReportUtils; 31 import com.bsth.util.ReportUtils;
31 import com.google.common.base.Splitter; 32 import com.google.common.base.Splitter;
32 33
@@ -273,6 +274,7 @@ public class YlbController extends BaseController&lt;Ylb, Integer&gt;{ @@ -273,6 +274,7 @@ public class YlbController extends BaseController&lt;Ylb, Integer&gt;{
273 m.put("sh", y.getSh()<=0?"0":y.getSh()); 274 m.put("sh", y.getSh()<=0?"0":y.getSh());
274 m.put("zlc", y.getZlc()<=0?"0":y.getZlc()); 275 m.put("zlc", y.getZlc()<=0?"0":y.getZlc());
275 m.put("bglyh", y.getBglyh()); 276 m.put("bglyh", y.getBglyh());
  277 + m.put("zyh", Arith.add(y.getSh(), y.getYh()));
276 resList.add(m); 278 resList.add(m);
277 } 279 }
278 try { 280 try {
src/main/java/com/bsth/data/gpsdata_v2/DataHandleProcess.java
1 -package com.bsth.data.gpsdata_v2;  
2 -  
3 -import com.bsth.data.gpsdata_v2.cache.GpsCacheData;  
4 -import com.bsth.data.gpsdata_v2.entity.GpsEntity;  
5 -import com.bsth.data.gpsdata_v2.handlers.*;  
6 -import com.google.common.collect.ArrayListMultimap;  
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.ArrayList;  
13 -import java.util.List;  
14 -import java.util.Set;  
15 -import java.util.concurrent.CountDownLatch;  
16 -import java.util.concurrent.ExecutorService;  
17 -import java.util.concurrent.Executors;  
18 -import java.util.concurrent.ThreadFactory;  
19 -  
20 -/**  
21 - * 实时信号数据处理  
22 - * Created by panzhao on 2017/11/15.  
23 - */  
24 -@Component  
25 -public class DataHandleProcess {  
26 -  
27 - static Logger logger = LoggerFactory.getLogger(DataHandleProcess.class);  
28 - final static int POOL_SIZE = 25;  
29 -  
30 - static ExecutorService threadPool = Executors.newFixedThreadPool(POOL_SIZE + 1, new HandlerThreadFactory());  
31 - public static CountDownLatch count;  
32 -  
33 - @Autowired  
34 - GpsStateProcess gpsStateProcess;  
35 - @Autowired  
36 - StationInsideProcess stationInsideProcess;  
37 - @Autowired  
38 - AbnormalStateProcess abnormalStateProcess;  
39 - @Autowired  
40 - InStationProcess inStationProcess;  
41 - @Autowired  
42 - OutStationProcess outStationProcess;  
43 - @Autowired  
44 - ReverseRouteProcess reverseRouteProcess;  
45 -  
46 - @Autowired  
47 - GpsRealData gpsRealData;  
48 -  
49 - public void handle(List<GpsEntity> list) {  
50 - try {  
51 - //按设备号分组数据(一个设备的多条数据,必须在一个线程里跑)  
52 - ArrayListMultimap multimap = ArrayListMultimap.create();  
53 - for (GpsEntity gps : list) {  
54 - multimap.put(gps.getDeviceId(), gps);  
55 - }  
56 - List<String> deviceList = new ArrayList<>(multimap.keySet());  
57 -  
58 - //数据均分给线程  
59 - ArrayListMultimap dataListMap = ArrayListMultimap.create();  
60 - int size = deviceList.size(), threadIndex = 0, threadSize = size / POOL_SIZE;  
61 - for (int i = 0; i < size; i++) {  
62 - if (i % threadSize == 0)  
63 - threadIndex++;  
64 - dataListMap.putAll(threadIndex, multimap.get(deviceList.get(i)));  
65 - }  
66 - Set<Integer> ks = dataListMap.keySet();  
67 - logger.info("analyse gps size: " + list.size() + ", ks: " + ks.size());  
68 - count = new CountDownLatch(ks.size());  
69 -  
70 - for (Integer index : ks) {  
71 - threadPool.execute(new SignalHandleThread(dataListMap.get(index), count));  
72 - }  
73 -  
74 - //等待子线程结束  
75 - count.await();  
76 -  
77 - //加入实时gps对照  
78 - for (GpsEntity gps : list)  
79 - gpsRealData.put(gps);  
80 - } catch (Exception e) {  
81 - logger.error("", e);  
82 - }  
83 - }  
84 -  
85 - public class SignalHandleThread implements Runnable {  
86 -  
87 - List<GpsEntity> list;  
88 - CountDownLatch count;  
89 -  
90 - SignalHandleThread(List<GpsEntity> gpsList, CountDownLatch count) {  
91 - this.list = gpsList;  
92 - this.count = count;  
93 - }  
94 -  
95 - @Override  
96 - public void run() {  
97 - try {  
98 - for (GpsEntity gps : list) {  
99 - try{  
100 - if(Math.abs(gps.getTimestamp() - gps.getServerTimestamp()) > 1000 * 60 * 20)  
101 - continue;  
102 -  
103 - gpsStateProcess.process(gps);//状态处理  
104 - stationInsideProcess.process(gps);//场站内外判定  
105 - reverseRouteProcess.process(gps);//反向路由处理  
106 - abnormalStateProcess.process(gps);//超速越界  
107 -  
108 - inStationProcess.process(gps);//进站  
109 - outStationProcess.process(gps);//出站  
110 -  
111 - GpsCacheData.putGps(gps);//历史gps缓存  
112 - }catch (Exception e){  
113 - logger.error("", e);  
114 - }  
115 - }  
116 - } finally {  
117 - if (count != null)  
118 - count.countDown();  
119 - }  
120 - }  
121 - }  
122 -  
123 - static class MyUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {  
124 - @Override  
125 - public void uncaughtException(Thread t, Throwable e) {  
126 - logger.error("caught " , e);  
127 - }  
128 - }  
129 -  
130 - static class HandlerThreadFactory implements ThreadFactory {  
131 - @Override  
132 - public Thread newThread(Runnable r) {  
133 - Thread t = new Thread(r);  
134 - t.setUncaughtExceptionHandler(new MyUncaughtExceptionHandler());  
135 - return t;  
136 - }  
137 - } 1 +package com.bsth.data.gpsdata_v2;
  2 +
  3 +import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
  4 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  5 +import com.bsth.data.gpsdata_v2.handlers.*;
  6 +import com.google.common.collect.ArrayListMultimap;
  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.ArrayList;
  13 +import java.util.List;
  14 +import java.util.Set;
  15 +import java.util.concurrent.CountDownLatch;
  16 +import java.util.concurrent.ExecutorService;
  17 +import java.util.concurrent.Executors;
  18 +import java.util.concurrent.ThreadFactory;
  19 +
  20 +/**
  21 + * 实时信号数据处理
  22 + * Created by panzhao on 2017/11/15.
  23 + */
  24 +@Component
  25 +public class DataHandleProcess {
  26 +
  27 + static Logger logger = LoggerFactory.getLogger(DataHandleProcess.class);
  28 + final static int POOL_SIZE = 25;
  29 +
  30 + static ExecutorService threadPool = Executors.newFixedThreadPool(POOL_SIZE + 1, new HandlerThreadFactory());
  31 + public static CountDownLatch count;
  32 +
  33 + @Autowired
  34 + GpsStateProcess gpsStateProcess;
  35 + @Autowired
  36 + StationInsideProcess stationInsideProcess;
  37 + @Autowired
  38 + AbnormalStateProcess abnormalStateProcess;
  39 + @Autowired
  40 + InStationProcess inStationProcess;
  41 + @Autowired
  42 + OutStationProcess outStationProcess;
  43 + @Autowired
  44 + ReverseRouteProcess reverseRouteProcess;
  45 +
  46 + @Autowired
  47 + GpsRealData gpsRealData;
  48 +
  49 + public void handle(List<GpsEntity> list) {
  50 + try {
  51 + //按设备号分组数据(一个设备的多条数据,必须在一个线程里跑)
  52 + ArrayListMultimap multimap = ArrayListMultimap.create();
  53 + for (GpsEntity gps : list) {
  54 + multimap.put(gps.getDeviceId(), gps);
  55 + }
  56 + List<String> deviceList = new ArrayList<>(multimap.keySet());
  57 +
  58 + //数据均分给线程
  59 + ArrayListMultimap dataListMap = ArrayListMultimap.create();
  60 + int size = deviceList.size(), threadIndex = 0, threadSize = size / POOL_SIZE;
  61 + for (int i = 0; i < size; i++) {
  62 + if (i % threadSize == 0)
  63 + threadIndex++;
  64 + dataListMap.putAll(threadIndex, multimap.get(deviceList.get(i)));
  65 + }
  66 + Set<Integer> ks = dataListMap.keySet();
  67 + logger.info("analyse gps size: " + list.size() + ", ks: " + ks.size());
  68 + count = new CountDownLatch(ks.size());
  69 +
  70 + for (Integer index : ks) {
  71 + threadPool.execute(new SignalHandleThread(dataListMap.get(index), count));
  72 + }
  73 +
  74 + //等待子线程结束
  75 + count.await();
  76 +
  77 + //加入实时gps对照
  78 + for (GpsEntity gps : list)
  79 + gpsRealData.put(gps);
  80 + } catch (Exception e) {
  81 + logger.error("", e);
  82 + }
  83 + }
  84 +
  85 + public class SignalHandleThread implements Runnable {
  86 +
  87 + List<GpsEntity> list;
  88 + CountDownLatch count;
  89 +
  90 + SignalHandleThread(List<GpsEntity> gpsList, CountDownLatch count) {
  91 + this.list = gpsList;
  92 + this.count = count;
  93 + }
  94 +
  95 + @Override
  96 + public void run() {
  97 + try {
  98 + for (GpsEntity gps : list) {
  99 + try{
  100 + if(Math.abs(gps.getTimestamp() - gps.getServerTimestamp()) > 1000 * 60 * 20)
  101 + continue;
  102 +
  103 + gpsStateProcess.process(gps);//状态处理
  104 + stationInsideProcess.process(gps);//场站内外判定
  105 + reverseRouteProcess.process(gps);//反向路由处理
  106 + abnormalStateProcess.process(gps);//超速越界
  107 +
  108 + inStationProcess.process(gps);//进站
  109 + outStationProcess.process(gps);//出站
  110 +
  111 + GpsCacheData.putGps(gps);//历史gps缓存
  112 + }catch (Exception e){
  113 + logger.error("", e);
  114 + }
  115 + }
  116 + } finally {
  117 + if (count != null)
  118 + count.countDown();
  119 + }
  120 + }
  121 + }
  122 +
  123 + static class MyUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
  124 + @Override
  125 + public void uncaughtException(Thread t, Throwable e) {
  126 + logger.error("caught " , e);
  127 + }
  128 + }
  129 +
  130 + static class HandlerThreadFactory implements ThreadFactory {
  131 + @Override
  132 + public Thread newThread(Runnable r) {
  133 + Thread t = new Thread(r);
  134 + t.setUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
  135 + return t;
  136 + }
  137 + }
138 } 138 }
139 \ No newline at end of file 139 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata_v2/cache/GeoCacheData.java
1 -package com.bsth.data.gpsdata_v2.cache;  
2 -  
3 -import com.bsth.data.gpsdata_v2.entity.CtLineString;  
4 -import com.bsth.data.gpsdata_v2.entity.GpsEntity;  
5 -import com.bsth.data.gpsdata_v2.entity.PreconditionGeo;  
6 -import com.bsth.data.gpsdata_v2.entity.StationRoute;  
7 -import com.bsth.data.gpsdata_v2.utils.StationRouteComp;  
8 -import com.bsth.util.Geo.Point;  
9 -import com.bsth.util.Geo.Polygon;  
10 -import com.google.common.base.Splitter;  
11 -import com.google.common.collect.ArrayListMultimap;  
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;  
16 -import org.springframework.jdbc.core.BeanPropertyRowMapper;  
17 -import org.springframework.jdbc.core.JdbcTemplate;  
18 -import org.springframework.jdbc.core.RowMapper;  
19 -import org.springframework.stereotype.Component;  
20 -  
21 -import java.sql.ResultSet;  
22 -import java.sql.SQLException;  
23 -import java.util.*;  
24 -  
25 -/**  
26 - * 空间数据缓存  
27 - * Created by panzhao on 2017/11/15.  
28 - */  
29 -@Component  
30 -public class GeoCacheData {  
31 -  
32 - static Logger logger = LoggerFactory.getLogger(GeoCacheData.class);  
33 -  
34 - /**  
35 - * 线路路段走向  
36 - */  
37 - private static ArrayListMultimap<String, CtLineString> sectionCacheMap;  
38 - /**  
39 - * 路段编码和名称对照  
40 - */  
41 - private static Map<String, String> sectionCode2Name;  
42 - /**  
43 - * 线路站点路由  
44 - */  
45 - private static ArrayListMultimap<String, StationRoute> stationCacheMap;  
46 - /**  
47 - * 线路前置进站围栏  
48 - */  
49 - public static ArrayListMultimap<String, PreconditionGeo> premiseGeoMap;  
50 - /**  
51 - * 线路_上下行_站点编码 ——> 站点  
52 - */  
53 - private static Map<String, StationRoute> routeCodeMap;  
54 - /**  
55 - * 停车场  
56 - */  
57 - public static Map<String, Polygon> tccMap;  
58 - /**  
59 - * 线路限速信息  
60 - */  
61 - private static Map<String, Double> speedLimitMap;  
62 -  
63 - @Autowired  
64 - JdbcTemplate jdbcTemplate;  
65 -  
66 - public void loadData() {  
67 - loadStationRoutesData();  
68 - loadTccMapData();  
69 - loadSpeedLimit();  
70 -  
71 - //加载路段信息  
72 - loadRoadsData();  
73 -  
74 - //加载前置进站围栏  
75 - loadPremiseGeoData();  
76 - }  
77 -  
78 - public static List<StationRoute> getStationRoute(String lineCode, int directions) {  
79 - return stationCacheMap.get(lineCode + "_" + directions);  
80 - }  
81 -  
82 - public static StationRoute getRouteCode(GpsEntity gps) {  
83 - return routeCodeMap.get(gps.getLineId() + "_" + gps.getUpDown() + "_" + gps.getStopNo());  
84 - }  
85 -  
86 - public static Double speedLimit(String lineCode){  
87 - return speedLimitMap.get(lineCode);  
88 - }  
89 -  
90 - public static List<CtLineString> getLineStringList(GpsEntity gps){  
91 - return sectionCacheMap.get(gps.getLineId() + "_" + gps.getUpDown());  
92 - }  
93 -  
94 - private void loadStationRoutesData(){  
95 - String sql = "select r.LINE_CODE,r.DIRECTIONS,r.STATION_CODE,r.STATION_MARK,s.SHAPES_TYPE,s.G_LONX,s.G_LATY,ST_AsText(s.G_POLYGON_GRID) as G_POLYGON_GRID,s.RADIUS, r.STATION_ROUTE_CODE,s.STATION_NAME from bsth_c_stationroute r left join bsth_c_station s on r.station=s.id where r.destroy=0 order by r.station_route_code";  
96 - List<StationRoute> routeList = jdbcTemplate.query(sql, new RowMapper<StationRoute>() {  
97 -  
98 - @Override  
99 - public StationRoute mapRow(ResultSet rs, int rowNum) throws SQLException {  
100 - StationRoute sRoute = new StationRoute();  
101 - sRoute.setCode(rs.getString("STATION_CODE"));  
102 - sRoute.setLineCode(rs.getString("LINE_CODE"));  
103 - sRoute.setDirections(rs.getInt("DIRECTIONS"));  
104 - sRoute.setPoint(new Point(rs.getFloat("G_LONX"), rs.getFloat("G_LATY")));  
105 - sRoute.setRadius(rs.getFloat("RADIUS"));  
106 - sRoute.setRouteSort(rs.getInt("STATION_ROUTE_CODE"));  
107 - sRoute.setMark(rs.getString("STATION_MARK"));  
108 - sRoute.setName(rs.getString("STATION_NAME"));  
109 -  
110 - String shapesType = rs.getString("SHAPES_TYPE");  
111 - //多边形电子围栏  
112 - if (StringUtils.isNotEmpty(shapesType) && shapesType.equals("d"))  
113 - sRoute.setPolygon(parsePolygon(rs.getString("G_POLYGON_GRID")));  
114 - return sRoute;  
115 - }  
116 - });  
117 -  
118 - //按线路和走向分组  
119 - if (routeList.size() > 0) {  
120 - ArrayListMultimap<String, StationRoute> tempMap = ArrayListMultimap.create();  
121 - Map<String, StationRoute> codeMap = new HashMap<>(routeList.size());  
122 - for (StationRoute sr : routeList) {  
123 - tempMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr);  
124 - //站点编码 ——> 和路由顺序对照  
125 - codeMap.put(sr.getLineCode() + "_" + sr.getDirections() + "_" + sr.getCode(), sr);  
126 - }  
127 -  
128 - StationRouteComp srCom = new StationRouteComp();  
129 - //连接路由  
130 - Set<String> set = tempMap.keySet();  
131 - for (String key : set) {  
132 - Collections.sort(tempMap.get(key), srCom);  
133 - connectStationRoute(tempMap.get(key));  
134 - }  
135 - stationCacheMap = tempMap;  
136 - routeCodeMap = codeMap;  
137 - }  
138 - }  
139 -  
140 - private void loadTccMapData(){  
141 - //加载停车场数据  
142 - String sql = "select PARK_CODE, ST_AsText(G_PARK_POINT) as G_PARK_POINT from bsth_c_car_park where park_code is not null and b_park_point is not null";  
143 - List<Map<String, Object>> tccList = jdbcTemplate.queryForList(sql);  
144 - Map<String, Polygon> tccTempMap = new HashMap<>();  
145 -  
146 - Polygon polygon;  
147 - for (Map<String, Object> tMap : tccList) {  
148 -  
149 - try {  
150 - polygon = parsePolygon(tMap.get("G_PARK_POINT").toString());  
151 - tccTempMap.put(tMap.get("PARK_CODE").toString()  
152 - , polygon);  
153 - } catch (Exception e) {  
154 - logger.error("停车场:" + tMap.get("PARK_CODE"), e);  
155 - }  
156 - }  
157 - if (tccTempMap.size() > 0){  
158 - tccMap = tccTempMap;  
159 - }  
160 - }  
161 -  
162 - private void loadSpeedLimit(){  
163 - //加载线路限速信息  
164 - String sql = "select l.LINE_CODE,i.SPEEDING from bsth_c_line_information i left join bsth_c_line l on i.line=l.id where i.speed_limit is not null";  
165 - List<Map<String, Object>> speedMap = jdbcTemplate.queryForList(sql);  
166 - Map<String, Double> speedTempMap = new HashMap<>();  
167 - for (Map<String, Object> tMap : speedMap) {  
168 - try {  
169 - speedTempMap.put(tMap.get("LINE_CODE").toString(), Double.parseDouble(tMap.get("SPEEDING").toString()));  
170 - } catch (NumberFormatException e) {  
171 - logger.error("speeding is null...");  
172 - }  
173 - }  
174 - speedLimitMap = speedTempMap;  
175 - }  
176 -  
177 - private void loadRoadsData() {  
178 - //加载线路下路段空间数据  
179 - String sql = "select r.LINE_CODE,r.SECTION_CODE,r.SECTIONROUTE_CODE,s.SECTION_NAME,ST_AsText(s.GSECTION_VECTOR) as GSECTION_VECTOR, r.DIRECTIONS, s.CROSES_ROAD from bsth_c_sectionroute r INNER JOIN bsth_c_section s on r.section=s.id where r.destroy=0 and GSECTION_VECTOR is not null order by line_code,directions,sectionroute_code";  
180 - List<Map<String, Object>> secList = jdbcTemplate.queryForList(sql);  
181 -  
182 - String polygonStr, key;  
183 - String[] coords;  
184 - int i, len;  
185 - ArrayListMultimap<String, CtLineString> sectionCacheTempMap = ArrayListMultimap.create();  
186 - String[] temps1, temps2;  
187 - CtLineString lineString;  
188 - for (Map<String, Object> tMap : secList) {  
189 - //空间数据映射  
190 - polygonStr = tMap.get("GSECTION_VECTOR").toString();  
191 - key = tMap.get("LINE_CODE") + "_" + tMap.get("DIRECTIONS");  
192 -  
193 - coords = polygonStr.substring(11, polygonStr.length() - 1).split(",");  
194 - len = coords.length - 1;  
195 - //每2个点连一条线  
196 - for(i = 0; i < len; i ++){  
197 - temps1 = coords[i].split(" ");  
198 - temps2 = coords[i + 1].split(" ");  
199 -  
200 - lineString = new CtLineString();  
201 - lineString.setS(new Point(Float.parseFloat(temps1[0]), Float.parseFloat(temps1[1])));  
202 - lineString.setE(new Point(Float.parseFloat(temps2[0]), Float.parseFloat(temps2[1])));  
203 -  
204 - sectionCacheTempMap.put(key, lineString);  
205 - }  
206 - }  
207 -  
208 - if(sectionCacheTempMap.size() > 0)  
209 - sectionCacheMap = sectionCacheTempMap;  
210 -  
211 - Map<String, String> sectionCode2NameTemp = new HashMap<>();  
212 -  
213 - //加载全量路段编码和名称对照  
214 - sql = "select SECTION_CODE,SECTION_NAME,CROSES_ROAD from bsth_c_section";  
215 - secList = jdbcTemplate.queryForList(sql);  
216 - String name = null, code;  
217 - for (Map<String, Object> tMap : secList) {  
218 - if(tMap.get("CROSES_ROAD") != null && StringUtils.isNotEmpty(tMap.get("CROSES_ROAD").toString()))  
219 - name = tMap.get("CROSES_ROAD").toString();  
220 - else if(tMap.get("SECTION_NAME") != null && StringUtils.isNotEmpty(tMap.get("SECTION_NAME").toString()))  
221 - name = tMap.get("SECTION_NAME").toString();  
222 -  
223 - code = tMap.get("SECTION_CODE").toString();  
224 - sectionCode2NameTemp.put(code, name);  
225 - }  
226 - if(sectionCode2NameTemp.size() > 0)  
227 - sectionCode2Name = sectionCode2NameTemp;  
228 - }  
229 -  
230 - private void loadPremiseGeoData() {  
231 - ArrayListMultimap<String, PreconditionGeo> premiseGeoMapCopy = ArrayListMultimap.create();  
232 -  
233 - String sql = "select * from bsth_f_geo_premise";  
234 - List<PreconditionGeo> list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(PreconditionGeo.class));  
235 -  
236 - List<String> coordList;  
237 - String[] cs;  
238 - Point point;  
239 - List<Point> ps;  
240 - StationRoute sr;  
241 - for(PreconditionGeo p : list){  
242 - try{  
243 - sr = routeCodeMap.get(p.getLineCode()+"_"+p.getUpDown()+"_"+p.getStationCode());  
244 - p.setOrder(sr.getRouteSort());  
245 - //polygon  
246 - ps = new ArrayList<>();  
247 - coordList = Splitter.on(",").trimResults().splitToList(p.getCoords());  
248 - for(String c : coordList){  
249 - cs = c.split(" ");  
250 - point = new Point(Double.parseDouble(cs[0]), Double.parseDouble(cs[1]));  
251 - ps.add(point);  
252 - }  
253 -  
254 - p.setPolygon(new Polygon(ps));  
255 -  
256 - sr.setPremise(true);  
257 - //按线路,走向分组  
258 - premiseGeoMapCopy.put(p.getLineCode()+"_"+p.getUpDown(), p);  
259 - }catch (Exception e){  
260 - logger.error("", e);  
261 - }  
262 - }  
263 -  
264 - //排序  
265 - Set<String> ks = premiseGeoMapCopy.keySet();  
266 - PreconditionGeoComp comp = new PreconditionGeoComp();  
267 - for(String k : ks){  
268 - Collections.sort(premiseGeoMapCopy.get(k), comp);  
269 - }  
270 -  
271 - premiseGeoMap = premiseGeoMapCopy;  
272 - }  
273 -  
274 - public Polygon parsePolygon(String polygonStr) {  
275 - String[] coords = polygonStr.substring(9, polygonStr.length() - 2).split(","), temps;  
276 -  
277 - List<Point> cds = new ArrayList<>(coords.length);  
278 - int len = coords.length;  
279 - for (int i = 0; i < len; i++) {  
280 - temps = coords[i].split(" ");  
281 - cds.add(new Point(Float.parseFloat(temps[0]), Float.parseFloat(temps[1])));  
282 - }  
283 - return new Polygon(cds);  
284 - }  
285 -  
286 - private void connectStationRoute(List<StationRoute> list) {  
287 - int size = list.size();  
288 - StationRoute sr = null;  
289 - for (int i = 0; i < size; i++) {  
290 - sr = list.get(i);  
291 - //上一个  
292 - if (i > 0)  
293 - sr.setPrve(list.get(i - 1));  
294 - //下一个  
295 - if (i < size - 1)  
296 - sr.setNext(list.get(i + 1));  
297 - }  
298 - }  
299 -  
300 - /**  
301 - * 是否是环线  
302 - * @param lineId  
303 - * @return  
304 - */  
305 - public static boolean isLoopLine(String lineId) {  
306 - List<StationRoute> srs = getStationRoute(lineId , 0);  
307 - if(srs.get(0).getName().equals(srs.get(srs.size()- 1).getName())  
308 - && getStationRoute(lineId , 1).size()==2)  
309 - return true;  
310 - return false;  
311 - }  
312 -  
313 - private static class PreconditionGeoComp implements Comparator<PreconditionGeo>{  
314 -  
315 - @Override  
316 - public int compare(PreconditionGeo p1, PreconditionGeo p2) {  
317 - return p1.getOrder() - p2.getOrder();  
318 - }  
319 - }  
320 -  
321 - public static Map<String, String> sectionCode2NameMap(){  
322 - return sectionCode2Name;  
323 - } 1 +package com.bsth.data.gpsdata_v2.cache;
  2 +
  3 +import com.bsth.data.gpsdata_v2.entity.CtLineString;
  4 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  5 +import com.bsth.data.gpsdata_v2.entity.PreconditionGeo;
  6 +import com.bsth.data.gpsdata_v2.entity.StationRoute;
  7 +import com.bsth.data.gpsdata_v2.utils.StationRouteComp;
  8 +import com.bsth.util.Geo.Point;
  9 +import com.bsth.util.Geo.Polygon;
  10 +import com.google.common.base.Splitter;
  11 +import com.google.common.collect.ArrayListMultimap;
  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;
  16 +import org.springframework.jdbc.core.BeanPropertyRowMapper;
  17 +import org.springframework.jdbc.core.JdbcTemplate;
  18 +import org.springframework.jdbc.core.RowMapper;
  19 +import org.springframework.stereotype.Component;
  20 +
  21 +import java.sql.ResultSet;
  22 +import java.sql.SQLException;
  23 +import java.util.*;
  24 +
  25 +/**
  26 + * 空间数据缓存
  27 + * Created by panzhao on 2017/11/15.
  28 + */
  29 +@Component
  30 +public class GeoCacheData {
  31 +
  32 + static Logger logger = LoggerFactory.getLogger(GeoCacheData.class);
  33 +
  34 + /**
  35 + * 线路路段走向
  36 + */
  37 + private static ArrayListMultimap<String, CtLineString> sectionCacheMap;
  38 + /**
  39 + * 路段编码和名称对照
  40 + */
  41 + private static Map<String, String> sectionCode2Name;
  42 + /**
  43 + * 线路站点路由
  44 + */
  45 + private static ArrayListMultimap<String, StationRoute> stationCacheMap;
  46 + /**
  47 + * 线路前置进站围栏
  48 + */
  49 + public static ArrayListMultimap<String, PreconditionGeo> premiseGeoMap;
  50 + /**
  51 + * 线路_上下行_站点编码 ——> 站点
  52 + */
  53 + private static Map<String, StationRoute> routeCodeMap;
  54 + /**
  55 + * 停车场
  56 + */
  57 + public static Map<String, Polygon> tccMap;
  58 + /**
  59 + * 线路限速信息
  60 + */
  61 + private static Map<String, Double> speedLimitMap;
  62 +
  63 + @Autowired
  64 + JdbcTemplate jdbcTemplate;
  65 +
  66 + public void loadData() {
  67 + loadStationRoutesData();
  68 + loadTccMapData();
  69 + loadSpeedLimit();
  70 +
  71 + //加载路段信息
  72 + loadRoadsData();
  73 +
  74 + //加载前置进站围栏
  75 + loadPremiseGeoData();
  76 + }
  77 +
  78 + public static List<StationRoute> getStationRoute(String lineCode, int directions) {
  79 + return stationCacheMap.get(lineCode + "_" + directions);
  80 + }
  81 +
  82 + public static StationRoute getRouteCode(GpsEntity gps) {
  83 + return routeCodeMap.get(gps.getLineId() + "_" + gps.getUpDown() + "_" + gps.getStopNo());
  84 + }
  85 +
  86 + public static Double speedLimit(String lineCode){
  87 + return speedLimitMap.get(lineCode);
  88 + }
  89 +
  90 + public static List<CtLineString> getLineStringList(GpsEntity gps){
  91 + return sectionCacheMap.get(gps.getLineId() + "_" + gps.getUpDown());
  92 + }
  93 +
  94 + private void loadStationRoutesData(){
  95 + String sql = "select r.LINE_CODE,r.DIRECTIONS,r.STATION_CODE,r.STATION_MARK,s.SHAPES_TYPE,s.G_LONX,s.G_LATY,ST_AsText(s.G_POLYGON_GRID) as G_POLYGON_GRID,s.RADIUS, r.STATION_ROUTE_CODE,s.STATION_NAME from bsth_c_stationroute r left join bsth_c_station s on r.station=s.id where r.destroy=0 order by r.station_route_code";
  96 + List<StationRoute> routeList = jdbcTemplate.query(sql, new RowMapper<StationRoute>() {
  97 +
  98 + @Override
  99 + public StationRoute mapRow(ResultSet rs, int rowNum) throws SQLException {
  100 + StationRoute sRoute = new StationRoute();
  101 + sRoute.setCode(rs.getString("STATION_CODE"));
  102 + sRoute.setLineCode(rs.getString("LINE_CODE"));
  103 + sRoute.setDirections(rs.getInt("DIRECTIONS"));
  104 + sRoute.setPoint(new Point(rs.getFloat("G_LONX"), rs.getFloat("G_LATY")));
  105 + sRoute.setRadius(rs.getFloat("RADIUS"));
  106 + sRoute.setRouteSort(rs.getInt("STATION_ROUTE_CODE"));
  107 + sRoute.setMark(rs.getString("STATION_MARK"));
  108 + sRoute.setName(rs.getString("STATION_NAME"));
  109 +
  110 + String shapesType = rs.getString("SHAPES_TYPE");
  111 + //多边形电子围栏
  112 + if (StringUtils.isNotEmpty(shapesType) && shapesType.equals("d"))
  113 + sRoute.setPolygon(parsePolygon(rs.getString("G_POLYGON_GRID")));
  114 + return sRoute;
  115 + }
  116 + });
  117 +
  118 + //按线路和走向分组
  119 + if (routeList.size() > 0) {
  120 + ArrayListMultimap<String, StationRoute> tempMap = ArrayListMultimap.create();
  121 + Map<String, StationRoute> codeMap = new HashMap<>(routeList.size());
  122 + for (StationRoute sr : routeList) {
  123 + tempMap.put(sr.getLineCode() + "_" + sr.getDirections(), sr);
  124 + //站点编码 ——> 和路由顺序对照
  125 + codeMap.put(sr.getLineCode() + "_" + sr.getDirections() + "_" + sr.getCode(), sr);
  126 + }
  127 +
  128 + StationRouteComp srCom = new StationRouteComp();
  129 + //连接路由
  130 + Set<String> set = tempMap.keySet();
  131 + for (String key : set) {
  132 + Collections.sort(tempMap.get(key), srCom);
  133 + connectStationRoute(tempMap.get(key));
  134 + }
  135 + stationCacheMap = tempMap;
  136 + routeCodeMap = codeMap;
  137 + }
  138 + }
  139 +
  140 + private void loadTccMapData(){
  141 + //加载停车场数据
  142 + String sql = "select PARK_CODE, ST_AsText(G_PARK_POINT) as G_PARK_POINT from bsth_c_car_park where park_code is not null and b_park_point is not null";
  143 + List<Map<String, Object>> tccList = jdbcTemplate.queryForList(sql);
  144 + Map<String, Polygon> tccTempMap = new HashMap<>();
  145 +
  146 + Polygon polygon;
  147 + for (Map<String, Object> tMap : tccList) {
  148 +
  149 + try {
  150 + polygon = parsePolygon(tMap.get("G_PARK_POINT").toString());
  151 + tccTempMap.put(tMap.get("PARK_CODE").toString()
  152 + , polygon);
  153 + } catch (Exception e) {
  154 + logger.error("停车场:" + tMap.get("PARK_CODE"), e);
  155 + }
  156 + }
  157 + if (tccTempMap.size() > 0){
  158 + tccMap = tccTempMap;
  159 + }
  160 + }
  161 +
  162 + private void loadSpeedLimit(){
  163 + //加载线路限速信息
  164 + String sql = "select l.LINE_CODE,i.SPEEDING from bsth_c_line_information i left join bsth_c_line l on i.line=l.id where i.speed_limit is not null";
  165 + List<Map<String, Object>> speedMap = jdbcTemplate.queryForList(sql);
  166 + Map<String, Double> speedTempMap = new HashMap<>();
  167 + for (Map<String, Object> tMap : speedMap) {
  168 + try {
  169 + speedTempMap.put(tMap.get("LINE_CODE").toString(), Double.parseDouble(tMap.get("SPEEDING").toString()));
  170 + } catch (NumberFormatException e) {
  171 + logger.error("speeding is null...");
  172 + }
  173 + }
  174 + speedLimitMap = speedTempMap;
  175 + }
  176 +
  177 + private void loadRoadsData() {
  178 + //加载线路下路段空间数据
  179 + String sql = "select r.LINE_CODE,r.SECTION_CODE,r.SECTIONROUTE_CODE,s.SECTION_NAME,ST_AsText(s.GSECTION_VECTOR) as GSECTION_VECTOR, r.DIRECTIONS, s.CROSES_ROAD from bsth_c_sectionroute r INNER JOIN bsth_c_section s on r.section=s.id where r.destroy=0 and GSECTION_VECTOR is not null order by line_code,directions,sectionroute_code";
  180 + List<Map<String, Object>> secList = jdbcTemplate.queryForList(sql);
  181 +
  182 + String polygonStr, key;
  183 + String[] coords;
  184 + int i, len;
  185 + ArrayListMultimap<String, CtLineString> sectionCacheTempMap = ArrayListMultimap.create();
  186 + String[] temps1, temps2;
  187 + CtLineString lineString;
  188 + for (Map<String, Object> tMap : secList) {
  189 + //空间数据映射
  190 + polygonStr = tMap.get("GSECTION_VECTOR").toString();
  191 + key = tMap.get("LINE_CODE") + "_" + tMap.get("DIRECTIONS");
  192 +
  193 + coords = polygonStr.substring(11, polygonStr.length() - 1).split(",");
  194 + len = coords.length - 1;
  195 + //每2个点连一条线
  196 + for(i = 0; i < len; i ++){
  197 + temps1 = coords[i].split(" ");
  198 + temps2 = coords[i + 1].split(" ");
  199 +
  200 + lineString = new CtLineString();
  201 + lineString.setS(new Point(Float.parseFloat(temps1[0]), Float.parseFloat(temps1[1])));
  202 + lineString.setE(new Point(Float.parseFloat(temps2[0]), Float.parseFloat(temps2[1])));
  203 +
  204 + sectionCacheTempMap.put(key, lineString);
  205 + }
  206 + }
  207 +
  208 + if(sectionCacheTempMap.size() > 0)
  209 + sectionCacheMap = sectionCacheTempMap;
  210 +
  211 + Map<String, String> sectionCode2NameTemp = new HashMap<>();
  212 +
  213 + //加载全量路段编码和名称对照
  214 + sql = "select SECTION_CODE,SECTION_NAME,CROSES_ROAD from bsth_c_section";
  215 + secList = jdbcTemplate.queryForList(sql);
  216 + String name = null, code;
  217 + for (Map<String, Object> tMap : secList) {
  218 + if(tMap.get("CROSES_ROAD") != null && StringUtils.isNotEmpty(tMap.get("CROSES_ROAD").toString()))
  219 + name = tMap.get("CROSES_ROAD").toString();
  220 + else if(tMap.get("SECTION_NAME") != null && StringUtils.isNotEmpty(tMap.get("SECTION_NAME").toString()))
  221 + name = tMap.get("SECTION_NAME").toString();
  222 +
  223 + code = tMap.get("SECTION_CODE").toString();
  224 + sectionCode2NameTemp.put(code, name);
  225 + }
  226 + if(sectionCode2NameTemp.size() > 0)
  227 + sectionCode2Name = sectionCode2NameTemp;
  228 + }
  229 +
  230 + private void loadPremiseGeoData() {
  231 + ArrayListMultimap<String, PreconditionGeo> premiseGeoMapCopy = ArrayListMultimap.create();
  232 +
  233 + String sql = "select * from bsth_f_geo_premise";
  234 + List<PreconditionGeo> list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(PreconditionGeo.class));
  235 +
  236 + List<String> coordList;
  237 + String[] cs;
  238 + Point point;
  239 + List<Point> ps;
  240 + StationRoute sr;
  241 + for(PreconditionGeo p : list){
  242 + try{
  243 + sr = routeCodeMap.get(p.getLineCode()+"_"+p.getUpDown()+"_"+p.getStationCode());
  244 + p.setOrder(sr.getRouteSort());
  245 + //polygon
  246 + ps = new ArrayList<>();
  247 + coordList = Splitter.on(",").trimResults().splitToList(p.getCoords());
  248 + for(String c : coordList){
  249 + cs = c.split(" ");
  250 + point = new Point(Double.parseDouble(cs[0]), Double.parseDouble(cs[1]));
  251 + ps.add(point);
  252 + }
  253 +
  254 + p.setPolygon(new Polygon(ps));
  255 +
  256 + sr.setPremise(true);
  257 + //按线路,走向分组
  258 + premiseGeoMapCopy.put(p.getLineCode()+"_"+p.getUpDown(), p);
  259 + }catch (Exception e){
  260 + logger.error("", e);
  261 + }
  262 + }
  263 +
  264 + //排序
  265 + Set<String> ks = premiseGeoMapCopy.keySet();
  266 + PreconditionGeoComp comp = new PreconditionGeoComp();
  267 + for(String k : ks){
  268 + Collections.sort(premiseGeoMapCopy.get(k), comp);
  269 + }
  270 +
  271 + premiseGeoMap = premiseGeoMapCopy;
  272 + }
  273 +
  274 + public Polygon parsePolygon(String polygonStr) {
  275 + String[] coords = polygonStr.substring(9, polygonStr.length() - 2).split(","), temps;
  276 +
  277 + List<Point> cds = new ArrayList<>(coords.length);
  278 + int len = coords.length;
  279 + for (int i = 0; i < len; i++) {
  280 + temps = coords[i].split(" ");
  281 + cds.add(new Point(Float.parseFloat(temps[0]), Float.parseFloat(temps[1])));
  282 + }
  283 + return new Polygon(cds);
  284 + }
  285 +
  286 + private void connectStationRoute(List<StationRoute> list) {
  287 + int size = list.size();
  288 + StationRoute sr = null;
  289 + for (int i = 0; i < size; i++) {
  290 + sr = list.get(i);
  291 + //上一个
  292 + if (i > 0)
  293 + sr.setPrve(list.get(i - 1));
  294 + //下一个
  295 + if (i < size - 1)
  296 + sr.setNext(list.get(i + 1));
  297 + }
  298 + }
  299 +
  300 + /**
  301 + * 是否是环线
  302 + * @param lineId
  303 + * @return
  304 + */
  305 + public static boolean isLoopLine(String lineId) {
  306 + List<StationRoute> srs = getStationRoute(lineId , 0);
  307 + if(srs.get(0).getName().equals(srs.get(srs.size()- 1).getName())
  308 + && getStationRoute(lineId , 1).size()==2)
  309 + return true;
  310 + return false;
  311 + }
  312 +
  313 + private static class PreconditionGeoComp implements Comparator<PreconditionGeo>{
  314 +
  315 + @Override
  316 + public int compare(PreconditionGeo p1, PreconditionGeo p2) {
  317 + return p1.getOrder() - p2.getOrder();
  318 + }
  319 + }
  320 +
  321 + public static Map<String, String> sectionCode2NameMap(){
  322 + return sectionCode2Name;
  323 + }
324 } 324 }
325 \ No newline at end of file 325 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata_v2/handlers/OutStationProcess.java
@@ -41,33 +41,34 @@ public class OutStationProcess { @@ -41,33 +41,34 @@ public class OutStationProcess {
41 GpsStatusManager gpsStatusManager; 41 GpsStatusManager gpsStatusManager;
42 private final static int MAX_BEFORE_TIME = 1000 * 60 * 120; 42 private final static int MAX_BEFORE_TIME = 1000 * 60 * 120;
43 43
44 - public void process(GpsEntity gps){ 44 + public void process(GpsEntity gps) {
45 //自动执行的班次信号,滚蛋 45 //自动执行的班次信号,滚蛋
46 LineConfig config = lineConfigData.get(gps.getLineId()); 46 LineConfig config = lineConfigData.get(gps.getLineId());
47 - if(null != config && config.isAutoExec()) 47 + if (null != config && config.isAutoExec())
48 return; 48 return;
49 49
50 GpsEntity prev = GpsCacheData.getPrev(gps); 50 GpsEntity prev = GpsCacheData.getPrev(gps);
51 51
52 - if(null == prev) 52 + if (null == prev)
53 return; 53 return;
54 54
55 //从站内到站外 55 //从站内到站外
56 - if(prev.getInstation() > 0 && gps.getInstation() == 0) 56 + if (prev.getInstation() > 0 && gps.getInstation() == 0)
57 outStation(gps, prev); 57 outStation(gps, prev);
58 58
59 //从站内到另一个站内 59 //从站内到另一个站内
60 - if(prev.getInstation() > 0 && gps.getInstation() > 0 60 + if (prev.getInstation() > 0 && gps.getInstation() > 0
61 && !prev.getStopNo().equals(gps.getStopNo())) 61 && !prev.getStopNo().equals(gps.getStopNo()))
62 outStation(gps, prev); 62 outStation(gps, prev);
63 63
64 //在被起点站覆盖的情况下出场 64 //在被起点站覆盖的情况下出场
65 - if(isOutPark(gps, prev)) 65 + if (isOutPark(gps, prev))
66 outStation(gps, prev); 66 outStation(gps, prev);
67 } 67 }
68 68
69 /** 69 /**
70 * 出站 70 * 出站
  71 + *
71 * @param gps 72 * @param gps
72 */ 73 */
73 private void outStation(GpsEntity gps, GpsEntity prev) { 74 private void outStation(GpsEntity gps, GpsEntity prev) {
@@ -76,23 +77,23 @@ public class OutStationProcess { @@ -76,23 +77,23 @@ public class OutStationProcess {
76 //起点发车 77 //起点发车
77 if (null != sch && 78 if (null != sch &&
78 ((sch.getQdzCode().equals(prev.getStopNo()) 79 ((sch.getQdzCode().equals(prev.getStopNo())
79 - && (gps.getInstation()==0 || !gps.getStopNo().equals(prev.getStopNo())))  
80 - || sch.getQdzCode().equals(prev.getCarparkNo()))){ 80 + && (gps.getInstation() == 0 || !gps.getStopNo().equals(prev.getStopNo())))
  81 + || sch.getQdzCode().equals(prev.getCarparkNo()))) {
81 //发车班次匹配 82 //发车班次匹配
82 - if(!signalSchPlanMatcher.outMatch(gps, sch)){ 83 + if (!signalSchPlanMatcher.outMatch(gps, sch)) {
83 outStation(gps, prev); 84 outStation(gps, prev);
84 return; 85 return;
85 } 86 }
86 87
87 int diff = (int) (sch.getDfsjT() - gps.getTimestamp()); 88 int diff = (int) (sch.getDfsjT() - gps.getTimestamp());
88 //首班出场最多提前2小时 89 //首班出场最多提前2小时
89 - if((dayOfSchedule.isFirstOut(sch) && diff > MAX_BEFORE_TIME) || diff > MAX_BEFORE_TIME / 2) 90 + if ((dayOfSchedule.isFirstOut(sch) && diff > MAX_BEFORE_TIME) || diff > MAX_BEFORE_TIME / 2)
90 return; 91 return;
91 92
92 gps.setPremiseCode(null);//清除前置围栏标记 93 gps.setPremiseCode(null);//清除前置围栏标记
93 94
94 - if(StringUtils.isNotEmpty(sch.getFcsjActual())  
95 - && !outManyFit(gps, sch)){ 95 + if (StringUtils.isNotEmpty(sch.getFcsjActual())
  96 + && !outManyFit(gps, sch)) {
96 return;//班次已经实发 97 return;//班次已经实发
97 } 98 }
98 99
@@ -115,7 +116,7 @@ public class OutStationProcess { @@ -115,7 +116,7 @@ public class OutStationProcess {
115 LateAdjustHandle.remove(sch.getClZbh()); 116 LateAdjustHandle.remove(sch.getClZbh());
116 117
117 //发车的时候,同步一下状态 118 //发车的时候,同步一下状态
118 - if(!gps.isService() && !dayOfSchedule.emptyService(sch)) 119 + if (!gps.isService() && !dayOfSchedule.emptyService(sch))
119 gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 0, "发车@系统"); 120 gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 0, "发车@系统");
120 121
121 logger.info("车辆:" + sch.getClZbh() + " 班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual()); 122 logger.info("车辆:" + sch.getClZbh() + " 班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual());
@@ -126,16 +127,17 @@ public class OutStationProcess { @@ -126,16 +127,17 @@ public class OutStationProcess {
126 127
127 /** 128 /**
128 * 是否是一个更合适的发车信号 129 * 是否是一个更合适的发车信号
  130 + *
129 * @param gps 131 * @param gps
130 * @param sch 132 * @param sch
131 * @return 133 * @return
132 */ 134 */
133 private boolean outManyFit(GpsEntity gps, ScheduleRealInfo sch) { 135 private boolean outManyFit(GpsEntity gps, ScheduleRealInfo sch) {
134 LineConfig conf = lineConfigData.get(sch.getXlBm()); 136 LineConfig conf = lineConfigData.get(sch.getXlBm());
135 - if(null != conf && conf.isLockFirstOutTime()) 137 + if (null != conf && conf.isLockFirstOutTime())
136 return false; 138 return false;
137 139
138 - if(StringUtils.isNotEmpty(sch.getZdsjActual())) 140 + if (StringUtils.isNotEmpty(sch.getZdsjActual()))
139 return false; 141 return false;
140 142
141 long t1 = sch.getFcsjActualTime(); 143 long t1 = sch.getFcsjActualTime();
@@ -143,18 +145,18 @@ public class OutStationProcess { @@ -143,18 +145,18 @@ public class OutStationProcess {
143 long c = sch.getDfsjT(); 145 long c = sch.getDfsjT();
144 146
145 int threshold = 1000 * 60 * 5; 147 int threshold = 1000 * 60 * 5;
146 - if(Math.abs(t2 - c) < threshold && c - t1 > threshold){ 148 + if (Math.abs(t2 - c) < threshold && c - t1 > threshold) {
147 return true; 149 return true;
148 } 150 }
149 151
150 - if(c - t1 > 1000 * 60 * 60 * 2 && Math.abs(t2 - c) < c - t1){ 152 + if (c - t1 > 1000 * 60 * 60 * 2 && Math.abs(t2 - c) < c - t1) {
151 return true; 153 return true;
152 } 154 }
153 return false; 155 return false;
154 } 156 }
155 157
156 - private void outStationAndOutPark(ScheduleRealInfo sch){  
157 - try{ 158 + private void outStationAndOutPark(ScheduleRealInfo sch) {
  159 + try {
158 LineConfig config = lineConfigData.get(sch.getXlBm()); 160 LineConfig config = lineConfigData.get(sch.getXlBm());
159 //限定出站既出场的停车场 161 //限定出站既出场的停车场
160 String park = config.getTwinsPark(); 162 String park = config.getTwinsPark();
@@ -175,26 +177,26 @@ public class OutStationProcess { @@ -175,26 +177,26 @@ public class OutStationProcess {
175 dayOfSchedule.save(schPrev); 177 dayOfSchedule.save(schPrev);
176 } 178 }
177 } 179 }
178 - }catch (Exception e){ 180 + } catch (Exception e) {
179 logger.error("", e); 181 logger.error("", e);
180 } 182 }
181 } 183 }
182 184
183 - private boolean isEmptyMileage(ScheduleRealInfo sch){  
184 - return sch.getBcsj()==0 || sch.getJhlcOrig().intValue()==0; 185 + private boolean isEmptyMileage(ScheduleRealInfo sch) {
  186 + return sch.getBcsj() == 0 || sch.getJhlcOrig().intValue() == 0;
185 } 187 }
186 188
187 - private boolean isOut(ScheduleRealInfo sch){ 189 + private boolean isOut(ScheduleRealInfo sch) {
188 return sch != null && sch.getBcType().equals("out"); 190 return sch != null && sch.getBcType().equals("out");
189 } 191 }
190 192
191 - private void endSch(ScheduleRealInfo sch, Long t){ 193 + private void endSch(ScheduleRealInfo sch, Long t) {
192 sch.setFcsjActualAll(t); 194 sch.setFcsjActualAll(t);
193 sch.setZdsjActualAll(t); 195 sch.setZdsjActualAll(t);
194 } 196 }
195 197
196 - private boolean isOutPark(GpsEntity gps, GpsEntity prve){  
197 - if(StringUtils.isNotEmpty(prve.getCarparkNo()) && StringUtils.isEmpty(gps.getCarparkNo())) 198 + private boolean isOutPark(GpsEntity gps, GpsEntity prve) {
  199 + if (StringUtils.isNotEmpty(prve.getCarparkNo()) && StringUtils.isEmpty(gps.getCarparkNo()))
198 return true; 200 return true;
199 return false; 201 return false;
200 } 202 }
src/main/java/com/bsth/data/gpsdata_v2/rfid/UploadRfidDataService.java
1 -package com.bsth.data.gpsdata_v2.rfid;  
2 -  
3 -import com.alibaba.fastjson.JSON;  
4 -import com.bsth.data.gpsdata_v2.rfid.entity.RfidInoutStation;  
5 -import com.bsth.data.gpsdata_v2.rfid.handle.RfidSignalHandle;  
6 -import org.slf4j.Logger;  
7 -import org.slf4j.LoggerFactory;  
8 -import org.springframework.beans.factory.annotation.Autowired;  
9 -import org.springframework.web.bind.annotation.RequestBody;  
10 -import org.springframework.web.bind.annotation.RequestMapping;  
11 -import org.springframework.web.bind.annotation.RequestMethod;  
12 -import org.springframework.web.bind.annotation.RestController;  
13 -  
14 -import java.util.List;  
15 -  
16 -/**  
17 - * RFID 数据上传入口  
18 - * Created by panzhao on 2017/11/22.  
19 - */  
20 -@RestController  
21 -@RequestMapping("/rfid")  
22 -public class UploadRfidDataService {  
23 -  
24 - @Autowired  
25 - RfidSignalHandle rfidSignalHandle;  
26 -  
27 - Logger logger = LoggerFactory.getLogger(this.getClass());  
28 -  
29 - @RequestMapping(value = "inside", method = RequestMethod.POST)  
30 - public void inside(@RequestBody List<RfidInoutStation> list) {  
31 - logger.info("up rfid: " + JSON.toJSONString(list));  
32 - rfidSignalHandle.handle(list);  
33 - }  
34 -  
35 - @RequestMapping(value = "test")  
36 - public int test() {  
37 - return 1;  
38 - } 1 +package com.bsth.data.gpsdata_v2.rfid;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.bsth.data.gpsdata_v2.rfid.entity.RfidInoutStation;
  5 +import com.bsth.data.gpsdata_v2.rfid.handle.RfidSignalHandle;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.web.bind.annotation.RequestBody;
  10 +import org.springframework.web.bind.annotation.RequestMapping;
  11 +import org.springframework.web.bind.annotation.RequestMethod;
  12 +import org.springframework.web.bind.annotation.RestController;
  13 +
  14 +import java.util.List;
  15 +
  16 +/**
  17 + * RFID 数据上传入口
  18 + * Created by panzhao on 2017/11/22.
  19 + */
  20 +@RestController
  21 +@RequestMapping("/rfid")
  22 +public class UploadRfidDataService {
  23 +
  24 + @Autowired
  25 + RfidSignalHandle rfidSignalHandle;
  26 +
  27 + Logger logger = LoggerFactory.getLogger(this.getClass());
  28 +
  29 + @RequestMapping(value = "inside", method = RequestMethod.POST)
  30 + public void inside(@RequestBody List<RfidInoutStation> list) {
  31 + logger.info("up rfid: " + JSON.toJSONString(list));
  32 + rfidSignalHandle.handle(list);
  33 + }
  34 +
  35 + @RequestMapping(value = "test")
  36 + public int test() {
  37 + return 1;
  38 + }
39 } 39 }
40 \ No newline at end of file 40 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata_v2/rfid/handle/RfidSignalHandle.java
1 -package com.bsth.data.gpsdata_v2.rfid.handle;  
2 -  
3 -import com.bsth.data.gpsdata_v2.rfid.entity.RfidInoutStation;  
4 -import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager;  
5 -import com.bsth.data.msg_queue.DirectivePushQueue;  
6 -import com.bsth.data.schedule.DayOfSchedule;  
7 -import com.bsth.entity.realcontrol.ScheduleRealInfo;  
8 -import com.bsth.websocket.handler.SendUtils;  
9 -import org.apache.commons.lang3.StringUtils;  
10 -import org.slf4j.Logger;  
11 -import org.slf4j.LoggerFactory;  
12 -import org.springframework.beans.factory.annotation.Autowired;  
13 -import org.springframework.stereotype.Component;  
14 -  
15 -import java.util.List;  
16 -  
17 -/**  
18 - * RFID信号处理  
19 - * Created by panzhao on 2017/11/22.  
20 - */  
21 -@Component  
22 -public class RfidSignalHandle {  
23 -  
24 - @Autowired  
25 - DayOfSchedule dayOfSchedule;  
26 -  
27 - @Autowired  
28 - SendUtils sendUtils;  
29 -  
30 - @Autowired  
31 - GpsStatusManager gpsStatusManager;  
32 -  
33 - private final static int MAX_TIME_DIFF = 1000 * 60 * 60 * 2;  
34 -  
35 - Logger logger = LoggerFactory.getLogger(this.getClass());  
36 -  
37 - public void handle(List<RfidInoutStation> list){  
38 - for(RfidInoutStation signal : list){  
39 - if(signal.getType()==2)  
40 - in(signal);  
41 - else if(signal.getType()==4)  
42 - out(signal);  
43 - }  
44 - }  
45 -  
46 - /**  
47 - * 出  
48 - * @param signal  
49 - */  
50 - private void out(RfidInoutStation signal) {  
51 - try{  
52 - String nbbm = signal.getNbbm();  
53 - ScheduleRealInfo sch = dayOfSchedule.executeCurr(nbbm);  
54 -  
55 - if(null == sch)  
56 - return;  
57 -  
58 - //最大时间差  
59 - if(Math.abs(sch.getDfsjT() - signal.getT()) > MAX_TIME_DIFF)  
60 - return;  
61 -  
62 - if(sch.getQdzCode().equals(signal.getStation())  
63 - && StringUtils.isEmpty(sch.getFcsjActual())){  
64 -  
65 - //班次发车  
66 - sch.setFcsjActualAll(signal.getT());  
67 -  
68 - //webSocket  
69 - sendUtils.sendFcsj(sch);  
70 -  
71 - //持久化  
72 - dayOfSchedule.save(sch);  
73 -  
74 - logger.info("RFID; 车辆:" + sch.getClZbh() + " 班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual());  
75 - }  
76 - }catch (Exception e){  
77 - logger.error("", e);  
78 - }  
79 - }  
80 -  
81 - /**  
82 - * 进  
83 - * @param signal  
84 - */  
85 - private void in(RfidInoutStation signal) {  
86 - try{  
87 - String nbbm = signal.getNbbm();  
88 - ScheduleRealInfo sch = dayOfSchedule.executeCurr(nbbm);  
89 -  
90 - if(null == sch)  
91 - return;  
92 -  
93 - //最大时间差  
94 - if(Math.abs(sch.getDfsjT() - signal.getT()) > MAX_TIME_DIFF)  
95 - return;  
96 -  
97 - if(sch.getZdzCode().equals(signal.getStation())  
98 - && StringUtils.isEmpty(sch.getZdsjActual())){  
99 -  
100 - sch.setZdsjActualAll(signal.getT());  
101 -  
102 - //持久化  
103 - dayOfSchedule.save(sch);  
104 -  
105 - //车辆的下一个班次  
106 - ScheduleRealInfo next = dayOfSchedule.next(sch);  
107 - if(next != null){  
108 - dayOfSchedule.addExecPlan(next);  
109 - }  
110 -  
111 - //路牌的下一个班次,页面显示起点实际到达时间  
112 - ScheduleRealInfo lpNext = dayOfSchedule.nextByLp(sch);  
113 - if(lpNext != null){  
114 - lpNext.setQdzArrDatesj(sch.getZdsjActual());  
115 - }  
116 -  
117 - //已完成班次数  
118 - int doneSum = dayOfSchedule.doneSum(nbbm);  
119 -  
120 - //webSocket  
121 - sendUtils.sendZdsj(sch, lpNext, doneSum);  
122 -  
123 - logger.info("RFID; 车辆:" + nbbm + " 班次:" + sch.getDfsj() + "到终点, 时间:" + sch.getZdsjActual());  
124 -  
125 - //下发调度指令  
126 - DirectivePushQueue.put6002(next, doneSum, "rfid@系统");  
127 -  
128 - //套跑 -下发线路切换指令  
129 - if(null != next && !next.getXlBm().equals(sch.getXlBm())){  
130 - gpsStatusManager.changeLine(next.getClZbh(), next.getXlBm(), "rfid@系统");  
131 - }  
132 -  
133 - if(null == next)  
134 - nonService(sch, "rfid1@系统");//班次结束  
135 - else if(null != next && dayOfSchedule.emptyService(next))  
136 - nonService(sch, "rfid2@系统");//下一班非营运  
137 - }  
138 - }catch (Exception e){  
139 - logger.error("", e);  
140 - }  
141 - }  
142 -  
143 - /**  
144 - * 将车载设备切换为非营运状态  
145 - * @param sch  
146 - * @param sender  
147 - */  
148 - private void nonService(ScheduleRealInfo sch, String sender){  
149 - gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 1, sender);  
150 - } 1 +package com.bsth.data.gpsdata_v2.rfid.handle;
  2 +
  3 +import com.bsth.data.gpsdata_v2.rfid.entity.RfidInoutStation;
  4 +import com.bsth.data.gpsdata_v2.status_manager.GpsStatusManager;
  5 +import com.bsth.data.msg_queue.DirectivePushQueue;
  6 +import com.bsth.data.schedule.DayOfSchedule;
  7 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  8 +import com.bsth.websocket.handler.SendUtils;
  9 +import org.apache.commons.lang3.StringUtils;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.stereotype.Component;
  14 +
  15 +import java.util.List;
  16 +
  17 +/**
  18 + * RFID信号处理
  19 + * Created by panzhao on 2017/11/22.
  20 + */
  21 +@Component
  22 +public class RfidSignalHandle {
  23 +
  24 + @Autowired
  25 + DayOfSchedule dayOfSchedule;
  26 +
  27 + @Autowired
  28 + SendUtils sendUtils;
  29 +
  30 + @Autowired
  31 + GpsStatusManager gpsStatusManager;
  32 +
  33 + private final static int MAX_TIME_DIFF = 1000 * 60 * 60 * 2;
  34 +
  35 + Logger logger = LoggerFactory.getLogger(this.getClass());
  36 +
  37 + public void handle(List<RfidInoutStation> list){
  38 + for(RfidInoutStation signal : list){
  39 + if(signal.getType()==2)
  40 + in(signal);
  41 + else if(signal.getType()==4)
  42 + out(signal);
  43 + }
  44 + }
  45 +
  46 + /**
  47 + * 出
  48 + * @param signal
  49 + */
  50 + private void out(RfidInoutStation signal) {
  51 + try{
  52 + String nbbm = signal.getNbbm();
  53 + ScheduleRealInfo sch = dayOfSchedule.executeCurr(nbbm);
  54 +
  55 + if(null == sch)
  56 + return;
  57 +
  58 + //最大时间差
  59 + if(Math.abs(sch.getDfsjT() - signal.getT()) > MAX_TIME_DIFF)
  60 + return;
  61 +
  62 + if(sch.getQdzCode().equals(signal.getStation())
  63 + && StringUtils.isEmpty(sch.getFcsjActual())){
  64 +
  65 + //班次发车
  66 + sch.setFcsjActualAll(signal.getT());
  67 +
  68 + //webSocket
  69 + sendUtils.sendFcsj(sch);
  70 +
  71 + //持久化
  72 + dayOfSchedule.save(sch);
  73 +
  74 + logger.info("RFID; 车辆:" + sch.getClZbh() + " 班次:" + sch.getDfsj() + "发车, 时间:" + sch.getFcsjActual());
  75 + }
  76 + }catch (Exception e){
  77 + logger.error("", e);
  78 + }
  79 + }
  80 +
  81 + /**
  82 + * 进
  83 + * @param signal
  84 + */
  85 + private void in(RfidInoutStation signal) {
  86 + try{
  87 + String nbbm = signal.getNbbm();
  88 + ScheduleRealInfo sch = dayOfSchedule.executeCurr(nbbm);
  89 +
  90 + if(null == sch)
  91 + return;
  92 +
  93 + //最大时间差
  94 + if(Math.abs(sch.getDfsjT() - signal.getT()) > MAX_TIME_DIFF)
  95 + return;
  96 +
  97 + if(sch.getZdzCode().equals(signal.getStation())
  98 + && StringUtils.isEmpty(sch.getZdsjActual())){
  99 +
  100 + sch.setZdsjActualAll(signal.getT());
  101 +
  102 + //持久化
  103 + dayOfSchedule.save(sch);
  104 +
  105 + //车辆的下一个班次
  106 + ScheduleRealInfo next = dayOfSchedule.next(sch);
  107 + if(next != null){
  108 + dayOfSchedule.addExecPlan(next);
  109 + }
  110 +
  111 + //路牌的下一个班次,页面显示起点实际到达时间
  112 + ScheduleRealInfo lpNext = dayOfSchedule.nextByLp(sch);
  113 + if(lpNext != null){
  114 + lpNext.setQdzArrDatesj(sch.getZdsjActual());
  115 + }
  116 +
  117 + //已完成班次数
  118 + int doneSum = dayOfSchedule.doneSum(nbbm);
  119 +
  120 + //webSocket
  121 + sendUtils.sendZdsj(sch, lpNext, doneSum);
  122 +
  123 + logger.info("RFID; 车辆:" + nbbm + " 班次:" + sch.getDfsj() + "到终点, 时间:" + sch.getZdsjActual());
  124 +
  125 + //下发调度指令
  126 + DirectivePushQueue.put6002(next, doneSum, "rfid@系统");
  127 +
  128 + //套跑 -下发线路切换指令
  129 + if(null != next && !next.getXlBm().equals(sch.getXlBm())){
  130 + gpsStatusManager.changeLine(next.getClZbh(), next.getXlBm(), "rfid@系统");
  131 + }
  132 +
  133 + if(null == next)
  134 + nonService(sch, "rfid1@系统");//班次结束
  135 + else if(null != next && dayOfSchedule.emptyService(next))
  136 + nonService(sch, "rfid2@系统");//下一班非营运
  137 + }
  138 + }catch (Exception e){
  139 + logger.error("", e);
  140 + }
  141 + }
  142 +
  143 + /**
  144 + * 将车载设备切换为非营运状态
  145 + * @param sch
  146 + * @param sender
  147 + */
  148 + private void nonService(ScheduleRealInfo sch, String sender){
  149 + gpsStatusManager.changeServiceState(sch.getClZbh(), sch.getXlDir(), 1, sender);
  150 + }
151 } 151 }
152 \ No newline at end of file 152 \ No newline at end of file
src/main/java/com/bsth/data/gpsdata_v2/thread/OfflineMonitorThread.java
1 -package com.bsth.data.gpsdata_v2.thread;  
2 -  
3 -import com.bsth.data.gpsdata_v2.GpsRealData;  
4 -import com.bsth.data.gpsdata_v2.entity.GpsEntity;  
5 -import com.bsth.websocket.handler.SendUtils;  
6 -import org.slf4j.Logger;  
7 -import org.slf4j.LoggerFactory;  
8 -import org.springframework.beans.factory.annotation.Autowired;  
9 -import org.springframework.stereotype.Component;  
10 -  
11 -import java.util.Collection;  
12 -  
13 -/**  
14 - * GPS掉离线监控  
15 - * Created by panzhao on 2017/1/11.  
16 - */  
17 -@Component  
18 -public class OfflineMonitorThread extends Thread{  
19 -  
20 - @Autowired  
21 - GpsRealData gpsRealData;  
22 -  
23 - //掉线阈值  
24 - private final static int LOSE_TIME = 1000 * 60 * 10;  
25 -  
26 - Logger logger = LoggerFactory.getLogger(this.getClass());  
27 -  
28 - @Autowired  
29 - SendUtils sendUtils;  
30 -  
31 - //无任务时 离线阈值  
32 - //private final static int OFFLINE_TIME = 1000 * 60 * 10;  
33 -  
34 - @Override  
35 - public void run() {  
36 - try{  
37 - long t = System.currentTimeMillis();  
38 - Collection<GpsEntity> list = gpsRealData.all();  
39 -  
40 - String state;  
41 - for(GpsEntity gps : list){  
42 - state = gps.getAbnormalStatus();  
43 -  
44 - if(state != null && state.equals("offline"))  
45 - continue;  
46 -  
47 - if (t - gps.getTimestamp() > LOSE_TIME){  
48 - gps.offline();  
49 -  
50 - //通知页面有设备掉线  
51 - sendUtils.deviceOffline(gps);  
52 - }  
53 - }  
54 - }catch (Exception e){  
55 - logger.error("", e);  
56 - }  
57 - }  
58 -} 1 +package com.bsth.data.gpsdata_v2.thread;
  2 +
  3 +import com.bsth.data.gpsdata_v2.GpsRealData;
  4 +import com.bsth.data.gpsdata_v2.entity.GpsEntity;
  5 +import com.bsth.websocket.handler.SendUtils;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.stereotype.Component;
  10 +
  11 +import java.util.Collection;
  12 +
  13 +/**
  14 + * GPS掉离线监控
  15 + * Created by panzhao on 2017/1/11.
  16 + */
  17 +@Component
  18 +public class OfflineMonitorThread extends Thread{
  19 +
  20 + @Autowired
  21 + GpsRealData gpsRealData;
  22 +
  23 + //掉线阈值
  24 + private final static int LOSE_TIME = 1000 * 60 * 10;
  25 +
  26 + Logger logger = LoggerFactory.getLogger(this.getClass());
  27 +
  28 + @Autowired
  29 + SendUtils sendUtils;
  30 +
  31 + //无任务时 离线阈值
  32 + //private final static int OFFLINE_TIME = 1000 * 60 * 10;
  33 +
  34 + @Override
  35 + public void run() {
  36 + try{
  37 + long t = System.currentTimeMillis();
  38 + Collection<GpsEntity> list = gpsRealData.all();
  39 +
  40 + String state;
  41 + for(GpsEntity gps : list){
  42 + state = gps.getAbnormalStatus();
  43 +
  44 + if(state != null && state.equals("offline"))
  45 + continue;
  46 +
  47 + if (t - gps.getTimestamp() > LOSE_TIME){
  48 + gps.offline();
  49 +
  50 + //通知页面有设备掉线
  51 + sendUtils.deviceOffline(gps);
  52 + }
  53 + }
  54 + }catch (Exception e){
  55 + logger.error("", e);
  56 + }
  57 + }
  58 +}
src/main/java/com/bsth/service/oil/impl/DlbServiceImpl.java
@@ -273,18 +273,18 @@ public class DlbServiceImpl extends BaseServiceImpl&lt;Dlb,Integer&gt; implements DlbS @@ -273,18 +273,18 @@ public class DlbServiceImpl extends BaseServiceImpl&lt;Dlb,Integer&gt; implements DlbS
273 } 273 }
274 } 274 }
275 275
276 - Map<String, Double> shMap=new HashMap<String,Double>();  
277 - for (int i = 0; i < dlList.size(); i++) {  
278 - Dlb dlb=dlList.get(i);  
279 - String cl=dlb.getNbbm();  
280 - if(shMap.get(cl)==null){  
281 - shMap.put(cl, dlb.getSh());  
282 - }else{  
283 - double sh=shMap.get(cl);  
284 - shMap.remove(cl);  
285 - shMap.put(cl, Arith.add(sh, dlb.getSh()));  
286 - }  
287 - } 276 +// Map<String, Double> shMap=new HashMap<String,Double>();
  277 +// for (int i = 0; i < dlList.size(); i++) {
  278 +// Dlb dlb=dlList.get(i);
  279 +// String cl=dlb.getNbbm();
  280 +// if(shMap.get(cl)==null){
  281 +// shMap.put(cl, dlb.getSh());
  282 +// }else{
  283 +// double sh=shMap.get(cl);
  284 +// shMap.remove(cl);
  285 +// shMap.put(cl, Arith.add(sh, dlb.getSh()));
  286 +// }
  287 +// }
288 List<Jdl> jdlList=jdlRepository.JdlList(rq); 288 List<Jdl> jdlList=jdlRepository.JdlList(rq);
289 String sxtj=map2.get("sxtj").toString(); 289 String sxtj=map2.get("sxtj").toString();
290 if(sxtj.equals("0")){ 290 if(sxtj.equals("0")){
@@ -357,13 +357,13 @@ public class DlbServiceImpl extends BaseServiceImpl&lt;Dlb,Integer&gt; implements DlbS @@ -357,13 +357,13 @@ public class DlbServiceImpl extends BaseServiceImpl&lt;Dlb,Integer&gt; implements DlbS
357 zjzl = Arith.add(zjzl,jdl.getJdl()); 357 zjzl = Arith.add(zjzl,jdl.getJdl());
358 } 358 }
359 } 359 }
360 - double clsh=0.0;  
361 - if(shMap.get(map_.get("clZbh").toString())==null){  
362 - clsh=0.0;  
363 - }else{  
364 - clsh=shMap.get(map_.get("clZbh").toString());  
365 - }  
366 - zjzl =Arith.sub(zjzl, clsh); 360 +// double clsh=0.0;
  361 +// if(shMap.get(map_.get("clZbh").toString())==null){
  362 +// clsh=0.0;
  363 +// }else{
  364 +// clsh=shMap.get(map_.get("clZbh").toString());
  365 +// }
  366 +// zjzl =Arith.sub(zjzl, clsh);
367 Double nextJzyl = 0.0; 367 Double nextJzyl = 0.0;
368 for (int i = 0; i < listpb.size(); i++) { 368 for (int i = 0; i < listpb.size(); i++) {
369 Map<String, Object> map = listpb.get(i); 369 Map<String, Object> map = listpb.get(i);
@@ -465,7 +465,6 @@ public class DlbServiceImpl extends BaseServiceImpl&lt;Dlb,Integer&gt; implements DlbS @@ -465,7 +465,6 @@ public class DlbServiceImpl extends BaseServiceImpl&lt;Dlb,Integer&gt; implements DlbS
465 t.setJhsj(map.get("fcsj")==null?"":map.get("fcsj").toString()); 465 t.setJhsj(map.get("fcsj")==null?"":map.get("fcsj").toString());
466 t.setRq(sdf.parse(rq)); 466 t.setRq(sdf.parse(rq));
467 t.setLp(map.get("lpName").toString()); 467 t.setLp(map.get("lpName").toString());
468 - t.setCdl(Arith.add(t.getCdl(), t.getSh()));  
469 if(!(t.getSsgsdm().equals("") || t.getFgsdm().equals(""))){ 468 if(!(t.getSsgsdm().equals("") || t.getFgsdm().equals(""))){
470 if(type.equals("add")){ 469 if(type.equals("add")){
471 t.setCreatetime(date); 470 t.setCreatetime(date);
src/main/java/com/bsth/service/oil/impl/YlbServiceImpl.java
@@ -404,7 +404,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS @@ -404,7 +404,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
404 Ylxxb ylxxb = ylxxList.get(i); 404 Ylxxb ylxxb = ylxxList.get(i);
405 if (map.get("clZbh").toString().equals(ylxxb.getNbbm()) 405 if (map.get("clZbh").toString().equals(ylxxb.getNbbm())
406 && map.get("jGh").toString().equals(ylxxb.getJsy()) 406 && map.get("jGh").toString().equals(ylxxb.getJsy())
407 - && ylxxb.getJylx()>0) { 407 + && ylxxb.getJylx()==1) {
408 if(ylxxb.getJzl()>0){ 408 if(ylxxb.getJzl()>0){
409 fage2=true; 409 fage2=true;
410 } 410 }
@@ -418,7 +418,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS @@ -418,7 +418,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
418 Ylxxb ylxxb = ylxxList.get(j); 418 Ylxxb ylxxb = ylxxList.get(j);
419 if (map.get("clZbh").toString().equals(ylxxb.getNbbm()) 419 if (map.get("clZbh").toString().equals(ylxxb.getNbbm())
420 && map.get("jGh").toString().equals(ylxxb.getJsy()) 420 && map.get("jGh").toString().equals(ylxxb.getJsy())
421 - && ylxxb.getJylx()>0) { 421 + && ylxxb.getJylx()==1) {
422 jzl =Arith.add(jzl, ylxxb.getJzl()); 422 jzl =Arith.add(jzl, ylxxb.getJzl());
423 } 423 }
424 } 424 }
@@ -528,16 +528,8 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS @@ -528,16 +528,8 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
528 List<Ylb> ylbList =new ArrayList<Ylb>(); 528 List<Ylb> ylbList =new ArrayList<Ylb>();
529 List<Ylb> ylbLists =new ArrayList<Ylb>(); 529 List<Ylb> ylbLists =new ArrayList<Ylb>();
530 List<Ylb> iterator2=new ArrayList<Ylb>(); 530 List<Ylb> iterator2=new ArrayList<Ylb>();
531 -// if(xlbm.equals("")){  
532 - ylbLists=this.listOrderBy(rq,gsbm,fgsbm,xlbm,nbbm,"jcsx");  
533 -// repository.obtainYl(rq,gsbm,fgsbm,xlbm,nbbm,"jcsx");  
534 - iterator2=this.listOrderBy(rq,gsbm,fgsbm,xlbm,nbbm,"nbbm,jcsx");  
535 -// repository.obtainYl(rq,gsbm,fgsbm,xlbm,nbbm,"nbbm,jcsx");  
536 -// }else{  
537 -// ylbLists=repository.obtainYl_eq(rq,gsbm,fgsbm,xlbm,nbbm,"jcsx");  
538 -// iterator2=repository.obtainYl_eq(rq,gsbm,fgsbm,xlbm,nbbm,"nbbm,jcsx");  
539 -// }  
540 - 531 + ylbLists=this.listOrderBy(rq,gsbm,fgsbm,xlbm,nbbm,"jcsx");
  532 + iterator2=this.listOrderBy(rq,gsbm,fgsbm,xlbm,nbbm,"nbbm,jcsx");
541 // 从排班表中计算出行驶的总里程 533 // 从排班表中计算出行驶的总里程
542 534
543 String sxtj=map.get("sxtj").toString(); 535 String sxtj=map.get("sxtj").toString();
@@ -594,7 +586,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS @@ -594,7 +586,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
594 zlc = Arith.add(zlc, Double.valueOf(sumList.get(j)[1].toString())); 586 zlc = Arith.add(zlc, Double.valueOf(sumList.get(j)[1].toString()));
595 zsh = Arith.add(zsh, Double.valueOf(sumList.get(j)[2].toString())); 587 zsh = Arith.add(zsh, Double.valueOf(sumList.get(j)[2].toString()));
596 } 588 }
597 - jzl = Arith.sub(jzl, zsh); 589 +// jzl = Arith.sub(jzl, zsh);
598 // 保留两位小数 590 // 保留两位小数
599 DecimalFormat df = new DecimalFormat("#.00"); 591 DecimalFormat df = new DecimalFormat("#.00");
600 Double zyl = 0.0; 592 Double zyl = 0.0;
@@ -622,7 +614,8 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS @@ -622,7 +614,8 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
622 if(zlc>0 ){ 614 if(zlc>0 ){
623 yh = Double.parseDouble(df.format(zyl * (t.getZlc() / zlc))); 615 yh = Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
624 } 616 }
625 - nextJzyl =Arith.sub( Arith.add(Arith.sub(t.getJzl(),t.getSh()), t.getCzyl()),yh); 617 + nextJzyl =Arith.sub( Arith.add(t.getJzl(), t.getCzyl()),yh);
  618 +// nextJzyl =Arith.sub( Arith.add(Arith.sub(t.getJzl(),t.getSh()), t.getCzyl()),yh);
626 //把进场油量的小数和整数分别取出 619 //把进场油量的小数和整数分别取出
627 // int ylxs=(int) nextJzyl; 10.6--11 10.3--10 620 // int ylxs=(int) nextJzyl; 10.6--11 10.3--10
628 if(zlc>0 && t.getZlc()>0){ 621 if(zlc>0 && t.getZlc()>0){
@@ -643,7 +636,8 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS @@ -643,7 +636,8 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
643 if(zlc>0){ 636 if(zlc>0){
644 yh= Double.parseDouble(df.format(zyl * (t.getZlc() / zlc))); 637 yh= Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
645 } 638 }
646 - nextJzyl =Arith.sub( Arith.add(Arith.sub(t.getJzl(),t.getSh()),nextJzyl),yh); 639 + nextJzyl =Arith.sub( Arith.add(t.getJzl(),nextJzyl),yh);
  640 +// nextJzyl =Arith.sub( Arith.add(Arith.sub(t.getJzl(),t.getSh()),nextJzyl),yh);
647 if(zlc>0 && t.getZlc()>0){ 641 if(zlc>0 && t.getZlc()>0){
648 long l=0l; 642 long l=0l;
649 double ylxs=0.0; 643 double ylxs=0.0;
@@ -765,7 +759,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS @@ -765,7 +759,7 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
765 for (int i = 0; i < ylxxbList.size(); i++) { 759 for (int i = 0; i < ylxxbList.size(); i++) {
766 Boolean fage=false; 760 Boolean fage=false;
767 Ylxxb y1=ylxxbList.get(i); 761 Ylxxb y1=ylxxbList.get(i);
768 - if(m.get(y1.getNbbm())!=null){ 762 + if(m.get(y1.getNbbm())==null){
769 Line line=BasicData.nbbm2LineMap.get(y1.getNbbm()); 763 Line line=BasicData.nbbm2LineMap.get(y1.getNbbm());
770 if(null !=line){ 764 if(null !=line){
771 if(!xlbm.equals("")){ 765 if(!xlbm.equals("")){
@@ -808,7 +802,6 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS @@ -808,7 +802,6 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
808 if(status){ 802 if(status){
809 t.setCzyl(0.0); 803 t.setCzyl(0.0);
810 } 804 }
811 -// double jzyl=Arith.add(t.getJzl(), t.getCzyl());  
812 t.setJzyl(Arith.add(t.getJzl(), t.getCzyl())); 805 t.setJzyl(Arith.add(t.getJzl(), t.getCzyl()));
813 t.setYh(0.0); 806 t.setYh(0.0);
814 if(!(t.getSsgsdm().equals("") || t.getFgsdm().equals(""))){ 807 if(!(t.getSsgsdm().equals("") || t.getFgsdm().equals(""))){
@@ -1160,26 +1153,11 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS @@ -1160,26 +1153,11 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
1160 Integer id =jsonObject.getInteger("id"); 1153 Integer id =jsonObject.getInteger("id");
1161 String nbbm =jsonObject.getString("nbbm"); 1154 String nbbm =jsonObject.getString("nbbm");
1162 String rq=jsonObject.getString("rq"); 1155 String rq=jsonObject.getString("rq");
1163 - double yh = Arith.sub(Arith.add(czyl, jzl), Arith.add(jzyl, sh)); 1156 + double yh = Arith.sub(Arith.add(czyl, jzl),sh);
1164 if(yh<0){ 1157 if(yh<0){
1165 yh=0.0; 1158 yh=0.0;
1166 } 1159 }
1167 - /*t.setJzyl(jzyl);  
1168 - t.setSh(sh);  
1169 - t.setShyy(shyy);  
1170 - t.setNs(ns);  
1171 - t.setRylx(rylx);  
1172 - t.setId(jsonObject.getInteger("id"));*/  
1173 repository.ylbUpdate(id, czyl, jzyl, yh, sh, shyy, ns, rylx,yhlx); 1160 repository.ylbUpdate(id, czyl, jzyl, yh, sh, shyy, ns, rylx,yhlx);
1174 - /*for (int z = 0; z < cylList.size(); z++) {  
1175 - Cyl cyl = cylList.get(z);  
1176 - if (nbbm.equals(cyl.getNbbm())) {  
1177 - cyl.setCyl(jzyl);  
1178 - cyl.setUpdatetime(sdf.parse(rq));  
1179 - break;  
1180 - }  
1181 - cylRepository.save(cyl);  
1182 - }*/  
1183 } 1161 }
1184 // List<Map<String, Object>> list=(List<Map<String, Object>>) map.get("ylbList"); 1162 // List<Map<String, Object>> list=(List<Map<String, Object>>) map.get("ylbList");
1185 1163
@@ -1233,12 +1211,12 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS @@ -1233,12 +1211,12 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
1233 } 1211 }
1234 // jzl = Arith.sub(jzl, zsh); 1212 // jzl = Arith.sub(jzl, zsh);
1235 //新的 损耗不等于 旧的损耗 总损耗从新算 1213 //新的 损耗不等于 旧的损耗 总损耗从新算
1236 - if(Arith.sub(ylb.getSh(),sh )!=0){ 1214 + /*if(Arith.sub(ylb.getSh(),sh )!=0){
1237 zsh =Arith.add(Arith.sub(zsh, ylb.getSh()), sh); 1215 zsh =Arith.add(Arith.sub(zsh, ylb.getSh()), sh);
1238 jzl =Arith.sub(jzl, zsh); 1216 jzl =Arith.sub(jzl, zsh);
1239 }else{ 1217 }else{
1240 jzl =Arith.sub(jzl, zsh); 1218 jzl =Arith.sub(jzl, zsh);
1241 - } 1219 + }*/
1242 map.put("nbbm_eq", nbbm_eq); 1220 map.put("nbbm_eq", nbbm_eq);
1243 map.put("rq_eq", rq_eq); 1221 map.put("rq_eq", rq_eq);
1244 1222
@@ -1265,7 +1243,8 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS @@ -1265,7 +1243,8 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
1265 if (zlc > 0 && t.getZlc() > 0) { 1243 if (zlc > 0 && t.getZlc() > 0) {
1266 yh = Double.parseDouble(df.format(zyl * (t.getZlc() / zlc))); 1244 yh = Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
1267 } 1245 }
1268 - nextJzyl =Arith.sub(Arith.add(t.getJzl(), t.getCzyl()), Arith.add(yh, t.getSh())); 1246 + nextJzyl =Arith.sub(Arith.add(t.getJzl(), t.getCzyl()), yh);
  1247 +// nextJzyl =Arith.sub(Arith.add(t.getJzl(), t.getCzyl()), Arith.add(yh, t.getSh()));
1269 if(zlc>0 && t.getZlc() > 0){ 1248 if(zlc>0 && t.getZlc() > 0){
1270 long l=Math.round(nextJzyl); 1249 long l=Math.round(nextJzyl);
1271 double ylxs=l*100/100; 1250 double ylxs=l*100/100;
@@ -1288,7 +1267,8 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS @@ -1288,7 +1267,8 @@ public class YlbServiceImpl extends BaseServiceImpl&lt;Ylb,Integer&gt; implements YlbS
1288 if (t.getZlc() >= 0) { 1267 if (t.getZlc() >= 0) {
1289 yh= Double.parseDouble(df.format(zyl * (t.getZlc() / zlc))); 1268 yh= Double.parseDouble(df.format(zyl * (t.getZlc() / zlc)));
1290 } 1269 }
1291 - nextJzyl = Arith.sub(Arith.add(t.getJzl(), nextJzyl), Arith.add(yh, t.getSh())); 1270 +// nextJzyl = Arith.sub(Arith.add(t.getJzl(), nextJzyl), Arith.add(yh, t.getSh()));
  1271 + nextJzyl = Arith.sub(Arith.add(t.getJzl(), nextJzyl), yh);
1292 if(zlc>0 && t.getZlc() >0){ 1272 if(zlc>0 && t.getZlc() >0){
1293 long l=0l; 1273 long l=0l;
1294 double ylxs=0.0; 1274 double ylxs=0.0;
src/main/java/com/bsth/service/schedule/datatools/TTInfoDetailDataToolsImpl.java
@@ -164,7 +164,7 @@ public class TTInfoDetailDataToolsImpl implements DataToolsService, TTInfoDetail @@ -164,7 +164,7 @@ public class TTInfoDetailDataToolsImpl implements DataToolsService, TTInfoDetail
164 ktrParms.put("erroroutputdir", dataToolsProperties.getTransErrordir()); 164 ktrParms.put("erroroutputdir", dataToolsProperties.getTransErrordir());
165 165
166 // 附加参数 166 // 附加参数
167 - ktrParms.put("injectktrfile", zdlyversion == null ? 167 + ktrParms.put("injectktrfile", zdlyversion == null || zdlyversion == -1 ?
168 ktrFile2.getAbsolutePath() : ktrFile2_ls.getAbsolutePath()); // 注入元数据的ktr文件 168 ktrFile2.getAbsolutePath() : ktrFile2_ls.getAbsolutePath()); // 注入元数据的ktr文件
169 ktrParms.put("sheetname", sheetname); // sheet工作区的名字 169 ktrParms.put("sheetname", sheetname); // sheet工作区的名字
170 ktrParms.put("lineinfoid", lineid); // 线路标准id 170 ktrParms.put("lineinfoid", lineid); // 线路标准id