Commit 37e95b0a16180fc79669742f2ff6d45db04e9ff2

Authored by 王通
1 parent c644d3df

1.营运公司编码和名称映射时需做限定

src/main/java/com/bsth/data/BasicData.java
1   -package com.bsth.data;
2   -
3   -import java.text.DateFormat;
4   -import java.text.SimpleDateFormat;
5   -import java.util.ArrayList;
6   -import java.util.Calendar;
7   -import java.util.Date;
8   -import java.util.HashMap;
9   -import java.util.HashSet;
10   -import java.util.Iterator;
11   -import java.util.List;
12   -import java.util.Map;
13   -import java.util.Set;
14   -
15   -import com.bsth.entity.*;
16   -import com.bsth.repository.*;
17   -import org.apache.commons.lang3.StringUtils;
18   -import org.slf4j.Logger;
19   -import org.slf4j.LoggerFactory;
20   -import org.springframework.beans.factory.annotation.Autowired;
21   -import org.springframework.jdbc.core.BeanPropertyRowMapper;
22   -import org.springframework.jdbc.core.JdbcTemplate;
23   -import org.springframework.stereotype.Component;
24   -
25   -import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
26   -import com.bsth.data.pinyin.PersionPinYinBuffer;
27   -import com.bsth.entity.calc.CalcInterval;
28   -import com.bsth.entity.schedule.CarConfigInfo;
29   -import com.bsth.repository.calc.CalcIntervalRepository;
30   -import com.bsth.repository.schedule.CarConfigInfoRepository;
31   -import com.google.common.collect.BiMap;
32   -import com.google.common.collect.HashBiMap;
33   -
34   -/**
35   - * @author PanZhao
36   - * @ClassName: BasicData
37   - * @Description: TODO(基础的映射数据)
38   - * @date 2016年8月10日 下午3:27:45
39   - */
40   -@Component
41   -public class BasicData {
42   -
43   - //公司代码和公司名对照(K: 公司编码,V:公司名)
44   - public static Map<String, String> businessCodeNameMap;
45   -
46   - //分公司公司代码和分公司公司名对照(K: 分公司编码_公司编码,V:分公司公司名)
47   - public static Map<String, String> businessFgsCodeNameMap;
48   -
49   - //设备号和车辆自编号 (K: 设备编码 ,V:车辆自编号)
50   - public static BiMap<String, String> deviceId2NbbmMap;
51   -
52   - //车辆自编号和公司代码对照 (K: 车辆自编号 ,V:公司代码)
53   - public static Map<String, String> nbbm2CompanyCodeMap;
54   -
55   - //车辆自编号和分公司代码对照 (K: 车辆自编号 ,V:分公司编码_公司编码)
56   - public static Map<String, String> nbbm2FgsCompanyCodeMap;
57   -
58   - //车辆自编号和牌照号对照 (K: 车辆自编号 ,V:牌照号)
59   - public static Map<String, String> nbbmCompanyPlateMap;
60   -
61   - //站点编码和名称对照,包括停车场 (K: lineCode_updown_stationCode ,V:站点名称)
62   - public static Map<String, String> stationCode2NameMap;
63   -
64   - //车辆和线路对照
65   - public static Map<String, Line> nbbm2LineMap;
66   -
67   - //线路历史配车(K: 线路编码 ,V:List<车辆自编号>)
68   - public static Map<String, List<String>> lineCodeHistoryNbbmMap;
69   -
70   - //线路ID和code 对照
71   - public static BiMap<Integer, String> lineId2CodeMap;
72   -
73   - //线路编码和名称对照
74   - public static Map<String, String> lineCode2NameMap;
75   -
76   - //名称和线路编码对照
77   - public static Map<String, String> lineName2CodeMap;
78   -
79   - public static Map<String, String> lineCodeAllNameMap;
80   - //停车场
81   - public static List<String> parkCodeList;
82   -
83   - //线路ID和shangHaiLinecode 对照
84   - public static Map<Integer, String> lineId2ShangHaiCodeMap;
85   -
86   - //线路Code和shangHaiLinecode 对照
87   - public static Map<String, String> lineCode2ShangHaiCodeMap;
88   -
89   - /*//驾驶员工号 和 personnel 对象映射
90   - public static Map<String, Personnel> jsyMap;
91   - //售票员工号 和 personnel 对象映射
92   - public static Map<String, Personnel> spyMap;*/
93   - //所以员工和personnerl 对象映射
94   - public static Map<String, Personnel> perMap;
95   - //全量员工 工号和姓名对照
96   - public static Map<String, String> allPerson;
97   -
98   - //站点名和运管处编号 对照
99   - public static Map<String, Integer> stationName2YgcNumber;
100   -
101   - // 线路编码_日期 等级
102   - public static Map<String, String> lineDate2Level;
103   -
104   - static Logger logger = LoggerFactory.getLogger(BasicData.class);
105   -
106   - public static String getStationNameByCode(String code, String prefix){
107   - String name = stationCode2NameMap.get(code);
108   - return name != null? name: stationCode2NameMap.get(prefix + code);
109   - }
110   -
111   -/* @Autowired
112   - JdbcTemplate jdbcTemplate;
113   - public Map<String, String> getNbbm2PlateNo(){
114   - 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");
115   -
116   - Map<String, String> rs = new HashMap<>();
117   - for(Map<String, Object> map : list){
118   - rs.put(map.get("CAR_CODE").toString(), map.get("CAR_PLATE").toString());
119   - }
120   - return rs;
121   - }*/
122   -
123   - @Component
124   - public static class BasicDataLoader extends Thread {
125   -
126   - @Autowired
127   - CarsRepository carsRepository;
128   -
129   - @Autowired
130   - StationRepository stationRepository;
131   -
132   - @Autowired
133   - CarParkRepository carParkRepository;
134   -
135   - @Autowired
136   - CarConfigInfoRepository carConfigInfoRepository;
137   -
138   - @Autowired
139   - LineRepository lineRepository;
140   -
141   - @Autowired
142   - StationRouteRepository stationRouteRepository;
143   -
144   - @Autowired
145   - PersonnelRepository personnelRepository;
146   -
147   - @Autowired
148   - BusinessRepository businessRepository;
149   -
150   - @Autowired
151   - GeoCacheData geoCacheData;
152   -
153   - @Autowired
154   - Station2ParkBuffer station2ParkBuffer;
155   -
156   - @Autowired
157   - PersionPinYinBuffer persionPinYinBuffer;
158   -
159   - @Autowired
160   - CalcIntervalRepository calcIntervalRepository;
161   -
162   - @Override
163   - public void run() {
164   - loadAllData();
165   - }
166   -
167   - /**
168   - * @Title: loadAllData
169   - * @Description: TODO(加载所有数据)
170   - */
171   - public int loadAllData() {
172   - try {
173   - logger.info("开始加载基础数据..,");
174   - //设备信息
175   - loadDeviceInfo();
176   - //站点信息
177   - loadStationInfo();
178   - //线路信息
179   - loadLineInfo();
180   - //车辆和线路映射信息
181   - loadNbbm2LineInfo();
182   - loadLineCodeHistoryNbbmMapInfo();
183   - //人员信息
184   - loadPersonnelInfo();
185   - //公司信息
186   - loadBusinessInfo();
187   - // 线路等级信息
188   - loadLineLevel();
189   -
190   - logger.info("load geo cache..,");
191   - geoCacheData.loadData();
192   - station2ParkBuffer.saveAll();
193   - logger.info("加载基础数据成功!,");
194   - } catch (Exception e) {
195   - logger.error("加载基础数据时出现异常,", e);
196   - }
197   - return 0;
198   - }
199   -
200   - /**
201   - * loadBusinessInfo
202   - * (公司代码公司名对照)
203   - */
204   - public void loadBusinessInfo() {
205   - Map<String, String> businessMap = new HashMap<String, String>();
206   - Map<String, String> businessFgsMap = new HashMap<String, String>();
207   - Iterator<Business> busIter = businessRepository.findAll().iterator();
208   - Business t;
209   - while (busIter.hasNext()) {
210   - t = busIter.next();
211   - businessMap.put(t.getBusinessCode(), t.getBusinessName());
212   - businessFgsMap.put(t.getBusinessCode() + "_" + t.getUpCode(), t.getBusinessName());
213   - }
214   - businessCodeNameMap = businessMap;
215   - businessFgsCodeNameMap = businessFgsMap;
216   - }
217   -
218   - /**
219   - * @Title: loadDeviceInfo
220   - * @Description: TODO(加载设备相关信息)
221   - */
222   - public void loadDeviceInfo() {
223   - BiMap<String, String> deviceId2Nbbm = HashBiMap.create();
224   - //车辆和公司代码对照
225   - Map<String, String> nbbm2CompanyCode = new HashMap<>();
226   - //车辆和分公司代码对照
227   - Map<String, String> nbbm2FgsCompanyCode = new HashMap<>();
228   -
229   - //车辆自编号和拍照号对照
230   - Map<String, String> nbbmCompanyPlate = new HashMap<>();
231   -
232   - Iterator<Cars> carIterator = carsRepository.findAll().iterator();
233   - Cars car;
234   - while (carIterator.hasNext()) {
235   - car = carIterator.next();
236   - deviceId2Nbbm.put(car.getEquipmentCode(), car.getInsideCode());
237   - nbbm2CompanyCode.put(car.getInsideCode(), car.getBusinessCode());
238   - nbbm2FgsCompanyCode.put(car.getInsideCode(), car.getBrancheCompanyCode() + "_" + car.getBusinessCode() );
239   - nbbmCompanyPlate.put(car.getInsideCode(), car.getCarPlate());
240   - }
241   -
242   - deviceId2NbbmMap = deviceId2Nbbm;
243   - nbbm2CompanyCodeMap = nbbm2CompanyCode;
244   - nbbm2FgsCompanyCodeMap = nbbm2FgsCompanyCode;
245   - nbbmCompanyPlateMap =nbbmCompanyPlate;
246   - }
247   -
248   - /**
249   - * @Title: loadStationInfo
250   - * @Description: TODO(加载站点信息)
251   - */
252   - public void loadStationInfo() {
253   - Map<String, String> stationCode2Name = new HashMap<>();
254   - Iterator<StationRoute> iterator = stationRouteRepository.findAll().iterator();
255   - StationRoute sroute;
256   - while (iterator.hasNext()) {
257   - sroute = iterator.next();
258   - stationCode2Name.put(sroute.getLineCode() + "_" + sroute.getDirections() + "_" + sroute.getStationCode(), sroute.getStationName());
259   - }
260   -
261   - //停车场
262   - Iterator<CarPark> iterator2 = carParkRepository.findAll().iterator();
263   -
264   - List<String> parkCodes = new ArrayList<>();
265   -
266   - CarPark carPark;
267   - while (iterator2.hasNext()) {
268   - carPark = iterator2.next();
269   - stationCode2Name.put(carPark.getParkCode(), carPark.getParkName());
270   -
271   - parkCodes.add(carPark.getParkCode());
272   - }
273   - parkCodeList = parkCodes;
274   - stationCode2NameMap = stationCode2Name;
275   - }
276   -
277   - /**
278   - * @Title: loadNbbm2LineInfo
279   - * @Description: TODO(车辆和线路对照)
280   - */
281   - public void loadNbbm2LineInfo() {
282   - Iterator<CarConfigInfo> allIterator = carConfigInfoRepository.findAll().iterator();
283   - Map<String, Line> ccMap = new HashMap<>();
284   -
285   - CarConfigInfo cci;
286   - while (allIterator.hasNext()) {
287   - cci = allIterator.next();
288   - if(cci.getIsCancel())
289   - continue;//排除已经报废的
290   - ccMap.put(cci.getCl().getInsideCode(), cci.getXl());
291   - }
292   - nbbm2LineMap = ccMap;
293   - }
294   -
295   - /**
296   - * @Title: loadLineCodeHistoryNbbmMapInfo
297   - * @Description: TODO(线路历史配车)
298   - */
299   - public void loadLineCodeHistoryNbbmMapInfo() {
300   - Iterator<CarConfigInfo> allIterator = carConfigInfoRepository.findAll().iterator();
301   - Map<String, List<String>> ccMap = new HashMap<>(); //用list保持排序
302   - Map<String, Set<String>> sMap = new HashMap<>(); //用Set去重
303   -
304   - CarConfigInfo cci;
305   - while (allIterator.hasNext()) {
306   - cci = allIterator.next();
307   - String lineCode = cci.getXl().getLineCode();
308   - if(!ccMap.containsKey(lineCode)){
309   - ccMap.put(lineCode, new ArrayList<String>());
310   - sMap.put(lineCode, new HashSet<String>());
311   - }
312   - if(sMap.get(lineCode).add(cci.getCl().getInsideCode())){
313   - ccMap.get(lineCode).add(cci.getCl().getInsideCode());
314   - }
315   - }
316   - lineCodeHistoryNbbmMap = ccMap;
317   - }
318   -
319   - /**
320   - * @Title: loadLineInfo
321   - * @Description: TODO(加载线路相关信息)
322   - */
323   - public void loadLineInfo() {
324   - Iterator<Line> iterator = lineRepository.findAllLine().iterator();
325   -
326   - Line line;
327   - BiMap<Integer, String> biMap = HashBiMap.create();
328   - Map<String, String> code2name = new HashMap<>();
329   - Map<String, String> name2code = new HashMap<>();
330   - Map<Integer, String> id2SHcode = new HashMap<Integer, String>();
331   - Map<String, String> code2SHcode = new HashMap<String, String>();
332   - Map<String, Integer> tempStationName2YgcNumber = new HashMap<String, Integer>();
333   -
334   - /**
335   - * 加载运管处的站点及序号
336   - * 上行从1开始,下行顺序续编
337   - */
338   - List<Map<String, String>> ygcLines = stationRouteRepository.findAllLineWithYgc();
339   - if(ygcLines != null && ygcLines.size() > 0){
340   - int size = ygcLines.size();
341   - Map<String, String> tempMap ;
342   - int num = 1;
343   - String key;
344   - String lineCode = "";
345   - for (int i = 0; i < size; i ++){
346   - tempMap = ygcLines.get(i);
347   - if(lineCode.equals("")){
348   - lineCode = tempMap.get("lineCode");
349   - }else if(!lineCode.equals(tempMap.get("lineCode"))){
350   - num = 1;
351   - lineCode = tempMap.get("lineCode");
352   - }
353   - key = tempMap.get("lineCode") + "_"+String.valueOf(tempMap.get("directions"))
354   - + "_"+tempMap.get("stationCode")+ "_"+tempMap.get("stationMark");
355   - tempStationName2YgcNumber.put(key,num++);
356   - }
357   - }
358   -
359   - while (iterator.hasNext()) {
360   - line = iterator.next();
361   - biMap.put(line.getId(), line.getLineCode());
362   - code2name.put(line.getLineCode(), line.getName());
363   - name2code.put(line.getName(), line.getLineCode());
364   - id2SHcode.put(line.getId(), line.getShanghaiLinecode());
365   - code2SHcode.put(line.getLineCode(), line.getShanghaiLinecode());
366   - }
367   -
368   - // 特殊线路ID为0的数据 (小模块轨迹)
369   - biMap.put(0, "0");
370   - code2name.put("0", "0");
371   -
372   - lineId2CodeMap = biMap;
373   - lineCode2NameMap = code2name;
374   - lineName2CodeMap = name2code;
375   - lineId2ShangHaiCodeMap = id2SHcode;
376   - lineCode2ShangHaiCodeMap = code2SHcode;
377   - stationName2YgcNumber = tempStationName2YgcNumber;
378   -
379   - Map<String, String> code2nameAll = new HashMap<>();
380   - Iterator<Line> iteratorAll = lineRepository.findAll().iterator();
381   - while (iteratorAll.hasNext()) {
382   - line = iteratorAll.next();
383   - code2nameAll.put(line.getLineCode(), line.getName());
384   - }
385   - lineCodeAllNameMap=code2nameAll;
386   - }
387   -
388   - /**
389   - * @Title: loadPersonnelInfo
390   - * @Description: TODO(加载人员信息)
391   - */
392   - public void loadPersonnelInfo() {
393   - Iterator<Personnel> iterator = personnelRepository.findAll().iterator();
394   -
395   - Map<String, Personnel> /*jsyTempMap = new HashMap<>(), spyTempMap = new HashMap<>(),*/perTempMap=new HashMap<>();
396   - Map<String, String> allPersonMap = new HashMap<>();
397   -
398   - Personnel p;
399   - String jobCode;
400   - while (iterator.hasNext()) {
401   - p = iterator.next();
402   -
403   - jobCode = p.getJobCode();
404   - if (StringUtils.isEmpty(jobCode))
405   - continue;
406   -
407   - /*if (p.getPosts() != null) {
408   - if (p.getPosts().equals("1"))
409   - jsyTempMap.put(jobCode, p);
410   - else if (p.getPosts().equals("2"))
411   - spyTempMap.put(jobCode, p);
412   - }*/
413   -
414   - perTempMap.put(jobCode, p);
415   -
416   - allPersonMap.put(jobCode, p.getPersonnelName());
417   - }
418   -
419   - //jsyMap = jsyTempMap;
420   - //spyMap = spyTempMap;
421   - allPerson = allPersonMap;
422   - perMap = perTempMap;
423   -
424   - //人员拼音转换
425   - persionPinYinBuffer.refresh();
426   - }
427   -
428   - /**
429   - * 加载线路级别信息 按当前日期取(当前+前后一天)的数据
430   - */
431   - public void loadLineLevel() {
432   - List<String> dates = new ArrayList<>();
433   - Map<String, String> result = new HashMap<>();
434   - DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
435   -
436   - Calendar c = Calendar.getInstance();
437   - c.setTime(new Date(System.currentTimeMillis() - 86400000));
438   - dates.add(df.format(c.getTime()));
439   -
440   - for (int i = 0;i < 2;i++) {
441   - c.add(Calendar.DATE, 1);
442   - dates.add(df.format(c.getTime()));
443   - }
444   -
445   - List<CalcInterval> l = calcIntervalRepository.selectByDates(dates);
446   - for (CalcInterval ci : l) {
447   - result.put(ci.getXlBm() + "_" + ci.getDate(), ci.getLevel());
448   - }
449   -
450   - lineDate2Level = result;
451   - }
452   - }
453   -}
  1 +package com.bsth.data;
  2 +
  3 +import java.text.DateFormat;
  4 +import java.text.SimpleDateFormat;
  5 +import java.util.ArrayList;
  6 +import java.util.Calendar;
  7 +import java.util.Date;
  8 +import java.util.HashMap;
  9 +import java.util.HashSet;
  10 +import java.util.Iterator;
  11 +import java.util.List;
  12 +import java.util.Map;
  13 +import java.util.Set;
  14 +
  15 +import com.bsth.entity.*;
  16 +import com.bsth.repository.*;
  17 +import org.apache.commons.lang3.StringUtils;
  18 +import org.slf4j.Logger;
  19 +import org.slf4j.LoggerFactory;
  20 +import org.springframework.beans.factory.annotation.Autowired;
  21 +import org.springframework.jdbc.core.BeanPropertyRowMapper;
  22 +import org.springframework.jdbc.core.JdbcTemplate;
  23 +import org.springframework.stereotype.Component;
  24 +
  25 +import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
  26 +import com.bsth.data.pinyin.PersionPinYinBuffer;
  27 +import com.bsth.entity.calc.CalcInterval;
  28 +import com.bsth.entity.schedule.CarConfigInfo;
  29 +import com.bsth.repository.calc.CalcIntervalRepository;
  30 +import com.bsth.repository.schedule.CarConfigInfoRepository;
  31 +import com.google.common.collect.BiMap;
  32 +import com.google.common.collect.HashBiMap;
  33 +
  34 +/**
  35 + * @author PanZhao
  36 + * @ClassName: BasicData
  37 + * @Description: TODO(基础的映射数据)
  38 + * @date 2016年8月10日 下午3:27:45
  39 + */
  40 +@Component
  41 +public class BasicData {
  42 +
  43 + //公司代码和公司名对照(K: 公司编码,V:公司名)
  44 + public static Map<String, String> businessCodeNameMap;
  45 +
  46 + //分公司公司代码和分公司公司名对照(K: 分公司编码_公司编码,V:分公司公司名)
  47 + public static Map<String, String> businessFgsCodeNameMap;
  48 +
  49 + //设备号和车辆自编号 (K: 设备编码 ,V:车辆自编号)
  50 + public static BiMap<String, String> deviceId2NbbmMap;
  51 +
  52 + //车辆自编号和公司代码对照 (K: 车辆自编号 ,V:公司代码)
  53 + public static Map<String, String> nbbm2CompanyCodeMap;
  54 +
  55 + //车辆自编号和分公司代码对照 (K: 车辆自编号 ,V:分公司编码_公司编码)
  56 + public static Map<String, String> nbbm2FgsCompanyCodeMap;
  57 +
  58 + //车辆自编号和牌照号对照 (K: 车辆自编号 ,V:牌照号)
  59 + public static Map<String, String> nbbmCompanyPlateMap;
  60 +
  61 + //站点编码和名称对照,包括停车场 (K: lineCode_updown_stationCode ,V:站点名称)
  62 + public static Map<String, String> stationCode2NameMap;
  63 +
  64 + //车辆和线路对照
  65 + public static Map<String, Line> nbbm2LineMap;
  66 +
  67 + //线路历史配车(K: 线路编码 ,V:List<车辆自编号>)
  68 + public static Map<String, List<String>> lineCodeHistoryNbbmMap;
  69 +
  70 + //线路ID和code 对照
  71 + public static BiMap<Integer, String> lineId2CodeMap;
  72 +
  73 + //线路编码和名称对照
  74 + public static Map<String, String> lineCode2NameMap;
  75 +
  76 + //名称和线路编码对照
  77 + public static Map<String, String> lineName2CodeMap;
  78 +
  79 + public static Map<String, String> lineCodeAllNameMap;
  80 + //停车场
  81 + public static List<String> parkCodeList;
  82 +
  83 + //线路ID和shangHaiLinecode 对照
  84 + public static Map<Integer, String> lineId2ShangHaiCodeMap;
  85 +
  86 + //线路Code和shangHaiLinecode 对照
  87 + public static Map<String, String> lineCode2ShangHaiCodeMap;
  88 +
  89 + /*//驾驶员工号 和 personnel 对象映射
  90 + public static Map<String, Personnel> jsyMap;
  91 + //售票员工号 和 personnel 对象映射
  92 + public static Map<String, Personnel> spyMap;*/
  93 + //所以员工和personnerl 对象映射
  94 + public static Map<String, Personnel> perMap;
  95 + //全量员工 工号和姓名对照
  96 + public static Map<String, String> allPerson;
  97 +
  98 + //站点名和运管处编号 对照
  99 + public static Map<String, Integer> stationName2YgcNumber;
  100 +
  101 + // 线路编码_日期 等级
  102 + public static Map<String, String> lineDate2Level;
  103 +
  104 + static Logger logger = LoggerFactory.getLogger(BasicData.class);
  105 +
  106 + public static String getStationNameByCode(String code, String prefix){
  107 + String name = stationCode2NameMap.get(code);
  108 + return name != null? name: stationCode2NameMap.get(prefix + code);
  109 + }
  110 +
  111 +/* @Autowired
  112 + JdbcTemplate jdbcTemplate;
  113 + public Map<String, String> getNbbm2PlateNo(){
  114 + 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");
  115 +
  116 + Map<String, String> rs = new HashMap<>();
  117 + for(Map<String, Object> map : list){
  118 + rs.put(map.get("CAR_CODE").toString(), map.get("CAR_PLATE").toString());
  119 + }
  120 + return rs;
  121 + }*/
  122 +
  123 + @Component
  124 + public static class BasicDataLoader extends Thread {
  125 +
  126 + @Autowired
  127 + CarsRepository carsRepository;
  128 +
  129 + @Autowired
  130 + StationRepository stationRepository;
  131 +
  132 + @Autowired
  133 + CarParkRepository carParkRepository;
  134 +
  135 + @Autowired
  136 + CarConfigInfoRepository carConfigInfoRepository;
  137 +
  138 + @Autowired
  139 + LineRepository lineRepository;
  140 +
  141 + @Autowired
  142 + StationRouteRepository stationRouteRepository;
  143 +
  144 + @Autowired
  145 + PersonnelRepository personnelRepository;
  146 +
  147 + @Autowired
  148 + BusinessRepository businessRepository;
  149 +
  150 + @Autowired
  151 + GeoCacheData geoCacheData;
  152 +
  153 + @Autowired
  154 + Station2ParkBuffer station2ParkBuffer;
  155 +
  156 + @Autowired
  157 + PersionPinYinBuffer persionPinYinBuffer;
  158 +
  159 + @Autowired
  160 + CalcIntervalRepository calcIntervalRepository;
  161 +
  162 + @Override
  163 + public void run() {
  164 + loadAllData();
  165 + }
  166 +
  167 + /**
  168 + * @Title: loadAllData
  169 + * @Description: TODO(加载所有数据)
  170 + */
  171 + public int loadAllData() {
  172 + try {
  173 + logger.info("开始加载基础数据..,");
  174 + //设备信息
  175 + loadDeviceInfo();
  176 + //站点信息
  177 + loadStationInfo();
  178 + //线路信息
  179 + loadLineInfo();
  180 + //车辆和线路映射信息
  181 + loadNbbm2LineInfo();
  182 + loadLineCodeHistoryNbbmMapInfo();
  183 + //人员信息
  184 + loadPersonnelInfo();
  185 + //公司信息
  186 + loadBusinessInfo();
  187 + // 线路等级信息
  188 + loadLineLevel();
  189 +
  190 + logger.info("load geo cache..,");
  191 + geoCacheData.loadData();
  192 + station2ParkBuffer.saveAll();
  193 + logger.info("加载基础数据成功!,");
  194 + } catch (Exception e) {
  195 + logger.error("加载基础数据时出现异常,", e);
  196 + }
  197 + return 0;
  198 + }
  199 +
  200 + /**
  201 + * loadBusinessInfo
  202 + * (公司代码公司名对照)
  203 + */
  204 + public void loadBusinessInfo() {
  205 + Map<String, String> businessMap = new HashMap<String, String>();
  206 + Map<String, String> businessFgsMap = new HashMap<String, String>();
  207 + Iterator<Business> busIter = businessRepository.findAll().iterator();
  208 + Business t;
  209 + while (busIter.hasNext()) {
  210 + t = busIter.next();
  211 + if ("88".equals(t.getUpCode())) {
  212 + businessMap.put(t.getBusinessCode(), t.getBusinessName());
  213 + }
  214 + businessFgsMap.put(t.getBusinessCode() + "_" + t.getUpCode(), t.getBusinessName());
  215 + }
  216 + businessCodeNameMap = businessMap;
  217 + businessFgsCodeNameMap = businessFgsMap;
  218 + }
  219 +
  220 + /**
  221 + * @Title: loadDeviceInfo
  222 + * @Description: TODO(加载设备相关信息)
  223 + */
  224 + public void loadDeviceInfo() {
  225 + BiMap<String, String> deviceId2Nbbm = HashBiMap.create();
  226 + //车辆和公司代码对照
  227 + Map<String, String> nbbm2CompanyCode = new HashMap<>();
  228 + //车辆和分公司代码对照
  229 + Map<String, String> nbbm2FgsCompanyCode = new HashMap<>();
  230 +
  231 + //车辆自编号和拍照号对照
  232 + Map<String, String> nbbmCompanyPlate = new HashMap<>();
  233 +
  234 + Iterator<Cars> carIterator = carsRepository.findAll().iterator();
  235 + Cars car;
  236 + while (carIterator.hasNext()) {
  237 + car = carIterator.next();
  238 + deviceId2Nbbm.put(car.getEquipmentCode(), car.getInsideCode());
  239 + nbbm2CompanyCode.put(car.getInsideCode(), car.getBusinessCode());
  240 + nbbm2FgsCompanyCode.put(car.getInsideCode(), car.getBrancheCompanyCode() + "_" + car.getBusinessCode() );
  241 + nbbmCompanyPlate.put(car.getInsideCode(), car.getCarPlate());
  242 + }
  243 +
  244 + deviceId2NbbmMap = deviceId2Nbbm;
  245 + nbbm2CompanyCodeMap = nbbm2CompanyCode;
  246 + nbbm2FgsCompanyCodeMap = nbbm2FgsCompanyCode;
  247 + nbbmCompanyPlateMap =nbbmCompanyPlate;
  248 + }
  249 +
  250 + /**
  251 + * @Title: loadStationInfo
  252 + * @Description: TODO(加载站点信息)
  253 + */
  254 + public void loadStationInfo() {
  255 + Map<String, String> stationCode2Name = new HashMap<>();
  256 + Iterator<StationRoute> iterator = stationRouteRepository.findAll().iterator();
  257 + StationRoute sroute;
  258 + while (iterator.hasNext()) {
  259 + sroute = iterator.next();
  260 + stationCode2Name.put(sroute.getLineCode() + "_" + sroute.getDirections() + "_" + sroute.getStationCode(), sroute.getStationName());
  261 + }
  262 +
  263 + //停车场
  264 + Iterator<CarPark> iterator2 = carParkRepository.findAll().iterator();
  265 +
  266 + List<String> parkCodes = new ArrayList<>();
  267 +
  268 + CarPark carPark;
  269 + while (iterator2.hasNext()) {
  270 + carPark = iterator2.next();
  271 + stationCode2Name.put(carPark.getParkCode(), carPark.getParkName());
  272 +
  273 + parkCodes.add(carPark.getParkCode());
  274 + }
  275 + parkCodeList = parkCodes;
  276 + stationCode2NameMap = stationCode2Name;
  277 + }
  278 +
  279 + /**
  280 + * @Title: loadNbbm2LineInfo
  281 + * @Description: TODO(车辆和线路对照)
  282 + */
  283 + public void loadNbbm2LineInfo() {
  284 + Iterator<CarConfigInfo> allIterator = carConfigInfoRepository.findAll().iterator();
  285 + Map<String, Line> ccMap = new HashMap<>();
  286 +
  287 + CarConfigInfo cci;
  288 + while (allIterator.hasNext()) {
  289 + cci = allIterator.next();
  290 + if(cci.getIsCancel())
  291 + continue;//排除已经报废的
  292 + ccMap.put(cci.getCl().getInsideCode(), cci.getXl());
  293 + }
  294 + nbbm2LineMap = ccMap;
  295 + }
  296 +
  297 + /**
  298 + * @Title: loadLineCodeHistoryNbbmMapInfo
  299 + * @Description: TODO(线路历史配车)
  300 + */
  301 + public void loadLineCodeHistoryNbbmMapInfo() {
  302 + Iterator<CarConfigInfo> allIterator = carConfigInfoRepository.findAll().iterator();
  303 + Map<String, List<String>> ccMap = new HashMap<>(); //用list保持排序
  304 + Map<String, Set<String>> sMap = new HashMap<>(); //用Set去重
  305 +
  306 + CarConfigInfo cci;
  307 + while (allIterator.hasNext()) {
  308 + cci = allIterator.next();
  309 + String lineCode = cci.getXl().getLineCode();
  310 + if(!ccMap.containsKey(lineCode)){
  311 + ccMap.put(lineCode, new ArrayList<String>());
  312 + sMap.put(lineCode, new HashSet<String>());
  313 + }
  314 + if(sMap.get(lineCode).add(cci.getCl().getInsideCode())){
  315 + ccMap.get(lineCode).add(cci.getCl().getInsideCode());
  316 + }
  317 + }
  318 + lineCodeHistoryNbbmMap = ccMap;
  319 + }
  320 +
  321 + /**
  322 + * @Title: loadLineInfo
  323 + * @Description: TODO(加载线路相关信息)
  324 + */
  325 + public void loadLineInfo() {
  326 + Iterator<Line> iterator = lineRepository.findAllLine().iterator();
  327 +
  328 + Line line;
  329 + BiMap<Integer, String> biMap = HashBiMap.create();
  330 + Map<String, String> code2name = new HashMap<>();
  331 + Map<String, String> name2code = new HashMap<>();
  332 + Map<Integer, String> id2SHcode = new HashMap<Integer, String>();
  333 + Map<String, String> code2SHcode = new HashMap<String, String>();
  334 + Map<String, Integer> tempStationName2YgcNumber = new HashMap<String, Integer>();
  335 +
  336 + /**
  337 + * 加载运管处的站点及序号
  338 + * 上行从1开始,下行顺序续编
  339 + */
  340 + List<Map<String, String>> ygcLines = stationRouteRepository.findAllLineWithYgc();
  341 + if(ygcLines != null && ygcLines.size() > 0){
  342 + int size = ygcLines.size();
  343 + Map<String, String> tempMap ;
  344 + int num = 1;
  345 + String key;
  346 + String lineCode = "";
  347 + for (int i = 0; i < size; i ++){
  348 + tempMap = ygcLines.get(i);
  349 + if(lineCode.equals("")){
  350 + lineCode = tempMap.get("lineCode");
  351 + }else if(!lineCode.equals(tempMap.get("lineCode"))){
  352 + num = 1;
  353 + lineCode = tempMap.get("lineCode");
  354 + }
  355 + key = tempMap.get("lineCode") + "_"+String.valueOf(tempMap.get("directions"))
  356 + + "_"+tempMap.get("stationCode")+ "_"+tempMap.get("stationMark");
  357 + tempStationName2YgcNumber.put(key,num++);
  358 + }
  359 + }
  360 +
  361 + while (iterator.hasNext()) {
  362 + line = iterator.next();
  363 + biMap.put(line.getId(), line.getLineCode());
  364 + code2name.put(line.getLineCode(), line.getName());
  365 + name2code.put(line.getName(), line.getLineCode());
  366 + id2SHcode.put(line.getId(), line.getShanghaiLinecode());
  367 + code2SHcode.put(line.getLineCode(), line.getShanghaiLinecode());
  368 + }
  369 +
  370 + // 特殊线路ID为0的数据 (小模块轨迹)
  371 + biMap.put(0, "0");
  372 + code2name.put("0", "0");
  373 +
  374 + lineId2CodeMap = biMap;
  375 + lineCode2NameMap = code2name;
  376 + lineName2CodeMap = name2code;
  377 + lineId2ShangHaiCodeMap = id2SHcode;
  378 + lineCode2ShangHaiCodeMap = code2SHcode;
  379 + stationName2YgcNumber = tempStationName2YgcNumber;
  380 +
  381 + Map<String, String> code2nameAll = new HashMap<>();
  382 + Iterator<Line> iteratorAll = lineRepository.findAll().iterator();
  383 + while (iteratorAll.hasNext()) {
  384 + line = iteratorAll.next();
  385 + code2nameAll.put(line.getLineCode(), line.getName());
  386 + }
  387 + lineCodeAllNameMap=code2nameAll;
  388 + }
  389 +
  390 + /**
  391 + * @Title: loadPersonnelInfo
  392 + * @Description: TODO(加载人员信息)
  393 + */
  394 + public void loadPersonnelInfo() {
  395 + Iterator<Personnel> iterator = personnelRepository.findAll().iterator();
  396 +
  397 + Map<String, Personnel> /*jsyTempMap = new HashMap<>(), spyTempMap = new HashMap<>(),*/perTempMap=new HashMap<>();
  398 + Map<String, String> allPersonMap = new HashMap<>();
  399 +
  400 + Personnel p;
  401 + String jobCode;
  402 + while (iterator.hasNext()) {
  403 + p = iterator.next();
  404 +
  405 + jobCode = p.getJobCode();
  406 + if (StringUtils.isEmpty(jobCode))
  407 + continue;
  408 +
  409 + /*if (p.getPosts() != null) {
  410 + if (p.getPosts().equals("1"))
  411 + jsyTempMap.put(jobCode, p);
  412 + else if (p.getPosts().equals("2"))
  413 + spyTempMap.put(jobCode, p);
  414 + }*/
  415 +
  416 + perTempMap.put(jobCode, p);
  417 +
  418 + allPersonMap.put(jobCode, p.getPersonnelName());
  419 + }
  420 +
  421 + //jsyMap = jsyTempMap;
  422 + //spyMap = spyTempMap;
  423 + allPerson = allPersonMap;
  424 + perMap = perTempMap;
  425 +
  426 + //人员拼音转换
  427 + persionPinYinBuffer.refresh();
  428 + }
  429 +
  430 + /**
  431 + * 加载线路级别信息 按当前日期取(当前+前后一天)的数据
  432 + */
  433 + public void loadLineLevel() {
  434 + List<String> dates = new ArrayList<>();
  435 + Map<String, String> result = new HashMap<>();
  436 + DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
  437 +
  438 + Calendar c = Calendar.getInstance();
  439 + c.setTime(new Date(System.currentTimeMillis() - 86400000));
  440 + dates.add(df.format(c.getTime()));
  441 +
  442 + for (int i = 0;i < 2;i++) {
  443 + c.add(Calendar.DATE, 1);
  444 + dates.add(df.format(c.getTime()));
  445 + }
  446 +
  447 + List<CalcInterval> l = calcIntervalRepository.selectByDates(dates);
  448 + for (CalcInterval ci : l) {
  449 + result.put(ci.getXlBm() + "_" + ci.getDate(), ci.getLevel());
  450 + }
  451 +
  452 + lineDate2Level = result;
  453 + }
  454 + }
  455 +}
... ...