Commit ee3384821716a1c6d0e26f3ef6549413d5c286d4

Authored by 潘钊
1 parent 9bf1aabc

update...

src/main/java/com/bsth/data/safe_driv/SafeDriv.java 0 → 100644
  1 +package com.bsth.data.safe_driv;
  2 +
  3 +/**
  4 + * 安全驾驶
  5 + * Created by panzhao on 2017/4/6.
  6 + */
  7 +public class SafeDriv {
  8 +
  9 + /**
  10 + * 时间
  11 + * 2017-04-06 08:00:00.0
  12 + */
  13 + private String Startime;
  14 +
  15 + /**
  16 + * 时间戳
  17 + */
  18 + private Long ts;
  19 +
  20 + /**
  21 + * 设备编号
  22 + */
  23 + private String sbbh;
  24 +
  25 + /**
  26 + * 线路名称
  27 + */
  28 + private String xlmc;
  29 +
  30 + /**
  31 + * 车辆自编号
  32 + */
  33 + private String clzbh;
  34 +
  35 + /**
  36 + * 车牌号
  37 + */
  38 + private String cph;
  39 +
  40 + /**
  41 + * 检查属性
  42 + * 双脱手 0 单脱手 1 其他为0都是异常
  43 + */
  44 + private String jctype;
  45 +
  46 + /**
  47 + * 异常种类
  48 + * 手部检测: 1
  49 + * 脸部检测: 5
  50 + * 摄像头检测: 2
  51 + * 安全带检测: 3
  52 + * 袖章检测: 4
  53 + */
  54 + private String yczltype;
  55 +
  56 + @Override
  57 + public int hashCode() {
  58 + return ("safe_" + (this.getClzbh() + this.getStartime())).hashCode();
  59 + }
  60 +
  61 + @Override
  62 + public boolean equals(Object obj) {
  63 + SafeDriv s2 = (SafeDriv)obj;
  64 + return (this.getClzbh() + this.getStartime()).equals(s2.getClzbh() + s2.getStartime());
  65 + }
  66 +
  67 + public String getStartime() {
  68 + return Startime;
  69 + }
  70 +
  71 + public void setStartime(String startime) {
  72 + Startime = startime;
  73 + }
  74 +
  75 + public String getSbbh() {
  76 + return sbbh;
  77 + }
  78 +
  79 + public void setSbbh(String sbbh) {
  80 + this.sbbh = sbbh;
  81 + }
  82 +
  83 + public String getXlmc() {
  84 + return xlmc;
  85 + }
  86 +
  87 + public void setXlmc(String xlmc) {
  88 + this.xlmc = xlmc;
  89 + }
  90 +
  91 + public String getClzbh() {
  92 + return clzbh;
  93 + }
  94 +
  95 + public void setClzbh(String clzbh) {
  96 + this.clzbh = clzbh;
  97 + }
  98 +
  99 + public String getCph() {
  100 + return cph;
  101 + }
  102 +
  103 + public void setCph(String cph) {
  104 + this.cph = cph;
  105 + }
  106 +
  107 + public String getJctype() {
  108 + return jctype;
  109 + }
  110 +
  111 + public void setJctype(String jctype) {
  112 + this.jctype = jctype;
  113 + }
  114 +
  115 + public String getYczltype() {
  116 + return yczltype;
  117 + }
  118 +
  119 + public void setYczltype(String yczltype) {
  120 + this.yczltype = yczltype;
  121 + }
  122 +
  123 + public Long getTs() {
  124 + return ts;
  125 + }
  126 +
  127 + public void setTs(Long ts) {
  128 + this.ts = ts;
  129 + }
  130 +}
