jinpengyong
2023-11-10 c8cc61e84189d8f986f7c4657d543408021b3da0
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
<?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="getCruiserInfo" resultType="com.moral.api.pojo.dto.cruiser.CruiserDTO">
        select  DATE_FORMAT(`time`, #{dateFormat}) AS time,value ->>'$.flylat' as flyLat,value ->>'$.flylon' as flyLon
        from history_second_cruiser
        WHERE mac = #{mac}
          AND `time` <![CDATA[>=]]> #{time1}
          AND `time` <![CDATA[<=]]> #{time2}
        order by time
    </select>
 
    <select id="cruiserList" resultType="com.moral.api.pojo.dto.cruiser.CruiserListDTO">
        WITH zb AS (
        SELECT
        DATE_FORMAT( `time`, '%Y-%m-%d %H:%i:%s' ) AS time,VALUE->> '$.flylat' AS flyLat,VALUE->> '$.flylon' AS flyLon
        FROM
        history_second_cruiser
        WHERE
        mac =  #{mac}
        AND `time` <![CDATA[>=]]> #{time1}
        AND `time` <![CDATA[<=]]> #{time2}
        ORDER BY
        time
        ),
        resultList AS (
        SELECT
        t1.time,
        t1.flyLat,
        t1.flyLon
        FROM
        zb t1
        INNER JOIN ( SELECT flyLon, flyLat, MAX( time ) AS max_time FROM zb GROUP BY flyLat, flyLon ) t2 ON t1.flyLon = t2.flyLon
        AND t1.flyLat = t2.flyLat
        AND t1.time = t2.max_time
        ),
        mx AS (
        SELECT t2.latitude,
            t2.longitude,
            t2.state,
            t2.coordinate_id ,max(t2.id) id
        FROM
        manage_coordinate t1
        LEFT JOIN manage_coordinate_detail t2 ON t1.coordinate_id = t2.coordinate_id
        LEFT JOIN special_device t3 ON t1.organization_id = t3.organization_id
        WHERE
        t1.is_del = 0
        AND t3.mac = #{mac} group by t2.latitude,
            t2.longitude,
            t2.state,
            t2.coordinate_id
        ) SELECT
        tt.time,
        tt.flyLat,
        tt.flyLon,
        COALESCE ( tt1.state, 0 ) AS state ,tt1.coordinate_id,tt1.id as id
        FROM
        resultList tt
        LEFT JOIN mx tt1 ON tt.flyLat = tt1.latitude
        AND tt.flyLon = tt1.longitude
    </select>
 
</mapper>