Commit f6997c4b9d94c07c37ec6aa9f6c7a7945f68ab70
1 parent
9d793358
查询电量相关的接口中电量统一改为保留三位小数;新增接口:查询车辆某时刻营运状态与最近到离站(给稽查检查手机端)。
Showing
3 changed files
with
202 additions
and
4 deletions
src/main/java/com/bsth/repository/ScheduleRealInfoRepository.java
| ... | ... | @@ -32,6 +32,16 @@ public interface ScheduleRealInfoRepository extends PagingAndSortingRepository<S |
| 32 | 32 | List<ScheduleRealInfo> findAll(String schDate, String lineCode); |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | + * 根据日期和车辆编码获取班次信息 | |
| 36 | + * @param schDate | |
| 37 | + * @param lineCode | |
| 38 | + * @return | |
| 39 | + */ | |
| 40 | + @EntityGraph(value = "scheduleRealInfo_cTasks", type = EntityGraph.EntityGraphType.FETCH) | |
| 41 | + @Query("select DISTINCT s from ScheduleRealInfo s where s.scheduleDateStr=?1 and s.clZbh=?2") | |
| 42 | + List<ScheduleRealInfo> findByDateAndNbbm(String schDate, String nbbm); | |
| 43 | + | |
| 44 | + /** | |
| 35 | 45 | * 获取大于指定日期的班次信息 |
| 36 | 46 | * @param schDate |
| 37 | 47 | * @return |
| ... | ... | @@ -82,4 +92,10 @@ public interface ScheduleRealInfoRepository extends PagingAndSortingRepository<S |
| 82 | 92 | |
| 83 | 93 | @Query(value = " select bc_type from bsth_c_s_sp_info where id = ?1 ", nativeQuery = true) |
| 84 | 94 | List<String> findoOriginalType(Long spId); |
| 95 | + | |
| 96 | + @Query(value = " select equipment_code from bsth_c_cars where inside_code = ?1 ", nativeQuery = true) | |
| 97 | + List<String> findDeviceId(String nbbm); | |
| 98 | + | |
| 99 | + @Query(value = " select station_name, b_jwpoints from bsth_c_station where station_cod = ?1 ", nativeQuery = true) | |
| 100 | + List<Object[]> findStationName(String stationCode); | |
| 85 | 101 | } | ... | ... |
src/main/java/com/bsth/server_rs/bigdata/BigdataService.java
| ... | ... | @@ -2,6 +2,8 @@ package com.bsth.server_rs.bigdata; |
| 2 | 2 | |
| 3 | 3 | import java.math.BigDecimal; |
| 4 | 4 | import java.math.RoundingMode; |
| 5 | +import java.sql.Connection; | |
| 6 | +import java.sql.PreparedStatement; | |
| 5 | 7 | import java.sql.ResultSet; |
| 6 | 8 | import java.sql.SQLException; |
| 7 | 9 | import java.text.DecimalFormat; |
| ... | ... | @@ -47,6 +49,7 @@ import com.bsth.repository.OilInfoRepository; |
| 47 | 49 | import com.bsth.repository.ScheduleRealInfoRepository; |
| 48 | 50 | import com.bsth.server_rs.base_info.car.buffer.CarBufferData; |
| 49 | 51 | import com.bsth.util.Arith; |
| 52 | +import com.bsth.util.DBUtils_MS; | |
| 50 | 53 | |
| 51 | 54 | @Component |
| 52 | 55 | @Path("/bigdata") |
| ... | ... | @@ -73,9 +76,15 @@ public class BigdataService { |
| 73 | 76 | private CalcInvestigateMonthRepository calcInvestigateMonthRepository; |
| 74 | 77 | |
| 75 | 78 | |
| 76 | - DecimalFormat df = new DecimalFormat("0.00"); | |
| 79 | + private DecimalFormat df = new DecimalFormat("0.00"); | |
| 77 | 80 | |
| 78 | - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 81 | + private SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy"); | |
| 82 | + | |
| 83 | + private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); | |
| 84 | + | |
| 85 | + private SimpleDateFormat HHmmFormat = new SimpleDateFormat("HH:mm"); | |
| 86 | + | |
| 87 | + private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 79 | 88 | |
| 80 | 89 | /* |
| 81 | 90 | * 线路接口开始 |
| ... | ... | @@ -1706,7 +1715,7 @@ public class BigdataService { |
| 1706 | 1715 | public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { |
| 1707 | 1716 | Map<String, Object> m=new HashMap<String,Object>(); |
| 1708 | 1717 | m.put("car", rs.getString("nbbm")); |
| 1709 | - m.put("degrees", new BigDecimal(rs.getDouble("hd")).setScale(2, RoundingMode.HALF_UP)); | |
| 1718 | + m.put("degrees", new BigDecimal(rs.getDouble("hd")).setScale(3, RoundingMode.HALF_UP)); // 保留三位小数 | |
| 1710 | 1719 | return m; |
| 1711 | 1720 | } |
| 1712 | 1721 | }); |
| ... | ... | @@ -2177,4 +2186,177 @@ public class BigdataService { |
| 2177 | 2186 | return resList; |
| 2178 | 2187 | } |
| 2179 | 2188 | |
| 2189 | + /** | |
| 2190 | + * 查询车辆某时刻营运状态与最近到离站(给稽查检查手机端) | |
| 2191 | + * @param nbbm 车辆自编号 | |
| 2192 | + * @param time 时间(时间戳) | |
| 2193 | + * @return | |
| 2194 | + */ | |
| 2195 | + @GET | |
| 2196 | + @Path("/carArrival/{nbbm}/{time}") | |
| 2197 | + public JSONObject carArrival(@PathParam("nbbm") String nbbm, | |
| 2198 | + @PathParam("time") String time) { | |
| 2199 | + JSONObject resJson = new JSONObject(); | |
| 2200 | + long timeLong = Long.valueOf(time); | |
| 2201 | + Date dateTime = new Date(timeLong); | |
| 2202 | + String year = yearFormat.format(dateTime); | |
| 2203 | + String dateStr = dateFormat.format(dateTime); | |
| 2204 | + String HHmm = HHmmFormat.format(dateTime); | |
| 2205 | + long HHmmLong = fcsjToLong(HHmm); | |
| 2206 | + | |
| 2207 | + Calendar cal = Calendar.getInstance(); | |
| 2208 | + cal.setTime(dateTime); | |
| 2209 | + //周数,表分区字段 | |
| 2210 | + int weeks_year = cal.get(Calendar.WEEK_OF_YEAR); | |
| 2211 | + int weeks_year_next=weeks_year +1; | |
| 2212 | + | |
| 2213 | + String lineName = ""; | |
| 2214 | + String lineCode = ""; | |
| 2215 | + String dir = ""; | |
| 2216 | + String dirStr = ""; | |
| 2217 | + String stationName = ""; | |
| 2218 | + String stationCode = ""; | |
| 2219 | + String GPStime = ""; | |
| 2220 | + String inOut = ""; | |
| 2221 | + String bLongitude = ""; | |
| 2222 | + String bLatitude = ""; | |
| 2223 | + | |
| 2224 | + List<ScheduleRealInfo> findByDateAndNbbm = scheduleRealInfoRepository.findByDateAndNbbm(dateStr, nbbm); | |
| 2225 | + | |
| 2226 | + ScheduleRealInfo temp = null; | |
| 2227 | + long t = -1; | |
| 2228 | + for(ScheduleRealInfo s : findByDateAndNbbm){ // 遍历寻找最近的班次 | |
| 2229 | + long tt = -1; | |
| 2230 | + String fcsj = s.getFcsj(); | |
| 2231 | + long fcsjLong = fcsjToLong(fcsj); | |
| 2232 | + Set<ChildTaskPlan> childTaskPlans = s.getcTasks(); | |
| 2233 | + if(!childTaskPlans.isEmpty()){ | |
| 2234 | + List<ChildTaskPlan> listit = new ArrayList<ChildTaskPlan>(childTaskPlans); | |
| 2235 | + Collections.sort(listit, new Comparator<ChildTaskPlan>() { | |
| 2236 | + @Override | |
| 2237 | + public int compare(ChildTaskPlan o1, ChildTaskPlan o2) { | |
| 2238 | + // TODO Auto-generated method stub | |
| 2239 | + return o1.getStartDate().compareTo(o2.getStartDate()); | |
| 2240 | + } | |
| 2241 | + }); | |
| 2242 | + for(ChildTaskPlan c : listit){ | |
| 2243 | + if(!c.isDestroy() && c.getMileageType().equals("service")){ | |
| 2244 | + String startDate = c.getStartDate(); | |
| 2245 | + long startDateLong = fcsjToLong(startDate); | |
| 2246 | + if(HHmmLong >= startDateLong){ | |
| 2247 | + long delay = HHmmLong - startDateLong; | |
| 2248 | + if(tt == -1l || delay < tt){ | |
| 2249 | + tt = delay; | |
| 2250 | + } | |
| 2251 | + } | |
| 2252 | + } | |
| 2253 | + } | |
| 2254 | + } else if(s.getFcsjActual() != null && s.getFcsjActual().length() > 0){ | |
| 2255 | + long fcsjToLong = fcsjToLong(s.getFcsjActual()); | |
| 2256 | + if(HHmmLong >= fcsjToLong){ | |
| 2257 | + long delay = HHmmLong - fcsjToLong; | |
| 2258 | + if(tt == -1l || delay < tt){ | |
| 2259 | + tt = delay; | |
| 2260 | + } | |
| 2261 | + } | |
| 2262 | + } | |
| 2263 | + if(tt != -1l && (t == -1l || tt < t)){ // 取最近的上一个班次 | |
| 2264 | + t = tt; | |
| 2265 | + temp = s; | |
| 2266 | + } | |
| 2267 | + } | |
| 2268 | + | |
| 2269 | + if(temp != null){ | |
| 2270 | + lineName = temp.getXlName(); | |
| 2271 | + lineCode = temp.getXlBm(); | |
| 2272 | + dir = temp.getXlDir(); | |
| 2273 | + } | |
| 2274 | + | |
| 2275 | + String deviceId = ""; | |
| 2276 | + List<String> findDeviceId = scheduleRealInfoRepository.findDeviceId(nbbm); | |
| 2277 | + if(findDeviceId != null && findDeviceId.size() > 0){ | |
| 2278 | + deviceId = findDeviceId.get(0); | |
| 2279 | + } | |
| 2280 | + | |
| 2281 | + Connection conn = null; | |
| 2282 | + PreparedStatement ps = null; | |
| 2283 | + ResultSet rs = null; | |
| 2284 | + String sql = "select stop_no, ts, in_out from bsth_c_arrival_info_"+year+" where weeks_year in (?, ?)" | |
| 2285 | + + " AND line_id = ? AND up_down = ? AND device_id = ? AND ts <= ? order by ts desc"; | |
| 2286 | + try{ | |
| 2287 | + conn = DBUtils_MS.getConnection(); | |
| 2288 | + ps = conn.prepareStatement(sql); | |
| 2289 | + ps.setInt(1, weeks_year); | |
| 2290 | + ps.setInt(2, weeks_year_next); | |
| 2291 | + ps.setString(3, lineCode); | |
| 2292 | + ps.setString(4, dir); | |
| 2293 | + ps.setString(5, deviceId); | |
| 2294 | + ps.setLong(6, timeLong); | |
| 2295 | + rs = ps.executeQuery(); | |
| 2296 | + | |
| 2297 | + while(rs.next()){ | |
| 2298 | + String stopNo = rs.getString("stop_no"); | |
| 2299 | + List<Object[]> findStationName = scheduleRealInfoRepository.findStationName(stopNo); | |
| 2300 | + if(findStationName != null && findStationName.size() > 0){ | |
| 2301 | + Object[] objects = findStationName.get(0); | |
| 2302 | + stationName = objects[0]!=null?objects[0].toString():""; | |
| 2303 | + stationCode = stopNo; | |
| 2304 | + String baiPoints = objects[1]!=null?objects[1].toString():""; | |
| 2305 | + if(baiPoints.contains(" ")){ | |
| 2306 | + String[] split = baiPoints.split(" "); | |
| 2307 | + bLongitude = split[0]; | |
| 2308 | + bLatitude = split[1]; | |
| 2309 | + } | |
| 2310 | + | |
| 2311 | + GPStime = sdf.format(new Date(rs.getLong("ts"))); | |
| 2312 | + switch (rs.getString("in_out")) { | |
| 2313 | + case "0": | |
| 2314 | + inOut = "进站"; | |
| 2315 | + break; | |
| 2316 | + case "1": | |
| 2317 | + inOut = "出站"; | |
| 2318 | + break; | |
| 2319 | + default: | |
| 2320 | + break; | |
| 2321 | + } | |
| 2322 | + break; | |
| 2323 | + } | |
| 2324 | + } | |
| 2325 | + | |
| 2326 | + switch (dir) { | |
| 2327 | + case "0": | |
| 2328 | + dirStr = "上行"; | |
| 2329 | + break; | |
| 2330 | + case "1": | |
| 2331 | + dirStr = "下行"; | |
| 2332 | + break; | |
| 2333 | + default: | |
| 2334 | + break; | |
| 2335 | + } | |
| 2336 | + | |
| 2337 | + resJson.put("lineName", lineName); | |
| 2338 | + resJson.put("lineCode", lineCode); | |
| 2339 | + resJson.put("dir", dirStr); | |
| 2340 | + resJson.put("stationName", stationName); | |
| 2341 | + resJson.put("stationCode", stationCode); | |
| 2342 | + resJson.put("GPStime", GPStime); | |
| 2343 | + resJson.put("inOut", inOut); | |
| 2344 | + resJson.put("bLongitude", bLongitude); | |
| 2345 | + resJson.put("bLatitude", bLatitude); | |
| 2346 | + | |
| 2347 | + }catch(Exception e){ | |
| 2348 | + logger.error("", e); | |
| 2349 | + }finally { | |
| 2350 | + DBUtils_MS.close(rs, ps, conn); | |
| 2351 | + } | |
| 2352 | + | |
| 2353 | + return resJson; | |
| 2354 | + } | |
| 2355 | + | |
| 2356 | + private long fcsjToLong(String fcsj){ | |
| 2357 | + String[] split = fcsj.split(":"); | |
| 2358 | + long l = Long.valueOf(split[0])*60 + Long.valueOf(split[1]); | |
| 2359 | + return l; | |
| 2360 | + } | |
| 2361 | + | |
| 2180 | 2362 | } | ... | ... |
src/main/resources/ms-jdbc.properties
| ... | ... | @@ -4,6 +4,6 @@ |
| 4 | 4 | #ms.mysql.password= panzhao |
| 5 | 5 | |
| 6 | 6 | ms.mysql.driver= com.mysql.jdbc.Driver |
| 7 | -ms.mysql.url= jdbc:mysql://10.10.200.226:3306/ms?useUnicode=true&characterEncoding=utf-8 | |
| 7 | +ms.mysql.url= jdbc:mysql://192.170.100.63/ms?useUnicode=true&characterEncoding=utf-8 | |
| 8 | 8 | ms.mysql.username= root |
| 9 | 9 | ms.mysql.password= root2jsp |
| 10 | 10 | \ No newline at end of file | ... | ... |