Commit 1895047f387432104c2366a90fbca61d5f948778
1 parent
1ef94bff
1.浦东公交提供经过闵行区的线路相关数据给闵行交通委
Showing
2 changed files
with
105 additions
and
94 deletions
src/main/java/com/bsth/server_rs/base_info/car/buffer/CarBufferData.java
| 1 | -package com.bsth.server_rs.base_info.car.buffer; | ||
| 2 | - | ||
| 3 | -import com.bsth.Application; | ||
| 4 | -import com.bsth.server_rs.base_info.car.Car; | ||
| 5 | -import com.bsth.server_rs.base_info.dto.BusCardDto; | ||
| 6 | -import com.google.common.collect.ArrayListMultimap; | ||
| 7 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | -import org.springframework.boot.CommandLineRunner; | ||
| 9 | -import org.springframework.core.annotation.Order; | ||
| 10 | -import org.springframework.stereotype.Component; | ||
| 11 | - | ||
| 12 | -import java.util.*; | ||
| 13 | -import java.util.concurrent.TimeUnit; | ||
| 14 | - | ||
| 15 | -/** | ||
| 16 | - * 车辆数据缓存 | ||
| 17 | - * Created by panzhao on 2017/3/30. | ||
| 18 | - */ | ||
| 19 | -@Component | ||
| 20 | -@Order(6) | ||
| 21 | -public class CarBufferData implements CommandLineRunner { | ||
| 22 | - | ||
| 23 | - private static List<Car> data; | ||
| 24 | - private static Map<String, Car> idMap; | ||
| 25 | - private static ArrayListMultimap<String, Car> companyListMap; | ||
| 26 | - | ||
| 27 | - /** | ||
| 28 | - * 待入库的bus car | ||
| 29 | - */ | ||
| 30 | - public static LinkedList<Car> pstList = new LinkedList<>(); | ||
| 31 | - | ||
| 32 | - @Autowired | ||
| 33 | - CarRefreshThread carRefreshThread; | ||
| 34 | - | ||
| 35 | - public static List<Car> findAll(){ | ||
| 36 | - return data; | ||
| 37 | - } | ||
| 38 | - | ||
| 39 | - public static Car findOne(String nbbm){ | ||
| 40 | - return idMap.get(nbbm); | ||
| 41 | - } | ||
| 42 | - | ||
| 43 | - public static List<Car> findByCompany(String company){ | ||
| 44 | - return companyListMap.get(company); | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | - public static void replaceAll(List<Car> newData){ | ||
| 48 | - data = newData; | ||
| 49 | - Map<String, Car> idMapCopy = new HashMap<>(); | ||
| 50 | - ArrayListMultimap<String, Car> listMap = ArrayListMultimap.create(); | ||
| 51 | - | ||
| 52 | - for(Car car : data){ | ||
| 53 | - idMapCopy.put(car.getNbbm(), car); | ||
| 54 | - listMap.put(car.getCompanyCode(), car); | ||
| 55 | - } | ||
| 56 | - idMap = idMapCopy; | ||
| 57 | - | ||
| 58 | - companyListMap = listMap; | ||
| 59 | - } | ||
| 60 | - | ||
| 61 | - @Override | ||
| 62 | - public void run(String... strings) throws Exception { | ||
| 63 | - Application.mainServices.scheduleWithFixedDelay(carRefreshThread, 10, 60 * 60, TimeUnit.SECONDS); | ||
| 64 | - } | ||
| 65 | - | ||
| 66 | - public static Map<String, Object> multiSaveCards(List<BusCardDto> list) { | ||
| 67 | - int success=0,error=0; | ||
| 68 | - //返回写入成功的卡数据 | ||
| 69 | - List<BusCardDto> rsList = new ArrayList<>(); | ||
| 70 | - | ||
| 71 | - Car c; | ||
| 72 | - for(BusCardDto bcd : list){ | ||
| 73 | - c = idMap.get(bcd.getNbbm()); | ||
| 74 | - if(c == null) | ||
| 75 | - error ++; | ||
| 76 | - else{ | ||
| 77 | - c.setIdRfid(bcd.getIdCard()); | ||
| 78 | - c.setTagRfid(bcd.getTagCard()); | ||
| 79 | - c.setRemark(bcd.getRemark()); | ||
| 80 | - success ++; | ||
| 81 | - | ||
| 82 | - pstList.add(c); | ||
| 83 | - rsList.add(bcd); | ||
| 84 | - } | ||
| 85 | - } | ||
| 86 | - | ||
| 87 | - Map<String, Object> rs = new HashMap<>(); | ||
| 88 | - rs.put("success", success); | ||
| 89 | - rs.put("successList", rsList); | ||
| 90 | - rs.put("error", error); | ||
| 91 | - return rs; | ||
| 92 | - } | ||
| 93 | -} | 1 | +package com.bsth.server_rs.base_info.car.buffer; |
| 2 | + | ||
| 3 | +import com.bsth.Application; | ||
| 4 | +import com.bsth.server_rs.base_info.car.Car; | ||
| 5 | +import com.bsth.server_rs.base_info.dto.BusCardDto; | ||
| 6 | +import com.google.common.collect.ArrayListMultimap; | ||
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | +import org.springframework.boot.CommandLineRunner; | ||
| 9 | +import org.springframework.core.annotation.Order; | ||
| 10 | +import org.springframework.stereotype.Component; | ||
| 11 | + | ||
| 12 | +import java.util.*; | ||
| 13 | +import java.util.concurrent.TimeUnit; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * 车辆数据缓存 | ||
| 17 | + * Created by panzhao on 2017/3/30. | ||
| 18 | + */ | ||
| 19 | +@Component | ||
| 20 | +@Order(6) | ||
| 21 | +public class CarBufferData implements CommandLineRunner { | ||
| 22 | + | ||
| 23 | + private static List<Car> data; | ||
| 24 | + private static Map<String, Car> idMap; | ||
| 25 | + private static ArrayListMultimap<String, Car> companyListMap; | ||
| 26 | + private static Map<String, Car> device2car = new HashMap<>(); | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 待入库的bus car | ||
| 30 | + */ | ||
| 31 | + public static LinkedList<Car> pstList = new LinkedList<>(); | ||
| 32 | + | ||
| 33 | + @Autowired | ||
| 34 | + CarRefreshThread carRefreshThread; | ||
| 35 | + | ||
| 36 | + public static List<Car> findAll(){ | ||
| 37 | + return data; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public static Car findOne(String nbbm){ | ||
| 41 | + return idMap.get(nbbm); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public static List<Car> findByCompany(String company){ | ||
| 45 | + return companyListMap.get(company); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public static Car findByDevice(String device){ | ||
| 49 | + return device2car.get(device); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public static void replaceAll(List<Car> newData){ | ||
| 53 | + data = newData; | ||
| 54 | + Map<String, Car> idMapCopy = new HashMap<>(); | ||
| 55 | + ArrayListMultimap<String, Car> listMap = ArrayListMultimap.create(); | ||
| 56 | + Map<String, Car> device2carCopy = new HashMap<>(); | ||
| 57 | + | ||
| 58 | + for(Car car : data){ | ||
| 59 | + idMapCopy.put(car.getNbbm(), car); | ||
| 60 | + listMap.put(car.getCompanyCode(), car); | ||
| 61 | + device2carCopy.put(car.getEquipmentCode(), car); | ||
| 62 | + } | ||
| 63 | + idMap = idMapCopy; | ||
| 64 | + | ||
| 65 | + companyListMap = listMap; | ||
| 66 | + device2car = device2carCopy; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + @Override | ||
| 70 | + public void run(String... strings) throws Exception { | ||
| 71 | + Application.mainServices.scheduleWithFixedDelay(carRefreshThread, 10, 60 * 60, TimeUnit.SECONDS); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public static Map<String, Object> multiSaveCards(List<BusCardDto> list) { | ||
| 75 | + int success=0,error=0; | ||
| 76 | + //返回写入成功的卡数据 | ||
| 77 | + List<BusCardDto> rsList = new ArrayList<>(); | ||
| 78 | + | ||
| 79 | + Car c; | ||
| 80 | + for(BusCardDto bcd : list){ | ||
| 81 | + c = idMap.get(bcd.getNbbm()); | ||
| 82 | + if(c == null) | ||
| 83 | + error ++; | ||
| 84 | + else{ | ||
| 85 | + c.setIdRfid(bcd.getIdCard()); | ||
| 86 | + c.setTagRfid(bcd.getTagCard()); | ||
| 87 | + c.setRemark(bcd.getRemark()); | ||
| 88 | + success ++; | ||
| 89 | + | ||
| 90 | + pstList.add(c); | ||
| 91 | + rsList.add(bcd); | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + Map<String, Object> rs = new HashMap<>(); | ||
| 96 | + rs.put("success", success); | ||
| 97 | + rs.put("successList", rsList); | ||
| 98 | + rs.put("error", error); | ||
| 99 | + return rs; | ||
| 100 | + } | ||
| 101 | +} |
src/main/java/com/bsth/server_rs/dks/BxRestService.java
| @@ -213,7 +213,10 @@ public class BxRestService { | @@ -213,7 +213,10 @@ public class BxRestService { | ||
| 213 | String lineCode = gps.getLineId(), deviceId = gps.getDeviceId(); | 213 | String lineCode = gps.getLineId(), deviceId = gps.getDeviceId(); |
| 214 | if (limitLines.indexOf(String.format("%s,", lineCode)) > -1) { | 214 | if (limitLines.indexOf(String.format("%s,", lineCode)) > -1) { |
| 215 | Line line = LineBufferData.findOne(lineCode); | 215 | Line line = LineBufferData.findOne(lineCode); |
| 216 | - Car car = CarBufferData.findOne(deviceId); | 216 | + Car car = CarBufferData.findByDevice(deviceId); |
| 217 | + if (car == null) { | ||
| 218 | + continue; | ||
| 219 | + } | ||
| 217 | Map<String, Object> gpsMap = new HashMap<>(); | 220 | Map<String, Object> gpsMap = new HashMap<>(); |
| 218 | gpsMap.put("lineName", line.getName()); | 221 | gpsMap.put("lineName", line.getName()); |
| 219 | gpsMap.put("lineCode", line.getShanghaiLinecode()); | 222 | gpsMap.put("lineCode", line.getShanghaiLinecode()); |