ZnddThread.java
8.54 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
package com.bsth.data.zndd;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bsth.data.LineConfigData;
import com.bsth.data.adjg.UserCarCountHandler;
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.adjg.domain.LargeGap;
import com.bsth.entity.calc.CalcIntervalDetail;
import com.bsth.entity.realcontrol.LineConfig;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.entity.zndd.znddStatus;
import com.bsth.repository.StationRouteRepository;
import com.bsth.repository.zndd.StationPeopleLoggerRepository;
import com.bsth.repository.zndd.ZnddStatusRepository;
import com.bsth.util.HttpClientUtils;
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.*;
/**
* 调度预案 发车间隔、误点、大间隔、满载、大客流
*/
@Component
public class ZnddThread extends Thread{
Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
StationPeopleLoggerRepository stationPeopleLoggerRepository;
@Autowired
DayOfSchedule dayOfSchedule;
@Autowired
LineConfigData lineConfs;
@Autowired
GpsRealData gpsRealData;
@Autowired
StationRouteRepository stationRouteRepository;
@Autowired
private UserCarCountHandler userCarCountHandler;
@Autowired
OutEntrance outEntrance;
@Autowired
AutomaticSch automaticSch;
@Autowired
ZnddStatusRepository znddStatusRepository;
static Map<String,List> ZNDDTYPEMAP = new HashMap<>(); //已经推送过的检测
String url = "https://lgapp.bsth.tech:13089/bsth_passengerflow/klbus/currentInsideNum.do"; //车内客流接口
String urldkl = "https://lgapp.bsth.tech:8005//monitor/api/getMonitorInfoByDay?key=1&solt=1111&t=1&dayStr="; //大客流接口
private static SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
private static SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd");
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
@Override
public void run() {
List<znddStatus> znddStatusList = (List<znddStatus>) znddStatusRepository.findAll();
//FCJG();//发车间隔检查 报价
//GPSDJG();//大间隔
// MZ(); //满载
//DKL(); //大客流 以接口方式
//automaticSch.mz();
//automaticSch.dfTz();//大间隔
//automaticSch.drivresponse(); //设备重发
for (znddStatus zs : znddStatusList){
if (zs.getOpenStatus().equals("0")) {
if (zs.getType().equals("sftz")) {
automaticSch.sftz();//实发调整
logger.info("实发执行完毕");
}
if (zs.getType().equals("ycsf")) {
automaticSch.sfCX();// 异常实发 - 实发撤销
logger.info("异常实发执行完毕");
}
}
}
}
//满载
public void MZ(){
try {
StringBuilder sb = HttpClientUtils.get(url);
List<Object> list = JSONArray.parseArray(String.valueOf(sb));
for (Object b :list){
Map m = (Map) b;
Integer num = Integer.parseInt(m.get("inside_num").toString());
if (num >= 15){ //大间隔阈值 检测到超过15个人的时候推送
ScheduleRealInfo sr = dayOfSchedule.executeCurr(m.get("nbbm").toString()); //查询当前车辆执行班次
GpsEntity gps = gpsRealData.get(m.get("sbbh").toString());
Map msp = new HashMap();
msp.put("lineCode",m.get("xlbm"));
msp.put("lineName",m.get("xlmc"));
msp.put("stationName",gps.getStationName());
msp.put("rqStr",sdfMonth.format(new Date()));
msp.put("rq",sdfHHmm.format(new Date()));
msp.put("type","MZ");
msp.put("numType",num);
if (sr != null )
msp.put("xlDir",sr.getXlDir());
if (gps != null )
msp.put("station",gps.getStation().getCode());
ts(msp);
}
}
}catch (Exception e){
logger.error("满载检测接口出错-----------",e);
}
}
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();
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小时内
if (Math.abs(s - sj) > (60 * 60 * 1000)){
i ++ ;
}
}
outEntrance.Znddjk(m);//测试推送
if (i == list.size()){
list.add(sj);
ZnddThread.ZNDDTYPEMAP.put(st,list);//存记录
outEntrance.Znddjk(m);//推送
}
return;
}else {
list.add(sj);
ZnddThread.ZNDDTYPEMAP.put(st,list);//存记录
outEntrance.Znddjk(m);//推送
}
}
/* 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();
List<Long> list = new ArrayList();
//111_DJG_2024-06-24
if (ZNDDTYPEMAP.get(st) != null ) {
list = ZNDDTYPEMAP.get(st);
int i = 0;
for (Long s : list){
if (Math.abs(s - sj) > (60 * 60 * 1000)){
i ++ ;
}
}
if (i == list.size()){
list.add(sj);
ZNDDTYPEMAP.put(st,list);//存记录
outEntrance.Znddjk(m);//推送
}
return;
}else {
list.add(sj);
ZNDDTYPEMAP.put(st,list);//存记录
outEntrance.Znddjk(m);//推送
}
}
*/
//发车间隔
public void FCJG(){
try {
//无数据情况下 查看发车间隔配置数据是否正常bsth_c_calc_interval
List<CalcIntervalDetail> fcjgList = userCarCountHandler.calcLast();
if (fcjgList!= null && !fcjgList.isEmpty()){
for (CalcIntervalDetail cd : fcjgList){
Map sp = new HashMap();
sp.put("lineCode",cd.getLineCode());
sp.put("lineName",cd.getLineName());
sp.put("rqStr",cd.getDate());
sp.put("rq",cd.getSjfc2());
sp.put("type","FCJG");
sp.put("xlDir",cd.getXlDir());
sp.put("numType",cd.getSubTime());
sp.put("fcsj",cd.getSjfc2());
sp.put("stationName",cd.getStation());
ts(sp);
}
}
}catch (Exception e){
logger.error("发车间隔检测出现出错-----------",e);
}
}
//转换
public Map addStationPeople(ScheduleRealInfo info,String type,Long sst,String sj) throws ParseException{
Map sp = new HashMap();
sp.put("lineCode",info.getXlBm());
sp.put("lineName",info.getXlName() );
sp.put("rqStr",info.getScheduleDateStr());
sp.put("rq",new java.sql.Date(sdf.parse((info.getScheduleDateStr()+" " + sj)).getTime())); //检测到时间
sp.put("type",type);
sp.put("xlDir",info.getXlDir());
sp.put("numType",sst);
return sp;
}
//排序
public static class GpsComp implements Comparator<GpsEntity> {
@Override
public int compare(GpsEntity o1, GpsEntity o2) {
return Integer.parseInt(o1.getRemark()) - Integer.parseInt(o2.getRemark());
}
}
}