Commit ab5fd6f0978d12bcf21501523c58d808f6733254

Authored by 潘钊
1 parent eb6a93a8

update...

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(9);
  14 + public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(10);
15 15  
16 16 @Override
17 17 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
... ...
src/main/java/com/bsth/CXFConfig.java
... ... @@ -6,6 +6,7 @@ import com.bsth.server_rs.base_info.line.LineRestService;
6 6 import com.bsth.server_rs.base_info.person.PersonRestService;
7 7 import com.bsth.server_rs.base_info.section.LD_SectionRestService;
8 8 import com.bsth.server_rs.base_info.station.StationRestService;
  9 +import com.bsth.server_rs.directive.DirectiveRestService;
9 10 import com.bsth.server_rs.exception.AesExceptionMapper;
10 11 import com.bsth.server_rs.gps.GpsRestService;
11 12 import com.bsth.server_rs.logs.RealLogRestService;
... ... @@ -95,6 +96,8 @@ public class CXFConfig {
95 96 RealLogRestService realLogRestService;
96 97 @Autowired
97 98 GpsRestService gpsRestService;
  99 + @Autowired
  100 + DirectiveRestService directiveRestService;
98 101  
99 102 @Bean
100 103 public Server rsServer() {
... ... @@ -110,7 +113,8 @@ public class CXFConfig {
110 113 stationRestService,
111 114 ldSectionRestService,
112 115 schedulePlanService,
113   - realLogRestService));
  116 + realLogRestService,
  117 + directiveRestService));
