Commit 3b24861588bb95ea46eefe12196f7d7c50b01fb3

Authored by 王通
1 parent 5fdd2dd4

1.

src/main/java/com/bsth/CXFConfig.java
@@ -16,6 +16,7 @@ import com.bsth.server_rs.destroy.DestroyDetailRestService; @@ -16,6 +16,7 @@ import com.bsth.server_rs.destroy.DestroyDetailRestService;
16 import com.bsth.server_rs.directive.DirectiveRestService; 16 import com.bsth.server_rs.directive.DirectiveRestService;
17 import com.bsth.server_rs.dks.BxRestService; 17 import com.bsth.server_rs.dks.BxRestService;
18 import com.bsth.server_rs.dks.DksRestService; 18 import com.bsth.server_rs.dks.DksRestService;
  19 +import com.bsth.server_rs.dks.ExternalRestService;
19 import com.bsth.server_rs.electric.ElectricService; 20 import com.bsth.server_rs.electric.ElectricService;
20 import com.bsth.server_rs.exception.AesExceptionMapper; 21 import com.bsth.server_rs.exception.AesExceptionMapper;
21 import com.bsth.server_rs.gps.GpsRestService; 22 import com.bsth.server_rs.gps.GpsRestService;
@@ -143,6 +144,9 @@ public class CXFConfig { @@ -143,6 +144,9 @@ public class CXFConfig {
143 @Autowired 144 @Autowired
144 private BxRestService bxRestService; 145 private BxRestService bxRestService;
145 146
  147 + @Autowired
  148 + private ExternalRestService externalRestService;
  149 +
146 @Bean 150 @Bean
147 public Server rsServer() { 151 public Server rsServer() {
148 JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean(); 152 JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
@@ -172,7 +176,8 @@ public class CXFConfig { @@ -172,7 +176,8 @@ public class CXFConfig {
172 dksRestService, 176 dksRestService,
173 xxfbRestService, 177 xxfbRestService,
174 manHoursRestService, 178 manHoursRestService,
175 - bxRestService)); 179 + bxRestService,
  180 + externalRestService));
176 endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper())); 181 endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper()));
177 //endpoint.setFeatures(Arrays.asList(new Swagger2Feature())); 182 //endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
178 endpoint.getInInterceptors().add(new AuthorizeInterceptor_IN()); 183 endpoint.getInInterceptors().add(new AuthorizeInterceptor_IN());
src/main/java/com/bsth/common/SystemParamKeys.java
@@ -14,4 +14,6 @@ public class SystemParamKeys { @@ -14,4 +14,6 @@ public class SystemParamKeys {
14 public static final String LIMIT_LINES = "limit.lines"; 14 public static final String LIMIT_LINES = "limit.lines";
15 15
16 public static final String LIMIT_DEVICES = "limit.devices"; 16 public static final String LIMIT_DEVICES = "limit.devices";
  17 +
  18 + public static final String LIMIT_DEVICES_EXTERNAL = "limit.devices.%s";
17 } 19 }
src/main/java/com/bsth/server_rs/base_info/car/buffer/CarBufferData.java
1 -package com.bsth.server_rs.base_info.car.buffer;  
2 -  
3 -import com.bsth.Application;  
4 -import com.bsth.server_rs.base_info.car.Car;  
5 -import com.bsth.server_rs.base_info.dto.BusCardDto;  
6 -import com.google.common.collect.ArrayListMultimap;  
7 -import org.springframework.beans.factory.annotation.Autowired;  
8 -import org.springframework.boot.CommandLineRunner;  
9 -import org.springframework.core.annotation.Order;  
10 -import org.springframework.stereotype.Component;  
11 -  
12 -import java.util.*;  
13 -import java.util.concurrent.TimeUnit;  
14 -  
15 -/**  
16 - * 车辆数据缓存  
17 - * Created by panzhao on 2017/3/30.  
18 - */  
19 -@Component  
20 -@Order(6)  
21 -public class CarBufferData implements CommandLineRunner {  
22 -  
23 - private static List<Car> data;  
24 - private static Map<String, Car> idMap;  
25 - private static ArrayListMultimap<String, Car> companyListMap;  
26 -  
27 - /**  
28 - * 待入库的bus car  
29 - */  
30 - public static LinkedList<Car> pstList = new LinkedList<>();  
31 -  
32 - @Autowired  
33 - CarRefreshThread carRefreshThread;  
34 -  
35 - public static List<Car> findAll(){  
36 - return data;  
37 - }  
38 -  
39 - public static Car findOne(String nbbm){  
40 - return idMap.get(nbbm);  
41 - }  
42 -  
43 - public static List<Car> findByCompany(String company){  
44 - return companyListMap.get(company);  
45 - }  
46 -  
47 - public static void replaceAll(List<Car> newData){  
48 - data = newData;  
49 - Map<String, Car> idMapCopy = new HashMap<>();  
50 - ArrayListMultimap<String, Car> listMap = ArrayListMultimap.create();  
51 -  
52 - for(Car car : data){  
53 - idMapCopy.put(car.getNbbm(), car);  
54 - listMap.put(car.getCompanyCode(), car);  
55 - }  
56 - idMap = idMapCopy;  
57 -  
58 - companyListMap = listMap;  
59 - }  
60 -  
61 - @Override  
62 - public void run(String... strings) throws Exception {  
63 - Application.mainServices.scheduleWithFixedDelay(carRefreshThread, 10, 60 * 60, TimeUnit.SECONDS);  
64 - }  
65 -  
66 - public static Map<String, Object> multiSaveCards(List<BusCardDto> list) {  
67 - int success=0,error=0;  
68 - //返回写入成功的卡数据  
69 - List<BusCardDto> rsList = new ArrayList<>();  
70 -  
71 - Car c;  
72 - for(BusCardDto bcd : list){  
73 - c = idMap.get(bcd.getNbbm());  
74 - if(c == null)  
75 - error ++;  
76 - else{  
77 - c.setIdRfid(bcd.getIdCard());  
78 - c.setTagRfid(bcd.getTagCard());  
79 - c.setRemark(bcd.getRemark());  
80 - success ++;  
81 -  
82 - pstList.add(c);  
83 - rsList.add(bcd);  
84 - }  
85 - }  
86 -  
87 - Map<String, Object> rs = new HashMap<>();  
88 - rs.put("success", success);  
89 - rs.put("successList", rsList);  
90 - rs.put("error", error);  
91 - return rs;  
92 - }  
93 -} 1 +package com.bsth.server_rs.base_info.car.buffer;
  2 +
  3 +import com.bsth.Application;
  4 +import com.bsth.server_rs.base_info.car.Car;
  5 +import com.bsth.server_rs.base_info.dto.BusCardDto;
  6 +import com.google.common.collect.ArrayListMultimap;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.boot.CommandLineRunner;
  9 +import org.springframework.core.annotation.Order;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +import java.util.*;
  13 +import java.util.concurrent.TimeUnit;
  14 +
  15 +/**
  16 + * 车辆数据缓存
  17 + * Created by panzhao on 2017/3/30.
  18 + */
  19 +@Component
  20 +@Order(6)
  21 +public class CarBufferData implements CommandLineRunner {
  22 +
  23 + private static List<Car> data;
  24 + private static Map<String, Car> idMap;
  25 + private static Map<String, Car> device2car;
  26 + private static ArrayListMultimap<String, Car> companyListMap;
  27 +
  28 + /**
  29 + * 待入库的bus car
  30 + */
  31 + public static LinkedList<Car> pstList = new LinkedList<>();
  32 +
  33 + @Autowired
  34 + CarRefreshThread carRefreshThread;
  35 +
  36 + public static List<Car> findAll(){
  37 + return data;
  38 + }
  39 +
  40 + public static Car findOne(String nbbm){
  41 + return idMap.get(nbbm);
  42 + }
  43 +
  44 + public static Car findOneByDevice(String device){
  45 + return device2car.get(device);
  46 + }
  47 +
  48 + public static List<Car> findByCompany(String company){
  49 + return companyListMap.get(company);
  50 + }
  51 +
  52 + public static void replaceAll(List<Car> newData){
  53 + data = newData;
  54 + Map<String, Car> idMapCopy = new HashMap<>();
  55 + Map<String, Car> device2carCopy = new HashMap<>();
  56 + ArrayListMultimap<String, Car> listMap = ArrayListMultimap.create();
  57 +
  58 + for(Car car : data){
  59 + idMapCopy.put(car.getNbbm(), car);
  60 + device2carCopy.put(car.getEquipmentCode(), car);
  61 + listMap.put(car.getCompanyCode(), car);
  62 + }
  63 + idMap = idMapCopy;
  64 + device2car = device2carCopy;
  65 + companyListMap = listMap;
  66 + }
  67 +
  68 + @Override
  69 + public void run(String... strings) throws Exception {
  70 + Application.mainServices.scheduleWithFixedDelay(carRefreshThread, 10, 60 * 60, TimeUnit.SECONDS);
  71 + }
  72 +
  73 + public static Map<String, Object> multiSaveCards(List<BusCardDto> list) {
  74 + int success=0,error=0;
  75 + //返回写入成功的卡数据
  76 + List<BusCardDto> rsList = new ArrayList<>();
  77 +
  78 + Car c;
  79 + for(BusCardDto bcd : list){
  80 + c = idMap.get(bcd.getNbbm());
  81 + if(c == null)
  82 + error ++;
  83 + else{
  84 + c.setIdRfid(bcd.getIdCard());
  85 + c.setTagRfid(bcd.getTagCard());
  86 + c.setRemark(bcd.getRemark());
  87 + success ++;
  88 +
  89 + pstList.add(c);
  90 + rsList.add(bcd);
  91 + }
  92 + }
  93 +
  94 + Map<String, Object> rs = new HashMap<>();
  95 + rs.put("success", success);
  96 + rs.put("successList", rsList);
  97 + rs.put("error", error);
  98 + return rs;
  99 + }
  100 +}
