Commit 567fa3ece313d0e06c3c15e639371eedeaa33208
1 parent
df403c1b
update...
Showing
6 changed files
with
189 additions
and
1 deletions
src/main/java/com/bsth/Application.java
| ... | ... | @@ -11,7 +11,7 @@ import java.util.concurrent.ScheduledExecutorService; |
| 11 | 11 | @SpringBootApplication |
| 12 | 12 | public class Application extends SpringBootServletInitializer { |
| 13 | 13 | |
| 14 | - public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(8); | |
| 14 | + public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(9); | |
| 15 | 15 | |
| 16 | 16 | @Override |
| 17 | 17 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | ... | ... |
src/main/java/com/bsth/StartCommand.java
| 1 | 1 | package com.bsth; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | +import com.bsth.server_rs.schedule.real.thread.SchInOutDataRefreshThread; | |
| 4 | 5 | import com.bsth.server_rs.thread.RfidCardInfoPersistenceThread; |
| 5 | 6 | import com.bsth.service.Line2SystemService; |
| 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; |
| ... | ... | @@ -25,6 +26,9 @@ public class StartCommand implements CommandLineRunner{ |
| 25 | 26 | @Autowired |
| 26 | 27 | RfidCardInfoPersistenceThread rfidCardInfoPersistenceThread; |
| 27 | 28 | |
| 29 | + @Autowired | |
| 30 | + SchInOutDataRefreshThread schInOutDataRefreshThread; | |
| 31 | + | |
| 28 | 32 | @Override |
| 29 | 33 | public void run(String... arg0){ |
| 30 | 34 | |
| ... | ... | @@ -37,6 +41,9 @@ public class StartCommand implements CommandLineRunner{ |
| 37 | 41 | sexec.scheduleWithFixedDelay(rfidCardInfoPersistenceThread, 120, 60 * 10, TimeUnit.SECONDS); |
| 38 | 42 | //OldWSClient.returnCCInfo(); |
| 39 | 43 | //OldWSClient.getCurrentDayPlan(); |
| 44 | + | |
| 45 | + //定时从调度系统刷新进出场数据 | |
| 46 | + sexec.scheduleWithFixedDelay(schInOutDataRefreshThread, 40, 20, TimeUnit.SECONDS); | |
| 40 | 47 | } catch (Exception e) { |
| 41 | 48 | e.printStackTrace(); |
| 42 | 49 | } | ... | ... |
src/main/java/com/bsth/server_rs/schedule/real/SchRealInfoBuffer.java
0 → 100644
| 1 | +package com.bsth.server_rs.schedule.real; | |
| 2 | + | |
| 3 | +import com.bsth.entity.ScheduleRealInfo; | |
| 4 | +import org.springframework.stereotype.Component; | |
| 5 | + | |
| 6 | +import java.util.List; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * 实际排班缓存 | |
| 10 | + * Created by panzhao on 2017/9/27. | |
| 11 | + */ | |
| 12 | +@Component | |
| 13 | +public class SchRealInfoBuffer { | |
| 14 | + | |
| 15 | + /** | |
| 16 | + * 进出场班次数据,定时从调度系统获取。 对各场站输出 | |
| 17 | + */ | |
| 18 | + public static List<ScheduleRealInfo> inOutList; | |
| 19 | + | |
| 20 | +} | ... | ... |
src/main/java/com/bsth/server_rs/schedule/real/ScheduleRealService.java
| ... | ... | @@ -46,6 +46,23 @@ public class ScheduleRealService { |
| 46 | 46 | return all; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | + /** | |
| 50 | + * 获取当天指定停车场的进出场排班数据(潘钊场站VIP特供版 -高实时) | |
| 51 | + * | |
| 52 | + * @return | |
| 53 | + */ | |
| 54 | + @GET | |
| 55 | + @Path("/in_out/{code}") | |
| 56 | + public List<ScheduleInOut> findInOut_real(@PathParam("code") String code) { | |
| 57 | + Set<String> lineArray = BasicData.lineDateMap.keySet(); | |
| 58 | + | |
| 59 | + List<ScheduleInOut> all = new ArrayList<>(); | |
| 60 | + for (String lineCode : lineArray) { | |
| 61 | + all.addAll(ScheduleInOut.getMultiInstance(redisService.read(BasicData.lineDateMap.get(lineCode), lineCode), code)); | |
| 62 | + } | |
| 63 | + return all; | |
| 64 | + } | |
| 65 | + | |
| 49 | 66 | @GET |
| 50 | 67 | @Path("/sch_jk/{company}/{rq}") |
| 51 | 68 | public List<ScheduleRealInfoDTO_JK> find_JK(@PathParam("company") String company, @PathParam("rq") String rq) { | ... | ... |
src/main/java/com/bsth/server_rs/schedule/real/thread/SchInOutDataRefreshThread.java
0 → 100644
| 1 | +package com.bsth.server_rs.schedule.real.thread; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSON; | |
| 4 | +import com.bsth.entity.ScheduleRealInfo; | |
| 5 | +import com.bsth.server_rs.schedule.real.SchRealInfoBuffer; | |
| 6 | +import com.bsth.util.ConfigUtil; | |
| 7 | +import com.bsth.util.HttpClientUtils; | |
| 8 | +import org.slf4j.Logger; | |
| 9 | +import org.slf4j.LoggerFactory; | |
| 10 | +import org.springframework.stereotype.Component; | |
| 11 | + | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * 从调度系统获取进出场数据线程 | |
| 16 | + * Created by panzhao on 2017/9/27. | |
| 17 | + */ | |
| 18 | +@Component | |
| 19 | +public class SchInOutDataRefreshThread extends Thread { | |
| 20 | + | |
| 21 | + static String url; | |
| 22 | + static String secretKey; | |
| 23 | + | |
| 24 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 25 | + | |
| 26 | + static { | |
| 27 | + secretKey = ConfigUtil.get("http.control.secret.key"); | |
| 28 | + url = ConfigUtil.get("http.control.service_data_url") + "/findCurrInAndOut?secretKey=" + secretKey; | |
| 29 | + } | |
| 30 | + | |
| 31 | + @Override | |
| 32 | + public void run() { | |
| 33 | + try { | |
| 34 | + StringBuilder sb = HttpClientUtils.get(url); | |
| 35 | + List<ScheduleRealInfo> list = JSON.parseArray(sb.toString(), ScheduleRealInfo.class); | |
| 36 | + | |
| 37 | + if(null != list && list.size() > 0){ | |
| 38 | + SchRealInfoBuffer.inOutList = list; | |
| 39 | + logger.info("从调度系统刷新进出场班次: " + list.size()); | |
| 40 | + } | |
| 41 | + } catch (Exception e) { | |
| 42 | + logger.error("", e); | |
| 43 | + } | |
| 44 | + } | |
| 45 | +} | ... | ... |
src/main/java/com/bsth/util/HttpClientUtils.java
0 → 100644
| 1 | +package com.bsth.util; | |
| 2 | + | |
| 3 | +import org.apache.http.HttpEntity; | |
| 4 | +import org.apache.http.client.config.RequestConfig; | |
| 5 | +import org.apache.http.client.methods.CloseableHttpResponse; | |
| 6 | +import org.apache.http.client.methods.HttpGet; | |
| 7 | +import org.apache.http.client.methods.HttpPost; | |
| 8 | +import org.apache.http.entity.StringEntity; | |
| 9 | +import org.apache.http.impl.client.CloseableHttpClient; | |
| 10 | +import org.apache.http.impl.client.HttpClients; | |
| 11 | +import org.slf4j.Logger; | |
| 12 | +import org.slf4j.LoggerFactory; | |
| 13 | + | |
| 14 | +import java.io.BufferedReader; | |
| 15 | +import java.io.IOException; | |
| 16 | +import java.io.InputStreamReader; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * Created by panzhao on 2017/8/2. | |
| 20 | + */ | |
| 21 | +public class HttpClientUtils { | |
| 22 | + | |
| 23 | + static Logger logger = LoggerFactory.getLogger(HttpClientUtils.class); | |
| 24 | + | |
| 25 | + public static StringBuilder get(String url) throws Exception { | |
| 26 | + CloseableHttpClient httpClient = null; | |
| 27 | + CloseableHttpResponse response = null; | |
| 28 | + StringBuilder stringBuffer = null; | |
| 29 | + try { | |
| 30 | + httpClient = HttpClients.createDefault(); | |
| 31 | + HttpGet get = new HttpGet(url); | |
| 32 | + //超时时间 | |
| 33 | + RequestConfig requestConfig = RequestConfig.custom() | |
| 34 | + .setConnectTimeout(2500).setConnectionRequestTimeout(2000) | |
| 35 | + .setSocketTimeout(2500).build(); | |
| 36 | + get.setConfig(requestConfig); | |
| 37 | + get.addHeader("Content-Encoding", "gzip"); | |
| 38 | + | |
| 39 | + response = httpClient.execute(get); | |
| 40 | + stringBuffer = getResult(response.getEntity()); | |
| 41 | + } catch (Exception e) { | |
| 42 | + logger.error("", e); | |
| 43 | + } finally { | |
| 44 | + if (null != httpClient) | |
| 45 | + httpClient.close(); | |
| 46 | + if (null != response) | |
| 47 | + response.close(); | |
| 48 | + } | |
| 49 | + return stringBuffer; | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * raw post data | |
| 54 | + * @param url | |
| 55 | + * @param data | |
| 56 | + * @return | |
| 57 | + */ | |
| 58 | + public static StringBuilder post(String url, String data) throws Exception { | |
| 59 | + CloseableHttpClient httpClient = null; | |
| 60 | + CloseableHttpResponse response = null; | |
| 61 | + StringBuilder stringBuffer = null; | |
| 62 | + try { | |
| 63 | + httpClient = HttpClients.createDefault(); | |
| 64 | + HttpPost post = new HttpPost(url); | |
| 65 | + | |
| 66 | + post.setHeader("Accept", "application/json"); | |
| 67 | + post.setHeader("Content-Type", "application/json"); | |
| 68 | + //超时时间 | |
| 69 | + RequestConfig requestConfig = RequestConfig.custom() | |
| 70 | + .setConnectTimeout(2500).setConnectionRequestTimeout(2000) | |
| 71 | + .setSocketTimeout(2500).build(); | |
| 72 | + post.setConfig(requestConfig); | |
| 73 | + post.setEntity((new StringEntity(data, "UTF-8"))); | |
| 74 | + | |
| 75 | + response = httpClient.execute(post); | |
| 76 | + stringBuffer = getResult(response.getEntity()); | |
| 77 | + } catch (Exception e) { | |
| 78 | + logger.error("", e); | |
| 79 | + } finally { | |
| 80 | + if (null != httpClient) | |
| 81 | + httpClient.close(); | |
| 82 | + if (null != response) | |
| 83 | + response.close(); | |
| 84 | + } | |
| 85 | + return stringBuffer; | |
| 86 | + } | |
| 87 | + | |
| 88 | + private static StringBuilder getResult(HttpEntity entity) throws IOException { | |
| 89 | + StringBuilder stringBuffer = null; | |
| 90 | + if (null != entity) { | |
| 91 | + BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
| 92 | + stringBuffer = new StringBuilder(); | |
| 93 | + String str = ""; | |
| 94 | + while ((str = br.readLine()) != null) | |
| 95 | + stringBuffer.append(str); | |
| 96 | + } | |
| 97 | + return stringBuffer; | |
| 98 | + } | |
| 99 | +} | ... | ... |