AutomaticSch.java
17.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
package com.bsth.data.zndd;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bsth.data.BasicData;
import com.bsth.data.adjg.domain.LargeGap;
import com.bsth.data.directive.DayOfDirectives;
import com.bsth.data.gpsdata_v2.GpsRealData;
import com.bsth.data.gpsdata_v2.entity.GpsEntity;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.data.schedule.ScheduleComparator;
import com.bsth.data.schedule.late_adjust.LateAdjustHandle;
import com.bsth.entity.StationRoute;
import com.bsth.entity.directive.D60;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.repository.StationRouteRepository;
import com.bsth.service.directive.DirectiveService;
import com.bsth.service.realcontrol.ScheduleRealInfoService;
import com.bsth.util.HttpClientUtils;
import com.google.gson.Gson;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* 自动检测调度异常
*/
@Component
public class AutomaticSch {
Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
GpsRealData gpsRealData;
@Autowired
DayOfSchedule dayOfSchedule;
@Autowired
DayOfDirectives dayOfDirectives;
@Autowired
ScheduleRealInfoService scheduleRealInfoService;
@Autowired
DirectiveService directiveService;
@Autowired
StationRouteRepository stationRouteRepository;
@Autowired
OutEntrance outEntrance;
@Autowired
carMonitor carMonitor;
@Autowired
BasicData basicData;
private static SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
private static Comparator<ScheduleRealInfo> cpm = new ScheduleComparator.DFSJ2();
private Map<String,Long> drivreMap =new HashMap<>(); //自动重发map
// 当日60指令缓存
private ConcurrentMap<Integer, D60> d60Map = new ConcurrentHashMap<>();//d60map
String urldkl = "http://10.10.200.202:5580/monitor/api/getMonitorInfoByDay?key=1&solt=1111&t=1&dayStr=2024-07-23"; //大间隔接口
//http://10.10.200.201:8083/wxk-prod-api/service-api/lggj/schedule/drByInfo 维修接口
private Map<String,Long> SFMAP = new HashMap<>();
//满载
public void mz(){
try {
ScheduleRealInfo sr = dayOfSchedule.executeCurr("S0R-054");
ts(addStationPeople(sr, "MZ", 0L));//第二种 设备未离线 出站时间内未出站
}
catch (Exception e){
logger.error("满载------------------",e);
}
}
//大间隔的情况
public void dfTz(){
try{
StringBuilder sb = HttpClientUtils.get(urldkl /*+ sdfMonth.format(new Date())*/);
if (sb == null)
return;
JSONObject obj = JSON.parseObject(sb.toString());
List<LargeGap> lgs = JSON.parseArray(obj.getString("largeGap"), LargeGap.class);
Long its = 0l;
//数据转换 并推送
for (LargeGap lg : lgs){
if(dayOfSchedule.executeCurr(lg.getNbbm()) != null){
its= dayOfSchedule.executeCurr(lg.getNbbm()).getId();
}else {
continue;
}
ts(ConvertDJK(lg,its.toString()));
}
}catch (Exception e){
logger.error("大间隔推送失败------------------",e);
}
}
//撤销班次 检测人员或者车辆故障 --//换人换车或烂班 //路牌对调
public void cxJC(){
}
//撤销撤销班次 检测人员或者车辆故障 --//换人换车或烂班 //路牌对调
public void cxJCX(){
}
//实发未发检测 -- 车辆GPS掉线的情况下,车辆该出站了
/**
* 1。已过待发时间还没发车的
* 2.设备离线
* --上一班次还没有抵达终点不做操作
*/
public void sftz(){
logger.warn("实发未发扫描开始");
try {
//获取所有线路
Map<String, String> lineMap = BasicData.lineCode2NameMap;
for (Map.Entry<String, String> t : lineMap.entrySet()){
List<ScheduleRealInfo> srList = dayOfSchedule.findByLineCode(t.getKey());
for (ScheduleRealInfo sr : srList){
//1.离线 2.实发时间为空 3.已过待发时间还没发车的
long time = System.currentTimeMillis();//实际时间+2分钟
//超过待发时间 实发时间还是null的
if (sr.getFcsjT()+ (1000 * 60 * 3) < time && sr.getFcsjT()+ (1000 * 60 * 7) > time) {
//起点站实际到达时间为null的情况下
/* if (StringUtils.isEmpty(sr.getQdzArrDatesj())) {
ScheduleRealInfo prev = dayOfSchedule.prev(sr);
//上一个班次没有实际终点到达时间
if (prev != null && StringUtils.isEmpty(prev.getZdsjActual())) {
continue;
}
}*/
//第一种 设备离线的情况下改出站
Integer staus = 0; //状态
if (StringUtils.isEmpty(sr.getFcsjActual())
&& (sr.getBcType().equals("normal") || sr.getBcType().equals("region"))
&& (StringUtils.isEmpty(sr.getRemarks()) || sr.getRemarks().equals("_智能调度-异常实发"))) {
GpsEntity gps = gpsRealData.getByNbbm(sr.getClZbh());
//当前设备离线的情况
//1。一直没收到gps
//2.gps长时间离线的情况下
//3.人为调整过的都跳过
if (gps == null || gps.getTimestamp() + (1000 * 60 * 3) < time || (gps.getAbnormalStatus() != null && gps.getAbnormalStatus().equals("offline"))){
ts(addStationPeople(sr, "SFTZ_1", 0L));
Gson gson = new Gson();
String chartStr = gson.toJsonTree(sr).toString();
logger.info("实发调整--"+chartStr);
}
}
}
}
}
}catch (Exception e){
logger.error("自动调度,实发未发推送失败---",e);
}
logger.warn("实发未发扫描结束");
}
//实发撤销检测 -- 出现快一慢三的情况 && 指令重发
public void sfCX(){
//查询所有班次
//remark 人工干预过的的不检测
try {
stationRouteRepository.findAll();
Iterator<StationRoute> iterator = stationRouteRepository.findAll().iterator();
// Map<String, String> stationCode2Name = new HashMap<>();
// StationRoute sroute;
// while (iterator.hasNext()) {
// sroute = iterator.next();
// stationCode2Name.put(sroute.getLineCode() + "_" + sroute.getDirections() + "_" + sroute.getStationCode(), sroute.getStationMark());
// }
//
Map<String, String> lineMap = BasicData.lineCode2NameMap;
List<ScheduleRealInfo> oldSchDateList;
String lineCode;
for (Map.Entry<String, String> ts : lineMap.entrySet()){
lineCode =ts.getKey();
oldSchDateList = dayOfSchedule.findByLineCode(lineCode);
Map m = new HashMap();
//排序
Collections.sort(oldSchDateList, new ScheduleComparator.FCSJ());
for (ScheduleRealInfo t : oldSchDateList){
// 发车误点
if (t.getDfsj() != null && t.getFcsjActual() != null
&& (t.getBcType().equals("normal") || t.getBcType().equals("region"))
&& (StringUtils.isEmpty(t.getRemarks()) || t.getRemarks().equals("_智能调度-异常实发"))) {
long sjc = t.getFcsjActualTime() - t.getDfsjT();
long time = System.currentTimeMillis();//当前时间
if (t.getDfsjT() > time) {
//快1慢3
if (sjc >= -1 * 60 * 1000 && sjc <= 3 * 60 * 1000) {
continue;
} else {
//异常实发
ts(addStationPeople(t, "YCSF", 0l));
Gson gson = new Gson();
String chartStr = gson.toJsonTree(t).toString();
logger.info("实发撤销--" + chartStr);
}
}
/* //待发时间要大于当前时间
//车辆还在站内
String mark = null;
if (gps != null){
mark = stationCode2Name.get(gps.getLineId()+"_"+gps.getUpDown()+"_"+gps.getStopNo());
}
if (t.getFcsjT() > time && ((gps!= null && gps.getInstation() == 2)
|| gps == null ||
(gps!= null && mark!=null && mark.equals("B") && gps.getInstation() == 1) ||
(gps!= null && mark!=null && mark.equals("E") && gps.getInstation() == 1))) {
}*/
}
}
}
}catch (Exception e){
logger.error("实发撤销推送接口出错-----------",e);
}
}
//发车信息微调检测 -- 车辆掉线后实发检测,重新计算时间发车时间
public void updatesf(){
}
//临加班次 -- 检测到大客流 //走落地屏客流接口
public void ljbc(){
}
/**
* 指令重发 -- 芦潮港1路
* 指令下发后设备未响应后 5分钟后重新发送一次 还未响应的话 未来一小时不自动发送该设备
*/
public void drivresponse(){
logger.warn("指令重发扫描开始");
try {
Map<String,Object> tempmap =new HashMap<>();
//所有缓存指令
Collection<D60> dptArray = dayOfDirectives.all60();
Map<String, String> lineMap = BasicData.lineCode2NameMap;
List<ScheduleRealInfo> oldSchDateList;
String lineCode;
for (Map.Entry<String, String> ts : lineMap.entrySet()) {
lineCode = ts.getKey();
/* if (!lineCode.equals("12101"))
return;*/
oldSchDateList = dayOfSchedule.findByLineCode(lineCode);
for (ScheduleRealInfo t : oldSchDateList){
//指令重发
//1.班次已经执行过的
//2.驾驶员未确认的
//3.
Long t1 = 1000L * 60 * 5;
Long sj = new Date().getTime();
if(t.getStatus() == 2 && t.getDirectiveState() != 200 && t.getBcType().equals("normal")){
//还未下发的
if (drivreMap.get(t.getClZbh()) == null){
//下发或者处置
drivreMap.put(t.getClZbh(),new Date().getTime());
directiveService.send60DispatchZndd(t.getId(), "智能调度");
//下发实际超过5分钟的
} else if (drivreMap.get(t.getClZbh()) + t1 <= sj){
directiveService.send60DispatchZndd(t.getId(), "智能调度");
//更新下发时间
drivreMap.put(t.getClZbh(),new Date().getTime());
//下发时间未超过5分钟返回
}
}
}
}
}catch (Exception e){
logger.error("自动调度,指令重发---",e);
}
logger.warn("指令重发扫描结束");
}
//误点检测 调度有的-LateAdjustHandle
public Map wd(){
//推送
try{
List<ScheduleRealInfo> all = new ArrayList<>(dayOfSchedule.findAll());
Collections.sort(all, cpm);
long t = System.currentTimeMillis();
int size = all.size();
ScheduleRealInfo sch;
for(int i = 0; i < size; i ++){
sch = all.get(i);
if(sch.getDfsjT() > t)
break;
/*if(sch.isLate())
continue;*/
if(sch.getStatus() == 0
&& StringUtils.isEmpty(sch.getFcsjActual())){
//检查应发未到 当前班次无起点到达时间
if(StringUtils.isEmpty(sch.getQdzArrDatesj())){
ScheduleRealInfo prev = dayOfSchedule.prev(sch);
//上一个班次也没有实际终点到达时间
if(prev != null && StringUtils.isEmpty(prev.getZdsjActual())){
//进入误点调整程序
LateAdjustHandle.putLate(sch);
List<Map> dzList = carMonitor.carMonitor(prev.getXlBm(), prev.getXlDir(), prev.getZdzCode()); //信息发布接口
for (Map m : dzList){
if (basicData.nbbmCompanyPlateMap.get(prev.getClZbh()) != null && m.get("terminal").equals(basicData.nbbmCompanyPlateMap.get(prev.getClZbh()).replaceAll("-",""))){
sch.setRemark(m.get("sj").toString());
Gson gson = new Gson();
String chartStr = gson.toJsonTree(sch).toString();
logger.info("误点--"+chartStr);
ts(addStationPeople(sch, "WD", 0L));
}
}
}
};
}
}
}catch (Exception e){
logger.error("误点检测推送接口出错---",e);
}
return null;
}
public void ts(Map m) throws ParseException {
//记录存一下 --超过当前时间的是否推送?
String st = m.get("lineCode")+"_"+m.get("type")+"_"+m.get("rqStr");
Long sj = sdf.parse(m.get("rqStr").toString() +" "+ m.get("rq")).getTime();
Long dsj = new Date().getTime();
List<Long> list = new ArrayList();
//111_DJG_2024-06-24
if (ZnddThread.ZNDDTYPEMAP.get(st) != null ) {
list = ZnddThread.ZNDDTYPEMAP.get(st);
int i = 0;
for (Long s : list){ //推送过的同样情况1小时内 &&//超过当前时间的不推送&& sj < dsj
if (Math.abs(s - sj) > (60 * 60 * 1000)){
i ++ ;
}
}
outEntrance.Znddjk(m);//测试推送
}else {
list.add(sj);
ZnddThread.ZNDDTYPEMAP.put(st,list);//存记录
outEntrance.Znddjk(m);//推送
}
}
//大间隔数据转换
public Map ConvertDJK(LargeGap lg,String ids){
Map sp = new HashMap();
sp.put("uuid",UUID());
sp.put("lineCode",lg.getLineCode());
sp.put("lineName",lg.getLineName() );
sp.put("rqStr",lg.getDateStr());
sp.put("rq",sdfHHmm.format(lg.getTsTime()));
sp.put("type","DJG");
sp.put("xlDir",lg.getUpDown());
sp.put("numType",lg.getIntervalMinute());
sp.put("stationCode",lg.getStationName());
sp.put("stationName",lg.getStationName());
sp.put("clzbh",lg.getNbbm());
sp.put("fcsj",lg.getBcfcsj());
sp.put("ids",ids);
sp.put("lg",lg);
return sp;
}
//转换
public Map addStationPeople(ScheduleRealInfo info,String type,Long sst) throws ParseException{
Map sp = new HashMap();
sp.put("uuid",UUID());
sp.put("lineCode",info.getXlBm());
sp.put("lineName",info.getXlName() );
sp.put("rqStr",info.getScheduleDateStr());
sp.put("rq",sdfHHmm.format(new Date())); //检测到时间
sp.put("type",type);
sp.put("xlDir",info.getXlDir());
sp.put("numType",sst);
sp.put("fcsj",info.getFcsj());
sp.put("id",info.getId());
sp.put("clzbh",info.getClZbh());
sp.put("ids",info.getId());
sp.put("sch",info);
return sp;
}
//生成唯一id
public String UUID(){
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
uuid=uuid.substring(0,10);
StringBuilder builder=new StringBuilder();
builder.append(uuid)
.append(getRandom(3));
return builder.toString();
}
private static long getRandom(long n) {
long min = 1, max = 9;
for (int i = 1; i < n; i++) {
min *= 10;
max *= 10;
}
long rangeLong = (((long) (new Random().nextDouble() * (max - min)))) + min;
return rangeLong;
}
}