Commit e2a404b66f7ef1924b44d3d54bebb9a63a9bbeb4

Authored by 王通
1 parent 4d626e00

1.临港配置信息改变

src/main/java/com/bsth/server_rs/schedule/real/ScheduleRealService.java
1   -package com.bsth.server_rs.schedule.real;
2   -
3   -import com.alibaba.fastjson.JSON;
4   -import com.alibaba.fastjson.JSONArray;
5   -import com.alibaba.fastjson.JSONObject;
6   -import com.bsth.Application;
7   -import com.bsth.common.BasicData;
8   -import com.bsth.common.ResponseCode;
9   -import com.bsth.entity.ScheduleRealInfo;
10   -import com.bsth.entity.ScheduleRealInfoVo;
11   -import com.bsth.redis.ScheduleRedisService;
12   -import com.bsth.repository.ScheduleRealInfoRepository;
13   -import com.bsth.server_rs.base_info.car.Car;
14   -import com.bsth.server_rs.base_info.car.buffer.CarBufferData;
15   -import com.bsth.server_rs.base_info.line.Line;
16   -import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
17   -import com.bsth.server_rs.schedule.dto.ScheduleCcInfoConfig;
18   -import com.bsth.server_rs.schedule.dto.ScheduleInOut;
19   -import com.bsth.server_rs.schedule.dto.ScheduleRealInfoDTO_JK;
20   -import com.bsth.util.ConfigUtil;
21   -import com.bsth.util.HttpClientUtils;
22   -import com.fasterxml.jackson.core.JsonProcessingException;
23   -import com.fasterxml.jackson.databind.ObjectMapper;
24   -import com.google.common.base.Splitter;
25   -import org.apache.commons.lang3.StringUtils;
26   -import org.apache.kafka.clients.producer.ProducerRecord;
27   -import org.joda.time.DateTime;
28   -import org.joda.time.format.DateTimeFormat;
29   -import org.joda.time.format.DateTimeFormatter;
30   -import org.slf4j.Logger;
31   -import org.slf4j.LoggerFactory;
32   -import org.springframework.beans.BeanUtils;
33   -import org.springframework.beans.factory.InitializingBean;
34   -import org.springframework.beans.factory.annotation.Autowired;
35   -import org.springframework.kafka.core.KafkaTemplate;
36   -import org.springframework.kafka.support.SendResult;
37   -import org.springframework.messaging.Message;
38   -import org.springframework.stereotype.Component;
39   -import org.springframework.util.concurrent.ListenableFuture;
40   -import org.springframework.util.concurrent.ListenableFutureCallback;
41   -
42   -import javax.ws.rs.*;
43   -import javax.ws.rs.core.MediaType;
44   -import java.net.URLEncoder;
45   -import java.util.*;
46   -import java.util.concurrent.*;
47   -
48   -/**
49   - * Created by panzhao on 2017/8/24.
50   - */
51   -@Component
52   -@Path("/schedule_real")
53   -@Produces({MediaType.APPLICATION_JSON})
54   -public class ScheduleRealService implements InitializingBean {
55   -
56   - @Autowired
57   - ScheduleRedisService redisService;
58   -
59   - @Autowired
60   - SchRealDataBuffer schRealDataBuffer;
61   -
62   - @Autowired
63   - private ScheduleRealInfoRepository scheduleRealInfoRepository;
64   -
65   - @Autowired
66   - private KafkaTemplate kafkaTemplate;
67   -
68   - Logger logger = LoggerFactory.getLogger(this.getClass());
69   -
70   - static String url;
71   - static String secretKey;
72   -
73   - private volatile long timestamp;
74   -
75   - private final static int KAFKA_BATCH_SIZE = 100;
76   -
77   - static {
78   - secretKey = ConfigUtil.get("http.control.secret.key");
79   - url = ConfigUtil.get("http.control.service_data_url");// + "/execSchList?secretKey=" + secretKey;
80   - }
81   -
82   - @POST
83   - @Path("tcc_tzrc")
84   - public Map<String, Object> tccTzrc(String jsonStr) {
85   - JSONObject rs = new JSONObject();
86   - try {
87   - StringBuilder sb = HttpClientUtils.post(url + "/tccHrhc?secretKey=" + secretKey, jsonStr);
88   -
89   - rs = JSONObject.parseObject(sb.toString());
90   -
91   - if ("SUCCESS".equals(rs.get("status"))) {
92   - rs.put("list", ScheduleInOut.getMultiInstance(JSONArray.parseArray(rs.getJSONArray("list").toJSONString(), ScheduleRealInfo.class)));
93   - }
94   - } catch (Exception e) {
95   - logger.error("", e);
96   - rs.put("status", ResponseCode.ERROR);
97   - rs.put("msg", "接口服务器出现异常!");
98   - }
99   - return rs;
100   - }
101   -
102   - @POST
103   - @Path("tcc_dftz")
104   - public Map<String, Object> tccDftz(String jsonStr) {
105   - JSONObject rs = new JSONObject();
106   - try {
107   - StringBuilder sb = HttpClientUtils.post(url + "/dftzAndDestroy?secretKey=" + secretKey, jsonStr);
108   -
109   - rs = JSON.parseObject(sb.toString());
110   -
111   - if ("SUCCESS".equals(rs.get("status"))) {
112   - rs.put("t", new ScheduleInOut(JSON.toJavaObject(JSON.parseObject(rs.get("t").toString()), ScheduleRealInfo.class)));
113   - }
114   - //ScheduleInOut.getMultiInstance
115   - } catch (Exception e) {
116   - logger.error("", e);
117   - rs.put("status", ResponseCode.ERROR);
118   - rs.put("msg", "接口服务器出现异常!");
119   - }
120   - return rs;
121   - }
122   -
123   - /**
124   - * 获取路牌下的班次信息
125   - *
126   - * @param lineCode
127   - * @param lpName
128   - * @return
129   - */
130   - @GET
131   - @Path("/findByLpName/{lineCode}/{lpName}")
132   - public List<ScheduleRealInfo> findByLpName(@PathParam("lineCode") String lineCode, @PathParam("lpName") String lpName) {
133   - List<ScheduleRealInfo> list = new ArrayList<>();
134   - try {
135   - if (StringUtils.isEmpty(lineCode) || StringUtils.isEmpty(lpName))
136   - return list;
137   -
138   - lpName = URLEncoder.encode(lpName, "UTF-8");
139   - StringBuilder sb = HttpClientUtils.get(url + "/findByLpName?secretKey=" + secretKey + "&lineCode=" + lineCode + "&lpName=" + lpName);
140   - list = JSON.parseArray(sb.toString(), ScheduleRealInfo.class);
141   - } catch (Exception e) {
142   - logger.error("", e);
143   - }
144   - return list;
145   - }
146   -
147   - /**
148   - * 获取当天指定停车场的进出场排班数据
149   - *
150   - * @return
151   - */
152   - @GET
153   - @Path("/in_out/{code}")
154   - public List<ScheduleInOut> findInOut(@PathParam("code") String code) {
155   - Set<String> lineArray = BasicData.lineDateMap.keySet();
156   -
157   - List<ScheduleInOut> all = new ArrayList<>();
158   - for (String lineCode : lineArray) {
159   - all.addAll(ScheduleInOut.getMultiInstance(redisService.read(BasicData.lineDateMap.get(lineCode), lineCode), code));
160   - }
161   - return all;
162   - }
163   -
164   - /**
165   - * 获取指定日期,指定公司的人员车辆配置情况(实际排班)
166   - *
167   - * @param company
168   - * @param rq
169   - * @return
170   - */
171   - @GET
172   - @Path("/ccConfig/{company}/{rq}")
173   - public List<ScheduleCcInfoConfig> ccInfoConfig(@PathParam("company") String company, @PathParam("rq") String rq) {
174   - List<Line> lines = LineBufferData.findByCompany(company);
175   -
176   - List<ScheduleCcInfoConfig> all = new ArrayList<>();
177   - for (Line line : lines) {
178   - all.addAll(ScheduleCcInfoConfig.getMultiInstance(redisService.read(rq, line.getLineCode())));
179   - }
180   - return all;
181   - }
182   -
183   - /**
184   - * 根据车辆自编号获取对应执行的班次信息
185   - *
186   - * @param nbbm
187   - * @return
188   - */
189   - @GET
190   - @Path("/exec/{nbbm}")
191   - public JSONObject getExecPlan(@PathParam("nbbm") String nbbm) {
192   - return schRealDataBuffer.getExecPlan(nbbm);
193   - }
194   -
195   - /**
196   - * 获取全部的 车辆 和班次对照信息
197   - *
198   - * @param
199   - * @return
200   - */
201   - @GET
202   - @Path("/execs")
203   - public Collection<JSONObject> execs(){
204   - return schRealDataBuffer.execs();
205   - }
206   -
207   - /**
208   - * 获取当天指定停车场的进出场排班数据(潘钊场站VIP特供版 -高实时)
209   - *
210   - * @return
211   - */
212   - @GET
213   - @Path("/in_out/pz_vip/{code}")
214   - public List<ScheduleInOut> findInOut_real(@PathParam("code") String code) {
215   - logger.info("in_out -" + code);
216   - return ScheduleInOut.getMultiInstance(schRealDataBuffer.findByParkCode(code));
217   - }
218   -
219   - @GET
220   - @Path("/sch_jk/{company}/{rq}")
221   - public List<ScheduleRealInfoDTO_JK> find_JK(@PathParam("company") String company, @PathParam("rq") String rq) {
222   - List<ScheduleRealInfoDTO_JK> all = new ArrayList<>();
223   -
224   - List<Line> lines = LineBufferData.findByCompany(company);
225   - for (Line line : lines) {
226   - all.addAll(ScheduleRealInfoDTO_JK.getMultiInstance(redisService.read(rq, line.getLineCode())));
227   - }
228   - return all;
229   - }
230   -
231   - @GET
232   - @Path("/sch_jk_db/{company}/{rq}")
233   - public List<ScheduleRealInfoDTO_JK> sch_jk(@PathParam("company") String company, @PathParam("rq") String rq) {
234   - DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd");
235   - DateTime dateTime = fmt.parseDateTime(rq);
236   - List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.findByDateAndCompany(dateTime.toString("yyyy-MM-dd"), company);
237   - redisService.calcTime(scheduleRealInfos);
238   - List<ScheduleRealInfoDTO_JK> result = ScheduleRealInfoDTO_JK.getMultiInstance(scheduleRealInfos);
239   -
240   - return result;
241   - }
242   -
243   - @GET
244   - @Path("/sch_jk4modify/{company}/{rq}/{timestamp}")
245   - public List<ScheduleRealInfoDTO_JK> sch_jk4modify(@PathParam("company") String company, @PathParam("rq") String rq, @PathParam("timestamp") long timestamp) {
246   - DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd");
247   - DateTime dateTime = fmt.parseDateTime(rq);
248   - List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.findByDateAndCompany(dateTime.toString("yyyy-MM-dd"), company, new Date(timestamp));
249   - redisService.calcTime(scheduleRealInfos);
250   - List<ScheduleRealInfoDTO_JK> result = ScheduleRealInfoDTO_JK.getMultiInstance(scheduleRealInfos);
251   -
252   - return result;
253   - }
254   -
255   - /**
256   - * 读取指定日期的redis 数据,计算程序调用
257   - *
258   - * @param rqs
259   - * @return
260   - */
261   - @GET
262   - @Path("/pz_vip/read/{rqs}")
263   - public List<ScheduleRealInfo> read(@PathParam("rqs") String rqs) {
264   - List<ScheduleRealInfo> all = new ArrayList<>(), rs = new ArrayList<>();
265   - List<Line> lines = LineBufferData.findAll();
266   - List<String> rqArray = Splitter.on(",").splitToList(rqs);
267   -
268   - for (Line line : lines) {
269   - for (String rq : rqArray)
270   - all.addAll(redisService.read(rq, line.getLineCode()));
271   - }
272   -
273   - for (ScheduleRealInfo sch : all) {
274   - if (sch.getBcType().equals("in") || sch.getBcType().equals("out") || sch.getBcType().equals("ldks"))
275   - continue;
276   -
277   - //烂班,临加,有子任务的
278   - if (sch.getStatus() == -1 || sch.isSflj() || (sch.getcTasks() != null && sch.getcTasks().size() > 0))
279   - rs.add(sch);
280   - }
281   - return rs;
282   - }
283   -
284   - /**
285   - * 读取指定日期线路的redis 数据,计算程序调用
286   - *
287   - * @param rq
288   - * @return
289   - */
290   - @GET
291   - @Path("/pz_vip/readByRqAndLine/{rq}/{lineCode}")
292   - public List<ScheduleRealInfo> readByLine(@PathParam("rq") String rq, @PathParam("lineCode") String lineCode) {
293   - List<ScheduleRealInfo> all = redisService.read(rq, lineCode), rs = new ArrayList<>();
294   -
295   - for (ScheduleRealInfo sch : all) {
296   - if (sch.getBcType().equals("in") || sch.getBcType().equals("out") || sch.getBcType().equals("ldks"))
297   - continue;
298   -
299   - //烂班,临加,有子任务的
300   - if (sch.getStatus() == -1 || sch.isSflj() || (sch.getcTasks() != null && sch.getcTasks().size() > 0))
301   - rs.add(sch);
302   - }
303   - return rs;
304   - }
305   -
306   - @Override
307   - public void afterPropertiesSet() throws Exception {
308   - Application.mainServices.scheduleWithFixedDelay(new Runnable() {
309   - @Override
310   - public void run() {
311   - try {
312   - DateTime dateTime = DateTime.now(), preDate = dateTime.minusDays(1);
313   - List<String> dates = new ArrayList<>();
314   - dates.add(dateTime.toString("yyyy-MM-dd"));
315   - dates.add(preDate.toString("yyyy-MM-dd"));
316   - if (timestamp == 0) {
317   - timestamp = dateTime.minusHours(1).getMillis();
318   - }
319   - List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.findByDates(dates, new Date(timestamp));
320   - timestamp = dateTime.getMillis();
321   -
322   - Queue<ScheduleRealInfoVo> queue = new ConcurrentLinkedDeque<>();
323   - for (ScheduleRealInfo sch : scheduleRealInfos) {
324   - ScheduleRealInfoVo scheduleRealInfoVo = new ScheduleRealInfoVo();
325   - BeanUtils.copyProperties(sch, scheduleRealInfoVo);
326   - Car car = CarBufferData.findOne(scheduleRealInfoVo.getClZbh());
327   - scheduleRealInfoVo.setCarPlate(car == null ? "" : car.getCarPlate());
328   - queue.add(scheduleRealInfoVo);
329   - }
330   -
331   - int size = scheduleRealInfos.size();
332   - for (int i = 0, len = size % KAFKA_BATCH_SIZE == 0 ? size / KAFKA_BATCH_SIZE : size / KAFKA_BATCH_SIZE + 1;i < len;i++) {
333   - List<ScheduleRealInfoVo> scheduleRealInfoVos = new ArrayList<>();
334   - for (int j = 0; j < KAFKA_BATCH_SIZE;j++) {
335   - ScheduleRealInfoVo scheduleRealInfoVo = queue.poll();
336   - if (scheduleRealInfoVo == null) {
337   - break;
338   - }
339   - scheduleRealInfoVos.add(scheduleRealInfoVo);
340   - }
341   -
342   - Map<String, Object> data = new HashMap<>();
343   - data.put("datatype", "waybill");
344   - data.put("datas", scheduleRealInfoVos);
345   -
346   - ObjectMapper mapper = new ObjectMapper();
347   - String json = mapper.writeValueAsString(data);
348   - logger.info(json);
349   - ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send("PDGJ_JQDD", json);
350   - future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
351   -
352   - @Override
353   - public void onSuccess(SendResult<String, String> result) {
354   -
355   - }
356   -
357   - @Override
358   - public void onFailure(Throwable ex) {
359   - logger.error("kafka发送电子路单异常", ex);
360   - }
361   - });
362   - }
363   - } catch (Exception e) {
364   - logger.error("kafka发电子路单调度异常", e);
365   - }
366   - }
367   - }, 30, 240, TimeUnit.SECONDS);
368   - }
369   -}
  1 +package com.bsth.server_rs.schedule.real;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONArray;
  5 +import com.alibaba.fastjson.JSONObject;
  6 +import com.bsth.Application;
  7 +import com.bsth.common.BasicData;
  8 +import com.bsth.common.ResponseCode;
  9 +import com.bsth.entity.ScheduleRealInfo;
  10 +import com.bsth.entity.ScheduleRealInfoVo;
  11 +import com.bsth.redis.ScheduleRedisService;
  12 +import com.bsth.repository.ScheduleRealInfoRepository;
  13 +import com.bsth.server_rs.base_info.car.Car;
  14 +import com.bsth.server_rs.base_info.car.buffer.CarBufferData;
  15 +import com.bsth.server_rs.base_info.line.Line;
  16 +import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
  17 +import com.bsth.server_rs.schedule.dto.ScheduleCcInfoConfig;
  18 +import com.bsth.server_rs.schedule.dto.ScheduleInOut;
  19 +import com.bsth.server_rs.schedule.dto.ScheduleRealInfoDTO_JK;
  20 +import com.bsth.util.ConfigUtil;
  21 +import com.bsth.util.HttpClientUtils;
  22 +import com.fasterxml.jackson.core.JsonProcessingException;
  23 +import com.fasterxml.jackson.databind.ObjectMapper;
  24 +import com.google.common.base.Splitter;
  25 +import org.apache.commons.lang3.StringUtils;
  26 +import org.apache.kafka.clients.producer.ProducerRecord;
  27 +import org.joda.time.DateTime;
  28 +import org.joda.time.format.DateTimeFormat;
  29 +import org.joda.time.format.DateTimeFormatter;
  30 +import org.slf4j.Logger;
  31 +import org.slf4j.LoggerFactory;
  32 +import org.springframework.beans.BeanUtils;
  33 +import org.springframework.beans.factory.InitializingBean;
  34 +import org.springframework.beans.factory.annotation.Autowired;
  35 +import org.springframework.kafka.core.KafkaTemplate;
  36 +import org.springframework.kafka.support.SendResult;
  37 +import org.springframework.messaging.Message;
  38 +import org.springframework.stereotype.Component;
  39 +import org.springframework.util.concurrent.ListenableFuture;
  40 +import org.springframework.util.concurrent.ListenableFutureCallback;
  41 +
  42 +import javax.ws.rs.*;
  43 +import javax.ws.rs.core.MediaType;
  44 +import java.net.URLEncoder;
  45 +import java.util.*;
  46 +import java.util.concurrent.*;
  47 +
  48 +/**
  49 + * Created by panzhao on 2017/8/24.
  50 + */
  51 +@Component
  52 +@Path("/schedule_real")
  53 +@Produces({MediaType.APPLICATION_JSON})
  54 +public class ScheduleRealService implements InitializingBean {
  55 +
  56 + @Autowired
  57 + ScheduleRedisService redisService;
  58 +
  59 + @Autowired
  60 + SchRealDataBuffer schRealDataBuffer;
  61 +
  62 + @Autowired
  63 + private ScheduleRealInfoRepository scheduleRealInfoRepository;
  64 +
  65 + @Autowired
  66 + private KafkaTemplate kafkaTemplate;
  67 +
  68 + Logger logger = LoggerFactory.getLogger(this.getClass());
  69 +
  70 + static String url;
  71 + static String secretKey;
  72 +
  73 + private volatile long timestamp;
  74 +
  75 + private final static int KAFKA_BATCH_SIZE = 100;
  76 +
  77 + static {
  78 + secretKey = ConfigUtil.get("http.control.secret.key");
  79 + url = ConfigUtil.get("http.control.service_data_url");// + "/execSchList?secretKey=" + secretKey;
  80 + }
  81 +
  82 + @POST
  83 + @Path("tcc_tzrc")
  84 + public Map<String, Object> tccTzrc(String jsonStr) {
  85 + JSONObject rs = new JSONObject();
  86 + try {
  87 + StringBuilder sb = HttpClientUtils.post(url + "/tccHrhc?secretKey=" + secretKey, jsonStr);
  88 +
  89 + rs = JSONObject.parseObject(sb.toString());
  90 +
  91 + if ("SUCCESS".equals(rs.get("status"))) {
  92 + rs.put("list", ScheduleInOut.getMultiInstance(JSONArray.parseArray(rs.getJSONArray("list").toJSONString(), ScheduleRealInfo.class)));
  93 + }
  94 + } catch (Exception e) {
  95 + logger.error("", e);
  96 + rs.put("status", ResponseCode.ERROR);
  97 + rs.put("msg", "接口服务器出现异常!");
  98 + }
  99 + return rs;
  100 + }
  101 +
  102 + @POST
  103 + @Path("tcc_dftz")
  104 + public Map<String, Object> tccDftz(String jsonStr) {
  105 + JSONObject rs = new JSONObject();
  106 + try {
  107 + StringBuilder sb = HttpClientUtils.post(url + "/dftzAndDestroy?secretKey=" + secretKey, jsonStr);
  108 +
  109 + rs = JSON.parseObject(sb.toString());
  110 +
  111 + if ("SUCCESS".equals(rs.get("status"))) {
  112 + rs.put("t", new ScheduleInOut(JSON.toJavaObject(JSON.parseObject(rs.get("t").toString()), ScheduleRealInfo.class)));
  113 + }
  114 + //ScheduleInOut.getMultiInstance
  115 + } catch (Exception e) {
  116 + logger.error("", e);
  117 + rs.put("status", ResponseCode.ERROR);
  118 + rs.put("msg", "接口服务器出现异常!");
  119 + }
  120 + return rs;
  121 + }
  122 +
  123 + /**
  124 + * 获取路牌下的班次信息
  125 + *
  126 + * @param lineCode
  127 + * @param lpName
  128 + * @return
  129 + */
  130 + @GET
  131 + @Path("/findByLpName/{lineCode}/{lpName}")
  132 + public List<ScheduleRealInfo> findByLpName(@PathParam("lineCode") String lineCode, @PathParam("lpName") String lpName) {
  133 + List<ScheduleRealInfo> list = new ArrayList<>();
  134 + try {
  135 + if (StringUtils.isEmpty(lineCode) || StringUtils.isEmpty(lpName))
  136 + return list;
  137 +
  138 + lpName = URLEncoder.encode(lpName, "UTF-8");
  139 + StringBuilder sb = HttpClientUtils.get(url + "/findByLpName?secretKey=" + secretKey + "&lineCode=" + lineCode + "&lpName=" + lpName);
  140 + list = JSON.parseArray(sb.toString(), ScheduleRealInfo.class);
  141 + } catch (Exception e) {
  142 + logger.error("", e);
  143 + }
  144 + return list;
  145 + }
  146 +
  147 + /**
  148 + * 获取当天指定停车场的进出场排班数据
  149 + *
  150 + * @return
  151 + */
  152 + @GET
  153 + @Path("/in_out/{code}")
  154 + public List<ScheduleInOut> findInOut(@PathParam("code") String code) {
  155 + Set<String> lineArray = BasicData.lineDateMap.keySet();
  156 +
  157 + List<ScheduleInOut> all = new ArrayList<>();
  158 + for (String lineCode : lineArray) {
  159 + all.addAll(ScheduleInOut.getMultiInstance(redisService.read(BasicData.lineDateMap.get(lineCode), lineCode), code));
  160 + }
  161 + return all;
  162 + }
  163 +
  164 + /**
  165 + * 获取指定日期,指定公司的人员车辆配置情况(实际排班)
  166 + *
  167 + * @param company
  168 + * @param rq
  169 + * @return
  170 + */
  171 + @GET
  172 + @Path("/ccConfig/{company}/{rq}")
  173 + public List<ScheduleCcInfoConfig> ccInfoConfig(@PathParam("company") String company, @PathParam("rq") String rq) {
  174 + List<Line> lines = LineBufferData.findByCompany(company);
  175 +
  176 + List<ScheduleCcInfoConfig> all = new ArrayList<>();
  177 + for (Line line : lines) {
  178 + all.addAll(ScheduleCcInfoConfig.getMultiInstance(redisService.read(rq, line.getLineCode())));
  179 + }
  180 + return all;
  181 + }
  182 +
  183 + /**
  184 + * 根据车辆自编号获取对应执行的班次信息
  185 + *
  186 + * @param nbbm
  187 + * @return
  188 + */
  189 + @GET
  190 + @Path("/exec/{nbbm}")
  191 + public JSONObject getExecPlan(@PathParam("nbbm") String nbbm) {
  192 + return schRealDataBuffer.getExecPlan(nbbm);
  193 + }
  194 +
  195 + /**
  196 + * 获取全部的 车辆 和班次对照信息
  197 + *
  198 + * @param
  199 + * @return
  200 + */
  201 + @GET
  202 + @Path("/execs")
  203 + public Collection<JSONObject> execs(){
  204 + return schRealDataBuffer.execs();
  205 + }
  206 +
  207 + /**
  208 + * 获取当天指定停车场的进出场排班数据(潘钊场站VIP特供版 -高实时)
  209 + *
  210 + * @return
  211 + */
  212 + @GET
  213 + @Path("/in_out/pz_vip/{code}")
  214 + public List<ScheduleInOut> findInOut_real(@PathParam("code") String code) {
  215 + logger.info("in_out -" + code);
  216 + return ScheduleInOut.getMultiInstance(schRealDataBuffer.findByParkCode(code));
  217 + }
  218 +
  219 + @GET
  220 + @Path("/sch_jk/{company}/{rq}")
  221 + public List<ScheduleRealInfoDTO_JK> find_JK(@PathParam("company") String company, @PathParam("rq") String rq) {
  222 + List<ScheduleRealInfoDTO_JK> all = new ArrayList<>();
  223 +
  224 + List<Line> lines = LineBufferData.findByCompany(company);
  225 + for (Line line : lines) {
  226 + all.addAll(ScheduleRealInfoDTO_JK.getMultiInstance(redisService.read(rq, line.getLineCode())));
  227 + }
  228 + return all;
  229 + }
  230 +
  231 + @GET
  232 + @Path("/sch_jk_db/{company}/{rq}")
  233 + public List<ScheduleRealInfoDTO_JK> sch_jk(@PathParam("company") String company, @PathParam("rq") String rq) {
  234 + DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd");
  235 + DateTime dateTime = fmt.parseDateTime(rq);
  236 + List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.findByDateAndCompany(dateTime.toString("yyyy-MM-dd"), company);
  237 + redisService.calcTime(scheduleRealInfos);
  238 + List<ScheduleRealInfoDTO_JK> result = ScheduleRealInfoDTO_JK.getMultiInstance(scheduleRealInfos);
  239 +
  240 + return result;
  241 + }
  242 +
  243 + @GET
  244 + @Path("/sch_jk4modify/{company}/{rq}/{timestamp}")
  245 + public List<ScheduleRealInfoDTO_JK> sch_jk4modify(@PathParam("company") String company, @PathParam("rq") String rq, @PathParam("timestamp") long timestamp) {
  246 + DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd");
  247 + DateTime dateTime = fmt.parseDateTime(rq);
  248 + List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.findByDateAndCompany(dateTime.toString("yyyy-MM-dd"), company, new Date(timestamp));
  249 + redisService.calcTime(scheduleRealInfos);
  250 + List<ScheduleRealInfoDTO_JK> result = ScheduleRealInfoDTO_JK.getMultiInstance(scheduleRealInfos);
  251 +
  252 + return result;
  253 + }
  254 +
  255 + /**
  256 + * 读取指定日期的redis 数据,计算程序调用
  257 + *
  258 + * @param rqs
  259 + * @return
  260 + */
  261 + @GET
  262 + @Path("/pz_vip/read/{rqs}")
  263 + public List<ScheduleRealInfo> read(@PathParam("rqs") String rqs) {
  264 + List<ScheduleRealInfo> all = new ArrayList<>(), rs = new ArrayList<>();
  265 + List<Line> lines = LineBufferData.findAll();
  266 + List<String> rqArray = Splitter.on(",").splitToList(rqs);
  267 +
  268 + for (Line line : lines) {
  269 + for (String rq : rqArray)
  270 + all.addAll(redisService.read(rq, line.getLineCode()));
  271 + }
  272 +
  273 + for (ScheduleRealInfo sch : all) {
  274 + if (sch.getBcType().equals("in") || sch.getBcType().equals("out") || sch.getBcType().equals("ldks"))
  275 + continue;
  276 +
  277 + //烂班,临加,有子任务的
  278 + if (sch.getStatus() == -1 || sch.isSflj() || (sch.getcTasks() != null && sch.getcTasks().size() > 0))
  279 + rs.add(sch);
  280 + }
  281 + return rs;
  282 + }
  283 +
  284 + /**
  285 + * 读取指定日期线路的redis 数据,计算程序调用
  286 + *
  287 + * @param rq
  288 + * @return
  289 + */
  290 + @GET
  291 + @Path("/pz_vip/readByRqAndLine/{rq}/{lineCode}")
  292 + public List<ScheduleRealInfo> readByLine(@PathParam("rq") String rq, @PathParam("lineCode") String lineCode) {
  293 + List<ScheduleRealInfo> all = redisService.read(rq, lineCode), rs = new ArrayList<>();
  294 +
  295 + for (ScheduleRealInfo sch : all) {
  296 + if (sch.getBcType().equals("in") || sch.getBcType().equals("out") || sch.getBcType().equals("ldks"))
  297 + continue;
  298 +
  299 + //烂班,临加,有子任务的
  300 + if (sch.getStatus() == -1 || sch.isSflj() || (sch.getcTasks() != null && sch.getcTasks().size() > 0))
  301 + rs.add(sch);
  302 + }
  303 + return rs;
  304 + }
  305 +
  306 + @Override
  307 + public void afterPropertiesSet() throws Exception {
  308 + /*Application.mainServices.scheduleWithFixedDelay(new Runnable() {
  309 + @Override
  310 + public void run() {
  311 + try {
  312 + DateTime dateTime = DateTime.now(), preDate = dateTime.minusDays(1);
  313 + List<String> dates = new ArrayList<>();
  314 + dates.add(dateTime.toString("yyyy-MM-dd"));
  315 + dates.add(preDate.toString("yyyy-MM-dd"));
  316 + if (timestamp == 0) {
  317 + timestamp = dateTime.minusHours(1).getMillis();
  318 + }
  319 + List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.findByDates(dates, new Date(timestamp));
  320 + timestamp = dateTime.getMillis();
  321 +
  322 + Queue<ScheduleRealInfoVo> queue = new ConcurrentLinkedDeque<>();
  323 + for (ScheduleRealInfo sch : scheduleRealInfos) {
  324 + ScheduleRealInfoVo scheduleRealInfoVo = new ScheduleRealInfoVo();
  325 + BeanUtils.copyProperties(sch, scheduleRealInfoVo);
  326 + Car car = CarBufferData.findOne(scheduleRealInfoVo.getClZbh());
  327 + scheduleRealInfoVo.setCarPlate(car == null ? "" : car.getCarPlate());
  328 + queue.add(scheduleRealInfoVo);
  329 + }
  330 +
  331 + int size = scheduleRealInfos.size();
  332 + for (int i = 0, len = size % KAFKA_BATCH_SIZE == 0 ? size / KAFKA_BATCH_SIZE : size / KAFKA_BATCH_SIZE + 1;i < len;i++) {
  333 + List<ScheduleRealInfoVo> scheduleRealInfoVos = new ArrayList<>();
  334 + for (int j = 0; j < KAFKA_BATCH_SIZE;j++) {
  335 + ScheduleRealInfoVo scheduleRealInfoVo = queue.poll();
  336 + if (scheduleRealInfoVo == null) {
  337 + break;
  338 + }
  339 + scheduleRealInfoVos.add(scheduleRealInfoVo);
  340 + }
  341 +
  342 + Map<String, Object> data = new HashMap<>();
  343 + data.put("datatype", "waybill");
  344 + data.put("datas", scheduleRealInfoVos);
  345 +
  346 + ObjectMapper mapper = new ObjectMapper();
  347 + String json = mapper.writeValueAsString(data);
  348 + logger.info(json);
  349 + ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send("PDGJ_JQDD", json);
  350 + future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
  351 +
  352 + @Override
  353 + public void onSuccess(SendResult<String, String> result) {
  354 +
  355 + }
  356 +
  357 + @Override
  358 + public void onFailure(Throwable ex) {
  359 + logger.error("kafka发送电子路单异常", ex);
  360 + }
  361 + });
  362 + }
  363 + } catch (Exception e) {
  364 + logger.error("kafka发电子路单调度异常", e);
  365 + }
  366 + }
  367 + }, 30, 240, TimeUnit.SECONDS);*/
  368 + }
  369 +}
... ...