Commit 90e19e949c204cde51dff3459d1ed9bd1a288d2c

Authored by 潘钊
1 parent c68baa08

update...

src/main/java/com/bsth/data/safe_driv/SafeDrivCenter.java
@@ -5,7 +5,6 @@ import org.joda.time.format.DateTimeFormat; @@ -5,7 +5,6 @@ import org.joda.time.format.DateTimeFormat;
5 import org.joda.time.format.DateTimeFormatter; 5 import org.joda.time.format.DateTimeFormatter;
6 import org.springframework.beans.BeansException; 6 import org.springframework.beans.BeansException;
7 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
8 -import org.springframework.boot.CommandLineRunner;  
9 import org.springframework.context.ApplicationContext; 8 import org.springframework.context.ApplicationContext;
10 import org.springframework.context.ApplicationContextAware; 9 import org.springframework.context.ApplicationContextAware;
11 import org.springframework.stereotype.Component; 10 import org.springframework.stereotype.Component;
@@ -20,7 +19,7 @@ import java.util.Set; @@ -20,7 +19,7 @@ import java.util.Set;
20 * Created by panzhao on 2017/4/6. 19 * Created by panzhao on 2017/4/6.
21 */ 20 */
22 @Component 21 @Component
23 -public class SafeDrivCenter implements CommandLineRunner,ApplicationContextAware { 22 +public class SafeDrivCenter implements ApplicationContextAware {
24 23
25 private static Set<SafeDriv> data; 24 private static Set<SafeDriv> data;
26 25
@@ -65,12 +64,6 @@ public class SafeDrivCenter implements CommandLineRunner,ApplicationContextAware @@ -65,12 +64,6 @@ public class SafeDrivCenter implements CommandLineRunner,ApplicationContextAware
65 } 64 }
66 65
67 @Override 66 @Override
68 - public void run(String... strings) throws Exception {  
69 - //定时加载安全驾驶数据  
70 - //Application.mainServices.scheduleWithFixedDelay(safeDrivDataLoadThread, 80, 7, TimeUnit.SECONDS);  
71 - }  
72 -  
73 - @Override  
74 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 67 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
75 sendUtils = applicationContext.getBean(SendUtils.class); 68 sendUtils = applicationContext.getBean(SendUtils.class);
76 } 69 }
src/main/java/com/bsth/data/safe_driv/SafeDrivDataLoadThread.java
@@ -2,6 +2,7 @@ package com.bsth.data.safe_driv; @@ -2,6 +2,7 @@ package com.bsth.data.safe_driv;
2 2
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 import org.apache.http.HttpEntity; 4 import org.apache.http.HttpEntity;
  5 +import org.apache.http.client.config.RequestConfig;
