cjl
2023-10-25 7e0534d52520407b1005e9a5f20945d927e92408
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?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.api.mapper.HistorySecondCruiserMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.moral.api.entity.HistorySecondCruiser">
        <result column="mac" property="mac"/>
        <result column="time" property="time"/>
        <result column="value" property="value"/>
        <result column="organization_id" property="organizationId"/>
        <result column="batch" property="batch"/>
    </resultMap>
 
    <select id="getDates" resultType="java.lang.String">
        SELECT DISTINCT DATE_FORMAT(`time`,'%Y-%m-%d') `time`
        FROM history_second_cruiser
        WHERE mac = #{mac}
        AND organization_id = #{orgId}
        AND `time` <![CDATA[>=]]> #{start}
        ORDER BY `time`
    </select>
 
    <select id="getCruiserData" resultType="java.util.Map">
        SELECT
        DATE_FORMAT(`time`, #{dateFormat}) AS `time`,
        `value`
        FROM `history_second_cruiser`
        WHERE mac = #{mac}
        AND `time` <![CDATA[>=]]> #{time1}
        AND `time` <![CDATA[<=]]> #{time2}
        AND organization_id = #{orgId}
    </select>
 
    <select id="getCruiserDataNewAvg" resultType="com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserListDTO">
        select  DATE_FORMAT(`time`, #{dateFormat}) AS time,value ->>'$.flylat' as flyLat,value ->>'$.flylon' as flyLon ,
           value ->> #{type} as num
        from history_second_cruiser
        WHERE mac = #{mac}
          AND `time` <![CDATA[>=]]> #{time1}
          AND `time` <![CDATA[<=]]> #{time2}
        <if test="orgId !=null and orgId != 0">
            AND organization_id = #{orgId}
        </if>
        <if test="orgIds != null and orgIds.size !=0">
            and organization_id in
            <foreach collection="orgIds" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        order by time
    </select>
 
    <select id="getDaily" resultType="java.lang.String">
        select AVG(JSON_EXTRACT(value,'$.dustld'))
        from `history_second_cruiser`
        WHERE mac = #{mac}
          AND `time` <![CDATA[>=]]> #{time1}
          AND `time` <![CDATA[<=]]> #{time2}
    </select>
 
    <select id="getDust" resultType="java.lang.String">
        select value ->>'$.dustld'
        from `history_second_cruiser`
        WHERE mac = #{mac}
          AND `time` <![CDATA[>=]]> #{start}
          AND `time` <![CDATA[<=]]> #{end}
    </select>
 
 
    <select id="getAllCruiserData" resultType="java.util.Map">
        SELECT
        `value`
        FROM `history_second_cruiser`
        WHERE mac = #{mac}
        AND `time` <![CDATA[>=]]> #{time1}
        AND `time` <![CDATA[<=]]> #{time2}
    </select>
 
 
    <select id="getDusts" resultType="java.util.Map">
        SELECT
            value ->>'$.flylat' as flyLat,value ->>'$.flylon' as flyLon,value ->>'$.dustld' as dustld,
            `time`
        FROM `history_second_cruiser`
        WHERE mac = #{mac}
          AND `time` <![CDATA[>=]]> #{startTime}
          AND `time` <![CDATA[<=]]> #{endTime}
    </select>
</mapper>