src/main/java/com/moral/controller/ScreenController.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/entity/Point.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/mapper/HistoryHourlyMapper.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/service/HistoryHourlyService.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/service/impl/HistoryHourlyServiceImpl.java | ●●●●● patch | view | raw | blame | history | |
src/main/resources/mapper/HistoryHourlyMapper.xml | ●●●●● patch | view | raw | blame | history | |
src/main/webapp/view/pollutionsource.jsp | ●●●●● patch | view | raw | blame | history |
src/main/java/com/moral/controller/ScreenController.java
@@ -69,6 +69,7 @@ import com.moral.entity.MapBounds; import com.moral.entity.MonitorPoint; import com.moral.entity.Organization; import com.moral.entity.Point; import com.moral.entity.Region; import com.moral.entity.alarm.AlarmConfig; import com.moral.entity.alarm.AlarmConfigValue; @@ -84,6 +85,7 @@ import com.moral.service.DictionaryDataService; import com.moral.service.HangzhouAqiService; import com.moral.service.HistoryDailyService; import com.moral.service.HistoryHourlyService; import com.moral.service.HistoryMinutelyService; import com.moral.service.HistoryService; import com.moral.service.MachineActivateService; @@ -142,6 +144,9 @@ */ @Resource private DeviceService deviceService; @Resource private HistoryHourlyService historyHourlyService; @Resource private HistoryMinutelyService historyMinutelyService; @@ -1219,34 +1224,30 @@ @GetMapping("/pollutionSource") @ApiOperation(value = "污染传播来源", notes = "污染传播来源") @ApiImplicitParams(value = { @ApiImplicitParam(name = "organizationId", defaultValue = "5", value = "登录账号的组织id", required = true, paramType = "query", dataType = "String"), @ApiImplicitParam(name = "mac", value = "设备mac地址(如:p5dnd7a0391972)", required = true, paramType = "query", dataType = "String"), @ApiImplicitParam(name = "time", value = "查询时间(格式:2019-08-22)", required = true, paramType = "query", dataType = "String")}) @ApiImplicitParam(name = "mac", value = "设备mac地址(如:898607b0101730392254)", required = true, paramType = "query", dataType = "String"), @ApiImplicitParam(name = "sensorKey", value = "查询的监测因子的key(格式:e1)", required = true, paramType = "query", dataType = "String"), @ApiImplicitParam(name = "time", value = "查询时间(格式:2019-09-01-10)", required = true, paramType = "query", dataType = "String")}) public ModelAndView pollutionSource(ModelAndView model, HttpServletRequest request) throws Exception { Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); LocalDate today = LocalDate.now(); String time = parameters.get("time").toString(); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDate selectTime = LocalDate.parse(time, dateTimeFormatter); int month = selectTime.getMonth().getValue(); LocalDate yesterday = today.minusDays(1); LocalDate futureDay = today.plusDays(14); Boolean isAfterYesterday = selectTime.isAfter(yesterday) || selectTime.isEqual(yesterday); Boolean isAfterFutureDay = selectTime.isAfter(futureDay); Map<String, Object> weatherInfoToday = weatherService.getWeatherDataByRegion(parameters); Map<String, Object> weatherInfoForecast = new HashMap<>(); if (isAfterYesterday && !isAfterFutureDay) { weatherInfoForecast = weatherService.get15DayWeatherDataByRegion(parameters); } Boolean isToday = selectTime.isEqual(today); String timeStr = parameters.get("time").toString(); String YearAndDay = timeStr.substring(0, timeStr.lastIndexOf("-")); String Hour = timeStr.substring(timeStr.lastIndexOf("-") + 1); String time = YearAndDay + " " + Hour + ":00:00"; DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); LocalDateTime timeLocalDateTime = LocalDateTime.parse(time, dateTimeFormatter); System.out.println(timeLocalDateTime); int month = timeLocalDateTime.getMonth().getValue(); Point dirPoint= historyHourlyService.getDirPoint(parameters); Map<String,Object> getPollutionSourceData=historyHourlyService.getPollutionSourceData(parameters); System.out.println(dirPoint.toString()); System.out.println("getPollutionSourceData:"+getPollutionSourceData); String mac = parameters.get("mac").toString(); Device device = deviceService.getDeviceByMac(mac, false); JSONObject params = new JSONObject(); params.put("weatherInfoToday", weatherInfoToday); params.put("weatherInfoForecast", weatherInfoForecast); params.put("device", device); params.put("isToday", isToday); params.put("month", month); params.put("dirPoint",dirPoint); params.put("getPollutionSourceData",getPollutionSourceData); String paramsJson = params.toJSONString(); model.addObject("pollutionSourceParams", paramsJson); model.setViewName("pollutionsource"); src/main/java/com/moral/entity/Point.java
New file @@ -0,0 +1,9 @@ package com.moral.entity; import lombok.Data; @Data public class Point { private double lng; private double lat; } src/main/java/com/moral/mapper/HistoryHourlyMapper.java
New file @@ -0,0 +1,8 @@ package com.moral.mapper; import java.util.Map; public interface HistoryHourlyMapper { Map<String, Object> getPollutionSourceData(Map<String, Object> parameters); } src/main/java/com/moral/service/HistoryHourlyService.java
New file @@ -0,0 +1,11 @@ package com.moral.service; import java.util.Map; import com.moral.entity.Point; public interface HistoryHourlyService { Map<String, Object> getPollutionSourceData(Map<String, Object> parameters) throws Exception; Point getDirPoint(Map<String, Object> parameters) throws Exception; } src/main/java/com/moral/service/impl/HistoryHourlyServiceImpl.java
New file @@ -0,0 +1,104 @@ package com.moral.service.impl; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.apache.commons.collections.MapUtils; import org.springframework.stereotype.Service; import com.moral.entity.Device; import com.moral.entity.Point; import com.moral.entity.Sensor; import com.moral.mapper.HistoryHourlyMapper; import com.moral.mapper.SensorMapper; import com.moral.service.DeviceService; import com.moral.service.HistoryHourlyService; @Service public class HistoryHourlyServiceImpl implements HistoryHourlyService { @Resource private HistoryHourlyMapper historyHourlyMapper; @Resource private DeviceService deviceService; @Resource private SensorMapper sensorMapper; @Override public Map<String, Object> getPollutionSourceData(Map<String, Object> parameters) throws Exception { List<Sensor> sensors = sensorMapper.getSensorsByMac(parameters); List<String> sensorKeys = new ArrayList<>(); for (Sensor sensor : sensors) { sensorKeys.add(sensor.getSensorKey()); } parameters.put("sensorKeys", sensorKeys); /* if(pollutionSourceData.get("e6")!=null&&pollutionSourceData.get("e18")!=null){ pollutionSourceData=historyHourlyMapper.getPollutionSourceData(parameters); } return pollutionSourceData;*/ System.out.println("----"+historyHourlyMapper.getPollutionSourceData(parameters)); return historyHourlyMapper.getPollutionSourceData(parameters); } @Override public Point getDirPoint(Map<String, Object> parameters) throws Exception{ Map<String,Object> pollutionSourceData=getPollutionSourceData(parameters); String mac = parameters.get("mac").toString(); Device device = deviceService.getDeviceByMac(mac, false); Point pointEnd=new Point(); if(MapUtils.isNotEmpty(pollutionSourceData)){ System.out.println("pollutionSourceData"+pollutionSourceData); if(pollutionSourceData.get("e18")!=null&&pollutionSourceData.get("e23")!=null&&pollutionSourceData.get("e6")!=null){ double windSpeed=Double.valueOf(pollutionSourceData.get("e18").toString()); double winDir=Double.valueOf(pollutionSourceData.get("e23").toString()); double distance=windSpeed*3600; double long1=device.getLongitude(); double lat1=device.getLatitude(); System.out.println("windSpeed:"+windSpeed+"---winDir:"+winDir+"---distance:"+distance+"--long1:"+long1+"--lat1:"+lat1); String[] result=calLocationByDistanceAndLocationAndDirection(winDir,long1,lat1,distance); System.out.println("result1:"+Double.valueOf(result[0])+"result2:"+Double.valueOf(result[1])); pointEnd.setLng(Double.valueOf(result[0])); pointEnd.setLat(Double.valueOf(result[1])); } } return pointEnd; } /** * 根据一点的坐标与距离,以及方向,计算另外一点的位置 * @param angle 角度,从正北顺时针方向开始计算 * @param startLong 起始点经度 * @param startLat 起始点纬度 * @param distance 距离,单位m * @return */ private String[] calLocationByDistanceAndLocationAndDirection(double angle, double startLong,double startLat, double distance){ /** 地球半径 **/ final double R = 6371e3; /** 180° **/ final DecimalFormat df = new DecimalFormat("0.000000"); String[] result = new String[2]; //将距离转换成经度的计算公式 double δ = distance/R; // 转换为radian,否则结果会不正确 angle = Math.toRadians(angle); startLong = Math.toRadians(startLong); startLat = Math.toRadians(startLat); double lat = Math.asin(Math.sin(startLat)*Math.cos(δ)+Math.cos(startLat)*Math.sin(δ)*Math.cos(angle)); double lng = startLong + Math.atan2(Math.sin(angle)*Math.sin(δ)*Math.cos(startLat),Math.cos(δ)-Math.sin(startLat)*Math.sin(lat)); // 转为正常的10进制经纬度 lng = Math.toDegrees(lng); lat = Math.toDegrees(lat); result[0] = df.format(lng); result[1] = df.format(lat); return result; } } src/main/resources/mapper/HistoryHourlyMapper.xml
New file @@ -0,0 +1,20 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.moral.mapper.HistoryHourlyMapper"> <select id="getPollutionSourceData" resultType="java.util.Map"> SELECT <foreach collection="sensorKeys" separator="," item="sensorKey"> json->'$.${sensorKey}[0]' AS '${sensorKey}' </foreach> FROM history_hourly <where> <if test="mac!=null"> AND mac=#{mac} </if> <if test="time!=null"> AND time= DATE_SUB(#{time}, INTERVAL 1 HOUR) </if> </where> </select> </mapper> src/main/webapp/view/pollutionsource.jsp
@@ -79,10 +79,29 @@ top: 35px !important; border-radius: 5px; } #cpm { width: 300px; height: 100px; position: absolute; background-color: #ffffff; display: none; left: 50%; top: 50%; margin-left: -150px; margin-top: -50px; z-index: 11; color: #000000; border: 2px solid #FF7F50; font-size: 28px; line-height: 100px; text-align: center; } </style> <body> <div class="main_body"> <div id="cpm">查无数据</div> <div id="mapCanvas"></div> <!-- 百度地图 --> <!-- 传sensorInfo,regionCode,regionName,monitorPoint,device--> <div id="pollutionSourceParams" style="display: none;"> @@ -99,14 +118,13 @@ style: "normal" // 设置地图风格为高端黑 }; var params = $.parseJSON($("#pollutionSourceParams").html()); var weatherInfoToday = params["weatherInfoToday"]; var weatherInfoForecast = params["weatherInfoForecast"]; var isToday = params["isToday"]; var month = params["month"]; var device = params["device"]; var cityName = params["weatherInfoToday"]["cityName"]; var dirPoint=params["dirPoint"]; console.log(dirPoint.lng); console.log(dirPoint.lat); var getPollutionSourceData=params["getPollutionSourceData"]; var map = new BMap.Map("mapCanvas", {enableMapClick: false}); map.setCurrentCity("昆山"); map.setMapStyle(mapStyle); map.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放 var navigation = new BMap.NavigationControl({ @@ -115,90 +133,112 @@ }); map.addControl(navigation); map.addControl(new BMap.ScaleControl()); if ($.isEmptyObject(dirPoint)||$.isEmptyObject(getPollutionSourceData)||getPollutionSourceData["e18"]==0) { showNoData(); }else{ var humidity=getPollutionSourceData["e6"]; var windSpeed=getPollutionSourceData["e18"]; var longitude = params["device"]["longitude"]; var latitude = params["device"]["latitude"]; var point = new BMap.Point(longitude, latitude); var icon = new BMap.Icon("/img/ico00.png", new BMap.Size(50, 50)); var marker = new BMap.Marker(point, {icon: icon, offset: new BMap.Size(0, -20)}); map.addOverlay(marker); map.setCurrentCity(cityName); map.centerAndZoom(point, 19); var bounds = map.getBounds(); //获取地图可视区域 var sw = bounds.getSouthWest(); //获取西南角的经纬度(左下端点) var ne = bounds.getNorthEast(); //获取东北角的经纬度(右上端点) var wn = new BMap.Point(sw.lng, ne.lat); //获取西北角的经纬度(左上端点) var es = new BMap.Point(ne.lng, sw.lat); //获取东南角的经纬度(右下端点) var n = new BMap.Point(longitude, ne.lat); var s = new BMap.Point(longitude, sw.lat); var w = new BMap.Point(sw.lng, latitude); var e = new BMap.Point(ne.lng, latitude); var dirPoint; var windLevel; var condition; if (Object.keys(weatherInfoForecast).length === 0) { var windDir = weatherInfoToday["windDir"]; dirPoint = getWindDir(windDir, dirPoint); windLevel = weatherInfoToday["windLevel"]; condition = weatherInfoToday["condition"]; } else { if (isToday) { var windDir = weatherInfoToday["windDir"]; dirPoint = getWindDir(windDir, dirPoint); windLevel = weatherInfoToday["windLevel"]; condition = weatherInfoToday["condition"]; } else { var windDir = weatherInfoForecast["windDirDay"]; dirPoint = getWindDir(windDir, dirPoint); windLevel = weatherInfoForecast["windLevelDay"]; condition = weatherInfoForecast["conditionDay"]; } } var polyline = new BMap.Polyline([ map.centerAndZoom(point, 17); var polyline1 = new BMap.Polyline([ dirPoint, point new BMap.Point(point.lng+0.01, point.lat+0.01) ], {strokeColor: "#5298FF", strokeWeight: 4, strokeOpacity: 1} ); map.addOverlay(polyline);// 画两点间线 addArrow(polyline, 50, Math.PI / 7); var polyline2 = new BMap.Polyline([ dirPoint, new BMap.Point( point.lng-0.02, point.lat-0.01) ], {strokeColor: "#5298FF", strokeWeight: 4, strokeOpacity: 1} ); var distance=windSpeed*3600; console.log(distance); var arrowLength;//两点间箭头长度 if (distance <= 5) { arrowLength = 0; } else if (distance > 5 && distance <= 20) { arrowLength = 2; } else if (distance > 20 && distance <= 50) { arrowLength = 3; } else if (distance > 50 && distance <= 100) { arrowLength = 5; } else if (distance > 100 && distance <= 200) { arrowLength = 10; } else if (distance > 200 && distance <= 500) { arrowLength = 20; } else if (distance > 500 && distance <= 1000) { arrowLength = 40; } else if (distance > 1000 && distance <= 2000) { arrowLength = 80; } else if (distance > 2000 && distance <= 3000) { arrowLength = 120; } else if (distance > 3000 && distance <= 10000) { arrowLength = 500; } else if (distance > 10000 && distance <= 20000) { arrowLength = 1000; } else if (distance > 20000 && distance <= 50000) { arrowLength = 2500; } else if (distance > 50000 && distance <= 100000) { arrowLength = 5000; } else if (distance > 100000 && distance <= 200000) { arrowLength = 10000; } else if (distance > 200000 && distance <= 500000) { arrowLength = 25000; } else if (distance > 500000 && distance <= 1000000) { arrowLength = 50000; } else if (distance > 1000000 && distance <= 2000000) { arrowLength = 100000; } else { arrowLength = 150000; } map.addOverlay(polyline1);// 画两点间线 addArrow(polyline1, arrowLength, Math.PI / 7,windSpeed); map.addOverlay(polyline2);// 画两点间线 addArrow(polyline2, arrowLength, Math.PI / 7,windSpeed); var winfowTextCause = "<p style='height: 44px;line-height: 22px'>汽车尾气,工厂废气,以及周边地区农田秸秆焚烧,污染传播途径是根据风向来做出调整</p>"; var winfowTextSource; var supplement; if (month == 12 || month == 1 || month == 2) { if (windLevel >= 3) { if (windSpeed >= 3.4) { supplement = ",但风速较大,大气扩散条件较有利,空气质量相对提升"; } if (condition.indexOf("雨") != -1) { if (humidity>=90.0) { supplement = ",但降雨有利于对颗粒物的沉降、冲刷,改善污染状况"; }else{ supplement =""; } winfowTextSource = "<p style='height: 22px;line-height: 22px'>压强升高气温降低,会因冷空气带来的颗粒物,导致污染上升" + supplement + "</p>"; } else if (month == 3 || month == 4 || month == 5) { if (windLevel >= 3) { if (windSpeed >= 3.4) { supplement = ",但风速较大,大气扩散条件较有利,空气质量相对提升"; } if (condition.indexOf("雨") != -1) { if (humidity>=90.0) { supplement = ",但降雨有利于对颗粒物的沉降、冲刷,改善污染状况"; }else{ supplement =""; } winfowTextSource = "<p style='height: 22px;line-height: 22px'>地面逆温频率的增加使污染物在近地层不断积累" + supplement + "</p>"; } else if (month == 6 || month == 7) { if (windLevel >= 3) { if (windSpeed >= 3.4) { supplement = ",同时风速较大,加速扩散"; } if (condition.indexOf("雨") != -1) { if (humidity>=90.0) { supplement = ",同时降雨有利于对颗粒物的沉降、冲刷,改善污染状况"; }else{ supplement =""; } winfowTextSource = "<p style='height: 22px;line-height: 22px'>夏季的气温条件不易发生逆温,利于污染物扩散" + supplement + "</p>"; } else if (month == 8 || month == 9 || month == 10 || month == 11) { if (windLevel >= 3) { if (windSpeed >= 3.4) { supplement = ",但风速较大,利于污染物扩散"; } if (condition.indexOf("雨") != -1) { if (humidity>=90.0) { supplement = ",但降雨有利于对颗粒物的沉降、冲刷,改善污染状况"; }else{ supplement =""; @@ -221,9 +261,11 @@ var infoWindow = new BMap.InfoWindow(winfowText, opts); this.openInfoWindow(infoWindow); }); } function addArrow(polyline, length, angleValue) { function addArrow(polyline, length, angleValue,windSpeed) { var linePoint = polyline.getPath();// 线的坐标串 var arrowCount = linePoint.length; for (var i = 1; i < arrowCount; i++) { // 在拐点处绘制箭头 @@ -267,32 +309,28 @@ var pointArrow = map.pixelToPoint(new BMap.Pixel(pixelX, pixelY)); var pointArrow1 = map.pixelToPoint(new BMap.Pixel(pixelX1, pixelY1)); var pointMiddle = map.pixelToPoint(new BMap.Pixel(poMiddleX, poMiddleY)); lab = new BMap.Label("风速:"+windSpeed+"m/s", {position: pointMiddle, offset: new BMap.Size(0, -30)}); lab.setStyle({ color: "red", fontSize: "16px", backgroundColor: "1", border: "0", fontWeight: "bold" }); map.addOverlay(lab); var Arrow = new BMap.Polyline([pointArrow, pointMiddle, pointArrow1], {strokeColor: "#5298FF", strokeWeight: 4, strokeOpacity: 1}); map.addOverlay(Arrow); } }; function getWindDir(windDir, dirPoint) { if (windDir == "北风") { dirPoint = n; } else if (windDir == "南风") { dirPoint = s; } else if (windDir == "西风") { dirPoint = w; } else if (windDir == "东风") { dirPoint = e; } else if (windDir == "西北风") { dirPoint = wn; } else if (windDir == "东北风") { dirPoint = ne; } else if (windDir == "西南风") { dirPoint = sw; } else if (windDir == "东南风") { dirPoint = es; } else { dirPoint = n; } return dirPoint; function showNoData() { var longitude = 120.987287; var latitude = 31.391562; var point = new BMap.Point(longitude, latitude); map.centerAndZoom(point, 17); setTimeout(function () { document.getElementById("cpm").style.display = 'block'; }, 250); }; </script>