Commit 12ab1b6d authored by zhuangzhuang's avatar zhuangzhuang

11.16--优化地图显示点

parent a7251597
......@@ -46,7 +46,7 @@ dependencies {
compile('org.springframework.boot:spring-boot-starter-data-redis')
compile ('org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0')
compile ('org.influxdb:influxdb-java:2.7')
compile ('com.github.miwurster:spring-data-influxdb:1.6')
F
compile('com.aliyun.oss:aliyun-sdk-oss:2.5.0')
compile('org.apache.poi:poi:3.9')
compile files('libs/javacsv-2.0.jar')
......
......@@ -31,6 +31,7 @@ public class MyWebMvcConfigurer extends WebMvcConfigurerAdapter {
.excludePathPatterns("/alarmLog/addAlarmLog")
.excludePathPatterns("/side/**")
.excludePathPatterns("/downLoad")
.excludePathPatterns("/getAddress")
.excludePathPatterns("/test")
.excludePathPatterns("/getData");
super.addInterceptors(registry);
......
......@@ -377,7 +377,7 @@ public class AliyunOSSClientUtil {
putResult = ossClient.putObject(BACKET_NAME, FOLDER3+ fileName, is, metadata);
} else if(fileName.contains("CHN")){
putResult = ossClient.putObject(BACKET_NAME, FOLDER6+ fileName, is, metadata);
} else if(fileName.contains("仓库温湿度观测记录")){
} else if(fileName.contains("仓库温湿度观测记录") || fileName.contains("Warehouse temperature and humidity historic data")|| fileName.contains("倉庫の温度および湿度の観測記録")){
putResult = ossClient.putObject(BACKET_NAME, FOLDER5+ fileName, is, metadata);
} else {
putResult = ossClient.putObject(BACKET_NAME, FOLDER1+ fileName, is, metadata);
......
......@@ -59,7 +59,7 @@ public class DataUtil {
fb.setMessage(i18n.getMessage(request, "noCircuit"));
return gson.toJson(fb);
}
Long t2 = System.currentTimeMillis();
// Long t2 = System.currentTimeMillis();
List<HistoryDataVo> historyDataVoList = new ArrayList<>();
for (int i = 0; i < devList.size(); i++) {
HistoryDataVo historyDataVo = new HistoryDataVo();
......@@ -81,7 +81,7 @@ public class DataUtil {
if (resultCircuitVo.getEndTime() != null && resultCircuitVo.getEndTime() != 0) {
sqls = "SELECT count("+field+") FROM \"tdl_policy\".\"" + device + "\" WHERE \"event\" = '"+event+"' and \"tdl\"='" + devList.get(i) + "' and time>=" + startTime + " and time <=" + resultCircuitVo.getEndTime() * 1000000l;
} else {
sqls = "SELECT count("+field+") FROM \"tdl_policy\".\"" + device + "\" WHERE \"event\" = '"+event+"' and \"tdl\"='" + devList.get(i) + "' and time>=" + startTime + " and time <=" + System.currentTimeMillis() * 1000000l;
sqls = "SELECT count("+field+") FROM \"tdl_policy\".\"" + device + "\" WHERE \"event\" = '"+event+"' and \"tdl\"='" + devList.get(i) + "' and time>=" + startTime ;
}
QueryResult queryResults = influxDBTemplate.query(new Query(sqls, database));
Integer count;
......@@ -92,31 +92,46 @@ public class DataUtil {
historyDataVoList.add(historyDataVo);
continue;
}
logger.info(count+"------");
// logger.info(field+":"+count+"------");
String sql = "";
if (count > 500) {
if (resultCircuitVo.getEndTime() != null && resultCircuitVo.getEndTime() != 0) {
sql = getSQL( gatewayVo.getgSN(),field, device, devList.get(i), event,startTime, resultCircuitVo.getEndTime() * 1000000l);
} else {
sql = getSQL(gatewayVo.getgSN(), field, device, devList.get(i),event, startTime, t1 * 1000000l);
sql = getSQL(gatewayVo.getgSN(), field, device, devList.get(i),event, startTime, System.currentTimeMillis() * 1000000l);
}
QueryResult queryResult = influxDBTemplate.query(new Query(sql, database,false));
if (queryResult.getResults() != null) {
historyData = getHistoryDatas(queryResult, field);
String sql3 = "Select " + field + " From \"tdl_policy\".\"" + device + "\" where " + "\"tdl\"='" + devList.get(i) + "' " + " ORDER BY time DESC limit 1";
QueryResult queryResult2 = influxDBTemplate.query(new Query(sql3, database));
if(queryResult2.getResults().get(0).getSeries() != null){
HistoryData data = new HistoryData();
data.setValue(queryResult2.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString());
data.setTime(UTCToCST(queryResult2.getResults().get(0).getSeries().get(0).getValues().get(0).get(0).toString(),"0"));
historyData.add(data);
}
}
historyDataVo.setDataList(historyData);
historyDataVoList.add(historyDataVo);
} else {
if (resultCircuitVo.getEndTime() != null && resultCircuitVo.getEndTime() != 0) {
sql = "SELECT "+field+" FROM \"tdl_policy\".\"" + device + "\" where \"data_type\" = 'data' AND \"tdl\"='" + devList.get(i) + "' and time >=" + startTime + " and time<=" + resultCircuitVo.getEndTime() * 1000000l + " ORDER BY time ";
sql = "SELECT "+field+" FROM \"tdl_policy\".\"" + device + "\" where \"data_type\" = 'data' AND \"tdl\"='" + devList.get(i) + "' and time >=" + startTime + " and time<=" + resultCircuitVo.getEndTime() * 1000000l ;
} else {
sql = "SELECT "+field+" FROM \"tdl_policy\".\"" + device + "\" where \"data_type\" = 'data' AND \"tdl\"='" + devList.get(i) + "' and time >=" + startTime + " ORDER BY time";
sql = "SELECT "+field+" FROM \"tdl_policy\".\"" + device + "\" where \"data_type\" = 'data' AND \"tdl\"='" + devList.get(i) + "' and time >=" + startTime ;
}
QueryResult queryResult = influxDBTemplate.query(new Query(sql, database, true));
if (queryResult.getResults().get(0).getSeries() != null) {
//解析数据
historyData = getHistoryData(queryResult, field);
String sql3 = "Select " + field + " From \"tdl_policy\".\"" + device + "\" where " + "\"tdl\"='" + devList.get(i) + "' " +" ORDER BY time DESC limit 1";
QueryResult queryResult2 = influxDBTemplate.query(new Query(sql3, database));
if(queryResult2.getResults().get(0).getSeries() != null){
HistoryData data = new HistoryData();
data.setValue(queryResult2.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString());
data.setTime(UTCToCST(queryResult2.getResults().get(0).getSeries().get(0).getValues().get(0).get(0).toString(),"0"));
historyData.add(data);
}
}
historyDataVo.setDataList(historyData);
historyDataVoList.add(historyDataVo);
......@@ -128,18 +143,15 @@ public class DataUtil {
public static String getSQL(String SN,String field, String device, String tdl,String event, Long startTime, Long endTime) {
String sql = "";
long times = (endTime - startTime) / 500;
logger.info(field +"---"+ times + "-----"+ startTime +"----" +endTime+"----" + tdl);
for (int i = 0; i < 500; i++) {
Long maxTime = startTime + times;
sql = sql + "Select " + field + " From \"tdl_policy\".\"" + device + "\" where " +
sql = sql + "Select " + field + " From \"tdl_policy\".\"" + device + "\" where " +
" \"event\" = '"+event+"' " +
" AND \"tdl\"='" + tdl + "' " +
"and time >= "+startTime +" and time <= " + maxTime + " order by time limit 1;";
" AND \"tdl\"='" + tdl + "' " +
" and time >= "+startTime +" and time <" + maxTime + " limit 1;";
startTime = maxTime;
}
sql = sql + "Select " + field + " From \"tdl_policy\".\"" + device + "\" where " +
" \"event\" = '"+event+"' " +
" AND \"tdl\"='" + tdl + "' " +
"and time >= "+startTime+" and time <= " + endTime + " order by time desc limit 1;";
return sql;
}
......@@ -184,6 +196,9 @@ public class DataUtil {
public static String parseTime(String time) {
String dateResult = null;
try {
......
package com.example.tdl.util;
import com.google.gson.Gson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -12,6 +13,9 @@ import java.net.URLConnection;
public class HttpRequester {
private static Logger logger = LoggerFactory.getLogger(HttpRequester.class);
//发送post请求
public static String sendPost(String url, String param) {
PrintWriter out = null;
......@@ -68,10 +72,11 @@ public class HttpRequester {
//发送get请求
public static String get(String url) {
Gson gson = new Gson();
BufferedReader in = null;
try {
URL realUrl = new URL(url);
logger.info(url+"url");
URLConnection connection = realUrl.openConnection();
connection.setRequestProperty("accept", "*/*");
......@@ -84,12 +89,13 @@ public class HttpRequester {
connection.connect();
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
in = new BufferedReader(new InputStreamReader(connection.getInputStream(),"utf-8"));
StringBuffer sb = new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
sb.append(line);
}
logger.info(sb.toString());
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
......
......@@ -26,20 +26,30 @@ public class MapUtils {
Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
s = s * EARTH_RADIUS;
s = Math.round(s * 1000);
// System.out.println("s:"+s);
return s;
}
//计算速度
public static double getSpeed(double lat1, double lng1, double lat2, double lng2,Long time){
public static double getSpeed(double lat1, double lng1, double lat2, double lng2,Long time,Float sppeed){
if(time ==0){
return 0d;
}
double s = getDistance( lat1, lng1, lat2, lng2);
double speed = (double) s/time;
// if((lng1+"") .contains("110.")){
// System.out.println("lng:" + lng1 +" ----lat:" +lat1 +" ----speed:" + speed +" ---time :" +time +" -----distance:"+s);
// }
// System.out.println("speed:"+speed);
if(s <1000 || s> 10000){
//计算速度
if(speed>250 || speed <3.3){
if(speed>250 || speed <sppeed){
// if((lng1+"") .contains("110.")){
// System.out.println("lng:" + lng1 +" ----lat:" +lat1 +" ----speed:" + speed +" ---time :" +time +" -----distance:"+s);
// }
return 0;
}
return s/time;
......
package com.example.tdl.web;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.tdl.domain.dto.CommFeedback;
import com.example.tdl.domain.vo.TransportationNoVo;
import com.example.tdl.util.HttpRequester;
import com.google.gson.Gson;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
@RestController("/location")
public class BaiduController {
private Logger logger = LoggerFactory.getLogger(CircuitController.class);
CommFeedback fb=new CommFeedback();
Gson gson=new Gson();
@ApiOperation(value = "模糊查询百度地图位置", notes = "模糊查询百度地图位置")
@PostMapping("/getAddress")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "header", name = "Account_token", value = "token", required = true, dataType = "String"),
@ApiImplicitParam(paramType = "header", name = "AccountLanguage", value = "language", required = true, dataType = "String"),
})
public String getLocation(@RequestBody String keyword, HttpServletRequest request){
JSONObject jsonObject= JSON.parseObject(keyword);
keyword=jsonObject.getString("keyword");
logger.info(keyword);
return HttpRequester.get("http://api.map.baidu.com/place_abroad/v1/search?query=" + keyword + "&page_size=1&page_num=0&scope=1&region=%E5%85%A8%E5%9B%BD&output=json&ak=rzjXpeDvGDDaBkuZxaSChdztTFc4NfC7");
}
}
......@@ -373,12 +373,10 @@ public class CircuitController {
String val = queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1) == null ? "" : queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString();
Boolean boo = Double.valueOf(val) <0;
if(Double.valueOf(val) <0){
logger.info(Double.valueOf(val) +"_______");
messageVo.setBattery("NA");
}else{
messageVo.setBattery(df.format(Double.valueOf(val)));
}
}
for(int i=0;i<TDL.size();i++){
CircuitMessageVo.TDL tdl = new CircuitMessageVo.TDL();
......
......@@ -149,6 +149,7 @@ public class DataController {
//解析经纬度数据
List<LocationDataVo> locationDataVos = new ArrayList<>();
if (queryResult.getResults().get(0).getSeries() != null) {
//博士测试线路:CHN20181016G3039
if(searchLocationVo.getTransportationNo().equals("CHN20181016G3039")){
locationDataVos =getLocation(queryResult);
}else{
......@@ -600,6 +601,10 @@ public class DataController {
public List<LocationDataVo> getData(QueryResult queryResult) {
List<List<Object>> values = DataUtil.getValues(queryResult);
Float sppeed = 3.3f;
if(queryResult.getResults().get(0).getSeries().get(0).getName().contains("17110202")){
sppeed =1.7f;
}
List<LocationDataVo> historyDataList = new ArrayList<>();
for (int i =0,length = values.size()-1;i<length;i++) {
LocationDataVo historyData = new LocationDataVo();
......@@ -627,9 +632,9 @@ public class DataController {
Double lng4 = Double.parseDouble(values.get(i+3).get(1).toString());
Double lat4 = Double.parseDouble(values.get(i+3).get(2).toString());
//获取运行时间
Double speed1 = MapUtils.getSpeed(lat1, lng1,lat2,lng2,(Long.valueOf(time2)-Long.valueOf(time1))/1000);
Double speed2 = MapUtils.getSpeed(lat2, lng2,lat3,lng3,(Long.valueOf(time3)-Long.valueOf(time2))/1000);
Double speed3 = MapUtils.getSpeed(lat3, lng3,lat4,lng4,(Long.valueOf(time4)-Long.valueOf(time3))/1000);
Double speed1 = MapUtils.getSpeed(lat1, lng1,lat2,lng2,(Long.valueOf(time2)-Long.valueOf(time1))/1000,sppeed);
Double speed2 = MapUtils.getSpeed(lat2, lng2,lat3,lng3,(Long.valueOf(time3)-Long.valueOf(time2))/1000,sppeed);
Double speed3 = MapUtils.getSpeed(lat3, lng3,lat4,lng4,(Long.valueOf(time4)-Long.valueOf(time3))/1000,sppeed);
//对比三个速度值,如果三者相差很小直接忽略
Math.abs(speed1-speed2) ;
Math.abs(speed3-speed2);
......@@ -647,7 +652,7 @@ public class DataController {
Double lat1 = Double.parseDouble(values.get(i).get(2).toString());
Double lng2 = Double.parseDouble(values.get(i+1).get(1).toString());
Double lat2 = Double.parseDouble(values.get(i+1).get(2).toString());
Double speed2 = MapUtils.getSpeed(lat1, lng1,lat2,lng2,(Long.valueOf(time2)-Long.valueOf(time1))/1000);
Double speed2 = MapUtils.getSpeed(lat1, lng1,lat2,lng2,(Long.valueOf(time2)-Long.valueOf(time1))/1000,sppeed);
if(speed2 >0){
historyData.setTime(time1);
historyData.setLng(lng1);
......@@ -667,6 +672,7 @@ public class DataController {
historyData.setLat(Double.parseDouble(values.get(0).get(2).toString()));
historyDataList.add(historyData);
}
logger.info(gson.toJson(historyDataList));
return historyDataList;
}
......
......@@ -11,6 +11,7 @@
## InfluxDB
#spring.influxdb.url=http://housetest-influxdb:8086
server.port=8092
spring.datasource.url=jdbc:mysql://witcloud-mysql:3306/tdlCloud?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
......
......@@ -7,7 +7,7 @@ spring.datasource.driver-class-name=com.mysql.jdbc.Driver
threadpool.corepoolsize = 30
threadpool.maxpoolsize = 50
server.port=9092
server.port=8092
management.security.enabled=false
......@@ -21,7 +21,7 @@ spring.messages.cache-seconds= 3600
spring.messages.encoding=UTF-8
tdl.redis.host=192.168.1.16
tdl.redis.host=127.0.0.1
tdl.redis.index=0
tdl.redis.port=6379
tdl.redis.password=
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<contextName>logback</contextName>
<property name="log.path" value="logback.log" />
<property name="log.path" value="log/logback.log" />
<!--输出到控制台-->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment