AdminUtilsController.java
9.19 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
package com.bsth.controller.realcontrol;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.text.SimpleDateFormat;
import java.util.*;
import com.bsth.service.schedule.utils.SpringUtils;
import com.bsth.util.MailUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.bsth.common.ResponseCode;
import com.bsth.data.directive.DayOfDirectives;
import com.bsth.data.directive.DirectivesPstThread;
import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
import com.bsth.data.gpsdata_v2.handlers.overspeed.OverspeedProcess;
import com.bsth.data.gpsdata_v2.thread.GpsDataLoaderThread;
import com.bsth.data.msg_queue.DirectivePushQueue;
import com.bsth.data.msg_queue.WebSocketPushQueue;
import com.bsth.data.pilot80.PilotReport;
import com.bsth.data.schedule.DayOfSchedule;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.websocket.handler.SendUtils;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
/**
* Created by panzhao on 2017/4/14.
*/
@RestController
@RequestMapping("adminUtils")
public class AdminUtilsController {
Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private ObjectMapper objectMapper;
@Autowired
DayOfSchedule dayOfSchedule;
@Autowired
GeoCacheData geoCacheData;
@Autowired
DayOfDirectives dayOfDirectives;
@Autowired
SendUtils sendUtils;
@Autowired
PilotReport pilotReport;
@Autowired
MailUtils mailUtils;
/**
* 出现重复班次的车辆
*
* @param
* @RequestMapping(value = "/schRepeat", method = RequestMethod.POST)
* public void schRepeat(@RequestParam String nbbm){
* logger.info("前端通知,车辆 " + nbbm + "出现重复班次,开始检测...");
* List<ScheduleRealInfo> list = dayOfSchedule.findByNbbm(nbbm);
* logger.info("检测前,车辆班次数量:" + list.size());
* <p>
* Map<Long, ScheduleRealInfo> map = new HashMap<>();
* for(ScheduleRealInfo sch : list){
* if(map.containsKey(sch.getId())){
* logger.info("检测到重复ID: " + sch.getId());
* }
* map.put(sch.getId(), sch);
* }
* <p>
* logger.info("检测后,车辆班次数量:" + list.size());
* if(map.values().size() > 0){
* dayOfSchedule.replaceByNbbm(nbbm, map.values());
* }
* }
*/
/* @RequestMapping(value = "/directivePushQueue")
public void directivePushQueue(){
DirectivePushQueue.start();
}*/
@RequestMapping(value = "/directiveQueueSize")
public void directiveQueueSize() {
DirectivePushQueue.size();
}
/*@RequestMapping(value = "/webSocketPushQueue")
public void webSocketPushQueue(){
WebSocketPushQueue.start();
}*/
@RequestMapping(value = "/webSocketQueueSize")
public void webSocketQueueSize() {
WebSocketPushQueue.size();
}
@RequestMapping(value = "/setHttpFlag")
public void setHttpFlag(@RequestParam int flag) {
if (flag != 0 && flag != -1)
return;
GpsDataLoaderThread.setFlag(flag);
}
@RequestMapping(value = "/updateCacheBuff")
public void updateCacheBuff() {
geoCacheData.loadData();
}
@RequestMapping(value = "/reCalcLpSch")
public void reCalcLpSch() {
dayOfSchedule._test_reCalcLpSch();
}
@RequestMapping(value = "/findSchByLpName")
public List<ScheduleRealInfo> findSchByLpName(@RequestParam String lpName) {
return dayOfSchedule.getLpScheduleMap().get(lpName);
}
@RequestMapping(value = "/findSchByNbbm")
public List<ScheduleRealInfo> findSchByNbbm(@RequestParam String nbbm) {
return dayOfSchedule.findByNbbm(nbbm);
}
@RequestMapping(value = "/executeCurr")
public ScheduleRealInfo executeCurr(@RequestParam String nbbm) {
return dayOfSchedule.executeCurr(nbbm);
};
@RequestMapping(value = "/reCalcExecPlan4Nbbm")
public void reCalcExecPlan4Nbbm(@RequestParam String nbbm) {
dayOfSchedule.reCalcExecPlan(nbbm);
};
@RequestMapping(value = "/reCalcExecPlan4Line")
public void reCalcExecPlan4Line(@RequestParam String lineCode) {
Set<String> nbbms = dayOfSchedule.findCarByLineCode(lineCode);
for (String nbbm : nbbms) {
dayOfSchedule.reCalcExecPlan(nbbm);
}
};
@RequestMapping(value = "/removeExecPlan")
public int removeExecPlan(@RequestParam String nbbm) {
dayOfSchedule.removeExecPlan(nbbm);
return 1;
}
@RequestMapping(value = "/sch_re_calc_id_maps")
public int reCalcIdMaps() {
return dayOfSchedule.reCalcIdMaps();
}
@RequestMapping(value = "/sch_size_string")
public String schSizeString() {
return dayOfSchedule.sizeString();
}
@RequestMapping(value = "/containerSize")
public Map<String, Integer> containerSize() {
Map<String, Integer> rs = new HashMap<>();
rs.put("60_size", dayOfDirectives.all60().size());
rs.put("80_size", pilotReport.findAll().size());
rs.put("nbbm_sch_size", dayOfSchedule.findAll().size());
rs.put("lp_sch_size", dayOfSchedule.findAllByLpContainer().size());
rs.put("id_sch_size", dayOfSchedule.findAllByIdContainer().size());
rs.put("pst_sch_size", dayOfSchedule.getPstSize());
rs.put("speeds_size", OverspeedProcess.size());
return rs;
}
@RequestMapping(value = "/websocketRadioText")
public int radioText(String t, String lineCode) {
sendUtils.sendRadioText(t, lineCode);
return 0;
}
@Autowired
DirectivesPstThread directivesPstThread;
@RequestMapping(value = "/_sd_60_pst")
public void sd_60_pst() {
logger.info("手动入库指令....");
directivesPstThread.run();
}
/**
* 删除班次,删除内存中未清理掉的非当天的班次
* @createDate 2019.05.13
* @author zhangxianzhou
* @param id 线路id
* @return 被删除的班次信息
*/
@RequestMapping("/deleteSchduleBC")
public Map<String, Object> deleteSchduleBC(Long id) {
Map<String, Object> rs = new HashMap<>();
rs.put("status", ResponseCode.ERROR);
ScheduleRealInfo sch = null;
try {
sch = dayOfSchedule.get(id);
if (sch == null) {
rs.put("msg", "无效的id号");
return rs;
}
//内存中删除
dayOfSchedule.deleteBC(sch);
rs.put("delete", sch);
rs.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
logger.error("", e);
rs.put("msg", e.getMessage());
sch.setDeleted(false);
}
return rs;
}
@RequestMapping("/changeLogLevel")
public Map<String, Object> changeLogLevel(@RequestParam String level) {
Map<String, Object> rs = new HashMap<>();
rs.put("errCode", 1);
LoggerContext context = (LoggerContext)LoggerFactory.getILoggerFactory();
context.getLogger("root").setLevel(Level.toLevel(level));
rs.put("errCode", 0);
rs.put("errMsg", "成功");
return rs;
}
@RequestMapping("/exportInstance")
public String exportInstance(@RequestParam String classType) {
Map<String, Object> result = new HashMap<>();
try {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
Class cls = Class.forName(classType);
Field[] fields = cls.getDeclaredFields();
for (Field field : fields) {
if (Modifier.isStatic(field.getModifiers()) && field.getName().indexOf("log") == -1) {
field.setAccessible(true);
result.put(field.getName(), field.get(cls));
}
}
result.put("_bean", SpringUtils.getBean(Class.forName(classType)));
return mapper.writeValueAsString(result);
} catch (ClassNotFoundException | JsonProcessingException | IllegalAccessException e) {
e.printStackTrace();
}
return "error";
}
@RequestMapping("/changeEmail")
public String changeEmail(@RequestParam String email) {
Map<String, Object> result = new HashMap<>();
try {
mailUtils.setEmailSendToAddress(email);
return "success";
} catch (Exception e) {
e.printStackTrace();
}
return "error";
}
@RequestMapping("/viewEmail")
public String viewEmail() {
Map<String, Object> result = new HashMap<>();
try {
return mailUtils.getEmailSendToAddress();
} catch (Exception e) {
e.printStackTrace();
}
return "error";
}
}