Commit 790a2c30b1ea06806f87244e7e084a9eb565a0c5
1 parent
7dd529ff
1.数知梦接口需要扩展进/external
Showing
5 changed files
with
164 additions
and
43 deletions
src/main/java/com/bsth/CXFConfig.java
| @@ -98,6 +98,8 @@ public class CXFConfig { | @@ -98,6 +98,8 @@ public class CXFConfig { | ||
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | @Autowired | 100 | @Autowired |
| 101 | + private AuthorizeInterceptor_IN authorizeInterceptorIn; | ||
| 102 | + @Autowired | ||
| 101 | ScheduleRealService scheduleRealService; | 103 | ScheduleRealService scheduleRealService; |
| 102 | @Autowired | 104 | @Autowired |
| 103 | StationRestService stationRestService; | 105 | StationRestService stationRestService; |
| @@ -166,7 +168,7 @@ public class CXFConfig { | @@ -166,7 +168,7 @@ public class CXFConfig { | ||
| 166 | bxRestService)); | 168 | bxRestService)); |
| 167 | endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper())); | 169 | endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper())); |
| 168 | //endpoint.setFeatures(Arrays.asList(new Swagger2Feature())); | 170 | //endpoint.setFeatures(Arrays.asList(new Swagger2Feature())); |
| 169 | - endpoint.getInInterceptors().add(new AuthorizeInterceptor_IN()); | 171 | + endpoint.getInInterceptors().add(authorizeInterceptorIn); |
| 170 | return endpoint.create(); | 172 | return endpoint.create(); |
| 171 | } | 173 | } |
| 172 | 174 |
src/main/java/com/bsth/server_rs/AuthorizeInterceptor_IN.java
| @@ -5,6 +5,7 @@ import com.bsth.entity.Resource; | @@ -5,6 +5,7 @@ import com.bsth.entity.Resource; | ||
| 5 | import com.bsth.server_rs.exception.AesException; | 5 | import com.bsth.server_rs.exception.AesException; |
| 6 | import com.bsth.service.SystemParamService; | 6 | import com.bsth.service.SystemParamService; |
| 7 | import com.bsth.service.UserService; | 7 | import com.bsth.service.UserService; |
| 8 | +import com.bsth.util.ThreadLocalUtils; | ||
| 8 | import org.apache.commons.lang3.StringEscapeUtils; | 9 | import org.apache.commons.lang3.StringEscapeUtils; |
| 9 | import org.apache.cxf.interceptor.Fault; | 10 | import org.apache.cxf.interceptor.Fault; |
| 10 | import org.apache.cxf.message.Message; | 11 | import org.apache.cxf.message.Message; |
| @@ -15,17 +16,20 @@ import org.eclipse.jetty.util.UrlEncoded; | @@ -15,17 +16,20 @@ import org.eclipse.jetty.util.UrlEncoded; | ||
| 15 | import org.slf4j.Logger; | 16 | import org.slf4j.Logger; |
| 16 | import org.slf4j.LoggerFactory; | 17 | import org.slf4j.LoggerFactory; |
| 17 | import org.springframework.beans.BeansException; | 18 | import org.springframework.beans.BeansException; |
| 19 | +import org.springframework.beans.factory.annotation.Value; | ||
| 18 | import org.springframework.context.ApplicationContext; | 20 | import org.springframework.context.ApplicationContext; |
| 19 | import org.springframework.context.ApplicationContextAware; | 21 | import org.springframework.context.ApplicationContextAware; |
| 20 | import org.springframework.stereotype.Component; | 22 | import org.springframework.stereotype.Component; |
| 21 | import org.springframework.util.AntPathMatcher; | 23 | import org.springframework.util.AntPathMatcher; |
| 22 | import org.springframework.util.PathMatcher; | 24 | import org.springframework.util.PathMatcher; |
| 23 | 25 | ||
| 26 | +import java.io.BufferedReader; | ||
| 27 | +import java.io.File; | ||
| 28 | +import java.io.FileReader; | ||
| 29 | +import java.io.IOException; | ||
| 24 | import java.security.MessageDigest; | 30 | import java.security.MessageDigest; |
| 25 | -import java.util.Arrays; | ||
| 26 | -import java.util.HashMap; | ||
| 27 | -import java.util.Map; | ||
| 28 | -import java.util.Set; | 31 | +import java.util.*; |
| 32 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 29 | 33 | ||
| 30 | /** | 34 | /** |
| 31 | * rest 接口授权校验(IN 输入拦截) | 35 | * rest 接口授权校验(IN 输入拦截) |
| @@ -49,6 +53,15 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> i | @@ -49,6 +53,15 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> i | ||
| 49 | 53 | ||
| 50 | private static PathMatcher matcher = new AntPathMatcher(); | 54 | private static PathMatcher matcher = new AntPathMatcher(); |
| 51 | 55 | ||
| 56 | + @Value("${path.limits}") | ||
| 57 | + private String pathLimits; | ||
| 58 | + | ||
| 59 | + private Map<String, Set<String>> pwd2lines = new ConcurrentHashMap<>(); | ||
| 60 | + | ||
| 61 | + private Map<String, Set<String>> pwd2device = new ConcurrentHashMap<>(); | ||
| 62 | + | ||
| 63 | + private ThreadLocal<String> passwords = new ThreadLocal<>(); | ||
| 64 | + | ||
| 52 | public AuthorizeInterceptor_IN() { | 65 | public AuthorizeInterceptor_IN() { |
| 53 | super(Phase.RECEIVE); | 66 | super(Phase.RECEIVE); |
| 54 | } | 67 | } |
| @@ -121,12 +134,15 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> i | @@ -121,12 +134,15 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> i | ||
| 121 | throw new AesException(AesException.SIGN_CHECK_FAIL); | 134 | throw new AesException(AesException.SIGN_CHECK_FAIL); |
| 122 | } | 135 | } |
| 123 | 136 | ||
| 137 | + ThreadLocalUtils.setPassword(map.get(PASSWORD)); | ||
| 124 | validate(map, message); | 138 | validate(map, message); |
| 125 | } | 139 | } |
| 126 | 140 | ||
| 127 | - private static void validate(Map<String, String> map, Message message) { | ||
| 128 | - PasswordUser user = userService.get(map.get(PASSWORD)); | 141 | + private void validate(Map<String, String> map, Message message) { |
| 142 | + String password = map.get(PASSWORD); | ||
| 143 | + PasswordUser user = userService.get(password); | ||
| 129 | if (user.getResources().size() > 0) { | 144 | if (user.getResources().size() > 0) { |
| 145 | + loadLimit(password); | ||
| 130 | boolean isMatch = false; | 146 | boolean isMatch = false; |
| 131 | String uri = (String) message.get(Message.REQUEST_URI); | 147 | String uri = (String) message.get(Message.REQUEST_URI); |
| 132 | for (Resource resource : user.getResources()) { | 148 | for (Resource resource : user.getResources()) { |
| @@ -141,6 +157,49 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> i | @@ -141,6 +157,49 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> i | ||
| 141 | } | 157 | } |
| 142 | } | 158 | } |
| 143 | 159 | ||
| 160 | + public void loadLimit(String password) { | ||
| 161 | + if (!pwd2lines.containsKey(password)) { | ||
| 162 | + Set<String> set = new HashSet<>(); | ||
| 163 | + try { | ||
| 164 | + BufferedReader reader = new BufferedReader(new FileReader(pathLimits + String.format("lines-%s.txt", password))); | ||
| 165 | + String line = null; | ||
| 166 | + while ((line = reader.readLine()) != null) { | ||
| 167 | + set.add(line); | ||
| 168 | + } | ||
| 169 | + } catch (IOException e) { | ||
| 170 | + logger.error("加载受限线路信息异常", e); | ||
| 171 | + } finally { | ||
| 172 | + pwd2lines.put(password, set); | ||
| 173 | + } | ||
| 174 | + } | ||
| 175 | + if (!pwd2device.containsKey(password)) { | ||
| 176 | + Set<String> set = new HashSet<>(); | ||
| 177 | + try { | ||
| 178 | + BufferedReader reader = new BufferedReader(new FileReader(pathLimits + String.format("devices-%s.txt", password))); | ||
| 179 | + String line = null; | ||
| 180 | + while ((line = reader.readLine()) != null) { | ||
| 181 | + set.add(line); | ||
| 182 | + } | ||
| 183 | + } catch (IOException e) { | ||
| 184 | + logger.error("加载受限设备信息异常", e); | ||
| 185 | + } finally { | ||
| 186 | + pwd2device.put(password, set); | ||
| 187 | + } | ||
| 188 | + } | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + public Set<String> getLimitLines(String password) { | ||
| 192 | + return pwd2lines.get(password); | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + public Set<String> getLimitDevices(String password) { | ||
| 196 | + return pwd2device.get(password); | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + public ThreadLocal<String> getPasswords() { | ||
| 200 | + return passwords; | ||
| 201 | + } | ||
| 202 | + | ||
| 144 | public static Map<String, String> multi2One(MultiMap<String> params) { | 203 | public static Map<String, String> multi2One(MultiMap<String> params) { |
| 145 | Map<String, String> map = new HashMap<>(); | 204 | Map<String, String> map = new HashMap<>(); |
| 146 | Set<String> ks = params.keySet(); | 205 | Set<String> ks = params.keySet(); |
src/main/java/com/bsth/server_rs/dks/BxRestService.java
| 1 | package com.bsth.server_rs.dks; | 1 | package com.bsth.server_rs.dks; |
| 2 | 2 | ||
| 3 | -import com.bsth.common.SystemParamKeys; | 3 | +import com.bsth.server_rs.AuthorizeInterceptor_IN; |
| 4 | import com.bsth.server_rs.base_info.car.Car; | 4 | import com.bsth.server_rs.base_info.car.Car; |
| 5 | import com.bsth.server_rs.base_info.car.buffer.CarBufferData; | 5 | import com.bsth.server_rs.base_info.car.buffer.CarBufferData; |
| 6 | import com.bsth.server_rs.base_info.carpark.Carpark; | 6 | import com.bsth.server_rs.base_info.carpark.Carpark; |
| @@ -8,26 +8,24 @@ import com.bsth.server_rs.base_info.carpark.buffer.CarparkBufferData; | @@ -8,26 +8,24 @@ import com.bsth.server_rs.base_info.carpark.buffer.CarparkBufferData; | ||
| 8 | import com.bsth.server_rs.base_info.line.Line; | 8 | import com.bsth.server_rs.base_info.line.Line; |
| 9 | import com.bsth.server_rs.base_info.line.buffer.LineBufferData; | 9 | import com.bsth.server_rs.base_info.line.buffer.LineBufferData; |
| 10 | import com.bsth.server_rs.base_info.section.buffer.LD_SectionBufferData; | 10 | import com.bsth.server_rs.base_info.section.buffer.LD_SectionBufferData; |
| 11 | -import com.bsth.server_rs.base_info.section.entity.LD_Section; | ||
| 12 | import com.bsth.server_rs.base_info.section.entity.LD_SectionRoute; | 11 | import com.bsth.server_rs.base_info.section.entity.LD_SectionRoute; |
| 13 | import com.bsth.server_rs.base_info.station.buffer.StationBufferData; | 12 | import com.bsth.server_rs.base_info.station.buffer.StationBufferData; |
| 14 | import com.bsth.server_rs.base_info.station.entity.StationRotue; | 13 | import com.bsth.server_rs.base_info.station.entity.StationRotue; |
| 15 | import com.bsth.server_rs.gps.buffer.BasicDataBuffer; | 14 | import com.bsth.server_rs.gps.buffer.BasicDataBuffer; |
| 16 | import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer; | 15 | import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer; |
| 16 | +import com.bsth.server_rs.gps.dao.HistoryGpsDao; | ||
| 17 | import com.bsth.server_rs.gps.entity.GpsEntity; | 17 | import com.bsth.server_rs.gps.entity.GpsEntity; |
| 18 | -import com.bsth.server_rs.gps.entity.LineInfo; | ||
| 19 | -import com.bsth.service.SystemParamService; | 18 | +import com.bsth.server_rs.gps.entity.HistoryArrivalEntity; |
| 19 | +import com.bsth.util.ThreadLocalUtils; | ||
| 20 | +import org.apache.commons.lang3.StringUtils; | ||
| 20 | import org.slf4j.Logger; | 21 | import org.slf4j.Logger; |
| 21 | import org.slf4j.LoggerFactory; | 22 | import org.slf4j.LoggerFactory; |
| 22 | import org.springframework.beans.factory.annotation.Autowired; | 23 | import org.springframework.beans.factory.annotation.Autowired; |
| 23 | import org.springframework.stereotype.Component; | 24 | import org.springframework.stereotype.Component; |
| 24 | 25 | ||
| 25 | -import javax.ws.rs.GET; | ||
| 26 | -import javax.ws.rs.Path; | ||
| 27 | -import javax.ws.rs.Produces; | 26 | +import javax.ws.rs.*; |
| 28 | import javax.ws.rs.core.MediaType; | 27 | import javax.ws.rs.core.MediaType; |
| 29 | import java.util.*; | 28 | import java.util.*; |
| 30 | -import java.util.concurrent.ConcurrentHashMap; | ||
| 31 | 29 | ||
| 32 | /** | 30 | /** |
| 33 | * @author Hill | 31 | * @author Hill |
| @@ -41,22 +39,26 @@ public class BxRestService { | @@ -41,22 +39,26 @@ public class BxRestService { | ||
| 41 | private final static Logger log = LoggerFactory.getLogger(BxRestService.class); | 39 | private final static Logger log = LoggerFactory.getLogger(BxRestService.class); |
| 42 | 40 | ||
| 43 | @Autowired | 41 | @Autowired |
| 44 | - private SystemParamService systemParamService; | 42 | + private LD_SectionBufferData ldSectionBufferData; |
| 45 | 43 | ||
| 46 | @Autowired | 44 | @Autowired |
| 47 | - private LD_SectionBufferData ldSectionBufferData; | 45 | + private HistoryGpsDao historyGpsDao; |
| 46 | + | ||
| 47 | + @Autowired | ||
| 48 | + private AuthorizeInterceptor_IN authorizeInterceptorIn; | ||
| 48 | 49 | ||
| 49 | @GET | 50 | @GET |
| 50 | @Path("/line") | 51 | @Path("/line") |
| 51 | public List<Map<String, Object>> findAllLine() { | 52 | public List<Map<String, Object>> findAllLine() { |
| 52 | List<Map<String, Object>> result = new ArrayList<>(); | 53 | List<Map<String, Object>> result = new ArrayList<>(); |
| 53 | - String limitLines = systemParamService.getValue(SystemParamKeys.LIMIT_LINES); | ||
| 54 | - if (limitLines == null) { | 54 | + String password = ThreadLocalUtils.getPassword(); |
| 55 | + Set<String> limitLines = authorizeInterceptorIn.getLimitLines(password); | ||
| 56 | + if (limitLines == null || limitLines.isEmpty()) { | ||
| 55 | return result; | 57 | return result; |
| 56 | } | 58 | } |
| 57 | for (Line line : LineBufferData.findAll()) { | 59 | for (Line line : LineBufferData.findAll()) { |
| 58 | String lineCode = line.getLineCode(); | 60 | String lineCode = line.getLineCode(); |
| 59 | - if (limitLines.indexOf(String.format(",%s,", lineCode)) > -1) { | 61 | + if (limitLines.contains(lineCode) || limitLines.contains("ALL")) { |
| 60 | Map<String, Object> lineMap = new HashMap<>(); | 62 | Map<String, Object> lineMap = new HashMap<>(); |
| 61 | Collection<LD_SectionRoute> sectionRoutes = ldSectionBufferData.findByLineCode(lineCode).get(String.format("%s_0", lineCode)); | 63 | Collection<LD_SectionRoute> sectionRoutes = ldSectionBufferData.findByLineCode(lineCode).get(String.format("%s_0", lineCode)); |
| 62 | StringBuilder sb = new StringBuilder(); | 64 | StringBuilder sb = new StringBuilder(); |
| @@ -68,6 +70,7 @@ public class BxRestService { | @@ -68,6 +70,7 @@ public class BxRestService { | ||
| 68 | lineMap.put("branch", BasicDataBuffer.getBusinessByCode(String.format("%s_%s", line.getCompany(), line.getBrancheCompany()))); | 70 | lineMap.put("branch", BasicDataBuffer.getBusinessByCode(String.format("%s_%s", line.getCompany(), line.getBrancheCompany()))); |
| 69 | lineMap.put("lineName", line.getName()); | 71 | lineMap.put("lineName", line.getName()); |
| 70 | lineMap.put("lineCode", line.getShanghaiLinecode()); | 72 | lineMap.put("lineCode", line.getShanghaiLinecode()); |
| 73 | + lineMap.put("lineCodeExternal", lineCode); | ||
| 71 | lineMap.put("startStation", line.getStartStationName()); | 74 | lineMap.put("startStation", line.getStartStationName()); |
| 72 | lineMap.put("endStation", line.getEndStationName()); | 75 | lineMap.put("endStation", line.getEndStationName()); |
| 73 | lineMap.put("lineLength", line.getTotalMileage()); | 76 | lineMap.put("lineLength", line.getTotalMileage()); |
| @@ -87,16 +90,23 @@ public class BxRestService { | @@ -87,16 +90,23 @@ public class BxRestService { | ||
| 87 | @Path("/station") | 90 | @Path("/station") |
| 88 | public List<Map<String, Object>> findAllStation() { | 91 | public List<Map<String, Object>> findAllStation() { |
| 89 | List<Map<String, Object>> result = new ArrayList<>(); | 92 | List<Map<String, Object>> result = new ArrayList<>(); |
| 90 | - String limitLines = systemParamService.getValue(SystemParamKeys.LIMIT_LINES); | ||
| 91 | - if (limitLines == null) { | 93 | + String password = ThreadLocalUtils.getPassword(); |
| 94 | + Set<String> limitLines = new HashSet<>(authorizeInterceptorIn.getLimitLines(password)); | ||
| 95 | + if (limitLines == null || limitLines.isEmpty()) { | ||
| 92 | return result; | 96 | return result; |
| 93 | } | 97 | } |
| 94 | - for (String lineCode : limitLines.split(",")) { | ||
| 95 | - if (!"".equals(lineCode)) { | 98 | + if (limitLines.contains("ALL")) { |
| 99 | + for (Line line : LineBufferData.findAll()) { | ||
| 100 | + limitLines.add(line.getLineCode()); | ||
| 101 | + } | ||
| 102 | + } | ||
| 103 | + for (String lineCode : limitLines) { | ||
| 104 | + if (StringUtils.isNotEmpty(lineCode)) { | ||
| 96 | Map<String, Object> lineMap = new HashMap<>(); | 105 | Map<String, Object> lineMap = new HashMap<>(); |
| 97 | Line line = LineBufferData.findOne(lineCode); | 106 | Line line = LineBufferData.findOne(lineCode); |
| 98 | lineMap.put("lineName", line.getName()); | 107 | lineMap.put("lineName", line.getName()); |
| 99 | lineMap.put("lineCode", line.getShanghaiLinecode()); | 108 | lineMap.put("lineCode", line.getShanghaiLinecode()); |
| 109 | + lineMap.put("lineCodeExternal", lineCode); | ||
| 100 | 110 | ||
| 101 | int count = 1; | 111 | int count = 1; |
| 102 | List<Map<String, Object>> upStations = new ArrayList<>(), downStations = new ArrayList<>(); | 112 | List<Map<String, Object>> upStations = new ArrayList<>(), downStations = new ArrayList<>(); |
| @@ -105,7 +115,7 @@ public class BxRestService { | @@ -105,7 +115,7 @@ public class BxRestService { | ||
| 105 | stopMap.put("levelNo", count); | 115 | stopMap.put("levelNo", count); |
| 106 | stopMap.put("levelName", route.getStationName()); | 116 | stopMap.put("levelName", route.getStationName()); |
| 107 | stopMap.put("levelLonlat", String.format("%f %f", route.getStation().getLon(), route.getStation().getLat())); | 117 | stopMap.put("levelLonlat", String.format("%f %f", route.getStation().getLon(), route.getStation().getLat())); |
| 108 | - stopMap.put("stationCode", null); | 118 | + stopMap.put("stationCode", route.getStationCode()); |
| 109 | upStations.add(stopMap); | 119 | upStations.add(stopMap); |
| 110 | count++; | 120 | count++; |
| 111 | } | 121 | } |
| @@ -115,7 +125,7 @@ public class BxRestService { | @@ -115,7 +125,7 @@ public class BxRestService { | ||
| 115 | stopMap.put("levelNo", count); | 125 | stopMap.put("levelNo", count); |
| 116 | stopMap.put("levelName", route.getStationName()); | 126 | stopMap.put("levelName", route.getStationName()); |
| 117 | stopMap.put("levelLonlat", String.format("%f %f", route.getStation().getLon(), route.getStation().getLat())); | 127 | stopMap.put("levelLonlat", String.format("%f %f", route.getStation().getLon(), route.getStation().getLat())); |
| 118 | - stopMap.put("stationCode", null); | 128 | + stopMap.put("stationCode", route.getStationCode()); |
| 119 | downStations.add(stopMap); | 129 | downStations.add(stopMap); |
| 120 | count++; | 130 | count++; |
| 121 | } | 131 | } |
| @@ -132,22 +142,19 @@ public class BxRestService { | @@ -132,22 +142,19 @@ public class BxRestService { | ||
| 132 | @GET | 142 | @GET |
| 133 | @Path("/vehicle") | 143 | @Path("/vehicle") |
| 134 | public List<Map<String, Object>> findAllVehicle() { | 144 | public List<Map<String, Object>> findAllVehicle() { |
| 135 | - StringBuilder sb = new StringBuilder(); | 145 | + List<Map<String, Object>> result = new ArrayList<>(); |
| 136 | Map<String, String> device2line = GpsRealDataBuffer.getDevice2Line(); | 146 | Map<String, String> device2line = GpsRealDataBuffer.getDevice2Line(); |
| 137 | - String limitLines = systemParamService.getValue(SystemParamKeys.LIMIT_LINES); | ||
| 138 | - for (Map.Entry<String, String> entry : device2line.entrySet()) { | ||
| 139 | - String deviceId = entry.getKey(), lineCode = entry.getValue(); | ||
| 140 | - if (limitLines.indexOf(String.format(",%s,", lineCode)) > -1) { | ||
| 141 | - sb.append(deviceId).append(","); | ||
| 142 | - } | 147 | + String password = ThreadLocalUtils.getPassword(); |
| 148 | + Set<String> limitLines = authorizeInterceptorIn.getLimitLines(password); | ||
| 149 | + Set<String> limitDevices = authorizeInterceptorIn.getLimitDevices(password); | ||
| 150 | + if (limitLines == null || limitLines.isEmpty()) { | ||
| 151 | + return result; | ||
| 143 | } | 152 | } |
| 144 | - String limitDevices = sb.toString(); | ||
| 145 | - List<Map<String, Object>> result = new ArrayList<>(); | ||
| 146 | - if (limitDevices.equals("")) { | 153 | + if (limitDevices == null || limitDevices.isEmpty()) { |
| 147 | return result; | 154 | return result; |
| 148 | } | 155 | } |
| 149 | for (Car car : CarBufferData.findAll()) { | 156 | for (Car car : CarBufferData.findAll()) { |
| 150 | - if (limitDevices.indexOf(String.format("%s,", car.getEquipmentCode())) > -1) { | 157 | + if (limitDevices.contains(car.getEquipmentCode()) || limitDevices.contains("ALL")) { |
| 151 | Map<String, Object> carMap = new HashMap<>(); | 158 | Map<String, Object> carMap = new HashMap<>(); |
| 152 | Line line = LineBufferData.findOne(device2line.get(car.getEquipmentCode())); | 159 | Line line = LineBufferData.findOne(device2line.get(car.getEquipmentCode())); |
| 153 | if (line == null) { | 160 | if (line == null) { |
| @@ -155,6 +162,7 @@ public class BxRestService { | @@ -155,6 +162,7 @@ public class BxRestService { | ||
| 155 | } | 162 | } |
| 156 | carMap.put("lineName", line.getName()); | 163 | carMap.put("lineName", line.getName()); |
| 157 | carMap.put("lineCode", line.getShanghaiLinecode()); | 164 | carMap.put("lineCode", line.getShanghaiLinecode()); |
| 165 | + carMap.put("lineCodeExternal", line.getLineCode()); | ||
| 158 | carMap.put("vehicleId", car.getCarPlate()); | 166 | carMap.put("vehicleId", car.getCarPlate()); |
| 159 | carMap.put("vehicleNo", car.getNbbm()); | 167 | carMap.put("vehicleNo", car.getNbbm()); |
| 160 | carMap.put("vehicleType", car.getVehicleType()); | 168 | carMap.put("vehicleType", car.getVehicleType()); |
| @@ -171,14 +179,15 @@ public class BxRestService { | @@ -171,14 +179,15 @@ public class BxRestService { | ||
| 171 | @Path("/parking") | 179 | @Path("/parking") |
| 172 | public List<Map<String, Object>> findAllParking() { | 180 | public List<Map<String, Object>> findAllParking() { |
| 173 | List<Map<String, Object>> result = new ArrayList<>(); | 181 | List<Map<String, Object>> result = new ArrayList<>(); |
| 174 | - String limitLines = systemParamService.getValue(SystemParamKeys.LIMIT_LINES); | ||
| 175 | - if (limitLines == null) { | 182 | + String password = ThreadLocalUtils.getPassword(); |
| 183 | + Set<String> limitLines = authorizeInterceptorIn.getLimitLines(password); | ||
| 184 | + if (limitLines == null || limitLines.isEmpty()) { | ||
| 176 | return result; | 185 | return result; |
| 177 | } | 186 | } |
| 178 | StringBuilder sb = new StringBuilder(); | 187 | StringBuilder sb = new StringBuilder(); |
| 179 | for (Line line : LineBufferData.findAll()) { | 188 | for (Line line : LineBufferData.findAll()) { |
| 180 | String lineCode = line.getLineCode(); | 189 | String lineCode = line.getLineCode(); |
| 181 | - if (limitLines.indexOf(String.format(",%s,", lineCode)) > -1) { | 190 | + if (limitLines.contains(lineCode) || limitLines.contains("ALL")) { |
| 182 | sb.append(line.getCarPark()).append(","); | 191 | sb.append(line.getCarPark()).append(","); |
| 183 | } | 192 | } |
| 184 | } | 193 | } |
| @@ -205,13 +214,15 @@ public class BxRestService { | @@ -205,13 +214,15 @@ public class BxRestService { | ||
| 205 | @Path("/gps/all") | 214 | @Path("/gps/all") |
| 206 | public List<Map<String, Object>> findAllGps() { | 215 | public List<Map<String, Object>> findAllGps() { |
| 207 | List<Map<String, Object>> result = new ArrayList<>(); | 216 | List<Map<String, Object>> result = new ArrayList<>(); |
| 208 | - String limitLines = systemParamService.getValue(SystemParamKeys.LIMIT_LINES); | ||
| 209 | - if (limitLines == null) { | 217 | + String password = ThreadLocalUtils.getPassword(); |
| 218 | + Set<String> limitLines = authorizeInterceptorIn.getLimitLines(password); | ||
| 219 | + Set<String> limitDevices = authorizeInterceptorIn.getLimitDevices(password); | ||
| 220 | + if (limitLines == null || limitLines.isEmpty()) { | ||
| 210 | return result; | 221 | return result; |
| 211 | } | 222 | } |
| 212 | for (GpsEntity gps : GpsRealDataBuffer.all()) { | 223 | for (GpsEntity gps : GpsRealDataBuffer.all()) { |
| 213 | String lineCode = gps.getLineId(), deviceId = gps.getDeviceId(); | 224 | String lineCode = gps.getLineId(), deviceId = gps.getDeviceId(); |
| 214 | - if (limitLines.indexOf(String.format(",%s,", lineCode)) > -1) { | 225 | + if ((limitLines.contains(lineCode) || limitLines.contains("ALL")) && (limitDevices.contains(deviceId) || limitDevices.contains("ALL"))) { |
| 215 | Line line = LineBufferData.findOne(lineCode); | 226 | Line line = LineBufferData.findOne(lineCode); |
| 216 | Car car = CarBufferData.findByDevice(deviceId); | 227 | Car car = CarBufferData.findByDevice(deviceId); |
| 217 | if (car == null) { | 228 | if (car == null) { |
| @@ -220,6 +231,7 @@ public class BxRestService { | @@ -220,6 +231,7 @@ public class BxRestService { | ||
| 220 | Map<String, Object> gpsMap = new HashMap<>(); | 231 | Map<String, Object> gpsMap = new HashMap<>(); |
| 221 | gpsMap.put("lineName", line.getName()); | 232 | gpsMap.put("lineName", line.getName()); |
| 222 | gpsMap.put("lineCode", line.getShanghaiLinecode()); | 233 | gpsMap.put("lineCode", line.getShanghaiLinecode()); |
| 234 | + gpsMap.put("lineCodeExternal", line.getLineCode()); | ||
| 223 | gpsMap.put("vehicleId", car.getCarPlate()); | 235 | gpsMap.put("vehicleId", car.getCarPlate()); |
| 224 | gpsMap.put("gpsTime", gps.getTimestamp()); | 236 | gpsMap.put("gpsTime", gps.getTimestamp()); |
| 225 | gpsMap.put("gpsLonlat", String.format("%f %f", gps.getLon(), gps.getLat())); | 237 | gpsMap.put("gpsLonlat", String.format("%f %f", gps.getLon(), gps.getLat())); |
| @@ -231,4 +243,39 @@ public class BxRestService { | @@ -231,4 +243,39 @@ public class BxRestService { | ||
| 231 | 243 | ||
| 232 | return result; | 244 | return result; |
| 233 | } | 245 | } |
| 246 | + @GET | ||
| 247 | + @Path("/history-arrival/{line}/{st}/{et}") | ||
| 248 | + public List<HistoryArrivalEntity> historyArrival(@PathParam("line") String line, @PathParam("st") String st, @PathParam("et") String et) { | ||
| 249 | + List<HistoryArrivalEntity> result = new ArrayList<>(); | ||
| 250 | + String password = ThreadLocalUtils.getPassword(); | ||
| 251 | + Set<String> limitLines = authorizeInterceptorIn.getLimitLines(password); | ||
| 252 | + Set<String> limitDevices = authorizeInterceptorIn.getLimitDevices(password); | ||
| 253 | + if (limitLines == null || limitLines.isEmpty() || !limitLines.contains(line)) { | ||
| 254 | + return result; | ||
| 255 | + } | ||
| 256 | + if (limitDevices == null || limitDevices.isEmpty()) { | ||
| 257 | + return result; | ||
| 258 | + } | ||
| 259 | + List<HistoryArrivalEntity> arrivals = historyGpsDao.queryArrival(line, Long.parseLong(st), Long.parseLong(et)); | ||
| 260 | + for (HistoryArrivalEntity arrival : arrivals) { | ||
| 261 | + String lineCode = String.valueOf(arrival.getLineId()), deviceId = arrival.getDeviceId(); | ||
| 262 | + Line line1 = LineBufferData.findOne(lineCode); | ||
| 263 | + if (line1 == null) { | ||
| 264 | + continue; | ||
| 265 | + } | ||
| 266 | + arrival.setLineName(line1.getName()); | ||
| 267 | + if ((limitLines.contains(lineCode) || limitLines.contains("ALL")) && (limitDevices.contains(deviceId) || limitDevices.contains("ALL"))) { | ||
| 268 | + result.add(arrival); | ||
| 269 | + } | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + return result; | ||
| 273 | + } | ||
| 274 | + | ||
| 275 | + @GET | ||
| 276 | + @Path("/limits/reload") | ||
| 277 | + public void reload() { | ||
| 278 | + String password = ThreadLocalUtils.getPassword(); | ||
| 279 | + authorizeInterceptorIn.loadLimit(password); | ||
| 280 | + } | ||
| 234 | } | 281 | } |
src/main/java/com/bsth/server_rs/gps/entity/HistoryArrivalEntity.java
| @@ -6,6 +6,8 @@ public class HistoryArrivalEntity { | @@ -6,6 +6,8 @@ public class HistoryArrivalEntity { | ||
| 6 | 6 | ||
| 7 | private int lineId; | 7 | private int lineId; |
| 8 | 8 | ||
| 9 | + private String lineName; | ||
| 10 | + | ||
| 9 | private String stopNo; | 11 | private String stopNo; |
| 10 | 12 | ||
| 11 | private int upDown; | 13 | private int upDown; |
| @@ -30,6 +32,14 @@ public class HistoryArrivalEntity { | @@ -30,6 +32,14 @@ public class HistoryArrivalEntity { | ||
| 30 | this.lineId = lineId; | 32 | this.lineId = lineId; |
| 31 | } | 33 | } |
| 32 | 34 | ||
| 35 | + public String getLineName() { | ||
| 36 | + return lineName; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public void setLineName(String lineName) { | ||
| 40 | + this.lineName = lineName; | ||
| 41 | + } | ||
| 42 | + | ||
| 33 | public String getStopNo() { | 43 | public String getStopNo() { |
| 34 | return stopNo; | 44 | return stopNo; |
| 35 | } | 45 | } |
src/main/resources/application.properties