src/main/java/com/bsth/server_rs/gps/buffer/GpsRefreshThread.java
1 -package com.bsth.server_rs.gps.buffer;  
2 -  
3 -import com.alibaba.fastjson.JSON;  
4 -import com.alibaba.fastjson.JSONObject;  
5 -import com.bsth.server_rs.gps.entity.GpsEntity;  
6 -import com.bsth.util.ConfigUtil;  
7 -import org.apache.http.HttpEntity;  
8 -import org.apache.http.client.config.RequestConfig;  
9 -import org.apache.http.client.methods.CloseableHttpResponse;  
10 -import org.apache.http.client.methods.HttpGet;  
11 -import org.apache.http.impl.client.CloseableHttpClient;  
12 -import org.apache.http.impl.client.HttpClients;  
13 -import org.slf4j.Logger;  
14 -import org.slf4j.LoggerFactory;  
15 -import org.springframework.stereotype.Component;  
16 -  
17 -import java.io.BufferedReader;  
18 -import java.io.InputStreamReader;  
19 -import java.util.List;  
20 -  
21 -/**  
22 - * Created by panzhao on 2017/3/30.  
23 - */  
24 -@Component  
25 -public class GpsRefreshThread extends Thread{  
26 -  
27 - static String url;  
28 -  
29 - static {  
30 - url = ConfigUtil.get("http.gps.real.url");  
31 - }  
32 -  
33 - Logger logger = LoggerFactory.getLogger(this.getClass());  
34 -  
35 - @Override  
36 - public void run() {  
37 - try {  
38 - CloseableHttpClient httpClient = null;  
39 - List<GpsEntity> rs = null;  
40 - httpClient = HttpClients.createDefault();  
41 - //超时时间  
42 - RequestConfig requestConfig = RequestConfig.custom()  
43 - .setConnectTimeout(2000).setConnectionRequestTimeout(1000)  
44 - .setSocketTimeout(3000).build();  
45 -  
46 - HttpGet get = new HttpGet(url);  
47 - get.setConfig(requestConfig);  
48 -  
49 - CloseableHttpResponse response = httpClient.execute(get);  
50 -  
51 - HttpEntity entity = response.getEntity();  
52 - BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));  
53 - StringBuffer stringBuffer = new StringBuffer();  
54 - String str = "";  
55 - while ((str = br.readLine()) != null)  
56 - stringBuffer.append(str);  
57 -  
58 - JSONObject jsonObj = JSON.parseObject(stringBuffer.toString());  
59 -  
60 - if (jsonObj != null)  
61 - rs = JSON.parseArray(jsonObj.getString("data"), GpsEntity.class);  
62 -  
63 - for(GpsEntity gps : rs){  
64 - GpsRealDataBuffer.put(gps);  
65 - }  
66 - }catch (Exception e){  
67 - logger.error("", e);  
68 - }  
69 - }  
70 -} 1 +package com.bsth.server_rs.gps.buffer;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.bsth.server_rs.base_info.car.Car;
  6 +import com.bsth.server_rs.base_info.car.buffer.CarBufferData;
  7 +import com.bsth.server_rs.gps.entity.GpsEntity;
  8 +import com.bsth.util.ConfigUtil;
  9 +import org.apache.http.HttpEntity;
  10 +import org.apache.http.client.config.RequestConfig;
  11 +import org.apache.http.client.methods.CloseableHttpResponse;
  12 +import org.apache.http.client.methods.HttpGet;
  13 +import org.apache.http.impl.client.CloseableHttpClient;
  14 +import org.apache.http.impl.client.HttpClients;
  15 +import org.slf4j.Logger;
  16 +import org.slf4j.LoggerFactory;
  17 +import org.springframework.stereotype.Component;
  18 +
  19 +import java.io.BufferedReader;
  20 +import java.io.InputStreamReader;
  21 +import java.util.List;
  22 +
  23 +/**
  24 + * Created by panzhao on 2017/3/30.
  25 + */
  26 +@Component
  27 +public class GpsRefreshThread extends Thread{
  28 +
  29 + static String url;
  30 +
  31 + static {
  32 + url = ConfigUtil.get("http.gps.real.url");
  33 + }
  34 +
  35 + Logger logger = LoggerFactory.getLogger(this.getClass());
  36 +
  37 + @Override
  38 + public void run() {
  39 + try {
  40 + CloseableHttpClient httpClient = null;
  41 + List<GpsEntity> rs = null;
  42 + httpClient = HttpClients.createDefault();
  43 + //超时时间
  44 + RequestConfig requestConfig = RequestConfig.custom()
  45 + .setConnectTimeout(2000).setConnectionRequestTimeout(1000)
  46 + .setSocketTimeout(3000).build();
  47 +
  48 + HttpGet get = new HttpGet(url);
  49 + get.setConfig(requestConfig);
  50 +
  51 + CloseableHttpResponse response = httpClient.execute(get);
  52 +
  53 + HttpEntity entity = response.getEntity();
  54 + BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
  55 + StringBuffer stringBuffer = new StringBuffer();
  56 + String str = "";
  57 + while ((str = br.readLine()) != null)
  58 + stringBuffer.append(str);
  59 +
  60 + JSONObject jsonObj = JSON.parseObject(stringBuffer.toString());
  61 +
  62 + if (jsonObj != null)
  63 + rs = JSON.parseArray(jsonObj.getString("data"), GpsEntity.class);
  64 +
  65 + for(GpsEntity gps : rs){
  66 + Car car = CarBufferData.findOneByDevice(gps.getDeviceId());
  67 + if (car != null) {
  68 + gps.setNbbm(car.getNbbm());
  69 + }
  70 + GpsRealDataBuffer.put(gps);
  71 + }
  72 + }catch (Exception e){
  73 + logger.error("", e);
  74 + }
  75 + }
  76 +}
