Commit 4acffd9ae3d4619d81a2c0c1053508ce00bbd059

Authored by 王通
1 parent 4d12176a

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