114 118 endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper()));
115 119 //endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
116 120 endpoint.getInInterceptors().add(new AuthorizeInterceptor_IN());
... ...
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.ExecSchDataRefreshThread;
4 5 import com.bsth.server_rs.schedule.real.thread.SchInOutDataRefreshThread;
5 6 import com.bsth.server_rs.thread.RfidCardInfoPersistenceThread;
6 7 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -26,6 +27,9 @@ public class StartCommand implements CommandLineRunner{
26 27 @Autowired
27 28 SchInOutDataRefreshThread schInOutDataRefreshThread;
28 29  
  30 + @Autowired
  31 + ExecSchDataRefreshThread execSchDataRefreshThread;
  32 +
29 33 @Override
30 34 public void run(String... arg0){
31 35  
... ... @@ -33,11 +37,11 @@ public class StartCommand implements CommandLineRunner{
33 37 ScheduledExecutorService sexec = Application.mainServices;
34 38 //定时将人车卡数据入库
35 39 sexec.scheduleWithFixedDelay(rfidCardInfoPersistenceThread, 120, 60 * 10, TimeUnit.SECONDS);
36   - //OldWSClient.returnCCInfo();
37   - //OldWSClient.getCurrentDayPlan();
38 40  
39 41 //定时从调度系统刷新进出场数据
40   - sexec.scheduleWithFixedDelay(schInOutDataRefreshThread, 40, 15, TimeUnit.SECONDS);
  42 + sexec.scheduleWithFixedDelay(schInOutDataRefreshThread, 40, 20, TimeUnit.SECONDS);
  43 + //定时从调度系统刷新车辆正在的执行班次
  44 + sexec.scheduleWithFixedDelay(execSchDataRefreshThread, 20, 60 * 2, TimeUnit.SECONDS);
41 45 } catch (Exception e) {
42 46 e.printStackTrace();
43 47 }
... ...
src/main/java/com/bsth/server_rs/directive/DirectiveRestService.java 0 → 100644
  1 +package com.bsth.server_rs.directive;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.bsth.server_rs.schedule.real.SchRealDataBuffer;
  5 +import com.bsth.util.ConfigUtil;
  6 +import com.bsth.util.HttpClientUtils;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Component;
  11 +import org.springframework.web.bind.annotation.RequestBody;
  12 +
  13 +import javax.ws.rs.*;
  14 +import javax.ws.rs.core.MediaType;
  15 +import java.util.List;
  16 +import java.util.Map;
  17 +
  18 +/**
  19 + * Created by panzhao on 2017/11/10.
  20 + */
  21 +@Component
  22 +@Path("/directive")
  23 +@Produces({MediaType.APPLICATION_JSON})
  24 +public class DirectiveRestService {
  25 +
  26 + static String url;
  27 + static String secretKey;
  28 +
  29 + @Autowired
  30 + SchRealDataBuffer schRealDataBuffer;
  31 + Logger logger = LoggerFactory.getLogger(this.getClass());
  32 +
  33 + static {
  34 + secretKey = ConfigUtil.get("http.control.secret.key");
  35 + url = ConfigUtil.get("http.control.service_data_url") + "/send60Phrase?secretKey=" + secretKey;
  36 + }
  37 +
  38 + @POST
  39 + @Path("/send")
  40 + public int send(@RequestBody Map<String, Object> map){
  41 + try{
  42 + map.put("sender", map.get("接口"));
  43 + StringBuilder sb = HttpClientUtils.post(url , JSON.toJSONString(map));
  44 + return Integer.parseInt(sb.toString());
  45 + }catch (Exception e){
  46 + logger.error("", e);
  47 + return -500;
  48 + }
  49 + }
  50 +
  51 + @GET
  52 + @Path("/reply/{msgIds}")
  53 + public List<Map> reply(@PathParam("msgIds") String msgIds){
  54 + try{
  55 + StringBuilder sb = HttpClientUtils.get(url + "&msgIds=" + msgIds);
  56 + return JSON.parseArray(sb.toString(), Map.class);
  57 + }catch (Exception e){
  58 + logger.error("", e);
  59 + return null;
  60 + }
  61 + }
  62 +}
... ...
src/main/java/com/bsth/server_rs/schedule/real/SchRealInfoBuffer.java renamed to src/main/java/com/bsth/server_rs/schedule/real/SchRealDataBuffer.java
1 1 package com.bsth.server_rs.schedule.real;
2 2  
  3 +import com.alibaba.fastjson.JSONObject;
3 4 import com.bsth.entity.ScheduleRealInfo;
4 5 import com.google.common.collect.ArrayListMultimap;
5 6 import org.apache.commons.lang3.StringUtils;
6 7 import org.springframework.stereotype.Component;
7 8  
8 9 import java.util.List;
  10 +import java.util.Map;
9 11  
10 12 /**
11 13 * 实际排班缓存
12 14 * Created by panzhao on 2017/9/27.
13 15 */
14 16 @Component
15   -public class SchRealInfoBuffer {
  17 +public class SchRealDataBuffer {
16 18  
17 19 /**
18 20 * 进出场班次数据,定时从调度系统获取。 对各场站输出
19 21 */
20 22 private static ArrayListMultimap<String, ScheduleRealInfo> inOutMap;
21 23  
22   - public void putInOutData(List<ScheduleRealInfo> list){
  24 + /**
  25 + * 车辆 和 当前正在执行班次对照
  26 + */
  27 + private static Map<String, JSONObject> execMap;
  28 +
  29 + public void putInOutData(List<ScheduleRealInfo> list) {
23 30 ArrayListMultimap<String, ScheduleRealInfo> inOutMapCopy = ArrayListMultimap.create();
24 31  
25 32 String type;
26   - for(ScheduleRealInfo sch : list){
  33 + for (ScheduleRealInfo sch : list) {
27 34 type = sch.getBcType();
28   - if(StringUtils.isEmpty(type))
  35 + if (StringUtils.isEmpty(type))
29 36 continue;
30 37  
31   - if(type.equals("in"))
  38 + if (type.equals("in"))
32 39 inOutMapCopy.put(sch.getZdzCode(), sch);
33   - else if(type.equals("out"))
  40 + else if (type.equals("out"))
34 41 inOutMapCopy.put(sch.getQdzCode(), sch);
35 42 }
36 43  
37 44 inOutMap = inOutMapCopy;
38 45 }
39 46  
40   - public List<ScheduleRealInfo> findByParkCode(String parkCode){
  47 +
  48 + public void setExecMap(Map<String, JSONObject> map) {
  49 + if (map.size() > 0)
  50 + execMap = map;
  51 + }
  52 +
  53 + public List<ScheduleRealInfo> findByParkCode(String parkCode) {
41 54 return inOutMap.get(parkCode);
42 55 }
  56 +
  57 + /* public List<JSONObject> findExec(List<String> cars){
  58 + List<JSONObject> rs = new ArrayList<>(cars.size());
  59 +
  60 + for(String nbbm : cars){
  61 + rs.add(execMap.get(nbbm));
  62 + }
  63 + return rs;
  64 + }*/
  65 +
  66 + public JSONObject getExecPlan(String nbbm) {
  67 + return execMap.get(nbbm);
  68 + }
43 69 }
... ...
src/main/java/com/bsth/server_rs/schedule/real/ScheduleRealService.java
1 1 package com.bsth.server_rs.schedule.real;
2 2  
  3 +import com.alibaba.fastjson.JSONObject;
3 4 import com.bsth.common.BasicData;
4 5 import com.bsth.redis.ScheduleRedisService;
5 6 import com.bsth.server_rs.base_info.line.Line;
... ... @@ -33,7 +34,7 @@ public class ScheduleRealService {
33 34 ScheduleRedisService redisService;
34 35  
35 36 @Autowired
36   - SchRealInfoBuffer schRealInfoBuffer;
  37 + SchRealDataBuffer schRealDataBuffer;
37 38  
38 39 Logger logger = LoggerFactory.getLogger(this.getClass());
39 40  
... ... @@ -56,23 +57,34 @@ public class ScheduleRealService {
56 57  
57 58 /**
58 59 * 获取指定日期,指定公司的人员车辆配置情况(实际排班)
59   - * @param code
  60 + * @param company
60 61 * @param rq
61 62 * @return
62 63 */
63 64 @GET
64   - @Path("/ccConfig/{code}/{rq}")
65   - public List<ScheduleCcInfoConfig> ccInfoConfig(@PathParam("code") String code, @PathParam("rq") String rq){
66   - Set<String> lineArray = BasicData.lineDateMap.keySet();
  65 + @Path("/ccConfig/{company}/{rq}")
  66 + public List<ScheduleCcInfoConfig> ccInfoConfig(@PathParam("company") String company, @PathParam("rq") String rq){
  67 + List<Line> lines = LineBufferData.findByCompany(company);
67 68  
68 69 List<ScheduleCcInfoConfig> all = new ArrayList<>();
69   - for (String lineCode : lineArray) {
70   - all.addAll(ScheduleCcInfoConfig.getMultiInstance(redisService.read(rq, lineCode)));
  70 + for (Line line : lines) {
  71 + all.addAll(ScheduleCcInfoConfig.getMultiInstance(redisService.read(rq, line.getLineCode())));
71 72 }
72 73 return all;
73 74 }
74 75  
75 76 /**
  77 + * 根据车辆自编号获取对应执行的班次信息
  78 + * @param nbbm
  79 + * @return
  80 + */
  81 + @GET
  82 + @Path("/exec/{nbbm}")
  83 + public JSONObject getExecPlan(@PathParam("nbbm") String nbbm){
  84 + return schRealDataBuffer.getExecPlan(nbbm);
  85 + }
  86 +
  87 + /**
76 88 * 获取当天指定停车场的进出场排班数据(潘钊场站VIP特供版 -高实时)
77 89 *
78 90 * @return
... ... @@ -81,7 +93,7 @@ public class ScheduleRealService {
81 93 @Path("/in_out/pz_vip/{code}")
82 94 public List<ScheduleInOut> findInOut_real(@PathParam("code") String code) {
83 95 logger.error("in_out -" + code);
84   - return ScheduleInOut.getMultiInstance(schRealInfoBuffer.findByParkCode(code));
  96 + return ScheduleInOut.getMultiInstance(schRealDataBuffer.findByParkCode(code));
85 97 }
86 98  
87 99 @GET
... ...
src/main/java/com/bsth/server_rs/schedule/real/thread/ExecSchDataRefreshThread.java 0 → 100644
  1 +package com.bsth.server_rs.schedule.real.thread;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.bsth.server_rs.schedule.real.SchRealDataBuffer;
  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.beans.factory.annotation.Autowired;
  11 +import org.springframework.stereotype.Component;
  12 +
  13 +import java.util.HashMap;
  14 +import java.util.List;
  15 +import java.util.Map;
  16 +
  17 +/**
  18 + * 车辆当前执行班次数据刷新线程
  19 + * Created by panzhao on 2017/11/9.
  20 + */
  21 +@Component
  22 +public class ExecSchDataRefreshThread extends Thread{
  23 +
  24 + static String url;
  25 + static String secretKey;
  26 +
  27 + @Autowired
  28 + SchRealDataBuffer schRealDataBuffer;
  29 + Logger logger = LoggerFactory.getLogger(this.getClass());
  30 +
  31 + static {
  32 + secretKey = ConfigUtil.get("http.control.secret.key");
  33 + url = ConfigUtil.get("http.control.service_data_url") + "/execSchList?secretKey=" + secretKey;
  34 + }
  35 +
  36 + @Override
  37 + public void run() {
  38 + try {
  39 + StringBuilder sb = HttpClientUtils.get(url);
  40 + List<JSONObject> list = JSON.parseArray(sb.toString(), JSONObject.class);
  41 +
  42 + Map<String, JSONObject> map = new HashMap<>();
  43 + for(JSONObject obj : list){
  44 + map.put(obj.getString("clZbh"), obj);
  45 + }
  46 +
  47 + if(map.size() > 0)
  48 + schRealDataBuffer.setExecMap(map);
  49 + } catch (Exception e) {
  50 + logger.error("", e);
  51 + }
  52 + }
  53 +}
... ...
src/main/java/com/bsth/server_rs/schedule/real/thread/SchInOutDataRefreshThread.java
... ... @@ -2,7 +2,7 @@ package com.bsth.server_rs.schedule.real.thread;
2 2  
3 3 import com.alibaba.fastjson.JSON;
4 4 import com.bsth.entity.ScheduleRealInfo;
5   -import com.bsth.server_rs.schedule.real.SchRealInfoBuffer;
  5 +import com.bsth.server_rs.schedule.real.SchRealDataBuffer;
6 6 import com.bsth.util.ConfigUtil;
7 7 import com.bsth.util.HttpClientUtils;
8 8 import org.slf4j.Logger;
... ... @@ -23,7 +23,7 @@ public class SchInOutDataRefreshThread extends Thread {
23 23 static String secretKey;
24 24  
25 25 @Autowired
26   - SchRealInfoBuffer schRealInfoBuffer;
  26 + SchRealDataBuffer schRealDataBuffer;
27 27 Logger logger = LoggerFactory.getLogger(this.getClass());
28 28  
29 29 static {
... ... @@ -38,7 +38,7 @@ public class SchInOutDataRefreshThread extends Thread {
38 38 List<ScheduleRealInfo> list = JSON.parseArray(sb.toString(), ScheduleRealInfo.class);
39 39  
40 40 if(null != list && list.size() > 0){
41   - schRealInfoBuffer.putInOutData(list);
  41 + schRealDataBuffer.putInOutData(list);
42 42 logger.info("从调度系统刷新进出场班次: " + list.size());
43 43 }
44 44 } catch (Exception e) {
... ...