BasicData.java
17.5 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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
package com.bsth.data;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.bsth.entity.*;
import com.bsth.repository.*;
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 com.bsth.data.gpsdata_v2.cache.GeoCacheData;
import com.bsth.data.pinyin.PersionPinYinBuffer;
import com.bsth.entity.Business;
import com.bsth.entity.CarPark;
import com.bsth.entity.Cars;
import com.bsth.entity.Line;
import com.bsth.entity.Personnel;
import com.bsth.entity.StationRoute;
import com.bsth.entity.calc.CalcInterval;
import com.bsth.entity.schedule.CarConfigInfo;
import com.bsth.repository.calc.CalcIntervalRepository;
import com.bsth.repository.schedule.CarConfigInfoRepository;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
/**
* @author PanZhao
* @ClassName: BasicData
* @Description: TODO(基础的映射数据)
* @date 2016年8月10日 下午3:27:45
*/
@Component
public class BasicData {
//公司代码和公司名对照(K: 公司编码,V:公司名)
public static Map<String, String> businessCodeNameMap;
//分公司公司代码和分公司公司名对照(K: 分公司编码_公司编码,V:分公司公司名)
public static Map<String, String> businessFgsCodeNameMap;
//设备号和车辆自编号 (K: 设备编码 ,V:车辆自编号)
public static BiMap<String, String> deviceId2NbbmMap;
//车辆自编号和公司代码对照 (K: 车辆自编号 ,V:公司代码)
public static Map<String, String> nbbm2CompanyCodeMap;
//车辆自编号和分公司代码对照 (K: 车辆自编号 ,V:分公司编码_公司编码)
public static Map<String, String> nbbm2FgsCompanyCodeMap;
//车辆自编号和牌照号对照 (K: 车辆自编号 ,V:牌照号)
public static BiMap<String, String> nbbmCompanyPlateMap;
//车辆自编号和牌照号对照 (K: 牌照号 ,V:车辆自编号)
public static BiMap<String, String> plate2NbbmMap;
//站点编码和名称对照,包括停车场 (K: lineCode_updown_stationCode ,V:站点名称)
public static Map<String, String> stationCode2NameMap;
//车辆和线路对照
public static Map<String, Line> nbbm2LineMap;
//线路历史配车(K: 线路编码 ,V:List<车辆自编号>)
public static Map<String, List<String>> lineCodeHistoryNbbmMap;
//线路ID和code 对照
public static BiMap<Integer, String> lineId2CodeMap;
//线路编码和名称对照
public static Map<String, String> lineCode2NameMap;
//名称和线路编码对照
public static Map<String, String> lineName2CodeMap;
public static Map<String, String> lineCodeAllNameMap;
//停车场
public static List<String> parkCodeList;
//线路ID和shangHaiLinecode 对照
public static Map<Integer, String> lineId2ShangHaiCodeMap;
//线路Code和shangHaiLinecode 对照
public static Map<String, String> lineCode2ShangHaiCodeMap;
/*//驾驶员工号 和 personnel 对象映射
public static Map<String, Personnel> jsyMap;
//售票员工号 和 personnel 对象映射
public static Map<String, Personnel> spyMap;*/
//所以员工和personnerl 对象映射
public static Map<String, Personnel> perMap;
//全量员工 工号和姓名对照
public static Map<String, String> allPerson;
//站点名和运管处编号 对照
public static Map<String, Integer> stationName2YgcNumber;
// 线路编码_日期 等级
public static Map<String, String> lineDate2Level;
public static Map<String, StationRoute> stationCode2StationMap;
private static List<String> serviceNbbmsList = new ArrayList<>();
static Logger logger = LoggerFactory.getLogger(BasicData.class);
public static String getStationNameByCode(String code, String prefix){
String name = stationCode2NameMap.get(code);
return name != null? name: stationCode2NameMap.get(prefix + code);
}
public static List<String> getServiceNbbms() {
return serviceNbbmsList;
}
/* @Autowired
JdbcTemplate jdbcTemplate;
public Map<String, String> getNbbm2PlateNo(){
List<Map<String, Object>> list = jdbcTemplate.queryForList("select CAR_CODE,CAR_PLATE from bsth_c_cars where CAR_CODE is not null and CAR_PLATE is not null");
Map<String, String> rs = new HashMap<>();
for(Map<String, Object> map : list){
rs.put(map.get("CAR_CODE").toString(), map.get("CAR_PLATE").toString());
}
return rs;
}*/
@Component
public static class BasicDataLoader extends Thread {
@Autowired
CarsRepository carsRepository;
@Autowired
StationRepository stationRepository;
@Autowired
CarParkRepository carParkRepository;
@Autowired
CarConfigInfoRepository carConfigInfoRepository;
@Autowired
LineRepository lineRepository;
@Autowired
StationRouteRepository stationRouteRepository;
@Autowired
PersonnelRepository personnelRepository;
@Autowired
BusinessRepository businessRepository;
@Autowired
GeoCacheData geoCacheData;
@Autowired
Station2ParkBuffer station2ParkBuffer;
@Autowired
PersionPinYinBuffer persionPinYinBuffer;
@Autowired
CalcIntervalRepository calcIntervalRepository;
@Autowired
private SystemParamRepository systemParamRepository;
@Override
public void run() {
loadAllData();
}
/**
* @Title: loadAllData
* @Description: TODO(加载所有数据)
*/
public int loadAllData() {
try {
logger.info("开始加载基础数据..,");
//设备信息
loadDeviceInfo();
//站点信息
loadStationInfo();
//线路信息
loadLineInfo();
//车辆和线路映射信息
loadNbbm2LineInfo();
loadLineCodeHistoryNbbmMapInfo();
//人员信息
loadPersonnelInfo();
//公司信息
loadBusinessInfo();
// 线路等级信息
loadLineLevel();
logger.info("load geo cache..,");
geoCacheData.loadData();
station2ParkBuffer.saveAll();
logger.info("加载基础数据成功!,");
} catch (Exception e) {
logger.error("加载基础数据时出现异常,", e);
}
return 0;
}
/**
* loadBusinessInfo
* (公司代码公司名对照)
*/
public void loadBusinessInfo() {
Map<String, String> businessMap = new HashMap<String, String>();
Map<String, String> businessFgsMap = new HashMap<String, String>();
Iterator<Business> busIter = businessRepository.findAll().iterator();
Business t;
while (busIter.hasNext()) {
t = busIter.next();
businessMap.put(t.getBusinessCode(), t.getBusinessName());
businessFgsMap.put(t.getBusinessCode() + "_" + t.getUpCode(), t.getBusinessName());
}
businessCodeNameMap = businessMap;
businessFgsCodeNameMap = businessFgsMap;
}
/**
* @Title: loadDeviceInfo
* @Description: TODO(加载设备相关信息)
*/
public void loadDeviceInfo() {
BiMap<String, String> deviceId2Nbbm = HashBiMap.create();
//车辆和公司代码对照
Map<String, String> nbbm2CompanyCode = new HashMap<>();
//车辆和分公司代码对照
Map<String, String> nbbm2FgsCompanyCode = new HashMap<>();
//车辆自编号和拍照号对照
BiMap<String, String> nbbmCompanyPlate = HashBiMap.create();
BiMap<String, String> plateNbbm = HashBiMap.create();
List<String> serviceNbbms = new ArrayList<>();
Iterator<Cars> carIterator = carsRepository.findAll().iterator();
Cars car;
while (carIterator.hasNext()) {
car = carIterator.next();
deviceId2Nbbm.put(car.getEquipmentCode(), car.getInsideCode());
nbbm2CompanyCode.put(car.getInsideCode(), car.getBusinessCode());
nbbm2FgsCompanyCode.put(car.getInsideCode(), car.getBrancheCompanyCode() + "_" + car.getBusinessCode() );
nbbmCompanyPlate.put(car.getInsideCode(), car.getCarPlate());
plateNbbm.put(car.getCarPlate(),car.getInsideCode());
if (car.getScrapState() == null || !car.getScrapState()) {
serviceNbbms.add(car.getInsideCode());
}
}
deviceId2NbbmMap = deviceId2Nbbm;
nbbm2CompanyCodeMap = nbbm2CompanyCode;
nbbm2FgsCompanyCodeMap = nbbm2FgsCompanyCode;
nbbmCompanyPlateMap =nbbmCompanyPlate;
plate2NbbmMap=plateNbbm;
serviceNbbmsList = serviceNbbms;
}
/**
* @Title: loadStationInfo
* @Description: TODO(加载站点信息)
*/
public void loadStationInfo() {
Map<String, String> stationCode2Name = new HashMap<>();
Map<String,StationRoute> stationCode2Station = new HashMap<>();
Iterator<StationRoute> iterator = stationRouteRepository.findAll().iterator();
StationRoute sroute;
while (iterator.hasNext()) {
sroute = iterator.next();
stationCode2Name.put(sroute.getLineCode() + "_" + sroute.getDirections() + "_" + sroute.getStationCode(), sroute.getStationName());
stationCode2Station.put(sroute.getLineCode()+"_"+sroute.getStationCode(),sroute);
}
//停车场
Iterator<CarPark> iterator2 = carParkRepository.findAll().iterator();
List<String> parkCodes = new ArrayList<>();
CarPark carPark;
while (iterator2.hasNext()) {
carPark = iterator2.next();
stationCode2Name.put(carPark.getParkCode(), carPark.getParkName());
parkCodes.add(carPark.getParkCode());
}
parkCodeList = parkCodes;
stationCode2NameMap = stationCode2Name;
stationCode2StationMap=stationCode2Station;
}
/**
* @Title: loadNbbm2LineInfo
* @Description: TODO(车辆和线路对照)
*/
public void loadNbbm2LineInfo() {
Iterator<CarConfigInfo> allIterator = carConfigInfoRepository.findAll().iterator();
Map<String, Line> ccMap = new HashMap<>();
CarConfigInfo cci;
while (allIterator.hasNext()) {
cci = allIterator.next();
if(cci.getIsCancel())
continue;//排除已经报废的
ccMap.put(cci.getCl().getInsideCode(), cci.getXl());
}
nbbm2LineMap = ccMap;
}
/**
* @Title: loadLineCodeHistoryNbbmMapInfo
* @Description: TODO(线路历史配车)
*/
public void loadLineCodeHistoryNbbmMapInfo() {
Iterator<CarConfigInfo> allIterator = carConfigInfoRepository.findAll().iterator();
Map<String, List<String>> ccMap = new HashMap<>(); //用list保持排序
Map<String, Set<String>> sMap = new HashMap<>(); //用Set去重
CarConfigInfo cci;
while (allIterator.hasNext()) {
cci = allIterator.next();
String lineCode = cci.getXl().getLineCode();
if(!ccMap.containsKey(lineCode)){
ccMap.put(lineCode, new ArrayList<String>());
sMap.put(lineCode, new HashSet<String>());
}
if(sMap.get(lineCode).add(cci.getCl().getInsideCode())){
ccMap.get(lineCode).add(cci.getCl().getInsideCode());
}
}
lineCodeHistoryNbbmMap = ccMap;
}
/**
* @Title: loadLineInfo
* @Description: TODO(加载线路相关信息)
*/
public void loadLineInfo() {
Iterator<Line> iterator = lineRepository.findAllLine().iterator();
Line line;
BiMap<Integer, String> biMap = HashBiMap.create();
Map<String, String> code2name = new HashMap<>();
Map<String, String> name2code = new HashMap<>();
Map<Integer, String> id2SHcode = new HashMap<Integer, String>();
Map<String, String> code2SHcode = new HashMap<String, String>();
Map<String, Integer> tempStationName2YgcNumber = new HashMap<String, Integer>();
/**
* 加载运管处的站点及序号
* 上行从1开始,下行顺序续编
*/
List<Map<String, String>> ygcLines = stationRouteRepository.findAllLineWithYgc();
if(ygcLines != null && ygcLines.size() > 0){
int size = ygcLines.size();
Map<String, String> tempMap ;
int num = 1;
String key;
String lineCode = "";
for (int i = 0; i < size; i ++){
tempMap = ygcLines.get(i);
if(lineCode.equals("")){
lineCode = tempMap.get("lineCode");
}else if(!lineCode.equals(tempMap.get("lineCode"))){
num = 1;
lineCode = tempMap.get("lineCode");
}
key = tempMap.get("lineCode") + "_"+String.valueOf(tempMap.get("directions"))
+ "_"+tempMap.get("stationCode")+ "_"+tempMap.get("stationMark");
tempStationName2YgcNumber.put(key,num++);
}
}
while (iterator.hasNext()) {
line = iterator.next();
biMap.put(line.getId(), line.getLineCode());
code2name.put(line.getLineCode(), line.getName());
name2code.put(line.getName(), line.getLineCode());
id2SHcode.put(line.getId(), line.getShanghaiLinecode());
code2SHcode.put(line.getLineCode(), line.getShanghaiLinecode());
}
lineId2CodeMap = biMap;
lineCode2NameMap = code2name;
lineName2CodeMap = name2code;
lineId2ShangHaiCodeMap = id2SHcode;
lineCode2ShangHaiCodeMap = code2SHcode;
stationName2YgcNumber = tempStationName2YgcNumber;
Map<String, String> code2nameAll = new HashMap<>();
Iterator<Line> iteratorAll = lineRepository.findAll().iterator();
while (iteratorAll.hasNext()) {
line = iteratorAll.next();
code2nameAll.put(line.getLineCode(), line.getName());
}
lineCodeAllNameMap=code2nameAll;
}
/**
* @Title: loadPersonnelInfo
* @Description: TODO(加载人员信息)
*/
public void loadPersonnelInfo() {
Iterator<Personnel> iterator = personnelRepository.findAll().iterator();
Map<String, Personnel> /*jsyTempMap = new HashMap<>(), spyTempMap = new HashMap<>(),*/perTempMap=new HashMap<>();
Map<String, String> allPersonMap = new HashMap<>();
Personnel p;
String jobCode;
while (iterator.hasNext()) {
p = iterator.next();
jobCode = p.getJobCode();
if (StringUtils.isEmpty(jobCode))
continue;
/*if (p.getPosts() != null) {
if (p.getPosts().equals("1"))
jsyTempMap.put(jobCode, p);
else if (p.getPosts().equals("2"))
spyTempMap.put(jobCode, p);
}*/
perTempMap.put(jobCode, p);
allPersonMap.put(jobCode, p.getPersonnelName());
}
//jsyMap = jsyTempMap;
//spyMap = spyTempMap;
allPerson = allPersonMap;
perMap = perTempMap;
//人员拼音转换
persionPinYinBuffer.refresh();
}
/**
* 加载线路级别信息 按当前日期取(当前+前后一天)的数据
*/
public void loadLineLevel() {
List<String> dates = new ArrayList<>();
Map<String, String> result = new HashMap<>();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(new Date(System.currentTimeMillis() - 86400000));
dates.add(df.format(c.getTime()));
for (int i = 0;i < 2;i++) {
c.add(Calendar.DATE, 1);
dates.add(df.format(c.getTime()));
}
List<CalcInterval> l = calcIntervalRepository.selectByDates(dates);
for (CalcInterval ci : l) {
result.put(ci.getXlBm() + "_" + ci.getDate(), ci.getLevel());
}
lineDate2Level = result;
}
}
}