吉安感知网项目-后端
xiebin
2026-04-01 939e76b90691c8f4e66e437791bce9e11bc4bfad
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?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="org.sxkj.resource.mapper.IFileMapper">
    <select id="getPage" resultType="org.sxkj.resource.entity.MediaFileEntity">
        SELECT * FROM media_new_file WHERE workspace_id = #{workspaceId}
 
        <if test="query.startTime !=null and query.endTime !=null">
            AND DATE_FORMAT(FROM_UNIXTIME(create_time/1000,'%Y-%m-%d'),'%Y-%m-%d') &gt;=
            DATE_FORMAT(#{query.startTime},'%Y-%m-%d')
        </if>
 
        <if test="query.endTime !=null and query.endTime !=null">
            AND DATE_FORMAT(FROM_UNIXTIME(create_time/1000,'%Y-%m-%d'),'%Y-%m-%d') &lt;=
            DATE_FORMAT(#{query.endTime},'%Y-%m-%d')
        </if>
 
        <if test="query.name !=null and query.name !=null">
            AND file_name LIKE CONCAT('%',#{query.name},'%')
        </if>
 
        <if test="query.subFileType != null and query.subFileType !='' ">
            AND sub_file_type in
            <foreach collection="query.subFileType.split(',')" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
 
        <if test="query.payload != null and query.payload !='' ">
            AND payload LIKE CONCAT('%',#{query.payload},'%')
        </if>
        ORDER BY create_time DESC
    </select>
    <select id="mediaPage" resultType="org.sxkj.resource.model.MediaJobDTO">
        SELECT
        j.collect_status,
        m.job_id,
        t.url,
        COUNT( CASE WHEN m.file_name LIKE '%.mp4' THEN 1 END) AS videoCount,
        COUNT( CASE WHEN m.file_name LIKE '%.jpeg' THEN 1 END ) AS picCount,
        DATE_FORMAT(FROM_UNIXTIME(j.create_time/1000,'%Y-%m-%d'),'%Y-%m-%d') as create_time
        FROM
        media_file m LEFT JOIN wayline_job j ON m.job_id = j.job_id
        -- LEFT JOIN (SELECT CONCAT("https://dev.jxpskj.com:8026/cloud-bucket",object_key) as url,job_id from media_file
        WHERE file_name LIKE '%.jpeg' GROUP BY job_id) t ON t.job_id = m.job_id
        LEFT JOIN (SELECT CONCAT(#{param.fileAddress},object_key) as url,job_id from media_file WHERE file_name LIKE
        '%.jpeg' GROUP BY job_id) t ON t.job_id = m.job_id
        LEFT JOIN wayline_file w ON w.wayline_id = j.file_id
        where 1=1
        <if test="workspaceId != null and workspaceId != ''">
            and j.workspace_id = #{workspaceId}
        </if>
        <if test="param.dockSn !=null and param.dockSn != ''">
            and j.dock_sn = #{param.dockSn}
        </if>
        <if test="param.startTime !=null and param.endTime !=null">
            AND DATE_FORMAT(FROM_UNIXTIME(j.create_time/1000,'%Y-%m-%d'),'%Y-%m-%d') &gt;=
            DATE_FORMAT(#{param.startTime},'%Y-%m-%d')
        </if>
 
        <if test="param.endTime !=null and param.endTime !=null">
            AND DATE_FORMAT(FROM_UNIXTIME(j.create_time/1000,'%Y-%m-%d'),'%Y-%m-%d') &lt;=
            DATE_FORMAT(#{param.endTime},'%Y-%m-%d')
        </if>
        <if test="param.waylineFileId != null and param.waylineFileId != ''">
            and w.wayline_id = #{param.waylineFileId}
        </if>
        GROUP BY m.job_id
        ORDER BY
        <if test="param.sort eq 2">
            j.collect_status = 1 desc,
        </if>
        <if test="param.sort eq 3">
            m.collect_status = 1 desc,
        </if>
        j.create_time desc
    </select>
    <select id="mediaDetail" resultType="org.sxkj.resource.model.MediaJobDTO">
        SELECT
        m.collect_status,
        m.job_id,
        m.file_id,
        CONCAT(#{fileAddress},m.object_key) as url,
        CASE WHEN m.file_name LIKE '%.mp4' THEN "视频" ELSE "图片" END AS type,
        DATE_FORMAT( FROM_UNIXTIME( m.create_time / 1000, '%Y-%m-%d' ), '%Y-%m-%d' ) AS create_time
        FROM
        media_file m
        WHERE
        1 = 1
        <if test="jobId != null and jobId != ''">
            and m.job_id = #{jobId}
        </if>
        ORDER BY type = '视频' DESC
    </select>
 
    <!--查询odm 信息-->
    <select id="getOdm" resultType="org.sxkj.common.model.OdmUrlDto">
        SELECT
        odm.base_path basePath,
        wj.dkbh,
        IFNULL(odm.ort_tb_path,odm.orthoimage_path) path,
        FROM_UNIXTIME( wj.completed_time/ 1000) as createTime,
        md.nickname as airportName
        FROM
        odm_task_info odm
        LEFT JOIN wayline_job wj ON wj.job_id = odm.wayline_job_id
        LEFT JOIN manage_device md on md.device_sn = wj.dock_sn
        <where>
            AND wj.job_type = 4
            AND wj.workspace_id = #{workspaceId}
            <if test="dkbhList != null and dkbhList.size() > 0">
                AND wj.dkbh in
                <foreach collection="dkbhList" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="startTime != null and startTime != ''  and endTime != null  and endTime != ''">
                AND date_format(FROM_UNIXTIME( wj.completed_time/1000),'%Y-%m-%d') between #{startTime} and #{endTime}
            </if>
            AND odm.running_progress = 1.00
            AND odm.orthoimage_path IS NOT NULL
            ORDER BY
            wj.end_time DESC
        </where>
    </select>
 
 
    <select id="getMediaFieByTid" resultType="org.sxkj.resource.entity.MediaFileEntity">
        select *
        from (SELECT *
              from media_new_file
              where drone = #{deviceId}) a
        where CAST(JSON_EXTRACT(metadata, '$.createdTime') AS UNSIGNED) >= #{timestamp}
        ORDER BY CAST(JSON_EXTRACT(metadata, '$.createdTime') / 1000 AS UNSIGNED) ASC
        LIMIT 1;
    </select>
 
    <!--媒体文件信息查询-->
    <select id="getMediaFileByObjectKey" resultType="org.sxkj.resource.entity.MediaFileEntity">
        SELECT *
        FROM media_new_file
        WHERE object_key = #{objectKey}
        limit 1
    </select>
 
    <!--根据类型获取数据成果数量-->
    <select id="getMediaFileCountByResultType" resultType="org.sxkj.resource.vo.MediaFileCountVO">
        SELECT
        IFNULL( sum( CASE WHEN result_type = 0 THEN 1 ELSE 0 END ), 0 ) AS "phoneNum",
        IFNULL( sum( CASE WHEN result_type = 1 THEN 1 ELSE 0 END ), 0 ) AS "videoNum",
        IFNULL( sum( CASE WHEN result_type = 2 THEN 1 ELSE 0 END ), 0 ) AS "aiNum",
        IFNULL( sum( CASE WHEN result_type = 3 THEN 1 ELSE 0 END ), 0 ) AS "gisNum",
        IFNULL( sum( CASE WHEN result_type = 4 THEN 1 ELSE 0 END ), 0 ) AS "tifNum",
        IFNULL( sum( CASE WHEN result_type = 5 THEN 1 ELSE 0 END ), 0 ) AS "fullNum"
        FROM
        blade_attach a
        LEFT JOIN wayline_job wj ON a.wayline_job_id = wj.job_id
        left JOIN wayline_job_info wji ON wji.id = wj.job_info_id AND wji.is_deleted = 0
        left join drone_job_event_rela rela on a.id = rela.attach_id
        <where>
            <if test="resultType != null">
                AND a.result_type = #{resultType}
            </if>
            <if test="areaCode != null and areaCode != ''">
                AND wj.area_code LIKE CONCAT(#{areaCode}, '%')
            </if>
 
            <if test="deptIdList!=null and deptIdList.size>0">
                AND a.create_dept IN
                <foreach collection="deptIdList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="permissionCondition != null and permissionCondition != ''">
                AND ${permissionCondition}
            </if>
            AND (rela.is_deleted = 0 or rela.is_deleted is null)
            AND a.is_deleted = 0
            AND wji.is_deleted = 0
            AND wj.job_info_id is not null
            AND a.result_type IN ( 0, 1, 2, 3, 4, 5,15 )
        </where>
    </select>
 
 
    <!-- 计算三维面积 -->
    <select id="calculateTheThreeDimensionalArea" resultType="org.sxkj.resource.vo.MediaFileCountVO">
        SELECT
        ROUND( sum( wj3d.area ) / 1000000, 2 ) AS gisNum
        FROM
        blade_attach a
        LEFT JOIN wayline_job wj ON a.wayline_job_id = wj.job_id
        left JOIN wayline_job_info wji ON wji.id = wj.job_info_id AND wji.is_deleted = 0
        left join drone_job_event_rela rela on a.id = rela.attach_id
        left join wayline_job_3d_record wj3d on wj3d.job_id = wj.job_id
        <where>
            <if test="resultType != null">
                AND a.result_type = #{resultType}
            </if>
            <if test="areaCode != null and areaCode != ''">
                AND wj3d.area_code LIKE CONCAT(#{areaCode}, '%')
            </if>
            <if test="deptIdList!=null and deptIdList.size>0">
                AND a.create_dept IN
                <foreach collection="deptIdList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="permissionCondition != null and permissionCondition != ''">
                AND ${permissionCondition}
            </if>
            AND (rela.is_deleted = 0 or rela.is_deleted is null)
            AND a.is_deleted = 0
            AND wji.is_deleted = 0
            AND wj.job_info_id is not null
            AND a.result_type in (3,13)
            AND wj3d.is_deleted = 0
        </where>
    </select>
 
    <!--根据类型获取数据成果数量-->
    <select id="getCountByResultType" resultType="org.sxkj.resource.vo.MediaFileCountVO">
        SELECT
        IFNULL( sum( CASE WHEN result_type = 3 THEN 1 ELSE 0 END ), 0 ) AS "gisNum",
        IFNULL( sum( CASE WHEN result_type = 5 THEN 1 ELSE 0 END ), 0 ) AS "fullNum"
        FROM
        blade_attach a
        LEFT JOIN blade_dept b ON (a.create_dept = b.id)
        <where>
            -- 成果类型:0图片,1=视频,2=ai,3=三维,4=正射,5=全景, 6=图片压缩小,7=图片压缩中,8视频一帧图,9视频压缩,10ai压缩小,11ai压缩中',
            AND a.result_type IN ( 3, 5 )
            AND a.is_deleted = 0
        </where>
    </select>
 
 
    <select id="timeEventNumStatistics" resultType="org.sxkj.resource.vo.JobStatisticsTimeVoBo">
        select count(*) "num", DATE_FORMAT(create_time,#{formatTime}) "time"
        FROM
        blade_attach a
        LEFT JOIN wayline_job wj ON a.wayline_job_id = wj.job_id
        left JOIN wayline_job_info wji ON wji.id = wj.job_info_id and wji.is_deleted = 0
        LEFT JOIN blade_dept b ON (a.create_dept = b.id)
        <where>
            <if test="startDate!=null">
                and a.create_time &gt;= #{startDate}
            </if>
            <if test="endDate!=null">
                and a.create_time &lt;= #{endDate}
            </if>
            and a.result_type in(0,1)
            and a.is_deleted = 0
        </where>
        group by DATE_FORMAT(create_time,#{formatTime})
    </select>
 
    <select id="countEventNumStatistics" resultType="java.lang.Long">
        select count(*) "num"
        FROM
        blade_attach a
        LEFT JOIN wayline_job wj ON a.wayline_job_id = wj.job_id
        left JOIN wayline_job_info wji ON wji.id = wj.job_info_id and wji.is_deleted = 0
        LEFT JOIN blade_dept b ON (a.create_dept = b.id)
        <where>
            <if test="startDate!=null">
                and a.create_time &gt;= #{startDate}
            </if>
            <if test="endDate!=null">
                and a.create_time &lt;= #{endDate}
            </if>
            and a.result_type in(0,1)
            and a.is_deleted = 0
        </where>
    </select>
 
 
    <!--媒体文件信息更新-->
    <update id="updateMediaFileByObjectKey">
        update media_new_file
        set min_object_key = #{minObjectKey}
        WHERE object_key = #{objectKey}
    </update>
 
 
    <delete id="batchDeleteByKeys" parameterType="java.util.List">
        DELETE FROM media_new_file
        WHERE id IN
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
 
 
    <select id="findNearByMediaUrl" resultType="org.sxkj.resource.entity.MediaFileEntity">
        SELECT domain_url,file_path,file_name,create_time
        FROM media_new_file
        WHERE ST_Distance_Sphere(
        POINT(#{longitude}, #{latitude}),
        POINT(json_extract(metadata,"$.shootPosition.lng"), json_extract(metadata,"$.shootPosition.lat"))
 
        ) &lt;= #{distance}
        <if test="startDate!=null">
            and create_time &gt;=#{startDateLong}
        </if>
        <if test="endDate!=null">
            and create_time &lt;=#{endDateLong}
        </if>
    </select>
</mapper>