Commit ba8b101ae7a6a4ffd76e5053605ad7ceecde6257

Authored by 潘钊
1 parent 4ec6a915

指令相关

Showing 31 changed files with 1410 additions and 458 deletions
src/main/java/com/bsth/StartCommand.java
@@ -11,9 +11,11 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -11,9 +11,11 @@ import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.boot.CommandLineRunner; 11 import org.springframework.boot.CommandLineRunner;
12 import org.springframework.stereotype.Component; 12 import org.springframework.stereotype.Component;
13 13
14 -import com.bsth.common.GetSchedulePlanThread;  
15 import com.bsth.security.SecurityMetadataSourceService; 14 import com.bsth.security.SecurityMetadataSourceService;
16 import com.bsth.util.DateUtils; 15 import com.bsth.util.DateUtils;
  16 +import com.bsth.vehicle.GetSchedulePlanThread;
  17 +import com.bsth.vehicle.common.CommonRefreshThread;
  18 +import com.bsth.vehicle.directive.DirectivePersistenceThread;
17 import com.bsth.vehicle.gpsdata.GpsRefreshThread; 19 import com.bsth.vehicle.gpsdata.GpsRefreshThread;
18 20
19 /** 21 /**
@@ -29,7 +31,7 @@ public class StartCommand implements CommandLineRunner{ @@ -29,7 +31,7 @@ public class StartCommand implements CommandLineRunner{
29 @Autowired 31 @Autowired
30 SecurityMetadataSourceService invocationSecurityMetadataSourceService; 32 SecurityMetadataSourceService invocationSecurityMetadataSourceService;
31 33
32 - public static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2); 34 + public static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(4);
33 35
34 @Autowired 36 @Autowired
35 GpsRefreshThread gpsRefreshThread; 37 GpsRefreshThread gpsRefreshThread;
@@ -37,6 +39,12 @@ public class StartCommand implements CommandLineRunner{ @@ -37,6 +39,12 @@ public class StartCommand implements CommandLineRunner{
37 @Autowired 39 @Autowired
38 GetSchedulePlanThread getSchedulePlanThread; 40 GetSchedulePlanThread getSchedulePlanThread;
39 41
  42 + @Autowired
  43 + CommonRefreshThread commonRefreshThread;
  44 +
  45 + @Autowired
  46 + DirectivePersistenceThread directivePersistenceThread;
  47 +
40 @Override 48 @Override
41 public void run(String... arg0){ 49 public void run(String... arg0){
42 50
@@ -44,18 +52,19 @@ public class StartCommand implements CommandLineRunner{ @@ -44,18 +52,19 @@ public class StartCommand implements CommandLineRunner{
44 //启动时加载所有资源 52 //启动时加载所有资源
45 invocationSecurityMetadataSourceService.loadResourceDefine(); 53 invocationSecurityMetadataSourceService.loadResourceDefine();
46 54
47 - /**  
48 - * GPS实时数据更新线程,每次执行完成4秒后开始下一次  
49 - * 如果抛出异常,后续执行将被取消  
50 - */ 55 + //GPS实时数据更新线程,每次执行完成4秒后开始下一次
51 //scheduler.scheduleWithFixedDelay(gpsRefreshThread, 0, 4, TimeUnit.SECONDS); 56 //scheduler.scheduleWithFixedDelay(gpsRefreshThread, 0, 4, TimeUnit.SECONDS);
52 57
53 - /**  
54 - * 定时0点从计划排班表抓取当天实际排班  
55 - */  
56 - //scheduler.scheduleAtFixedRate(getSchedulePlanThread  
57 - // , 0//DateUtils.getTimesnight() - System.currentTimeMillis() / 1000  
58 - // , 60 * 60 * 24, TimeUnit.SECONDS); 58 + //定时0点从计划排班表抓取当天实际排班
  59 + /*scheduler.scheduleAtFixedRate(getSchedulePlanThread
  60 + , 0//DateUtils.getTimesnight() - System.currentTimeMillis() / 1000
  61 + , 60 * 60 * 24, TimeUnit.SECONDS);*/
  62 +
  63 + //两分钟调度指令入库一次
  64 + //scheduler.scheduleWithFixedDelay(directivePersistenceThread, 20, 60 * 1, TimeUnit.SECONDS);
  65 +
  66 + //两小时刷新一次对照数据
  67 + //scheduler.scheduleWithFixedDelay(commonRefreshThread, 0, 60 * 60 * 2, TimeUnit.SECONDS);
