Commit 9c9f8a96dba978ad8cf63f6649691d918c5b004b
1 parent
d0d99dd2
1.初始化companyListMap
Showing
1 changed file
with
71 additions
and
71 deletions
src/main/java/com/bsth/server_rs/base_info/line/buffer/LineBufferData.java
| 1 | -package com.bsth.server_rs.base_info.line.buffer; | ||
| 2 | - | ||
| 3 | -import com.bsth.Application; | ||
| 4 | -import com.bsth.server_rs.base_info.line.Line; | ||
| 5 | -import com.google.common.collect.ArrayListMultimap; | ||
| 6 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | -import org.springframework.boot.CommandLineRunner; | ||
| 8 | -import org.springframework.core.annotation.Order; | ||
| 9 | -import org.springframework.stereotype.Component; | ||
| 10 | - | ||
| 11 | -import java.util.ArrayList; | ||
| 12 | -import java.util.HashMap; | ||
| 13 | -import java.util.List; | ||
| 14 | -import java.util.Map; | ||
| 15 | -import java.util.concurrent.TimeUnit; | ||
| 16 | - | ||
| 17 | -/** | ||
| 18 | - * 线路数据缓存(自更新) | ||
| 19 | - * Created by panzhao on 2017/3/27. | ||
| 20 | - */ | ||
| 21 | -@Component | ||
| 22 | -@Order(5) | ||
| 23 | -public class LineBufferData implements CommandLineRunner { | ||
| 24 | - | ||
| 25 | - @Autowired | ||
| 26 | - LineRefreshThread lineRefreshThread; | ||
| 27 | - | ||
| 28 | - private static List<Line> data; | ||
| 29 | - private static Map<String, Line> idMap; | ||
| 30 | - private static ArrayListMultimap<String, Line> companyListMap; | ||
| 31 | - | ||
| 32 | - public static List<Line> findAll(){ | ||
| 33 | - return data; | ||
| 34 | - } | ||
| 35 | - | ||
| 36 | - public static Line findOne(String lineCode){ | ||
| 37 | - return idMap.get(lineCode); | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | - public static List<Line> findByCompany(String company){ | ||
| 41 | - return companyListMap.get(company); | ||
| 42 | - } | ||
| 43 | - | ||
| 44 | - public static void replaceAll(List<Line> newData){ | ||
| 45 | - data = newData; | ||
| 46 | - Map<String, Line> idMapCopy = new HashMap<>(); | ||
| 47 | - ArrayListMultimap<String, Line> listMap = ArrayListMultimap.create(); | ||
| 48 | - | ||
| 49 | - for(Line line : data){ | ||
| 50 | - idMapCopy.put(line.getLineCode(), line); | ||
| 51 | - listMap.put(line.getCompany(), line); | ||
| 52 | - } | ||
| 53 | - idMap = idMapCopy; | ||
| 54 | - | ||
| 55 | - companyListMap = listMap; | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - @Override | ||
| 59 | - public void run(String... strings) throws Exception { | ||
| 60 | - Application.mainServices.scheduleWithFixedDelay(lineRefreshThread, 10, 60 * 60, TimeUnit.SECONDS); | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - public static List<String> findCodesByCompany(String company) { | ||
| 64 | - List<Line> list = companyListMap.get(company); | ||
| 65 | - List<String> codes = new ArrayList<>(list.size()); | ||
| 66 | - | ||
| 67 | - for(Line line : list) | ||
| 68 | - codes.add(line.getLineCode()); | ||
| 69 | - return codes; | ||
| 70 | - } | ||
| 71 | -} | 1 | +package com.bsth.server_rs.base_info.line.buffer; |
| 2 | + | ||
| 3 | +import com.bsth.Application; | ||
| 4 | +import com.bsth.server_rs.base_info.line.Line; | ||
| 5 | +import com.google.common.collect.ArrayListMultimap; | ||
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | +import org.springframework.boot.CommandLineRunner; | ||
| 8 | +import org.springframework.core.annotation.Order; | ||
| 9 | +import org.springframework.stereotype.Component; | ||
| 10 | + | ||
| 11 | +import java.util.ArrayList; | ||
| 12 | +import java.util.HashMap; | ||
| 13 | +import java.util.List; | ||
| 14 | +import java.util.Map; | ||
| 15 | +import java.util.concurrent.TimeUnit; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * 线路数据缓存(自更新) | ||
| 19 | + * Created by panzhao on 2017/3/27. | ||
| 20 | + */ | ||
| 21 | +@Component | ||
| 22 | +@Order(5) | ||
| 23 | +public class LineBufferData implements CommandLineRunner { | ||
| 24 | + | ||
| 25 | + @Autowired | ||
| 26 | + LineRefreshThread lineRefreshThread; | ||
| 27 | + | ||
| 28 | + private static List<Line> data; | ||
| 29 | + private static Map<String, Line> idMap; | ||
| 30 | + private static ArrayListMultimap<String, Line> companyListMap = ArrayListMultimap.create(); | ||
| 31 | + | ||
| 32 | + public static List<Line> findAll(){ | ||
| 33 | + return data; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public static Line findOne(String lineCode){ | ||
| 37 | + return idMap.get(lineCode); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public static List<Line> findByCompany(String company){ | ||
| 41 | + return companyListMap.get(company); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public static void replaceAll(List<Line> newData){ | ||
| 45 | + data = newData; | ||
| 46 | + Map<String, Line> idMapCopy = new HashMap<>(); | ||
| 47 | + ArrayListMultimap<String, Line> listMap = ArrayListMultimap.create(); | ||
| 48 | + | ||
| 49 | + for(Line line : data){ | ||
| 50 | + idMapCopy.put(line.getLineCode(), line); | ||
| 51 | + listMap.put(line.getCompany(), line); | ||
| 52 | + } | ||
| 53 | + idMap = idMapCopy; | ||
| 54 | + | ||
| 55 | + companyListMap = listMap; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + @Override | ||
| 59 | + public void run(String... strings) throws Exception { | ||
| 60 | + Application.mainServices.scheduleWithFixedDelay(lineRefreshThread, 10, 60 * 60, TimeUnit.SECONDS); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public static List<String> findCodesByCompany(String company) { | ||
| 64 | + List<Line> list = companyListMap.get(company); | ||
| 65 | + List<String> codes = new ArrayList<>(list.size()); | ||
| 66 | + | ||
| 67 | + for(Line line : list) | ||
| 68 | + codes.add(line.getLineCode()); | ||
| 69 | + return codes; | ||
| 70 | + } | ||
| 71 | +} |