Commit e5afeda5c3308a6a1cf4b5a4f2d9139bef00d8b8

Authored by 王通
1 parent 9c13d31f

1.IP白名单相关

src/main/java/com/bsth/Application.java
... ... @@ -17,7 +17,7 @@ import java.util.concurrent.ScheduledExecutorService;
17 17 @SpringBootApplication
18 18 public class Application extends SpringBootServletInitializer {
19 19  
20   - public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(18);
  20 + public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(20);
21 21  
22 22 @Override
23 23 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
... ...
src/main/java/com/bsth/XDApplication.java
... ... @@ -45,6 +45,8 @@ public class XDApplication implements CommandLineRunner {
45 45 @Autowired
46 46 BasicData.BasicDataLoader basicDataLoader;
47 47 @Autowired
  48 + BasicData.WhiteIpDataLoader whiteIpDataLoader;
  49 + @Autowired
48 50 UpdateDBThread fcxxUpdateThread;
49 51 @Autowired
50 52 ScheduleRefreshThread scheduleRefreshThread;
... ... @@ -155,6 +157,7 @@ public class XDApplication implements CommandLineRunner {
155 157 sexec.scheduleWithFixedDelay(threadMonotor, 240, 60, TimeUnit.SECONDS);//线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作)
156 158 sexec.scheduleWithFixedDelay(sampleTimeDataLoader, 140, 120 * 60, TimeUnit.SECONDS);//到离站预测需要的站点间耗时数据
157 159 sexec.scheduleWithFixedDelay(basicDataLoader, 1, 1, TimeUnit.HOURS);//基础数据更新
  160 + sexec.scheduleWithFixedDelay(whiteIpDataLoader, 0, 1, TimeUnit.MINUTES);//IP白名单数据更新
158 161 sexec.scheduleWithFixedDelay(autoExecScanThread, 180, 50, TimeUnit.SECONDS);//班次自动执行
159 162 //DirectivePushQueue.start();//消息队列 -指令,系统下发的
160 163 WebSocketPushQueue.start();//消息队列 -webSocket ,推送至线调web页面的
... ... @@ -199,6 +202,7 @@ public class XDApplication implements CommandLineRunner {
199 202 sexec.scheduleWithFixedDelay(threadMonotor, 240, 60, TimeUnit.SECONDS);//线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作)
200 203 sexec.scheduleWithFixedDelay(sampleTimeDataLoader, 140, 120 * 60, TimeUnit.SECONDS);//到离站预测需要的站点间耗时数据
201 204 sexec.scheduleWithFixedDelay(basicDataLoader, 1, 1, TimeUnit.HOURS);//基础数据更新
  205 + sexec.scheduleWithFixedDelay(whiteIpDataLoader, 0, 1, TimeUnit.MINUTES);//IP白名单数据更新
202 206 sexec.scheduleWithFixedDelay(autoExecScanThread, 180, 50, TimeUnit.SECONDS);//班次自动执行
203 207 DirectivePushQueue.start();//消息队列 -指令,系统下发的
204 208 WebSocketPushQueue.start();//消息队列 -webSocket ,推送至线调web页面的
... ... @@ -244,6 +248,7 @@ public class XDApplication implements CommandLineRunner {
244 248 sexec.scheduleWithFixedDelay(threadMonotor, 240, 60, TimeUnit.SECONDS);//线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作)
245 249 sexec.scheduleWithFixedDelay(sampleTimeDataLoader, 140, 120 * 60, TimeUnit.SECONDS);//到离站预测需要的站点间耗时数据
246 250 sexec.scheduleWithFixedDelay(basicDataLoader, 1, 1, TimeUnit.HOURS);//基础数据更新
  251 + sexec.scheduleWithFixedDelay(whiteIpDataLoader, 0, 1, TimeUnit.MINUTES);//IP白名单数据更新
247 252 sexec.scheduleWithFixedDelay(autoExecScanThread, 180, 50, TimeUnit.SECONDS);//班次自动执行
248 253 //DirectivePushQueue.start();//消息队列 -指令,系统下发的
249 254 WebSocketPushQueue.start();//消息队列 -webSocket ,推送至线调web页面的
... ...
src/main/java/com/bsth/common/Setting.java 0 → 100644
  1 +package com.bsth.common;
  2 +
  3 +import org.springframework.beans.factory.annotation.Value;
  4 +import org.springframework.stereotype.Component;
  5 +
  6 +@Component
  7 +public class Setting {
  8 +
  9 + @Value("${enabled.whiteip}")
  10 + private boolean whiteipEnabled;
  11 +
  12 + public boolean isWhiteipEnabled() {
  13 + return whiteipEnabled;
  14 + }
  15 +
  16 + public void setWhiteipEnabled(boolean whiteipEnabled) {
  17 + this.whiteipEnabled = whiteipEnabled;
  18 + }
  19 +}
... ...
src/main/java/com/bsth/controller/realcontrol/AdminUtilsController.java
... ... @@ -5,6 +5,8 @@ import java.lang.reflect.Modifier;
5 5 import java.text.SimpleDateFormat;
6 6 import java.util.*;
7 7  
  8 +import com.bsth.common.Setting;
  9 +import com.bsth.data.BasicData;
8 10 import com.bsth.service.schedule.utils.SpringUtils;
9 11 import com.bsth.util.MailUtils;
10 12 import com.fasterxml.jackson.core.JsonProcessingException;
... ... @@ -65,6 +67,12 @@ public class AdminUtilsController {
65 67 @Autowired
66 68 MailUtils mailUtils;
67 69  
  70 + @Autowired
  71 + BasicData.BasicDataLoader basicDataLoader;
  72 +
  73 + @Autowired
  74 + Setting setting;
  75 +
68 76 /**
69 77 * 出现重复班次的车辆
70 78 *
... ... @@ -292,4 +300,30 @@ public class AdminUtilsController {
292 300  
293 301 return "error";
294 302 }
  303 +
  304 + @RequestMapping("/refreshBasicAll")
  305 + public String refreshBasicAll() {
  306 + Map<String, Object> result = new HashMap<>();
  307 + try {
  308 + basicDataLoader.loadAllData();
  309 + return "success";
  310 + } catch (Exception e) {
  311 + e.printStackTrace();
  312 + }
  313 +
  314 + return "error";
  315 + }
  316 +
  317 + @RequestMapping("/whiteipSwitch")
  318 + public String whiteipSwitch(boolean whiteipEnabled) {
  319 + Map<String, Object> result = new HashMap<>();
  320 + try {
  321 + setting.setWhiteipEnabled(whiteipEnabled);
  322 + return "success";
  323 + } catch (Exception e) {
  324 + e.printStackTrace();
  325 + }
  326 +
  327 + return "error";
  328 + }
295 329 }
296 330 \ No newline at end of file
... ...
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 org.apache.commons.lang3.StringUtils;
16   -import org.slf4j.Logger;
17   -import org.slf4j.LoggerFactory;
18   -import org.springframework.beans.factory.annotation.Autowired;
19   -import org.springframework.stereotype.Component;
20   -
21   -import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
22   -import com.bsth.data.pinyin.PersionPinYinBuffer;
23   -import com.bsth.entity.Business;
24   -import com.bsth.entity.CarPark;
25   -import com.bsth.entity.Cars;
26   -import com.bsth.entity.Line;
27   -import com.bsth.entity.Personnel;
28   -import com.bsth.entity.StationRoute;
29   -import com.bsth.entity.calc.CalcInterval;
30   -import com.bsth.entity.schedule.CarConfigInfo;
31   -import com.bsth.repository.BusinessRepository;
32   -import com.bsth.repository.CarParkRepository;
33   -import com.bsth.repository.CarsRepository;
34   -import com.bsth.repository.LineRepository;
35   -import com.bsth.repository.PersonnelRepository;
36   -import com.bsth.repository.StationRepository;
37   -import com.bsth.repository.StationRouteRepository;
38   -import com.bsth.repository.calc.CalcIntervalRepository;
39   -import com.bsth.repository.schedule.CarConfigInfoRepository;
40   -import com.google.common.collect.BiMap;
41   -import com.google.common.collect.HashBiMap;
42   -
43   -/**
44   - * @author PanZhao
45   - * @ClassName: BasicData
46   - * @Description: TODO(基础的映射数据)
47   - * @date 2016年8月10日 下午3:27:45
48   - */
49   -@Component
50   -public class BasicData {
51   -
52   - //公司代码和公司名对照(K: 公司编码,V:公司名)
53   - public static Map<String, String> businessCodeNameMap;
54   -
55   - //分公司公司代码和分公司公司名对照(K: 分公司编码_公司编码,V:分公司公司名)
56   - public static Map<String, String> businessFgsCodeNameMap;
57   -
58   - //设备号和车辆自编号 (K: 设备编码 ,V:车辆自编号)
59   - public static BiMap<String, String> deviceId2NbbmMap;
60   -
61   - //车辆自编号和公司代码对照 (K: 车辆自编号 ,V:公司代码)
62   - public static Map<String, String> nbbm2CompanyCodeMap;
63   -
64   - //车辆自编号和分公司代码对照 (K: 车辆自编号 ,V:分公司编码_公司编码)
65   - public static Map<String, String> nbbm2FgsCompanyCodeMap;
66   -
67   - //车辆自编号和牌照号对照 (K: 车辆自编号 ,V:牌照号)
68   - public static Map<String, String> nbbmCompanyPlateMap;
69   -
70   - //站点编码和名称对照,包括停车场 (K: lineCode_updown_stationCode ,V:站点名称)
71   - public static Map<String, String> stationCode2NameMap;
72   -
73   - //车辆和线路对照
74   - public static Map<String, Line> nbbm2LineMap;
75   -
76   - //线路历史配车(K: 线路编码 ,V:List<车辆自编号>)
77   - public static Map<String, List<String>> lineCodeHistoryNbbmMap;
78   -
79   - //线路ID和code 对照
80   - public static BiMap<Integer, String> lineId2CodeMap;
81   -
82   - //线路编码和名称对照
83   - public static Map<String, String> lineCode2NameMap;
84   -
85   - public static Map<String, String> lineCodeAllNameMap;
86   - //停车场
87   - public static List<String> parkCodeList;
88   -
89   - //线路ID和shangHaiLinecode 对照
90   - public static Map<Integer, String> lineId2ShangHaiCodeMap;
91   -
92   - //线路Code和shangHaiLinecode 对照
93   - public static Map<String, String> lineCode2ShangHaiCodeMap;
94   -
95   - /*//驾驶员工号 和 personnel 对象映射
96   - public static Map<String, Personnel> jsyMap;
97   - //售票员工号 和 personnel 对象映射
98   - public static Map<String, Personnel> spyMap;*/
99   - //所以员工和personnerl 对象映射
100   - public static Map<String, Personnel> perMap;
101   - //全量员工 工号和姓名对照
102   - public static Map<String, String> allPerson;
103   -
104   - //站点名和运管处编号 对照
105   - public static Map<String, Integer> stationName2YgcNumber;
106   -
107   - // 线路编码_日期 等级
108   - public static Map<String, String> lineDate2Level;
109   -
110   - static Logger logger = LoggerFactory.getLogger(BasicData.class);
111   -
112   - public static String getStationNameByCode(String code, String prefix){
113   - String name = stationCode2NameMap.get(code);
114   - return name != null? name: stationCode2NameMap.get(prefix + code);
115   - }
116   -
117   -/* @Autowired
118   - JdbcTemplate jdbcTemplate;
119   - public Map<String, String> getNbbm2PlateNo(){
120   - 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");
121   -
122   - Map<String, String> rs = new HashMap<>();
123   - for(Map<String, Object> map : list){
124   - rs.put(map.get("CAR_CODE").toString(), map.get("CAR_PLATE").toString());
125   - }
126   - return rs;
127   - }*/
128   -
129   - @Component
130   - public static class BasicDataLoader extends Thread {
131   -
132   - @Autowired
133   - CarsRepository carsRepository;
134   -
135   - @Autowired
136   - StationRepository stationRepository;
137   -
138   - @Autowired
139   - CarParkRepository carParkRepository;
140   -
141   - @Autowired
142   - CarConfigInfoRepository carConfigInfoRepository;
143   -
144   - @Autowired
145   - LineRepository lineRepository;
146   -
147   - @Autowired
148   - StationRouteRepository stationRouteRepository;
149   -
150   - @Autowired
151   - PersonnelRepository personnelRepository;
152   -
153   - @Autowired
154   - BusinessRepository businessRepository;
155   -
156   - @Autowired
157   - GeoCacheData geoCacheData;
158   -
159   - @Autowired
160   - Station2ParkBuffer station2ParkBuffer;
161   -
162   - @Autowired
163   - PersionPinYinBuffer persionPinYinBuffer;
164   -
165   - @Autowired
166   - CalcIntervalRepository calcIntervalRepository;
167   -
168   - @Override
169   - public void run() {
170   - loadAllData();
171   - }
172   -
173   - /**
174   - * @Title: loadAllData
175   - * @Description: TODO(加载所有数据)
176   - */
177   - public int loadAllData() {
178   - try {
179   - logger.info("开始加载基础数据..,");
180   - //设备信息
181   - loadDeviceInfo();
182   - //站点信息
183   - loadStationInfo();
184   - //线路信息
185   - loadLineInfo();
186   - //车辆和线路映射信息
187   - loadNbbm2LineInfo();
188   - loadLineCodeHistoryNbbmMapInfo();
189   - //人员信息
190   - loadPersonnelInfo();
191   - //公司信息
192   - loadBusinessInfo();
193   - // 线路等级信息
194   - loadLineLevel();
195   -
196   - logger.info("load geo cache..,");
197   - geoCacheData.loadData();
198   - station2ParkBuffer.saveAll();
199   - logger.info("加载基础数据成功!,");
200   - } catch (Exception e) {
201   - logger.error("加载基础数据时出现异常,", e);
202   - }
203   - return 0;
204   - }
205   -
206   - /**
207   - * loadBusinessInfo
208   - * (公司代码公司名对照)
209   - */
210   - public void loadBusinessInfo() {
211   - Map<String, String> businessMap = new HashMap<String, String>();
212   - Map<String, String> businessFgsMap = new HashMap<String, String>();
213   - Iterator<Business> busIter = businessRepository.findAll().iterator();
214   - Business t;
215   - while (busIter.hasNext()) {
216   - t = busIter.next();
217   - businessMap.put(t.getBusinessCode(), t.getBusinessName());
218   - businessFgsMap.put(t.getBusinessCode() + "_" + t.getUpCode(), t.getBusinessName());
219   - }
220   - businessCodeNameMap = businessMap;
221   - businessFgsCodeNameMap = businessFgsMap;
222   - }
223   -
224   - /**
225   - * @Title: loadDeviceInfo
226   - * @Description: TODO(加载设备相关信息)
227   - */
228   - public void loadDeviceInfo() {
229   - BiMap<String, String> deviceId2Nbbm = HashBiMap.create();
230   - //车辆和公司代码对照
231   - Map<String, String> nbbm2CompanyCode = new HashMap<>();
232   - //车辆和分公司代码对照
233   - Map<String, String> nbbm2FgsCompanyCode = new HashMap<>();
234   -
235   - //车辆自编号和拍照号对照
236   - Map<String, String> nbbmCompanyPlate = new HashMap<>();
237   -
238   - Iterator<Cars> carIterator = carsRepository.findAll().iterator();
239   - Cars car;
240   - while (carIterator.hasNext()) {
241   - car = carIterator.next();
242   - deviceId2Nbbm.put(car.getEquipmentCode(), car.getInsideCode());
243   - nbbm2CompanyCode.put(car.getInsideCode(), car.getBusinessCode());
244   - nbbm2FgsCompanyCode.put(car.getInsideCode(), car.getBrancheCompanyCode() + "_" + car.getBusinessCode() );
245   - nbbmCompanyPlate.put(car.getInsideCode(), car.getCarPlate());
246   - }
247   -
248   - deviceId2NbbmMap = deviceId2Nbbm;
249   - nbbm2CompanyCodeMap = nbbm2CompanyCode;
250   - nbbm2FgsCompanyCodeMap = nbbm2FgsCompanyCode;
251   - nbbmCompanyPlateMap =nbbmCompanyPlate;
252   - }
253   -
254   - /**
255   - * @Title: loadStationInfo
256   - * @Description: TODO(加载站点信息)
257   - */
258   - public void loadStationInfo() {
259   - Map<String, String> stationCode2Name = new HashMap<>();
260   - Iterator<StationRoute> iterator = stationRouteRepository.findAll().iterator();
261   - StationRoute sroute;
262   - while (iterator.hasNext()) {
263   - sroute = iterator.next();
264   - stationCode2Name.put(sroute.getLineCode() + "_" + sroute.getDirections() + "_" + sroute.getStationCode(), sroute.getStationName());
265   - }
266   -
267   - //停车场
268   - Iterator<CarPark> iterator2 = carParkRepository.findAll().iterator();
269   -
270   - List<String> parkCodes = new ArrayList<>();
271   -
272   - CarPark carPark;
273   - while (iterator2.hasNext()) {
274   - carPark = iterator2.next();
275   - stationCode2Name.put(carPark.getParkCode(), carPark.getParkName());
276   -
277   - parkCodes.add(carPark.getParkCode());
278   - }
279   - parkCodeList = parkCodes;
280   - stationCode2NameMap = stationCode2Name;
281   - }
282   -
283   - /**
284   - * @Title: loadNbbm2LineInfo
285   - * @Description: TODO(车辆和线路对照)
286   - */
287   - public void loadNbbm2LineInfo() {
288   - Iterator<CarConfigInfo> allIterator = carConfigInfoRepository.findAll().iterator();
289   - Map<String, Line> ccMap = new HashMap<>();
290   -
291   - CarConfigInfo cci;
292   - while (allIterator.hasNext()) {
293   - cci = allIterator.next();
294   - if(cci.getIsCancel())
295   - continue;//排除已经报废的
296   - ccMap.put(cci.getCl().getInsideCode(), cci.getXl());
297   - }
298   - nbbm2LineMap = ccMap;
299   - }
300   -
301   - /**
302   - * @Title: loadLineCodeHistoryNbbmMapInfo
303   - * @Description: TODO(线路历史配车)
304   - */
305   - public void loadLineCodeHistoryNbbmMapInfo() {
306   - Iterator<CarConfigInfo> allIterator = carConfigInfoRepository.findAll().iterator();
307   - Map<String, List<String>> ccMap = new HashMap<>(); //用list保持排序
308   - Map<String, Set<String>> sMap = new HashMap<>(); //用Set去重
309   -
310   - CarConfigInfo cci;
311   - while (allIterator.hasNext()) {
312   - cci = allIterator.next();
313   - String lineCode = cci.getXl().getLineCode();
314   - if(!ccMap.containsKey(lineCode)){
315   - ccMap.put(lineCode, new ArrayList<String>());
316   - sMap.put(lineCode, new HashSet<String>());
317   - }
318   - if(sMap.get(lineCode).add(cci.getCl().getInsideCode())){
319   - ccMap.get(lineCode).add(cci.getCl().getInsideCode());
320   - }
321   - }
322   - lineCodeHistoryNbbmMap = ccMap;
323   - }
324   -
325   - /**
326   - * @Title: loadLineInfo
327   - * @Description: TODO(加载线路相关信息)
328   - */
329   - public void loadLineInfo() {
330   - Iterator<Line> iterator = lineRepository.findAllService().iterator();
331   -
332   - Line line;
333   - BiMap<Integer, String> biMap = HashBiMap.create();
334   - Map<String, String> code2name = new HashMap<>();
335   - Map<Integer, String> id2SHcode = new HashMap<Integer, String>();
336   - Map<String, String> code2SHcode = new HashMap<String, String>();
337   - Map<String, Integer> tempStationName2YgcNumber = new HashMap<String, Integer>();
338   -
339   - /**
340   - * 加载运管处的站点及序号
341   - * 上行从1开始,下行顺序续编
342   - */
343   - List<Map<String, String>> ygcLines = stationRouteRepository.findAllLineWithYgc();
344   - if(ygcLines != null && ygcLines.size() > 0){
345   - int size = ygcLines.size();
346   - Map<String, String> tempMap ;
347   - int num = 1;
348   - String key;
349   - String lineCode = "";
350   - for (int i = 0; i < size; i ++){
351   - tempMap = ygcLines.get(i);
352   - if(lineCode.equals("")){
353   - lineCode = tempMap.get("lineCode");
354   - }else if(!lineCode.equals(tempMap.get("lineCode"))){
355   - num = 1;
356   - lineCode = tempMap.get("lineCode");
357   - }
358   - key = tempMap.get("lineCode") + "_"+String.valueOf(tempMap.get("directions"))
359   - + "_"+tempMap.get("stationCode")+ "_"+tempMap.get("stationMark");
360   - tempStationName2YgcNumber.put(key,num++);
361   - }
362   - }
363   -
364   - while (iterator.hasNext()) {
365   - line = iterator.next();
366   - biMap.put(line.getId(), line.getLineCode());
367   - code2name.put(line.getLineCode(), line.getName());
368   - id2SHcode.put(line.getId(), line.getShanghaiLinecode());
369   - code2SHcode.put(line.getLineCode(), line.getShanghaiLinecode());
370   - }
371   -
372   - lineId2CodeMap = biMap;
373   - lineCode2NameMap = code2name;
374   - lineId2ShangHaiCodeMap = id2SHcode;
375   - lineCode2ShangHaiCodeMap = code2SHcode;
376   - stationName2YgcNumber = tempStationName2YgcNumber;
377   -
378   - Map<String, String> code2nameAll = new HashMap<>();
379   - Iterator<Line> iteratorAll = lineRepository.findAll().iterator();
380   - while (iteratorAll.hasNext()) {
381   - line = iteratorAll.next();
382   - code2nameAll.put(line.getLineCode(), line.getName());
383   - }
384   - lineCodeAllNameMap=code2nameAll;
385   - }
386   -
387   - /**
388   - * @Title: loadPersonnelInfo
389   - * @Description: TODO(加载人员信息)
390   - */
391   - public void loadPersonnelInfo() {
392   - Iterator<Personnel> iterator = personnelRepository.findAll().iterator();
393   -
394   - Map<String, Personnel> /*jsyTempMap = new HashMap<>(), spyTempMap = new HashMap<>(),*/perTempMap=new HashMap<>();
395   - Map<String, String> allPersonMap = new HashMap<>();
396   -
397   - Personnel p;
398   - String jobCode;
399   - while (iterator.hasNext()) {
400   - p = iterator.next();
401   -
402   - jobCode = p.getJobCode();
403   - if (StringUtils.isEmpty(jobCode))
404   - continue;
405   -
406   - /*if (p.getPosts() != null) {
407   - if (p.getPosts().equals("1"))
408   - jsyTempMap.put(jobCode, p);
409   - else if (p.getPosts().equals("2"))
410   - spyTempMap.put(jobCode, p);
411   - }*/
412   -
413   - perTempMap.put(jobCode, p);
414   -
415   - allPersonMap.put(jobCode, p.getPersonnelName());
416   - }
417   -
418   - //jsyMap = jsyTempMap;
419   - //spyMap = spyTempMap;
420   - allPerson = allPersonMap;
421   - perMap = perTempMap;
422   -
423   - //人员拼音转换
424   - persionPinYinBuffer.refresh();
425   - }
426   -
427   - /**
428   - * 加载线路级别信息 按当前日期取(当前+前后一天)的数据
429   - */
430   - public void loadLineLevel() {
431   - List<String> dates = new ArrayList<>();
432   - Map<String, String> result = new HashMap<>();
433   - DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
434   -
435   - Calendar c = Calendar.getInstance();
436   - c.setTime(new Date(System.currentTimeMillis() - 86400000));
437   - dates.add(df.format(c.getTime()));
438   -
439   - for (int i = 0;i < 2;i++) {
440   - c.add(Calendar.DATE, 1);
441   - dates.add(df.format(c.getTime()));
442   - }
443   -
444   - List<CalcInterval> l = calcIntervalRepository.selectByDates(dates);
445   - for (CalcInterval ci : l) {
446   - result.put(ci.getXlBm() + "_" + ci.getDate(), ci.getLevel());
447   - }
448   -
449   - lineDate2Level = result;
450   - }
451   - }
452   -}
  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 org.apache.commons.lang3.StringUtils;
  17 +import org.slf4j.Logger;
  18 +import org.slf4j.LoggerFactory;
  19 +import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.jdbc.core.BeanPropertyRowMapper;
  21 +import org.springframework.jdbc.core.JdbcTemplate;
  22 +import org.springframework.stereotype.Component;
  23 +
  24 +import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
  25 +import com.bsth.data.pinyin.PersionPinYinBuffer;
  26 +import com.bsth.entity.calc.CalcInterval;
  27 +import com.bsth.entity.schedule.CarConfigInfo;
  28 +import com.bsth.repository.BusinessRepository;
  29 +import com.bsth.repository.CarParkRepository;
  30 +import com.bsth.repository.CarsRepository;
  31 +import com.bsth.repository.LineRepository;
  32 +import com.bsth.repository.PersonnelRepository;
  33 +import com.bsth.repository.StationRepository;
  34 +import com.bsth.repository.StationRouteRepository;
  35 +import com.bsth.repository.calc.CalcIntervalRepository;
  36 +import com.bsth.repository.schedule.CarConfigInfoRepository;
  37 +import com.google.common.collect.BiMap;
  38 +import com.google.common.collect.HashBiMap;
  39 +
  40 +/**
  41 + * @author PanZhao
  42 + * @ClassName: BasicData
  43 + * @Description: TODO(基础的映射数据)
  44 + * @date 2016年8月10日 下午3:27:45
  45 + */
  46 +@Component
  47 +public class BasicData {
  48 +
  49 + //公司代码和公司名对照(K: 公司编码,V:公司名)
  50 + public static Map<String, String> businessCodeNameMap;
  51 +
  52 + //分公司公司代码和分公司公司名对照(K: 分公司编码_公司编码,V:分公司公司名)
  53 + public static Map<String, String> businessFgsCodeNameMap;
  54 +
  55 + //设备号和车辆自编号 (K: 设备编码 ,V:车辆自编号)
  56 + public static BiMap<String, String> deviceId2NbbmMap;
  57 +
  58 + //车辆自编号和公司代码对照 (K: 车辆自编号 ,V:公司代码)
  59 + public static Map<String, String> nbbm2CompanyCodeMap;
  60 +
  61 + //车辆自编号和分公司代码对照 (K: 车辆自编号 ,V:分公司编码_公司编码)
  62 + public static Map<String, String> nbbm2FgsCompanyCodeMap;
  63 +
  64 + //车辆自编号和牌照号对照 (K: 车辆自编号 ,V:牌照号)
  65 + public static Map<String, String> nbbmCompanyPlateMap;
  66 +
  67 + //站点编码和名称对照,包括停车场 (K: lineCode_updown_stationCode ,V:站点名称)
  68 + public static Map<String, String> stationCode2NameMap;
  69 +
  70 + //车辆和线路对照
  71 + public static Map<String, Line> nbbm2LineMap;
  72 +
  73 + //线路历史配车(K: 线路编码 ,V:List<车辆自编号>)
  74 + public static Map<String, List<String>> lineCodeHistoryNbbmMap;
  75 +
  76 + //线路ID和code 对照
  77 + public static BiMap<Integer, String> lineId2CodeMap;
  78 +
  79 + //线路编码和名称对照
  80 + public static Map<String, String> lineCode2NameMap;
  81 +
  82 + public static Map<String, String> lineCodeAllNameMap;
  83 + //停车场
  84 + public static List<String> parkCodeList;
  85 +
  86 + //线路ID和shangHaiLinecode 对照
  87 + public static Map<Integer, String> lineId2ShangHaiCodeMap;
  88 +
  89 + //线路Code和shangHaiLinecode 对照
  90 + public static Map<String, String> lineCode2ShangHaiCodeMap;
  91 +
  92 + /*//驾驶员工号 和 personnel 对象映射
  93 + public static Map<String, Personnel> jsyMap;
  94 + //售票员工号 和 personnel 对象映射
  95 + public static Map<String, Personnel> spyMap;*/
  96 + //所以员工和personnerl 对象映射
  97 + public static Map<String, Personnel> perMap;
  98 + //全量员工 工号和姓名对照
  99 + public static Map<String, String> allPerson;
  100 +
  101 + //站点名和运管处编号 对照
  102 + public static Map<String, Integer> stationName2YgcNumber;
  103 +
  104 + // 线路编码_日期 等级
  105 + public static Map<String, String> lineDate2Level;
  106 +
  107 + public static List<WhiteIp> whiteIpList;
  108 +
  109 + static Logger logger = LoggerFactory.getLogger(BasicData.class);
  110 +
  111 + public static String getStationNameByCode(String code, String prefix){
  112 + String name = stationCode2NameMap.get(code);
  113 + return name != null? name: stationCode2NameMap.get(prefix + code);
  114 + }
  115 +
  116 +/* @Autowired
  117 + JdbcTemplate jdbcTemplate;
  118 + public Map<String, String> getNbbm2PlateNo(){
  119 + 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");
  120 +
  121 + Map<String, String> rs = new HashMap<>();
  122 + for(Map<String, Object> map : list){
  123 + rs.put(map.get("CAR_CODE").toString(), map.get("CAR_PLATE").toString());
  124 + }
  125 + return rs;
  126 + }*/
  127 +
  128 + @Component
  129 + public static class BasicDataLoader extends Thread {
  130 +
  131 + @Autowired
  132 + CarsRepository carsRepository;
  133 +
  134 + @Autowired
  135 + StationRepository stationRepository;
  136 +
  137 + @Autowired
  138 + CarParkRepository carParkRepository;
  139 +
  140 + @Autowired
  141 + CarConfigInfoRepository carConfigInfoRepository;
  142 +
  143 + @Autowired
  144 + LineRepository lineRepository;
  145 +
  146 + @Autowired
  147 + StationRouteRepository stationRouteRepository;
  148 +
  149 + @Autowired
  150 + PersonnelRepository personnelRepository;
  151 +
  152 + @Autowired
  153 + BusinessRepository businessRepository;
  154 +
  155 + @Autowired
  156 + GeoCacheData geoCacheData;
  157 +
  158 + @Autowired
  159 + Station2ParkBuffer station2ParkBuffer;
  160 +
  161 + @Autowired
  162 + PersionPinYinBuffer persionPinYinBuffer;
  163 +
  164 + @Autowired
  165 + CalcIntervalRepository calcIntervalRepository;
  166 +
  167 + @Override
  168 + public void run() {
  169 + loadAllData();
  170 + }
  171 +
  172 + /**
  173 + * @Title: loadAllData
  174 + * @Description: TODO(加载所有数据)
  175 + */
  176 + public int loadAllData() {
  177 + try {
  178 + logger.info("开始加载基础数据..,");
  179 + //设备信息
  180 + loadDeviceInfo();
  181 + //站点信息
  182 + loadStationInfo();
  183 + //线路信息
  184 + loadLineInfo();
  185 + //车辆和线路映射信息
  186 + loadNbbm2LineInfo();
  187 + loadLineCodeHistoryNbbmMapInfo();
  188 + //人员信息
  189 + loadPersonnelInfo();
  190 + //公司信息
  191 + loadBusinessInfo();
  192 + // 线路等级信息
  193 + loadLineLevel();
  194 +
  195 + logger.info("load geo cache..,");
  196 + geoCacheData.loadData();
  197 + station2ParkBuffer.saveAll();
  198 + logger.info("加载基础数据成功!,");
  199 + } catch (Exception e) {
  200 + logger.error("加载基础数据时出现异常,", e);
  201 + }
  202 + return 0;
  203 + }
  204 +
  205 + /**
  206 + * loadBusinessInfo
  207 + * (公司代码公司名对照)
  208 + */
  209 + public void loadBusinessInfo() {
  210 + Map<String, String> businessMap = new HashMap<String, String>();
  211 + Map<String, String> businessFgsMap = new HashMap<String, String>();
  212 + Iterator<Business> busIter = businessRepository.findAll().iterator();
  213 + Business t;
  214 + while (busIter.hasNext()) {
  215 + t = busIter.next();
  216 + businessMap.put(t.getBusinessCode(), t.getBusinessName());
  217 + businessFgsMap.put(t.getBusinessCode() + "_" + t.getUpCode(), t.getBusinessName());
  218 + }
  219 + businessCodeNameMap = businessMap;
  220 + businessFgsCodeNameMap = businessFgsMap;
  221 + }
  222 +
  223 + /**
  224 + * @Title: loadDeviceInfo
  225 + * @Description: TODO(加载设备相关信息)
  226 + */
  227 + public void loadDeviceInfo() {
  228 + BiMap<String, String> deviceId2Nbbm = HashBiMap.create();
  229 + //车辆和公司代码对照
  230 + Map<String, String> nbbm2CompanyCode = new HashMap<>();
  231 + //车辆和分公司代码对照
  232 + Map<String, String> nbbm2FgsCompanyCode = new HashMap<>();
  233 +
  234 + //车辆自编号和拍照号对照
  235 + Map<String, String> nbbmCompanyPlate = new HashMap<>();
  236 +
  237 + Iterator<Cars> carIterator = carsRepository.findAll().iterator();
  238 + Cars car;
  239 + while (carIterator.hasNext()) {
  240 + car = carIterator.next();
  241 + deviceId2Nbbm.put(car.getEquipmentCode(), car.getInsideCode());
  242 + nbbm2CompanyCode.put(car.getInsideCode(), car.getBusinessCode());
  243 + nbbm2FgsCompanyCode.put(car.getInsideCode(), car.getBrancheCompanyCode() + "_" + car.getBusinessCode() );
  244 + nbbmCompanyPlate.put(car.getInsideCode(), car.getCarPlate());
  245 + }
  246 +
  247 + deviceId2NbbmMap = deviceId2Nbbm;
  248 + nbbm2CompanyCodeMap = nbbm2CompanyCode;
  249 + nbbm2FgsCompanyCodeMap = nbbm2FgsCompanyCode;
  250 + nbbmCompanyPlateMap =nbbmCompanyPlate;
  251 + }
  252 +
  253 + /**
  254 + * @Title: loadStationInfo
  255 + * @Description: TODO(加载站点信息)
  256 + */
  257 + public void loadStationInfo() {
  258 + Map<String, String> stationCode2Name = new HashMap<>();
  259 + Iterator<StationRoute> iterator = stationRouteRepository.findAll().iterator();
  260 + StationRoute sroute;
  261 + while (iterator.hasNext()) {
  262 + sroute = iterator.next();
  263 + stationCode2Name.put(sroute.getLineCode() + "_" + sroute.getDirections() + "_" + sroute.getStationCode(), sroute.getStationName());
  264 + }
  265 +
  266 + //停车场
  267 + Iterator<CarPark> iterator2 = carParkRepository.findAll().iterator();
  268 +
  269 + List<String> parkCodes = new ArrayList<>();
  270 +
  271 + CarPark carPark;
  272 + while (iterator2.hasNext()) {
  273 + carPark = iterator2.next();
  274 + stationCode2Name.put(carPark.getParkCode(), carPark.getParkName());
  275 +
  276 + parkCodes.add(carPark.getParkCode());
  277 + }
  278 + parkCodeList = parkCodes;
  279 + stationCode2NameMap = stationCode2Name;
  280 + }
  281 +
  282 + /**
  283 + * @Title: loadNbbm2LineInfo
  284 + * @Description: TODO(车辆和线路对照)
  285 + */
  286 + public void loadNbbm2LineInfo() {
  287 + Iterator<CarConfigInfo> allIterator = carConfigInfoRepository.findAll().iterator();
  288 + Map<String, Line> ccMap = new HashMap<>();
  289 +
  290 + CarConfigInfo cci;
  291 + while (allIterator.hasNext()) {
  292 + cci = allIterator.next();
  293 + if(cci.getIsCancel())
  294 + continue;//排除已经报废的
  295 + ccMap.put(cci.getCl().getInsideCode(), cci.getXl());
  296 + }
  297 + nbbm2LineMap = ccMap;
  298 + }
  299 +
  300 + /**
  301 + * @Title: loadLineCodeHistoryNbbmMapInfo
  302 + * @Description: TODO(线路历史配车)
  303 + */
  304 + public void loadLineCodeHistoryNbbmMapInfo() {
  305 + Iterator<CarConfigInfo> allIterator = carConfigInfoRepository.findAll().iterator();
  306 + Map<String, List<String>> ccMap = new HashMap<>(); //用list保持排序
  307 + Map<String, Set<String>> sMap = new HashMap<>(); //用Set去重
  308 +
  309 + CarConfigInfo cci;
  310 + while (allIterator.hasNext()) {
  311 + cci = allIterator.next();
  312 + String lineCode = cci.getXl().getLineCode();
  313 + if(!ccMap.containsKey(lineCode)){
  314 + ccMap.put(lineCode, new ArrayList<String>());
  315 + sMap.put(lineCode, new HashSet<String>());
  316 + }
  317 + if(sMap.get(lineCode).add(cci.getCl().getInsideCode())){
  318 + ccMap.get(lineCode).add(cci.getCl().getInsideCode());
  319 + }
  320 + }
  321 + lineCodeHistoryNbbmMap = ccMap;
  322 + }
  323 +
  324 + /**
  325 + * @Title: loadLineInfo
  326 + * @Description: TODO(加载线路相关信息)
  327 + */
  328 + public void loadLineInfo() {
  329 + Iterator<Line> iterator = lineRepository.findAllService().iterator();
  330 +
  331 + Line line;
  332 + BiMap<Integer, String> biMap = HashBiMap.create();
  333 + Map<String, String> code2name = new HashMap<>();
  334 + Map<Integer, String> id2SHcode = new HashMap<Integer, String>();
  335 + Map<String, String> code2SHcode = new HashMap<String, String>();
  336 + Map<String, Integer> tempStationName2YgcNumber = new HashMap<String, Integer>();
  337 +
  338 + /**
  339 + * 加载运管处的站点及序号
  340 + * 上行从1开始,下行顺序续编
  341 + */
  342 + List<Map<String, String>> ygcLines = stationRouteRepository.findAllLineWithYgc();
  343 + if(ygcLines != null && ygcLines.size() > 0){
  344 + int size = ygcLines.size();
  345 + Map<String, String> tempMap ;
  346 + int num = 1;
  347 + String key;
  348 + String lineCode = "";
  349 + for (int i = 0; i < size; i ++){
  350 + tempMap = ygcLines.get(i);
  351 + if(lineCode.equals("")){
  352 + lineCode = tempMap.get("lineCode");
  353 + }else if(!lineCode.equals(tempMap.get("lineCode"))){
  354 + num = 1;
  355 + lineCode = tempMap.get("lineCode");
  356 + }
  357 + key = tempMap.get("lineCode") + "_"+String.valueOf(tempMap.get("directions"))
  358 + + "_"+tempMap.get("stationCode")+ "_"+tempMap.get("stationMark");
  359 + tempStationName2YgcNumber.put(key,num++);
  360 + }
  361 + }
  362 +
  363 + while (iterator.hasNext()) {
  364 + line = iterator.next();
  365 + biMap.put(line.getId(), line.getLineCode());
  366 + code2name.put(line.getLineCode(), line.getName());
  367 + id2SHcode.put(line.getId(), line.getShanghaiLinecode());
  368 + code2SHcode.put(line.getLineCode(), line.getShanghaiLinecode());
  369 + }
  370 +
  371 + lineId2CodeMap = biMap;
  372 + lineCode2NameMap = code2name;
  373 + lineId2ShangHaiCodeMap = id2SHcode;
  374 + lineCode2ShangHaiCodeMap = code2SHcode;
  375 + stationName2YgcNumber = tempStationName2YgcNumber;
  376 +
  377 + Map<String, String> code2nameAll = new HashMap<>();
  378 + Iterator<Line> iteratorAll = lineRepository.findAll().iterator();
  379 + while (iteratorAll.hasNext()) {
  380 + line = iteratorAll.next();
  381 + code2nameAll.put(line.getLineCode(), line.getName());
  382 + }
  383 + lineCodeAllNameMap=code2nameAll;
  384 + }
  385 +
  386 + /**
  387 + * @Title: loadPersonnelInfo
  388 + * @Description: TODO(加载人员信息)
  389 + */
  390 + public void loadPersonnelInfo() {
  391 + Iterator<Personnel> iterator = personnelRepository.findAll().iterator();
  392 +
  393 + Map<String, Personnel> /*jsyTempMap = new HashMap<>(), spyTempMap = new HashMap<>(),*/perTempMap=new HashMap<>();
  394 + Map<String, String> allPersonMap = new HashMap<>();
  395 +
  396 + Personnel p;
  397 + String jobCode;
  398 + while (iterator.hasNext()) {
  399 + p = iterator.next();
  400 +
  401 + jobCode = p.getJobCode();
  402 + if (StringUtils.isEmpty(jobCode))
  403 + continue;
  404 +
  405 + /*if (p.getPosts() != null) {
  406 + if (p.getPosts().equals("1"))
  407 + jsyTempMap.put(jobCode, p);
  408 + else if (p.getPosts().equals("2"))
  409 + spyTempMap.put(jobCode, p);
  410 + }*/
  411 +
  412 + perTempMap.put(jobCode, p);
  413 +
  414 + allPersonMap.put(jobCode, p.getPersonnelName());
  415 + }
  416 +
  417 + //jsyMap = jsyTempMap;
  418 + //spyMap = spyTempMap;
  419 + allPerson = allPersonMap;
  420 + perMap = perTempMap;
  421 +
  422 + //人员拼音转换
  423 + persionPinYinBuffer.refresh();
  424 + }
  425 +
  426 + /**
  427 + * 加载线路级别信息 按当前日期取(当前+前后一天)的数据
  428 + */
  429 + public void loadLineLevel() {
  430 + List<String> dates = new ArrayList<>();
  431 + Map<String, String> result = new HashMap<>();
  432 + DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
  433 +
  434 + Calendar c = Calendar.getInstance();
  435 + c.setTime(new Date(System.currentTimeMillis() - 86400000));
  436 + dates.add(df.format(c.getTime()));
  437 +
  438 + for (int i = 0;i < 2;i++) {
  439 + c.add(Calendar.DATE, 1);
  440 + dates.add(df.format(c.getTime()));
  441 + }
  442 +
  443 + List<CalcInterval> l = calcIntervalRepository.selectByDates(dates);
  444 + for (CalcInterval ci : l) {
  445 + result.put(ci.getXlBm() + "_" + ci.getDate(), ci.getLevel());
  446 + }
  447 +
  448 + lineDate2Level = result;
  449 + }
  450 + }
  451 +
  452 + @Component
  453 + public static class WhiteIpDataLoader extends Thread {
  454 + @Autowired
  455 + JdbcTemplate jdbcTemplate;
  456 +
  457 + @Override
  458 + public void run() {
  459 + // IP白名单
  460 + loadData();
  461 + }
  462 +
  463 + /**
  464 + * @Title: loadAllData
  465 + * @Description: TODO(加载所有数据)
  466 + */
  467 + public int loadData() {
  468 + try {
  469 + logger.info("开始加载IP白名单数据..,");
  470 + loadWhiteIp();
  471 + logger.info("加载IP白名单数据成功!,");
  472 + } catch (Exception e) {
  473 + logger.error("加载IP白名单数据时出现异常,", e);
  474 + }
  475 + return 0;
  476 + }
  477 +
  478 + /**
  479 + * 加载IP白名单
  480 + */
  481 + public void loadWhiteIp() {
  482 + List<WhiteIp> result = jdbcTemplate.query("select * from control_interface.bsth_c_white_ip where valid_date > now()", BeanPropertyRowMapper.newInstance(WhiteIp.class));
  483 + whiteIpList = result;
  484 + }
  485 + }
  486 +}
... ...
src/main/java/com/bsth/entity/WhiteIp.java 0 → 100644
  1 +package com.bsth.entity;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonIgnore;
  4 +
  5 +import java.util.Date;
  6 +
  7 +
  8 +/**
  9 + * @author Hill
  10 + */
  11 +public class WhiteIp {
  12 +
  13 + @JsonIgnore
  14 + private Integer id;
  15 +
  16 + private String ip;
  17 +
  18 + private String commitCompany;
  19 +
  20 + private String commitBcompany;
  21 +
  22 + @JsonIgnore
  23 + private String commitName;
  24 +
  25 + private Date validDate;
  26 +
  27 + @JsonIgnore
  28 + private String hash;
  29 +
  30 + @JsonIgnore
  31 + private Date createDate;
  32 +
  33 + @JsonIgnore
  34 + private Date updateDate;
  35 +
  36 + public Integer getId() {
  37 + return id;
  38 + }
  39 +
  40 + public void setId(Integer id) {
  41 + this.id = id;
  42 + }
  43 +
  44 + public String getIp() {
  45 + return ip;
  46 + }
  47 +
  48 + public void setIp(String ip) {
  49 + this.ip = ip;
  50 + }
  51 +
  52 + public String getCommitCompany() {
  53 + return commitCompany;
  54 + }
  55 +
  56 + public void setCommitCompany(String commitCompany) {
  57 + this.commitCompany = commitCompany;
  58 + }
  59 +
  60 + public String getCommitBcompany() {
  61 + return commitBcompany;
  62 + }
  63 +
  64 + public void setCommitBcompany(String commitBcompany) {
  65 + this.commitBcompany = commitBcompany;
  66 + }
  67 +
  68 + public String getCommitName() {
  69 + return commitName;
  70 + }
  71 +
  72 + public void setCommitName(String commitName) {
  73 + this.commitName = commitName;
  74 + }
  75 +
  76 + public Date getValidDate() {
  77 + return validDate;
  78 + }
  79 +
  80 + public void setValidDate(Date validDate) {
  81 + this.validDate = validDate;
  82 + }
  83 +
  84 + public String getHash() {
  85 + return hash;
  86 + }
  87 +
  88 + public void setHash(String hash) {
  89 + this.hash = hash;
  90 + }
  91 +
  92 + public Date getCreateDate() {
  93 + return createDate;
  94 + }
  95 +
  96 + public void setCreateDate(Date createDate) {
  97 + this.createDate = createDate;
  98 + }
  99 +
  100 + public Date getUpdateDate() {
  101 + return updateDate;
  102 + }
  103 +
  104 + public void setUpdateDate(Date updateDate) {
  105 + this.updateDate = updateDate;
  106 + }
  107 +}
... ...
src/main/java/com/bsth/filter/WhiteIpFilter.java 0 → 100644
  1 +package com.bsth.filter;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.bsth.common.Setting;
  5 +import com.bsth.data.BasicData;
  6 +import com.bsth.entity.WhiteIp;
  7 +import com.bsth.entity.sys.SysUser;
  8 +import com.bsth.security.util.SecurityUtils;
  9 +import com.bsth.util.IpUtils;
  10 +import com.google.common.collect.Lists;
  11 +import com.google.common.collect.Maps;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.core.annotation.Order;
  16 +import org.springframework.stereotype.Component;
  17 +
  18 +import javax.servlet.FilterChain;
  19 +import javax.servlet.ServletException;
  20 +import javax.servlet.http.HttpServletRequest;
  21 +import javax.servlet.http.HttpServletResponse;
  22 +import java.io.IOException;
  23 +import java.util.Enumeration;
  24 +import java.util.List;
  25 +import java.util.Map;
  26 +
  27 +/**
  28 + * IP白名单过滤器
  29 + * @author Hill
  30 + */
  31 +@Component
  32 +@Order(1)
  33 +public class WhiteIpFilter extends BaseFilter {
  34 +
  35 + Logger logger = LoggerFactory.getLogger(this.getClass());
  36 +
  37 + @Autowired
  38 + private Setting setting;
  39 +
  40 + @Override
  41 + public void doFilter(HttpServletRequest request,
  42 + HttpServletResponse response, FilterChain chain)
  43 + throws IOException, ServletException {
  44 +
  45 + String ip = IpUtils.getIpAddr(request);
  46 + boolean isMatch = false;
  47 + List<WhiteIp> whiteIps = BasicData.whiteIpList;
  48 + if (whiteIps != null) {
  49 + for (WhiteIp whiteIp : whiteIps) {
  50 + if (ip.equals(whiteIp.getIp())) {
  51 + isMatch = true;
  52 + }
  53 + }
  54 + }
  55 + if (isMatch || !setting.isWhiteipEnabled()) {
  56 + chain.doFilter(request, response);
  57 + } else {
  58 + logger.info(ip + "未在白名单中,不予访问");
  59 + response.setStatus(404);
  60 + return;
  61 + }
  62 + }
  63 +}
... ...