... ...
src/main/java/com/bsth/data/safe_driv/SafeDrivCenter.java 0 → 100644
  1 +package com.bsth.data.safe_driv;
  2 +
  3 +import com.bsth.Application;
  4 +import com.bsth.websocket.handler.SendUtils;
  5 +import org.joda.time.format.DateTimeFormat;
  6 +import org.joda.time.format.DateTimeFormatter;
  7 +import org.springframework.beans.BeansException;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.boot.CommandLineRunner;
  10 +import org.springframework.context.ApplicationContext;
  11 +import org.springframework.context.ApplicationContextAware;
  12 +import org.springframework.stereotype.Component;
  13 +
  14 +import java.util.HashMap;
  15 +import java.util.HashSet;
  16 +import java.util.Map;
  17 +import java.util.Set;
  18 +import java.util.concurrent.TimeUnit;
  19 +
  20 +/**
  21 + * 安全驾驶
  22 + * Created by panzhao on 2017/4/6.
  23 + */
  24 +@Component
  25 +public class SafeDrivCenter implements CommandLineRunner,ApplicationContextAware {
  26 +
  27 + private static Set<SafeDriv> data;
  28 +
  29 + @Autowired
  30 + SafeDrivDataLoadThread safeDrivDataLoadThread;
  31 +
  32 + static SendUtils sendUtils;
  33 +
  34 + /**
  35 + * 车辆自编号 和 最新一条数据对照
  36 + */
  37 + private static Map<String, SafeDriv> safeMap;
  38 +
  39 + static {
  40 + data = new HashSet<>();
  41 + safeMap = new HashMap<>();
  42 + }
  43 +
  44 + private static DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS");
  45 + public static void put(SafeDriv sd){
  46 + sd.setTs(fmt.parseMillis(sd.getStartime()));
  47 + data.add(sd);
  48 +
  49 + if(sd.getYczltype().indexOf("A") == -1)
  50 + sd.setYczltype("A" + sd.getYczltype());
  51 +
  52 + SafeDriv old = safeMap.get(sd.getClzbh());
  53 + if(old == null || sd.getTs() > old.getTs()){
  54 + //通知客户端
  55 + sendUtils.sendSafeDriv(sd);
  56 + }
  57 +
  58 + safeMap.put(sd.getClzbh(), sd);
  59 + }
  60 +
  61 + @Override
  62 + public void run(String... strings) throws Exception {
  63 + //定时加载安全驾驶数据
  64 + Application.mainServices.scheduleWithFixedDelay(safeDrivDataLoadThread, 60, 5, TimeUnit.SECONDS);
  65 + }
  66 +
  67 + @Override
  68 + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  69 + sendUtils = applicationContext.getBean(SendUtils.class);
  70 + }
  71 +}
... ...
src/main/java/com/bsth/data/safe_driv/SafeDrivDataLoadThread.java 0 → 100644
  1 +package com.bsth.data.safe_driv;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import org.apache.http.HttpEntity;
  5 +import org.apache.http.client.methods.CloseableHttpResponse;
  6 +import org.apache.http.client.methods.HttpGet;
  7 +import org.apache.http.impl.client.CloseableHttpClient;
  8 +import org.apache.http.impl.client.HttpClients;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.stereotype.Component;
  12 +
  13 +import java.io.BufferedReader;
  14 +import java.io.InputStreamReader;
  15 +import java.util.List;
  16 +
  17 +/**
  18 + * 安全驾驶数据加载线程
  19 + * Created by panzhao on 2017/4/6.
  20 + */
  21 +@Component
  22 +public class SafeDrivDataLoadThread extends Thread{
  23 +
  24 + private final static String url = "http://180.166.5.82:9988//bsth-safedriving/Crlcxb/realtimeInterface.do";
  25 +
  26 + Logger logger = LoggerFactory.getLogger(this.getClass());
  27 +
  28 + @Override
  29 + public void run() {
  30 + List<SafeDriv> list = null;
  31 + CloseableHttpClient httpClient = null;
  32 + CloseableHttpResponse response = null;
  33 + try {
  34 + httpClient = HttpClients.createDefault();
  35 + HttpGet get = new HttpGet(url);
  36 +
  37 + response = httpClient.execute(get);
  38 +
  39 + HttpEntity entity = response.getEntity();
  40 + if (null != entity) {
  41 + BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
  42 + StringBuffer stringBuffer = new StringBuffer();
  43 + String str = "";
  44 + while ((str = br.readLine()) != null)
  45 + stringBuffer.append(str);
  46 +
  47 +
  48 + 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 +
  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){
  84 + SafeDrivCenter.put(sd);
  85 + }
  86 + }
  87 +
  88 + httpClient.close();
  89 + response.close();
  90 + } catch (Exception e) {
  91 + logger.error("", e);
  92 + }
  93 + }
  94 +}