5 import org.apache.http.client.methods.CloseableHttpResponse; 6 import org.apache.http.client.methods.CloseableHttpResponse;
6 import org.apache.http.client.methods.HttpGet; 7 import org.apache.http.client.methods.HttpGet;
7 import org.apache.http.impl.client.CloseableHttpClient; 8 import org.apache.http.impl.client.CloseableHttpClient;
@@ -21,24 +22,43 @@ import java.util.List; @@ -21,24 +22,43 @@ import java.util.List;
21 @Component 22 @Component
22 public class SafeDrivDataLoadThread extends Thread{ 23 public class SafeDrivDataLoadThread extends Thread{
23 24
24 - private final static String url = "http://180.166.5.82:9007/bsth-safedriving/Crlcxb/realtimeInterface.do";  
25 -  
26 Logger logger = LoggerFactory.getLogger(this.getClass()); 25 Logger logger = LoggerFactory.getLogger(this.getClass());
27 26
  27 + static String url;
  28 + static CloseableHttpClient httpClient = null;
  29 + static HttpGet get;
  30 + static RequestConfig requestConfig;
  31 + static CloseableHttpResponse response;
  32 + static HttpEntity entity;
  33 + static BufferedReader br;
  34 +
  35 + static {
  36 + url = "http://180.166.5.82:9007/bsth-safedriving/Crlcxb/realtimeInterface.do";
  37 + httpClient = HttpClients.createDefault();
  38 + get = new HttpGet(url);
  39 + requestConfig = RequestConfig.custom()
  40 + .setConnectTimeout(2500).setConnectionRequestTimeout(2000)
  41 + .setSocketTimeout(2500).build();
  42 + get.setConfig(requestConfig);
  43 + }
  44 +
28 @Override 45 @Override
29 public void run() { 46 public void run() {
30 - List<SafeDriv> list = null;  
31 - CloseableHttpClient httpClient = null;  
32 - CloseableHttpResponse response = null; 47 + List<SafeDriv> list;
33 try { 48 try {
34 - httpClient = HttpClients.createDefault();  
35 - HttpGet get = new HttpGet(url);  
36 49
37 response = httpClient.execute(get); 50 response = httpClient.execute(get);
38 51
39 - HttpEntity entity = response.getEntity(); 52 + int statusCode = response.getStatusLine().getStatusCode();
  53 + if(statusCode != 200){
  54 + get.abort();
  55 + logger.error("http client status code: " + statusCode);
  56 + return;
  57 + }
  58 +
  59 + entity = response.getEntity();
40 if (null != entity) { 60 if (null != entity) {
41 - BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent())); 61 + br = new BufferedReader(new InputStreamReader(entity.getContent()));
42 StringBuffer stringBuffer = new StringBuffer(); 62 StringBuffer stringBuffer = new StringBuffer();
43 String str = ""; 63 String str = "";
44 while ((str = br.readLine()) != null) 64 while ((str = br.readLine()) != null)
@@ -46,47 +66,14 @@ public class SafeDrivDataLoadThread extends Thread{ @@ -46,47 +66,14 @@ public class SafeDrivDataLoadThread extends Thread{
46 66
47 67
48 list = JSON.parseArray(stringBuffer.toString(), SafeDriv.class); 68 list = JSON.parseArray(stringBuffer.toString(), SafeDriv.class);
49 - /**  
50 - * 模拟数据  
51 -  
52 - SafeDriv sd1 = new SafeDriv();  
53 - sd1.setYczltype("1");  
54 - sd1.setClzbh("W2B-001");  
55 - sd1.setStartime("2017-04-07 08:00:00.0");  
56 -  
57 - SafeDriv sd2 = new SafeDriv();  
58 - sd2.setYczltype("2");  
59 - sd2.setClzbh("W2B-002");  
60 - sd2.setStartime("2017-04-07 08:02:00.0");  
61 -  
62 - SafeDriv sd3 = new SafeDriv();  
63 - sd3.setYczltype("3");  
64 - sd3.setClzbh("W2B-003");  
65 - sd3.setStartime("2017-04-07 08:03:00.0");  
66 -  
67 - SafeDriv sd4 = new SafeDriv();  
68 - sd4.setYczltype("4");  
69 - sd4.setClzbh("W2B-004");  
70 - sd4.setStartime("2017-04-07 08:04:00.0");  
71 -  
72 - SafeDriv sd5 = new SafeDriv();  
73 - sd5.setYczltype("5");  
74 - sd5.setClzbh("W2B-005");  
75 - sd5.setStartime("2017-04-07 08:05:00.0");  
76 69
77 - list.add(sd1);  
78 - list.add(sd2);  
79 - list.add(sd3);  
80 - list.add(sd4);  
81 - list.add(sd5);  
82 - */  
83 for(SafeDriv sd : list){ 70 for(SafeDriv sd : list){
84 SafeDrivCenter.put(sd); 71 SafeDrivCenter.put(sd);
85 } 72 }
86 } 73 }
87 74
88 - httpClient.close();  
89 - response.close(); 75 + if (null != response)
  76 + response.close();
90 } catch (Exception e) { 77 } catch (Exception e) {
91 logger.error("安全驾驶接口报错了" , e.getMessage()); 78 logger.error("安全驾驶接口报错了" , e.getMessage());
92 } 79 }
src/main/java/com/bsth/websocket/handler/SendUtils.java
@@ -168,8 +168,7 @@ public class SendUtils{ @@ -168,8 +168,7 @@ public class SendUtils{
168 ObjectMapper mapper = new ObjectMapper(); 168 ObjectMapper mapper = new ObjectMapper();
169 169
170 try { 170 try {
171 - socketHandler.sendMessage(mapper.writeValueAsString(map));  
172 - 171 + socketHandler.sendMessageToLine(sd.getXlbm(), mapper.writeValueAsString(map));
173 } catch (JsonProcessingException e) { 172 } catch (JsonProcessingException e) {
174 logger.error("", e); 173 logger.error("", e);
175 } 174 }
src/main/resources/static/pages/base/line/list.html
@@ -305,7 +305,7 @@ @@ -305,7 +305,7 @@
305 <a href="edit.html?no={{obj.id}}" class="btn default blue-stripe btn-sm" data-pjax> 修改 </a> 305 <a href="edit.html?no={{obj.id}}" class="btn default blue-stripe btn-sm" data-pjax> 修改 </a>
306 306
307 {{if obj.destroy==1}} 307 {{if obj.destroy==1}}
308 - <a class="ct_base_line_delete_link" data-id="{{obj.id}}" data-name="{{obj.name}}"> 删除 </a> 308 + <!--<a class="ct_base_line_delete_link" data-id="{{obj.id}}" data-name="{{obj.name}}"> 删除 </a>-->
309 {{/if}} 309 {{/if}}
310 </td> 310 </td>
311 </tr> 311 </tr>
src/main/resources/static/real_control_v2/js/safe_driv/safeDriv.js
@@ -20,10 +20,10 @@ var gb_safe_driv = (function () { @@ -20,10 +20,10 @@ var gb_safe_driv = (function () {
20 var max = 5; 20 var max = 5;
21 21
22 var pop = function (sd) { 22 var pop = function (sd) {
23 - //只有admin用户能收到 23 + /*//只有admin用户能收到
24 var user = gb_northToolbar.user(); 24 var user = gb_northToolbar.user();
25 if (!user || user.userName.indexOf('admin') == -1) 25 if (!user || user.userName.indexOf('admin') == -1)
26 - return; 26 + return;*/
27 27
28 //时间格式化 28 //时间格式化
29 var stm = moment(sd.ts); 29 var stm = moment(sd.ts);
@@ -60,7 +60,7 @@ var gb_safe_driv = (function () { @@ -60,7 +60,7 @@ var gb_safe_driv = (function () {
60 '</div>'; 60 '</div>';
61 61
62 $wrap.on('click', '.safe_driv_pop', function () { 62 $wrap.on('click', '.safe_driv_pop', function () {
63 - var title = $(this).data('title') + '&nbsp;<button data-nbbm="'+$(this).data('nbbm')+'" class="uk-button uk-button-mini uk-button-primary" id="openPhoneModalBtn" type="button">打电话</button>'; 63 + var title = $(this).data('title');// + '&nbsp;<button data-nbbm="'+$(this).data('nbbm')+'" class="uk-button uk-button-mini uk-button-primary" id="openPhoneModalBtn" type="button">打电话</button>';
64 var url = $(this).data('url'); 64 var url = $(this).data('url');
65 $(this).remove(); 65 $(this).remove();
66 var lightbox = UIkit.lightbox.create([ 66 var lightbox = UIkit.lightbox.create([