lizijie
2020-12-03 a66d53c3cbfb0024804045f4d795be06089d4f9d
五分钟表相关代码,平均风向、平局风速工具类
1 files added
4 files modified
109 ■■■■■ changed files
src/main/java/com/moral/mapper/HistoryFiveMinutelyMapper.java 1 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/HistoryFiveMinutelyService.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/HistoryFiveMinutelyServiceImpl.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/util/WindUtils.java 88 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/HistoryFiveMinutelyMapper.xml 12 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/mapper/HistoryFiveMinutelyMapper.java
@@ -9,4 +9,5 @@
    Map<String,Object> getFiveMinutesDataByMac(Map<String,Object> parameters);
    List<Map<String,Object>> getFiveMinutesSersorDataByMacsAndTime(Map<String,Object> parameters);
}
src/main/java/com/moral/service/HistoryFiveMinutelyService.java
@@ -7,4 +7,6 @@
    List<Map<String, Object>> getFiveMinutesDataByMacsAndTime(Map<String, Object> parameters);
    Map<String,Object> getFiveMinutesDataByMac(Map<String, Object> parameters);
    List<Map<String, Object>> getFiveMinutesSersorDataByMacsAndTime(Map<String,Object> parameters);
}
src/main/java/com/moral/service/impl/HistoryFiveMinutelyServiceImpl.java
@@ -26,5 +26,11 @@
        return historyFiveMinutelyMapper.getFiveMinutesDataByMac(parameters);
    }
    @Override
    public List<Map<String, Object>> getFiveMinutesSersorDataByMacsAndTime(Map<String, Object> parameters) {
        ValidateUtil.notNull(parameters,"查询五分钟数据参数为空");
        return historyFiveMinutelyMapper.getFiveMinutesSersorDataByMacsAndTime(parameters);
    }
}
src/main/java/com/moral/util/WindUtils.java
New file
@@ -0,0 +1,88 @@
package com.moral.util;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class WindUtils {
    /**
     *@Description: 根据方向和风速,获取UV风向
     * @return:                                                                <                                                               com.moral.entity.Device>>
     * @Author: lizijie
     * @Date: 2020/12/03
     *
     * */
    public static Map<String, Double> getWind_direction_speed(List<Map<String, Object>> list){
        //定义u:水平方向,v:竖直方向
        double u = 0;
        double v = 0;
        for (Map map:list) {
            double u1 = 0;
            double v1 = 0;
            double wind_speed = Double.parseDouble(map.get("wind_speed").toString());
            double wind_direction = Double.parseDouble(map.get("wind_direction").toString());
            if (wind_speed == 0){
                continue;//如果风速为0,结束此次循环,进入下次循环
            }
            if (wind_direction==0){
                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);
            }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);
            }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);
            }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);
            }
            u = u+u1;
            v = v+v1;
        }
        Map<String,Double> windDirectionSpeedMap = new HashMap<>();
        if (u==0&&v==0){
            windDirectionSpeedMap.put("wind_direction",0.0);
            windDirectionSpeedMap.put("wind_speed",0.0);
        }else if (u==0&&v>0){
            windDirectionSpeedMap.put("wind_direction",0.0);
            windDirectionSpeedMap.put("wind_speed",v);
        }else if (u>0&&v>0){
            windDirectionSpeedMap.put("wind_direction",Math.atan2(u,v));
            windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v));
        }else if (u>0&&v==0){
            windDirectionSpeedMap.put("wind_direction",90.0);
            windDirectionSpeedMap.put("wind_speed",u);
        }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));
        }else if (u==0&&v<0){
            windDirectionSpeedMap.put("wind_direction",180.0);
            windDirectionSpeedMap.put("wind_speed",-v);
        }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));
        }else if (u<0&&v==0){
            windDirectionSpeedMap.put("wind_direction",270.0);
            windDirectionSpeedMap.put("wind_speed",-u);
        }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));
        }
        return windDirectionSpeedMap;
    }
}
src/main/resources/mapper/HistoryFiveMinutelyMapper.xml
@@ -20,4 +20,16 @@
        where  h.time = #{time}
        and h.mac = #{mac}
    </select>
    <select id="getFiveMinutesSersorDataByMacsAndTime" 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 time = #{time} and mac IN
        <foreach collection="macs" separator="," open="(" close=")" item="mac">
            #{mac}
        </foreach>
    </select>
</mapper>