... ...
src/main/java/com/bsth/websocket/handler/RealControlSocketHandler.java
... ... @@ -94,7 +94,7 @@ public class RealControlSocketHandler implements WebSocketHandler {
94 94 /**
95 95 * 根据线路推送消息
96 96 */
97   - public synchronized void sendMessageToLine(String lineCode, String msg) {
  97 + public void sendMessageToLine(String lineCode, String msg) {
98 98  
99 99 TextMessage message = new TextMessage(msg.getBytes());
100 100  
... ... @@ -117,4 +117,28 @@ public class RealControlSocketHandler implements WebSocketHandler {
117 117 }
118 118 }
119 119 }
  120 +
  121 +
  122 +
  123 + /**
  124 + * 全局推送
  125 + */
  126 + public void sendMessage(String msg) {
  127 +
  128 + TextMessage message = new TextMessage(msg.getBytes());
  129 +
  130 + Iterator<WebSocketSession> iterator = users.iterator();
  131 +
  132 + WebSocketSession user;
  133 + while(iterator.hasNext()){
  134 + user = iterator.next();
  135 + try {
  136 + if (user.isOpen()) {
  137 + user.sendMessage(message);
  138 + }
  139 + } catch (Exception e) {
  140 + logger.error("sendMessage error ...."+msg);
  141 + }
  142 + }
  143 + }
120 144 }
... ...
src/main/java/com/bsth/websocket/handler/SendUtils.java
... ... @@ -5,6 +5,7 @@ import com.bsth.data.BasicData;
5 5 import com.bsth.data.LineConfigData;
6 6 import com.bsth.data.gpsdata.GpsEntity;
7 7 import com.bsth.data.gpsdata.arrival.entity.SignalState;
  8 +import com.bsth.data.safe_driv.SafeDriv;
8 9 import com.bsth.entity.directive.D80;
9 10 import com.bsth.entity.realcontrol.ScheduleRealInfo;
10 11 import com.fasterxml.jackson.core.JsonProcessingException;
... ... @@ -184,4 +185,18 @@ public class SendUtils{
184 185 logger.error("", e);
185 186 }
186 187 }
  188 +
  189 + public void sendSafeDriv(SafeDriv sd){
  190 + Map<String, Object> map = new HashMap<>();
  191 + map.put("fn", "safeDriv");
  192 + map.put("t", sd);;
  193 + ObjectMapper mapper = new ObjectMapper();
  194 +
  195 + try {
  196 + socketHandler.sendMessage(mapper.writeValueAsString(map));
  197 +
  198 + } catch (JsonProcessingException e) {
  199 + logger.error("", e);
  200 + }
  201 + }
187 202 }
... ...
src/main/resources/static/real_control_v2/css/main.css
... ... @@ -923,4 +923,41 @@ option.oil_station_opt{
923 923 }
924 924 .park-and-station-wrap select{
925 925 width: auto !important;
  926 +}
  927 +
  928 +/** 安全驾驶相关css */
  929 +.safe_driv_pop_wrap{
  930 + position: absolute;
  931 + right: 12px;
  932 + bottom: 12px;
  933 +}
  934 +
  935 +.safe_driv_pop{
  936 + height: 45px;
  937 + background: #d44b4b;
  938 + color: #f2f2f2;
  939 + font-size: 15px;
  940 + padding: 9px 10px 0;
  941 + border: 1px solid #f4f0f0;
  942 + border-radius: 5px;
  943 + cursor: pointer;
  944 + box-shadow: 0 8px 17px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
  945 +}
  946 +
  947 +.safe_driv_pop:hover{
  948 + background: #bc2a2a;
  949 +}
  950 +
  951 +.safe_driv_pop .title{
  952 + font-weight: 600;
  953 +}
  954 +
  955 +.safe_driv_pop i.uk-icon-times-circle{
  956 + margin-right: 5px;
  957 +}
  958 +.safe_driv_pop .desc{
  959 + display: block;
  960 + font-size: 12px;
  961 + margin: 2px 0 0 20px;
  962 + color: #e3e3e3;
926 963 }
927 964 \ No newline at end of file
... ...
src/main/resources/static/real_control_v2/js/safe_driv/safeDriv.js 0 → 100644
  1 +/**
  2 + * 安全驾驶相关
  3 + */
  4 +var gb_safe_driv = (function () {
  5 +
  6 + var codes = {
  7 + 'A1': '手部违规',
  8 + 'A2': '摄像头偏离',
  9 + 'A3': '安全带',
  10 + 'A4': '手臂袖章',
  11 + 'A5': '脸部检测'
  12 + };
  13 +
  14 + var $wrap = $('.safe_driv_pop_wrap');
  15 + var max = 5;
  16 +
  17 + var pop = function (sd) {
  18 + //只有admin用户能收到
  19 + var user = gb_northToolbar.user();
  20 + if(!user || user.userName.indexOf('admin') == -1)
  21 + return;
  22 +
  23 + var htmlStr = '<div class="safe_driv_pop uk-animation-slide-bottom">'+
  24 + ' <span class="title"><i class="uk-icon-times-circle"></i>安全驾驶 '+moment(sd.ts).format('HH:mm')+'</span>'+
  25 + ' <span class="text"> '+sd.clzbh+' 违规驾驶('+codes[sd.yczltype]+')</span><span class="desc">请至安全驾驶监管平台查看图像信息</span>'+
  26 + '</div>';
  27 +
  28 + var items = $wrap.find('.safe_driv_pop'), len = items.length;
  29 + if(len >= max)
  30 + $wrap.find('.safe_driv_pop:lt('+(len - max)+')').remove();
  31 +
  32 + $wrap.append(htmlStr);
  33 + };
  34 +
  35 + $wrap.on('click', '.safe_driv_pop', function () {
  36 + $(this).remove();
  37 + });
  38 +
  39 + return {
  40 + pop: pop
  41 + }
  42 +})();
