Commit 3a5c96c1fcf801d263c0b500e497b85265812e91

Authored by yiming
1 parent fb672d59

接口验签

src/main/java/com/bsth/XDApplication.java
@@ -163,7 +163,7 @@ public class XDApplication implements CommandLineRunner { @@ -163,7 +163,7 @@ public class XDApplication implements CommandLineRunner {
163 sexec.scheduleWithFixedDelay(scheduleRefreshThread, 10, 120, TimeUnit.SECONDS);//班次更新线程 163 sexec.scheduleWithFixedDelay(scheduleRefreshThread, 10, 120, TimeUnit.SECONDS);//班次更新线程
164 sexec.scheduleWithFixedDelay(scheduleLateThread, 140, 20, TimeUnit.SECONDS);//检查班次误点 164 sexec.scheduleWithFixedDelay(scheduleLateThread, 140, 20, TimeUnit.SECONDS);//检查班次误点
165 sexec.scheduleWithFixedDelay(gpsDataLoader, 100, 2, TimeUnit.SECONDS);//抓取GPS数据 165 sexec.scheduleWithFixedDelay(gpsDataLoader, 100, 2, TimeUnit.SECONDS);//抓取GPS数据
166 - sexec.scheduleWithFixedDelay(rfidDataLoader, 5, 5, TimeUnit.SECONDS);//抓取RFID数据 166 + //sexec.scheduleWithFixedDelay(rfidDataLoader, 5, 5, TimeUnit.SECONDS);//抓取RFID数据
167 sexec.scheduleWithFixedDelay(fixedCheckStationCodeThread, 60, 60 * 5, TimeUnit.SECONDS);//检查班次站点编码 167 sexec.scheduleWithFixedDelay(fixedCheckStationCodeThread, 60, 60 * 5, TimeUnit.SECONDS);//检查班次站点编码
168 168
169 sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线 169 sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线
@@ -214,7 +214,7 @@ public class XDApplication implements CommandLineRunner { @@ -214,7 +214,7 @@ public class XDApplication implements CommandLineRunner {
214 sexec.scheduleWithFixedDelay(scheduleRefreshThread, 10, 120, TimeUnit.SECONDS);//班次更新线程 214 sexec.scheduleWithFixedDelay(scheduleRefreshThread, 10, 120, TimeUnit.SECONDS);//班次更新线程
215 sexec.scheduleWithFixedDelay(scheduleLateThread, 140, 20, TimeUnit.SECONDS);//检查班次误点 215 sexec.scheduleWithFixedDelay(scheduleLateThread, 140, 20, TimeUnit.SECONDS);//检查班次误点
216 sexec.scheduleWithFixedDelay(gpsDataLoader, 0, 2, TimeUnit.SECONDS);//抓取GPS数据 216 sexec.scheduleWithFixedDelay(gpsDataLoader, 0, 2, TimeUnit.SECONDS);//抓取GPS数据
217 - sexec.scheduleWithFixedDelay(rfidDataLoader, 5, 5, TimeUnit.SECONDS);//抓取RFID数据 217 + //sexec.scheduleWithFixedDelay(rfidDataLoader, 5, 5, TimeUnit.SECONDS);//抓取RFID数据
218 sexec.scheduleWithFixedDelay(fixedCheckStationCodeThread, 60, 60 * 5, TimeUnit.SECONDS);//检查班次站点编码 218 sexec.scheduleWithFixedDelay(fixedCheckStationCodeThread, 60, 60 * 5, TimeUnit.SECONDS);//检查班次站点编码
219 219
220 sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线 220 sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线
@@ -266,7 +266,7 @@ public class XDApplication implements CommandLineRunner { @@ -266,7 +266,7 @@ public class XDApplication implements CommandLineRunner {
266 sexec.scheduleWithFixedDelay(scheduleRefreshThread, 10, 120, TimeUnit.SECONDS);//班次更新线程 266 sexec.scheduleWithFixedDelay(scheduleRefreshThread, 10, 120, TimeUnit.SECONDS);//班次更新线程
267 sexec.scheduleWithFixedDelay(scheduleLateThread, 140, 20, TimeUnit.SECONDS);//检查班次误点 267 sexec.scheduleWithFixedDelay(scheduleLateThread, 140, 20, TimeUnit.SECONDS);//检查班次误点
268 sexec.scheduleWithFixedDelay(gpsDataLoader, 0, 2, TimeUnit.SECONDS);//抓取GPS数据 268 sexec.scheduleWithFixedDelay(gpsDataLoader, 0, 2, TimeUnit.SECONDS);//抓取GPS数据
269 - sexec.scheduleWithFixedDelay(rfidDataLoader, 5, 5, TimeUnit.SECONDS);//抓取RFID数据 269 + //sexec.scheduleWithFixedDelay(rfidDataLoader, 5, 5, TimeUnit.SECONDS);//抓取RFID数据
270 sexec.scheduleWithFixedDelay(fixedCheckStationCodeThread, 60, 60 * 5, TimeUnit.SECONDS);//检查班次站点编码 270 sexec.scheduleWithFixedDelay(fixedCheckStationCodeThread, 60, 60 * 5, TimeUnit.SECONDS);//检查班次站点编码
271 271
272 sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线 272 sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线
@@ -312,7 +312,7 @@ public class XDApplication implements CommandLineRunner { @@ -312,7 +312,7 @@ public class XDApplication implements CommandLineRunner {
312 sexec.scheduleWithFixedDelay(scheduleRefreshThread, 10, 120, TimeUnit.SECONDS);//班次更新线程 312 sexec.scheduleWithFixedDelay(scheduleRefreshThread, 10, 120, TimeUnit.SECONDS);//班次更新线程
313 sexec.scheduleWithFixedDelay(scheduleLateThread, 140, 20, TimeUnit.SECONDS);//检查班次误点 313 sexec.scheduleWithFixedDelay(scheduleLateThread, 140, 20, TimeUnit.SECONDS);//检查班次误点
314 sexec.scheduleWithFixedDelay(gpsDataLoader, 0, 2, TimeUnit.SECONDS);//抓取GPS数据 314 sexec.scheduleWithFixedDelay(gpsDataLoader, 0, 2, TimeUnit.SECONDS);//抓取GPS数据
315 - sexec.scheduleWithFixedDelay(rfidDataLoader, 5, 5, TimeUnit.SECONDS);//抓取RFID数据 315 + //sexec.scheduleWithFixedDelay(rfidDataLoader, 5, 5, TimeUnit.SECONDS);//抓取RFID数据
316 sexec.scheduleWithFixedDelay(fixedCheckStationCodeThread, 60, 60 * 5, TimeUnit.SECONDS);//检查班次站点编码 316 sexec.scheduleWithFixedDelay(fixedCheckStationCodeThread, 60, 60 * 5, TimeUnit.SECONDS);//检查班次站点编码
317 317
318 sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线 318 sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线
src/main/java/com/bsth/common/SystemParamKeys.java
@@ -40,4 +40,6 @@ public class SystemParamKeys { @@ -40,4 +40,6 @@ public class SystemParamKeys {
40 public static final String URL_HTTP_SSO_LOGOUT = "url.http.sso.logout"; 40 public static final String URL_HTTP_SSO_LOGOUT = "url.http.sso.logout";
41 41
42 public static final String URL_HTTP_SSO_AUTH = "url.http.sso.auth"; 42 public static final String URL_HTTP_SSO_AUTH = "url.http.sso.auth";
  43 +
  44 + public static final String URL_HTTP_PWD = "url.http.pwd";
43 } 45 }
src/main/java/com/bsth/data/SystemParamCache.java
@@ -90,6 +90,10 @@ public class SystemParamCache implements InitializingBean { @@ -90,6 +90,10 @@ public class SystemParamCache implements InitializingBean {
90 return systemParamService1.getValue(SystemParamKeys.URL_HTTP_SSO_AUTH); 90 return systemParamService1.getValue(SystemParamKeys.URL_HTTP_SSO_AUTH);
91 } 91 }
92 92
  93 + public static String getUrlHttpPwd() {
  94 + return systemParamService1.getValue(SystemParamKeys.URL_HTTP_PWD);
  95 + }
  96 +
93 @Override 97 @Override
94 public void afterPropertiesSet() throws Exception { 98 public void afterPropertiesSet() throws Exception {
95 systemParamService1 = systemParamService; 99 systemParamService1 = systemParamService;
src/main/java/com/bsth/data/commonData/SyncData.java
@@ -91,7 +91,8 @@ public class SyncData extends Thread{ @@ -91,7 +91,8 @@ public class SyncData extends Thread{
91 @Autowired 91 @Autowired
92 BasicData.BasicDataLoader basicDataLoader; 92 BasicData.BasicDataLoader basicDataLoader;
93 93
94 - @Scheduled(cron = "0 1 * * * ?") 94 + //@Scheduled(cron = "0 1 * * * ?")
  95 + //@Transactional()
95 public void SyncData(){ 96 public void SyncData(){
96 syncBusiness(); 97 syncBusiness();
97 syncCarPark(); 98 syncCarPark();
src/main/java/com/bsth/data/gpsdata_v2/load/GatewayHttpLoader.java
1 package com.bsth.data.gpsdata_v2.load; 1 package com.bsth.data.gpsdata_v2.load;
2 2
  3 +import cn.hutool.http.HttpUtil;
3 import com.alibaba.fastjson.JSON; 4 import com.alibaba.fastjson.JSON;
4 import com.bsth.data.BasicData; 5 import com.bsth.data.BasicData;
5 import com.bsth.data.SystemParamCache; 6 import com.bsth.data.SystemParamCache;
6 import com.bsth.data.gpsdata_v2.GpsRealData; 7 import com.bsth.data.gpsdata_v2.GpsRealData;
7 import com.bsth.data.gpsdata_v2.entity.GpsEntity; 8 import com.bsth.data.gpsdata_v2.entity.GpsEntity;
8 import com.bsth.data.gpsdata_v2.utils.GpsDataUtils; 9 import com.bsth.data.gpsdata_v2.utils.GpsDataUtils;
  10 +import com.bsth.util.WebserviceSign;
9 import org.apache.commons.lang3.StringUtils; 11 import org.apache.commons.lang3.StringUtils;
10 import org.apache.http.HttpEntity; 12 import org.apache.http.HttpEntity;
11 import org.apache.http.client.config.RequestConfig; 13 import org.apache.http.client.config.RequestConfig;
12 import org.apache.http.client.methods.CloseableHttpResponse; 14 import org.apache.http.client.methods.CloseableHttpResponse;
13 import org.apache.http.client.methods.HttpGet; 15 import org.apache.http.client.methods.HttpGet;
14 import org.apache.http.impl.client.CloseableHttpClient; 16 import org.apache.http.impl.client.CloseableHttpClient;
  17 +import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
15 import org.apache.http.impl.client.HttpClients; 18 import org.apache.http.impl.client.HttpClients;
  19 +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
16 import org.slf4j.Logger; 20 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory; 21 import org.slf4j.LoggerFactory;
18 import org.springframework.beans.BeansException; 22 import org.springframework.beans.BeansException;
@@ -24,7 +28,9 @@ import org.springframework.stereotype.Component; @@ -24,7 +28,9 @@ import org.springframework.stereotype.Component;
24 import java.io.BufferedReader; 28 import java.io.BufferedReader;
25 import java.io.InputStreamReader; 29 import java.io.InputStreamReader;
26 import java.util.ArrayList; 30 import java.util.ArrayList;
  31 +import java.util.HashMap;
27 import java.util.List; 32 import java.util.List;
  33 +import java.util.Map;
28 34
29 /** 35 /**
30 * 从网关http 接口加载数据 36 * 从网关http 接口加载数据
@@ -51,22 +57,12 @@ public class GatewayHttpLoader implements ApplicationContextAware, InitializingB @@ -51,22 +57,12 @@ public class GatewayHttpLoader implements ApplicationContextAware, InitializingB
51 if(list.size() > 0) 57 if(list.size() > 0)
52 list.clear(); 58 list.clear();
53 59
54 - response = httpClient.execute(get);  
55 - entity = response.getEntity();  
56 60
57 - logger.info("entity:" + entity + "get:" + get);  
58 - if(null == entity)  
59 - return list;  
60 -  
61 - br = new BufferedReader(new InputStreamReader(entity.getContent()));  
62 -  
63 - StringBuilder sb = new StringBuilder();  
64 - String str;  
65 - while ((str = br.readLine()) != null)  
66 - sb.append(str);  
67 -  
68 - logger.debug("gps:" + sb.toString());  
69 - list = JSON.parseArray(JSON.parseObject(sb.toString()).getString("data"), GpsEntity.class); 61 + url =generateEndpoint(SystemParamCache.getUrlHttpGpsReal());
  62 + logger.info("get:" + url);
  63 + String sb = HttpUtil.get(url);
  64 + logger.info("gps:" + sb);
  65 + list = JSON.parseArray(sb, GpsEntity.class);
70 //过滤掉无效的点位 66 //过滤掉无效的点位
71 list = GpsDataUtils.clearInvalid(list); 67 list = GpsDataUtils.clearInvalid(list);
72 68
@@ -119,4 +115,33 @@ public class GatewayHttpLoader implements ApplicationContextAware, InitializingB @@ -119,4 +115,33 @@ public class GatewayHttpLoader implements ApplicationContextAware, InitializingB
119 .setSocketTimeout(2500).build(); 115 .setSocketTimeout(2500).build();
120 get.setConfig(requestConfig); 116 get.setConfig(requestConfig);
121 } 117 }
  118 +
  119 + /**
  120 + * 生成请求接口链接
  121 + * @param uri
  122 + * @return
  123 + */
  124 + private static String generateEndpoint(String uri) {
  125 + StringBuilder endpoint = new StringBuilder();
  126 + String timestamp = String.valueOf(System.currentTimeMillis());
  127 + String nonce = WebserviceSign.getRandomString(5);
  128 + Map<String, String> map = new HashMap<String, String>(3);
  129 + // 时间戳
  130 + map.put("timestamp", timestamp);
  131 + // 随机字符串
  132 + map.put("nonce", nonce);
  133 + // 密码
  134 + map.put("password", SystemParamCache.getUrlHttpPwd());
  135 + String signStr = null;
  136 + try {
  137 + signStr = WebserviceSign.getSHA1(map);
  138 + } catch (Exception e) {
  139 + logger.error("生成签名异常", e);
  140 + }
  141 + endpoint.append(uri).append("?timestamp=")
  142 + .append(timestamp).append("&nonce=").append(nonce).append("&password=")
  143 + .append(SystemParamCache.getUrlHttpPwd()).append("&sign=").append(signStr);
  144 + System.out.println(endpoint.toString());
  145 + return endpoint.toString();
  146 + }
122 } 147 }
src/main/java/com/bsth/service/impl/LsSectionRouteServiceImpl.java
@@ -15,6 +15,7 @@ import org.springframework.data.domain.Sort; @@ -15,6 +15,7 @@ import org.springframework.data.domain.Sort;
15 import org.springframework.stereotype.Service; 15 import org.springframework.stereotype.Service;
16 import org.springframework.transaction.annotation.Transactional; 16 import org.springframework.transaction.annotation.Transactional;
17 17
  18 +import java.util.Date;
18 import java.util.HashMap; 19 import java.util.HashMap;
19 import java.util.List; 20 import java.util.List;
20 import java.util.Map; 21 import java.util.Map;
@@ -121,6 +122,8 @@ public class LsSectionRouteServiceImpl extends BaseServiceImpl&lt;LsSectionRoute, I @@ -121,6 +122,8 @@ public class LsSectionRouteServiceImpl extends BaseServiceImpl&lt;LsSectionRoute, I
121 if (!isPresent) { 122 if (!isPresent) {
122 sectionRepository.save(section); 123 sectionRepository.save(section);
123 } 124 }
  125 + sectionRoute.setCreateDate(new Date());
  126 + sectionRoute.setUpdateDate(new Date());
124 lsSectionRouteRepository.save(sectionRoute); 127 lsSectionRouteRepository.save(sectionRoute);
125 if (sectionRoute.getVersions().equals(version)) { 128 if (sectionRoute.getVersions().equals(version)) {
126 refreshCurrent(line.getId(), version); 129 refreshCurrent(line.getId(), version);
src/main/java/com/bsth/util/WebserviceSign.java 0 → 100644
  1 +package com.bsth.util;
  2 +
  3 +import java.security.MessageDigest;
  4 +import java.util.Arrays;
  5 +import java.util.Map;
  6 +import java.util.Random;
  7 +
  8 +public class WebserviceSign {
  9 +
  10 + /**
  11 + * 生成签名
  12 + * @param map
  13 + * @return
  14 + * @throws Exception
  15 + */
  16 + public static String getSHA1(Map<String, String> map) throws Exception {
  17 + try {
  18 + String[] array = new String[map.size()];
  19 + map.values().toArray(array);
  20 + StringBuffer sb = new StringBuffer();
  21 + // 字符串排序
  22 + Arrays.sort(array);
  23 + for (int i = 0; i < array.length; i++) {
  24 + sb.append(array[i]);
  25 + }
  26 + String str = sb.toString();
  27 + // SHA1签名生成
  28 + MessageDigest md = MessageDigest.getInstance("SHA-1");
  29 + md.update(str.getBytes());
  30 + byte[] digest = md.digest();
  31 + StringBuffer hexstr = new StringBuffer();
  32 + String shaHex = "";
  33 + for (int i = 0; i < digest.length; i++) {
  34 + shaHex = Integer.toHexString(digest[i] & 0xFF);
  35 + if (shaHex.length() < 2) {
  36 + hexstr.append(0);
  37 + }
  38 + hexstr.append(shaHex);
  39 + }
  40 + return hexstr.toString();
  41 + } catch (Exception e) {
  42 + throw e;
  43 + }
  44 + }
  45 +
  46 + /**
  47 + * 生成随机字符串
  48 + * @param length
  49 + * @return
  50 + */
  51 + public static String getRandomString(int length) { //length表示生成字符串的长度
  52 + String base = "abcdefghijklmnopqrstuvwxyz0123456789";
  53 + Random random = new Random();
  54 + StringBuffer sb = new StringBuffer();
  55 + for (int i = 0; i < length; i++) {
  56 + int number = random.nextInt(base.length());
  57 + sb.append(base.charAt(number));
  58 + }
  59 + return sb.toString();
  60 + }
  61 +
  62 + public static void main(String[] args) {
  63 + // TODO Auto-generated method stub
  64 +
  65 + }
  66 +
  67 +
  68 +}
src/main/resources/static/real_control_v2/css/north.css
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 } 6 }
7 7
8 .north.main { 8 .north.main {
9 - background: linear-gradient(to right, #082F4A, #125688, #0a3f64); 9 + background: linear-gradient(to right, #ececef, #ececef, #ececef);
10 /*background-image: url('/assets/img/title-bg.jpg');*/ 10 /*background-image: url('/assets/img/title-bg.jpg');*/
11 padding-bottom: 0; 11 padding-bottom: 0;
12 } 12 }