Commit 7582ef846e7826c844f48c9074f93726969f6761
1 parent
aa9c5bb7
1.线路ID和CODE不一致时轨迹回放站点信息异常修复
2.线调中加入维修保养计划提示,并可下发短语提示驾驶员
Showing
13 changed files
with
2172 additions
and
1677 deletions
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(20); | |
| 20 | + public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(21); | |
| 21 | 21 | |
| 22 | 22 | @Override |
| 23 | 23 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | ... | ... |
src/main/java/com/bsth/XDApplication.java
| ... | ... | @@ -9,6 +9,7 @@ import com.bsth.data.forecast.SampleTimeDataLoader; |
| 9 | 9 | import com.bsth.data.gpsdata_v2.thread.GpsDataLoaderThread; |
| 10 | 10 | import com.bsth.data.gpsdata_v2.thread.OfflineMonitorThread; |
| 11 | 11 | import com.bsth.data.gpsdata_v2.thread.RfidDataLoaderThread; |
| 12 | +import com.bsth.data.maintenance_plan.MtPlanDataLoadThread; | |
| 12 | 13 | import com.bsth.data.msg_queue.DirectivePushQueue; |
| 13 | 14 | import com.bsth.data.msg_queue.WebSocketPushQueue; |
| 14 | 15 | import com.bsth.data.safe_driv.SafeDrivDataLoadThread; |
| ... | ... | @@ -89,6 +90,9 @@ public class XDApplication implements CommandLineRunner { |
| 89 | 90 | SafeDrivDataLoadThread safeDrivDataLoadThread; |
| 90 | 91 | |
| 91 | 92 | @Autowired |
| 93 | + MtPlanDataLoadThread mtPlanDataLoadThread; | |
| 94 | + | |
| 95 | + @Autowired | |
| 92 | 96 | FixedCheckStationCodeThread fixedCheckStationCodeThread; |
| 93 | 97 | |
| 94 | 98 | private static long timeDiff; |
| ... | ... | @@ -189,6 +193,7 @@ public class XDApplication implements CommandLineRunner { |
| 189 | 193 | ScheduledExecutorService sexec = Application.mainServices; |
| 190 | 194 | //安全驾驶 |
| 191 | 195 | sexec.scheduleWithFixedDelay(safeDrivDataLoadThread, 180, 10, TimeUnit.SECONDS); |
| 196 | + sexec.scheduleWithFixedDelay(mtPlanDataLoadThread, 180, 10, TimeUnit.SECONDS); | |
| 192 | 197 | |
| 193 | 198 | GpsDataLoaderThread.setFlag(-1); |
| 194 | 199 | /** 线调业务 */ | ... | ... |
src/main/java/com/bsth/data/maintenance_plan/MaintenancePlan.java
0 → 100644
| 1 | +package com.bsth.data.maintenance_plan; | |
| 2 | + | |
| 3 | +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * 维修保养计划 | |
| 7 | + * @author Hill | |
| 8 | + */ | |
| 9 | +@JsonIgnoreProperties(ignoreUnknown = true) | |
| 10 | +public class MaintenancePlan { | |
| 11 | + | |
| 12 | + /** | |
| 13 | + * 线路编码 | |
| 14 | + */ | |
| 15 | + private String line; | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * 线路名称 | |
| 19 | + */ | |
| 20 | + private String lineName; | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * 公司名称 | |
| 24 | + */ | |
| 25 | + private String gsmc; | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * 自编号 | |
| 29 | + */ | |
| 30 | + private String zbh; | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * 保养时间 | |
| 34 | + */ | |
| 35 | + private long bysj; | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * 保养等级 | |
| 39 | + */ | |
| 40 | + private String bydj; | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * 保养地点 | |
| 44 | + */ | |
| 45 | + private String bydd; | |
| 46 | + | |
| 47 | + @Override | |
| 48 | + public int hashCode() { | |
| 49 | + return ("mt_" + (this.getZbh() + this.getBysj())).hashCode(); | |
| 50 | + } | |
| 51 | + | |
| 52 | + @Override | |
| 53 | + public boolean equals(Object obj) { | |
| 54 | + MaintenancePlan s2 = (MaintenancePlan)obj; | |
| 55 | + return (this.getZbh() + this.getBysj()).equals(s2.getZbh() + s2.getBysj()); | |
| 56 | + } | |
| 57 | + | |
| 58 | + public String getLine() { | |
| 59 | + return line; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public void setLine(String line) { | |
| 63 | + this.line = line; | |
| 64 | + } | |
| 65 | + | |
| 66 | + public String getLineName() { | |
| 67 | + return lineName; | |
| 68 | + } | |
| 69 | + | |
| 70 | + public void setLineName(String lineName) { | |
| 71 | + this.lineName = lineName; | |
| 72 | + } | |
| 73 | + | |
| 74 | + public String getGsmc() { | |
| 75 | + return gsmc; | |
| 76 | + } | |
| 77 | + | |
| 78 | + public void setGsmc(String gcmc) { | |
| 79 | + this.gsmc = gcmc; | |
| 80 | + } | |
| 81 | + | |
| 82 | + public String getZbh() { | |
| 83 | + return zbh; | |
| 84 | + } | |
| 85 | + | |
| 86 | + public void setZbh(String zbh) { | |
| 87 | + this.zbh = zbh; | |
| 88 | + } | |
| 89 | + | |
| 90 | + public long getBysj() { | |
| 91 | + return bysj; | |
| 92 | + } | |
| 93 | + | |
| 94 | + public void setBysj(long bysj) { | |
| 95 | + this.bysj = bysj; | |
| 96 | + } | |
| 97 | + | |
| 98 | + public String getBydj() { | |
| 99 | + return bydj; | |
| 100 | + } | |
| 101 | + | |
| 102 | + public void setBydj(String bydj) { | |
| 103 | + this.bydj = bydj; | |
| 104 | + } | |
| 105 | + | |
| 106 | + public String getBydd() { | |
| 107 | + return bydd; | |
| 108 | + } | |
| 109 | + | |
| 110 | + public void setBydd(String bydd) { | |
| 111 | + this.bydd = bydd; | |
| 112 | + } | |
| 113 | +} | ... | ... |
src/main/java/com/bsth/data/maintenance_plan/MtPlanCenter.java
0 → 100644
| 1 | +package com.bsth.data.maintenance_plan; | |
| 2 | + | |
| 3 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 4 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 5 | +import com.bsth.websocket.handler.SendUtils; | |
| 6 | +import org.joda.time.format.DateTimeFormat; | |
| 7 | +import org.joda.time.format.DateTimeFormatter; | |
| 8 | +import org.slf4j.Logger; | |
| 9 | +import org.slf4j.LoggerFactory; | |
| 10 | +import org.springframework.beans.BeansException; | |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 12 | +import org.springframework.context.ApplicationContext; | |
| 13 | +import org.springframework.context.ApplicationContextAware; | |
| 14 | +import org.springframework.stereotype.Component; | |
| 15 | + | |
| 16 | +import java.util.HashMap; | |
| 17 | +import java.util.HashSet; | |
| 18 | +import java.util.Map; | |
| 19 | +import java.util.Set; | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * 维修保养计划推送 | |
| 23 | + * @author Hill | |
| 24 | + */ | |
| 25 | +@Component | |
| 26 | +public class MtPlanCenter implements ApplicationContextAware { | |
| 27 | + | |
| 28 | + private static Set<MaintenancePlan> data; | |
| 29 | + | |
| 30 | + private static SendUtils sendUtils; | |
| 31 | + | |
| 32 | + @Autowired | |
| 33 | + private static DayOfSchedule dayOfSchedule; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * 车辆自编号 和 最新一条数据对照 | |
| 37 | + */ | |
| 38 | + private static Map<String, MaintenancePlan> safeMap; | |
| 39 | + | |
| 40 | + private static Logger logger = LoggerFactory.getLogger(MtPlanCenter.class); | |
| 41 | + | |
| 42 | + static { | |
| 43 | + data = new HashSet<>(); | |
| 44 | + safeMap = new HashMap<>(); | |
| 45 | + } | |
| 46 | + | |
| 47 | + private static DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS"); | |
| 48 | + public static void put(MaintenancePlan maintenancePlan){ | |
| 49 | + if(!data.contains(maintenancePlan)){ | |
| 50 | + ScheduleRealInfo scheduleRealInfo = dayOfSchedule.executeCurr(maintenancePlan.getZbh()); | |
| 51 | + if (scheduleRealInfo != null) { | |
| 52 | + maintenancePlan.setLine(scheduleRealInfo.getXlBm()); | |
| 53 | + maintenancePlan.setLineName(scheduleRealInfo.getXlName()); | |
| 54 | + } | |
| 55 | + //通知客户端 | |
| 56 | + sendUtils.sendMaintenancePlan(maintenancePlan); | |
| 57 | + data.add(maintenancePlan); | |
| 58 | + safeMap.put(maintenancePlan.getZbh(), maintenancePlan); | |
| 59 | + } | |
| 60 | + } | |
| 61 | + | |
| 62 | + public static Set<MaintenancePlan> findAll(){ | |
| 63 | + return data; | |
| 64 | + } | |
| 65 | + | |
| 66 | + public static void clear(){ | |
| 67 | + data = new HashSet<>(); | |
| 68 | + safeMap = new HashMap<>(); | |
| 69 | + logger.info("清除安全驾驶数据,,,"); | |
| 70 | + } | |
| 71 | + | |
| 72 | + @Override | |
| 73 | + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | |
| 74 | + sendUtils = applicationContext.getBean(SendUtils.class); | |
| 75 | + dayOfSchedule = applicationContext.getBean(DayOfSchedule.class); | |
| 76 | + } | |
| 77 | +} | ... | ... |
src/main/java/com/bsth/data/maintenance_plan/MtPlanDataLoadThread.java
0 → 100644
| 1 | +package com.bsth.data.maintenance_plan; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson.JSON; | |
| 4 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
| 5 | +import org.apache.http.HttpEntity; | |
| 6 | +import org.apache.http.client.config.RequestConfig; | |
| 7 | +import org.apache.http.client.methods.CloseableHttpResponse; | |
| 8 | +import org.apache.http.client.methods.HttpGet; | |
| 9 | +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; | |
| 10 | +import org.apache.http.impl.client.CloseableHttpClient; | |
| 11 | +import org.apache.http.impl.client.HttpClients; | |
| 12 | +import org.joda.time.DateTime; | |
| 13 | +import org.slf4j.Logger; | |
| 14 | +import org.slf4j.LoggerFactory; | |
| 15 | +import org.springframework.beans.factory.InitializingBean; | |
| 16 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 17 | +import org.springframework.beans.factory.annotation.Value; | |
| 18 | +import org.springframework.stereotype.Component; | |
| 19 | + | |
| 20 | +import javax.net.ssl.*; | |
| 21 | +import java.io.BufferedReader; | |
| 22 | +import java.io.InputStreamReader; | |
| 23 | +import java.security.cert.CertificateException; | |
| 24 | +import java.security.cert.X509Certificate; | |
| 25 | +import java.util.List; | |
| 26 | +import java.util.Map; | |
| 27 | + | |
| 28 | +/** | |
| 29 | + * 维修保养计划 | |
| 30 | + */ | |
| 31 | +@Component | |
| 32 | +public class MtPlanDataLoadThread extends Thread implements InitializingBean { | |
| 33 | + | |
| 34 | + private Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 35 | + | |
| 36 | + @Value("${http.mtplan.interface}") | |
| 37 | + private String url; | |
| 38 | + private CloseableHttpClient httpClient; | |
| 39 | + private RequestConfig requestConfig; | |
| 40 | + private CloseableHttpResponse response; | |
| 41 | + private HttpEntity entity; | |
| 42 | + private BufferedReader br; | |
| 43 | + | |
| 44 | + private final static String HTTPS = "https://"; | |
| 45 | + | |
| 46 | + private SSLConnectionSocketFactory sslConnectionSocketFactory; | |
| 47 | + | |
| 48 | + @Autowired | |
| 49 | + private ObjectMapper objectMapper; | |
| 50 | + | |
| 51 | + public CloseableHttpClient defaultHttpClient(String url) { | |
| 52 | + if (url.startsWith(HTTPS)) { | |
| 53 | + return HttpClients.custom().setSSLSocketFactory(sslConnectionSocketFactory).build(); | |
| 54 | + } | |
| 55 | + return HttpClients.createDefault(); | |
| 56 | + } | |
| 57 | + | |
| 58 | + @Override | |
| 59 | + public void run() { | |
| 60 | + List<MaintenancePlan> list; | |
| 61 | + StringBuilder sb = new StringBuilder(url); | |
| 62 | + try { | |
| 63 | + HttpGet get = new HttpGet(sb.append("?date=").append(new DateTime().toString("yyyy-MM-dd")).toString()); | |
| 64 | + get.setConfig(requestConfig); | |
| 65 | + response = httpClient.execute(get); | |
| 66 | + | |
| 67 | + int statusCode = response.getStatusLine().getStatusCode(); | |
| 68 | + if(statusCode != 200){ | |
| 69 | + logger.error("http client status code: " + statusCode); | |
| 70 | + } | |
| 71 | + | |
| 72 | + entity = response.getEntity(); | |
| 73 | + if (null != entity) { | |
| 74 | + br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
| 75 | + StringBuffer stringBuffer = new StringBuffer(); | |
| 76 | + String str = ""; | |
| 77 | + while ((str = br.readLine()) != null) { | |
| 78 | + stringBuffer.append(str); | |
| 79 | + } | |
| 80 | + | |
| 81 | + //stringBuffer = new StringBuffer("{\"result\": [{\"gsmc\": \"杨高公司\", \"zbh\": \"S01-002\", \"bysj\": 1663171200000, \"bydj\": \"一级保养\", \"bydd\": \"成山路\"}], \"msg\": \"成功\", \"code\": \"200\", \"success\": true}"); | |
| 82 | + Map map = objectMapper.readValue(stringBuffer.toString(), Map.class); | |
| 83 | + list = objectMapper.readValue(objectMapper.writeValueAsString(map.get("result")), objectMapper.getTypeFactory().constructParametricType(List.class, MaintenancePlan.class)); | |
| 84 | + | |
| 85 | + for (MaintenancePlan sd : list) { | |
| 86 | + MtPlanCenter.put(sd); | |
| 87 | + } | |
| 88 | + } | |
| 89 | + | |
| 90 | + if (null != response) | |
| 91 | + response.close(); | |
| 92 | + } catch (Exception e) { | |
| 93 | + logger.error("维修保养计划接口报错了", e); | |
| 94 | + } | |
| 95 | + } | |
| 96 | + | |
| 97 | + @Override | |
| 98 | + public void afterPropertiesSet() throws Exception { | |
| 99 | + try { | |
| 100 | + SSLContext sslCtx = SSLContext.getInstance("TLSv1.2"); | |
| 101 | + sslCtx.init(null, new TrustManager[] { | |
| 102 | + new X509TrustManager() { | |
| 103 | + @Override | |
| 104 | + public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { | |
| 105 | + } | |
| 106 | + | |
| 107 | + @Override | |
| 108 | + public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { | |
| 109 | + } | |
| 110 | + | |
| 111 | + @Override | |
| 112 | + public X509Certificate[] getAcceptedIssuers() { | |
| 113 | + return null; | |
| 114 | + } | |
| 115 | + } | |
| 116 | + }, null); | |
| 117 | + sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslCtx, new HostnameVerifier() { | |
| 118 | + | |
| 119 | + @Override | |
| 120 | + public boolean verify(String hostname, SSLSession session) { | |
| 121 | + // TODO Auto-generated method stub | |
| 122 | + return true; | |
| 123 | + } | |
| 124 | + }); | |
| 125 | + } catch (Exception e) { | |
| 126 | + logger.error("SSL context set fail: {}", e); | |
| 127 | + } | |
| 128 | + | |
| 129 | + httpClient = defaultHttpClient(url); | |
| 130 | + | |
| 131 | + requestConfig = RequestConfig.custom() | |
| 132 | + .setConnectTimeout(5500).setConnectionRequestTimeout(5000) | |
| 133 | + .setSocketTimeout(5500).build(); | |
| 134 | + } | |
| 135 | +} | ... | ... |
src/main/java/com/bsth/service/gps/GpsServiceImpl.java
| 1 | -package com.bsth.service.gps; | |
| 2 | - | |
| 3 | -import java.io.IOException; | |
| 4 | -import java.io.OutputStream; | |
| 5 | -import java.io.UnsupportedEncodingException; | |
| 6 | -import java.lang.reflect.Field; | |
| 7 | -import java.net.URLEncoder; | |
| 8 | -import java.sql.Connection; | |
| 9 | -import java.sql.PreparedStatement; | |
| 10 | -import java.sql.ResultSet; | |
| 11 | -import java.sql.SQLException; | |
| 12 | -import java.text.DecimalFormat; | |
| 13 | -import java.text.ParseException; | |
| 14 | -import java.text.SimpleDateFormat; | |
| 15 | -import java.util.ArrayList; | |
| 16 | -import java.util.Arrays; | |
| 17 | -import java.util.Calendar; | |
| 18 | -import java.util.Collections; | |
| 19 | -import java.util.Comparator; | |
| 20 | -import java.util.Date; | |
| 21 | -import java.util.HashMap; | |
| 22 | -import java.util.HashSet; | |
| 23 | -import java.util.Iterator; | |
| 24 | -import java.util.LinkedList; | |
| 25 | -import java.util.List; | |
| 26 | -import java.util.Map; | |
| 27 | -import java.util.Set; | |
| 28 | - | |
| 29 | -import javax.servlet.http.HttpServletResponse; | |
| 30 | - | |
| 31 | -import org.apache.commons.lang3.StringUtils; | |
| 32 | -import org.apache.poi.hssf.usermodel.HSSFCellStyle; | |
| 33 | -import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |
| 34 | -import org.apache.poi.ss.usermodel.CellStyle; | |
| 35 | -import org.apache.poi.ss.usermodel.Row; | |
| 36 | -import org.apache.poi.ss.usermodel.Sheet; | |
| 37 | -import org.apache.poi.ss.usermodel.Workbook; | |
| 38 | -import org.joda.time.format.DateTimeFormat; | |
| 39 | -import org.joda.time.format.DateTimeFormatter; | |
| 40 | -import org.slf4j.Logger; | |
| 41 | -import org.slf4j.LoggerFactory; | |
| 42 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 43 | -import org.springframework.dao.DataAccessException; | |
| 44 | -import org.springframework.jdbc.core.BeanPropertyRowMapper; | |
| 45 | -import org.springframework.jdbc.core.JdbcTemplate; | |
| 46 | -import org.springframework.stereotype.Service; | |
| 47 | - | |
| 48 | -import com.bsth.common.ResponseCode; | |
| 49 | -import com.bsth.data.BasicData; | |
| 50 | -import com.bsth.data.forecast.entity.ArrivalEntity; | |
| 51 | -import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 52 | -import com.bsth.data.gpsdata_v2.cache.GeoCacheData; | |
| 53 | -import com.bsth.data.gpsdata_v2.cache.GpsCacheData; | |
| 54 | -import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 55 | -import com.bsth.data.gpsdata_v2.utils.GeoUtils; | |
| 56 | -import com.bsth.data.pilot80.PilotReport; | |
| 57 | -import com.bsth.data.safe_driv.SafeDriv; | |
| 58 | -import com.bsth.data.safe_driv.SafeDrivCenter; | |
| 59 | -import com.bsth.data.schedule.DayOfSchedule; | |
| 60 | -import com.bsth.entity.LineVersions; | |
| 61 | -import com.bsth.entity.LsSectionRoute; | |
| 62 | -import com.bsth.entity.LsStationRoute; | |
| 63 | -import com.bsth.entity.directive.D80; | |
| 64 | -import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 65 | -import com.bsth.repository.CarParkRepository; | |
| 66 | -import com.bsth.repository.LineRepository; | |
| 67 | -import com.bsth.repository.LineVersionsRepository; | |
| 68 | -import com.bsth.repository.LsSectionRouteRepository; | |
| 69 | -import com.bsth.repository.LsStationRouteRepository; | |
| 70 | -import com.bsth.repository.StationRepository; | |
| 71 | -import com.bsth.repository.realcontrol.ScheduleRealInfoRepository; | |
| 72 | -import com.bsth.service.gps.entity.DeviceChange; | |
| 73 | -import com.bsth.service.gps.entity.GpsOutbound_DTO; | |
| 74 | -import com.bsth.service.gps.entity.GpsSpeed; | |
| 75 | -import com.bsth.service.gps.entity.GpsSpeed_DTO; | |
| 76 | -import com.bsth.service.gps.entity.HistoryGps_DTO; | |
| 77 | -import com.bsth.service.gps.entity.HistoryGps_DTOV3; | |
| 78 | -import com.bsth.service.gps.entity.Road_DTO; | |
| 79 | -import com.bsth.util.TransGPS; | |
| 80 | -import com.bsth.util.TransGPS.Location; | |
| 81 | -import com.bsth.util.db.DBUtils_MS; | |
| 82 | - | |
| 83 | -@Service | |
| 84 | -public class GpsServiceImpl implements GpsService { | |
| 85 | - /** | |
| 86 | - * 历史gps查询最大范围 24小时 | |
| 87 | - */ | |
| 88 | - final static Long GPS_RANGE = 60 * 60 * 24L; | |
| 89 | - | |
| 90 | - /** | |
| 91 | - * jdbc | |
| 92 | - */ | |
| 93 | - Connection conn = null; | |
| 94 | - PreparedStatement ps = null; | |
| 95 | - ResultSet rs = null; | |
| 96 | - | |
| 97 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 98 | - | |
| 99 | - @Autowired | |
| 100 | - GpsRealData gpsRealData; | |
| 101 | - | |
| 102 | - @Autowired | |
| 103 | - JdbcTemplate jdbcTemplate; | |
| 104 | - | |
| 105 | - @Autowired | |
| 106 | - DayOfSchedule dayOfSchedule; | |
| 107 | - | |
| 108 | - @Autowired | |
| 109 | - ScheduleRealInfoRepository scheduleRealInfoRepository; | |
| 110 | - | |
| 111 | - | |
| 112 | - @Autowired | |
| 113 | - LineVersionsRepository lineVersionsRepository; | |
| 114 | - | |
| 115 | - @Autowired | |
| 116 | - LineRepository lineRepository; | |
| 117 | - | |
| 118 | - @Autowired | |
| 119 | - LsStationRouteRepository lsStationRouteRepository; | |
| 120 | - | |
| 121 | - @Autowired | |
| 122 | - LsSectionRouteRepository lsSectionRouteRepository; | |
| 123 | - | |
| 124 | - // 历史gps查询 | |
| 125 | - @Override | |
| 126 | - public List<Map<String, Object>> history(String device, Long startTime, Long endTime, int directions) { | |
| 127 | - Calendar sCal = Calendar.getInstance(); | |
| 128 | - sCal.setTime(new Date(startTime)); | |
| 129 | - | |
| 130 | - Calendar eCal = Calendar.getInstance(); | |
| 131 | - eCal.setTime(new Date(endTime)); | |
| 132 | - | |
| 133 | - int dayOfYear = sCal.get(Calendar.DAY_OF_YEAR); | |
| 134 | - /* | |
| 135 | - * if(dayOfYear != eCal.get(Calendar.DAY_OF_YEAR)){ | |
| 136 | - * System.out.println("暂时不支持跨天查询..."); return null; } | |
| 137 | - */ | |
| 138 | - | |
| 139 | - String sql = "select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE ,STOP_NO from bsth_c_gps_info where days_year=? and device_id=? and ts > ? and ts < ?"; | |
| 140 | - Connection conn = null; | |
| 141 | - PreparedStatement ps = null; | |
| 142 | - ResultSet rs = null; | |
| 143 | - List<Map<String, Object>> list = new ArrayList<>(); | |
| 144 | - Map<String, Object> map = null; | |
| 145 | - try { | |
| 146 | - conn = DBUtils_MS.getConnection(); | |
| 147 | - ps = conn.prepareStatement(sql); | |
| 148 | - ps.setInt(1, dayOfYear); | |
| 149 | - ps.setString(2, device); | |
| 150 | - ps.setLong(3, startTime); | |
| 151 | - ps.setLong(4, endTime); | |
| 152 | - | |
| 153 | - rs = ps.executeQuery(); | |
| 154 | - Float lon, lat; | |
| 155 | - Location location; | |
| 156 | - int upDown; | |
| 157 | - while (rs.next()) { | |
| 158 | - upDown = getUpOrDown(rs.getLong("SERVICE_STATE")); | |
| 159 | - if (upDown != directions) | |
| 160 | - continue; | |
| 161 | - | |
| 162 | - // to 百度坐标 | |
| 163 | - lon = rs.getFloat("LON"); | |
| 164 | - lat = rs.getFloat("LAT"); | |
| 165 | - location = TransGPS.LocationMake(lon, lat); | |
| 166 | - location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location)); | |
| 167 | - | |
| 168 | - map = new HashMap<>(); | |
| 169 | - map.put("device", rs.getString("DEVICE_ID")); | |
| 170 | - map.put("lon", location.getLng()); | |
| 171 | - map.put("lat", location.getLat()); | |
| 172 | - map.put("ts", rs.getLong("TS")); | |
| 173 | - map.put("stopNo", rs.getString("STOP_NO")); | |
| 174 | - map.put("inout_stop", rs.getInt("INOUT_STOP")); | |
| 175 | - // 上下行 | |
| 176 | - map.put("upDown", upDown); | |
| 177 | - list.add(map); | |
| 178 | - } | |
| 179 | - } catch (Exception e) { | |
| 180 | - e.printStackTrace(); | |
| 181 | - } finally { | |
| 182 | - DBUtils_MS.close(rs, ps, conn); | |
| 183 | - } | |
| 184 | - return list; | |
| 185 | - } | |
| 186 | - | |
| 187 | - /** | |
| 188 | - * 王通 2016/6/29 9:23:24 获取车辆线路上下行 | |
| 189 | - * | |
| 190 | - * @return -1无效 0上行 1下行 | |
| 191 | - */ | |
| 192 | - public static byte getUpOrDown(long serviceState) { | |
| 193 | - /*if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000 | |
| 194 | - || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000) | |
| 195 | - return -1;*/ | |
| 196 | - return (byte) (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0); | |
| 197 | - } | |
| 198 | - | |
| 199 | - /** | |
| 200 | - * 获取运营状态 | |
| 201 | - * | |
| 202 | - * @return -1无效 0运营 1未运营 | |
| 203 | - */ | |
| 204 | - public static byte getService(long serviceState) { | |
| 205 | - /*if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000) | |
| 206 | - return -1;*/ | |
| 207 | - return (byte) (((serviceState & 0x02000000) == 0x02000000) ? 1 : 0); | |
| 208 | - } | |
| 209 | - | |
| 210 | - private static DateTimeFormatter fmtyyyy = DateTimeFormat.forPattern("yyyy"); | |
| 211 | - @Override | |
| 212 | - public Map<String, Object> history(String[] nbbmArray, Long st, Long et) { | |
| 213 | - Map<String, Object> rsMap = new HashMap<>(); | |
| 214 | - List<Map<String, Object>> list = new ArrayList<>(); | |
| 215 | - rsMap.put("list", list); | |
| 216 | - if (et - st > GPS_RANGE) | |
| 217 | - return rsMap; | |
| 218 | - | |
| 219 | - st = st * 1000; | |
| 220 | - et = et * 1000; | |
| 221 | - // day_of_year 分区字段 | |
| 222 | - Calendar sCal = Calendar.getInstance(); | |
| 223 | - sCal.setTime(new Date(st)); | |
| 224 | - int sDayOfYear = sCal.get(Calendar.DAY_OF_YEAR); | |
| 225 | - Calendar eCal = Calendar.getInstance(); | |
| 226 | - eCal.setTime(new Date(et)); | |
| 227 | - int eDayOfYear = eCal.get(Calendar.DAY_OF_YEAR); | |
| 228 | - | |
| 229 | - String nbbm = nbbmArray[0]; | |
| 230 | - | |
| 231 | - List<DeviceChange> dcs = findDeviceChangeLogs(nbbm, et, st); | |
| 232 | - | |
| 233 | - //按年分表 | |
| 234 | - String tableName = "bsth_c_gps_info_" + fmtyyyy.print(st); | |
| 235 | - | |
| 236 | - StringBuilder sql = new StringBuilder(""); | |
| 237 | - long t1,t2; | |
| 238 | - DeviceChange dc; | |
| 239 | - for(int i = 0,len=dcs.size(); i < len; i++){ | |
| 240 | - t1 = st; | |
| 241 | - t2 = et; | |
| 242 | - dc = dcs.get(i); | |
| 243 | - if(dc.getSt() > st) | |
| 244 | - t1 = dc.getSt(); | |
| 245 | - if(dc.getEt() < et && dc.getEt()!=0) | |
| 246 | - t2 = dc.getEt(); | |
| 247 | - | |
| 248 | - sql.append("select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE ,STOP_NO,DIRECTION,LINE_ID,SPEED_GPS,SECTION_CODE from "+tableName+" where days_year in ("+sDayOfYear+","+eDayOfYear+") " + | |
| 249 | - " and device_id='"+dc.getDevice()+"' and ts >= "+t1+" and ts <= "+t2+" "); | |
| 250 | - | |
| 251 | - if(i == len - 1) | |
| 252 | - sql.append(" ORDER BY device_id,ts,stop_no"); | |
| 253 | - else | |
| 254 | - sql.append(" UNION "); | |
| 255 | - } | |
| 256 | - | |
| 257 | - logger.info("轨迹回放 nbbm: " + nbbm + " -st: " + st + " -et: " + et + " -sql: " + sql.toString()); | |
| 258 | - | |
| 259 | - // 查询到离站数据 | |
| 260 | - Map<String, ArrivalEntity> arrivalMap = findArrivalByTs(st, et, dcs); | |
| 261 | - | |
| 262 | - //查询GPS数据 | |
| 263 | - JdbcTemplate jdbcTemplate_ms = new JdbcTemplate(DBUtils_MS.getDataSource()); | |
| 264 | - List<Map<String, Object>> dataList = jdbcTemplate_ms.queryForList(sql.toString()); | |
| 265 | - | |
| 266 | - Float lon, lat; | |
| 267 | - Location bdLoc, gdLoc; | |
| 268 | - int inOutStop; | |
| 269 | - long serviceState; | |
| 270 | - ArrivalEntity arrival; | |
| 271 | - Set<Integer> lineSet=new HashSet<Integer>(); | |
| 272 | - List<Map<String,Object>> lineSwitch=new ArrayList<>(); | |
| 273 | - | |
| 274 | - List<Map<String, Object>> gpsNotValidList=new ArrayList<>(); | |
| 275 | - List<Map<String, Object>> gpsEqualsZeroList=new ArrayList<>(); | |
| 276 | - Map<String, Object> map = null; | |
| 277 | - int oldLineId = -1, oldGpsValid = -1, oldLonlat = -1; | |
| 278 | - | |
| 279 | - // 默认加入一个线路切换信息 | |
| 280 | - Map<String, Object> fls = new HashMap<String, Object>(); | |
| 281 | - fls.put("abnormalType", "normal"); | |
| 282 | - fls.put("st", "-1"); | |
| 283 | - lineSwitch.add(fls); | |
| 284 | - | |
| 285 | - // 默认加入一个GPS无效异常信息 | |
| 286 | - Map<String, Object> fgv = new HashMap<String, Object>(); | |
| 287 | - fgv.put("abnormalType", "normal"); | |
| 288 | - fgv.put("st", "-1"); | |
| 289 | - gpsNotValidList.add(fgv); | |
| 290 | - | |
| 291 | - // 默认加入一个经纬度为零异常信息 | |
| 292 | - Map<String, Object> fgez = new HashMap<String, Object>(); | |
| 293 | - fgez.put("abnormalType", "normal"); | |
| 294 | - fgez.put("st", "-1"); | |
| 295 | - gpsEqualsZeroList.add(fgez); | |
| 296 | - | |
| 297 | - for(Map<String, Object> rs : dataList) { | |
| 298 | - Object lineId = rs.get("LINE_ID"); | |
| 299 | - // 线路ID发生变化时补全线路切换信息 并新加入一个 | |
| 300 | - if (oldLineId != (Integer)lineId) { | |
| 301 | - String lineName = BasicData.lineCode2NameMap.get(lineId.toString()); | |
| 302 | - lineSwitch.get(lineSwitch.size() - 1).put("line2", lineName); | |
| 303 | - lineSwitch.get(lineSwitch.size() - 1).put("et", rs.get("TS")); | |
| 304 | - | |
| 305 | - Map<String, Object> ls = new HashMap<String, Object>(); | |
| 306 | - ls.put("abnormalType", "lineSwitch"); | |
| 307 | - ls.put("line1", lineName); | |
| 308 | - lineSwitch.add(ls); | |
| 309 | - | |
| 310 | - lineSet.add((Integer)lineId); | |
| 311 | - oldLineId = (Integer)lineId; | |
| 312 | - } | |
| 313 | - serviceState = map_get_long(rs, "SERVICE_STATE"); | |
| 314 | - // GPS状态发生变化时补全信息 并新加入一个 | |
| 315 | - if (getGpsValid(serviceState) != oldGpsValid) { | |
| 316 | - gpsNotValidList.get(gpsNotValidList.size() - 1).put("et", rs.get("TS")); | |
| 317 | - | |
| 318 | - Map<String, Object> gv = new HashMap<String, Object>(); | |
| 319 | - gv.put("abnormalType", getGpsValid(serviceState) == 0 ? "normal" : "gpsNotValid"); | |
| 320 | - gv.put("st", rs.get("TS")); | |
| 321 | - gpsNotValidList.add(gv); | |
| 322 | - | |
| 323 | - oldGpsValid = getGpsValid(serviceState); | |
| 324 | - } | |
| 325 | - | |
| 326 | - map = new HashMap<>(); | |
| 327 | - lon = map_get_float(rs, "LON"); | |
| 328 | - lat = map_get_float(rs, "LAT"); | |
| 329 | - // 经纬度为零 | |
| 330 | - if ((lon == 0 || lat == 0 ? 1 : 0) != oldLonlat){ | |
| 331 | - gpsEqualsZeroList.get(gpsEqualsZeroList.size() - 1).put("et", rs.get("TS")); | |
| 332 | - | |
| 333 | - Map<String, Object> gez = new HashMap<String, Object>(); | |
| 334 | - gez.put("abnormalType", (lon == 0 || lat == 0 ? 1 : 0) == 0 ? "normal" : "gpsZero"); | |
| 335 | - gez.put("st", rs.get("TS")); | |
| 336 | - gpsEqualsZeroList.add(gez); | |
| 337 | - | |
| 338 | - oldLonlat = (lon == 0 || lat == 0 ? 1 : 0); | |
| 339 | - } | |
| 340 | - | |
| 341 | - // 高德坐标 | |
| 342 | - gdLoc = TransGPS.transformFromWGSToGCJ(TransGPS.LocationMake(lon, lat)); | |
| 343 | - map.put("gcj_lon", gdLoc.getLng()); | |
| 344 | - map.put("gcj_lat", gdLoc.getLat()); | |
| 345 | - // 百度坐标 | |
| 346 | - bdLoc = TransGPS.bd_encrypt(gdLoc); | |
| 347 | - map.put("bd_lon", bdLoc.getLng()); | |
| 348 | - map.put("bd_lat", bdLoc.getLat()); | |
| 349 | - //原始坐标 | |
| 350 | - map.put("lon", lon); | |
| 351 | - map.put("lat", lat); | |
| 352 | - | |
| 353 | - map.put("deviceId", map_get_str(rs, "DEVICE_ID")); | |
| 354 | - map.put("ts", map_get_long(rs, "TS")); | |
| 355 | - map.put("timestamp", map_get_long(rs, "TS")); | |
| 356 | - map.put("stopNo", map_get_str(rs, "STOP_NO")); | |
| 357 | - map.put("direction", map_get_float(rs,"DIRECTION")); | |
| 358 | - | |
| 359 | - map.put("lineId", map_get_str(rs, "LINE_ID")); | |
| 360 | - map.put("speed", map_get_float(rs,"SPEED_GPS")); | |
| 361 | - | |
| 362 | - inOutStop = Integer.parseInt(rs.get("INOUT_STOP").toString()); | |
| 363 | - map.put("inout_stop", inOutStop); | |
| 364 | - | |
| 365 | - arrival = arrivalMap.get(map_get_str(rs, "DEVICE_ID") + "_" + map_get_long(rs, "TS")); | |
| 366 | - if (arrival != null) { | |
| 367 | - map.put("inout_stop_info", arrival); | |
| 368 | - map.put("inout_stop", arrival.getInOut()); | |
| 369 | - } | |
| 370 | - | |
| 371 | - //map.put("nbbm", nbbm); | |
| 372 | - map.put("state", getService(serviceState)); | |
| 373 | - // 上下行 | |
| 374 | - map.put("upDown", getUpOrDown(serviceState)); | |
| 375 | - //路段编码 | |
| 376 | - map.put("section_code", map_get_str(rs,"SECTION_CODE")); | |
| 377 | - list.add(map); | |
| 378 | - } | |
| 379 | - if (dataList.size() > 0) { | |
| 380 | - Map<String, Object> rs = dataList.get(dataList.size() - 1); | |
| 381 | - gpsNotValidList.get(gpsNotValidList.size() - 1).put("et", rs.get("TS")); | |
| 382 | - gpsEqualsZeroList.get(gpsEqualsZeroList.size() - 1).put("et", rs.get("TS")); | |
| 383 | - } | |
| 384 | - | |
| 385 | - for (int i = lineSwitch.size() - 1;i > -1;i--) { | |
| 386 | - Map<String, Object> ls = lineSwitch.get(i); | |
| 387 | - if ("normal".equals(ls.get("abnormalType")) || ls.get("et") == null) { | |
| 388 | - lineSwitch.remove(i); | |
| 389 | - } | |
| 390 | - } | |
| 391 | - | |
| 392 | - for (int i = gpsNotValidList.size() - 1;i > -1;i--) { | |
| 393 | - Map<String, Object> gnv = gpsNotValidList.get(i); | |
| 394 | - if ("normal".equals(gnv.get("abnormalType"))) { | |
| 395 | - gpsNotValidList.remove(i); | |
| 396 | - } | |
| 397 | - } | |
| 398 | - | |
| 399 | - for (int i = gpsEqualsZeroList.size() - 1;i > -1;i--) { | |
| 400 | - Map<String, Object> gez = gpsEqualsZeroList.get(i); | |
| 401 | - if ("normal".equals(gez.get("abnormalType"))) { | |
| 402 | - gpsEqualsZeroList.remove(i); | |
| 403 | - } | |
| 404 | - } | |
| 405 | - | |
| 406 | - if (lineSet.size() > 0){ | |
| 407 | - List<Map<String,Object>> vlist=new ArrayList<>(); | |
| 408 | - Map<String, Map<String, Object>> vmap = new HashMap<>(); | |
| 409 | - Map<String, Map<String, String>> lv2station = new HashMap<String, Map<String, String>>();//lv2section = new HashMap<String, Map<String, String>>(); | |
| 410 | - for (Integer lineId : lineSet) { | |
| 411 | - List<LineVersions> lvs = lineVersionsRepository.findBylineId(lineId); | |
| 412 | - for (LineVersions lv : lvs) { | |
| 413 | - long vst = lv.getStartDate().getTime(), vet = lv.getEndDate().getTime(); | |
| 414 | - if (st >= vst && st <= vet || et >= vst && et <= vet) { | |
| 415 | - List<LsStationRoute> stations = lsStationRouteRepository.findupdated(lineId, lineId.toString(), lv.getVersions()); | |
| 416 | - //List<LsSectionRoute> sections = lsSectionRouteRepository.findupdated(lineId, lineId.toString(), lv.getVersions()); | |
| 417 | - Map<String, Object> vm = new HashMap<String, Object>(); | |
| 418 | - vm.put("lineId", lineId.toString()); | |
| 419 | - vm.put("version", lv.getVersions()); | |
| 420 | - vm.put("startTime", vst); | |
| 421 | - vm.put("endTime", vet); | |
| 422 | - vm.put("stations", stations); | |
| 423 | - //vm.put("sections", sections); | |
| 424 | - | |
| 425 | - Map<String, String> stationcode2name = new HashMap<String, String>();//sectioncode2name = new HashMap<String, String>(); | |
| 426 | - for (LsStationRoute lsr : stations) { | |
| 427 | - stationcode2name.put(lsr.getStationCode(), lsr.getStationName()); | |
| 428 | - } | |
| 429 | - //for (LsSectionRoute lsr : sections) { | |
| 430 | - // sectioncode2name.put(lsr.getSectionCode(), lsr.getSection().getSectionName()); | |
| 431 | - //} | |
| 432 | - lv2station.put(lineId + "_" + lv.getVersions(), stationcode2name); | |
| 433 | - // 路段因为可能漂到其它线路路段 因此需要使用最新的全量路段 | |
| 434 | - //lv2section.put(lineId + "_" + lv.getVersions(), sectioncode2name); | |
| 435 | - | |
| 436 | - vlist.add(vm); | |
| 437 | - vmap.put(lineId + "_" + lv.getVersions(), vm); | |
| 438 | - } | |
| 439 | - } | |
| 440 | - } | |
| 441 | - rsMap.put("lineVerson",vlist); | |
| 442 | - | |
| 443 | - for (Map<String, Object> gps : list) { | |
| 444 | - long ts = (long)gps.get("timestamp"); | |
| 445 | - for (Map<String, Object> vm : vlist) { | |
| 446 | - long vst = (long)vm.get("startTime"), vet = (long)vm.get("endTime"); | |
| 447 | - if (gps.get("lineId").equals(vm.get("lineId")) && ts >= vst && ts <= vet) { | |
| 448 | - gps.put("version", vm.get("version")); | |
| 449 | - String key = vm.get("lineId") + "_" + vm.get("version"); | |
| 450 | - /*if (StringUtils.isEmpty(sectionCode)) { | |
| 451 | - gps.put("section_code", "-00404"); | |
| 452 | - gps.put("section_name", "未知路段"); | |
| 453 | - } | |
| 454 | - gps.put("section_name", lv2section.get(key).get(sectionCode));*/ | |
| 455 | - ArrivalEntity ae = (ArrivalEntity)gps.get("inout_stop_info"); | |
| 456 | - if (ae != null) { | |
| 457 | - ae.setStopName(lv2station.get(key).get(ae.getStopNo())); | |
| 458 | - if (StringUtils.isEmpty(lv2station.get(key).get(ae.getStopNo()))) { | |
| 459 | - ae.setStopName(BasicData.stationCode2NameMap.get(ae.getStopNo())); | |
| 460 | - } | |
| 461 | - } | |
| 462 | - } | |
| 463 | - } | |
| 464 | - } | |
| 465 | - } | |
| 466 | - // 按时间排序 | |
| 467 | - Collections.sort(list, new Comparator<Map<String, Object>>() { | |
| 468 | - | |
| 469 | - @Override | |
| 470 | - public int compare(Map<String, Object> o1, Map<String, Object> o2) { | |
| 471 | - return (int) (Long.parseLong(o1.get("ts").toString()) - Long.parseLong(o2.get("ts").toString())); | |
| 472 | - } | |
| 473 | - }); | |
| 474 | - | |
| 475 | - rsMap.put("list", list); | |
| 476 | - rsMap.put("dcs", dcs); | |
| 477 | - rsMap.put("gpsNotValid",gpsNotValidList); | |
| 478 | - rsMap.put("lineSwitch",lineSwitch); | |
| 479 | - rsMap.put("lonlatZero",gpsEqualsZeroList); | |
| 480 | - return rsMap; | |
| 481 | - } | |
| 482 | - | |
| 483 | - private String map_get_str(Map<String, Object> map, String key){ | |
| 484 | - return map.containsKey(key)?map.get(key).toString():""; | |
| 485 | - } | |
| 486 | - | |
| 487 | - private Long map_get_long(Map<String, Object> map, String key){ | |
| 488 | - return map.containsKey(key)?Long.parseLong(map.get(key).toString()):-1; | |
| 489 | - } | |
| 490 | - | |
| 491 | - private Float map_get_float(Map<String, Object> map, String key){ | |
| 492 | - return map.containsKey(key)?Float.parseFloat(map.get(key).toString()):-1; | |
| 493 | - } | |
| 494 | - | |
| 495 | - private List<DeviceChange> findDeviceChangeLogs(String nbbm, long et, long st){ | |
| 496 | - List<DeviceChange> dcs = null; | |
| 497 | - List<DeviceChange> rs = new ArrayList<>(); | |
| 498 | - try{ | |
| 499 | - | |
| 500 | - //JdbcTemplate jdbcTemplate_ms = new JdbcTemplate(DBUtils_MS.getDataSource()); | |
| 501 | - dcs = jdbcTemplate.query("select cl_zbh as nbbm,new_device_no as device,old_device_no as old_device,UNIX_TIMESTAMP(qyrq) * 1000 as st from bsth_c_car_device where is_cancel=0 and cl_zbh='"+nbbm+"' order by qyrq" | |
| 502 | - , BeanPropertyRowMapper.newInstance(DeviceChange.class)); | |
| 503 | - | |
| 504 | - | |
| 505 | - //生成一条初始记录 | |
| 506 | - if(dcs.size() > 0){ | |
| 507 | - DeviceChange first = dcs.get(0); | |
| 508 | - | |
| 509 | - DeviceChange initDv = new DeviceChange(); | |
| 510 | - initDv.setDevice(first.getOldDevice()); | |
| 511 | - if(StringUtils.isNotEmpty(initDv.getDevice())){ | |
| 512 | - initDv.setNbbm(first.getNbbm()); | |
| 513 | - initDv.setSt(0); | |
| 514 | - initDv.setEt(first.getSt()); | |
| 515 | - dcs.add(0, initDv); | |
| 516 | - } | |
| 517 | - } | |
| 518 | - for(int i = 0,len=dcs.size(); i < len - 1; i++){ | |
| 519 | - dcs.get(i).setEt(dcs.get(i + 1).getSt()); | |
| 520 | - } | |
| 521 | - | |
| 522 | - for(DeviceChange dc : dcs){ | |
| 523 | - if(dc.getEt() < st && dc.getEt() != 0) | |
| 524 | - continue; | |
| 525 | - if(dc.getSt() > et) | |
| 526 | - continue; | |
| 527 | - | |
| 528 | - rs.add(dc); | |
| 529 | - } | |
| 530 | - | |
| 531 | - //没有设备变更记录,则参考车辆信息上的设备号 | |
| 532 | - if(null == rs || rs.size() == 0){ | |
| 533 | - DeviceChange dc = new DeviceChange(); | |
| 534 | - dc.setNbbm(nbbm); | |
| 535 | - dc.setDevice(BasicData.deviceId2NbbmMap.inverse().get(nbbm)); | |
| 536 | - dc.setSt(st); | |
| 537 | - dc.setEt(et); | |
| 538 | - dc.setType(1); | |
| 539 | - | |
| 540 | - rs.add(dc); | |
| 541 | - } | |
| 542 | - }catch (Exception e){ | |
| 543 | - logger.error("", e); | |
| 544 | - } | |
| 545 | - return rs; | |
| 546 | - } | |
| 547 | - | |
| 548 | - public static byte getGpsValid(long serviceState) { | |
| 549 | - return (byte)(((serviceState & 0x80000000) == 0x80000000) ? 1 : 0); | |
| 550 | - } | |
| 551 | - | |
| 552 | - public static void main(String[] args){ | |
| 553 | - System.out.println(getGpsValid(-2147483648)); | |
| 554 | - } | |
| 555 | - | |
| 556 | - public Map<String, ArrivalEntity> findArrivalByTs(Long st, Long et, List<DeviceChange> dcs) { | |
| 557 | - Map<String, ArrivalEntity> map = new HashMap<>(); | |
| 558 | - | |
| 559 | - // weeks_year 分区字段 | |
| 560 | - Calendar sCal = Calendar.getInstance(); | |
| 561 | - sCal.setTime(new Date(st)); | |
| 562 | - int sWeekOfYear = sCal.get(Calendar.WEEK_OF_YEAR); | |
| 563 | - Calendar eCal = Calendar.getInstance(); | |
| 564 | - eCal.setTime(new Date(et)); | |
| 565 | - int eWeekOfYear = eCal.get(Calendar.WEEK_OF_YEAR); | |
| 566 | - | |
| 567 | - //按年分表 | |
| 568 | - String tableName = "bsth_c_arrival_info_" + fmtyyyy.print(st); | |
| 569 | - | |
| 570 | - StringBuilder sql = new StringBuilder(""); | |
| 571 | - long t1,t2; | |
| 572 | - DeviceChange dc; | |
| 573 | - for(int i = 0,len=dcs.size(); i < len; i++){ | |
| 574 | - t1 = st; | |
| 575 | - t2 = et; | |
| 576 | - dc = dcs.get(i); | |
| 577 | - if(dc.getSt() > st) | |
| 578 | - t1 = dc.getSt(); | |
| 579 | - if(dc.getEt() < et && dc.getEt() != 0) | |
| 580 | - t2 = dc.getEt(); | |
| 581 | - | |
| 582 | - sql.append("SELECT DEVICE_ID,LINE_ID as LINE_CODE,STOP_NO,TS,UP_DOWN,IN_OUT,WEEKS_YEAR,CREATE_DATE FROM " + tableName + | |
| 583 | - " where weeks_year in ("+sWeekOfYear+", "+eWeekOfYear+") and device_id='"+dc.getDevice()+"' and ts > "+t1+" and ts < " + t2); | |
| 584 | - | |
| 585 | - if(i == len - 1) | |
| 586 | - sql.append(" ORDER BY device_id,ts,stop_no "); | |
| 587 | - else | |
| 588 | - sql.append(" UNION "); | |
| 589 | - } | |
| 590 | - | |
| 591 | - logger.info("arrivl sql : " + sql.toString()); | |
| 592 | - JdbcTemplate jdbcTemplate_ms = new JdbcTemplate(DBUtils_MS.getDataSource()); | |
| 593 | - List<ArrivalEntity> list = jdbcTemplate_ms.query(sql.toString(), BeanPropertyRowMapper.newInstance(ArrivalEntity.class)); | |
| 594 | - | |
| 595 | - String stationName, prefix; | |
| 596 | - for(ArrivalEntity arr : list){ | |
| 597 | - prefix = arr.getLineCode() + "_" + arr.getUpDown() + "_"; | |
| 598 | - stationName = BasicData.getStationNameByCode(arr.getStopNo(), prefix); | |
| 599 | - | |
| 600 | - arr.setStopName(stationName); | |
| 601 | - | |
| 602 | - // 反转进出状态 | |
| 603 | - map.put(arr.getDeviceId() + "_" + arr.getTs(), arr); | |
| 604 | - } | |
| 605 | - return map; | |
| 606 | - } | |
| 607 | - | |
| 608 | - | |
| 609 | - @Autowired | |
| 610 | - StationRepository stationRepository; | |
| 611 | - | |
| 612 | - @Autowired | |
| 613 | - CarParkRepository carParkRepository; | |
| 614 | - | |
| 615 | - @Override | |
| 616 | - public Map<String, Object> findBuffAeraByCode(String code, String type) { | |
| 617 | - Object[][] obj = null; | |
| 618 | - if (type.equals("station")) | |
| 619 | - obj = stationRepository.bufferAera(code); | |
| 620 | - else if (type.equals("park")) | |
| 621 | - obj = carParkRepository.bufferAera(code); | |
| 622 | - | |
| 623 | - Map<String, Object> rs = new HashMap<>(); | |
| 624 | - | |
| 625 | - Object[] subObj = obj[0]; | |
| 626 | - if (subObj != null && subObj.length == 6) { | |
| 627 | - rs.put("polygon", subObj[0]); | |
| 628 | - rs.put("type", subObj[1]); | |
| 629 | - rs.put("cPoint", subObj[2]); | |
| 630 | - rs.put("radius", subObj[3]); | |
| 631 | - rs.put("code", subObj[4]); | |
| 632 | - rs.put("text", subObj[5]); | |
| 633 | - } | |
| 634 | - | |
| 635 | - return rs; | |
| 636 | - } | |
| 637 | - | |
| 638 | - @Override | |
| 639 | - public Map<String, Object> search(Map<String, Object> map, int page, int size, String order, String direction) { | |
| 640 | - Map<String, Object> rsMap = new HashMap<>(); | |
| 641 | - try { | |
| 642 | - //全量 | |
| 643 | - List<GpsEntity> list = new ArrayList<>(gpsRealData.all()); | |
| 644 | - //过滤后的 | |
| 645 | - List<GpsEntity> rs = new ArrayList<>(); | |
| 646 | - Field[] fields = GpsEntity.class.getDeclaredFields(); | |
| 647 | - //参与过滤的字段 | |
| 648 | - List<Field> fs = new ArrayList<>(); | |
| 649 | - for (Field f : fields) { | |
| 650 | - f.setAccessible(true); | |
| 651 | - if (map.containsKey(f.getName())) | |
| 652 | - fs.add(f); | |
| 653 | - } | |
| 654 | - //过滤数据 | |
| 655 | - for (GpsEntity gps : list) { | |
| 656 | - if (fieldEquals(fs, gps, map)) | |
| 657 | - rs.add(gps); | |
| 658 | - } | |
| 659 | - | |
| 660 | - //时间戳排序 | |
| 661 | - Collections.sort(rs, new Comparator<GpsEntity>() { | |
| 662 | - @Override | |
| 663 | - public int compare(GpsEntity o1, GpsEntity o2) { | |
| 664 | - return o2.getTimestamp().intValue() - o1.getTimestamp().intValue(); | |
| 665 | - } | |
| 666 | - }); | |
| 667 | - | |
| 668 | - //分页 | |
| 669 | - int count = rs.size(), s = page * size, e = s + size; | |
| 670 | - if (e > count) | |
| 671 | - e = count; | |
| 672 | - | |
| 673 | - rsMap.put("list", rs.subList(s, e)); | |
| 674 | - rsMap.put("totalPages", count % size == 0 ? count / size - 1 : count / size); | |
| 675 | - rsMap.put("page", page); | |
| 676 | - rsMap.put("status", ResponseCode.SUCCESS); | |
| 677 | - } catch (Exception e) { | |
| 678 | - logger.error("", e); | |
| 679 | - rsMap.put("status", ResponseCode.ERROR); | |
| 680 | - } | |
| 681 | - return rsMap; | |
| 682 | - } | |
| 683 | - | |
| 684 | - @Override | |
| 685 | - public Map<String, Object> removeRealGps(String device) { | |
| 686 | - Map<String, Object> rs = new HashMap<>(); | |
| 687 | - try { | |
| 688 | - | |
| 689 | - gpsRealData.remove(device); | |
| 690 | - GpsCacheData.remove(BasicData.deviceId2NbbmMap.get(device)); | |
| 691 | - rs.put("status", ResponseCode.SUCCESS); | |
| 692 | - } catch (Exception e) { | |
| 693 | - rs.put("status", ResponseCode.ERROR); | |
| 694 | - } | |
| 695 | - return rs; | |
| 696 | - } | |
| 697 | - | |
| 698 | - @Override | |
| 699 | - public Map<String, Object> findRoadSpeed(String lineCode) { | |
| 700 | - Map<String, Object> rs = new HashMap<>(); | |
| 701 | - | |
| 702 | - try { | |
| 703 | - String sql = "select ID, ST_AsText(GROAD_VECTOR) as GROAD_VECTOR,ROAD_CODE,ROAD_NAME,SPEED from bsth_c_road where road_code in(select section_code from bsth_c_sectionroute where line_code=? and destroy=0)"; | |
| 704 | - List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, lineCode); | |
| 705 | - rs.put("status", ResponseCode.SUCCESS); | |
| 706 | - rs.put("roads", list); | |
| 707 | - } catch (DataAccessException e) { | |
| 708 | - logger.error("", e); | |
| 709 | - rs.put("status", ResponseCode.ERROR); | |
| 710 | - } | |
| 711 | - return rs; | |
| 712 | - } | |
| 713 | - | |
| 714 | - /** | |
| 715 | - * gps补全 | |
| 716 | - * | |
| 717 | - * @param schId | |
| 718 | - * @return | |
| 719 | - */ | |
| 720 | - @Override | |
| 721 | - public Map<String, Object> gpsCompletion(long schId, int type) { | |
| 722 | - Map<String, Object> rs = new HashMap<>(); | |
| 723 | - | |
| 724 | - try { | |
| 725 | - ScheduleRealInfo sch = dayOfSchedule.get(schId); | |
| 726 | - if (sch == null) { | |
| 727 | - rs.put("status", ResponseCode.ERROR); | |
| 728 | - rs.put("msg", "找不到对应班次!!!"); | |
| 729 | - return rs; | |
| 730 | - } | |
| 731 | - | |
| 732 | - if (sch.isReissue()) { | |
| 733 | - rs.put("status", ResponseCode.ERROR); | |
| 734 | - rs.put("msg", "你不能重复这个操作"); | |
| 735 | - return rs; | |
| 736 | - } | |
| 737 | - | |
| 738 | - String sql = "select * from bsth_gps_template where line_id='" + sch.getXlBm() + "' and up_down=" + sch.getXlDir(); | |
| 739 | - List<Map<String, Object>> list = jdbcTemplate.queryForList(sql); | |
| 740 | - | |
| 741 | - if (list.size() == 0) { | |
| 742 | - rs.put("status", ResponseCode.ERROR); | |
| 743 | - rs.put("msg", "缺少模板数据,请联系系统管理员!!"); | |
| 744 | - return rs; | |
| 745 | - } | |
| 746 | - //排序 | |
| 747 | - Collections.sort(list, new Comparator<Map<String, Object>>() { | |
| 748 | - @Override | |
| 749 | - public int compare(Map<String, Object> o1, Map<String, Object> o2) { | |
| 750 | - return (int) (Long.parseLong(o1.get("ts").toString()) - Long.parseLong(o2.get("ts").toString())); | |
| 751 | - } | |
| 752 | - }); | |
| 753 | - Map<String, Object> fs = list.get(0); | |
| 754 | - //替换设备号和时间 | |
| 755 | - long diff = ((sch.getDfsjT() - Long.parseLong(fs.get("ts").toString())) - 1000 * 70); | |
| 756 | - | |
| 757 | - String deviceId = BasicData.deviceId2NbbmMap.inverse().get(sch.getClZbh()); | |
| 758 | - int serviceState; | |
| 759 | - for (Map<String, Object> map : list) { | |
| 760 | - map.put("device_id", deviceId); | |
| 761 | - map.put("ts", Long.parseLong(map.get("ts").toString()) + diff); | |
| 762 | - if(type==1){ | |
| 763 | - //走补传协议 | |
| 764 | - serviceState = Integer.parseInt(map.get("service_state").toString()); | |
| 765 | - map.put("service_state", serviceState |= 0x00100000); | |
| 766 | - } | |
| 767 | - } | |
| 768 | - | |
| 769 | - String sqlBefore = "insert into bsth_c_template(", sqlValues = " values("; | |
| 770 | - | |
| 771 | - Set<String> ks = fs.keySet(); | |
| 772 | - for (String k : ks) { | |
| 773 | - sqlBefore += (k + ","); | |
| 774 | - sqlValues += "?,"; | |
| 775 | - } | |
| 776 | - sqlBefore = sqlBefore.substring(0, sqlBefore.length() - 1) + ", create_ts)"; | |
| 777 | - sqlValues = sqlValues.substring(0, sqlValues.length() - 1) + ", " + System.currentTimeMillis() + ")"; | |
| 778 | - sql = sqlBefore + " " + sqlValues; | |
| 779 | - | |
| 780 | - Connection conn = DBUtils_MS.getConnection(); | |
| 781 | - conn.setAutoCommit(false); | |
| 782 | - ps = conn.prepareStatement(sql); | |
| 783 | - int fsize = ks.size(); | |
| 784 | - List<Object> vs; | |
| 785 | - for (Map<String, Object> map : list) { | |
| 786 | - vs = new ArrayList<>(map.values()); | |
| 787 | - for (int i = 0; i < fsize; i++) { | |
| 788 | - ps.setObject(i + 1, vs.get(i)); | |
| 789 | - } | |
| 790 | - ps.addBatch(); | |
| 791 | - } | |
| 792 | - ps.executeBatch(); | |
| 793 | - conn.commit(); | |
| 794 | - | |
| 795 | - rs.put("status", ResponseCode.SUCCESS); | |
| 796 | - | |
| 797 | - //标记班次 | |
| 798 | - sch.setReissue(true); | |
| 799 | - scheduleRealInfoRepository.save(sch); | |
| 800 | - | |
| 801 | - rs.put("status", ResponseCode.SUCCESS); | |
| 802 | - } catch (Exception e) { | |
| 803 | - logger.error("", e); | |
| 804 | - rs.put("status", ResponseCode.ERROR); | |
| 805 | - } | |
| 806 | - return rs; | |
| 807 | - } | |
| 808 | - | |
| 809 | - @Override | |
| 810 | - public Map<String, Object> history_v2(String nbbm, long st, long et) { | |
| 811 | - Map<String, Object> rs = new HashMap<>(); | |
| 812 | - | |
| 813 | - try { | |
| 814 | - //获取历史gps 数据 | |
| 815 | - List<HistoryGps_DTO> list = HistoryGps_DTO.craete((List<Map<String, Object>>) history(new String[]{nbbm}, st, et).get("list")); | |
| 816 | - if (list != null && list.size() > 0) { | |
| 817 | - //获取路段信息 | |
| 818 | - String sql = "select ID, ST_AsText(GROAD_VECTOR) as GROAD_VECTOR,ROAD_CODE,ROAD_NAME,SPEED from bsth_c_road where road_code in(select section_code from bsth_c_sectionroute where line_code=? and destroy=0)"; | |
| 819 | - List<Road_DTO> roads = Road_DTO.craete(jdbcTemplate.queryForList(sql, list.get(0).getLineId())); | |
| 820 | - | |
| 821 | - //为GPS数据关联路段信息 | |
| 822 | - for (HistoryGps_DTO gps : list) { | |
| 823 | - matchRoadToGps(gps, roads); | |
| 824 | - } | |
| 825 | - } | |
| 826 | - | |
| 827 | - //超速数据 | |
| 828 | - List<GpsSpeed_DTO> speedList = speeds(nbbm, st, et); | |
| 829 | - //越界数据 | |
| 830 | - List<GpsOutbound_DTO> outboundList = outbounds(nbbm, st, et); | |
| 831 | - //计算里程 | |
| 832 | - List<HistoryGps_DTO> effList = new ArrayList<>(); | |
| 833 | - for(HistoryGps_DTO gps : list){ | |
| 834 | - if(gps.getLat() != 0 && gps.getLon() != 0) | |
| 835 | - effList.add(gps); | |
| 836 | - } | |
| 837 | - double sum = 0, dist; | |
| 838 | - for (int i = 0; i < effList.size() - 1; i++) { | |
| 839 | - dist = GeoUtils.getDistance(effList.get(i).getPoint(), effList.get(i + 1).getPoint()); | |
| 840 | - //点位相同时,dist会NaN | |
| 841 | - if(String.valueOf(dist).matches("^[0.0-9.0]+$")) | |
| 842 | - sum += dist; | |
| 843 | - } | |
| 844 | - | |
| 845 | - rs.put("status", ResponseCode.SUCCESS); | |
| 846 | - rs.put("list", removeDuplicate(effList)); | |
| 847 | - rs.put("speedList", speedList); | |
| 848 | - rs.put("outboundList", outboundList); | |
| 849 | - rs.put("sumMileage", new DecimalFormat(".##").format(sum / 1000)); | |
| 850 | - } catch (Exception e) { | |
| 851 | - logger.error("", e); | |
| 852 | - rs.put("status", ResponseCode.ERROR); | |
| 853 | - } | |
| 854 | - return rs; | |
| 855 | - } | |
| 856 | - | |
| 857 | - | |
| 858 | - @Override | |
| 859 | - public Map<String, Object> history_v3(String nbbm, long st, long et) { | |
| 860 | - Map<String, Object> rs = new HashMap<>(); | |
| 861 | - | |
| 862 | - try { | |
| 863 | - //获取历史gps 数据 | |
| 864 | - Map<String, Object> gpsMap = history(new String[]{nbbm}, st, et); | |
| 865 | - List<HistoryGps_DTOV3> list = HistoryGps_DTOV3.craete((List<Map<String, Object>>) gpsMap.get("list")); | |
| 866 | - if (list != null && list.size() > 0) { | |
| 867 | - //关联路段名称 | |
| 868 | - Map<String, String> sectionCode2Name = GeoCacheData.sectionCode2NameMap(); | |
| 869 | - for(HistoryGps_DTOV3 gps : list){ | |
| 870 | - if(StringUtils.isNotEmpty(gps.getSection_code())) | |
| 871 | - gps.setSection_name(sectionCode2Name.get(gps.getSection_code())); | |
| 872 | - else{ | |
| 873 | - gps.setSection_code("-00404"); | |
| 874 | - gps.setSection_name("未知路段"); | |
| 875 | - } | |
| 876 | - } | |
| 877 | - } | |
| 878 | - | |
| 879 | - //超速数据 | |
| 880 | - List<GpsSpeed_DTO> speedList = speeds(nbbm, st, et); | |
| 881 | - | |
| 882 | - //越界数据 | |
| 883 | - List<GpsOutbound_DTO> outboundList = outbounds(nbbm, st, et); | |
| 884 | - | |
| 885 | - //计算里程 | |
| 886 | - List<HistoryGps_DTOV3> effList = new ArrayList<>(); | |
| 887 | - for(HistoryGps_DTOV3 gps : list){ | |
| 888 | - if(gps.getLat() != 0 && gps.getLon() != 0) | |
| 889 | - effList.add(gps); | |
| 890 | - } | |
| 891 | - double sum = 0, dist; | |
| 892 | - for (int i = 0; i < effList.size() - 1; i++) { | |
| 893 | - dist = GeoUtils.getDistance(effList.get(i).getPoint(), effList.get(i + 1).getPoint()); | |
| 894 | - //点位相同时,dist会NaN | |
| 895 | - if(String.valueOf(dist).matches("^[0.0-9.0]+$")){ | |
| 896 | - if(dist > 0.8) | |
| 897 | - sum += dist; | |
| 898 | - } | |
| 899 | - } | |
| 900 | - | |
| 901 | - rs.put("status", ResponseCode.SUCCESS); | |
| 902 | - rs.put("list", removeDuplicateV3(effList)); | |
| 903 | - rs.put("speedList", speedList); | |
| 904 | - rs.put("outboundList", outboundList); | |
| 905 | - rs.put("sumMileage", new DecimalFormat(".##").format(sum / 1000)); | |
| 906 | - rs.put("dcs", gpsMap.get("dcs")); | |
| 907 | - rs.put("lineVerson",gpsMap.get("lineVerson")); | |
| 908 | - rs.put("gpsInvalid",gpsMap.get("gpsNotValid")); | |
| 909 | - rs.put("gpslineSwitch",gpsMap.get("lineSwitch")); | |
| 910 | - rs.put("gpslonlatex",gpsMap.get("lonlatZero")); | |
| 911 | - } catch (Exception e) { | |
| 912 | - logger.error("", e); | |
| 913 | - rs.put("status", ResponseCode.ERROR); | |
| 914 | - rs.put("msg", e.getMessage()); | |
| 915 | - } | |
| 916 | - return rs; | |
| 917 | - } | |
| 918 | - | |
| 919 | - @Override | |
| 920 | - public void trailExcel(String nbbm, long st, long et, HttpServletResponse resp) { | |
| 921 | - //获取历史gps 数据 | |
| 922 | - List<HistoryGps_DTOV3> list = HistoryGps_DTOV3.craete((List<Map<String, Object>>) history(new String[]{nbbm}, st, et).get("list")); | |
| 923 | - if (list != null && list.size() > 0) { | |
| 924 | - //关联路段名称 | |
| 925 | - Map<String, String> sectionCode2Name = GeoCacheData.sectionCode2NameMap(); | |
| 926 | - for(HistoryGps_DTOV3 gps : list){ | |
| 927 | - if(StringUtils.isNotEmpty(gps.getSection_code())) | |
| 928 | - gps.setSection_name(sectionCode2Name.get(gps.getSection_code())); | |
| 929 | - else{ | |
| 930 | - gps.setSection_code("-00404"); | |
| 931 | - gps.setSection_name("未知路段"); | |
| 932 | - } | |
| 933 | - } | |
| 934 | - } | |
| 935 | - | |
| 936 | - //创建excel工作簿 | |
| 937 | - Workbook wb = new HSSFWorkbook(); | |
| 938 | - Sheet sheet = wb.createSheet("行车轨迹"); | |
| 939 | - //表头 | |
| 940 | - Row row = sheet.createRow(0); | |
| 941 | - row.setHeight((short) (1.5 * 256)); | |
| 942 | - row.createCell(0).setCellValue("序号"); | |
| 943 | - row.createCell(1).setCellValue("车辆"); | |
| 944 | - row.createCell(2).setCellValue("牌照号"); | |
| 945 | - row.createCell(3).setCellValue("所在道路"); | |
| 946 | - row.createCell(4).setCellValue("经度"); | |
| 947 | - row.createCell(5).setCellValue("纬度"); | |
| 948 | - row.createCell(6).setCellValue("时间"); | |
| 949 | - row.createCell(7).setCellValue("速度"); | |
| 950 | - //数据 | |
| 951 | - DateTimeFormatter fmtHHmmss = DateTimeFormat.forPattern("HH:mm.ss"), | |
| 952 | - fmt = DateTimeFormat.forPattern("yyyyMMddHHmm"); | |
| 953 | - HistoryGps_DTOV3 gps; | |
| 954 | - for(int i = 0; i < list.size(); i ++){ | |
| 955 | - gps = list.get(i); | |
| 956 | - row = sheet.createRow(i + 1); | |
| 957 | - row.createCell(0).setCellValue(i + 1); | |
| 958 | - row.createCell(1).setCellValue(nbbm); | |
| 959 | - row.createCell(2).setCellValue(BasicData.nbbmCompanyPlateMap.get(nbbm)); | |
| 960 | - row.createCell(3).setCellValue(gps.getSection_name()); | |
| 961 | - row.createCell(4).setCellValue(gps.getLon()); | |
| 962 | - row.createCell(5).setCellValue(gps.getLat()); | |
| 963 | - row.createCell(6).setCellValue(fmtHHmmss.print(gps.getTimestamp())); | |
| 964 | - row.createCell(7).setCellValue(gps.getSpeed()); | |
| 965 | - } | |
| 966 | - | |
| 967 | - st = st * 1000; | |
| 968 | - et = et * 1000; | |
| 969 | - String filename = nbbm + "轨迹数据" + fmt.print(st) + "至" + fmt.print(et) + ".xls"; | |
| 970 | - try { | |
| 971 | - resp.setContentType("application/x-msdownload"); | |
| 972 | - resp.addHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8")); | |
| 973 | - | |
| 974 | - OutputStream out=resp.getOutputStream(); | |
| 975 | - wb.write(out); | |
| 976 | - out.flush(); | |
| 977 | - out.close(); | |
| 978 | - } catch (UnsupportedEncodingException e) { | |
| 979 | - logger.error("", e); | |
| 980 | - } catch (IOException e) { | |
| 981 | - logger.error("", e); | |
| 982 | - } | |
| 983 | - } | |
| 984 | - | |
| 985 | - @Override | |
| 986 | - public void abnormalExcel(String nbbm, long st, long et, HttpServletResponse resp) { | |
| 987 | - //超速数据 | |
| 988 | - List<GpsSpeed_DTO> speedList = speeds(nbbm, st, et); | |
| 989 | - //越界数据 | |
| 990 | - List<GpsOutbound_DTO> outboundList = outbounds(nbbm, st, et); | |
| 991 | - | |
| 992 | - //创建excel工作簿 | |
| 993 | - Workbook wb = new HSSFWorkbook(); | |
| 994 | - | |
| 995 | - DateTimeFormatter fmtHHmmss = DateTimeFormat.forPattern("HH:mm.ss"), | |
| 996 | - fmt = DateTimeFormat.forPattern("yyyyMMddHHmm"); | |
| 997 | - if(speedList.size() > 0){ | |
| 998 | - Sheet sheet = wb.createSheet("超速"); | |
| 999 | - //表头 | |
| 1000 | - Row row = sheet.createRow(0); | |
| 1001 | - row.setHeight((short) (1.5 * 256)); | |
| 1002 | - row.createCell(0).setCellValue("异常信息"); | |
| 1003 | - row.createCell(1).setCellValue("最大速度"); | |
| 1004 | - row.createCell(2).setCellValue("开始时间"); | |
| 1005 | - row.createCell(3).setCellValue("结束时间"); | |
| 1006 | - row.createCell(4).setCellValue("持续(秒)"); | |
| 1007 | - row.createCell(5).setCellValue("所在路段"); | |
| 1008 | - | |
| 1009 | - GpsSpeed_DTO speed; | |
| 1010 | - for(int i = 0; i < speedList.size(); i++){ | |
| 1011 | - speed = speedList.get(i); | |
| 1012 | - row = sheet.createRow(i + 1); | |
| 1013 | - row.createCell(0).setCellValue("超速"); | |
| 1014 | - row.createCell(1).setCellValue(speed.getSpeed()); | |
| 1015 | - row.createCell(2).setCellValue(fmtHHmmss.print(speed.getSt())); | |
| 1016 | - row.createCell(3).setCellValue(fmtHHmmss.print(speed.getEt())); | |
| 1017 | - if(speed.getEt() != 0) | |
| 1018 | - row.createCell(4).setCellValue((speed.getEt() - speed.getSt()) / 1000); | |
| 1019 | - row.createCell(5).setCellValue(""); | |
| 1020 | - } | |
| 1021 | - } | |
| 1022 | - | |
| 1023 | - if(outboundList.size() > 0){ | |
| 1024 | - Sheet sheet = wb.createSheet("越界"); | |
| 1025 | - //表头 | |
| 1026 | - Row row = sheet.createRow(0); | |
| 1027 | - row.setHeight((short) (1.5 * 256)); | |
| 1028 | - row.createCell(0).setCellValue("异常信息"); | |
| 1029 | - row.createCell(1).setCellValue("开始时间"); | |
| 1030 | - row.createCell(2).setCellValue("结束时间"); | |
| 1031 | - row.createCell(3).setCellValue("持续(秒)"); | |
| 1032 | - row.createCell(4).setCellValue("所在路段"); | |
| 1033 | - row.createCell(5).setCellValue("路径"); | |
| 1034 | - | |
| 1035 | - GpsOutbound_DTO outbound; | |
| 1036 | - //设置路径单元格 水平对齐 填充 | |
| 1037 | - CellStyle cs = wb.createCellStyle(); | |
| 1038 | - cs.setAlignment(HSSFCellStyle.ALIGN_FILL); | |
| 1039 | - for(int i = 0; i < outboundList.size(); i++){ | |
| 1040 | - outbound = outboundList.get(i); | |
| 1041 | - row = sheet.createRow(i + 1); | |
| 1042 | - row.createCell(0).setCellValue("超速"); | |
| 1043 | - row.createCell(1).setCellValue(fmtHHmmss.print(outbound.getSt())); | |
| 1044 | - row.createCell(2).setCellValue(fmtHHmmss.print(outbound.getEt())); | |
| 1045 | - if(outbound.getEt() != 0) | |
| 1046 | - row.createCell(3).setCellValue((outbound.getEt() - outbound.getSt()) / 1000); | |
| 1047 | - row.createCell(4).setCellValue(""); | |
| 1048 | - row.createCell(5).setCellValue(outbound.getLocations()); | |
| 1049 | - | |
| 1050 | - row.getCell(5).setCellStyle(cs); | |
| 1051 | - } | |
| 1052 | - } | |
| 1053 | - | |
| 1054 | - st = st * 1000; | |
| 1055 | - et = et * 1000; | |
| 1056 | - String filename = nbbm + "异常信息" + fmt.print(st) + "至" + fmt.print(et) + ".xls"; | |
| 1057 | - try { | |
| 1058 | - resp.setContentType("application/x-msdownload"); | |
| 1059 | - resp.addHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8")); | |
| 1060 | - | |
| 1061 | - OutputStream out=resp.getOutputStream(); | |
| 1062 | - wb.write(out); | |
| 1063 | - out.flush(); | |
| 1064 | - out.close(); | |
| 1065 | - } catch (UnsupportedEncodingException e) { | |
| 1066 | - logger.error("", e); | |
| 1067 | - } catch (IOException e) { | |
| 1068 | - logger.error("", e); | |
| 1069 | - } | |
| 1070 | - } | |
| 1071 | - | |
| 1072 | - @Override | |
| 1073 | - public void arrivalExcel(String nbbm, long st, long et, HttpServletResponse resp) { | |
| 1074 | - | |
| 1075 | - } | |
| 1076 | - | |
| 1077 | - @Override | |
| 1078 | - public List<GpsSpeed_DTO> speeds(String nbbm, long st, long et) { | |
| 1079 | - st = st * 1000; | |
| 1080 | - et = et * 1000; | |
| 1081 | - //按周分区 | |
| 1082 | - Calendar sCal = Calendar.getInstance(); | |
| 1083 | - sCal.setTime(new Date(st)); | |
| 1084 | - int sWeekYear = sCal.get(Calendar.WEEK_OF_YEAR); | |
| 1085 | - Calendar eCal = Calendar.getInstance(); | |
| 1086 | - eCal.setTime(new Date(et)); | |
| 1087 | - int eWeekYear = eCal.get(Calendar.WEEK_OF_YEAR); | |
| 1088 | - | |
| 1089 | - //按年分表 | |
| 1090 | - String tableName = "bsth_c_speeding_" + fmtyyyy.print(st); | |
| 1091 | - | |
| 1092 | - List<DeviceChange> dcs = findDeviceChangeLogs(nbbm, et, st); | |
| 1093 | - StringBuilder sql = new StringBuilder(""); | |
| 1094 | - long t1,t2; | |
| 1095 | - DeviceChange dc; | |
| 1096 | - for(int i = 0,len=dcs.size(); i < len; i++){ | |
| 1097 | - t1 = st; | |
| 1098 | - t2 = et; | |
| 1099 | - dc = dcs.get(i); | |
| 1100 | - if(dc.getSt() > st) | |
| 1101 | - t1 = dc.getSt(); | |
| 1102 | - if(dc.getEt() < et && dc.getEt()!=0) | |
| 1103 | - t2 = dc.getEt(); | |
| 1104 | - | |
| 1105 | - sql.append(" select vehicle, line, up_down, lon, lat, speed,timestamp from "+tableName+" where " + | |
| 1106 | - " weeks_year in ("+sWeekYear+", "+eWeekYear+") and vehicle='"+dc.getDevice()+"' and timestamp>="+t1+" and timestamp<= " + t2); | |
| 1107 | - | |
| 1108 | - if(i == len - 1) | |
| 1109 | - sql.append(" ORDER BY vehicle,timestamp"); | |
| 1110 | - else | |
| 1111 | - sql.append(" UNION "); | |
| 1112 | - } | |
| 1113 | - | |
| 1114 | - logger.info("speed sql : " + sql.toString()); | |
| 1115 | - return GpsSpeed_DTO.create(new JdbcTemplate(DBUtils_MS.getDataSource()).queryForList(sql.toString())); | |
| 1116 | - } | |
| 1117 | - | |
| 1118 | - @Override | |
| 1119 | - public List<GpsOutbound_DTO> outbounds(String nbbm, long st, long et) { | |
| 1120 | - st = st * 1000; | |
| 1121 | - et = et * 1000; | |
| 1122 | - //按周分区 | |
| 1123 | - Calendar sCal = Calendar.getInstance(); | |
| 1124 | - sCal.setTime(new Date(st)); | |
| 1125 | - int sWeekYear = sCal.get(Calendar.WEEK_OF_YEAR); | |
| 1126 | - Calendar eCal = Calendar.getInstance(); | |
| 1127 | - eCal.setTime(new Date(et)); | |
| 1128 | - int eWeekYear = eCal.get(Calendar.WEEK_OF_YEAR); | |
| 1129 | - | |
| 1130 | - //按年分表 | |
| 1131 | - String tableName = "bsth_c_outbound_" + fmtyyyy.print(st); | |
| 1132 | - | |
| 1133 | - List<DeviceChange> dcs = findDeviceChangeLogs(nbbm, et, st); | |
| 1134 | - StringBuilder sql = new StringBuilder(""); | |
| 1135 | - long t1,t2; | |
| 1136 | - DeviceChange dc; | |
| 1137 | - for(int i = 0,len=dcs.size(); i < len; i++){ | |
| 1138 | - t1 = st; | |
| 1139 | - t2 = et; | |
| 1140 | - dc = dcs.get(i); | |
| 1141 | - if(dc.getSt() > st) | |
| 1142 | - t1 = dc.getSt(); | |
| 1143 | - if(dc.getEt() < et && dc.getEt()!=0) | |
| 1144 | - t2 = dc.getEt(); | |
| 1145 | - | |
| 1146 | - sql.append("select vehicle,line,up_down,lon,lat,timestamp from "+tableName+" where " + | |
| 1147 | - " weeks_year in ("+sWeekYear+", "+eWeekYear+") and vehicle='"+dc.getDevice()+"' and timestamp>="+t1+" and timestamp<=" + t2); | |
| 1148 | - | |
| 1149 | - if(i == len - 1) | |
| 1150 | - sql.append(" ORDER BY vehicle,timestamp"); | |
| 1151 | - else | |
| 1152 | - sql.append(" UNION "); | |
| 1153 | - } | |
| 1154 | - | |
| 1155 | - logger.info("outbounds sql : " + sql.toString()); | |
| 1156 | - return GpsOutbound_DTO.create(new JdbcTemplate(DBUtils_MS.getDataSource()).queryForList(sql.toString())); | |
| 1157 | - } | |
| 1158 | - | |
| 1159 | - @Override | |
| 1160 | - public Map<String, Object> safeDrivList(Map<String, Object> map, int page, int size, String order, String direction) { | |
| 1161 | - Map<String, Object> rsMap = new HashMap<>(); | |
| 1162 | - try { | |
| 1163 | - //全量 | |
| 1164 | - List<SafeDriv> list = new ArrayList<>(SafeDrivCenter.findAll()); | |
| 1165 | - //过滤后的 | |
| 1166 | - List<SafeDriv> rs = new ArrayList<>(); | |
| 1167 | - Field[] fields = SafeDriv.class.getDeclaredFields(); | |
| 1168 | - //参与过滤的字段 | |
| 1169 | - List<Field> fs = new ArrayList<>(); | |
| 1170 | - for (Field f : fields) { | |
| 1171 | - f.setAccessible(true); | |
| 1172 | - if (map.containsKey(f.getName())) | |
| 1173 | - fs.add(f); | |
| 1174 | - } | |
| 1175 | - //过滤数据 | |
| 1176 | - for (SafeDriv sd : list) { | |
| 1177 | - if (isSpecialLines(sd, map) && fieldEqualstow(fs, sd, map)) | |
| 1178 | - rs.add(sd); | |
| 1179 | - } | |
| 1180 | - | |
| 1181 | - //时间戳排序 | |
| 1182 | - Collections.sort(rs, new Comparator<SafeDriv>() { | |
| 1183 | - @Override | |
| 1184 | - public int compare(SafeDriv o1, SafeDriv o2) { | |
| 1185 | - return o2.getTs().intValue() - o1.getTs().intValue(); | |
| 1186 | - } | |
| 1187 | - }); | |
| 1188 | - | |
| 1189 | - //分页 | |
| 1190 | - int count = rs.size(), s = page * size, e = s + size; | |
| 1191 | - if (e > count) | |
| 1192 | - e = count; | |
| 1193 | - | |
| 1194 | - rsMap.put("list", rs.subList(s, e)); | |
| 1195 | - rsMap.put("totalPages", count % size == 0 ? count / size - 1 : count / size); | |
| 1196 | - rsMap.put("page", page); | |
| 1197 | - rsMap.put("status", ResponseCode.SUCCESS); | |
| 1198 | - } catch (Exception e) { | |
| 1199 | - logger.error("", e); | |
| 1200 | - rsMap.put("status", ResponseCode.ERROR); | |
| 1201 | - } | |
| 1202 | - return rsMap; | |
| 1203 | - } | |
| 1204 | - | |
| 1205 | - private void matchRoadToGps(HistoryGps_DTO gps, List<Road_DTO> roads) { | |
| 1206 | - double min = -1, distance; | |
| 1207 | - Road_DTO nearRoad = null; | |
| 1208 | - for (Road_DTO road : roads) { | |
| 1209 | - distance = GeoUtils.getDistanceFromLine(road.getLineStr(), gps.getPoint()); | |
| 1210 | - | |
| 1211 | - if (min > distance || min == -1) { | |
| 1212 | - min = distance; | |
| 1213 | - nearRoad = road; | |
| 1214 | - } | |
| 1215 | - } | |
| 1216 | - | |
| 1217 | - gps.setRoad(nearRoad); | |
| 1218 | - gps.setRoadMinDistance(min); | |
| 1219 | - } | |
| 1220 | - | |
| 1221 | - | |
| 1222 | - private void matchRoadToGps(HistoryGps_DTOV3 gps, List<Road_DTO> roads) { | |
| 1223 | - double min = -1, distance; | |
| 1224 | - Road_DTO nearRoad = null; | |
| 1225 | - for (Road_DTO road : roads) { | |
| 1226 | - distance = GeoUtils.getDistanceFromLine(road.getLineStr(), gps.getPoint()); | |
| 1227 | - | |
| 1228 | - if (min > distance || min == -1) { | |
| 1229 | - min = distance; | |
| 1230 | - nearRoad = road; | |
| 1231 | - } | |
| 1232 | - } | |
| 1233 | - | |
| 1234 | - if(min < 200){ | |
| 1235 | - gps.setSection_code(nearRoad.getROAD_CODE()); | |
| 1236 | - gps.setSection_name(nearRoad.getROAD_NAME()); | |
| 1237 | - } | |
| 1238 | - else { | |
| 1239 | - gps.setSection_code("-00404"); | |
| 1240 | - gps.setSection_name("未知路段"); | |
| 1241 | - } | |
| 1242 | - //gps.setRoad(nearRoad); | |
| 1243 | - //gps.setRoadMinDistance(min); | |
| 1244 | - } | |
| 1245 | - | |
| 1246 | - /** | |
| 1247 | - * 去重复 | |
| 1248 | - * | |
| 1249 | - * @param list | |
| 1250 | - * @return | |
| 1251 | - */ | |
| 1252 | - private Set<HistoryGps_DTO> removeDuplicate(List<HistoryGps_DTO> list) { | |
| 1253 | - Set<HistoryGps_DTO> set = new HashSet<>(); | |
| 1254 | - for (HistoryGps_DTO gps : list) { | |
| 1255 | - set.add(gps); | |
| 1256 | - } | |
| 1257 | - return set; | |
| 1258 | - } | |
| 1259 | - | |
| 1260 | - /** | |
| 1261 | - * 去重复 | |
| 1262 | - * | |
| 1263 | - * @param list | |
| 1264 | - * @return | |
| 1265 | - */ | |
| 1266 | - private Set<HistoryGps_DTOV3> removeDuplicateV3(List<HistoryGps_DTOV3> list) { | |
| 1267 | - Set<HistoryGps_DTOV3> set = new HashSet<>(); | |
| 1268 | - for (HistoryGps_DTOV3 gps : list) { | |
| 1269 | - set.add(gps); | |
| 1270 | - } | |
| 1271 | - return set; | |
| 1272 | - } | |
| 1273 | - | |
| 1274 | - | |
| 1275 | - private void sortGpsList(final Field f, List<GpsEntity> rs) { | |
| 1276 | - Collections.sort(rs, new Comparator<GpsEntity>() { | |
| 1277 | - | |
| 1278 | - @Override | |
| 1279 | - public int compare(GpsEntity o1, GpsEntity o2) { | |
| 1280 | - try { | |
| 1281 | - if (f.get(o1) == f.get(o2)) | |
| 1282 | - return 0; | |
| 1283 | - | |
| 1284 | - if (null == f.get(o1)) | |
| 1285 | - return 1; | |
| 1286 | - | |
| 1287 | - if (null == f.get(o2)) | |
| 1288 | - return -1; | |
| 1289 | - | |
| 1290 | - return f.get(o1).toString().compareTo(f.get(o2).toString()); | |
| 1291 | - } catch (Exception e) { | |
| 1292 | - logger.error("", e); | |
| 1293 | - return -1; | |
| 1294 | - } | |
| 1295 | - } | |
| 1296 | - }); | |
| 1297 | - } | |
| 1298 | - | |
| 1299 | - /** | |
| 1300 | - * | |
| 1301 | - * @param sd | |
| 1302 | - * @param map | |
| 1303 | - * @return | |
| 1304 | - */ | |
| 1305 | - public boolean isSpecialLines(SafeDriv sd, Map<String, Object> map) { | |
| 1306 | - String lines = (String)map.get("lines"); | |
| 1307 | - if (lines == null) lines = ""; | |
| 1308 | - | |
| 1309 | - if (Arrays.asList(lines.split(",")).contains(sd.getXlbm())) return true; | |
| 1310 | - return false; | |
| 1311 | - } | |
| 1312 | - | |
| 1313 | - public boolean fieldEquals(List<Field> fs, Object obj, Map<String, Object> map) { | |
| 1314 | - try { | |
| 1315 | - String fv, v; | |
| 1316 | - for (Field f : fs) { | |
| 1317 | - if (StringUtils.isEmpty(map.get(f.getName()).toString())) | |
| 1318 | - continue; | |
| 1319 | - | |
| 1320 | - if(f.get(obj) == null) | |
| 1321 | - return false; | |
| 1322 | - | |
| 1323 | - fv = f.get(obj).toString(); | |
| 1324 | - v = map.get(f.getName()).toString(); | |
| 1325 | - | |
| 1326 | - if(!fv.startsWith(v)/* && !fv.endsWith(v)*/) | |
| 1327 | - return false; | |
| 1328 | - } | |
| 1329 | - } catch (Exception e) { | |
| 1330 | - logger.error("", e); | |
| 1331 | - return false; | |
| 1332 | - } | |
| 1333 | - return true; | |
| 1334 | - } | |
| 1335 | - | |
| 1336 | - public boolean fieldEqualstow(List<Field> fs, Object obj, Map<String, Object> map) { | |
| 1337 | - try { | |
| 1338 | - String fv, v; | |
| 1339 | - for (Field f : fs) { | |
| 1340 | - if (StringUtils.isEmpty(map.get(f.getName()).toString())) | |
| 1341 | - continue; | |
| 1342 | - | |
| 1343 | - if(f.get(obj) == null) | |
| 1344 | - return false; | |
| 1345 | - | |
| 1346 | - fv = f.get(obj).toString(); | |
| 1347 | - v = map.get(f.getName()).toString(); | |
| 1348 | - SafeDriv sd = (SafeDriv) obj; | |
| 1349 | - if(v.equals(sd.getJctype())) | |
| 1350 | - return true; | |
| 1351 | - else if(!fv.startsWith(v)/* && !fv.endsWith(v)*/) | |
| 1352 | - return false; | |
| 1353 | - } | |
| 1354 | - } catch (Exception e) { | |
| 1355 | - logger.error("", e); | |
| 1356 | - return false; | |
| 1357 | - } | |
| 1358 | - return true; | |
| 1359 | - } | |
| 1360 | - | |
| 1361 | - | |
| 1362 | - @Override | |
| 1363 | - public List<GpsSpeed> findPosition(String deviceid, String startdate, | |
| 1364 | - String enddate) throws ParseException{ | |
| 1365 | - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 1366 | - Calendar c = Calendar.getInstance(); | |
| 1367 | - Date date = sdf.parse(startdate); | |
| 1368 | - c.setTime(date); | |
| 1369 | - int daysYear = c.get(Calendar.DAY_OF_YEAR);//获取当前是今年的第几天。 | |
| 1370 | - | |
| 1371 | - long startTime = sdf.parse(startdate).getTime(); | |
| 1372 | - long endTime = sdf.parse(enddate).getTime(); | |
| 1373 | - | |
| 1374 | - String sql = "select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE ,speed_gps from bsth_c_gps_info where days_year=? and device_id=? and ts >= ? and ts <= ?" + | |
| 1375 | - " ORDER BY TS "; | |
| 1376 | - Connection conn = null; | |
| 1377 | - PreparedStatement ps = null; | |
| 1378 | - ResultSet rs = null; | |
| 1379 | - List<GpsSpeed> listResult = new ArrayList<GpsSpeed>(); | |
| 1380 | - GpsSpeed gpsSpeed = null; | |
| 1381 | - try { | |
| 1382 | - conn = DBUtils_MS.getConnection(); | |
| 1383 | - ps = conn.prepareStatement(sql); | |
| 1384 | - ps.setInt(1, daysYear); | |
| 1385 | - ps.setString(2, deviceid); | |
| 1386 | - ps.setLong(3,startTime); | |
| 1387 | - ps.setLong(4,endTime); | |
| 1388 | - rs = ps.executeQuery(); | |
| 1389 | - Float lon, lat; | |
| 1390 | - Location location; | |
| 1391 | - while (rs.next()) { | |
| 1392 | - gpsSpeed = new GpsSpeed(); | |
| 1393 | - // to 百度坐标 | |
| 1394 | - lon = rs.getFloat("LON"); | |
| 1395 | - lat = rs.getFloat("LAT"); | |
| 1396 | - location = TransGPS.LocationMake(lon, lat); | |
| 1397 | - location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location)); | |
| 1398 | - gpsSpeed.setVehicle(rs.getString("device_id")); | |
| 1399 | - gpsSpeed.setLon((float)location.getLng()); | |
| 1400 | - gpsSpeed.setLat((float)location.getLat()); | |
| 1401 | - gpsSpeed.setSpeed(rs.getFloat("speed_gps")); | |
| 1402 | - gpsSpeed.setTimestamp(rs.getLong("TS")); | |
| 1403 | - // 上下行 | |
| 1404 | - listResult.add(gpsSpeed); | |
| 1405 | - } | |
| 1406 | - } catch (Exception e) { | |
| 1407 | - e.printStackTrace(); | |
| 1408 | - } finally { | |
| 1409 | - DBUtils_MS.close(rs, ps, conn); | |
| 1410 | - } | |
| 1411 | - return listResult; | |
| 1412 | - | |
| 1413 | - } | |
| 1414 | - | |
| 1415 | - @Override | |
| 1416 | - public Map<String, Object> Pagequery(Map<String, Object> map) { | |
| 1417 | - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 1418 | - Integer totalDays = 0;//数据跨越天数 | |
| 1419 | - try { | |
| 1420 | - totalDays = (int) ((sdf.parse(map.get("endDate").toString()+" 23:59:59").getTime()-sdf.parse(map.get("startDate").toString()+" 00:00:00").getTime()+1)/(3600*24*1000))+1; | |
| 1421 | - } catch (ParseException e) { | |
| 1422 | - e.printStackTrace(); | |
| 1423 | - }//总页数 | |
| 1424 | - map.put("totalDays",totalDays); | |
| 1425 | - List<GpsSpeed> list=findAll(map); | |
| 1426 | - List<GpsSpeed> listResult = new ArrayList<GpsSpeed>(); | |
| 1427 | - int curPage = 0;//页码 | |
| 1428 | - int pageData = 0;//每页的记录条数 | |
| 1429 | - if(list.size()>1){ | |
| 1430 | - GpsSpeed GpsSpeedNow;//下标为i的车辆行驶记录 | |
| 1431 | - GpsSpeed GpsSpeedLast;//下标为i-1的车辆行驶记录 | |
| 1432 | - GpsSpeed spped = null;//整合后的车辆行驶记录 | |
| 1433 | - String strNow; | |
| 1434 | - String strLast; | |
| 1435 | - boolean Flag = false;//判断是否有连续超速记录,默认没有 | |
| 1436 | - for(int i = 1;i<list.size();i++){ | |
| 1437 | - GpsSpeedNow = list.get(i); | |
| 1438 | - GpsSpeedLast = list.get(i-1); | |
| 1439 | - strNow = GpsSpeedNow.getVehicle()+GpsSpeedNow.getLine()+GpsSpeedNow.getUp_down(); | |
| 1440 | - strLast = GpsSpeedLast.getVehicle()+GpsSpeedLast.getLine()+GpsSpeedLast.getUp_down(); | |
| 1441 | - if(GpsSpeedNow.getSpeed()>60 && GpsSpeedLast.getSpeed()>60 && strNow.equals(strLast)){//如果两条连续的记录都是超速且属于同一辆车。 | |
| 1442 | - if(Flag==false){// | |
| 1443 | - spped = new GpsSpeed(); | |
| 1444 | - spped.setLine(GpsSpeedLast.getLine());//设置连续超速记录线路 | |
| 1445 | - spped.setLineName(GpsSpeedLast.getLineName());//设置连续超速记录线路名称 | |
| 1446 | - spped.setVehicle(GpsSpeedLast.getVehicle());//设置连续超速记录的车辆编号 | |
| 1447 | - spped.setUp_down(GpsSpeedLast.getUp_down());//设置上下行 | |
| 1448 | - spped.setLon(GpsSpeedLast.getLon());//设置开始时经度 | |
| 1449 | - spped.setLat(GpsSpeedLast.getLat());//设置开始时纬度 | |
| 1450 | - spped.setTimestamp(GpsSpeedLast.getTimestamp());//设置连续超速记录的开始时间 | |
| 1451 | - spped.setTimestampDate(GpsSpeedLast.getTimestampDate());//设置连续超速记录的开始时间戳 | |
| 1452 | - } | |
| 1453 | - spped.setEndtimestamp(GpsSpeedNow.getTimestamp());//设置结束时间戳 | |
| 1454 | - spped.setEndtimestampDate(sdf.format(new Date(GpsSpeedNow.getTimestamp())));//设置结束时间 | |
| 1455 | - spped.setEndlon(GpsSpeedNow.getLon());//设置结束时的经度 | |
| 1456 | - spped.setEndlat(GpsSpeedNow.getLat());//设置结束时的纬度 | |
| 1457 | - Flag = true; | |
| 1458 | - }else{ | |
| 1459 | - if(Flag){//如果上一条记录超速。 | |
| 1460 | - listResult.add(spped); | |
| 1461 | - Flag = false; | |
| 1462 | - } | |
| 1463 | - } | |
| 1464 | - } | |
| 1465 | - if(listResult.size()>0){ | |
| 1466 | - Iterator<GpsSpeed> speedIt = listResult.iterator(); | |
| 1467 | - while(speedIt.hasNext()){ | |
| 1468 | - GpsSpeed GpsSpeed = speedIt.next(); | |
| 1469 | - if(GpsSpeed.getEndtimestamp()-GpsSpeed.getTimestamp()<=1000){ | |
| 1470 | - speedIt.remove(); | |
| 1471 | - } | |
| 1472 | - } | |
| 1473 | - } | |
| 1474 | - } | |
| 1475 | - if(map.get("curPage") == null || map.get("curPage").equals("0")){ | |
| 1476 | - curPage = 0; | |
| 1477 | - }else{ | |
| 1478 | - curPage = Integer.parseInt((String) map.get("curPage")); | |
| 1479 | - } | |
| 1480 | - Integer totalPage = totalDays; | |
| 1481 | - pageData = listResult.size();//每页的记录条数就是当前页查出的全部数据。 | |
| 1482 | - Map<String,Object> paramMap = new HashMap<String,Object>(); | |
| 1483 | - paramMap.put("totalPage", totalPage); | |
| 1484 | - paramMap.put("page", curPage); | |
| 1485 | - paramMap.put("pageData", pageData); | |
| 1486 | - paramMap.put("list", listResult); | |
| 1487 | - return paramMap; | |
| 1488 | - } | |
| 1489 | - | |
| 1490 | - @Override | |
| 1491 | - public Map<String, Object> allCarsByLine(String lineCode) { | |
| 1492 | - Map<String, Object> map = new HashMap(); | |
| 1493 | - try{ | |
| 1494 | - List<Map<String, Object>> list = new ArrayList<>(); | |
| 1495 | - Map<String, Object> item; | |
| 1496 | - GpsEntity gps; | |
| 1497 | - //当天线路下营运的车辆 | |
| 1498 | - Set<String> cars = dayOfSchedule.findCarByLineCode(lineCode); | |
| 1499 | - ScheduleRealInfo sch; | |
| 1500 | - String device; | |
| 1501 | - | |
| 1502 | - Map<String, Integer> allDevices = new HashMap<>(); | |
| 1503 | - String execStr = ""; | |
| 1504 | - D80 d80; | |
| 1505 | - for(String nbbm : cars){ | |
| 1506 | - item = new HashMap<>(); | |
| 1507 | - device = BasicData.deviceId2NbbmMap.inverse().get(nbbm); | |
| 1508 | - allDevices.put(device, 1); | |
| 1509 | - item.put("nbbm", nbbm); | |
| 1510 | - item.put("device", device); | |
| 1511 | - | |
| 1512 | - sch = dayOfSchedule.executeCurr(nbbm); | |
| 1513 | - if(null != sch){ | |
| 1514 | - execStr = (sch.getXlDir().equals("0")?"上行":"下行") + "("+sch.getDfsj()+")"; | |
| 1515 | - if(!sch.getXlBm().equals(lineCode)) | |
| 1516 | - execStr = sch.getXlName()+execStr; | |
| 1517 | - else | |
| 1518 | - item.put("schId", sch.getId()); | |
| 1519 | - item.put("exec", execStr); | |
| 1520 | - } | |
| 1521 | - | |
| 1522 | - gps = gpsRealData.get(device); | |
| 1523 | - if(null != gps){ | |
| 1524 | - item.put("loc", gps.getStationName()); | |
| 1525 | - item.put("lineCodeReal", gps.getLineId()); | |
| 1526 | - item.put("status", gps.isOffline()?"离线":"在线"); | |
| 1527 | - item.put("gpsTs", gps.getTimestamp()); | |
| 1528 | - } | |
| 1529 | - //请求出场时间 | |
| 1530 | - d80 = PilotReport.qqccMap.get(device); | |
| 1531 | - if(null != d80) | |
| 1532 | - item.put("qqcc", d80.getTimestamp()); | |
| 1533 | - | |
| 1534 | - list.add(item); | |
| 1535 | - } | |
| 1536 | - | |
| 1537 | - //车载编码落在该线路的设备 | |
| 1538 | - Set<String> devices = gpsRealData.findDevices(lineCode); | |
| 1539 | - for(String d : devices){ | |
| 1540 | - if(allDevices.containsKey(d)) | |
| 1541 | - continue; | |
| 1542 | - | |
| 1543 | - gps = gpsRealData.get(d); | |
| 1544 | - if(null == gps) | |
| 1545 | - continue; | |
| 1546 | - | |
| 1547 | - item = new HashMap<>(); | |
| 1548 | - item.put("nbbm", gps.getNbbm()); | |
| 1549 | - item.put("device", d); | |
| 1550 | - item.put("loc", gps.getStationName()); | |
| 1551 | - item.put("lineCodeReal", gps.getLineId()); | |
| 1552 | - item.put("status", gps.isOffline()?"离线":"在线"); | |
| 1553 | - item.put("gpsTs", gps.getTimestamp()); | |
| 1554 | - | |
| 1555 | - //请求出场时间 | |
| 1556 | - d80 = PilotReport.qqccMap.get(d); | |
| 1557 | - if(null != d80) | |
| 1558 | - item.put("qqcc", d80.getTimestamp()); | |
| 1559 | - | |
| 1560 | - list.add(item); | |
| 1561 | - } | |
| 1562 | - | |
| 1563 | - map.put("list", list); | |
| 1564 | - map.put("status", ResponseCode.SUCCESS); | |
| 1565 | - }catch (Exception e){ | |
| 1566 | - logger.error("", e); | |
| 1567 | - map.put("status", ResponseCode.ERROR); | |
| 1568 | - map.put("msg", e.getMessage()); | |
| 1569 | - } | |
| 1570 | - return map; | |
| 1571 | - } | |
| 1572 | - | |
| 1573 | - static List<GpsSpeed> findAll(Map<String, Object> map) { | |
| 1574 | - Connection conn = null; | |
| 1575 | - PreparedStatement ps = null; | |
| 1576 | - ResultSet rs = null; | |
| 1577 | - List<GpsSpeed> list=new ArrayList<GpsSpeed>(); | |
| 1578 | - String sql="select * from bsth_c_gps_info where 1=1 "; | |
| 1579 | - Object line=map.get("line"); | |
| 1580 | - Object nbbm=map.get("nbbm"); | |
| 1581 | - Object updown=map.get("updown"); | |
| 1582 | - Object startDate=map.get("startDate"); | |
| 1583 | - Object endDate=map.get("endDate"); | |
| 1584 | - Integer totalDays = Integer.valueOf(map.get("totalDays").toString()); | |
| 1585 | - Integer curPage = 0;//页码 | |
| 1586 | - if(map.get("curPage") == null || map.get("curPage").equals("0")){ | |
| 1587 | - curPage = 0; | |
| 1588 | - }else{ | |
| 1589 | - curPage = Integer.parseInt((String) map.get("curPage")); | |
| 1590 | - } | |
| 1591 | - | |
| 1592 | - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 1593 | - if(line!=null){ | |
| 1594 | - sql +=" and line_id like'%"+line.toString().trim()+"%'"; | |
| 1595 | - } | |
| 1596 | - | |
| 1597 | - if(nbbm!=null){ | |
| 1598 | - nbbm=BasicData.deviceId2NbbmMap.inverse().get(nbbm); | |
| 1599 | - if(nbbm!=null) | |
| 1600 | - sql +=" and vehicle like '%"+nbbm.toString()+"%'"; | |
| 1601 | - } | |
| 1602 | - | |
| 1603 | - if(updown!=null){ | |
| 1604 | - sql +="and industry_code like '%"+updown.toString()+"%'"; | |
| 1605 | - } | |
| 1606 | - if(startDate!=null){ | |
| 1607 | - if (startDate.toString().length()>0) { | |
| 1608 | - try { | |
| 1609 | - Long t1=sdf.parse(startDate.toString()+" 00:00:00").getTime()+curPage*3600*24*1000; | |
| 1610 | - sql += " and ts >="+t1; | |
| 1611 | - } catch (ParseException e) { | |
| 1612 | - e.printStackTrace(); | |
| 1613 | - } | |
| 1614 | - } | |
| 1615 | - | |
| 1616 | - } | |
| 1617 | - if(endDate!=null){ | |
| 1618 | - if (endDate.toString().length()>0) { | |
| 1619 | - try { | |
| 1620 | - Long t2=sdf.parse(endDate.toString()+" 23:59:59").getTime()-(totalDays-1-curPage)*3600*24*1000; | |
| 1621 | - sql += " and ts <="+t2; | |
| 1622 | - } catch (ParseException e) { | |
| 1623 | - e.printStackTrace(); | |
| 1624 | - } | |
| 1625 | - } | |
| 1626 | - | |
| 1627 | - } | |
| 1628 | - | |
| 1629 | - try { | |
| 1630 | - conn = DBUtils_MS.getConnection(); | |
| 1631 | - ps = conn.prepareStatement(sql); | |
| 1632 | - rs = ps.executeQuery(); | |
| 1633 | - list = resultSet2Set(rs); | |
| 1634 | - } catch (SQLException e) { | |
| 1635 | - e.printStackTrace(); | |
| 1636 | - }finally { | |
| 1637 | - DBUtils_MS.close(rs, ps, conn); | |
| 1638 | - } | |
| 1639 | - | |
| 1640 | - return list; | |
| 1641 | - } | |
| 1642 | - | |
| 1643 | - static List<GpsSpeed> resultSet2Set(ResultSet rs) throws SQLException{ | |
| 1644 | - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 1645 | - List<GpsSpeed> list=new ArrayList<GpsSpeed>(); | |
| 1646 | - GpsSpeed GpsSpeed; | |
| 1647 | - Float lon, lat; | |
| 1648 | - Location location; | |
| 1649 | - while(rs.next()){ | |
| 1650 | - lon = rs.getFloat("lon"); | |
| 1651 | - lat = rs.getFloat("lat"); | |
| 1652 | - location = TransGPS.LocationMake(lon, lat); | |
| 1653 | - location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location)); | |
| 1654 | - GpsSpeed=new GpsSpeed(); | |
| 1655 | - GpsSpeed.setLon((float)location.getLng()); | |
| 1656 | - GpsSpeed.setLat((float)location.getLat()); | |
| 1657 | - GpsSpeed.setLine(rs.getObject("line_id").toString()); | |
| 1658 | - //run 时注解 | |
| 1659 | - GpsSpeed.setLineName(BasicData.lineCode2NameMap.get(GpsSpeed.getLine().toString())); | |
| 1660 | - GpsSpeed.setSpeed(Float.valueOf(rs.getObject("speed_gps").toString())); | |
| 1661 | - GpsSpeed.setTimestamp((Long.valueOf(rs.getObject("ts").toString()))); | |
| 1662 | - GpsSpeed.setTimestampDate(sdf.format(new Date(GpsSpeed.getTimestamp()))); | |
| 1663 | - GpsSpeed.setUp_down(((Integer.valueOf(rs.getObject("service_state").toString())) & 0x10000000)==0?0:1); | |
| 1664 | - GpsSpeed.setVehicle(BasicData.deviceId2NbbmMap.get(rs.getObject("device_id").toString())); | |
| 1665 | - list.add(GpsSpeed); | |
| 1666 | - } | |
| 1667 | - return list; | |
| 1668 | - } | |
| 1669 | - | |
| 1670 | -} | |
| 1671 | - | |
| 1 | +package com.bsth.service.gps; | |
| 2 | + | |
| 3 | +import java.io.IOException; | |
| 4 | +import java.io.OutputStream; | |
| 5 | +import java.io.UnsupportedEncodingException; | |
| 6 | +import java.lang.reflect.Field; | |
| 7 | +import java.net.URLEncoder; | |
| 8 | +import java.sql.Connection; | |
| 9 | +import java.sql.PreparedStatement; | |
| 10 | +import java.sql.ResultSet; | |
| 11 | +import java.sql.SQLException; | |
| 12 | +import java.text.DecimalFormat; | |
| 13 | +import java.text.ParseException; | |
| 14 | +import java.text.SimpleDateFormat; | |
| 15 | +import java.util.ArrayList; | |
| 16 | +import java.util.Arrays; | |
| 17 | +import java.util.Calendar; | |
| 18 | +import java.util.Collections; | |
| 19 | +import java.util.Comparator; | |
| 20 | +import java.util.Date; | |
| 21 | +import java.util.HashMap; | |
| 22 | +import java.util.HashSet; | |
| 23 | +import java.util.Iterator; | |
| 24 | +import java.util.LinkedList; | |
| 25 | +import java.util.List; | |
| 26 | +import java.util.Map; | |
| 27 | +import java.util.Set; | |
| 28 | + | |
| 29 | +import javax.servlet.http.HttpServletResponse; | |
| 30 | + | |
| 31 | +import org.apache.commons.lang3.StringUtils; | |
| 32 | +import org.apache.poi.hssf.usermodel.HSSFCellStyle; | |
| 33 | +import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |
| 34 | +import org.apache.poi.ss.usermodel.CellStyle; | |
| 35 | +import org.apache.poi.ss.usermodel.Row; | |
| 36 | +import org.apache.poi.ss.usermodel.Sheet; | |
| 37 | +import org.apache.poi.ss.usermodel.Workbook; | |
| 38 | +import org.joda.time.format.DateTimeFormat; | |
| 39 | +import org.joda.time.format.DateTimeFormatter; | |
| 40 | +import org.slf4j.Logger; | |
| 41 | +import org.slf4j.LoggerFactory; | |
| 42 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 43 | +import org.springframework.dao.DataAccessException; | |
| 44 | +import org.springframework.jdbc.core.BeanPropertyRowMapper; | |
| 45 | +import org.springframework.jdbc.core.JdbcTemplate; | |
| 46 | +import org.springframework.stereotype.Service; | |
| 47 | + | |
| 48 | +import com.bsth.common.ResponseCode; | |
| 49 | +import com.bsth.data.BasicData; | |
| 50 | +import com.bsth.data.forecast.entity.ArrivalEntity; | |
| 51 | +import com.bsth.data.gpsdata_v2.GpsRealData; | |
| 52 | +import com.bsth.data.gpsdata_v2.cache.GeoCacheData; | |
| 53 | +import com.bsth.data.gpsdata_v2.cache.GpsCacheData; | |
| 54 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | |
| 55 | +import com.bsth.data.gpsdata_v2.utils.GeoUtils; | |
| 56 | +import com.bsth.data.pilot80.PilotReport; | |
| 57 | +import com.bsth.data.safe_driv.SafeDriv; | |
| 58 | +import com.bsth.data.safe_driv.SafeDrivCenter; | |
| 59 | +import com.bsth.data.schedule.DayOfSchedule; | |
| 60 | +import com.bsth.entity.LineVersions; | |
| 61 | +import com.bsth.entity.LsSectionRoute; | |
| 62 | +import com.bsth.entity.LsStationRoute; | |
| 63 | +import com.bsth.entity.directive.D80; | |
| 64 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 65 | +import com.bsth.repository.CarParkRepository; | |
| 66 | +import com.bsth.repository.LineRepository; | |
| 67 | +import com.bsth.repository.LineVersionsRepository; | |
| 68 | +import com.bsth.repository.LsSectionRouteRepository; | |
| 69 | +import com.bsth.repository.LsStationRouteRepository; | |
| 70 | +import com.bsth.repository.StationRepository; | |
| 71 | +import com.bsth.repository.realcontrol.ScheduleRealInfoRepository; | |
| 72 | +import com.bsth.service.gps.entity.DeviceChange; | |
| 73 | +import com.bsth.service.gps.entity.GpsOutbound_DTO; | |
| 74 | +import com.bsth.service.gps.entity.GpsSpeed; | |
| 75 | +import com.bsth.service.gps.entity.GpsSpeed_DTO; | |
| 76 | +import com.bsth.service.gps.entity.HistoryGps_DTO; | |
| 77 | +import com.bsth.service.gps.entity.HistoryGps_DTOV3; | |
| 78 | +import com.bsth.service.gps.entity.Road_DTO; | |
| 79 | +import com.bsth.util.TransGPS; | |
| 80 | +import com.bsth.util.TransGPS.Location; | |
| 81 | +import com.bsth.util.db.DBUtils_MS; | |
| 82 | + | |
| 83 | +@Service | |
| 84 | +public class GpsServiceImpl implements GpsService { | |
| 85 | + /** | |
| 86 | + * 历史gps查询最大范围 24小时 | |
| 87 | + */ | |
| 88 | + final static Long GPS_RANGE = 60 * 60 * 24L; | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * jdbc | |
| 92 | + */ | |
| 93 | + Connection conn = null; | |
| 94 | + PreparedStatement ps = null; | |
| 95 | + ResultSet rs = null; | |
| 96 | + | |
| 97 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 98 | + | |
| 99 | + @Autowired | |
| 100 | + GpsRealData gpsRealData; | |
| 101 | + | |
| 102 | + @Autowired | |
| 103 | + JdbcTemplate jdbcTemplate; | |
| 104 | + | |
| 105 | + @Autowired | |
| 106 | + DayOfSchedule dayOfSchedule; | |
| 107 | + | |
| 108 | + @Autowired | |
| 109 | + ScheduleRealInfoRepository scheduleRealInfoRepository; | |
| 110 | + | |
| 111 | + | |
| 112 | + @Autowired | |
| 113 | + LineVersionsRepository lineVersionsRepository; | |
| 114 | + | |
| 115 | + @Autowired | |
| 116 | + LineRepository lineRepository; | |
| 117 | + | |
| 118 | + @Autowired | |
| 119 | + LsStationRouteRepository lsStationRouteRepository; | |
| 120 | + | |
| 121 | + @Autowired | |
| 122 | + LsSectionRouteRepository lsSectionRouteRepository; | |
| 123 | + | |
| 124 | + // 历史gps查询 | |
| 125 | + @Override | |
| 126 | + public List<Map<String, Object>> history(String device, Long startTime, Long endTime, int directions) { | |
| 127 | + Calendar sCal = Calendar.getInstance(); | |
| 128 | + sCal.setTime(new Date(startTime)); | |
| 129 | + | |
| 130 | + Calendar eCal = Calendar.getInstance(); | |
| 131 | + eCal.setTime(new Date(endTime)); | |
| 132 | + | |
| 133 | + int dayOfYear = sCal.get(Calendar.DAY_OF_YEAR); | |
| 134 | + /* | |
| 135 | + * if(dayOfYear != eCal.get(Calendar.DAY_OF_YEAR)){ | |
| 136 | + * System.out.println("暂时不支持跨天查询..."); return null; } | |
| 137 | + */ | |
| 138 | + | |
| 139 | + String sql = "select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE ,STOP_NO from bsth_c_gps_info where days_year=? and device_id=? and ts > ? and ts < ?"; | |
| 140 | + Connection conn = null; | |
| 141 | + PreparedStatement ps = null; | |
| 142 | + ResultSet rs = null; | |
| 143 | + List<Map<String, Object>> list = new ArrayList<>(); | |
| 144 | + Map<String, Object> map = null; | |
| 145 | + try { | |
| 146 | + conn = DBUtils_MS.getConnection(); | |
| 147 | + ps = conn.prepareStatement(sql); | |
| 148 | + ps.setInt(1, dayOfYear); | |
| 149 | + ps.setString(2, device); | |
| 150 | + ps.setLong(3, startTime); | |
| 151 | + ps.setLong(4, endTime); | |
| 152 | + | |
| 153 | + rs = ps.executeQuery(); | |
| 154 | + Float lon, lat; | |
| 155 | + Location location; | |
| 156 | + int upDown; | |
| 157 | + while (rs.next()) { | |
| 158 | + upDown = getUpOrDown(rs.getLong("SERVICE_STATE")); | |
| 159 | + if (upDown != directions) | |
| 160 | + continue; | |
| 161 | + | |
| 162 | + // to 百度坐标 | |
| 163 | + lon = rs.getFloat("LON"); | |
| 164 | + lat = rs.getFloat("LAT"); | |
| 165 | + location = TransGPS.LocationMake(lon, lat); | |
| 166 | + location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location)); | |
| 167 | + | |
| 168 | + map = new HashMap<>(); | |
| 169 | + map.put("device", rs.getString("DEVICE_ID")); | |
| 170 | + map.put("lon", location.getLng()); | |
| 171 | + map.put("lat", location.getLat()); | |
| 172 | + map.put("ts", rs.getLong("TS")); | |
| 173 | + map.put("stopNo", rs.getString("STOP_NO")); | |
| 174 | + map.put("inout_stop", rs.getInt("INOUT_STOP")); | |
| 175 | + // 上下行 | |
| 176 | + map.put("upDown", upDown); | |
| 177 | + list.add(map); | |
| 178 | + } | |
| 179 | + } catch (Exception e) { | |
| 180 | + e.printStackTrace(); | |
| 181 | + } finally { | |
| 182 | + DBUtils_MS.close(rs, ps, conn); | |
| 183 | + } | |
| 184 | + return list; | |
| 185 | + } | |
| 186 | + | |
| 187 | + /** | |
| 188 | + * 王通 2016/6/29 9:23:24 获取车辆线路上下行 | |
| 189 | + * | |
| 190 | + * @return -1无效 0上行 1下行 | |
| 191 | + */ | |
| 192 | + public static byte getUpOrDown(long serviceState) { | |
| 193 | + /*if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000 | |
| 194 | + || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000) | |
| 195 | + return -1;*/ | |
| 196 | + return (byte) (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0); | |
| 197 | + } | |
| 198 | + | |
| 199 | + /** | |
| 200 | + * 获取运营状态 | |
| 201 | + * | |
| 202 | + * @return -1无效 0运营 1未运营 | |
| 203 | + */ | |
| 204 | + public static byte getService(long serviceState) { | |
| 205 | + /*if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000) | |
| 206 | + return -1;*/ | |
| 207 | + return (byte) (((serviceState & 0x02000000) == 0x02000000) ? 1 : 0); | |
| 208 | + } | |
| 209 | + | |
| 210 | + private static DateTimeFormatter fmtyyyy = DateTimeFormat.forPattern("yyyy"); | |
| 211 | + @Override | |
| 212 | + public Map<String, Object> history(String[] nbbmArray, Long st, Long et) { | |
| 213 | + Map<String, Object> rsMap = new HashMap<>(); | |
| 214 | + List<Map<String, Object>> list = new ArrayList<>(); | |
| 215 | + rsMap.put("list", list); | |
| 216 | + if (et - st > GPS_RANGE) | |
| 217 | + return rsMap; | |
| 218 | + | |
| 219 | + st = st * 1000; | |
| 220 | + et = et * 1000; | |
| 221 | + // day_of_year 分区字段 | |
| 222 | + Calendar sCal = Calendar.getInstance(); | |
| 223 | + sCal.setTime(new Date(st)); | |
| 224 | + int sDayOfYear = sCal.get(Calendar.DAY_OF_YEAR); | |
| 225 | + Calendar eCal = Calendar.getInstance(); | |
| 226 | + eCal.setTime(new Date(et)); | |
| 227 | + int eDayOfYear = eCal.get(Calendar.DAY_OF_YEAR); | |
| 228 | + | |
| 229 | + String nbbm = nbbmArray[0]; | |
| 230 | + | |
| 231 | + List<DeviceChange> dcs = findDeviceChangeLogs(nbbm, et, st); | |
| 232 | + | |
| 233 | + //按年分表 | |
| 234 | + String tableName = "bsth_c_gps_info_" + fmtyyyy.print(st); | |
| 235 | + | |
| 236 | + StringBuilder sql = new StringBuilder(""); | |
| 237 | + long t1,t2; | |
| 238 | + DeviceChange dc; | |
| 239 | + for(int i = 0,len=dcs.size(); i < len; i++){ | |
| 240 | + t1 = st; | |
| 241 | + t2 = et; | |
| 242 | + dc = dcs.get(i); | |
| 243 | + if(dc.getSt() > st) | |
| 244 | + t1 = dc.getSt(); | |
| 245 | + if(dc.getEt() < et && dc.getEt()!=0) | |
| 246 | + t2 = dc.getEt(); | |
| 247 | + | |
| 248 | + sql.append("select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE ,STOP_NO,DIRECTION,LINE_ID,SPEED_GPS,SECTION_CODE from "+tableName+" where days_year in ("+sDayOfYear+","+eDayOfYear+") " + | |
| 249 | + " and device_id='"+dc.getDevice()+"' and ts >= "+t1+" and ts <= "+t2+" "); | |
| 250 | + | |
| 251 | + if(i == len - 1) | |
| 252 | + sql.append(" ORDER BY device_id,ts,stop_no"); | |
| 253 | + else | |
| 254 | + sql.append(" UNION "); | |
| 255 | + } | |
| 256 | + | |
| 257 | + logger.info("轨迹回放 nbbm: " + nbbm + " -st: " + st + " -et: " + et + " -sql: " + sql.toString()); | |
| 258 | + | |
| 259 | + // 查询到离站数据 | |
| 260 | + Map<String, ArrivalEntity> arrivalMap = findArrivalByTs(st, et, dcs); | |
| 261 | + | |
| 262 | + //查询GPS数据 | |
| 263 | + JdbcTemplate jdbcTemplate_ms = new JdbcTemplate(DBUtils_MS.getDataSource()); | |
| 264 | + List<Map<String, Object>> dataList = jdbcTemplate_ms.queryForList(sql.toString()); | |
| 265 | + | |
| 266 | + Float lon, lat; | |
| 267 | + Location bdLoc, gdLoc; | |
| 268 | + int inOutStop; | |
| 269 | + long serviceState; | |
| 270 | + ArrivalEntity arrival; | |
| 271 | + Set<Integer> lineSet=new HashSet<Integer>(); | |
| 272 | + List<Map<String,Object>> lineSwitch=new ArrayList<>(); | |
| 273 | + | |
| 274 | + List<Map<String, Object>> gpsNotValidList=new ArrayList<>(); | |
| 275 | + List<Map<String, Object>> gpsEqualsZeroList=new ArrayList<>(); | |
| 276 | + Map<String, Object> map = null; | |
| 277 | + int oldLineId = -1, oldGpsValid = -1, oldLonlat = -1; | |
| 278 | + | |
| 279 | + // 默认加入一个线路切换信息 | |
| 280 | + Map<String, Object> fls = new HashMap<String, Object>(); | |
| 281 | + fls.put("abnormalType", "normal"); | |
| 282 | + fls.put("st", "-1"); | |
| 283 | + lineSwitch.add(fls); | |
| 284 | + | |
| 285 | + // 默认加入一个GPS无效异常信息 | |
| 286 | + Map<String, Object> fgv = new HashMap<String, Object>(); | |
| 287 | + fgv.put("abnormalType", "normal"); | |
| 288 | + fgv.put("st", "-1"); | |
| 289 | + gpsNotValidList.add(fgv); | |
| 290 | + | |
| 291 | + // 默认加入一个经纬度为零异常信息 | |
| 292 | + Map<String, Object> fgez = new HashMap<String, Object>(); | |
| 293 | + fgez.put("abnormalType", "normal"); | |
| 294 | + fgez.put("st", "-1"); | |
| 295 | + gpsEqualsZeroList.add(fgez); | |
| 296 | + | |
| 297 | + Map<String, Integer> lineCode2IdMap = BasicData.lineId2CodeMap.inverse(); | |
| 298 | + for(Map<String, Object> rs : dataList) { | |
| 299 | + Object lineCode = rs.get("LINE_ID"); | |
| 300 | + // 线路ID发生变化时补全线路切换信息 并新加入一个 | |
| 301 | + if (oldLineId != (Integer)lineCode) { | |
| 302 | + String lineName = BasicData.lineCode2NameMap.get(lineCode.toString()); | |
| 303 | + Integer lineId = lineCode2IdMap.get(lineCode.toString()); | |
| 304 | + lineSwitch.get(lineSwitch.size() - 1).put("line2", lineName); | |
| 305 | + lineSwitch.get(lineSwitch.size() - 1).put("et", rs.get("TS")); | |
| 306 | + | |
| 307 | + Map<String, Object> ls = new HashMap<String, Object>(); | |
| 308 | + ls.put("abnormalType", "lineSwitch"); | |
| 309 | + ls.put("line1", lineName); | |
| 310 | + lineSwitch.add(ls); | |
| 311 | + | |
| 312 | + lineSet.add((Integer)lineId); | |
| 313 | + oldLineId = (Integer)lineId; | |
| 314 | + } | |
| 315 | + serviceState = map_get_long(rs, "SERVICE_STATE"); | |
| 316 | + // GPS状态发生变化时补全信息 并新加入一个 | |
| 317 | + if (getGpsValid(serviceState) != oldGpsValid) { | |
| 318 | + gpsNotValidList.get(gpsNotValidList.size() - 1).put("et", rs.get("TS")); | |
| 319 | + | |
| 320 | + Map<String, Object> gv = new HashMap<String, Object>(); | |
| 321 | + gv.put("abnormalType", getGpsValid(serviceState) == 0 ? "normal" : "gpsNotValid"); | |
| 322 | + gv.put("st", rs.get("TS")); | |
| 323 | + gpsNotValidList.add(gv); | |
| 324 | + | |
| 325 | + oldGpsValid = getGpsValid(serviceState); | |
| 326 | + } | |
| 327 | + | |
| 328 | + map = new HashMap<>(); | |
| 329 | + lon = map_get_float(rs, "LON"); | |
| 330 | + lat = map_get_float(rs, "LAT"); | |
| 331 | + // 经纬度为零 | |
| 332 | + if ((lon == 0 || lat == 0 ? 1 : 0) != oldLonlat){ | |
| 333 | + gpsEqualsZeroList.get(gpsEqualsZeroList.size() - 1).put("et", rs.get("TS")); | |
| 334 | + | |
| 335 | + Map<String, Object> gez = new HashMap<String, Object>(); | |
| 336 | + gez.put("abnormalType", (lon == 0 || lat == 0 ? 1 : 0) == 0 ? "normal" : "gpsZero"); | |
| 337 | + gez.put("st", rs.get("TS")); | |
| 338 | + gpsEqualsZeroList.add(gez); | |
| 339 | + | |
| 340 | + oldLonlat = (lon == 0 || lat == 0 ? 1 : 0); | |
| 341 | + } | |
| 342 | + | |
| 343 | + // 高德坐标 | |
| 344 | + gdLoc = TransGPS.transformFromWGSToGCJ(TransGPS.LocationMake(lon, lat)); | |
| 345 | + map.put("gcj_lon", gdLoc.getLng()); | |
| 346 | + map.put("gcj_lat", gdLoc.getLat()); | |
| 347 | + // 百度坐标 | |
| 348 | + bdLoc = TransGPS.bd_encrypt(gdLoc); | |
| 349 | + map.put("bd_lon", bdLoc.getLng()); | |
| 350 | + map.put("bd_lat", bdLoc.getLat()); | |
| 351 | + //原始坐标 | |
| 352 | + map.put("lon", lon); | |
| 353 | + map.put("lat", lat); | |
| 354 | + | |
| 355 | + map.put("deviceId", map_get_str(rs, "DEVICE_ID")); | |
| 356 | + map.put("ts", map_get_long(rs, "TS")); | |
| 357 | + map.put("timestamp", map_get_long(rs, "TS")); | |
| 358 | + map.put("stopNo", map_get_str(rs, "STOP_NO")); | |
| 359 | + map.put("direction", map_get_float(rs,"DIRECTION")); | |
| 360 | + | |
| 361 | + map.put("lineId", map_get_str(rs, "LINE_ID")); | |
| 362 | + map.put("speed", map_get_float(rs,"SPEED_GPS")); | |
| 363 | + | |
| 364 | + inOutStop = Integer.parseInt(rs.get("INOUT_STOP").toString()); | |
| 365 | + map.put("inout_stop", inOutStop); | |
| 366 | + | |
| 367 | + arrival = arrivalMap.get(map_get_str(rs, "DEVICE_ID") + "_" + map_get_long(rs, "TS")); | |
| 368 | + if (arrival != null) { | |
| 369 | + map.put("inout_stop_info", arrival); | |
| 370 | + map.put("inout_stop", arrival.getInOut()); | |
| 371 | + } | |
| 372 | + | |
| 373 | + //map.put("nbbm", nbbm); | |
| 374 | + map.put("state", getService(serviceState)); | |
| 375 | + // 上下行 | |
| 376 | + map.put("upDown", getUpOrDown(serviceState)); | |
| 377 | + //路段编码 | |
| 378 | + map.put("section_code", map_get_str(rs,"SECTION_CODE")); | |
| 379 | + list.add(map); | |
| 380 | + } | |
| 381 | + if (dataList.size() > 0) { | |
| 382 | + Map<String, Object> rs = dataList.get(dataList.size() - 1); | |
| 383 | + gpsNotValidList.get(gpsNotValidList.size() - 1).put("et", rs.get("TS")); | |
| 384 | + gpsEqualsZeroList.get(gpsEqualsZeroList.size() - 1).put("et", rs.get("TS")); | |
| 385 | + } | |
| 386 | + | |
| 387 | + for (int i = lineSwitch.size() - 1;i > -1;i--) { | |
| 388 | + Map<String, Object> ls = lineSwitch.get(i); | |
| 389 | + if ("normal".equals(ls.get("abnormalType")) || ls.get("et") == null) { | |
| 390 | + lineSwitch.remove(i); | |
| 391 | + } | |
| 392 | + } | |
| 393 | + | |
| 394 | + for (int i = gpsNotValidList.size() - 1;i > -1;i--) { | |
| 395 | + Map<String, Object> gnv = gpsNotValidList.get(i); | |
| 396 | + if ("normal".equals(gnv.get("abnormalType"))) { | |
| 397 | + gpsNotValidList.remove(i); | |
| 398 | + } | |
| 399 | + } | |
| 400 | + | |
| 401 | + for (int i = gpsEqualsZeroList.size() - 1;i > -1;i--) { | |
| 402 | + Map<String, Object> gez = gpsEqualsZeroList.get(i); | |
| 403 | + if ("normal".equals(gez.get("abnormalType"))) { | |
| 404 | + gpsEqualsZeroList.remove(i); | |
| 405 | + } | |
| 406 | + } | |
| 407 | + | |
| 408 | + if (lineSet.size() > 0){ | |
| 409 | + List<Map<String,Object>> vlist=new ArrayList<>(); | |
| 410 | + Map<String, Map<String, Object>> vmap = new HashMap<>(); | |
| 411 | + Map<String, Map<String, String>> lv2station = new HashMap<String, Map<String, String>>();//lv2section = new HashMap<String, Map<String, String>>(); | |
| 412 | + for (Integer lineId : lineSet) { | |
| 413 | + String lineCode = BasicData.lineId2CodeMap.get(lineId); | |
| 414 | + List<LineVersions> lvs = lineVersionsRepository.findBylineId(lineId); | |
| 415 | + for (LineVersions lv : lvs) { | |
| 416 | + long vst = lv.getStartDate().getTime(), vet = lv.getEndDate().getTime(); | |
| 417 | + if (st >= vst && st <= vet || et >= vst && et <= vet) { | |
| 418 | + List<LsStationRoute> stations = lsStationRouteRepository.findupdated(lineId, lineId.toString(), lv.getVersions()); | |
| 419 | + //List<LsSectionRoute> sections = lsSectionRouteRepository.findupdated(lineId, lineId.toString(), lv.getVersions()); | |
| 420 | + Map<String, Object> vm = new HashMap<String, Object>(); | |
| 421 | + vm.put("lineId", lineCode); | |
| 422 | + vm.put("version", lv.getVersions()); | |
| 423 | + vm.put("startTime", vst); | |
| 424 | + vm.put("endTime", vet); | |
| 425 | + vm.put("stations", stations); | |
| 426 | + //vm.put("sections", sections); | |
| 427 | + | |
| 428 | + Map<String, String> stationcode2name = new HashMap<String, String>();//sectioncode2name = new HashMap<String, String>(); | |
| 429 | + for (LsStationRoute lsr : stations) { | |
| 430 | + stationcode2name.put(lsr.getStationCode(), lsr.getStationName()); | |
| 431 | + } | |
| 432 | + //for (LsSectionRoute lsr : sections) { | |
| 433 | + // sectioncode2name.put(lsr.getSectionCode(), lsr.getSection().getSectionName()); | |
| 434 | + //} | |
| 435 | + lv2station.put(lineCode + "_" + lv.getVersions(), stationcode2name); | |
| 436 | + // 路段因为可能漂到其它线路路段 因此需要使用最新的全量路段 | |
| 437 | + //lv2section.put(lineId + "_" + lv.getVersions(), sectioncode2name); | |
| 438 | + | |
| 439 | + vlist.add(vm); | |
| 440 | + vmap.put(lineCode + "_" + lv.getVersions(), vm); | |
| 441 | + } | |
| 442 | + } | |
| 443 | + } | |
| 444 | + rsMap.put("lineVerson",vlist); | |
| 445 | + | |
| 446 | + for (Map<String, Object> gps : list) { | |
| 447 | + long ts = (long)gps.get("timestamp"); | |
| 448 | + for (Map<String, Object> vm : vlist) { | |
| 449 | + long vst = (long)vm.get("startTime"), vet = (long)vm.get("endTime"); | |
| 450 | + if (gps.get("lineId").equals(vm.get("lineId")) && ts >= vst && ts <= vet) { | |
| 451 | + gps.put("version", vm.get("version")); | |
| 452 | + String key = vm.get("lineId") + "_" + vm.get("version"); | |
| 453 | + /*if (StringUtils.isEmpty(sectionCode)) { | |
| 454 | + gps.put("section_code", "-00404"); | |
| 455 | + gps.put("section_name", "未知路段"); | |
| 456 | + } | |
| 457 | + gps.put("section_name", lv2section.get(key).get(sectionCode));*/ | |
| 458 | + ArrivalEntity ae = (ArrivalEntity)gps.get("inout_stop_info"); | |
| 459 | + if (ae != null) { | |
| 460 | + ae.setStopName(lv2station.get(key).get(ae.getStopNo())); | |
| 461 | + if (StringUtils.isEmpty(lv2station.get(key).get(ae.getStopNo()))) { | |
| 462 | + ae.setStopName(BasicData.stationCode2NameMap.get(ae.getStopNo())); | |
| 463 | + } | |
| 464 | + } | |
| 465 | + } | |
| 466 | + } | |
| 467 | + } | |
| 468 | + } | |
| 469 | + // 按时间排序 | |
| 470 | + Collections.sort(list, new Comparator<Map<String, Object>>() { | |
| 471 | + | |
| 472 | + @Override | |
| 473 | + public int compare(Map<String, Object> o1, Map<String, Object> o2) { | |
| 474 | + return (int) (Long.parseLong(o1.get("ts").toString()) - Long.parseLong(o2.get("ts").toString())); | |
| 475 | + } | |
| 476 | + }); | |
| 477 | + | |
| 478 | + rsMap.put("list", list); | |
| 479 | + rsMap.put("dcs", dcs); | |
| 480 | + rsMap.put("gpsNotValid",gpsNotValidList); | |
| 481 | + rsMap.put("lineSwitch",lineSwitch); | |
| 482 | + rsMap.put("lonlatZero",gpsEqualsZeroList); | |
| 483 | + return rsMap; | |
| 484 | + } | |
| 485 | + | |
| 486 | + private String map_get_str(Map<String, Object> map, String key){ | |
| 487 | + return map.containsKey(key)?map.get(key).toString():""; | |
| 488 | + } | |
| 489 | + | |
| 490 | + private Long map_get_long(Map<String, Object> map, String key){ | |
| 491 | + return map.containsKey(key)?Long.parseLong(map.get(key).toString()):-1; | |
| 492 | + } | |
| 493 | + | |
| 494 | + private Float map_get_float(Map<String, Object> map, String key){ | |
| 495 | + return map.containsKey(key)?Float.parseFloat(map.get(key).toString()):-1; | |
| 496 | + } | |
| 497 | + | |
| 498 | + private List<DeviceChange> findDeviceChangeLogs(String nbbm, long et, long st){ | |
| 499 | + List<DeviceChange> dcs = null; | |
| 500 | + List<DeviceChange> rs = new ArrayList<>(); | |
| 501 | + try{ | |
| 502 | + | |
| 503 | + //JdbcTemplate jdbcTemplate_ms = new JdbcTemplate(DBUtils_MS.getDataSource()); | |
| 504 | + dcs = jdbcTemplate.query("select cl_zbh as nbbm,new_device_no as device,old_device_no as old_device,UNIX_TIMESTAMP(qyrq) * 1000 as st from bsth_c_car_device where is_cancel=0 and cl_zbh='"+nbbm+"' order by qyrq" | |
| 505 | + , BeanPropertyRowMapper.newInstance(DeviceChange.class)); | |
| 506 | + | |
| 507 | + | |
| 508 | + //生成一条初始记录 | |
| 509 | + if(dcs.size() > 0){ | |
| 510 | + DeviceChange first = dcs.get(0); | |
| 511 | + | |
| 512 | + DeviceChange initDv = new DeviceChange(); | |
| 513 | + initDv.setDevice(first.getOldDevice()); | |
| 514 | + if(StringUtils.isNotEmpty(initDv.getDevice())){ | |
| 515 | + initDv.setNbbm(first.getNbbm()); | |
| 516 | + initDv.setSt(0); | |
| 517 | + initDv.setEt(first.getSt()); | |
| 518 | + dcs.add(0, initDv); | |
| 519 | + } | |
| 520 | + } | |
| 521 | + for(int i = 0,len=dcs.size(); i < len - 1; i++){ | |
| 522 | + dcs.get(i).setEt(dcs.get(i + 1).getSt()); | |
| 523 | + } | |
| 524 | + | |
| 525 | + for(DeviceChange dc : dcs){ | |
| 526 | + if(dc.getEt() < st && dc.getEt() != 0) | |
| 527 | + continue; | |
| 528 | + if(dc.getSt() > et) | |
| 529 | + continue; | |
| 530 | + | |
| 531 | + rs.add(dc); | |
| 532 | + } | |
| 533 | + | |
| 534 | + //没有设备变更记录,则参考车辆信息上的设备号 | |
| 535 | + if(null == rs || rs.size() == 0){ | |
| 536 | + DeviceChange dc = new DeviceChange(); | |
| 537 | + dc.setNbbm(nbbm); | |
| 538 | + dc.setDevice(BasicData.deviceId2NbbmMap.inverse().get(nbbm)); | |
| 539 | + dc.setSt(st); | |
| 540 | + dc.setEt(et); | |
| 541 | + dc.setType(1); | |
| 542 | + | |
| 543 | + rs.add(dc); | |
| 544 | + } | |
| 545 | + }catch (Exception e){ | |
| 546 | + logger.error("", e); | |
| 547 | + } | |
| 548 | + return rs; | |
| 549 | + } | |
| 550 | + | |
| 551 | + public static byte getGpsValid(long serviceState) { | |
| 552 | + return (byte)(((serviceState & 0x80000000) == 0x80000000) ? 1 : 0); | |
| 553 | + } | |
| 554 | + | |
| 555 | + public static void main(String[] args){ | |
| 556 | + System.out.println(getGpsValid(-2147483648)); | |
| 557 | + } | |
| 558 | + | |
| 559 | + public Map<String, ArrivalEntity> findArrivalByTs(Long st, Long et, List<DeviceChange> dcs) { | |
| 560 | + Map<String, ArrivalEntity> map = new HashMap<>(); | |
| 561 | + | |
| 562 | + // weeks_year 分区字段 | |
| 563 | + Calendar sCal = Calendar.getInstance(); | |
| 564 | + sCal.setTime(new Date(st)); | |
| 565 | + int sWeekOfYear = sCal.get(Calendar.WEEK_OF_YEAR); | |
| 566 | + Calendar eCal = Calendar.getInstance(); | |
| 567 | + eCal.setTime(new Date(et)); | |
| 568 | + int eWeekOfYear = eCal.get(Calendar.WEEK_OF_YEAR); | |
| 569 | + | |
| 570 | + //按年分表 | |
| 571 | + String tableName = "bsth_c_arrival_info_" + fmtyyyy.print(st); | |
| 572 | + | |
| 573 | + StringBuilder sql = new StringBuilder(""); | |
| 574 | + long t1,t2; | |
| 575 | + DeviceChange dc; | |
| 576 | + for(int i = 0,len=dcs.size(); i < len; i++){ | |
| 577 | + t1 = st; | |
| 578 | + t2 = et; | |
| 579 | + dc = dcs.get(i); | |
| 580 | + if(dc.getSt() > st) | |
| 581 | + t1 = dc.getSt(); | |
| 582 | + if(dc.getEt() < et && dc.getEt() != 0) | |
| 583 | + t2 = dc.getEt(); | |
| 584 | + | |
| 585 | + sql.append("SELECT DEVICE_ID,LINE_ID as LINE_CODE,STOP_NO,TS,UP_DOWN,IN_OUT,WEEKS_YEAR,CREATE_DATE FROM " + tableName + | |
| 586 | + " where weeks_year in ("+sWeekOfYear+", "+eWeekOfYear+") and device_id='"+dc.getDevice()+"' and ts > "+t1+" and ts < " + t2); | |
| 587 | + | |
| 588 | + if(i == len - 1) | |
| 589 | + sql.append(" ORDER BY device_id,ts,stop_no "); | |
| 590 | + else | |
| 591 | + sql.append(" UNION "); | |
| 592 | + } | |
| 593 | + | |
| 594 | + logger.info("arrivl sql : " + sql.toString()); | |
| 595 | + JdbcTemplate jdbcTemplate_ms = new JdbcTemplate(DBUtils_MS.getDataSource()); | |
| 596 | + List<ArrivalEntity> list = jdbcTemplate_ms.query(sql.toString(), BeanPropertyRowMapper.newInstance(ArrivalEntity.class)); | |
| 597 | + | |
| 598 | + String stationName, prefix; | |
| 599 | + for(ArrivalEntity arr : list){ | |
| 600 | + prefix = arr.getLineCode() + "_" + arr.getUpDown() + "_"; | |
| 601 | + stationName = BasicData.getStationNameByCode(arr.getStopNo(), prefix); | |
| 602 | + | |
| 603 | + arr.setStopName(stationName); | |
| 604 | + | |
| 605 | + // 反转进出状态 | |
| 606 | + map.put(arr.getDeviceId() + "_" + arr.getTs(), arr); | |
| 607 | + } | |
| 608 | + return map; | |
| 609 | + } | |
| 610 | + | |
| 611 | + | |
| 612 | + @Autowired | |
| 613 | + StationRepository stationRepository; | |
| 614 | + | |
| 615 | + @Autowired | |
| 616 | + CarParkRepository carParkRepository; | |
| 617 | + | |
| 618 | + @Override | |
| 619 | + public Map<String, Object> findBuffAeraByCode(String code, String type) { | |
| 620 | + Object[][] obj = null; | |
| 621 | + if (type.equals("station")) | |
| 622 | + obj = stationRepository.bufferAera(code); | |
| 623 | + else if (type.equals("park")) | |
| 624 | + obj = carParkRepository.bufferAera(code); | |
| 625 | + | |
| 626 | + Map<String, Object> rs = new HashMap<>(); | |
| 627 | + | |
| 628 | + Object[] subObj = obj[0]; | |
| 629 | + if (subObj != null && subObj.length == 6) { | |
| 630 | + rs.put("polygon", subObj[0]); | |
| 631 | + rs.put("type", subObj[1]); | |
| 632 | + rs.put("cPoint", subObj[2]); | |
| 633 | + rs.put("radius", subObj[3]); | |
| 634 | + rs.put("code", subObj[4]); | |
| 635 | + rs.put("text", subObj[5]); | |
| 636 | + } | |
| 637 | + | |
| 638 | + return rs; | |
| 639 | + } | |
| 640 | + | |
| 641 | + @Override | |
| 642 | + public Map<String, Object> search(Map<String, Object> map, int page, int size, String order, String direction) { | |
| 643 | + Map<String, Object> rsMap = new HashMap<>(); | |
| 644 | + try { | |
| 645 | + //全量 | |
| 646 | + List<GpsEntity> list = new ArrayList<>(gpsRealData.all()); | |
| 647 | + //过滤后的 | |
| 648 | + List<GpsEntity> rs = new ArrayList<>(); | |
| 649 | + Field[] fields = GpsEntity.class.getDeclaredFields(); | |
| 650 | + //参与过滤的字段 | |
| 651 | + List<Field> fs = new ArrayList<>(); | |
| 652 | + for (Field f : fields) { | |
| 653 | + f.setAccessible(true); | |
| 654 | + if (map.containsKey(f.getName())) | |
| 655 | + fs.add(f); | |
| 656 | + } | |
| 657 | + //过滤数据 | |
| 658 | + for (GpsEntity gps : list) { | |
| 659 | + if (fieldEquals(fs, gps, map)) | |
| 660 | + rs.add(gps); | |
| 661 | + } | |
| 662 | + | |
| 663 | + //时间戳排序 | |
| 664 | + Collections.sort(rs, new Comparator<GpsEntity>() { | |
| 665 | + @Override | |
| 666 | + public int compare(GpsEntity o1, GpsEntity o2) { | |
| 667 | + return o2.getTimestamp().intValue() - o1.getTimestamp().intValue(); | |
| 668 | + } | |
| 669 | + }); | |
| 670 | + | |
| 671 | + //分页 | |
| 672 | + int count = rs.size(), s = page * size, e = s + size; | |
| 673 | + if (e > count) | |
| 674 | + e = count; | |
| 675 | + | |
| 676 | + rsMap.put("list", rs.subList(s, e)); | |
| 677 | + rsMap.put("totalPages", count % size == 0 ? count / size - 1 : count / size); | |
| 678 | + rsMap.put("page", page); | |
| 679 | + rsMap.put("status", ResponseCode.SUCCESS); | |
| 680 | + } catch (Exception e) { | |
| 681 | + logger.error("", e); | |
| 682 | + rsMap.put("status", ResponseCode.ERROR); | |
| 683 | + } | |
| 684 | + return rsMap; | |
| 685 | + } | |
| 686 | + | |
| 687 | + @Override | |
| 688 | + public Map<String, Object> removeRealGps(String device) { | |
| 689 | + Map<String, Object> rs = new HashMap<>(); | |
| 690 | + try { | |
| 691 | + | |
| 692 | + gpsRealData.remove(device); | |
| 693 | + GpsCacheData.remove(BasicData.deviceId2NbbmMap.get(device)); | |
| 694 | + rs.put("status", ResponseCode.SUCCESS); | |
| 695 | + } catch (Exception e) { | |
| 696 | + rs.put("status", ResponseCode.ERROR); | |
| 697 | + } | |
| 698 | + return rs; | |
| 699 | + } | |
| 700 | + | |
| 701 | + @Override | |
| 702 | + public Map<String, Object> findRoadSpeed(String lineCode) { | |
| 703 | + Map<String, Object> rs = new HashMap<>(); | |
| 704 | + | |
| 705 | + try { | |
| 706 | + String sql = "select ID, ST_AsText(GROAD_VECTOR) as GROAD_VECTOR,ROAD_CODE,ROAD_NAME,SPEED from bsth_c_road where road_code in(select section_code from bsth_c_sectionroute where line_code=? and destroy=0)"; | |
| 707 | + List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, lineCode); | |
| 708 | + rs.put("status", ResponseCode.SUCCESS); | |
| 709 | + rs.put("roads", list); | |
| 710 | + } catch (DataAccessException e) { | |
| 711 | + logger.error("", e); | |
| 712 | + rs.put("status", ResponseCode.ERROR); | |
| 713 | + } | |
| 714 | + return rs; | |
| 715 | + } | |
| 716 | + | |
| 717 | + /** | |
| 718 | + * gps补全 | |
| 719 | + * | |
| 720 | + * @param schId | |
| 721 | + * @return | |
| 722 | + */ | |
| 723 | + @Override | |
| 724 | + public Map<String, Object> gpsCompletion(long schId, int type) { | |
| 725 | + Map<String, Object> rs = new HashMap<>(); | |
| 726 | + | |
| 727 | + try { | |
| 728 | + ScheduleRealInfo sch = dayOfSchedule.get(schId); | |
| 729 | + if (sch == null) { | |
| 730 | + rs.put("status", ResponseCode.ERROR); | |
| 731 | + rs.put("msg", "找不到对应班次!!!"); | |
| 732 | + return rs; | |
| 733 | + } | |
| 734 | + | |
| 735 | + if (sch.isReissue()) { | |
| 736 | + rs.put("status", ResponseCode.ERROR); | |
| 737 | + rs.put("msg", "你不能重复这个操作"); | |
| 738 | + return rs; | |
| 739 | + } | |
| 740 | + | |
| 741 | + String sql = "select * from bsth_gps_template where line_id='" + sch.getXlBm() + "' and up_down=" + sch.getXlDir(); | |
| 742 | + List<Map<String, Object>> list = jdbcTemplate.queryForList(sql); | |
| 743 | + | |
| 744 | + if (list.size() == 0) { | |
| 745 | + rs.put("status", ResponseCode.ERROR); | |
| 746 | + rs.put("msg", "缺少模板数据,请联系系统管理员!!"); | |
| 747 | + return rs; | |
| 748 | + } | |
| 749 | + //排序 | |
| 750 | + Collections.sort(list, new Comparator<Map<String, Object>>() { | |
| 751 | + @Override | |
| 752 | + public int compare(Map<String, Object> o1, Map<String, Object> o2) { | |
| 753 | + return (int) (Long.parseLong(o1.get("ts").toString()) - Long.parseLong(o2.get("ts").toString())); | |
| 754 | + } | |
| 755 | + }); | |
| 756 | + Map<String, Object> fs = list.get(0); | |
| 757 | + //替换设备号和时间 | |
| 758 | + long diff = ((sch.getDfsjT() - Long.parseLong(fs.get("ts").toString())) - 1000 * 70); | |
| 759 | + | |
| 760 | + String deviceId = BasicData.deviceId2NbbmMap.inverse().get(sch.getClZbh()); | |
| 761 | + int serviceState; | |
| 762 | + for (Map<String, Object> map : list) { | |
| 763 | + map.put("device_id", deviceId); | |
| 764 | + map.put("ts", Long.parseLong(map.get("ts").toString()) + diff); | |
| 765 | + if(type==1){ | |
| 766 | + //走补传协议 | |
| 767 | + serviceState = Integer.parseInt(map.get("service_state").toString()); | |
| 768 | + map.put("service_state", serviceState |= 0x00100000); | |
| 769 | + } | |
| 770 | + } | |
| 771 | + | |
| 772 | + String sqlBefore = "insert into bsth_c_template(", sqlValues = " values("; | |
| 773 | + | |
| 774 | + Set<String> ks = fs.keySet(); | |
| 775 | + for (String k : ks) { | |
| 776 | + sqlBefore += (k + ","); | |
| 777 | + sqlValues += "?,"; | |
| 778 | + } | |
| 779 | + sqlBefore = sqlBefore.substring(0, sqlBefore.length() - 1) + ", create_ts)"; | |
| 780 | + sqlValues = sqlValues.substring(0, sqlValues.length() - 1) + ", " + System.currentTimeMillis() + ")"; | |
| 781 | + sql = sqlBefore + " " + sqlValues; | |
| 782 | + | |
| 783 | + Connection conn = DBUtils_MS.getConnection(); | |
| 784 | + conn.setAutoCommit(false); | |
| 785 | + ps = conn.prepareStatement(sql); | |
| 786 | + int fsize = ks.size(); | |
| 787 | + List<Object> vs; | |
| 788 | + for (Map<String, Object> map : list) { | |
| 789 | + vs = new ArrayList<>(map.values()); | |
| 790 | + for (int i = 0; i < fsize; i++) { | |
| 791 | + ps.setObject(i + 1, vs.get(i)); | |
| 792 | + } | |
| 793 | + ps.addBatch(); | |
| 794 | + } | |
| 795 | + ps.executeBatch(); | |
| 796 | + conn.commit(); | |
| 797 | + | |
| 798 | + rs.put("status", ResponseCode.SUCCESS); | |
| 799 | + | |
| 800 | + //标记班次 | |
| 801 | + sch.setReissue(true); | |
| 802 | + scheduleRealInfoRepository.save(sch); | |
| 803 | + | |
| 804 | + rs.put("status", ResponseCode.SUCCESS); | |
| 805 | + } catch (Exception e) { | |
| 806 | + logger.error("", e); | |
| 807 | + rs.put("status", ResponseCode.ERROR); | |
| 808 | + } | |
| 809 | + return rs; | |
| 810 | + } | |
| 811 | + | |
| 812 | + @Override | |
| 813 | + public Map<String, Object> history_v2(String nbbm, long st, long et) { | |
| 814 | + Map<String, Object> rs = new HashMap<>(); | |
| 815 | + | |
| 816 | + try { | |
| 817 | + //获取历史gps 数据 | |
| 818 | + List<HistoryGps_DTO> list = HistoryGps_DTO.craete((List<Map<String, Object>>) history(new String[]{nbbm}, st, et).get("list")); | |
| 819 | + if (list != null && list.size() > 0) { | |
| 820 | + //获取路段信息 | |
| 821 | + String sql = "select ID, ST_AsText(GROAD_VECTOR) as GROAD_VECTOR,ROAD_CODE,ROAD_NAME,SPEED from bsth_c_road where road_code in(select section_code from bsth_c_sectionroute where line_code=? and destroy=0)"; | |
| 822 | + List<Road_DTO> roads = Road_DTO.craete(jdbcTemplate.queryForList(sql, list.get(0).getLineId())); | |
| 823 | + | |
| 824 | + //为GPS数据关联路段信息 | |
| 825 | + for (HistoryGps_DTO gps : list) { | |
| 826 | + matchRoadToGps(gps, roads); | |
| 827 | + } | |
| 828 | + } | |
| 829 | + | |
| 830 | + //超速数据 | |
| 831 | + List<GpsSpeed_DTO> speedList = speeds(nbbm, st, et); | |
| 832 | + //越界数据 | |
| 833 | + List<GpsOutbound_DTO> outboundList = outbounds(nbbm, st, et); | |
| 834 | + //计算里程 | |
| 835 | + List<HistoryGps_DTO> effList = new ArrayList<>(); | |
| 836 | + for(HistoryGps_DTO gps : list){ | |
| 837 | + if(gps.getLat() != 0 && gps.getLon() != 0) | |
| 838 | + effList.add(gps); | |
| 839 | + } | |
| 840 | + double sum = 0, dist; | |
| 841 | + for (int i = 0; i < effList.size() - 1; i++) { | |
| 842 | + dist = GeoUtils.getDistance(effList.get(i).getPoint(), effList.get(i + 1).getPoint()); | |
| 843 | + //点位相同时,dist会NaN | |
| 844 | + if(String.valueOf(dist).matches("^[0.0-9.0]+$")) | |
| 845 | + sum += dist; | |
| 846 | + } | |
| 847 | + | |
| 848 | + rs.put("status", ResponseCode.SUCCESS); | |
| 849 | + rs.put("list", removeDuplicate(effList)); | |
| 850 | + rs.put("speedList", speedList); | |
| 851 | + rs.put("outboundList", outboundList); | |
| 852 | + rs.put("sumMileage", new DecimalFormat(".##").format(sum / 1000)); | |
| 853 | + } catch (Exception e) { | |
| 854 | + logger.error("", e); | |
| 855 | + rs.put("status", ResponseCode.ERROR); | |
| 856 | + } | |
| 857 | + return rs; | |
| 858 | + } | |
| 859 | + | |
| 860 | + | |
| 861 | + @Override | |
| 862 | + public Map<String, Object> history_v3(String nbbm, long st, long et) { | |
| 863 | + Map<String, Object> rs = new HashMap<>(); | |
| 864 | + | |
| 865 | + try { | |
| 866 | + //获取历史gps 数据 | |
| 867 | + Map<String, Object> gpsMap = history(new String[]{nbbm}, st, et); | |
| 868 | + List<HistoryGps_DTOV3> list = HistoryGps_DTOV3.craete((List<Map<String, Object>>) gpsMap.get("list")); | |
| 869 | + if (list != null && list.size() > 0) { | |
| 870 | + //关联路段名称 | |
| 871 | + Map<String, String> sectionCode2Name = GeoCacheData.sectionCode2NameMap(); | |
| 872 | + for(HistoryGps_DTOV3 gps : list){ | |
| 873 | + if(StringUtils.isNotEmpty(gps.getSection_code())) | |
| 874 | + gps.setSection_name(sectionCode2Name.get(gps.getSection_code())); | |
| 875 | + else{ | |
| 876 | + gps.setSection_code("-00404"); | |
| 877 | + gps.setSection_name("未知路段"); | |
| 878 | + } | |
| 879 | + } | |
| 880 | + } | |
| 881 | + | |
| 882 | + //超速数据 | |
| 883 | + List<GpsSpeed_DTO> speedList = speeds(nbbm, st, et); | |
| 884 | + | |
| 885 | + //越界数据 | |
| 886 | + List<GpsOutbound_DTO> outboundList = outbounds(nbbm, st, et); | |
| 887 | + | |
| 888 | + //计算里程 | |
| 889 | + List<HistoryGps_DTOV3> effList = new ArrayList<>(); | |
| 890 | + for(HistoryGps_DTOV3 gps : list){ | |
| 891 | + if(gps.getLat() != 0 && gps.getLon() != 0) | |
| 892 | + effList.add(gps); | |
| 893 | + } | |
| 894 | + double sum = 0, dist; | |
| 895 | + for (int i = 0; i < effList.size() - 1; i++) { | |
| 896 | + dist = GeoUtils.getDistance(effList.get(i).getPoint(), effList.get(i + 1).getPoint()); | |
| 897 | + //点位相同时,dist会NaN | |
| 898 | + if(String.valueOf(dist).matches("^[0.0-9.0]+$")){ | |
| 899 | + if(dist > 0.8) | |
| 900 | + sum += dist; | |
| 901 | + } | |
| 902 | + } | |
| 903 | + | |
| 904 | + rs.put("status", ResponseCode.SUCCESS); | |
| 905 | + rs.put("list", removeDuplicateV3(effList)); | |
| 906 | + rs.put("speedList", speedList); | |
| 907 | + rs.put("outboundList", outboundList); | |
| 908 | + rs.put("sumMileage", new DecimalFormat(".##").format(sum / 1000)); | |
| 909 | + rs.put("dcs", gpsMap.get("dcs")); | |
| 910 | + rs.put("lineVerson",gpsMap.get("lineVerson")); | |
| 911 | + rs.put("gpsInvalid",gpsMap.get("gpsNotValid")); | |
| 912 | + rs.put("gpslineSwitch",gpsMap.get("lineSwitch")); | |
| 913 | + rs.put("gpslonlatex",gpsMap.get("lonlatZero")); | |
| 914 | + } catch (Exception e) { | |
| 915 | + logger.error("", e); | |
| 916 | + rs.put("status", ResponseCode.ERROR); | |
| 917 | + rs.put("msg", e.getMessage()); | |
| 918 | + } | |
| 919 | + return rs; | |
| 920 | + } | |
| 921 | + | |
| 922 | + @Override | |
| 923 | + public void trailExcel(String nbbm, long st, long et, HttpServletResponse resp) { | |
| 924 | + //获取历史gps 数据 | |
| 925 | + List<HistoryGps_DTOV3> list = HistoryGps_DTOV3.craete((List<Map<String, Object>>) history(new String[]{nbbm}, st, et).get("list")); | |
| 926 | + if (list != null && list.size() > 0) { | |
| 927 | + //关联路段名称 | |
| 928 | + Map<String, String> sectionCode2Name = GeoCacheData.sectionCode2NameMap(); | |
| 929 | + for(HistoryGps_DTOV3 gps : list){ | |
| 930 | + if(StringUtils.isNotEmpty(gps.getSection_code())) | |
| 931 | + gps.setSection_name(sectionCode2Name.get(gps.getSection_code())); | |
| 932 | + else{ | |
| 933 | + gps.setSection_code("-00404"); | |
| 934 | + gps.setSection_name("未知路段"); | |
| 935 | + } | |
| 936 | + } | |
| 937 | + } | |
| 938 | + | |
| 939 | + //创建excel工作簿 | |
| 940 | + Workbook wb = new HSSFWorkbook(); | |
| 941 | + Sheet sheet = wb.createSheet("行车轨迹"); | |
| 942 | + //表头 | |
| 943 | + Row row = sheet.createRow(0); | |
| 944 | + row.setHeight((short) (1.5 * 256)); | |
| 945 | + row.createCell(0).setCellValue("序号"); | |
| 946 | + row.createCell(1).setCellValue("车辆"); | |
| 947 | + row.createCell(2).setCellValue("牌照号"); | |
| 948 | + row.createCell(3).setCellValue("所在道路"); | |
| 949 | + row.createCell(4).setCellValue("经度"); | |
| 950 | + row.createCell(5).setCellValue("纬度"); | |
| 951 | + row.createCell(6).setCellValue("时间"); | |
| 952 | + row.createCell(7).setCellValue("速度"); | |
| 953 | + //数据 | |
| 954 | + DateTimeFormatter fmtHHmmss = DateTimeFormat.forPattern("HH:mm.ss"), | |
| 955 | + fmt = DateTimeFormat.forPattern("yyyyMMddHHmm"); | |
| 956 | + HistoryGps_DTOV3 gps; | |
| 957 | + for(int i = 0; i < list.size(); i ++){ | |
| 958 | + gps = list.get(i); | |
| 959 | + row = sheet.createRow(i + 1); | |
| 960 | + row.createCell(0).setCellValue(i + 1); | |
| 961 | + row.createCell(1).setCellValue(nbbm); | |
| 962 | + row.createCell(2).setCellValue(BasicData.nbbmCompanyPlateMap.get(nbbm)); | |
| 963 | + row.createCell(3).setCellValue(gps.getSection_name()); | |
| 964 | + row.createCell(4).setCellValue(gps.getLon()); | |
| 965 | + row.createCell(5).setCellValue(gps.getLat()); | |
| 966 | + row.createCell(6).setCellValue(fmtHHmmss.print(gps.getTimestamp())); | |
| 967 | + row.createCell(7).setCellValue(gps.getSpeed()); | |
| 968 | + } | |
| 969 | + | |
| 970 | + st = st * 1000; | |
| 971 | + et = et * 1000; | |
| 972 | + String filename = nbbm + "轨迹数据" + fmt.print(st) + "至" + fmt.print(et) + ".xls"; | |
| 973 | + try { | |
| 974 | + resp.setContentType("application/x-msdownload"); | |
| 975 | + resp.addHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8")); | |
| 976 | + | |
| 977 | + OutputStream out=resp.getOutputStream(); | |
| 978 | + wb.write(out); | |
| 979 | + out.flush(); | |
| 980 | + out.close(); | |
| 981 | + } catch (UnsupportedEncodingException e) { | |
| 982 | + logger.error("", e); | |
| 983 | + } catch (IOException e) { | |
| 984 | + logger.error("", e); | |
| 985 | + } | |
| 986 | + } | |
| 987 | + | |
| 988 | + @Override | |
| 989 | + public void abnormalExcel(String nbbm, long st, long et, HttpServletResponse resp) { | |
| 990 | + //超速数据 | |
| 991 | + List<GpsSpeed_DTO> speedList = speeds(nbbm, st, et); | |
| 992 | + //越界数据 | |
| 993 | + List<GpsOutbound_DTO> outboundList = outbounds(nbbm, st, et); | |
| 994 | + | |
| 995 | + //创建excel工作簿 | |
| 996 | + Workbook wb = new HSSFWorkbook(); | |
| 997 | + | |
| 998 | + DateTimeFormatter fmtHHmmss = DateTimeFormat.forPattern("HH:mm.ss"), | |
| 999 | + fmt = DateTimeFormat.forPattern("yyyyMMddHHmm"); | |
| 1000 | + if(speedList.size() > 0){ | |
| 1001 | + Sheet sheet = wb.createSheet("超速"); | |
| 1002 | + //表头 | |
| 1003 | + Row row = sheet.createRow(0); | |
| 1004 | + row.setHeight((short) (1.5 * 256)); | |
| 1005 | + row.createCell(0).setCellValue("异常信息"); | |
| 1006 | + row.createCell(1).setCellValue("最大速度"); | |
| 1007 | + row.createCell(2).setCellValue("开始时间"); | |
| 1008 | + row.createCell(3).setCellValue("结束时间"); | |
| 1009 | + row.createCell(4).setCellValue("持续(秒)"); | |
| 1010 | + row.createCell(5).setCellValue("所在路段"); | |
| 1011 | + | |
| 1012 | + GpsSpeed_DTO speed; | |
| 1013 | + for(int i = 0; i < speedList.size(); i++){ | |
| 1014 | + speed = speedList.get(i); | |
| 1015 | + row = sheet.createRow(i + 1); | |
| 1016 | + row.createCell(0).setCellValue("超速"); | |
| 1017 | + row.createCell(1).setCellValue(speed.getSpeed()); | |
| 1018 | + row.createCell(2).setCellValue(fmtHHmmss.print(speed.getSt())); | |
| 1019 | + row.createCell(3).setCellValue(fmtHHmmss.print(speed.getEt())); | |
| 1020 | + if(speed.getEt() != 0) | |
| 1021 | + row.createCell(4).setCellValue((speed.getEt() - speed.getSt()) / 1000); | |
| 1022 | + row.createCell(5).setCellValue(""); | |
| 1023 | + } | |
| 1024 | + } | |
| 1025 | + | |
| 1026 | + if(outboundList.size() > 0){ | |
| 1027 | + Sheet sheet = wb.createSheet("越界"); | |
| 1028 | + //表头 | |
| 1029 | + Row row = sheet.createRow(0); | |
| 1030 | + row.setHeight((short) (1.5 * 256)); | |
| 1031 | + row.createCell(0).setCellValue("异常信息"); | |
| 1032 | + row.createCell(1).setCellValue("开始时间"); | |
| 1033 | + row.createCell(2).setCellValue("结束时间"); | |
| 1034 | + row.createCell(3).setCellValue("持续(秒)"); | |
| 1035 | + row.createCell(4).setCellValue("所在路段"); | |
| 1036 | + row.createCell(5).setCellValue("路径"); | |
| 1037 | + | |
| 1038 | + GpsOutbound_DTO outbound; | |
| 1039 | + //设置路径单元格 水平对齐 填充 | |
| 1040 | + CellStyle cs = wb.createCellStyle(); | |
| 1041 | + cs.setAlignment(HSSFCellStyle.ALIGN_FILL); | |
| 1042 | + for(int i = 0; i < outboundList.size(); i++){ | |
| 1043 | + outbound = outboundList.get(i); | |
| 1044 | + row = sheet.createRow(i + 1); | |
| 1045 | + row.createCell(0).setCellValue("超速"); | |
| 1046 | + row.createCell(1).setCellValue(fmtHHmmss.print(outbound.getSt())); | |
| 1047 | + row.createCell(2).setCellValue(fmtHHmmss.print(outbound.getEt())); | |
| 1048 | + if(outbound.getEt() != 0) | |
| 1049 | + row.createCell(3).setCellValue((outbound.getEt() - outbound.getSt()) / 1000); | |
| 1050 | + row.createCell(4).setCellValue(""); | |
| 1051 | + row.createCell(5).setCellValue(outbound.getLocations()); | |
| 1052 | + | |
| 1053 | + row.getCell(5).setCellStyle(cs); | |
| 1054 | + } | |
| 1055 | + } | |
| 1056 | + | |
| 1057 | + st = st * 1000; | |
| 1058 | + et = et * 1000; | |
| 1059 | + String filename = nbbm + "异常信息" + fmt.print(st) + "至" + fmt.print(et) + ".xls"; | |
| 1060 | + try { | |
| 1061 | + resp.setContentType("application/x-msdownload"); | |
| 1062 | + resp.addHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8")); | |
| 1063 | + | |
| 1064 | + OutputStream out=resp.getOutputStream(); | |
| 1065 | + wb.write(out); | |
| 1066 | + out.flush(); | |
| 1067 | + out.close(); | |
| 1068 | + } catch (UnsupportedEncodingException e) { | |
| 1069 | + logger.error("", e); | |
| 1070 | + } catch (IOException e) { | |
| 1071 | + logger.error("", e); | |
| 1072 | + } | |
| 1073 | + } | |
| 1074 | + | |
| 1075 | + @Override | |
| 1076 | + public void arrivalExcel(String nbbm, long st, long et, HttpServletResponse resp) { | |
| 1077 | + | |
| 1078 | + } | |
| 1079 | + | |
| 1080 | + @Override | |
| 1081 | + public List<GpsSpeed_DTO> speeds(String nbbm, long st, long et) { | |
| 1082 | + st = st * 1000; | |
| 1083 | + et = et * 1000; | |
| 1084 | + //按周分区 | |
| 1085 | + Calendar sCal = Calendar.getInstance(); | |
| 1086 | + sCal.setTime(new Date(st)); | |
| 1087 | + int sWeekYear = sCal.get(Calendar.WEEK_OF_YEAR); | |
| 1088 | + Calendar eCal = Calendar.getInstance(); | |
| 1089 | + eCal.setTime(new Date(et)); | |
| 1090 | + int eWeekYear = eCal.get(Calendar.WEEK_OF_YEAR); | |
| 1091 | + | |
| 1092 | + //按年分表 | |
| 1093 | + String tableName = "bsth_c_speeding_" + fmtyyyy.print(st); | |
| 1094 | + | |
| 1095 | + List<DeviceChange> dcs = findDeviceChangeLogs(nbbm, et, st); | |
| 1096 | + StringBuilder sql = new StringBuilder(""); | |
| 1097 | + long t1,t2; | |
| 1098 | + DeviceChange dc; | |
| 1099 | + for(int i = 0,len=dcs.size(); i < len; i++){ | |
| 1100 | + t1 = st; | |
| 1101 | + t2 = et; | |
| 1102 | + dc = dcs.get(i); | |
| 1103 | + if(dc.getSt() > st) | |
| 1104 | + t1 = dc.getSt(); | |
| 1105 | + if(dc.getEt() < et && dc.getEt()!=0) | |
| 1106 | + t2 = dc.getEt(); | |
| 1107 | + | |
| 1108 | + sql.append(" select vehicle, line, up_down, lon, lat, speed,timestamp from "+tableName+" where " + | |
| 1109 | + " weeks_year in ("+sWeekYear+", "+eWeekYear+") and vehicle='"+dc.getDevice()+"' and timestamp>="+t1+" and timestamp<= " + t2); | |
| 1110 | + | |
| 1111 | + if(i == len - 1) | |
| 1112 | + sql.append(" ORDER BY vehicle,timestamp"); | |
| 1113 | + else | |
| 1114 | + sql.append(" UNION "); | |
| 1115 | + } | |
| 1116 | + | |
| 1117 | + logger.info("speed sql : " + sql.toString()); | |
| 1118 | + return GpsSpeed_DTO.create(new JdbcTemplate(DBUtils_MS.getDataSource()).queryForList(sql.toString())); | |
| 1119 | + } | |
| 1120 | + | |
| 1121 | + @Override | |
| 1122 | + public List<GpsOutbound_DTO> outbounds(String nbbm, long st, long et) { | |
| 1123 | + st = st * 1000; | |
| 1124 | + et = et * 1000; | |
| 1125 | + //按周分区 | |
| 1126 | + Calendar sCal = Calendar.getInstance(); | |
| 1127 | + sCal.setTime(new Date(st)); | |
| 1128 | + int sWeekYear = sCal.get(Calendar.WEEK_OF_YEAR); | |
| 1129 | + Calendar eCal = Calendar.getInstance(); | |
| 1130 | + eCal.setTime(new Date(et)); | |
| 1131 | + int eWeekYear = eCal.get(Calendar.WEEK_OF_YEAR); | |
| 1132 | + | |
| 1133 | + //按年分表 | |
| 1134 | + String tableName = "bsth_c_outbound_" + fmtyyyy.print(st); | |
| 1135 | + | |
| 1136 | + List<DeviceChange> dcs = findDeviceChangeLogs(nbbm, et, st); | |
| 1137 | + StringBuilder sql = new StringBuilder(""); | |
| 1138 | + long t1,t2; | |
| 1139 | + DeviceChange dc; | |
| 1140 | + for(int i = 0,len=dcs.size(); i < len; i++){ | |
| 1141 | + t1 = st; | |
| 1142 | + t2 = et; | |
| 1143 | + dc = dcs.get(i); | |
| 1144 | + if(dc.getSt() > st) | |
| 1145 | + t1 = dc.getSt(); | |
| 1146 | + if(dc.getEt() < et && dc.getEt()!=0) | |
| 1147 | + t2 = dc.getEt(); | |
| 1148 | + | |
| 1149 | + sql.append("select vehicle,line,up_down,lon,lat,timestamp from "+tableName+" where " + | |
| 1150 | + " weeks_year in ("+sWeekYear+", "+eWeekYear+") and vehicle='"+dc.getDevice()+"' and timestamp>="+t1+" and timestamp<=" + t2); | |
| 1151 | + | |
| 1152 | + if(i == len - 1) | |
| 1153 | + sql.append(" ORDER BY vehicle,timestamp"); | |
| 1154 | + else | |
| 1155 | + sql.append(" UNION "); | |
| 1156 | + } | |
| 1157 | + | |
| 1158 | + logger.info("outbounds sql : " + sql.toString()); | |
| 1159 | + return GpsOutbound_DTO.create(new JdbcTemplate(DBUtils_MS.getDataSource()).queryForList(sql.toString())); | |
| 1160 | + } | |
| 1161 | + | |
| 1162 | + @Override | |
| 1163 | + public Map<String, Object> safeDrivList(Map<String, Object> map, int page, int size, String order, String direction) { | |
| 1164 | + Map<String, Object> rsMap = new HashMap<>(); | |
| 1165 | + try { | |
| 1166 | + //全量 | |
| 1167 | + List<SafeDriv> list = new ArrayList<>(SafeDrivCenter.findAll()); | |
| 1168 | + //过滤后的 | |
| 1169 | + List<SafeDriv> rs = new ArrayList<>(); | |
| 1170 | + Field[] fields = SafeDriv.class.getDeclaredFields(); | |
| 1171 | + //参与过滤的字段 | |
| 1172 | + List<Field> fs = new ArrayList<>(); | |
| 1173 | + for (Field f : fields) { | |
| 1174 | + f.setAccessible(true); | |
| 1175 | + if (map.containsKey(f.getName())) | |
| 1176 | + fs.add(f); | |
| 1177 | + } | |
| 1178 | + //过滤数据 | |
| 1179 | + for (SafeDriv sd : list) { | |
| 1180 | + if (isSpecialLines(sd, map) && fieldEqualstow(fs, sd, map)) | |
| 1181 | + rs.add(sd); | |
| 1182 | + } | |
| 1183 | + | |
| 1184 | + //时间戳排序 | |
| 1185 | + Collections.sort(rs, new Comparator<SafeDriv>() { | |
| 1186 | + @Override | |
| 1187 | + public int compare(SafeDriv o1, SafeDriv o2) { | |
| 1188 | + return o2.getTs().intValue() - o1.getTs().intValue(); | |
| 1189 | + } | |
| 1190 | + }); | |
| 1191 | + | |
| 1192 | + //分页 | |
| 1193 | + int count = rs.size(), s = page * size, e = s + size; | |
| 1194 | + if (e > count) | |
| 1195 | + e = count; | |
| 1196 | + | |
| 1197 | + rsMap.put("list", rs.subList(s, e)); | |
| 1198 | + rsMap.put("totalPages", count % size == 0 ? count / size - 1 : count / size); | |
| 1199 | + rsMap.put("page", page); | |
| 1200 | + rsMap.put("status", ResponseCode.SUCCESS); | |
| 1201 | + } catch (Exception e) { | |
| 1202 | + logger.error("", e); | |
| 1203 | + rsMap.put("status", ResponseCode.ERROR); | |
| 1204 | + } | |
| 1205 | + return rsMap; | |
| 1206 | + } | |
| 1207 | + | |
| 1208 | + private void matchRoadToGps(HistoryGps_DTO gps, List<Road_DTO> roads) { | |
| 1209 | + double min = -1, distance; | |
| 1210 | + Road_DTO nearRoad = null; | |
| 1211 | + for (Road_DTO road : roads) { | |
| 1212 | + distance = GeoUtils.getDistanceFromLine(road.getLineStr(), gps.getPoint()); | |
| 1213 | + | |
| 1214 | + if (min > distance || min == -1) { | |
| 1215 | + min = distance; | |
| 1216 | + nearRoad = road; | |
| 1217 | + } | |
| 1218 | + } | |
| 1219 | + | |
| 1220 | + gps.setRoad(nearRoad); | |
| 1221 | + gps.setRoadMinDistance(min); | |
| 1222 | + } | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + private void matchRoadToGps(HistoryGps_DTOV3 gps, List<Road_DTO> roads) { | |
| 1226 | + double min = -1, distance; | |
| 1227 | + Road_DTO nearRoad = null; | |
| 1228 | + for (Road_DTO road : roads) { | |
| 1229 | + distance = GeoUtils.getDistanceFromLine(road.getLineStr(), gps.getPoint()); | |
| 1230 | + | |
| 1231 | + if (min > distance || min == -1) { | |
| 1232 | + min = distance; | |
| 1233 | + nearRoad = road; | |
| 1234 | + } | |
| 1235 | + } | |
| 1236 | + | |
| 1237 | + if(min < 200){ | |
| 1238 | + gps.setSection_code(nearRoad.getROAD_CODE()); | |
| 1239 | + gps.setSection_name(nearRoad.getROAD_NAME()); | |
| 1240 | + } | |
| 1241 | + else { | |
| 1242 | + gps.setSection_code("-00404"); | |
| 1243 | + gps.setSection_name("未知路段"); | |
| 1244 | + } | |
| 1245 | + //gps.setRoad(nearRoad); | |
| 1246 | + //gps.setRoadMinDistance(min); | |
| 1247 | + } | |
| 1248 | + | |
| 1249 | + /** | |
| 1250 | + * 去重复 | |
| 1251 | + * | |
| 1252 | + * @param list | |
| 1253 | + * @return | |
| 1254 | + */ | |
| 1255 | + private Set<HistoryGps_DTO> removeDuplicate(List<HistoryGps_DTO> list) { | |
| 1256 | + Set<HistoryGps_DTO> set = new HashSet<>(); | |
| 1257 | + for (HistoryGps_DTO gps : list) { | |
| 1258 | + set.add(gps); | |
| 1259 | + } | |
| 1260 | + return set; | |
| 1261 | + } | |
| 1262 | + | |
| 1263 | + /** | |
| 1264 | + * 去重复 | |
| 1265 | + * | |
| 1266 | + * @param list | |
| 1267 | + * @return | |
| 1268 | + */ | |
| 1269 | + private Set<HistoryGps_DTOV3> removeDuplicateV3(List<HistoryGps_DTOV3> list) { | |
| 1270 | + Set<HistoryGps_DTOV3> set = new HashSet<>(); | |
| 1271 | + for (HistoryGps_DTOV3 gps : list) { | |
| 1272 | + set.add(gps); | |
| 1273 | + } | |
| 1274 | + return set; | |
| 1275 | + } | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + private void sortGpsList(final Field f, List<GpsEntity> rs) { | |
| 1279 | + Collections.sort(rs, new Comparator<GpsEntity>() { | |
| 1280 | + | |
| 1281 | + @Override | |
| 1282 | + public int compare(GpsEntity o1, GpsEntity o2) { | |
| 1283 | + try { | |
| 1284 | + if (f.get(o1) == f.get(o2)) | |
| 1285 | + return 0; | |
| 1286 | + | |
| 1287 | + if (null == f.get(o1)) | |
| 1288 | + return 1; | |
| 1289 | + | |
| 1290 | + if (null == f.get(o2)) | |
| 1291 | + return -1; | |
| 1292 | + | |
| 1293 | + return f.get(o1).toString().compareTo(f.get(o2).toString()); | |
| 1294 | + } catch (Exception e) { | |
| 1295 | + logger.error("", e); | |
| 1296 | + return -1; | |
| 1297 | + } | |
| 1298 | + } | |
| 1299 | + }); | |
| 1300 | + } | |
| 1301 | + | |
| 1302 | + /** | |
| 1303 | + * | |
| 1304 | + * @param sd | |
| 1305 | + * @param map | |
| 1306 | + * @return | |
| 1307 | + */ | |
| 1308 | + public boolean isSpecialLines(SafeDriv sd, Map<String, Object> map) { | |
| 1309 | + String lines = (String)map.get("lines"); | |
| 1310 | + if (lines == null) lines = ""; | |
| 1311 | + | |
| 1312 | + if (Arrays.asList(lines.split(",")).contains(sd.getXlbm())) return true; | |
| 1313 | + return false; | |
| 1314 | + } | |
| 1315 | + | |
| 1316 | + public boolean fieldEquals(List<Field> fs, Object obj, Map<String, Object> map) { | |
| 1317 | + try { | |
| 1318 | + String fv, v; | |
| 1319 | + for (Field f : fs) { | |
| 1320 | + if (StringUtils.isEmpty(map.get(f.getName()).toString())) | |
| 1321 | + continue; | |
| 1322 | + | |
| 1323 | + if(f.get(obj) == null) | |
| 1324 | + return false; | |
| 1325 | + | |
| 1326 | + fv = f.get(obj).toString(); | |
| 1327 | + v = map.get(f.getName()).toString(); | |
| 1328 | + | |
| 1329 | + if(!fv.startsWith(v)/* && !fv.endsWith(v)*/) | |
| 1330 | + return false; | |
| 1331 | + } | |
| 1332 | + } catch (Exception e) { | |
| 1333 | + logger.error("", e); | |
| 1334 | + return false; | |
| 1335 | + } | |
| 1336 | + return true; | |
| 1337 | + } | |
| 1338 | + | |
| 1339 | + public boolean fieldEqualstow(List<Field> fs, Object obj, Map<String, Object> map) { | |
| 1340 | + try { | |
| 1341 | + String fv, v; | |
| 1342 | + for (Field f : fs) { | |
| 1343 | + if (StringUtils.isEmpty(map.get(f.getName()).toString())) | |
| 1344 | + continue; | |
| 1345 | + | |
| 1346 | + if(f.get(obj) == null) | |
| 1347 | + return false; | |
| 1348 | + | |
| 1349 | + fv = f.get(obj).toString(); | |
| 1350 | + v = map.get(f.getName()).toString(); | |
| 1351 | + SafeDriv sd = (SafeDriv) obj; | |
| 1352 | + if(v.equals(sd.getJctype())) | |
| 1353 | + return true; | |
| 1354 | + else if(!fv.startsWith(v)/* && !fv.endsWith(v)*/) | |
| 1355 | + return false; | |
| 1356 | + } | |
| 1357 | + } catch (Exception e) { | |
| 1358 | + logger.error("", e); | |
| 1359 | + return false; | |
| 1360 | + } | |
| 1361 | + return true; | |
| 1362 | + } | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + @Override | |
| 1366 | + public List<GpsSpeed> findPosition(String deviceid, String startdate, | |
| 1367 | + String enddate) throws ParseException{ | |
| 1368 | + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 1369 | + Calendar c = Calendar.getInstance(); | |
| 1370 | + Date date = sdf.parse(startdate); | |
| 1371 | + c.setTime(date); | |
| 1372 | + int daysYear = c.get(Calendar.DAY_OF_YEAR);//获取当前是今年的第几天。 | |
| 1373 | + | |
| 1374 | + long startTime = sdf.parse(startdate).getTime(); | |
| 1375 | + long endTime = sdf.parse(enddate).getTime(); | |
| 1376 | + | |
| 1377 | + String sql = "select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE ,speed_gps from bsth_c_gps_info where days_year=? and device_id=? and ts >= ? and ts <= ?" + | |
| 1378 | + " ORDER BY TS "; | |
| 1379 | + Connection conn = null; | |
| 1380 | + PreparedStatement ps = null; | |
| 1381 | + ResultSet rs = null; | |
| 1382 | + List<GpsSpeed> listResult = new ArrayList<GpsSpeed>(); | |
| 1383 | + GpsSpeed gpsSpeed = null; | |
| 1384 | + try { | |
| 1385 | + conn = DBUtils_MS.getConnection(); | |
| 1386 | + ps = conn.prepareStatement(sql); | |
| 1387 | + ps.setInt(1, daysYear); | |
| 1388 | + ps.setString(2, deviceid); | |
| 1389 | + ps.setLong(3,startTime); | |
| 1390 | + ps.setLong(4,endTime); | |
| 1391 | + rs = ps.executeQuery(); | |
| 1392 | + Float lon, lat; | |
| 1393 | + Location location; | |
| 1394 | + while (rs.next()) { | |
| 1395 | + gpsSpeed = new GpsSpeed(); | |
| 1396 | + // to 百度坐标 | |
| 1397 | + lon = rs.getFloat("LON"); | |
| 1398 | + lat = rs.getFloat("LAT"); | |
| 1399 | + location = TransGPS.LocationMake(lon, lat); | |
| 1400 | + location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location)); | |
| 1401 | + gpsSpeed.setVehicle(rs.getString("device_id")); | |
| 1402 | + gpsSpeed.setLon((float)location.getLng()); | |
| 1403 | + gpsSpeed.setLat((float)location.getLat()); | |
| 1404 | + gpsSpeed.setSpeed(rs.getFloat("speed_gps")); | |
| 1405 | + gpsSpeed.setTimestamp(rs.getLong("TS")); | |
| 1406 | + // 上下行 | |
| 1407 | + listResult.add(gpsSpeed); | |
| 1408 | + } | |
| 1409 | + } catch (Exception e) { | |
| 1410 | + e.printStackTrace(); | |
| 1411 | + } finally { | |
| 1412 | + DBUtils_MS.close(rs, ps, conn); | |
| 1413 | + } | |
| 1414 | + return listResult; | |
| 1415 | + | |
| 1416 | + } | |
| 1417 | + | |
| 1418 | + @Override | |
| 1419 | + public Map<String, Object> Pagequery(Map<String, Object> map) { | |
| 1420 | + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 1421 | + Integer totalDays = 0;//数据跨越天数 | |
| 1422 | + try { | |
| 1423 | + totalDays = (int) ((sdf.parse(map.get("endDate").toString()+" 23:59:59").getTime()-sdf.parse(map.get("startDate").toString()+" 00:00:00").getTime()+1)/(3600*24*1000))+1; | |
| 1424 | + } catch (ParseException e) { | |
| 1425 | + e.printStackTrace(); | |
| 1426 | + }//总页数 | |
| 1427 | + map.put("totalDays",totalDays); | |
| 1428 | + List<GpsSpeed> list=findAll(map); | |
| 1429 | + List<GpsSpeed> listResult = new ArrayList<GpsSpeed>(); | |
| 1430 | + int curPage = 0;//页码 | |
| 1431 | + int pageData = 0;//每页的记录条数 | |
| 1432 | + if(list.size()>1){ | |
| 1433 | + GpsSpeed GpsSpeedNow;//下标为i的车辆行驶记录 | |
| 1434 | + GpsSpeed GpsSpeedLast;//下标为i-1的车辆行驶记录 | |
| 1435 | + GpsSpeed spped = null;//整合后的车辆行驶记录 | |
| 1436 | + String strNow; | |
| 1437 | + String strLast; | |
| 1438 | + boolean Flag = false;//判断是否有连续超速记录,默认没有 | |
| 1439 | + for(int i = 1;i<list.size();i++){ | |
| 1440 | + GpsSpeedNow = list.get(i); | |
| 1441 | + GpsSpeedLast = list.get(i-1); | |
| 1442 | + strNow = GpsSpeedNow.getVehicle()+GpsSpeedNow.getLine()+GpsSpeedNow.getUp_down(); | |
| 1443 | + strLast = GpsSpeedLast.getVehicle()+GpsSpeedLast.getLine()+GpsSpeedLast.getUp_down(); | |
| 1444 | + if(GpsSpeedNow.getSpeed()>60 && GpsSpeedLast.getSpeed()>60 && strNow.equals(strLast)){//如果两条连续的记录都是超速且属于同一辆车。 | |
| 1445 | + if(Flag==false){// | |
| 1446 | + spped = new GpsSpeed(); | |
| 1447 | + spped.setLine(GpsSpeedLast.getLine());//设置连续超速记录线路 | |
| 1448 | + spped.setLineName(GpsSpeedLast.getLineName());//设置连续超速记录线路名称 | |
| 1449 | + spped.setVehicle(GpsSpeedLast.getVehicle());//设置连续超速记录的车辆编号 | |
| 1450 | + spped.setUp_down(GpsSpeedLast.getUp_down());//设置上下行 | |
| 1451 | + spped.setLon(GpsSpeedLast.getLon());//设置开始时经度 | |
| 1452 | + spped.setLat(GpsSpeedLast.getLat());//设置开始时纬度 | |
| 1453 | + spped.setTimestamp(GpsSpeedLast.getTimestamp());//设置连续超速记录的开始时间 | |
| 1454 | + spped.setTimestampDate(GpsSpeedLast.getTimestampDate());//设置连续超速记录的开始时间戳 | |
| 1455 | + } | |
| 1456 | + spped.setEndtimestamp(GpsSpeedNow.getTimestamp());//设置结束时间戳 | |
| 1457 | + spped.setEndtimestampDate(sdf.format(new Date(GpsSpeedNow.getTimestamp())));//设置结束时间 | |
| 1458 | + spped.setEndlon(GpsSpeedNow.getLon());//设置结束时的经度 | |
| 1459 | + spped.setEndlat(GpsSpeedNow.getLat());//设置结束时的纬度 | |
| 1460 | + Flag = true; | |
| 1461 | + }else{ | |
| 1462 | + if(Flag){//如果上一条记录超速。 | |
| 1463 | + listResult.add(spped); | |
| 1464 | + Flag = false; | |
| 1465 | + } | |
| 1466 | + } | |
| 1467 | + } | |
| 1468 | + if(listResult.size()>0){ | |
| 1469 | + Iterator<GpsSpeed> speedIt = listResult.iterator(); | |
| 1470 | + while(speedIt.hasNext()){ | |
| 1471 | + GpsSpeed GpsSpeed = speedIt.next(); | |
| 1472 | + if(GpsSpeed.getEndtimestamp()-GpsSpeed.getTimestamp()<=1000){ | |
| 1473 | + speedIt.remove(); | |
| 1474 | + } | |
| 1475 | + } | |
| 1476 | + } | |
| 1477 | + } | |
| 1478 | + if(map.get("curPage") == null || map.get("curPage").equals("0")){ | |
| 1479 | + curPage = 0; | |
| 1480 | + }else{ | |
| 1481 | + curPage = Integer.parseInt((String) map.get("curPage")); | |
| 1482 | + } | |
| 1483 | + Integer totalPage = totalDays; | |
| 1484 | + pageData = listResult.size();//每页的记录条数就是当前页查出的全部数据。 | |
| 1485 | + Map<String,Object> paramMap = new HashMap<String,Object>(); | |
| 1486 | + paramMap.put("totalPage", totalPage); | |
| 1487 | + paramMap.put("page", curPage); | |
| 1488 | + paramMap.put("pageData", pageData); | |
| 1489 | + paramMap.put("list", listResult); | |
| 1490 | + return paramMap; | |
| 1491 | + } | |
| 1492 | + | |
| 1493 | + @Override | |
| 1494 | + public Map<String, Object> allCarsByLine(String lineCode) { | |
| 1495 | + Map<String, Object> map = new HashMap(); | |
| 1496 | + try{ | |
| 1497 | + List<Map<String, Object>> list = new ArrayList<>(); | |
| 1498 | + Map<String, Object> item; | |
| 1499 | + GpsEntity gps; | |
| 1500 | + //当天线路下营运的车辆 | |
| 1501 | + Set<String> cars = dayOfSchedule.findCarByLineCode(lineCode); | |
| 1502 | + ScheduleRealInfo sch; | |
| 1503 | + String device; | |
| 1504 | + | |
| 1505 | + Map<String, Integer> allDevices = new HashMap<>(); | |
| 1506 | + String execStr = ""; | |
| 1507 | + D80 d80; | |
| 1508 | + for(String nbbm : cars){ | |
| 1509 | + item = new HashMap<>(); | |
| 1510 | + device = BasicData.deviceId2NbbmMap.inverse().get(nbbm); | |
| 1511 | + allDevices.put(device, 1); | |
| 1512 | + item.put("nbbm", nbbm); | |
| 1513 | + item.put("device", device); | |
| 1514 | + | |
| 1515 | + sch = dayOfSchedule.executeCurr(nbbm); | |
| 1516 | + if(null != sch){ | |
| 1517 | + execStr = (sch.getXlDir().equals("0")?"上行":"下行") + "("+sch.getDfsj()+")"; | |
| 1518 | + if(!sch.getXlBm().equals(lineCode)) | |
| 1519 | + execStr = sch.getXlName()+execStr; | |
| 1520 | + else | |
| 1521 | + item.put("schId", sch.getId()); | |
| 1522 | + item.put("exec", execStr); | |
| 1523 | + } | |
| 1524 | + | |
| 1525 | + gps = gpsRealData.get(device); | |
| 1526 | + if(null != gps){ | |
| 1527 | + item.put("loc", gps.getStationName()); | |
| 1528 | + item.put("lineCodeReal", gps.getLineId()); | |
| 1529 | + item.put("status", gps.isOffline()?"离线":"在线"); | |
| 1530 | + item.put("gpsTs", gps.getTimestamp()); | |
| 1531 | + } | |
| 1532 | + //请求出场时间 | |
| 1533 | + d80 = PilotReport.qqccMap.get(device); | |
| 1534 | + if(null != d80) | |
| 1535 | + item.put("qqcc", d80.getTimestamp()); | |
| 1536 | + | |
| 1537 | + list.add(item); | |
| 1538 | + } | |
| 1539 | + | |
| 1540 | + //车载编码落在该线路的设备 | |
| 1541 | + Set<String> devices = gpsRealData.findDevices(lineCode); | |
| 1542 | + for(String d : devices){ | |
| 1543 | + if(allDevices.containsKey(d)) | |
| 1544 | + continue; | |
| 1545 | + | |
| 1546 | + gps = gpsRealData.get(d); | |
| 1547 | + if(null == gps) | |
| 1548 | + continue; | |
| 1549 | + | |
| 1550 | + item = new HashMap<>(); | |
| 1551 | + item.put("nbbm", gps.getNbbm()); | |
| 1552 | + item.put("device", d); | |
| 1553 | + item.put("loc", gps.getStationName()); | |
| 1554 | + item.put("lineCodeReal", gps.getLineId()); | |
| 1555 | + item.put("status", gps.isOffline()?"离线":"在线"); | |
| 1556 | + item.put("gpsTs", gps.getTimestamp()); | |
| 1557 | + | |
| 1558 | + //请求出场时间 | |
| 1559 | + d80 = PilotReport.qqccMap.get(d); | |
| 1560 | + if(null != d80) | |
| 1561 | + item.put("qqcc", d80.getTimestamp()); | |
| 1562 | + | |
| 1563 | + list.add(item); | |
| 1564 | + } | |
| 1565 | + | |
| 1566 | + map.put("list", list); | |
| 1567 | + map.put("status", ResponseCode.SUCCESS); | |
| 1568 | + }catch (Exception e){ | |
| 1569 | + logger.error("", e); | |
| 1570 | + map.put("status", ResponseCode.ERROR); | |
| 1571 | + map.put("msg", e.getMessage()); | |
| 1572 | + } | |
| 1573 | + return map; | |
| 1574 | + } | |
| 1575 | + | |
| 1576 | + static List<GpsSpeed> findAll(Map<String, Object> map) { | |
| 1577 | + Connection conn = null; | |
| 1578 | + PreparedStatement ps = null; | |
| 1579 | + ResultSet rs = null; | |
| 1580 | + List<GpsSpeed> list=new ArrayList<GpsSpeed>(); | |
| 1581 | + String sql="select * from bsth_c_gps_info where 1=1 "; | |
| 1582 | + Object line=map.get("line"); | |
| 1583 | + Object nbbm=map.get("nbbm"); | |
| 1584 | + Object updown=map.get("updown"); | |
| 1585 | + Object startDate=map.get("startDate"); | |
| 1586 | + Object endDate=map.get("endDate"); | |
| 1587 | + Integer totalDays = Integer.valueOf(map.get("totalDays").toString()); | |
| 1588 | + Integer curPage = 0;//页码 | |
| 1589 | + if(map.get("curPage") == null || map.get("curPage").equals("0")){ | |
| 1590 | + curPage = 0; | |
| 1591 | + }else{ | |
| 1592 | + curPage = Integer.parseInt((String) map.get("curPage")); | |
| 1593 | + } | |
| 1594 | + | |
| 1595 | + SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 1596 | + if(line!=null){ | |
| 1597 | + sql +=" and line_id like'%"+line.toString().trim()+"%'"; | |
| 1598 | + } | |
| 1599 | + | |
| 1600 | + if(nbbm!=null){ | |
| 1601 | + nbbm=BasicData.deviceId2NbbmMap.inverse().get(nbbm); | |
| 1602 | + if(nbbm!=null) | |
| 1603 | + sql +=" and vehicle like '%"+nbbm.toString()+"%'"; | |
| 1604 | + } | |
| 1605 | + | |
| 1606 | + if(updown!=null){ | |
| 1607 | + sql +="and industry_code like '%"+updown.toString()+"%'"; | |
| 1608 | + } | |
| 1609 | + if(startDate!=null){ | |
| 1610 | + if (startDate.toString().length()>0) { | |
| 1611 | + try { | |
| 1612 | + Long t1=sdf.parse(startDate.toString()+" 00:00:00").getTime()+curPage*3600*24*1000; | |
| 1613 | + sql += " and ts >="+t1; | |
| 1614 | + } catch (ParseException e) { | |
| 1615 | + e.printStackTrace(); | |
| 1616 | + } | |
| 1617 | + } | |
| 1618 | + | |
| 1619 | + } | |
| 1620 | + if(endDate!=null){ | |
| 1621 | + if (endDate.toString().length()>0) { | |
| 1622 | + try { | |
| 1623 | + Long t2=sdf.parse(endDate.toString()+" 23:59:59").getTime()-(totalDays-1-curPage)*3600*24*1000; | |
| 1624 | + sql += " and ts <="+t2; | |
| 1625 | + } catch (ParseException e) { | |
| 1626 | + e.printStackTrace(); | |
| 1627 | + } | |
| 1628 | + } | |
| 1629 | + | |
| 1630 | + } | |
| 1631 | + | |
| 1632 | + try { | |
| 1633 | + conn = DBUtils_MS.getConnection(); | |
| 1634 | + ps = conn.prepareStatement(sql); | |
| 1635 | + rs = ps.executeQuery(); | |
| 1636 | + list = resultSet2Set(rs); | |
| 1637 | + } catch (SQLException e) { | |
| 1638 | + e.printStackTrace(); | |
| 1639 | + }finally { | |
| 1640 | + DBUtils_MS.close(rs, ps, conn); | |
| 1641 | + } | |
| 1642 | + | |
| 1643 | + return list; | |
| 1644 | + } | |
| 1645 | + | |
| 1646 | + static List<GpsSpeed> resultSet2Set(ResultSet rs) throws SQLException{ | |
| 1647 | + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 1648 | + List<GpsSpeed> list=new ArrayList<GpsSpeed>(); | |
| 1649 | + GpsSpeed GpsSpeed; | |
| 1650 | + Float lon, lat; | |
| 1651 | + Location location; | |
| 1652 | + while(rs.next()){ | |
| 1653 | + lon = rs.getFloat("lon"); | |
| 1654 | + lat = rs.getFloat("lat"); | |
| 1655 | + location = TransGPS.LocationMake(lon, lat); | |
| 1656 | + location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location)); | |
| 1657 | + GpsSpeed=new GpsSpeed(); | |
| 1658 | + GpsSpeed.setLon((float)location.getLng()); | |
| 1659 | + GpsSpeed.setLat((float)location.getLat()); | |
| 1660 | + GpsSpeed.setLine(rs.getObject("line_id").toString()); | |
| 1661 | + //run 时注解 | |
| 1662 | + GpsSpeed.setLineName(BasicData.lineCode2NameMap.get(GpsSpeed.getLine().toString())); | |
| 1663 | + GpsSpeed.setSpeed(Float.valueOf(rs.getObject("speed_gps").toString())); | |
| 1664 | + GpsSpeed.setTimestamp((Long.valueOf(rs.getObject("ts").toString()))); | |
| 1665 | + GpsSpeed.setTimestampDate(sdf.format(new Date(GpsSpeed.getTimestamp()))); | |
| 1666 | + GpsSpeed.setUp_down(((Integer.valueOf(rs.getObject("service_state").toString())) & 0x10000000)==0?0:1); | |
| 1667 | + GpsSpeed.setVehicle(BasicData.deviceId2NbbmMap.get(rs.getObject("device_id").toString())); | |
| 1668 | + list.add(GpsSpeed); | |
| 1669 | + } | |
| 1670 | + return list; | |
| 1671 | + } | |
| 1672 | + | |
| 1673 | +} | |
| 1674 | + | ... | ... |
src/main/java/com/bsth/websocket/handler/SendUtils.java
| ... | ... | @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; |
| 4 | 4 | import com.bsth.data.BasicData; |
| 5 | 5 | import com.bsth.data.LineConfigData; |
| 6 | 6 | import com.bsth.data.gpsdata_v2.entity.GpsEntity; |
| 7 | +import com.bsth.data.maintenance_plan.MaintenancePlan; | |
| 7 | 8 | import com.bsth.data.safe_driv.SafeDriv; |
| 8 | 9 | import com.bsth.entity.directive.D80; |
| 9 | 10 | import com.bsth.entity.realcontrol.ScheduleRealInfo; |
| ... | ... | @@ -249,4 +250,20 @@ public class SendUtils{ |
| 249 | 250 | logger.error("sendContingencyPlan", e); |
| 250 | 251 | } |
| 251 | 252 | } |
| 253 | + | |
| 254 | + /** | |
| 255 | + * 将维修保养计划发送至线调页面 | |
| 256 | + */ | |
| 257 | + public void sendMaintenancePlan(MaintenancePlan maintenancePlan) { | |
| 258 | + Map<String, Object> map = new HashMap<>(); | |
| 259 | + map.put("fn", "maintenancePlan"); | |
| 260 | + map.put("data", maintenancePlan); | |
| 261 | + ObjectMapper mapper = new ObjectMapper(); | |
| 262 | + | |
| 263 | + try { | |
| 264 | + socketHandler.sendMessageToLine(maintenancePlan.getLine(), mapper.writeValueAsString(map)); | |
| 265 | + } catch (JsonProcessingException e) { | |
| 266 | + logger.error("sendMaintenancePlan", e); | |
| 267 | + } | |
| 268 | + } | |
| 252 | 269 | } | ... | ... |
src/main/resources/application-prod.properties
| ... | ... | @@ -49,6 +49,7 @@ http.report.url.26= http://116.236.141.34:8088/nhjwsystem_j2ee/clbx/clbx_dd.do |
| 49 | 49 | http.report.url.55= http://180.168.216.248:8088/snjwsystem_j2ee/clbx/clbx_dd.do |
| 50 | 50 | ## http ticketing interface |
| 51 | 51 | http.ticketing.interface= http://112.64.187.3:1080/gjService/request |
| 52 | +http.mtplan.interface= https://112.64.45.51/wxk-prod-api/service-api/pdgj/schedule/byinfo | |
| 52 | 53 | ## first last generate |
| 53 | 54 | ms.fl.generate=true |
| 54 | 55 | ## dsm ack interface | ... | ... |
src/main/resources/static/real_control_v2/fragments/multi_plat_msg/mt_plan_modal.html
0 → 100644
| 1 | +<div class="uk-modal ct-form-modal" id="mt_plan_modal"> | |
| 2 | + <div class="uk-modal-dialog"> | |
| 3 | + <a href="" class="uk-modal-close uk-close"></a> | |
| 4 | + <h2>维修保养计划</h2> | |
| 5 | + | |
| 6 | + <div class="mt_plan_info"> | |
| 7 | + <form class="uk-form uk-form-horizontal"> | |
| 8 | + | |
| 9 | + <!--<div class="uk-form-row"> | |
| 10 | + <label class="uk-form-label" for="form-h-line">线路</label> | |
| 11 | + <div class="uk-form-controls"> | |
| 12 | + <input name="line" type="text" id="form-h-line" disabled autocomplete="off"> | |
| 13 | + </div> | |
| 14 | + </div>--> | |
| 15 | + <div class="uk-form-row"> | |
| 16 | + <label class="uk-form-label" for="form-h-zbh">车辆编码</label> | |
| 17 | + <div class="uk-form-controls"> | |
| 18 | + <input name="zbh" type="text" id="form-h-zbh" disabled autocomplete="off"> | |
| 19 | + </div> | |
| 20 | + </div> | |
| 21 | + <div class="uk-form-row"> | |
| 22 | + <label class="uk-form-label" for="form-h-bydj">保养等级</label> | |
| 23 | + <div class="uk-form-controls"> | |
| 24 | + <input name="bydj" type="text" id="form-h-bydj" disabled autocomplete="off"> | |
| 25 | + </div> | |
| 26 | + </div> | |
| 27 | + <div class="uk-form-row"> | |
| 28 | + <label class="uk-form-label" for="form-h-bysj">保养时间</label> | |
| 29 | + <div class="uk-form-controls"> | |
| 30 | + <input name="bysj" type="text" id="form-h-bysj" disabled autocomplete="off"> | |
| 31 | + </div> | |
| 32 | + </div> | |
| 33 | + <div class="uk-form-row"> | |
| 34 | + <label class="uk-form-label" for="form-h-bydd">保养地点</label> | |
| 35 | + <div class="uk-form-controls"> | |
| 36 | + <input name="bydd" type="text" id="form-h-bydd" disabled autocomplete="off"> | |
| 37 | + </div> | |
| 38 | + </div> | |
| 39 | + <div class="uk-form-row"> | |
| 40 | + <label class="uk-form-label" for="form-h-text">消息内容</label> | |
| 41 | + <div class="uk-form-controls"> | |
| 42 | + <textarea name="text" id="form-h-text" autocomplete="off" style="width: 100%;"></textarea> | |
| 43 | + </div> | |
| 44 | + </div> | |
| 45 | + <br> | |
| 46 | + <div class="uk-form-row"> | |
| 47 | + <button disabled class="uk-button uk-button-danger uk-button-large uk-width-1-3 confirm_btn" | |
| 48 | + type="button" style="visibility: hidden;"> | |
| 49 | + </button> | |
| 50 | + <button class="uk-button uk-button-danger uk-button-large uk-width-1-3 confirm_btn" | |
| 51 | + type="button"> | |
| 52 | + 发送维保提醒 | |
| 53 | + </button> | |
| 54 | + </div> | |
| 55 | + </form> | |
| 56 | + </div> | |
| 57 | + </div> | |
| 58 | + | |
| 59 | + <script> | |
| 60 | + (function () { | |
| 61 | + var modal = '#mt_plan_modal', | |
| 62 | + mtPlanModal = JSON.parse(window.localStorage.getItem('mtPlanModal')), | |
| 63 | + f = $('.mt_plan_info>form', modal), htmlStr = new Array(); | |
| 64 | + | |
| 65 | + $('input', modal).each( function() { | |
| 66 | + $(this).val(mtPlanModal[this.name]); | |
| 67 | + }); | |
| 68 | + htmlStr.push('请'); | |
| 69 | + htmlStr.push(mtPlanModal.bysj); | |
| 70 | + htmlStr.push('至'); | |
| 71 | + htmlStr.push(mtPlanModal.bydd); | |
| 72 | + htmlStr.push('做'); | |
| 73 | + htmlStr.push(mtPlanModal.bydj); | |
| 74 | + $('textarea[name="text"]').text(htmlStr.join('')); | |
| 75 | + | |
| 76 | + $('.confirm_btn', f).on('click', function () { | |
| 77 | + var data = f.serializeJSON(); | |
| 78 | + data.nbbm = mtPlanModal.zbh; | |
| 79 | + if (!$.trim(data.text)) { | |
| 80 | + return notify_err('消息短语不能为空!'); | |
| 81 | + } | |
| 82 | + ajaxPostPhrase(data, function() { | |
| 83 | + notify_succ('短语已发出'); | |
| 84 | + UIkit.modal(modal).hide(); | |
| 85 | + }, function() { | |
| 86 | + notify_err('发送短语消息失败', f); | |
| 87 | + }); | |
| 88 | + }); | |
| 89 | + | |
| 90 | + var ajaxPostPhrase = function(data, succ, err) { | |
| 91 | + $.post('/directive/phrase', data, function(rs) { | |
| 92 | + if (rs == 0) { | |
| 93 | + succ && succ(); | |
| 94 | + } else { | |
| 95 | + err && err(); | |
| 96 | + } | |
| 97 | + }); | |
| 98 | + }; | |
| 99 | + })(); | |
| 100 | + </script> | |
| 101 | +</div> | ... | ... |
src/main/resources/static/real_control_v2/js/mt_plan/mtPlan.js
0 → 100644
| 1 | +/** | |
| 2 | + * 应急预案相关 | |
| 3 | + */ | |
| 4 | +var gb_mt_plan = (function () { | |
| 5 | + var $wrap = $('.multi_plat_msg_pop_wrap'); | |
| 6 | + var max = 5; | |
| 7 | + | |
| 8 | + var pop = function (data) { | |
| 9 | + //时间格式化 | |
| 10 | + var stm = moment(data.bysj); | |
| 11 | + data.timeStr = stm.format('HH时mm分'); | |
| 12 | + data.dateTimeStr = stm.format('YYYY-MM-DD HH:mm') | |
| 13 | + data.type = 'mt'; | |
| 14 | + | |
| 15 | + var htmlStr = template('mt_plat_msg_template', data); | |
| 16 | + var items = $wrap.find('.multi_plat_msg_pop'), len = items.length; | |
| 17 | + if (len >= max) | |
| 18 | + $wrap.find('.multi_plat_msg_pop:lt(' + (len - max) + ')').remove(); | |
| 19 | + | |
| 20 | + $wrap.append(htmlStr); | |
| 21 | + }; | |
| 22 | + | |
| 23 | + return { | |
| 24 | + pop: pop | |
| 25 | + } | |
| 26 | +})(); | |
| 0 | 27 | \ No newline at end of file | ... | ... |
src/main/resources/static/real_control_v2/js/safe_driv/safeDriv.js
| ... | ... | @@ -83,8 +83,11 @@ var gb_safe_driv = (function () { |
| 83 | 83 | $.post('/realSchedule/ackCp', {id : id}, function(res) {}); |
| 84 | 84 | } |
| 85 | 85 | break; |
| 86 | - // 机务保养平台 | |
| 87 | - case 'jw': | |
| 86 | + // 浦东公交维修库 | |
| 87 | + case 'mt': | |
| 88 | + var data = { zbh: $(this).data('zbh'), bydj: $(this).data('bydj'), bysj: $(this).data('bysj'), bydd: $(this).data('bydd')}; | |
| 89 | + window.localStorage.setItem('mtPlanModal', JSON.stringify(data)); | |
| 90 | + open_modal('/real_control_v2/fragments/multi_plat_msg/mt_plan_modal.html', {}, {center: false, bgclose: false}); | |
| 88 | 91 | break; |
| 89 | 92 | default: |
| 90 | 93 | break; | ... | ... |
src/main/resources/static/real_control_v2/js/websocket/sch_websocket.js
| ... | ... | @@ -193,10 +193,13 @@ var gb_sch_websocket = (function () { |
| 193 | 193 | }; |
| 194 | 194 | |
| 195 | 195 | var contingencyPlan = function (msg){ |
| 196 | - debugger | |
| 197 | 196 | gb_con_plan.pop(msg.data); |
| 198 | 197 | }; |
| 199 | 198 | |
| 199 | + var maintenancePlan = function (msg){ | |
| 200 | + gb_mt_plan.pop(msg.data); | |
| 201 | + }; | |
| 202 | + | |
| 200 | 203 | var msgHandle = { |
| 201 | 204 | report80: report80, |
| 202 | 205 | faChe: faChe, |
| ... | ... | @@ -209,7 +212,8 @@ var gb_sch_websocket = (function () { |
| 209 | 212 | safeDriv: safeDriv, |
| 210 | 213 | auto_wdtz: autoWdtz, |
| 211 | 214 | rfid: refreshRfid, |
| 212 | - contingencyPlan: contingencyPlan | |
| 215 | + contingencyPlan: contingencyPlan, | |
| 216 | + maintenancePlan: maintenancePlan | |
| 213 | 217 | }; |
| 214 | 218 | |
| 215 | 219 | function currentSecond() { | ... | ... |
src/main/resources/static/real_control_v2/main.html
| ... | ... | @@ -236,7 +236,7 @@ |
| 236 | 236 | </div> |
| 237 | 237 | </script> |
| 238 | 238 | <script id="cp_plat_msg_template" type="text/html"> |
| 239 | - <div class="multi_plat_msg_pop uk-animation-slide-bottom" data-type="{{type}}" data-id="{{id}}" data-confirm="{{responseState}}" data-ts="{{ts}}"> | |
| 239 | + <div class="multi_plat_msg_pop uk-animation-slide-bottom" data-type="{{type}}" data-id="{{id}}" data-title="{{responseState}}" data-ts="{{ts}}"> | |
| 240 | 240 | <div> |
| 241 | 241 | <span class="title">应急预案</span> |
| 242 | 242 | <span class="text"> {{instructionsContent}}</span> |
| ... | ... | @@ -244,9 +244,19 @@ |
| 244 | 244 | </div> |
| 245 | 245 | </div> |
| 246 | 246 | </script> |
| 247 | +<script id="mt_plat_msg_template" type="text/html"> | |
| 248 | + <div class="multi_plat_msg_pop uk-animation-slide-bottom" style="background-color: #0aae0a;" data-type="{{type}}" data-confirm="维修保养计划" data-line="{{line}}" data-zbh="{{zbh}}" data-bydj="{{bydj}}" data-bysj="{{dateTimeStr}}" data-bydd="{{bydd}}"> | |
| 249 | + <div> | |
| 250 | + <span class="title">维修保养计划</span> | |
| 251 | + <span class="text"> {{zbh}} {{timeStr}} 进场保养</span> | |
| 252 | + <span class="desc">--浦东公交维修库</span> | |
| 253 | + </div> | |
| 254 | + </div> | |
| 255 | +</script> | |
| 247 | 256 | |
| 248 | 257 | <script src="/real_control_v2/js/safe_driv/safeDriv.js" merge="custom_js"></script> |
| 249 | 258 | <script src="/real_control_v2/js/con_plan/conPlan.js" merge="custom_js"></script> |
| 259 | +<script src="/real_control_v2/js/mt_plan/mtPlan.js" merge="custom_js"></script> | |
| 250 | 260 | <!-- #### 安全驾驶 end ### --> |
| 251 | 261 | |
| 252 | 262 | <!-- 打电话 --> | ... | ... |