0 43 \ No newline at end of file
... ...
src/main/resources/static/real_control_v2/js/websocket/sch_websocket.js
... ... @@ -70,6 +70,10 @@ var gb_sch_websocket = (function () {
70 70 calcUntreated(msg.data.lineId);
71 71 };
72 72  
  73 + var safeDriv = function (msg) {
  74 + gb_safe_driv.pop(msg.t);
  75 + };
  76 +
73 77 var waitRemoves = [];
74 78 //车辆发出
75 79 var faChe = function (msg) {
... ... @@ -150,7 +154,8 @@ var gb_sch_websocket = (function () {
150 154 d80Confirm: d80Confirm,
151 155 directive: directiveStatus,
152 156 signal_state: signalState,
153   - deviceOffline: deviceOffline
  157 + deviceOffline: deviceOffline,
  158 + safeDriv: safeDriv
154 159 };
155 160  
156 161 function currentSecond() {
... ...
src/main/resources/static/real_control_v2/main.html
... ... @@ -60,6 +60,7 @@
60 60 </div>
61 61 </div>
62 62  
  63 +<div class="safe_driv_pop_wrap"></div>
63 64 <script>
64 65 delete window.exports;
65 66 delete window.module;
... ... @@ -182,8 +183,10 @@
182 183  
183 184 <!-- 处理表单片段嵌入问题 -->
184 185 <script src="/real_control_v2/js/forms/form_embed.js"></script>
185   -
  186 +<!-- 模态框扩展 -->
186 187 <script src="/real_control_v2/js/modal_extend.js"></script>
  188 +<!-- 安全驾驶相关 -->
  189 +<script src="/real_control_v2/js/safe_driv/safeDriv.js" ></script>
187 190 </body>
188 191  
189 192 </html>
... ...
src/main/resources/static/real_control_v2/mapmonitor/js/playback.js
... ... @@ -3,7 +3,7 @@
3 3 var gb_map_play_back = (function () {
4 4  
5 5 var dom;
6   - $.get('/real_control_v2/mapmonitor/fragments/playback_v2/main.html', function (rs) {
  6 + $.get('/real_control_v2/mapmonitor/fragments/playback/main.html', function (rs) {
7 7 dom = rs;
8 8 });
9 9  
... ... @@ -13,11 +13,10 @@ var gb_map_play_back = (function () {
13 13 gb_map_imap.call('closeWin', deviceId);
14 14  
15 15 //show modal
16   - open_modal_dom(dom, {deviceId: deviceId, nbbm: nbbm});
17   - //var modal = '#map-playback2-modal';
18   - //$(document.body).append(dom);
19   - //UIkit.modal(modal, {bgclose: false}).show();
20   - //$(modal).trigger('show_form', {deviceId: deviceId, nbbm: nbbm});
  16 + var modal = '#map-playback-modal';
  17 + $(document.body).append(dom);
  18 + UIkit.modal(modal, {bgclose: false}).show();
  19 + $(modal).trigger('show_form', {deviceId: deviceId, nbbm: nbbm});
21 20 };
22 21  
23 22 //导出excel
... ...