59 } catch (Exception e) { 68 } catch (Exception e) {
60 e.printStackTrace(); 69 e.printStackTrace();
61 } 70 }
src/main/java/com/bsth/common/Constants.java
@@ -20,4 +20,7 @@ public class Constants { @@ -20,4 +20,7 @@ public class Constants {
20 public static final String FAVICON_URL = "/favicon.ico"; 20 public static final String FAVICON_URL = "/favicon.ico";
21 public static final String METRONIC_URL = "/metronic_v4.5.4/**"; 21 public static final String METRONIC_URL = "/metronic_v4.5.4/**";
22 public static final String LOGIN_FAILURE = "/user/loginFailure"; 22 public static final String LOGIN_FAILURE = "/user/loginFailure";
  23 +
  24 + //车载网关上行接口
  25 + public static final String UPSTREAM_URL = "/control/upstream";
23 } 26 }
src/main/java/com/bsth/controller/realcontrol/DirectiveController.java deleted 100644 → 0
1 -package com.bsth.controller.realcontrol;  
2 -  
3 -import org.springframework.web.bind.annotation.RequestMapping;  
4 -import org.springframework.web.bind.annotation.RestController;  
5 -  
6 -/**  
7 - *  
8 - * @ClassName: DirectiveController  
9 - * @Description: TODO(调度指令)  
10 - * @author PanZhao  
11 - * @date 2016年6月7日 上午9:52:11  
12 - *  
13 - */  
14 -@RestController  
15 -@RequestMapping("/realcontrol/directive")  
16 -public class DirectiveController {  
17 -  
18 -}  
src/main/java/com/bsth/entity/realcontrol/ScheduleRealInfo.java
@@ -11,247 +11,109 @@ import java.util.Date; @@ -11,247 +11,109 @@ import java.util.Date;
11 @Entity 11 @Entity
12 @Table(name = "bsth_c_s_sp_info_real") 12 @Table(name = "bsth_c_s_sp_info_real")
13 public class ScheduleRealInfo { 13 public class ScheduleRealInfo {
14 -  
15 - /** 主键Id */  
16 - @Id  
17 - @GeneratedValue  
18 - private Long id;  
19 -  
20 - /** 排班计划日期 */  
21 - private Date scheduleDate;  
22 -  
23 - /** 路牌名称 */  
24 - private String lpName;  
25 - /** 线路编码 */  
26 - private String xlBm;  
27 - /** 线路名称 */  
28 - private String xlName;  
29 - /** 车辆自编号 */  
30 - private String clZbh;  
31 -  
32 - /** 报道1时间(格式 HH:mm) */  
33 - private String bd1Time;  
34 - /** 出场1时间(格式 HH:mm) */  
35 - private String cc1Time;  
36 - /** 驾驶员1工号 */  
37 - private String j1Gh;  
38 - /** 驾驶员1名字 */  
39 - private String j1Name;  
40 - /** 售票员1工号 */  
41 - private String s1Gh;  
42 - /** 售票员1名字 */  
43 - private String s1Name;  
44 -  
45 - // 冗余的时刻明细信息  
46 - /** 线路方向 */  
47 - private String xlDir;  
48 - /** 起点站名称 */  
49 - private String qdz;  
50 - /** 终点站名称 */  
51 - private String zdz;  
52 - /** 发车时间(格式 HH:mm) */  
53 - private String fcsj;  
54 - /** 发车顺序号 */  
55 - private int fcno;  
56 - /** 对应班次数 */  
57 - private int bcs;  
58 - /** 计划里程 */  
59 - private double jhlc;  
60 - /** 班次历时 */  
61 - private int bcsj;  
62 -  
63 - /** 操作人 */  
64 - @ManyToOne(optional = false, cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)  
65 - private SysUser user;  
66 -  
67 - // 创建日期  
68 - @Column(updatable = false, name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")  
69 - private Date createDate;  
70 - // 修改日期  
71 - @Column(name = "update_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")  
72 - private Date updateDate;  
73 -  
74 - public Long getId() {  
75 - return id;  
76 - }  
77 -  
78 - public void setId(Long id) {  
79 - this.id = id;  
80 - }  
81 -  
82 - public Date getScheduleDate() {  
83 - return scheduleDate;  
84 - }  
85 -  
86 - public void setScheduleDate(Date scheduleDate) {  
87 - this.scheduleDate = scheduleDate;  
88 - }  
89 -  
90 - public String getLpName() {  
91 - return lpName;  
92 - }  
93 -  
94 - public void setLpName(String lpName) {  
95 - this.lpName = lpName;  
96 - }  
97 -  
98 - public String getXlName() {  
99 - return xlName;  
100 - }  
101 -  
102 - public void setXlName(String xlName) {  
103 - this.xlName = xlName;  
104 - }  
105 -  
106 - public String getClZbh() {  
107 - return clZbh;  
108 - }  
109 -  
110 - public void setClZbh(String clZbh) {  
111 - this.clZbh = clZbh;  
112 - }  
113 -  
114 - public String getCc1Time() {  
115 - return cc1Time;  
116 - }  
117 -  
118 - public void setCc1Time(String cc1Time) {  
119 - this.cc1Time = cc1Time;  
120 - }  
121 -  
122 - public String getJ1Gh() {  
123 - return j1Gh;  
124 - }  
125 -  
126 - public void setJ1Gh(String j1Gh) {  
127 - this.j1Gh = j1Gh;  
128 - }  
129 -  
130 - public String getJ1Name() {  
131 - return j1Name;  
132 - }  
133 -  
134 - public void setJ1Name(String j1Name) {  
135 - this.j1Name = j1Name;  
136 - }  
137 -  
138 - public String getS1Gh() {  
139 - return s1Gh;  
140 - }  
141 -  
142 - public void setS1Gh(String s1Gh) {  
143 - this.s1Gh = s1Gh;  
144 - }  
145 -  
146 - public String getS1Name() {  
147 - return s1Name;  
148 - }  
149 -  
150 - public void setS1Name(String s1Name) {  
151 - this.s1Name = s1Name;  
152 - }  
153 -  
154 - public String getBd1Time() {  
155 - return bd1Time;  
156 - }  
157 -  
158 - public void setBd1Time(String bd1Time) {  
159 - this.bd1Time = bd1Time;  
160 - }  
161 -  
162 - public String getXlDir() {  
163 - return xlDir;  
164 - }  
165 -  
166 - public void setXlDir(String xlDir) {  
167 - this.xlDir = xlDir;  
168 - }  
169 -  
170 - public String getQdz() {  
171 - return qdz;  
172 - }  
173 -  
174 - public void setQdz(String qdz) {  
175 - this.qdz = qdz;  
176 - }  
177 -  
178 - public String getZdz() {  
179 - return zdz;  
180 - }  
181 -  
182 - public void setZdz(String zdz) {  
183 - this.zdz = zdz;  
184 - }  
185 -  
186 - public String getFcsj() {  
187 - return fcsj;  
188 - }  
189 -  
190 - public void setFcsj(String fcsj) {  
191 - this.fcsj = fcsj;  
192 - }  
193 -  
194 - public SysUser getUser() {  
195 - return user;  
196 - }  
197 -  
198 - public void setUser(SysUser user) {  
199 - this.user = user;  
200 - }  
201 -  
202 - public Date getCreateDate() {  
203 - return createDate;  
204 - }  
205 -  
206 - public void setCreateDate(Date createDate) {  
207 - this.createDate = createDate;  
208 - }  
209 -  
210 - public Date getUpdateDate() {  
211 - return updateDate;  
212 - }  
213 -  
214 - public void setUpdateDate(Date updateDate) {  
215 - this.updateDate = updateDate;  
216 - }  
217 -  
218 - public int getFcno() {  
219 - return fcno;  
220 - }  
221 -  
222 - public void setFcno(int fcno) {  
223 - this.fcno = fcno;  
224 - }  
225 -  
226 - public int getBcs() {  
227 - return bcs;  
228 - }  
229 -  
230 - public void setBcs(int bcs) {  
231 - this.bcs = bcs;  
232 - }  
233 -  
234 - public double getJhlc() {  
235 - return jhlc;  
236 - }  
237 -  
238 - public void setJhlc(double jhlc) {  
239 - this.jhlc = jhlc;  
240 - }  
241 -  
242 - public int getBcsj() {  
243 - return bcsj;  
244 - }  
245 -  
246 - public void setBcsj(int bcsj) {  
247 - this.bcsj = bcsj;  
248 - }  
249 -  
250 - public String getXlBm() {  
251 - return xlBm;  
252 - }  
253 -  
254 - public void setXlBm(String xlBm) {  
255 - this.xlBm = xlBm;  
256 - } 14 + /** 主键Id */
  15 + @Id
  16 + @GeneratedValue
  17 + private Long id;
  18 +
  19 + /** 排班计划日期 */
  20 + @Column(nullable = false)
  21 + private Date scheduleDate;
  22 +
  23 + /** 关联 bsth_c_line 主键,不做mapping */
  24 + @Column(nullable = false)
  25 + private Integer xl;
  26 + /** 线路名称 */
  27 + @Column(nullable = false)
  28 + private String xlName;
  29 + /** 线路编码 */
  30 + @Column(nullable = false)
  31 + private String xlBm;
  32 +
  33 + /** 关联 bsth_c_s_gbi 主键,不做mapping */
  34 + @Column(nullable = false)
  35 + private Long lp;
  36 + /** 路牌名称 */
  37 + @Column(nullable = false)
  38 + private String lpName;
  39 +
  40 + /** 关联 bsth_c_cars 主键,不做mapping */
  41 + @Column(nullable = false)
  42 + private Integer cl;
  43 + /** 车辆自编号 */
  44 + @Column(nullable = false)
  45 + private String clZbh;
  46 +
  47 + /** 报道时间(格式 HH:mm) */
  48 + private String bdTime;
  49 + /** 出场时间(格式 HH:mm) */
  50 + private String ccTime;
  51 + /** 关联 bsth_c_personnel 主键,不做mapping */
  52 + @Column(nullable = false)
  53 + private Integer j;
  54 + /** 驾驶员工号 */
  55 + @Column(nullable = false)
  56 + private String jGh;
  57 + /** 驾驶员名字 */
  58 + @Column(nullable = false)
  59 + private String jName;
  60 + /** 售票员工号 */
  61 + private String sGh;
  62 + /** 售票员名字 */
  63 + private String sName;
  64 +
  65 + /** 线路方向(TODO:上下行,上行,下行,这个以后用枚举还是字典再议,现在先用文字) */
  66 + @Column(nullable = false)
  67 + private String xlDir;
  68 + /** 起点站id,根据班次类型,会关联 bsth_c_station,或 bsth_c_car_park,不做mapping */
  69 + @Column(nullable = false)
  70 + private Integer qdz;
  71 + /** 起点站名字 */
  72 + @Column(nullable = false)
  73 + private String qdzName;
  74 + /** 终点站id,根据班次类型,会关联 bsth_c_station,或 bsth_c_car_park,不做mapping */
  75 + @Column(nullable = false)
  76 + private Integer zdz;
  77 + /** 终点站名字 */
  78 + @Column(nullable = false)
  79 + private String zdzName;
  80 +
  81 + /** 发车时间(格式 HH:mm) */
  82 + @Column(nullable = false)
  83 + private String fcsj;
  84 + /** 发车顺序号 */
  85 + @Column(nullable = false)
  86 + private Integer fcno;
  87 + /** 对应班次数 */
  88 + @Column(nullable = false)
  89 + private Integer bcs;
  90 + /** 计划里程 */
  91 + private Double jhlc;
  92 + /** 班次历时 */
  93 + private Integer bcsj;
  94 +
  95 + /**
  96 + * 班次类型 TODO:正常班次、出场、进场、加油、临加班次、区间班次、放空班次、放大站班次、两点间空驶
  97 + * TODO:这个以后用枚举还是字典再议,现在先用文字
  98 + */
  99 + @Column(nullable = false)
  100 + private String bcType;
  101 +
  102 + /** 创建人 */
  103 + @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
  104 + private SysUser createBy;
  105 + /** 修改人 */
  106 + @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
  107 + private SysUser updateBy;
  108 + /** 创建日期 */
  109 + @Column(updatable = false, name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
  110 + private Date createDate;
  111 + /** 修改日期 */
  112 + @Column(name = "update_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
  113 + private Date updateDate;
  114 +
  115 + //实际发车时间
  116 + private String sjqdsj;
  117 + //实际到达时间
  118 + private String sjzdsj;
257 } 119 }
src/main/java/com/bsth/filter/BaseFilter.java
@@ -24,7 +24,7 @@ public abstract class BaseFilter implements Filter { @@ -24,7 +24,7 @@ public abstract class BaseFilter implements Filter {
24 * 白名单 24 * 白名单
25 */ 25 */
26 private String[] whiteListURLs = { Constants.LOGIN_PAGE, 26 private String[] whiteListURLs = { Constants.LOGIN_PAGE,
27 - Constants.ASSETS_URL, Constants.FAVICON_URL, Constants.METRONIC_URL, Constants.LOGIN, Constants.LOGIN_FAILURE }; 27 + Constants.ASSETS_URL, Constants.FAVICON_URL, Constants.METRONIC_URL, Constants.LOGIN, Constants.LOGIN_FAILURE, Constants.UPSTREAM_URL };
28 28
29 @Override 29 @Override
30 public void destroy() { 30 public void destroy() {
src/main/java/com/bsth/security/WebSecurityConfig.java
@@ -36,7 +36,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @@ -36,7 +36,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
36 // 白名单 36 // 白名单
37 web.ignoring().antMatchers(Constants.ASSETS_URL, Constants.FAVICON_URL, 37 web.ignoring().antMatchers(Constants.ASSETS_URL, Constants.FAVICON_URL,
38 Constants.METRONIC_URL, Constants.LOGIN_PAGE, 38 Constants.METRONIC_URL, Constants.LOGIN_PAGE,
39 - Constants.LOGIN_FAILURE); 39 + Constants.LOGIN_FAILURE, Constants.UPSTREAM_URL);
40 } 40 }
41 41
42 @Override 42 @Override
src/main/java/com/bsth/common/GetSchedulePlanThread.java renamed to src/main/java/com/bsth/vehicle/GetSchedulePlanThread.java
1 -package com.bsth.common; 1 +package com.bsth.vehicle;
2 2
3 import java.text.SimpleDateFormat; 3 import java.text.SimpleDateFormat;
4 -import java.util.Date;  
5 -import java.util.Iterator;  
6 import java.util.List; 4 import java.util.List;
7 5
8 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,7 +29,5 @@ public class GetSchedulePlanThread extends Thread{ @@ -31,7 +29,5 @@ public class GetSchedulePlanThread extends Thread{
31 public void run() { 29 public void run() {
32 List<SchedulePlanInfo> list = schedulePlanInfoRepository.findByDate(/*sdf.format(new Date())*/"2016-06-01"); 30 List<SchedulePlanInfo> list = schedulePlanInfoRepository.findByDate(/*sdf.format(new Date())*/"2016-06-01");
33 31
34 -  
35 -  
36 } 32 }
37 } 33 }
src/main/java/com/bsth/vehicle/UpstreamEntrance.java
1 package com.bsth.vehicle; 1 package com.bsth.vehicle;
2 2
  3 +import org.slf4j.Logger;
  4 +import org.slf4j.LoggerFactory;
  5 +import org.springframework.beans.factory.annotation.Autowired;
3 import org.springframework.web.bind.annotation.RequestMapping; 6 import org.springframework.web.bind.annotation.RequestMapping;
  7 +import org.springframework.web.bind.annotation.RequestMethod;
  8 +import org.springframework.web.bind.annotation.RequestParam;
4 import org.springframework.web.bind.annotation.RestController; 9 import org.springframework.web.bind.annotation.RestController;
5 10
  11 +import com.alibaba.fastjson.JSON;
  12 +import com.alibaba.fastjson.JSONObject;
  13 +import com.bsth.vehicle.directive.buffer.DirectiveBuffer;
  14 +import com.bsth.vehicle.directive.entity.DirectiveReply;
  15 +import com.bsth.vehicle.directive.entity.DriverReport;
  16 +
6 /** 17 /**
7 * 18 *
8 * @ClassName: UpstreamEntrance 19 * @ClassName: UpstreamEntrance
9 - * @Description: TODO(车载网关上行入口) 20 + * @Description: TODO(车载网关HTTP上行入口)
10 * @author PanZhao 21 * @author PanZhao
11 * @date 2016年6月7日 下午3:00:01 22 * @date 2016年6月7日 下午3:00:01
12 * 23 *
13 */ 24 */
14 @RestController 25 @RestController
15 -@RequestMapping("/control/upstream") 26 +@RequestMapping("/control")
16 public class UpstreamEntrance { 27 public class UpstreamEntrance {
17 - 28 +
  29 + Logger logger = LoggerFactory.getLogger(this.getClass());
  30 +
  31 + @Autowired
  32 + DirectiveBuffer directiveBuffer;
  33 +
  34 + @RequestMapping(value = "/upstream" , method = RequestMethod.POST)
  35 + public int main(@RequestParam String json){
  36 + logger.info(json);
  37 + JSONObject jsonParam = JSONObject.parseObject(json);
  38 +
  39 + //46和47 调度指令确认
  40 + if(jsonParam.getInteger("operCode") == null
  41 + && jsonParam.getInteger("status") != null){
  42 + try{
  43 + DirectiveReply reply = JSON.toJavaObject(jsonParam, DirectiveReply.class);
  44 + directiveBuffer.reply(reply);
  45 + }catch(NumberFormatException e){
  46 + logger.error("NumberFormatException ,,,,一般是老数据,msgId太大");
  47 + }
  48 + }
  49 + //80协议,驾驶员上报
  50 + else if(jsonParam.getInteger("operCode") == 0X80){
  51 + try{
  52 + DriverReport report = JSON.toJavaObject(jsonParam, DriverReport.class);
  53 + directiveBuffer.jsyReport(report);
  54 + }catch(Exception e){
  55 + logger.error("", e);
  56 + }
  57 + }
  58 + //64协议 线路切换回复
  59 + else if(jsonParam.getInteger("operCode") == 0X64){
  60 + directiveBuffer.reply64(jsonParam);
  61 + }
  62 + else
  63 + logger.warn("未知的上行数据,p: " + json);
  64 +
  65 + return 0;
  66 + }
18 } 67 }
src/main/java/com/bsth/vehicle/common/CommonMapped.java 0 → 100644
  1 +package com.bsth.vehicle.common;
  2 +
  3 +import java.util.Map;
  4 +
  5 +import com.google.common.collect.BiMap;
  6 +
  7 +/**
  8 + *
  9 + * @ClassName: CommonMapped
  10 + * @Description: TODO(常用的数据映射)
  11 + * @author PanZhao
  12 + * @date 2016年6月7日 下午4:01:43
  13 + *
  14 + */
  15 +public class CommonMapped {
  16 +
  17 +
  18 + /**
  19 + * 设备号和车辆自编号
  20 + * (K: 设备编码 ,V:车辆自编号)
  21 + */
  22 + public static BiMap<String, String> vehicDeviceBiMap;
  23 +
  24 + /**
  25 + * 设备号和线路编码对照
  26 + * (K: 设备编码 ,V:线路编码)
  27 + */
  28 + //public static Map<String, Integer> deviceLineMap;
  29 +
  30 +
  31 + /**
  32 + * 车辆自编号和公司代码对照
  33 + * (K: 车辆自编号 ,V:公司代码)
  34 + */
  35 + public static Map<String , String> vehicCompanyMap;
  36 +
  37 + /**
  38 + * 站点和编码对照
  39 + *(K: 站点编码 ,V:站点名称)
  40 + */
  41 + public static Map<String, String> stationCodeMap;
  42 +
  43 +}
src/main/java/com/bsth/vehicle/common/CommonRefreshThread.java 0 → 100644
  1 +package com.bsth.vehicle.common;
  2 +
  3 +import java.util.HashMap;
  4 +import java.util.Iterator;
  5 +import java.util.Map;
  6 +
  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 com.bsth.entity.Cars;
  13 +import com.bsth.entity.Station;
  14 +import com.bsth.repository.CarsRepository;
  15 +import com.bsth.repository.StationRepository;
  16 +import com.google.common.collect.BiMap;
  17 +import com.google.common.collect.HashBiMap;
  18 +
  19 +/**
  20 + *
  21 + * @ClassName: CommonRefreshThread
  22 + * @Description: TODO(刷新映射数据)
  23 + * @author PanZhao
  24 + * @date 2016年6月7日 下午4:05:34
  25 + *
  26 + */
  27 +@Component
  28 +public class CommonRefreshThread extends Thread{
  29 +
  30 + @Autowired
  31 + CarsRepository carsRepository;
  32 +
  33 + @Autowired
  34 + StationRepository stationRepository;
  35 +
  36 + Logger logger = LoggerFactory.getLogger(this.getClass());
  37 +
  38 + @Override
  39 + public void run() {
  40 + try {
  41 + initVehicMapp();
  42 + initStationCodeMap();
  43 + } catch (Exception e) {
  44 + logger.error("", e);
  45 + }
  46 + }
  47 +
  48 + /**
  49 + *
  50 + * @Title: initDeviceMapp
  51 + * @Description: TODO(初始化车辆相关对照)
  52 + */
  53 + public void initVehicMapp(){
  54 + BiMap<String, String> biMap = HashBiMap.create();
  55 + //车辆和公司代码对照
  56 + Map<String, String> vcMap = new HashMap<>();
  57 + Iterator<Cars> carIterator = carsRepository.findAll().iterator();
  58 + Cars car;
  59 + while(carIterator.hasNext()){
  60 + car = carIterator.next();
  61 + biMap.put(car.getEquipmentCode(), car.getInsideCode());
  62 + vcMap.put(car.getInsideCode(), car.getBusinessCode());
  63 + }
  64 +
  65 + CommonMapped.vehicDeviceBiMap = biMap;
  66 + CommonMapped.vehicCompanyMap = vcMap;
  67 + }
  68 +
  69 + /**
  70 + *
  71 + * @Title: initStationCodeMap
  72 + * @Description: TODO(初始化站点和编码对照)
  73 + */
  74 + public void initStationCodeMap(){
  75 + Map<String, String> newMap = new HashMap<>();
  76 + Iterator<Station> iterator = stationRepository.findAll().iterator();
  77 +
  78 + Station station;
  79 + while(iterator.hasNext()){
  80 + station = iterator.next();
  81 + newMap.put(station.getStationCod(), station.getStationName());
  82 + }
  83 +
  84 + CommonMapped.stationCodeMap = newMap;
  85 + }
  86 +}
src/main/java/com/bsth/vehicle/directive/Consts.java
1 package com.bsth.vehicle.directive; 1 package com.bsth.vehicle.directive;
2 2
  3 +import com.bsth.util.Tools;
  4 +
3 public class Consts { 5 public class Consts {
  6 +
  7 + static Tools tools = new Tools("application.properties");
  8 +
4 /** 9 /**
5 * 调度指令 -多营运状态 [0][0]上行营运 [0][1]上行非营运 [1][0]下行营运 [1][1]下行非营运 10 * 调度指令 -多营运状态 [0][0]上行营运 [0][1]上行非营运 [1][0]下行营运 [1][1]下行非营运
6 */ 11 */
7 public static final int[][] SERVICE_STATE = { { 0, 0x02000000 }, { 0x10000000, 0x12000000 } }; 12 public static final int[][] SERVICE_STATE = { { 0, 0x02000000 }, { 0x10000000, 0x12000000 } };
  13 +
  14 + /**
  15 + * 消息下发地址
  16 + */
  17 + public static final String SEND_DIRECTIVE_URL = tools.getValue("http.send.directive");
8 } 18 }
src/main/java/com/bsth/vehicle/directive/DirectivePersistenceThread.java 0 → 100644
  1 +package com.bsth.vehicle.directive;
  2 +
  3 +import java.util.ArrayList;
  4 +import java.util.LinkedList;
  5 +import java.util.List;
  6 +
  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 com.bsth.vehicle.directive.buffer.DirectiveBuffer;
  13 +import com.bsth.vehicle.directive.entity.Directive;
  14 +import com.bsth.vehicle.directive.repository.DirectiveRepository;
  15 +
  16 +/**
  17 + *
  18 + * @ClassName: DirectivePersistenceThread
  19 + * @Description: TODO(调度指令定时入库)
  20 + * @author PanZhao
  21 + * @date 2016年6月8日 上午10:42:32
  22 + *
  23 + */
  24 +@Component
  25 +public class DirectivePersistenceThread extends Thread{
  26 +
  27 + @Autowired
  28 + DirectiveRepository directiveRepository;
  29 +
  30 + Logger logger = LoggerFactory.getLogger(this.getClass());
  31 +
  32 + @Override
  33 + public void run() {
  34 + LinkedList<Directive> list = DirectiveBuffer.transientList;
  35 +
  36 + List<Directive> persList = new ArrayList<>();
  37 +
  38 + Directive directive;
  39 + for(int i = 0; i < 1000; i ++){
  40 + directive = list.poll();
  41 +
  42 + if(null == directive)
  43 + break;
  44 +
  45 + persList.add(directive);
  46 + }
  47 +
  48 + if(persList.size() > 0){
  49 + try{
  50 + directiveRepository.save(persList);
  51 + }catch(Exception e){
  52 + logger.error("", e);
  53 + }
  54 + }
  55 + }
  56 +}
src/main/java/com/bsth/vehicle/directive/MsgIdGenerator.java 0 → 100644
  1 +package com.bsth.vehicle.directive;
  2 +
  3 +/**
  4 + *
  5 + * @ClassName: MsgIdGenerator
  6 + * @Description: TODO(指令下发 msgId 生成器)
  7 + * @author PanZhao
  8 + * @date 2016年6月7日 下午4:38:04
  9 + *
  10 + */
  11 +public class MsgIdGenerator {
  12 +
  13 + private static int msgId = 0;
  14 +
  15 + public synchronized static int getMsgId(){
  16 + msgId ++;
  17 + if(msgId == Integer.MAX_VALUE){
  18 + msgId = 0;
  19 + }
  20 + return msgId;
  21 + }
  22 +}
src/main/java/com/bsth/vehicle/directive/buffer/DirectiveBuffer.java 0 → 100644
  1 +package com.bsth.vehicle.directive.buffer;
  2 +
  3 +import java.util.HashMap;
  4 +import java.util.LinkedList;
  5 +import java.util.Map;
  6 +
  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 com.alibaba.fastjson.JSONObject;
  13 +import com.bsth.vehicle.directive.entity.Directive;
  14 +import com.bsth.vehicle.directive.entity.DirectiveReply;
  15 +import com.bsth.vehicle.directive.entity.DriverReport;
  16 +import com.bsth.vehicle.directive.entity.LineChange;
  17 +import com.bsth.vehicle.directive.repository.DriverReportRepository;
  18 +import com.bsth.vehicle.directive.repository.LineChangeRepository;
  19 +import com.google.common.collect.ArrayListMultimap;
  20 +import com.google.common.collect.Multimap;
  21 +
  22 +/**
  23 + *
  24 + * @ClassName: DirectiveBuffer
  25 + * @Description: TODO(调度指令缓存)
  26 + * @author PanZhao
  27 + * @date 2016年6月7日 下午3:24:19
  28 + *
  29 + */
  30 +@Component
  31 +public class DirectiveBuffer {
  32 +
  33 + Logger logger = LoggerFactory.getLogger(this.getClass());
  34 +
  35 + @Autowired
  36 + DriverReportRepository driverReportRepository;
  37 +
  38 + @Autowired
  39 + LineChangeRepository lineChangeRepository;
  40 +
  41 + /**
  42 + * 等待入库的调度指令
  43 + */
  44 + public static LinkedList<Directive> transientList;
  45 +
  46 + /**
  47 + * 等待确认的线路切换指令
  48 + */
  49 + public static Map<String, LineChange> changeMap;
  50 +
  51 + /**
  52 + * 当日调度指令缓存
  53 + */
  54 + private static Map<Integer, Directive> directiveMap;
  55 +
  56 + /**
  57 + * 驾驶员上报数据
  58 + * {K: 线路编码}
  59 + */
  60 + private static Multimap<Integer, DriverReport> reportMultiMap;
  61 +
  62 + static{
  63 + transientList = new LinkedList<>();
  64 + directiveMap = new HashMap<>();
  65 + reportMultiMap = ArrayListMultimap.create();
  66 + changeMap = new HashMap<>();
  67 + }
  68 +
  69 + public static void put(Directive directive){
  70 + transientList.add(directive);
  71 + directiveMap.put(directive.getMsgId(), directive);
  72 + }
  73 +
  74 + /**
  75 + *
  76 + * @Title: reply
  77 + * @Description: TODO(指令 46,47 响应)
  78 + * @throws
  79 + */
  80 + public void reply(DirectiveReply reply){
  81 + Integer msgId = reply.getMsgId();
  82 + if(msgId == null){
  83 + logger.error("reply error , msgId is null.");
  84 + return;
  85 + }
  86 +
  87 + Directive directive = directiveMap.get(msgId);
  88 +
  89 + if(null == directive){
  90 + //无效的响应
  91 + return;
  92 + }
  93 +
  94 + switch (reply.getStatus()) {
  95 + case 0:
  96 + //失败
  97 + directive.setReply46((short)-1);
  98 + break;
  99 +
  100 + case 1:
  101 + //发送成功
  102 + directive.setReply46((short)0);
  103 + break;
  104 + case 2:
  105 + //驾驶员阅读
  106 + directive.setReply47((short)0);
  107 + break;
  108 + }
  109 + transientList.add(directive);
  110 + }
  111 +
  112 + /**
  113 + *
  114 + * @Title: reply64
  115 + * @Description: TODO(64协议响应)
  116 + * @throws
  117 + */
  118 + public void reply64(JSONObject json){
  119 + String key = json.getString("deviceId") + "_" + json.getString("timestamp");
  120 +
  121 + LineChange change = changeMap.get(key);
  122 +
  123 + if(null == change)
  124 + logger.warn("64响应 -找不到请求源,json: " + json);
  125 + else{
  126 + JSONObject data = json.getJSONObject("data");
  127 +
  128 + changeMap.remove(key);
  129 +
  130 + if(null == data)
  131 + logger.warn("64响应 data is null ,json: " + json);
  132 + else{
  133 + change.setRespAck(data.getShort("requestAck"));
  134 + //响应入库
  135 + lineChangeRepository.save(change);
  136 + }
  137 + }
  138 + }
  139 +
  140 + /**
  141 + *
  142 + * @Title: jsyReport
  143 + * @Description: TODO(80 驾驶员上报)
  144 + * @throws
  145 + */
  146 + public void jsyReport(DriverReport report){
  147 + logger.info("驾驶员上报");
  148 + //实时入库
  149 + driverReportRepository.save(report);
  150 + reportMultiMap.put(report.getData().getLineId(), report);
  151 + }
  152 +}
src/main/java/com/bsth/vehicle/directive/controller/DirectiveController.java 0 → 100644
  1 +package com.bsth.vehicle.directive.controller;
  2 +
  3 +import org.springframework.beans.factory.annotation.Autowired;
  4 +import org.springframework.web.bind.annotation.RequestMapping;
  5 +import org.springframework.web.bind.annotation.RequestMethod;
  6 +import org.springframework.web.bind.annotation.RequestParam;
  7 +import org.springframework.web.bind.annotation.RestController;
  8 +
  9 +import com.bsth.vehicle.directive.service.DirectiveService;
  10 +
  11 +/**
  12 + *
  13 + * @ClassName: DirectiveController
  14 + * @Description: TODO(页面下发调度指令) .0
  15 + * @author PanZhao
  16 + * @date 2016年6月8日 上午9:34:51
  17 + *
  18 + */
  19 +@RestController
  20 +@RequestMapping("/directive")
  21 +public class DirectiveController {
  22 +
  23 + @Autowired
  24 + DirectiveService directiveService;
  25 +
  26 + /**
  27 + *
  28 + * @Title: send60
  29 + * @Description: TODO(60协议短语下发)
  30 + * @throws
  31 + */
  32 + @RequestMapping(value = "/phrase", method = RequestMethod.GET)
  33 + public int send60Phrase(@RequestParam String nbbm, @RequestParam String text){
  34 + return directiveService.send60Phrase(nbbm, text);
  35 + }
  36 +
  37 + /**
  38 + *
  39 + * @Title: lineChange
  40 + * @Description: TODO(切换线路)
  41 + * @param @param nbbm 车辆内部编码
  42 + * @param @param lineId 新线路编码
  43 + * @throws
  44 + */
  45 + @RequestMapping(value = "/lineChnage", method = RequestMethod.GET)
  46 + public int lineChange(@RequestParam String nbbm, @RequestParam Integer lineId){
  47 + return directiveService.lineChange(nbbm, lineId);
  48 + }
  49 +}
src/main/java/com/bsth/vehicle/directive/entity/Directive.java
1 package com.bsth.vehicle.directive.entity; 1 package com.bsth.vehicle.directive.entity;
2 2
  3 +import javax.persistence.Embeddable;
3 import javax.persistence.Entity; 4 import javax.persistence.Entity;
4 import javax.persistence.GeneratedValue; 5 import javax.persistence.GeneratedValue;
5 import javax.persistence.Id; 6 import javax.persistence.Id;
6 import javax.persistence.Table; 7 import javax.persistence.Table;
  8 +import javax.persistence.Transient;
7 9
8 10
9 /** 11 /**
@@ -15,18 +17,160 @@ import javax.persistence.Table; @@ -15,18 +17,160 @@ import javax.persistence.Table;
15 * 17 *
16 */ 18 */
17 @Entity 19 @Entity
18 -@Table(name = "bsth_v_directive") 20 +@Table(name = "bsth_v_directive_60")
19 public class Directive { 21 public class Directive {
20 22
21 @Id 23 @Id
22 @GeneratedValue 24 @GeneratedValue
23 private Integer id; 25 private Integer id;
24 26
25 - //一级协议 27 + /**
  28 + * 一级协议
  29 + */
26 private short operCode; 30 private short operCode;
27 31
28 - //数据 32 + /**
  33 + * 数据
  34 + */
29 private DirectiveData data; 35 private DirectiveData data;
  36 +
  37 + /**
  38 + * 设备号
  39 + */
  40 + @Transient
  41 + private String deviceId;
  42 +
  43 + /**
  44 + * 时间戳
  45 + */
  46 + @Transient
  47 + private Long timestamp;
  48 +
  49 + /**
  50 + * 唯一标识
  51 + */
  52 + @Transient
  53 + private Integer msgId;
  54 +
  55 + /**
  56 + * 46上行
  57 + */
  58 + private Short reply46;
  59 +
  60 + /**
  61 + * 47上行
  62 + */
  63 + private Short reply47;
  64 +
  65 +
  66 + @Embeddable
  67 + public static class DirectiveData {
  68 + // 公司代码
  69 + private short companyCode;
  70 +
  71 + // 设备号
  72 + private String deviceId;
  73 +
  74 + // 时间戳
  75 + private Long timestamp;
  76 +
  77 + // 保留 默认0
  78 + private short instructType = 0;
  79 +
  80 + /*
  81 + * 调度指令 调度指令。
  82 + * 0X00表示信息短语
  83 + * 0X01表示取消上次指令+调度指令(闹钟有效)
  84 + * 0x02表示为调度指令(闹钟有效)
  85 + * 0x03表示运营状态指令(闹钟无效)
  86 + * 0x04表示其他指令
  87 + */
  88 + private DispatchInstruct dispatchInstruct;
  89 +
  90 + // 唯一标识
  91 + private int msgId;
  92 +
  93 + // 闹钟
  94 + private Long alarmTime;
  95 +
  96 + // 多个运营状态字节
  97 + private Long serviceState;
  98 +
  99 + // 消息文本
  100 + private String txtContent;
  101 +
  102 + public short getCompanyCode() {
  103 + return companyCode;
  104 + }
  105 +
  106 + public void setCompanyCode(short companyCode) {
  107 + this.companyCode = companyCode;
  108 + }
  109 +
  110 + public String getDeviceId() {
  111 + return deviceId;
  112 + }
  113 +
  114 + public void setDeviceId(String deviceId) {
  115 + this.deviceId = deviceId;
  116 + }
  117 +
  118 + public Long getTimestamp() {
  119 + return timestamp;
  120 + }
  121 +
  122 + public void setTimestamp(Long timestamp) {
  123 + this.timestamp = timestamp;
  124 + }
  125 +
  126 + public short getInstructType() {
  127 + return instructType;
  128 + }
  129 +
  130 + public void setInstructType(short instructType) {
  131 + this.instructType = instructType;
  132 + }
  133 +
  134 + public DispatchInstruct getDispatchInstruct() {
  135 + return dispatchInstruct;
  136 + }
  137 +
  138 + public void setDispatchInstruct(DispatchInstruct dispatchInstruct) {
  139 + this.dispatchInstruct = dispatchInstruct;
  140 + }
  141 +
  142 + public int getMsgId() {
  143 + return msgId;
  144 + }
  145 +
  146 + public void setMsgId(int msgId) {
  147 + this.msgId = msgId;
  148 + }
  149 +
  150 + public Long getAlarmTime() {
  151 + return alarmTime;
  152 + }
  153 +
  154 + public void setAlarmTime(Long alarmTime) {
  155 + this.alarmTime = alarmTime;
  156 + }
  157 +
  158 + public Long getServiceState() {
  159 + return serviceState;
  160 + }
  161 +
  162 + public void setServiceState(Long serviceState) {
  163 + this.serviceState = serviceState;
  164 + }
  165 +
  166 + public String getTxtContent() {
  167 + return txtContent;
  168 + }
  169 +
  170 + public void setTxtContent(String txtContent) {
  171 + this.txtContent = txtContent;
  172 + }
  173 + }
30 174
31 public Integer getId() { 175 public Integer getId() {
32 return id; 176 return id;
@@ -51,4 +195,44 @@ public class Directive { @@ -51,4 +195,44 @@ public class Directive {
51 public void setData(DirectiveData data) { 195 public void setData(DirectiveData data) {
52 this.data = data; 196 this.data = data;
53 } 197 }
  198 +
  199 + public String getDeviceId() {
  200 + return deviceId;
  201 + }
  202 +
  203 + public void setDeviceId(String deviceId) {
  204 + this.deviceId = deviceId;
  205 + }
  206 +
  207 + public Long getTimestamp() {
  208 + return timestamp;
  209 + }
  210 +
  211 + public void setTimestamp(Long timestamp) {
  212 + this.timestamp = timestamp;
  213 + }
  214 +
  215 + public Integer getMsgId() {
  216 + return msgId;
  217 + }
  218 +
  219 + public void setMsgId(Integer msgId) {
  220 + this.msgId = msgId;
  221 + }
  222 +
  223 + public Short getReply46() {
  224 + return reply46;
  225 + }
  226 +
  227 + public void setReply46(Short reply46) {
  228 + this.reply46 = reply46;
  229 + }
  230 +
  231 + public Short getReply47() {
  232 + return reply47;
  233 + }
  234 +
  235 + public void setReply47(Short reply47) {
  236 + this.reply47 = reply47;
  237 + }
54 } 238 }
src/main/java/com/bsth/vehicle/directive/entity/DirectiveData.java deleted 100644 → 0
1 -package com.bsth.vehicle.directive.entity;  
2 -  
3 -import javax.persistence.Embeddable;  
4 -  
5 -@Embeddable  
6 -public class DirectiveData {  
7 - // 公司代码  
8 - private short companyCode;  
9 -  
10 - // 设备号  
11 - private String deviceId;  
12 -  
13 - // 时间戳  
14 - private Long timestamp;  
15 -  
16 - // 保留 默认0  
17 - private short instructType = 0;  
18 -  
19 - /*  
20 - * 调度指令 调度指令。 0X00表示信息短语 0X01表示取消上次指令+调度指令(闹钟有效) 0x02表示为调度指令(闹钟有效)  
21 - * 0x03表示运营状态指令(闹钟无效) 0x04表示其他指令  
22 - */  
23 - private DispatchInstruct dispatchInstruct;  
24 -  
25 - // 唯一标识  
26 - private Long msgId;  
27 -  
28 - // 闹钟  
29 - private Long alarmTime;  
30 -  
31 - // 多个运营状态字节  
32 - private Long serviceState;  
33 -  
34 - // 消息文本  
35 - private String txtContent;  
36 -  
37 - public short getCompanyCode() {  
38 - return companyCode;  
39 - }  
40 -  
41 - public void setCompanyCode(short companyCode) {  
42 - this.companyCode = companyCode;  
43 - }  
44 -  
45 - public String getDeviceId() {  
46 - return deviceId;  
47 - }  
48 -  
49 - public void setDeviceId(String deviceId) {  
50 - this.deviceId = deviceId;  
51 - }  
52 -  
53 - public Long getTimestamp() {  
54 - return timestamp;  
55 - }  
56 -  
57 - public void setTimestamp(Long timestamp) {  
58 - this.timestamp = timestamp;  
59 - }  
60 -  
61 - public short getInstructType() {  
62 - return instructType;  
63 - }  
64 -  
65 - public void setInstructType(short instructType) {  
66 - this.instructType = instructType;  
67 - }  
68 -  
69 - public DispatchInstruct getDispatchInstruct() {  
70 - return dispatchInstruct;  
71 - }  
72 -  
73 - public void setDispatchInstruct(DispatchInstruct dispatchInstruct) {  
74 - this.dispatchInstruct = dispatchInstruct;  
75 - }  
76 -  
77 - public Long getMsgId() {  
78 - return msgId;  
79 - }  
80 -  
81 - public void setMsgId(Long msgId) {  
82 - this.msgId = msgId;  
83 - }  
84 -  
85 - public Long getAlarmTime() {  
86 - return alarmTime;  
87 - }  
88 -  
89 - public void setAlarmTime(Long alarmTime) {  
90 - this.alarmTime = alarmTime;  
91 - }  
92 -  
93 - public Long getServiceState() {  
94 - return serviceState;  
95 - }  
96 -  
97 - public void setServiceState(Long serviceState) {  
98 - this.serviceState = serviceState;  
99 - }  
100 -  
101 - public String getTxtContent() {  
102 - return txtContent;  
103 - }  
104 -  
105 - public void setTxtContent(String txtContent) {  
106 - this.txtContent = txtContent;  
107 - }  
108 -}  
src/main/java/com/bsth/vehicle/directive/entity/DirectiveReply.java 0 → 100644
  1 +package com.bsth.vehicle.directive.entity;
  2 +
  3 +/**
  4 + *
  5 + * @ClassName: DirectiveReply
  6 + * @Description: TODO(上行响应)
  7 + * @author PanZhao
  8 + * @date 2016年6月7日 下午8:41:11
  9 + *
  10 + */
  11 +public class DirectiveReply {
  12 +
  13 + //设备编号
  14 + private String deviceId;
  15 +
  16 + private Integer msgId;
  17 +
  18 + /**
  19 + * operCode 为 0x80时无数据
  20 + * 0表示失败
  21 + * 1表示成功或设备确认
  22 + * 2表示驾驶员阅读
  23 + */
  24 + private Integer status;
  25 +
  26 + //时间戳(ms)
  27 + private Long timestamp;
  28 +
  29 + public String getDeviceId() {
  30 + return deviceId;
  31 + }
  32 +
  33 + public void setDeviceId(String deviceId) {
  34 + this.deviceId = deviceId;
  35 + }
  36 +
  37 + public Integer getMsgId() {
  38 + return msgId;
  39 + }
  40 +
  41 + public void setMsgId(Integer msgId) {
  42 + this.msgId = msgId;
  43 + }
  44 +
  45 + public Long getTimestamp() {
  46 + return timestamp;
  47 + }
  48 +
  49 + public void setTimestamp(Long timestamp) {
  50 + this.timestamp = timestamp;
  51 + }
  52 +
  53 + public Integer getStatus() {
  54 + return status;
  55 + }
  56 +
  57 + public void setStatus(Integer status) {
  58 + this.status = status;
  59 + }
  60 +}
src/main/java/com/bsth/vehicle/directive/entity/DispatchInstruct.java
@@ -3,21 +3,35 @@ package com.bsth.vehicle.directive.entity; @@ -3,21 +3,35 @@ package com.bsth.vehicle.directive.entity;
3 /** 3 /**
4 * 4 *
5 * @ClassName: DispatchInstruct 5 * @ClassName: DispatchInstruct
6 - * @Description: TODO(调度指令) 6 + * @Description: TODO(调度指令类型)
7 * @author PanZhao 7 * @author PanZhao
8 * @date 2016年6月7日 下午2:15:10 8 * @date 2016年6月7日 下午2:15:10
9 * 9 *
10 */ 10 */
11 public enum DispatchInstruct { 11 public enum DispatchInstruct {
12 - // 信息短语 12 + /**
  13 + * 信息短语
  14 + */
13 PHRASE((byte) 0x00), 15 PHRASE((byte) 0x00),
14 - // 取消上次指令+调度指令(闹钟有效) 16 +
  17 + /**
  18 + * 取消上次指令+调度指令(闹钟有效)
  19 + */
15 CANCEL_AND_CLOCK_ON((byte) 0x01), 20 CANCEL_AND_CLOCK_ON((byte) 0x01),
16 - // 调度指令(闹钟有效) 21 +
  22 + /**
  23 + * 调度指令(闹钟有效)
  24 + */
17 DISPATCH_CLOCK_ON((byte) 0x02), 25 DISPATCH_CLOCK_ON((byte) 0x02),
18 - // 运营状态指令(闹钟无效) 26 +
  27 + /**
  28 + * 运营状态指令(闹钟无效)
  29 + */
19 OPERATE_CLOCK_OFF((byte) 0x03), 30 OPERATE_CLOCK_OFF((byte) 0x03),
20 - // 其他 31 +
  32 + /**
  33 + * 其他
  34 + */
21 OTHER((byte) 0x04); 35 OTHER((byte) 0x04);
22 36
23 private final byte value; 37 private final byte value;
src/main/java/com/bsth/vehicle/directive/entity/DriverReport.java 0 → 100644
  1 +package com.bsth.vehicle.directive.entity;
  2 +
  3 +import javax.persistence.Embeddable;
  4 +import javax.persistence.Entity;
  5 +import javax.persistence.GeneratedValue;
  6 +import javax.persistence.Id;
  7 +import javax.persistence.Table;
  8 +
  9 +/**
  10 + *
  11 + * @ClassName: DriverReport
  12 + * @Description: TODO(驾驶员上报)
  13 + * @author PanZhao
  14 + * @date 2016年6月8日 下午12:36:42
  15 + *
  16 + */
  17 +@Entity
  18 +@Table(name = "bsth_v_report_80")
  19 +public class DriverReport {
  20 +
  21 + @Id
  22 + @GeneratedValue
  23 + private Integer id;
  24 +
  25 + /**
  26 + * 设备编号
  27 + */
  28 + private String deviceId;
  29 +
  30 + /**
  31 + * 时间戳(ms)
  32 + */
  33 + private Long timestamp;
  34 +
  35 + /**
  36 + * 一级协议
  37 + */
  38 + private Short operCode;
  39 +
  40 + private DriverReportData data;
  41 +
  42 + @Embeddable
  43 + public static class DriverReportData {
  44 +
  45 + private Short operCode2;
  46 +
  47 + /**
  48 + * 请求代码 0xa1 恢复运营 0xa2 申请调档 0xa3 出场请求 0xa5 进场请求 0xa7 加油请求 0x50 车辆故障 0x70
  49 + * 路阻报告 0x60 事故报告 0x11 扣证纠纷 0x12 报警
  50 + */
  51 + private Short requestCode;
  52 +
  53 + /**
  54 + * 线路编码
  55 + */
  56 + private Integer lineId;
  57 +
  58 + public Short getOperCode2() {
  59 + return operCode2;
  60 + }
  61 +
  62 + public void setOperCode2(Short operCode2) {
  63 + this.operCode2 = operCode2;
  64 + }
  65 +
  66 + public Short getRequestCode() {
  67 + return requestCode;
  68 + }
  69 +
  70 + public void setRequestCode(Short requestCode) {
  71 + this.requestCode = requestCode;
  72 + }
  73 +
  74 + public Integer getLineId() {
  75 + return lineId;
  76 + }
  77 +
  78 + public void setLineId(Integer lineId) {
  79 + this.lineId = lineId;
  80 + }
  81 + }
  82 +
  83 + public Integer getId() {
  84 + return id;
  85 + }
  86 +
  87 + public void setId(Integer id) {
  88 + this.id = id;
  89 + }
  90 +
  91 + public String getDeviceId() {
  92 + return deviceId;
  93 + }
  94 +
  95 + public void setDeviceId(String deviceId) {
  96 + this.deviceId = deviceId;
  97 + }
  98 +
  99 + public Long getTimestamp() {
  100 + return timestamp;
  101 + }
  102 +
  103 + public void setTimestamp(Long timestamp) {
  104 + this.timestamp = timestamp;
  105 + }
  106 +
  107 + public Short getOperCode() {
  108 + return operCode;
  109 + }
  110 +
  111 + public void setOperCode(Short operCode) {
  112 + this.operCode = operCode;
  113 + }
  114 +
  115 + public DriverReportData getData() {
  116 + return data;
  117 + }
  118 +
  119 + public void setData(DriverReportData data) {
  120 + this.data = data;
  121 + }
  122 +}
src/main/java/com/bsth/vehicle/directive/entity/LineChange.java 0 → 100644
  1 +package com.bsth.vehicle.directive.entity;
  2 +
  3 +import javax.persistence.Table;
  4 +import javax.persistence.Transient;
  5 +import javax.persistence.Embeddable;
  6 +import javax.persistence.Entity;
  7 +import javax.persistence.GeneratedValue;
  8 +import javax.persistence.Id;
  9 +
  10 +/**
  11 + *
  12 + * @ClassName: LineChange
  13 + * @Description: TODO(线路切换指令)
  14 + * @author PanZhao
  15 + * @date 2016年6月8日 下午1:41:15
  16 + *
  17 + */
  18 +@Entity
  19 +@Table(name = "bsth_v_directive_64")
  20 +public class LineChange {
  21 +
  22 + @Id
  23 + @GeneratedValue
  24 + private Integer id;
  25 +
  26 + /**
  27 + * 设备编号
  28 + */
  29 + @Transient
  30 + private String deviceId;
  31 +
  32 + /**
  33 + * 时间戳(ms)
  34 + */
  35 + private Long timestamp;
  36 +
  37 + /**
  38 + * 一级协议
  39 + */
  40 + private Short operCode;
  41 +
  42 + /**
  43 + * 设备响应应答字
  44 + * 0x06同意 0x15不同意
  45 + */
  46 + private Short respAck;
  47 +
  48 + private LineChangeData data;
  49 +
  50 + @Embeddable
  51 + public static class LineChangeData {
  52 +
  53 + private Short cityCode;
  54 +
  55 + private String deviceId;
  56 +
  57 + private String lineId;
  58 +
  59 + public Short getCityCode() {
  60 + return cityCode;
  61 + }
  62 +
  63 + public void setCityCode(Short cityCode) {
  64 + this.cityCode = cityCode;
  65 + }
  66 +
  67 + public String getDeviceId() {
  68 + return deviceId;
  69 + }
  70 +
  71 + public void setDeviceId(String deviceId) {
  72 + this.deviceId = deviceId;
  73 + }
  74 +
  75 + public String getLineId() {
  76 + return lineId;
  77 + }
  78 +
  79 + public void setLineId(String lineId) {
  80 + this.lineId = lineId;
  81 + }
  82 + }
  83 +
  84 + public Integer getId() {
  85 + return id;
  86 + }
  87 +
  88 + public void setId(Integer id) {
  89 + this.id = id;
  90 + }
  91 +
  92 + public String getDeviceId() {
  93 + return deviceId;
  94 + }
  95 +
  96 + public void setDeviceId(String deviceId) {
  97 + this.deviceId = deviceId;
  98 + }
  99 +
  100 + public Long getTimestamp() {
  101 + return timestamp;
  102 + }
  103 +
  104 + public void setTimestamp(Long timestamp) {
  105 + this.timestamp = timestamp;
  106 + }
  107 +
  108 + public Short getOperCode() {
  109 + return operCode;
  110 + }
  111 +
  112 + public void setOperCode(Short operCode) {
  113 + this.operCode = operCode;
  114 + }
  115 +
  116 + public LineChangeData getData() {
  117 + return data;
  118 + }
  119 +
  120 + public void setData(LineChangeData data) {
  121 + this.data = data;
  122 + }
  123 +
  124 + public Short getRespAck() {
  125 + return respAck;
  126 + }
  127 +
  128 + public void setRespAck(Short respAck) {
  129 + this.respAck = respAck;
  130 + }
  131 +}
src/main/java/com/bsth/vehicle/directive/repository/DirectiveRepository.java 0 → 100644
  1 +package com.bsth.vehicle.directive.repository;
  2 +
  3 +import org.springframework.stereotype.Repository;
  4 +
  5 +import com.bsth.repository.BaseRepository;
  6 +import com.bsth.vehicle.directive.entity.Directive;
  7 +
  8 +@Repository
  9 +public interface DirectiveRepository extends BaseRepository<Directive, Integer>{
  10 +
  11 +}
src/main/java/com/bsth/vehicle/directive/repository/DriverReportRepository.java 0 → 100644
  1 +package com.bsth.vehicle.directive.repository;
  2 +
  3 +import org.springframework.stereotype.Repository;
  4 +
  5 +import com.bsth.repository.BaseRepository;
  6 +import com.bsth.vehicle.directive.entity.DriverReport;
  7 +
  8 +@Repository
  9 +public interface DriverReportRepository extends BaseRepository<DriverReport, Integer>{
  10 +
  11 +}
src/main/java/com/bsth/vehicle/directive/repository/LineChangeRepository.java 0 → 100644
  1 +package com.bsth.vehicle.directive.repository;
  2 +
  3 +import org.springframework.stereotype.Repository;
  4 +
  5 +import com.bsth.repository.BaseRepository;
  6 +import com.bsth.vehicle.directive.entity.LineChange;
  7 +
  8 +@Repository
  9 +public interface LineChangeRepository extends BaseRepository<LineChange, Integer>{
  10 +
  11 +}
src/main/java/com/bsth/vehicle/directive/service/DirectiveService.java 0 → 100644
  1 +package com.bsth.vehicle.directive.service;
  2 +
  3 +
  4 +import com.bsth.service.BaseService;
  5 +import com.bsth.vehicle.directive.entity.Directive;
  6 +
  7 +public interface DirectiveService extends BaseService<Directive, Integer>{
  8 +
  9 + /**
  10 + *
  11 + * @Title: send60Phrase
  12 + * @Description: TODO(60短语下发)
  13 + * @param @param nbbm 车辆内部编码
  14 + * @param @param text 短语
  15 + * @return int 返回类型
  16 + * @throws
  17 + */
  18 + int send60Phrase(String nbbm, String text);
  19 +
  20 + int send60Dispatch(String nbbm, String text);
  21 +
  22 + //60营运指令
  23 + int send60Operation(String nbbm, int state, int upDown);
  24 +
  25 + /**
  26 + *
  27 + * @Title: lineChange
  28 + * @Description: TODO(线路切换)
  29 + * @param @param nbbm 车辆内部编码
  30 + * @param @param lineId 新线路编码
  31 + * @throws
  32 + */
  33 + int lineChange(String nbbm, Integer lineId);
  34 +}
src/main/java/com/bsth/vehicle/directive/service/DirectiveServiceImpl.java 0 → 100644
  1 +package com.bsth.vehicle.directive.service;
  2 +
  3 +import java.io.IOException;
  4 +
  5 +import org.apache.http.client.methods.CloseableHttpResponse;
  6 +import org.apache.http.client.methods.HttpPost;
  7 +import org.apache.http.entity.StringEntity;
  8 +import org.apache.http.impl.client.CloseableHttpClient;
  9 +import org.apache.http.impl.client.HttpClients;
  10 +import org.apache.http.util.EntityUtils;
  11 +import org.slf4j.Logger;
  12 +import org.slf4j.LoggerFactory;
  13 +import org.springframework.beans.factory.annotation.Autowired;
  14 +import org.springframework.stereotype.Service;
  15 +
  16 +import com.alibaba.fastjson.JSON;
  17 +import com.alibaba.fastjson.JSONObject;
  18 +import com.bsth.service.impl.BaseServiceImpl;
  19 +import com.bsth.vehicle.common.CommonMapped;
  20 +import com.bsth.vehicle.directive.Consts;
  21 +import com.bsth.vehicle.directive.MsgIdGenerator;
  22 +import com.bsth.vehicle.directive.buffer.DirectiveBuffer;
  23 +import com.bsth.vehicle.directive.entity.Directive;
  24 +import com.bsth.vehicle.directive.entity.Directive.DirectiveData;
  25 +import com.bsth.vehicle.directive.entity.DispatchInstruct;
  26 +import com.bsth.vehicle.directive.entity.LineChange;
  27 +import com.bsth.vehicle.directive.entity.LineChange.LineChangeData;
  28 +import com.bsth.vehicle.directive.repository.DirectiveRepository;
  29 +import com.bsth.vehicle.directive.repository.LineChangeRepository;
  30 +import com.bsth.vehicle.gpsdata.buffer.GpsRealDataBuffer;
  31 +import com.bsth.vehicle.gpsdata.entity.GpsRealData;
  32 +
  33 +@Service
  34 +public class DirectiveServiceImpl extends BaseServiceImpl<Directive, Integer> implements DirectiveService{
  35 +
  36 + Logger logger = LoggerFactory.getLogger(this.getClass());
  37 +
  38 + @Autowired
  39 + DirectiveRepository directiveRepository;
  40 +
  41 + @Autowired
  42 + GpsRealDataBuffer gpsRealDataBuffer;
  43 +
  44 + @Autowired
  45 + LineChangeRepository lineChangeRepository;
  46 +
  47 + @Override
  48 + public int send60Phrase(String nbbm, String text) {
  49 + Directive directive = create60Data(nbbm, text, DispatchInstruct.PHRASE);
  50 +
  51 + //发送指令
  52 + int code = postJson(JSON.toJSONString(directive));
  53 +
  54 + if(code == 0){
  55 + //添加到缓存,等待入库
  56 + DirectiveBuffer.put(directive);
  57 + }else{
  58 + logger.error("send60Phrase error, code: " + code);
  59 + }
  60 + return code;
  61 + }
  62 +
  63 + @Override
  64 + public int send60Dispatch(String nbbm, String text) {
  65 + return 0;
  66 + }
  67 +
  68 + @Override
  69 + public int send60Operation(String nbbm, int state, int upDown) {
  70 + return 0;
  71 + }
  72 +
  73 + /**
  74 + * 线路切换
  75 + */
  76 + @Override
  77 + public int lineChange(String nbbm, Integer lineId) {
  78 + Long t = System.currentTimeMillis();
  79 + String deviceId = CommonMapped.vehicDeviceBiMap.inverse().get(nbbm);
  80 +
  81 + LineChange change = new LineChange();
  82 + LineChangeData data = new LineChangeData();
  83 + //暂时写死,没什么用
  84 + data.setCityCode((short) 22);
  85 + data.setDeviceId(deviceId);
  86 + data.setLineId(String.valueOf(lineId));
  87 +
  88 + change.setDeviceId(deviceId);
  89 + change.setOperCode((short) 0X64);
  90 + change.setTimestamp(t);
  91 + change.setData(data);
  92 +
  93 + int code = 0;//postJson(JSON.toJSONString(change));
  94 + //if(code == 0){
  95 + //入库
  96 + lineChangeRepository.save(change);
  97 + DirectiveBuffer.changeMap.put(deviceId + '_' + t , change);
  98 + //}else{
  99 + // logger.error("send60Phrase error, code: " + code);
  100 + //}
  101 + return code;
  102 + }
  103 +
  104 +
  105 + public Directive create60Data(String nbbm, String text, DispatchInstruct dispatchInstruct){
  106 + Long timestamp = System.currentTimeMillis();
  107 +
  108 + String deviceId = CommonMapped.vehicDeviceBiMap.inverse().get(nbbm);
  109 + Short company = Short.parseShort(CommonMapped.vehicCompanyMap.get(nbbm));
  110 + if(null == deviceId){
  111 + logger.error("没有设备号对照的车辆:" + nbbm);
  112 + return null;
  113 + }
  114 +
  115 + GpsRealData gpsData = gpsRealDataBuffer.findOneByDeviceId(deviceId);
  116 + if(null == gpsData){
  117 + logger.error("没有找到gps对照,无法确认营运状态和上下行:" + nbbm);
  118 + return null;
  119 + }
  120 +
  121 + int msgId = MsgIdGenerator.getMsgId();
  122 +
  123 + Directive directive = new Directive();
  124 + DirectiveData data = new DirectiveData();
  125 + //一级协议
  126 + directive.setOperCode((short) 0x60);
  127 + //设备号
  128 + directive.setDeviceId(deviceId);
  129 + //时间戳
  130 + directive.setTimestamp(timestamp);
  131 + directive.setMsgId(msgId);
  132 + //构造数据
  133 + data.setDeviceId(deviceId);
  134 + data.setDispatchInstruct(dispatchInstruct);
  135 + data.setTimestamp(timestamp);
  136 + data.setCompanyCode(company);
  137 + data.setMsgId(msgId);
  138 + directive.setData(data);
  139 + long serviceState;
  140 + try{
  141 + serviceState = Consts.SERVICE_STATE[gpsData.getUpDown()][gpsData.getState()];
  142 + }catch(IndexOutOfBoundsException e){
  143 + //未知营运状态的直接默认为上行非营运
  144 + serviceState = Consts.SERVICE_STATE[0][1];
  145 + }
  146 + data.setServiceState(serviceState);
  147 + data.setTxtContent(text);
  148 +
  149 + return directive;
  150 + }
  151 +
  152 + public int postJson(String jsonStr){
  153 + CloseableHttpClient httpClient = null;
  154 + int code = -1;
  155 + try{
  156 + httpClient = HttpClients.createDefault();
  157 + HttpPost post = new HttpPost(Consts.SEND_DIRECTIVE_URL);
  158 +
  159 + post.setEntity(new StringEntity(jsonStr, "utf-8"));
  160 +
  161 + CloseableHttpResponse response = httpClient.execute(post);
  162 +
  163 + JSONObject json = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
  164 + if(null != json && json.getInteger("errCode") == 0)
  165 + code = 0;
  166 + else
  167 + logger.error("和网关http通讯失败,rs: " + json);
  168 + }catch(Exception e){
  169 + logger.error("", e);
  170 + }finally {
  171 + try {
  172 + if(httpClient != null)
  173 + httpClient.close();
  174 + } catch (IOException e) {
  175 + logger.error("", e);
  176 + }
  177 + }
  178 + return code;
  179 + }
  180 +}
src/main/java/com/bsth/vehicle/gpsdata/GpsRefreshThread.java
@@ -52,8 +52,6 @@ public class GpsRefreshThread extends Thread{ @@ -52,8 +52,6 @@ public class GpsRefreshThread extends Thread{
52 @Override 52 @Override
53 public void run() { 53 public void run() {
54 try{ 54 try{
55 - long t = System.currentTimeMillis();  
56 -  
57 List<GpsRealData> newList = getterRealGpsData(); 55 List<GpsRealData> newList = getterRealGpsData();
58 56
59 if(gpsBuffer.isNullEmpty()) 57 if(gpsBuffer.isNullEmpty())
@@ -85,10 +83,10 @@ public class GpsRefreshThread extends Thread{ @@ -85,10 +83,10 @@ public class GpsRefreshThread extends Thread{
85 gpsBuffer.setLastUpdateTime(System.currentTimeMillis()); 83 gpsBuffer.setLastUpdateTime(System.currentTimeMillis());
86 } 84 }
87 85
88 - logger.info("本次刷新GPS实时数据耗时:" + (System.currentTimeMillis() - t) + "毫秒"); 86 + //logger.info("本次刷新GPS实时数据耗时:" + (System.currentTimeMillis() - t) + "毫秒");
89 }catch(Exception e){ 87 }catch(Exception e){
90 //logger.error("", e); 88 //logger.error("", e);
91 - logger.error("加载gps数据失败"); 89 + logger.error("加载gps数据失败," + e.getMessage());
92 } 90 }
93 } 91 }
94 92
src/main/java/com/bsth/vehicle/gpsdata/buffer/GpsRealDataBuffer.java
@@ -9,13 +9,8 @@ import java.util.Set; @@ -9,13 +9,8 @@ import java.util.Set;
9 9
10 import org.slf4j.Logger; 10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory; 11 import org.slf4j.LoggerFactory;
12 -import org.springframework.beans.factory.annotation.Autowired;  
13 import org.springframework.stereotype.Component; 12 import org.springframework.stereotype.Component;
14 13
15 -import com.bsth.entity.Cars;  
16 -import com.bsth.entity.Station;  
17 -import com.bsth.repository.CarsRepository;  
18 -import com.bsth.repository.StationRepository;  
19 import com.bsth.vehicle.gpsdata.entity.GpsRealData; 14 import com.bsth.vehicle.gpsdata.entity.GpsRealData;
20 import com.google.common.collect.ArrayListMultimap; 15 import com.google.common.collect.ArrayListMultimap;
21 import com.google.common.collect.ImmutableMap; 16 import com.google.common.collect.ImmutableMap;
@@ -34,12 +29,6 @@ public class GpsRealDataBuffer { @@ -34,12 +29,6 @@ public class GpsRealDataBuffer {
34 29
35 private Logger logger = LoggerFactory.getLogger(this.getClass()); 30 private Logger logger = LoggerFactory.getLogger(this.getClass());
36 31
37 - @Autowired  
38 - CarsRepository carsRepository;  
39 -  
40 - @Autowired  
41 - StationRepository stationRepository;  
42 -  
43 /** 32 /**
44 * 线路和GPS对照 33 * 线路和GPS对照
45 *(K: 线路编码 ,V:GpsRealData) 34 *(K: 线路编码 ,V:GpsRealData)
@@ -89,36 +78,6 @@ public class GpsRealDataBuffer { @@ -89,36 +78,6 @@ public class GpsRealDataBuffer {
89 deviceGpsMap.put(gpsData.getDeviceId(), gpsData); 78 deviceGpsMap.put(gpsData.getDeviceId(), gpsData);
90 } 79 }
91 logger.info("init gps buffer gps! list size: " + list.size()); 80 logger.info("init gps buffer gps! list size: " + list.size());
92 - initDeviceMapp();  
93 - initStationCodeMap();  
94 - }  
95 -  
96 - public void initDeviceMapp(){  
97 - //初始化车辆设备号对照  
98 - vehicDeviceMap = new HashMap<>();  
99 - Iterator<Cars> carIterator = carsRepository.findAll().iterator();  
100 -  
101 - Cars car;  
102 - while(carIterator.hasNext()){  
103 - car = carIterator.next();  
104 - vehicDeviceMap.put(car.getEquipmentCode(), car.getInsideCode());  
105 - }  
106 -  
107 - logger.info("初始化车辆设备号对照 数量: " + vehicDeviceMap.size());  
108 - }  
109 -  
110 - public void initStationCodeMap(){  
111 - //初始化站点和编码对照  
112 - stationCodeMap = new HashMap<>();  
113 - Iterator<Station> iterator = stationRepository.findAll().iterator();  
114 -  
115 - Station station;  
116 - while(iterator.hasNext()){  
117 - station = iterator.next();  
118 - stationCodeMap.put(station.getStationCod(), station.getStationName());  
119 - }  
120 -  
121 - logger.info("初始化站点编码对照 数量: " + stationCodeMap.size());  
122 } 81 }
123 82
124 public void putLineMultimap(String lineCode, GpsRealData gpsData){ 83 public void putLineMultimap(String lineCode, GpsRealData gpsData){
@@ -154,7 +113,7 @@ public class GpsRealDataBuffer { @@ -154,7 +113,7 @@ public class GpsRealDataBuffer {
154 gpsdata = iterator.next(); 113 gpsdata = iterator.next();
155 lineGpsMultimap.put(gpsdata.getLineId(), gpsdata); 114 lineGpsMultimap.put(gpsdata.getLineId(), gpsdata);
156 } 115 }
157 - logger.info("update gps buffer over! new gps list size: " + upGpsList.size() + " - lineGpsMultimap size: " + lineGpsMultimap.size()); 116 + //logger.info("update gps buffer over! new gps list size: " + upGpsList.size() + " - lineGpsMultimap size: " + lineGpsMultimap.size());
158 } 117 }
159 118
160 /** 119 /**
@@ -213,6 +172,10 @@ public class GpsRealDataBuffer { @@ -213,6 +172,10 @@ public class GpsRealDataBuffer {
213 return list; 172 return list;
214 } 173 }
215 174
  175 + public GpsRealData findOneByDeviceId(String deviceId){
  176 + return deviceGpsMap.get(deviceId);
  177 + }
  178 +
216 179
217 public void setLastUpdateTime(Long time){ 180 public void setLastUpdateTime(Long time){
218 lastUpdateTime = time; 181 lastUpdateTime = time;
src/main/resources/application.properties
@@ -9,9 +9,9 @@ spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy @@ -9,9 +9,9 @@ spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy
9 spring.jpa.database= MYSQL 9 spring.jpa.database= MYSQL
10 spring.jpa.show-sql= true 10 spring.jpa.show-sql= true
11 spring.datasource.driver-class-name= com.mysql.jdbc.Driver 11 spring.datasource.driver-class-name= com.mysql.jdbc.Driver
12 -spring.datasource.url= jdbc:mysql://192.168.168.201:3306/control 12 +spring.datasource.url= jdbc:mysql://127.0.0.1:3306/control
13 spring.datasource.username= root 13 spring.datasource.username= root
14 -spring.datasource.password= 123456 14 +spring.datasource.password= panzhao
15 15
16 #DATASOURCE 16 #DATASOURCE
17 spring.datasource.max-active=100 17 spring.datasource.max-active=100
@@ -26,5 +26,8 @@ server.session-timeout=-1 @@ -26,5 +26,8 @@ server.session-timeout=-1
26 security.basic.enabled=false 26 security.basic.enabled=false
27 27
28 ## 28 ##
29 -#http.gps.real.url= http://222.66.0.204:5555/transport_server/rtgps/ 29 +#222.66.0.204:5555
  30 +##\u5B9E\u65F6gps
30 http.gps.real.url= http://192.168.168.192:8080/transport_server/rtgps/ 31 http.gps.real.url= http://192.168.168.192:8080/transport_server/rtgps/
  32 +##\u6D88\u606F\u4E0B\u53D1
  33 +http.send.directive = http://192.168.168.192:8080/transport_server/message/
src/main/resources/fatso/exclude.txt 0 → 100644
src/main/resources/logback.xml
@@ -17,9 +17,9 @@ @@ -17,9 +17,9 @@
17 <!-- 主日志文件 --> 17 <!-- 主日志文件 -->
18 <appender name="FILE" 18 <appender name="FILE"
19 class="ch.qos.logback.core.rolling.RollingFileAppender"> 19 class="ch.qos.logback.core.rolling.RollingFileAppender">
20 - <file>${LOG_BASE}/main.log</file> 20 + <file>${LOG_BASE}/main/main.log</file>
21 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 21 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
22 - <fileNamePattern>${LOG_BASE}/main-%d{yyyy-MM-dd}.%i.log</fileNamePattern> 22 + <fileNamePattern>${LOG_BASE}/main/main-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
23 <timeBasedFileNamingAndTriggeringPolicy 23 <timeBasedFileNamingAndTriggeringPolicy
24 class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> 24 class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
25 <maxFileSize>100MB</maxFileSize> 25 <maxFileSize>100MB</maxFileSize>
@@ -39,28 +39,47 @@ @@ -39,28 +39,47 @@
39 <!-- 访问日志 --> 39 <!-- 访问日志 -->
40 <appender name="ACCESS" 40 <appender name="ACCESS"
41 class="ch.qos.logback.core.rolling.RollingFileAppender"> 41 class="ch.qos.logback.core.rolling.RollingFileAppender">
42 - <file>${LOG_BASE}/access.log</file> 42 + <file>${LOG_BASE}/access/access.log</file>
43 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 43 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
44 - <fileNamePattern>${LOG_BASE}/access-%d{yyyy-MM-dd}.%i.log</fileNamePattern> 44 + <fileNamePattern>${LOG_BASE}/access/access-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
45 <timeBasedFileNamingAndTriggeringPolicy 45 <timeBasedFileNamingAndTriggeringPolicy
46 class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> 46 class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
47 <maxFileSize>100MB</maxFileSize> 47 <maxFileSize>100MB</maxFileSize>
48 </timeBasedFileNamingAndTriggeringPolicy> 48 </timeBasedFileNamingAndTriggeringPolicy>
49 </rollingPolicy> 49 </rollingPolicy>
50 - <encoder>  
51 - <pattern>%msg%n</pattern>  
52 - </encoder>  
53 50
54 <layout class="ch.qos.logback.classic.PatternLayout"> 51 <layout class="ch.qos.logback.classic.PatternLayout">
55 <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 --> 52 <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
56 - <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%file:%line] %-5level -%msg%n 53 + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level -%msg%n
57 </pattern> 54 </pattern>
58 </layout> 55 </layout>
59 </appender> 56 </appender>
60 -  
61 <logger name="com.bsth.filter.AccessLogFilter" level="INFO" additivity="false"> 57 <logger name="com.bsth.filter.AccessLogFilter" level="INFO" additivity="false">
62 <appender-ref ref="ACCESS" /> 58 <appender-ref ref="ACCESS" />
63 </logger> 59 </logger>
  60 +
  61 + <!-- 调度指令日志 -->
  62 + <appender name="DEVICE"
  63 + class="ch.qos.logback.core.rolling.RollingFileAppender">
  64 + <file>${LOG_BASE}/device/device.log</file>
  65 + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  66 + <fileNamePattern>${LOG_BASE}/device/device-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  67 + <timeBasedFileNamingAndTriggeringPolicy
  68 + class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
  69 + <maxFileSize>100MB</maxFileSize>
  70 + </timeBasedFileNamingAndTriggeringPolicy>
  71 + </rollingPolicy>
  72 +
  73 + <layout class="ch.qos.logback.classic.PatternLayout">
  74 + <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
  75 + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%file:%line] %-5level -%msg%n
  76 + </pattern>
  77 + </layout>
  78 + </appender>
  79 + <logger name="com.bsth.vehicle" level="INFO" additivity="false">
  80 + <appender-ref ref="DEVICE" />
  81 + </logger>
  82 +
64 83
65 <!-- 日志输出级别 --> 84 <!-- 日志输出级别 -->
66 <root level="info"> 85 <root level="info">