src/main/java/com/bsth/service/impl/SystemParamServiceImpl.java
@@ -20,7 +20,7 @@ public class SystemParamServiceImpl implements SystemParamService { @@ -20,7 +20,7 @@ public class SystemParamServiceImpl implements SystemParamService {
20 20
21 private Map<String, String> pairs = new HashMap<>(); 21 private Map<String, String> pairs = new HashMap<>();
22 22
23 - @Scheduled(cron = "0 0/30 * * * ?") 23 + @Scheduled(cron = "0 0/5 * * * ?")
24 public void refresh() { 24 public void refresh() {
25 for (SystemParam sp : systemParamRepository.findAll()) { 25 for (SystemParam sp : systemParamRepository.findAll()) {
26 pairs.put(sp.getKey(), sp.getValue()); 26 pairs.put(sp.getKey(), sp.getValue());
src/main/resources/application.properties
1 -spring.profiles: dev,prod  
2 -spring.profiles.active: prod  
3 -  
4 -spring.view.suffix=.html  
5 -server.session-timeout=-1  
6 -security.basic.enabled=false  
7 -  
8 -# \u4E0A\u4F20\u6587\u4EF6\u5927\u5C0F\u9650\u5236\u914D\u7F6E  
9 -# File size limit  
10 -multipart.maxFileSize = -1  
11 -# Total request size for a multipart/form-data  
12 -multipart.maxRequestSize = -1  
13 -  
14 -server.compression.enabled=true  
15 -server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain,text/javascript,text/css,application/javascript  
16 -  
17 -#redis  
18 -cache.days=15 1 +spring.profiles.active= prod
  2 +
  3 +spring.view.suffix=.html
  4 +server.session-timeout=-1
  5 +security.basic.enabled=false
  6 +
  7 +# \u4E0A\u4F20\u6587\u4EF6\u5927\u5C0F\u9650\u5236\u914D\u7F6E
  8 +# File size limit
  9 +multipart.maxFileSize = -1
  10 +# Total request size for a multipart/form-data
  11 +multipart.maxRequestSize = -1
  12 +
  13 +server.compression.enabled=true
  14 +server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain,text/javascript,text/css,application/javascript
  15 +
  16 +#redis
  17 +cache.days=15