|  |  |  | 
|---|
|  |  |  | @ApiImplicitParams(value = { | 
|---|
|  |  |  | @ApiImplicitParam(name = "monitorPointId", value = "公司Id", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "sensorKey", value = "因子", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "realTime", value = "实时", required = true, paramType = "query", dataType = "String"), | 
|---|
|  |  |  | @ApiImplicitParam(name = "accountId", value = "用户id", required = false, paramType = "query", dataType = "String")}) | 
|---|
|  |  |  | public ModelAndView unorganizedEmissionsBackupsV2(HttpServletRequest request, ModelAndView model) { | 
|---|
|  |  |  | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|---|
|  |  |  | 
|---|
|  |  |  | List<Device> deviceList = deviceService.getDevicesByMonitorPointId(539); | 
|---|
|  |  |  | //获取五分钟数据 | 
|---|
|  |  |  | Map<String,Object> pa = new HashMap<>(); | 
|---|
|  |  |  | //获取开始时间和结束时间 | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | 
|---|
|  |  |  | Calendar beforeTime = Calendar.getInstance(); | 
|---|
|  |  |  | Date newTime = beforeTime.getTime(); | 
|---|
|  |  |  | beforeTime.add(Calendar.MINUTE,-5); | 
|---|
|  |  |  | Date startTime = beforeTime.getTime(); | 
|---|
|  |  |  | beforeTime.add(Calendar.MINUTE,6); | 
|---|
|  |  |  | Date endTime = beforeTime.getTime(); | 
|---|
|  |  |  | //pa.put("sensorKey","e1"); | 
|---|
|  |  |  | pa.put("yearAndMonth","202012"); | 
|---|
|  |  |  | pa.put("time","2020-12-03 10:10:00"); | 
|---|
|  |  |  | pa.put("yearAndMonth",sdf.format(newTime).substring(0,7).replace("-","")); | 
|---|
|  |  |  | pa.put("startTime",startTime); | 
|---|
|  |  |  | pa.put("endTime",endTime); | 
|---|
|  |  |  | List<String> macs = new ArrayList<>(); | 
|---|
|  |  |  | List<String> sensorKeys = new ArrayList<>(); | 
|---|
|  |  |  | for (Device device:deviceList) { | 
|---|
|  |  |  | 
|---|
|  |  |  | sensorKeys.add("e23"); | 
|---|
|  |  |  | pa.put("macs",macs); | 
|---|
|  |  |  | pa.put("sensorKeys",sensorKeys); | 
|---|
|  |  |  | List<Map<String, Object>> fiveMinuteDataList = historyFiveMinutelyService.getFiveMinutesSersorDataByMacsAndTime(pa); | 
|---|
|  |  |  | pa.put("macNumber",macs.size()); | 
|---|
|  |  |  | List<Map<String, Object>> fiveMinuteDataList = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTimeSolt(pa); | 
|---|
|  |  |  | //声明数组,存放所有设备的数值 | 
|---|
|  |  |  | double[] allDeviceData = new double[fiveMinuteDataList.size()]; | 
|---|
|  |  |  | System.out.println(fiveMinuteDataList); | 
|---|
|  |  |  | 
|---|
|  |  |  | List<Map<String,Object>> windList = new ArrayList<>(); | 
|---|
|  |  |  | for (Map map:fiveMinuteDataList) { | 
|---|
|  |  |  | String[] wind_speed = map.get("e18").toString().split(","); | 
|---|
|  |  |  | if (!map.containsKey("e23")){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String[] wind_direction = map.get("e23").toString().split(","); | 
|---|
|  |  |  | Map<String,Object> windMap = new HashMap<>(); | 
|---|
|  |  |  | windMap.put("wind_speed",wind_speed[0].substring(1,wind_speed[0].length())); | 
|---|
|  |  |  | 
|---|
|  |  |  | i = i+1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //计算平均风向和风速 | 
|---|
|  |  |  | System.out.println("windList:"+windList); | 
|---|
|  |  |  | Map<String,Double> res = WindUtils.getWind_direction_speed(windList); | 
|---|
|  |  |  | System.out.println("res:"+res); | 
|---|
|  |  |  | //计算该站点的点与污染源点的角度 | 
|---|
|  |  |  | Map<String,Double> angleMap = new HashMap(); | 
|---|
|  |  |  | MyLatLng pollutionSourcePoint_log_lat = new MyLatLng(pollutionSourcePoint.getLongitude(),pollutionSourcePoint.getLatitude()); | 
|---|
|  |  |  | 
|---|
|  |  |  | double deviceDataAvg = sum/allDeviceData.length; | 
|---|
|  |  |  | //计算污染源点与设备点之间的距离 | 
|---|
|  |  |  | double distance = mapUtils.getDistance(pollutionSourcePoint.getLongitude(),pollutionSourcePoint.getLatitude(),referenceDevice.getLongitude(),referenceDevice.getLatitude()); | 
|---|
|  |  |  | System.out.println("distance:"+distance); | 
|---|
|  |  |  | //已知距离,角度,求x,y | 
|---|
|  |  |  | double x = Math.cos(minDisparity.get().getValue())*distance; | 
|---|
|  |  |  | double y = Math.sin(minDisparity.get().getValue())*distance; | 
|---|
|  |  |  | System.out.println(minDisparity.get().getValue()); | 
|---|
|  |  |  | double x = Math.cos(Math.toRadians(minDisparity.get().getValue()))*distance; | 
|---|
|  |  |  | System.out.println("三角函数:"+Math.cos(minDisparity.get().getValue())); | 
|---|
|  |  |  | System.out.println(x); | 
|---|
|  |  |  | double y = Math.sin(Math.toRadians(minDisparity.get().getValue()))*distance; | 
|---|
|  |  |  | //获取设备的数值 | 
|---|
|  |  |  | String[] fiveMinuteData = fiveMinuteDataMap.get("e21").toString().split(","); | 
|---|
|  |  |  | String[] fiveMinuteData = fiveMinuteDataMap.get(sensorKey).toString().split(","); | 
|---|
|  |  |  | double c = Double.parseDouble(fiveMinuteData[0].substring(1,fiveMinuteData[0].length()))-deviceDataAvg; | 
|---|
|  |  |  | System.out.println(c); | 
|---|
|  |  |  | //计算源强 | 
|---|
|  |  |  | double pollutionSourceIntensity = EmissionDataUtil.getPollutionSourceIntensity(c,x,y,res.get("wind_speed")); | 
|---|
|  |  |  | System.out.println("c:"+c); | 
|---|
|  |  |  | System.out.println("x:"+x); | 
|---|
|  |  |  | System.out.println("y:"+y); | 
|---|
|  |  |  | System.out.println("风速:"+res.get("wind_speed")); | 
|---|
|  |  |  | System.out.println(pollutionSourceIntensity); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //存放地图中心点 | 
|---|
|  |  |  | 
|---|
|  |  |  | Map<String,Object> getFiveMinutesDataByMac(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> getFiveMinutesSersorDataByMacsAndTime(Map<String,Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> getFiveMinutesDataByMacsAndTimeSolt(Map<String,Object> parameters); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return historyFiveMinutelyMapper.getFiveMinutesSersorDataByMacsAndTime(parameters); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Map<String, Object>> getFiveMinutesDataByMacsAndTimeSolt(Map<String, Object> parameters) { | 
|---|
|  |  |  | ValidateUtil.notNull(parameters,"查询五分钟数据参数为空"); | 
|---|
|  |  |  | return historyFiveMinutelyMapper.getFiveMinutesDataByMacsAndTimeSolt(parameters); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.moral.util; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | 
|---|
|  |  |  | u1 = 0; | 
|---|
|  |  |  | v1 = wind_speed*1; | 
|---|
|  |  |  | }else if (0<wind_direction&&wind_direction<90){ | 
|---|
|  |  |  | u1 = wind_speed*Math.sin(wind_direction); | 
|---|
|  |  |  | v1 = wind_speed*Math.cos(wind_direction); | 
|---|
|  |  |  | u1 = wind_speed*Math.sin(Math.toRadians(wind_direction)); | 
|---|
|  |  |  | v1 = wind_speed*Math.cos(Math.toRadians(wind_direction)); | 
|---|
|  |  |  | }else if (wind_direction == 90){ | 
|---|
|  |  |  | u1 = wind_speed*1; | 
|---|
|  |  |  | v1 = 0; | 
|---|
|  |  |  | }else if (90<wind_direction&&wind_direction<180){ | 
|---|
|  |  |  | u1 = wind_speed*Math.sin(180-wind_direction); | 
|---|
|  |  |  | v1 = -1*wind_speed*Math.cos(180-wind_direction); | 
|---|
|  |  |  | u1 = wind_speed*Math.sin(Math.toRadians(180-wind_direction)); | 
|---|
|  |  |  | v1 = -1*wind_speed*Math.cos(Math.toRadians(180-wind_direction)); | 
|---|
|  |  |  | }else if (wind_direction == 180){ | 
|---|
|  |  |  | u1 = 0; | 
|---|
|  |  |  | v1 = wind_speed*-1; | 
|---|
|  |  |  | }else if (180<wind_direction&&wind_direction<270){ | 
|---|
|  |  |  | u1 = -1*wind_speed*Math.sin(wind_direction-180); | 
|---|
|  |  |  | v1 = -1*wind_speed*Math.cos(wind_direction-180); | 
|---|
|  |  |  | u1 = -1*wind_speed*Math.sin(Math.toRadians(wind_direction-180)); | 
|---|
|  |  |  | v1 = -1*wind_speed*Math.cos(Math.toRadians(wind_direction-180)); | 
|---|
|  |  |  | }else if (wind_direction == 270){ | 
|---|
|  |  |  | u1 = wind_speed*-1; | 
|---|
|  |  |  | v1 = 0; | 
|---|
|  |  |  | }else if (270<wind_direction&&wind_direction<360){ | 
|---|
|  |  |  | u1 = wind_speed*Math.sin(360-wind_direction); | 
|---|
|  |  |  | v1 = -1*wind_speed*Math.cos(360-wind_direction); | 
|---|
|  |  |  | u1 = wind_speed*Math.sin(Math.toRadians(360-wind_direction)); | 
|---|
|  |  |  | v1 = -1*wind_speed*Math.cos(Math.toRadians(360-wind_direction)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | u = u+u1; | 
|---|
|  |  |  | v = v+v1; | 
|---|
|  |  |  | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",0.0); | 
|---|
|  |  |  | }else if (u==0&&v>0){ | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",0.0); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",v); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",v/list.size()); | 
|---|
|  |  |  | }else if (u>0&&v>0){ | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",Math.atan2(u,v)); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",Math.toDegrees(Math.atan2(u,v))); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)/list.size()); | 
|---|
|  |  |  | }else if (u>0&&v==0){ | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",90.0); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",u); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",u/list.size()); | 
|---|
|  |  |  | }else if (u>0&&v<0){ | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",Math.atan2(-v,u)+90); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",Math.toDegrees(Math.atan2(-v,u))+90); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)/list.size()); | 
|---|
|  |  |  | }else if (u==0&&v<0){ | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",180.0); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",-v); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.abs(v)/list.size()); | 
|---|
|  |  |  | }else if (u<0&&v<0){ | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",Math.atan2(-u,-v)+180); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",Math.toDegrees(Math.atan2(-u,-v))+180); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)/list.size()); | 
|---|
|  |  |  | }else if (u<0&&v==0){ | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",270.0); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",-u); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.abs(u)/list.size()); | 
|---|
|  |  |  | }else if (u<0&&v>0){ | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",Math.atan2(v,-u)+270); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_direction",Math.toDegrees(Math.atan2(v,-u))+270); | 
|---|
|  |  |  | windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)/list.size()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return windDirectionSpeedMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /*public static void main(String[] args) { | 
|---|
|  |  |  | List list = new ArrayList(); | 
|---|
|  |  |  | Map map = new HashMap(); | 
|---|
|  |  |  | Map map2 = new HashMap(); | 
|---|
|  |  |  | map.put("wind_direction",45); | 
|---|
|  |  |  | map.put("wind_speed",1); | 
|---|
|  |  |  | map2.put("wind_direction",45); | 
|---|
|  |  |  | map2.put("wind_speed",1); | 
|---|
|  |  |  | list.add(map); | 
|---|
|  |  |  | list.add(map2); | 
|---|
|  |  |  | Map<String, Double> re = getWind_direction_speed(list); | 
|---|
|  |  |  | System.out.println(re); | 
|---|
|  |  |  | System.out.println(Math.toRadians(45)); | 
|---|
|  |  |  | System.out.println(Math.sin(Math.toRadians(45))); | 
|---|
|  |  |  | System.out.println(Math.cos(Math.toRadians(45))); | 
|---|
|  |  |  | }*/ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | #{mac} | 
|---|
|  |  |  | </foreach> | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <select id="getFiveMinutesDataByMacsAndTimeSolt" resultType="map"> | 
|---|
|  |  |  | select h.mac,h.time, | 
|---|
|  |  |  | <foreach collection="sensorKeys" separator="," item="sensorKey"> | 
|---|
|  |  |  | json->'$.${sensorKey}' AS '${sensorKey}' | 
|---|
|  |  |  | </foreach> | 
|---|
|  |  |  | FROM history_five_minutely_${yearAndMonth} h | 
|---|
|  |  |  | WHERE mac IN | 
|---|
|  |  |  | <foreach collection="macs" separator="," open="(" close=")" item="mac"> | 
|---|
|  |  |  | #{mac} | 
|---|
|  |  |  | </foreach> | 
|---|
|  |  |  | AND time BETWEEN #{startTime} AND #{endTime} | 
|---|
|  |  |  | ORDER BY h.time DESC | 
|---|
|  |  |  | LIMIT #{macNumber} | 
|---|
|  |  |  | </select> | 
|---|
|  |  |  | </mapper> | 
|---|