吉安感知网项目-后端
linwei
2026-06-09 3ba4841f2f11d4fcadb78a4891595e9368323571
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
<?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.AttachMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="attachResultMap" type="org.sxkj.resource.entity.Attach">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="link" property="link"/>
        <result column="domain_url" property="domainUrl"/>
        <result column="name" property="name"/>
        <result column="original_name" property="originalName"/>
        <result column="extension" property="extension"/>
        <result column="attach_size" property="attachSize"/>
        <result column="result_type" property="resultType" typeHandler="org.sxkj.common.handler.GenericListTypeHandler"/>
    </resultMap>
 
    <!--自定义分页查询-->
    <select id="selectAttachPage" resultMap="attachResultMap" >
        select
        ba.*,
        bd.dept_name,
        coalesce(ba.nick_name,ba.original_name) nickName
        from
        blade_attach ba
        left join
        /* 修改点1:双向转为 text 对齐 */
        blade_dept bd on ba.create_dept::text = bd.id::text
        where
        ba.is_deleted = 0
        <if test="attach.nickName!=null and attach.nickName!=''">
            and ba.nick_name like concat('%',#{attach.nickName},'%')
        </if>
        <if test="attach.resultType!=null and attach.resultType!='' ">
            /* 将逗号分隔的字符串转换为带引号的格式,如 "road,road1" 转为 "\"road\",\"road1\"" */
            and ba.result_type like concat('%',
            (
            select string_agg(concat('"', trim(arr_val), '"'), ',')
            from unnest(string_to_array(#{attach.resultType}, ',')) as arr_val
            ),
            '%')
        </if>
        <if test="attach.deptList != null and attach.deptList.size > 0">
            and ba.create_dept::text in
            <foreach collection="attach.deptList" item="deptId" open="(" separator="," close=")">
                #{deptId}::text
            </foreach>
        </if>
          order by ba.create_time desc, ba.id desc
    </select>
 
    <select id="findAiAttachImages" resultType="org.sxkj.resource.vo.AttachVO">
        select
        DISTINCT attach.id,
        attach.link,
        attach.name,
        COALESCE( attach.nick_name,SUBSTRING_INDEX( SUBSTRING_INDEX( attach.NAME, '/', - 1 ), '.', 1 )) AS nick_name,
        attach.original_name,
        attach.extension,
        attach.device_sn,
        attach.workspace_id,
        attach.metadata,
        attach.result_type,
        attach.create_time,
        attach.longitude,
        attach.latitude,
        attach.media_create_time,
        attach.media_category,
        rela.event_num,
        rela.event_name,
        wj.name AS job_name,
        rela.status
        from blade_attach attach
        left join drone_job_event_rela rela on attach.id::VARCHAR = rela.attach_id::VARCHAR
        left join wayline_job wj ON attach.wayline_job_id::VARCHAR = wj.job_id::VARCHAR
        left join wayline_job_info info on wj.job_info_id::VARCHAR = info.id::VARCHAR
        where attach.is_deleted = 0
        and info.is_deleted = 0
        and attach.is_thumbnail = 0
        and (rela.is_deleted = 0 or rela.is_deleted is null)
        and wj.`status` in (2, 3, 5, 6, 7)
        <if test="attach.jobName!=null and attach.jobName!=''">
            and wj.name like concat('%',#{attach.jobName},'%')
        </if>
        <if test="attach.startTime!=null and attach.startTime!='' and attach.endTime!=null and attach.endTime!='' ">
            AND wj.begin_time &gt;= UNIX_TIMESTAMP(CONCAT(#{attach.startTime},' 00:00:00')) * 1000
            AND wj.begin_time &lt;= UNIX_TIMESTAMP(CONCAT(#{attach.endTime},' 23:59:59')) * 1000
        </if>
 
        <if test="attach.resultTypes!=null and attach.resultTypes.size()>0">
            and attach.result_type in
            <foreach collection="attach.resultTypes" item="resultType" open="(" close=")" separator=",">
                #{resultType}
            </foreach>
        </if>
 
        <if test="attach.wordOrderType!=null and attach.wordOrderType!=''">
            and rela.work_order_type_dict_key = #{attach.wordOrderType}
        </if>
        <if test="attach.aiStatus!=null">
            and rela.status = #{attach.aiStatus}
            and rela.is_draft = 0
            and rela.md5 is not null and rela.md5 != ''
        </if>
        <if test="attach.photoType!=null and attach.photoType!=''">
            <choose>
                <when test="attach.photoType=='visable'">
                    and attach.media_category = 0
                </when>
                <when test="attach.photoType=='ir'">
                    and attach.media_category = 1
                </when>
            </choose>
        </if>
        <if test="attach.md5s!=null and attach.md5s.size()>0">
            and attach.md5 in
            <foreach collection="attach.md5s" item="md5" separator="," open="(" close=")">
                #{md5}
            </foreach>
        </if>
        <if test="attach.wayLineJobIdList!=null and attach.wayLineJobIdList.size>0">
            and attach.wayline_job_id in
            <foreach collection="attach.wayLineJobIdList" item="wayLineJobId" separator="," open="(" close=")">
                #{wayLineJobId}
            </foreach>
        </if>
        <if test="attach.deviceSn!=null and attach.deviceSn!=''">
            and attach.device_sn = #{attach.deviceSn}
        </if>
        <if test="deptIdList!=null and deptIdList.size>0">
            AND attach.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>
        <if test="attach.orderByCreateTime!=null">
            <choose>
                <when test="attach.orderByCreateTime">
                    order by attach.media_create_time desc
                </when>
                <otherwise>
                    order by attach.media_create_time asc
                </otherwise>
            </choose>
        </if>
 
    </select>
 
    <select id="findAllMd5ByAi" resultType="org.sxkj.resource.vo.EventImgMd5VO">
        select md5,original_md5
        from drone_job_event_rela rela
        left join ai_event_record record on rela.ai_event_record_uuid::VARCHAR = record.uuid::VARCHAR
        <where>
            and record.id in
            <foreach collection="aiRecordIds" item="eventRecordId" separator="," open="(" close=")">
                #{eventRecordId}
            </foreach>
        </where>
    </select>
    <select id="findAiMd5s" resultType="java.lang.String">
        select md5s from ai_event_record
        <where>
            and id in
            <foreach collection="aiRecordIds" item="eventRecordId" separator="," open="(" close=")">
                #{eventRecordId}
            </foreach>
        </where>
    </select>
    <!--自定义分页查询-->
    <select id="selectEventAttachPage" resultType="org.sxkj.resource.vo.AttachVO">
        select
        DISTINCT
        attach.id,
        attach.link,
        attach.name,
        attach.nick_name,
        attach.original_name,
        attach.extension,
        attach.device_sn,
        attach.workspace_id,
        attach.metadata,
        attach.create_time,
        rela.status
        from blade_attach attach
        right join drone_job_event_rela rela on attach.id::VARCHAR = rela.attach_id::VARCHAR
        where attach.is_deleted = 0 and attach.is_thumbnail = 0
        <if test="attach.nickName != null and attach.nickName != ''">
            AND (nick_name LIKE CONCAT('%', #{attach.nickName}, '%') OR name LIKE CONCAT('%', #{attach.nickName}, '%'))
        </if>
        <if test="attach.originalName!=null and attach.originalName!=''">
            and attach.original_name like concat('%',#{attach.originalName},'%')
        </if>
        <if test="attach.extension!=null and attach.extension!=''">
            and attach.extension like concat('%',#{attach.extension},'%')
        </if>
        <if test="attach.startTime!=null and attach.startTime!=''">
            and date_format(attach.create_time,'%Y-%m-%d') &gt;= #{attach.startTime}
        </if>
        <if test="attach.endTime!=null and attach.endTime!=''">
            and date_format(attach.create_time,'%Y-%m-%d') &lt;= #{attach.endTime}
        </if>
        <if test="attach.resultType!=null">
            and attach.result_type = #{attach.resultType}
        </if>
        <if test="attach.wayLineJobId!=null and attach.wayLineJobId!=''">
            and attach.wayline_job_id = #{attach.wayLineJobId}
        </if>
        <if test="attach.deviceSn!=null and attach.deviceSn!=''">
            and attach.device_sn = #{attach.deviceSn}
        </if>
 
        order by attach.create_time desc,attach.id desc
    </select>
 
    <select id="findAttachImages" resultType="org.sxkj.resource.vo.AttachVO">
        select
        attach.id,
        attach.link,
        attach.name,
        attach.attach_size,
        COALESCE( attach.nick_name,SUBSTRING_INDEX( SUBSTRING_INDEX( attach.NAME, '/', - 1 ), '.', 1 )) nick_name,
        attach.original_name,
        attach.extension,
        attach.device_sn,
        attach.workspace_id,
        attach.metadata,
        attach.create_time,
        attach.result_type,
        attach.wayline_job_id,
        attach.is_change_monitor,
        rela.event_num,
        rela.event_name,
        rela.status,
        mde.longitude dockLongitude,
        mde.latitude dockLatitude,
        CASE
        WHEN attach.media_category = 0 THEN 'visible'
        WHEN attach.media_category = 1 THEN 'ir'
        ELSE 'unknown'
        END AS photoType,
        DATE_FORMAT(FROM_UNIXTIME(job.execute_time/1000,'%Y-%m-%d %H:%i:%s'),'%Y-%m-%d %H:%i:%s') jobTime,
        job.name job_name,
        <if test="attach.areaCode != null and attach.areaCode != ''">
            <choose>
                <when test="attach.areaCode.length() == 2">
                    CONCAT_WS(',', region.province_name, region.city_name, region.district_name) region_name,
                </when>
                <when test="attach.areaCode.length() == 4">
                    CONCAT_WS(',', region.city_name, region.district_name) region_name,
                </when>
                <otherwise>
                    CONCAT_WS(',', region.province_name, region.city_name, region.district_name) region_name,
                </otherwise>
            </choose>
        </if>
        device.nickName nestName
        from blade_attach attach
        left join wayline_job job on attach.wayline_job_id::VARCHAR = job.job_id::VARCHAR
        left join wayline_job_info wji on wji.id = job.job_info_id::VARCHAR
        left join manage_device device on job.dock_sn = device.device_sn::VARCHAR
        left join manage_device_expansion mde on job.dock_sn = mde.device_sn::VARCHAR
        left join blade_region region on device.area_code = region.code::VARCHAR
        left join drone_job_event_rela rela on attach.id = rela.attach_id::VARCHAR
        where
        attach.is_deleted = 0
        and wji.is_deleted = 0
        and (rela.is_deleted = 0 or rela.is_deleted is null)
        and job.job_info_id is not null
        <if test="attach.startTime!=null and attach.startTime!='' and attach.endTime!=null and attach.endTime!=''">
            and (DATE_FORMAT(FROM_UNIXTIME(job.execute_time/1000,'%Y-%m-%d %H:%i:%s'),'%Y-%m-%d %H:%i:%s') between
            #{attach.startTime} and #{attach.endTime} or rela.create_time between #{attach.startTime}::timestamp and #{attach.endTime}::timestamp )
        </if>
        <if test="attach.name!=null and attach.name!=''">
            and COALESCE(attach.nick_name, SUBSTRING_INDEX(SUBSTRING_INDEX(attach.NAME, '/', -1), '.', 1))
            like concat('%',#{attach.name},'%')
        </if>
        <if test="attach.jobName!=null and attach.jobName!=''">
            and job.name like concat('%',#{attach.jobName},'%')
        </if>
        <if test="!attach.resultTypes.isEmpty()">
            and attach.result_type in
            <foreach collection="attach.resultTypes" item="resultType" open="(" close=")" separator=",">
                #{resultType}
            </foreach>
        </if>
 
        <if test="attach.resultTypes.isEmpty()">
            and attach.result_type in (0,1,2,3,4,5)
        </if>
 
        <if test="attach.resultType != null">
            and attach.result_type = #{attach.resultType}
        </if>
 
        <if test="attach.wordOrderType!=null and attach.wordOrderType!=''">
            and JSON_CONTAINS(rela.ai_type,CONCAT('"', #{attach.wordOrderType}, '"'))
        </if>
 
        <if test="attach.photoType != null and attach.photoType != ''">
            <choose>
                <when test="attach.photoType == 'visible'">
                    and attach.media_category = 0
                </when>
                <when test="attach.photoType == 'ir'">
                    and attach.media_category = 1
                </when>
            </choose>
        </if>
 
        <if test="attach.wayLineJobId!=null and attach.wayLineJobId!=''">
            and attach.wayline_job_id = #{attach.wayLineJobId}
        </if>
        <if test="attach.deviceSn!=null and attach.deviceSn!=''">
            and attach.device_sn = #{attach.deviceSn}
        </if>
 
        <if test="deptIdList!=null and deptIdList.size>0">
            AND (attach.create_dept IN
            <foreach collection="deptIdList" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
            OR rela.update_user = #{userId})
        </if>
        <if test="permissionCondition != null and permissionCondition != ''">
            AND ${permissionCondition}
        </if>
        <if test="attach.orderByCreateTime!=null">
            <choose>
                <when test="attach.orderByCreateTime">
                    order by job.execute_time desc
                </when>
                <otherwise>
                    order by attach.media_create_time DESC
                </otherwise>
            </choose>
        </if>
        <if test="attach.orderAsc!=null">
            <choose>
                <when test="attach.orderAsc">
                    order by attach.media_create_time asc
                </when>
                <otherwise>
                    order by attach.media_create_time desc
                </otherwise>
            </choose>
        </if>
    </select>
 
 
    <select id="getDeptAllSize" resultType="org.sxkj.resource.vo.DeptAndSizeVo">
 
        select a.dept_name as name, a.id as id, COALESCE(b.storageUse, 0) as storageUse
        FROM blade_dept a
                 LEFT JOIN (select create_dept, sum(attach_size) storageUse
                            from blade_attach
                            where is_deleted = 0
                              and create_time &gt; #{startTime}
                              and create_time &lt; #{endTime}
                            GROUP BY create_dept) b
                           on (a.id = b.create_dept::VARCHAR)
    </select>
 
    <!--判断附件是否已存在-->
    <select id="getAttachNumberByParam" resultType="java.lang.Integer">
        select count(*)
        from blade_attach
        where name = #{attach.name}
    </select>
 
    <!--查询正射的图片信息-->
    <select id="getHisOrtPicList" resultType="org.sxkj.resource.entity.Attach">
        select id, original_name
        from blade_attach
        where is_deleted = 0
          and result_type = 4
    </select>
 
    <!--查询媒体属性根据图片,名称-->
    <select id="findMetaDataByName" resultType="org.sxkj.resource.entity.Attach">
        select metadata,original_name from blade_attach where original_name in
        <foreach collection="names" item="name" open="(" close=")" separator=",">
            #{name}
        </foreach>
    </select>
 
 
    <select id="mapAreaCodeAttachStatistics" resultType="org.sxkj.resource.vo.AttachStatisticsBo">
        select
        device.area_code "dictKey",
        count(*)"num"
        from blade_attach attach
        left join manage_device device on attach.device_sn = device.device_sn::VARCHAR
        left join wayline_job job on attach.wayline_job_id = job.job_id::VARCHAR
        left join wayline_job_info wji on wji.id = job.job_info_id::VARCHAR
        <where>
            and attach.is_deleted = 0
            and wji.is_deleted = 0
            <if test="resultType!=null and resultType!=''">
                and attach.result_type =#{resultType}
            </if>
            <if test="deviceSn!=null and deviceSn!=''">
                and device.device_sn =#{deviceSn}
            </if>
            <if test="startTime!=null">
                and job.execute_time &gt;=#{startTime}
            </if>
            <if test="endTime!=null">
                and job.execute_time &lt;= #{endTime}
            </if>
            <if test="wayLineJobId!=null">
                and attach.wayline_job_id =#{wayLineJobId}
            </if>
            <if test="jobName!=null and jobName!=''">
                and job.name like concat('%',#{jobName},'%')
            </if>
        </where>
        group by device.area_code
    </select>
    <!--先放这里-->
    <select id="mapAreaCodeZhenSheStatistics" resultType="org.sxkj.resource.vo.AttachStatisticsBo">
        SELECT
        count(*) "num"
        device.area_code "dictKey"
        FROM
        odm_task_info oti
        LEFT JOIN wayline_job wj ON wj.job_id = oti.wayline_job_id::VARCHAR
        LEFT JOIN manage_device device ON wj.dock_sn = device.device_sn::VARCHAR
        LEFT JOIN tb_lot_info tli ON tli.dkbh = wj.dkbh::VARCHAR
        WHERE
        ( wj.job_type = 4 OR wj.job_type = 2 )
        AND oti.running_progress = 1.00::VARCHAR
        <if test="startDate!=null">
            and oti.create_time &gt;=#{startDate}
        </if>
        <if test="endDate!=null">
            and oti.create_time &lt;=#{endDate}
        </if>
        <if test="deviceSn!=null and deviceSn!=''">
            and device.device_sn =#{deviceSn}
        </if>
 
    </select>
 
 
    <select id="mapAttachList" resultType="org.sxkj.resource.vo.AttachMapVo">
        select
        device.area_code,
        attach.id,
        IF(attach.longitude IS NOT NULL AND attach.longitude != 0,attach.longitude,JSON_EXTRACT(attach.metadata,
        '$.shootPosition.lng') ) AS longitude,
        IF(attach.latitude IS NOT NULL AND attach.latitude != 0, attach.latitude, JSON_EXTRACT(attach.metadata,
        '$.shootPosition.lat') ) AS latitude
        <if test="resultType!=null and resultType!='' and resultType==4">
            ,odm.orthoimage_api 'url',
            public.st_astext ( odm.geom ) "geom"
        </if>
        from blade_attach attach
        left join manage_device device on attach.device_sn = device.device_sn::VARCHAR
        left join wayline_job job on attach.wayline_job_id = job.job_id::VARCHAR
        left join wayline_job_info wji on wji.id = job.job_info_id::VARCHAR
        <if test="resultType!=null and resultType!='' and resultType==4">
            left join odm_task_info odm on attach.wayline_job_id = odm.wayline_job_id::VARCHAR
        </if>
        <where>
            and attach.is_deleted = 0
            and wji.is_deleted = 0
            <if test="resultType!=null and resultType!=''">
                and attach.result_type =#{resultType}
            </if>
            <if test="deviceSn!=null and deviceSn!=''">
                and device.device_sn =#{deviceSn}
            </if>
            <if test="wayLineJobId!=null and wayLineJobId!=''">
                and attach.wayline_job_id =#{wayLineJobId}
            </if>
            <if test="startTime!=null">
                and job.execute_time &gt;=#{startTime}
            </if>
            <if test="endTime!=null">
                and job.execute_time &lt;= #{endTime}
            </if>
            <if test="jobName!=null and jobName!=''">
                and job.name like concat('%',#{jobName},'%')
            </if>
        </where>
    </select>
 
    <select id="getAttachList" resultType="org.sxkj.resource.vo.AttachVO">
        select
            attach.*
        from
            blade_attach attach
         <where>
            <if test="attachIds!=null and attachIds.size()>0">
                and attach.id in
                <foreach item="item" index="index" collection="attachIds" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="fileName!=null and fileName!=''">
                and attach.name like concat('%',#{fileName},'%')
            </if>
            AND attach.is_deleted = 0
        </where>
    </select>
 
 
    <select id="findPointAttach" resultType="org.sxkj.resource.vo.AnalysisAttachVo">
        SELECT DISTINCT
        attach.id,
        attach.name,
        attach.extension,
        attach.nick_name,
        attach.create_time,
        attach.link,
        rela.event_name,
        COALESCE(attach.result_type,2) "result_type"
        FROM blade_attach attach
        LEFT JOIN drone_job_event_rela rela ON attach.id = rela.attach_id::VARCHAR
        WHERE
        attach.is_deleted = 0
        AND attach.is_thumbnail = 0
        AND (
        (
        attach.result_type IN (0,2)
        AND (
        (
        JSON_EXTRACT(attach.metadata, '$.shootPosition.lat') = #{lat}
        AND JSON_EXTRACT(attach.metadata, '$.shootPosition.lng') = #{lng}
        )
        OR (
        attach.longitude = #{lng}
        AND attach.latitude = #{lat}
        )
        )
        <if test="beforeDate != null">
            AND attach.create_time &gt;= #{beforeDate}
        </if>
        <if test="afterDate != null">
            AND attach.create_time &lt;= #{afterDate}
        </if>
        )
        <if test="id != null">
            OR attach.id = #{id}
        </if>
        )
        LIMIT 400;
 
    </select>
    <select id="getAttachInfo" resultType="org.sxkj.resource.vo.AttachInfoVO">
        select attach.create_time,
               attach.id,
               attach.name,
               COALESCE(attach.nick_name, SUBSTRING_INDEX(SUBSTRING_INDEX(attach.NAME, '/', - 1), '.', 1))   nick_name,
               attach.link,
               attach.device_sn,
               attach.metadata,
               attach.result_type,
               attach.attach_size,
               attach.wayline_job_id,
               CASE
                   WHEN attach.media_category = 0 THEN 'visible'
                   WHEN attach.media_category = 1 THEN 'ir'
                   ELSE 'visible'
                   END AS                                                                                  photoType,
               job.name                                                                                    jobName,
               DATE_FORMAT(FROM_UNIXTIME(job.begin_time / 1000, '%Y-%m-%d %H:%i:%s'), '%Y-%m-%d %H:%i:%s') jobTime,
               device.nickname                                                                             nestName,
               CONCAT_WS(',', region.province_name, region.city_name, region.district_name)                region_name
        from blade_attach attach
                 left join wayline_job job on attach.wayline_job_id = job.job_id::VARCHAR
                 left join manage_device device on attach.device_sn = device.device_sn::VARCHAR
                 left join blade_region region on device.area_code = region.code::VARCHAR
        where attach.id = #{id}
    </select>
 
    <select id="getAttachInfoByJobId" resultType="org.sxkj.resource.vo.AttachInfoVO">
        select attach.create_time,
               attach.id,
               attach.name,
               COALESCE(attach.nick_name, SUBSTRING_INDEX(SUBSTRING_INDEX(attach.NAME, '/', - 1), '.', 1))   nick_name,
               attach.link,
               attach.device_sn,
               attach.metadata,
               attach.result_type,
               rela.status,
               rela.event_name,
               rela.event_num,
               job.name                                                                                    jobName,
               DATE_FORMAT(FROM_UNIXTIME(job.begin_time / 1000, '%Y-%m-%d %H:%i:%s'), '%Y-%m-%d %H:%i:%s') jobTime,
               device.nickname,
               CONCAT_WS(',', region.province_name, region.city_name, region.district_name)                region_name
        from wayline_job job
                 left join blade_attach attach on attach.wayline_job_id = job.job_id::VARCHAR
                 left join manage_device device on attach.device_sn = device.device_sn::VARCHAR
                 left join blade_region region on device.area_code = region.code::VARCHAR
                 left join drone_job_event_rela rela on attach.id = rela.attach_id::VARCHAR
        where job.job_id = #{jobId}
          and attach.result_type in (0, 2, 5)
    </select>
 
    <select id="attachTypeStatistics" resultType="org.sxkj.resource.vo.AttachTypeStatisticsVO">
        select
        attach.result_type type,
        count(attach.id) count
        FROM blade_attach attach
        LEFT JOIN wayline_job wj ON attach.wayline_job_id = wj.job_id::VARCHAR
        LEFT JOIN wayline_job_info wji on wji.id = wj.job_info_id::VARCHAR
        LEFT JOIN drone_job_event_rela rela on attach.id = rela.attach_id::VARCHAR
        <where>
            <if test="param.deviceSn!=null and param.deviceSn!=''">
                and attach.device_sn = #{param.deviceSn}
            </if>
            <if test="param.startDate!=null and param.endDate !=null ">
                and attach.create_time between #{param.startDate} and #{param.endDate}
            </if>
 
            <if test="deptIdList!=null and deptIdList.size>0">
                AND attach.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 attach.is_deleted = 0
            AND attach.result_type IN ( 0, 1, 2, 3, 4, 5,15 )
            AND wji.is_deleted = 0
            AND wj.job_info_id IS NOT NULL
            GROUP BY
            attach.result_type
        </where>
 
    </select>
 
    <!-- 计算三维面积 -->
    <select id="calculateTheThreeDimensionalArea" resultType="org.sxkj.resource.vo.AttachTypeStatisticsVO">
        SELECT
        ROUND( sum( wj3d.area ) / 1000000, 2 ) AS area
        FROM
        blade_attach attach
        LEFT JOIN wayline_job wj ON attach.wayline_job_id = wj.job_id::VARCHAR
        LEFT JOIN wayline_job_info wji ON wji.id = wj.job_info_id::VARCHAR AND wji.is_deleted = 0
        LEFT JOIN wayline_job_3d_record wj3d on wj3d.job_id = wj.job_id::VARCHAR
        <where>
            <if test="param.deviceSn!=null and param.deviceSn!=''">
                AND attach.device_sn = #{param.deviceSn}
            </if>
            <if test="param.areaCode!=null and param.areaCode!=''">
                AND wj3d.area_code like concat(#{param.areaCode},'%')
            </if>
            <if test="param.startDate!=null and param.startDate!='' and param.endDate !=null and param.endDate !='' ">
                AND attach.create_time between #{param.startDate} and #{param.endDate}
            </if>
 
            <if test="deptIdList!=null and deptIdList.size>0">
                AND attach.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 attach.is_deleted = 0
            AND wji.is_deleted = 0
            <if test="param.resultTypeList!=null and param.resultTypeList.size>0">
                AND attach.result_type IN
                <foreach collection="param.resultTypeList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="param.jobType!=null and param.jobType == 6 ">
                AND wj3d.job_type = 6
            </if>
 
            <if test="param.jobType!=null and param.jobType != 6 ">
                AND wj3d.job_type in (5,7,9 )
            </if>
            AND wj3d.is_deleted = 0
            AND wj.job_info_id IS NOT NULL
        </where>
    </select>
        <!-- 分区域计算三维面积 -->
    <select id="calculateTheThreeDimensionalAreaGroupBy" resultType="org.sxkj.resource.vo.AttachTypeStatisticsVO">
        SELECT
        ROUND( sum( wj3d.area ) / 1000000, 2 ) AS area,
        wj3d.area_code
        FROM
        blade_attach attach
        LEFT JOIN wayline_job wj ON attach.wayline_job_id = wj.job_id::VARCHAR
        LEFT JOIN wayline_job_info wji ON wji.id = wj.job_info_id::VARCHAR AND wji.is_deleted = 0
        LEFT JOIN wayline_job_3d_record wj3d on wj3d.job_id = wj.job_id::VARCHAR
        <where>
            <if test="param.deviceSn!=null and param.deviceSn!=''">
                AND attach.device_sn = #{param.deviceSn}
            </if>
            <if test="param.areaCode!=null and param.areaCode!=''">
                AND wj3d.area_code like concat(#{param.areaCode},'%')
            </if>
            <if test="param.startDate!=null and param.startDate!='' and param.endDate !=null and param.endDate !='' ">
                AND attach.create_time between #{param.startDate} and #{param.endDate}
            </if>
 
            <if test="deptIdList!=null and deptIdList.size>0">
                AND attach.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 attach.is_deleted = 0
            AND wji.is_deleted = 0
            <if test="param.resultTypeList!=null and param.resultTypeList.size>0">
                AND attach.result_type IN
                <foreach collection="param.resultTypeList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="param.jobType!=null and param.jobType == 6 ">
                AND wj3d.job_type = 6
            </if>
 
            <if test="param.jobType!=null and param.jobType != 6 ">
                AND wj3d.job_type in (5,7,9 )
            </if>
            AND wj3d.is_deleted = 0
            AND wj.job_info_id IS NOT NULL
        </where>
        GROUP BY
        wj3d.area_code
    </select>
 
    <select id="getManageAttachTypeStatistics" resultType="org.sxkj.resource.vo.AttachTypeStatisticsVO">
        select
        attach.result_type type,
        count(attach.id) count,
        DATE_FORMAT(attach.create_time, #{param1.formatTime}) timeStr
        from blade_attach attach
        LEFT JOIN wayline_job wj ON attach.wayline_job_id = wj.job_id::VARCHAR
        left JOIN wayline_job_info wji ON wji.id = wj.job_info_id::VARCHAR and wji.is_deleted = 0
        <where>
            <if test="param1.deviceSn!=null and param1.deviceSn!=''">
                and attach.device_sn = #{param1.deviceSn}
            </if>
            <if test="param1.startDate!=null and param1.endDate !=null ">
                and attach.create_time between #{param.startDate} and #{param1.endDate}
            </if>
            <if test="deptIdList!=null and deptIdList.size>0">
                AND attach.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 attach.is_deleted = 0
            and wj.is_deleted = 0
            and wji.is_deleted = 0
            and attach.result_type is not null
            and attach.result_type in ( 0, 1, 2, 3, 4, 5,15 )
            group by
            attach.result_type,
            DATE_FORMAT(attach.create_time, #{param1.formatTime})
        </where>
 
    </select>
 
 
    <delete id="deletedEventData">
        update drone_job_event_rela
        set is_deleted=1
        where md5 = #{md5}
    </delete>
<!--    删除媒体文件及其关联文件,并软删除数据库记录。-->
    <delete id="deleteAttach">
 
        UPDATE blade_attach ba
            INNER JOIN wayline_job wj ON ba.wayline_job_id = wj.job_id::VARCHAR
            INNER JOIN wayline_job_info wji ON wj.job_info_id = wji.id::VARCHAR
            INNER JOIN wayline_job_record wjr ON wji.id = wjr.job_info_id::VARCHAR
            SET ba.is_deleted = 1,
                ba.update_user = #{operator}
        WHERE ba.workspace_id = #{workspaceId}
          AND wjr.is_deleted = 0
          AND wj.is_deleted = 0
          AND wj.workspace_id = #{workspaceId}
          AND wjr.device_sn IS NOT NULL
          AND JSON_LENGTH(wjr.device_sn) &lt;= 1
    </delete>
    <select id="getlotInfoList" resultType="org.sxkj.resource.entity.Attach">
        SELECT
            a.id,
            a.tenant_id,
            a.link,
            a.domain_url,
            a.nick_name,
            a.name,
            a.original_name,
            a.extension,
            a.attach_size,
            a.create_user,
            a.create_dept,
            a.create_time,
            a.update_user,
            a.update_time,
            a.status,
            a.wayline_job_id,
            a.result_type,
            a.device_sn,
            a.workspace_id,
            a.metadata,
            a.md5,
            a.is_thumbnail,
            a.longitude,
            a.latitude,
            a.media_category,
            a.media_create_time,
            a.is_deleted
        FROM
            blade_attach a
                INNER JOIN
            wayline_job j ON a.wayline_job_id = j.job_id::VARCHAR
        WHERE
            (
                #{lotInfoId} = ANY(string_to_array(j.lot_info_id, ',')::bigint[])
                OR j.lot_info_id = #{lotInfoId}
            )
          AND a.result_type = 0  -- 根据您的需求,只查询成果类型为 0 (图片) 的数据
          AND a.is_deleted = 0   -- 确保附件未被逻辑删除
          AND j.is_deleted = 0   -- 确保关联的任务也未被逻辑删除
    </select>
 
</mapper>