leutu
2024-05-08 543e4eb01ca210b20876e8139cb3d0403d7d065c
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
<?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.skyline.electricity.mapper.DetectMapper">
<!--    <select id="checkInFence" resultType="FencePosition" parameterType="map">-->
<!--    SELECT * from fence where st_intersects(ST_GeomFromText('POINT(#{lat} #{lon})'),    fenceposition) and status='enabled'-->
 
 
<!--    </select>-->
 
    <select id="judge" resultType="string" parameterType="map">
 
    SELECT
     st_intersects(
    (st_geomfromtext (#{point}, 4326 )),
    (st_geomfromtext (#{polygon}, 4326 )))
 
    </select>
 
    <insert id="insertPoint" parameterType="personposition">
 
        INSERT INTO "position"(userid,username,latitude,longitude,satellitenum,userindex,altitude,time,course)
        VALUES (#{userId},#{userName},#{latitude},#{longitude},#{satelliteNum},#{userIndex},#{altitude},#{time},#{course})
 
    </insert>
 
    <select id="getPositionById" parameterType="String" resultType="personposition">
 
 
        select distinct * from position where userid=#{userId}
 
    </select>
 
    <select id="getRoute" resultType="String" parameterType="String">
 
        select point from coordinate where username=#{username} ORDER BY
        createtime asc
 
 
    </select>
 
    <select id="getWifiInfo" resultType="wifi">
 
        select "gid", "te_type", "te_desc", "te_fname", "te_yaw", "te_pitch", "te_roll",
        "te_width", "te_length", "te_height", "te_scale",  substr(rtrim(ST_AsText("geom"), ')'), 11) as gemo
        from wifi_jz
 
    </select>
 
    <select id="getMonitorInfo" resultType="monitor">
 
        select "gid", "te_type", "te_desc", "te_fname", "te_yaw", "te_pitch", "te_roll",
        "te_width", "te_length", "te_height", "te_scale", substr(rtrim(ST_AsText("geom"), ')'), 11) as gemo,regionpath,transptz,
         cameraname,cameraindex,status
        from video
 
    </select>
 
    <select id="getDoorAccessInfo" resultType="dooraccess">
 
        select * from dooraccess
 
    </select>
 
    <insert id="insertPolygon" parameterType="fenceposition" >
 
        insert into fence(workid, fname, fenceposition, startaltitude, endaltitude, createtime, starttime, disabledtime,
                          status, type, level)
        values (#{workId}, #{fname}, ST_GeomFromText(#{fenceposition}), #{startaltitude}, #{endaltitude}, #{createtime},
                #{starttime}, #{disabledtime}, #{status}, #{type}, #{level})
 
    </insert>
 
    <select id="selectPolygon" parameterType="fenceposition" resultType="fenceposition">
 
            select * from fence where workid = #{workId}
 
    </select>
 
    <insert id="insertHp" parameterType="historyposition">
 
        insert into historyposition(timestamp,altitude,satellitenum,latitude,course,entityid,time,longitude,username)
        values (#{timestamp},#{altitude},#{satelliteNum},#{latitude},#{course},#{entityId},#{time},#{longitude},#{userName})
 
    </insert>
 
    <select id="getRouteByUserId"  resultType="historyposition">
 
        select distinct timestamp,altitude,satellitenum,latitude,course,entityid,time,longitude,username
        from historyposition where entityid=#{entityId} and  to_timestamp(timestamp, 'yyyy-MM-dd HH24:MI:SS')
        between  to_timestamp(#{starttime}, 'yyyy-MM-dd HH24:MI:SS') and to_timestamp( #{endtime}, 'yyyy-MM-dd HH24:MI:SS')
        ORDER BY "timestamp" asc
 
    </select>
 
 
    <select id="getFenceInfo" resultType="fenceposition">
 
        SELECT fid,fname,workid,substr(rtrim(ST_AsText(fenceposition), ')'), 10) as fenceposition,starttime,disabledtime,createtime,startaltitude,
        endaltitude,personcount,alarmcount
        from fence where status='enabled' and workid not in(#{workId})
 
 
    </select>
 
    <select id="getFenceInfoByStatus" resultType="fenceposition">
 
        SELECT fid,fname,workid,substr(rtrim(ST_AsText(fenceposition), ')'), 10) as fenceposition,starttime,disabledtime,createtime,startaltitude,endaltitude,status,type,level,personcount,alarmcount from fence
        where status='enabled'
 
    </select>
 
    <select id="getFixedFenceInfo" resultType="fenceposition">
 
        SELECT fid,fname,workid,substr(rtrim(ST_AsText(fenceposition), ')'), 10) as fenceposition,starttime,disabledtime,createtime,startaltitude,endaltitude,status,type,level,personcount,alarmcount  from fence
        where type='fixed'
 
    </select>
 
    <select id="getTempFenceInfo" resultType="fenceposition">
 
        SELECT fid,fname,workid,substr(rtrim(ST_AsText(fenceposition), ')'), 10) as fenceposition,
        starttime,disabledtime,createtime,personcount,alarmcount  from fence where type='temp'
 
    </select>
 
 
    <update id="updateFenceInfo" parameterType="FencePosition">
 
 
        update fence
        <set >
            <if test="fname != null" >
                fname = #{fname},
            </if>
            <if test="endaltitude != null and endaltitude != -9999" >
                endaltitude = #{endaltitude},
            </if>
            <if test="startaltitude !=null and startaltitude != -9999" >
                startaltitude = #{startaltitude},
            </if>
            <if test="starttime != null" >
                starttime = #{starttime},
            </if>
            <if test="disabledtime != null" >
                disabledtime = #{disabledtime},
            </if>
             <if test="personcount != null " >
                personcount = #{personcount},
            </if>
        </set>
        where workid = #{workId}
 
    </update>
 
    <update id="updateFenceById" parameterType="fenceposition">
 
        update fence
        <set >
            <if test="fname != null"  >
                fname = #{fname},
            </if>
            <if test="fenceposition != null" >
                fenceposition = ST_GeomFromText(#{fenceposition}),
            </if>
            <if test="createtime != null" >
                createtime = #{createtime},
            </if>
            <if test="startaltitude !=null and startaltitude != -9999" >
                startaltitude = #{startaltitude},
            </if>
            <if test="endaltitude != null  and endaltitude != -9999" >
                endaltitude = #{endaltitude},
            </if>
 
        </set>
        where workid = #{workId}
 
    </update>
 
    <select id="intersects" parameterType="map" resultType="String">
 
     select  st_intersects(
    (st_geomfromtext (#{polygon}, 4326 )),
    (st_geomfromtext (#{py}, 4326 )))
 
    </select>
 
 
    <delete id="deleteFenceById" parameterType="String">
 
        delete from fence where workid = #{workId}
 
    </delete>
 
    <delete id="deleteFence">
 
        delete from fence
 
    </delete>
 
    <update id="changeFenceStatus" parameterType="string">
 
        update fence set status='enabled' where workid = #{workId}
 
    </update>
 
    <delete id="deleteDisabledFence">
 
        delete from fence
        where NOW() > to_timestamp(disabledtime, 'yyyy-MM-dd HH24:MI')
 
    </delete>
 
    <select id="selectPosition" parameterType="string" resultType="information">
 
        select * from information where userid=#{userId} and status='in' and wtid=#{workId}
 
    </select>
 
 
    <select id="selectPositionDelay" parameterType="string" resultType="information">
 
        select * from information where userid=#{userId} and (status='in' or status='not in') and wtid=#{workId} order by starttime desc limit 1
 
    </select>
 
    <insert id="insertInfo" parameterType="information">
 
        insert into information(userId,userName,wtid,name,starttime,status,fence_type,xy,hb)
        values (#{userId},#{userName},#{wtId},#{name},#{startTime},#{status},#{fence_type},#{xy},#{hb})
 
    </insert>
    <update id="updateInfomation" parameterType="information">
 
        update information
        set userid=#{userId},username=#{userName},wtid = #{wtId},name=#{name},starttime=#{startTime},status=#{status},fence_type=#{fence_type},xy=#{xy},hb=#{hb} where userid=#{userId}
 
    </update>
    <update id="changeStatus" parameterType="string">
 
        update information set status='not in' where userid=#{userId} and status='in' and wtid=#{workId}
 
    </update>
 
    <select id="getFenceInfoById" resultType="fenceposition" parameterType="String">
 
        select fid,fname,workid,substr(rtrim(ST_AsText(fenceposition), ')'), 10) as fenceposition,starttime,disabledtime,createtime,startaltitude,
        endaltitude,status,type,level
        from fence where workid=#{workId}
 
    </select>
 
    <update id="setFenceEnabled">
 
        update fence set status='enabled' where workid=#{workId}
 
    </update>
 
    <update id="setFenceEnabledByStartTime">
 
        update fence set status='enabled'
        where workid=#{workId}
 
    </update>
 
    <update id="setFenceDisabled">
 
        update fence set status='disabled' where workid=#{workId}
 
    </update>
 
    <update id="setEnabled" parameterType="int">
 
        update fence set status='enabled'
 
    </update>
 
    <update id="setDisabled" parameterType="int">
 
        update fence set status='disabled'
 
    </update>
 
    <select id="transLocation" parameterType="String" resultType="String">
 
        select substr(rtrim(ST_AsText(ST_Transform(st_geometryfromtext('point(${point})',2436),4326)), ')'), 7)
 
    </select>
 
    <select id="getDeviceInfo" resultType="DeviceInfo">
 
        select "gid", "filename", "x", "y", "z", "xpl2id", "设备名" as device_name, "台账名" as account, "设备id" as device_id, "测点" as testpoint,
         "编码" as code, "kks类型" as kkstype, substr(rtrim(ST_AsText("geom"), ')'), 11) as gemo
        from kks_equip where "设备id"!=''
 
    </select>
 
    <select id="getDeviceInfoById" parameterType="String" resultType="DeviceInfo">
 
        select "gid", "filename", "x", "y", "z", "xpl2id", "设备名" as device_name, "台账名" as account, "设备id" as device_id, "测点" as testpoint,
         "编码" as code, "kks类型" as kkstype, substr(rtrim(ST_AsText("geom"), ')'), 11) as gemo
        from kks_equip where 设备id=#{device_id}
 
    </select>
 
 
    <select id="getDeviceId" resultType="String">
 
        select distinct device_id from devicekks  where device_id!=''
 
    </select>
 
    <select id="getDeviceKKSInfo" resultType="DeviceKKS">
 
        select * from devicekks where device_id=#{device_id}
 
    </select>
 
 
    <select id="getMonitorDeviceInfo" resultType="MonitorInfo">
 
        select gid,"monitor_name", "monitor_type", "belong_device", "aisle_no", "aisle_type", "video_ip", "monitor_id", "belong_area", "monitor_index",
        "desc", "x", "y", "z", "hk_rtsp", substr(rtrim(ST_AsText("geom"), ')'), 11) as geom
        from monitor
 
    </select>
 
    <select id="getMonitorDeviceInfoById" resultType="MonitorInfo">
 
        select gid,"monitor_name", "monitor_type", "belong_device", "aisle_no", "aisle_type", "video_ip", "monitor_id", "belong_area", "monitor_index",
        "desc", "x", "y", "z", "hk_rtsp", substr(rtrim(ST_AsText("geom"), ')'), 11) as geom
        from monitor where monitor_index=#{monitor_index}
 
    </select>
     <insert id="insertFencePersonRel" parameterType="map" useGeneratedKeys="true" keyColumn="id" keyProperty="id" >
        INSERT INTO "fence_person_rel"(
            fname,
            workid,
            userid,
            personcount,
            type
            )
        VALUES
           <foreach collection="list" item="item" index="index" separator=",">(
            #{ item.fname},
            #{ item.workid },
            #{ item.userid },
            #{ item.personcount },
            'fence'
        )
        </foreach>
 
    </insert>
 
 
     <insert id="insertfixareaPersonRel" parameterType="map" useGeneratedKeys="true" keyColumn="id" keyProperty="id" >
        INSERT INTO "fence_person_rel"(
            workid,
            userid,
            personcount,
            type
            )
        VALUES
           <foreach collection="list" item="item" index="index" separator=",">(
            #{ item.workid },
            #{ item.userid },
            #{ item.personcount },
            'fixedArea'
        )
        </foreach>
 
    </insert>
 <delete id="delFencePersonRel" flushCache="true" parameterType="String" >
        delete from "fence_person_rel" where "workid" = #{_parameter}
    </delete>
 
    <update id="delAllFencePersonRel" flushCache="true" >
        truncate  table  "fence_person_rel"
    </update>
 
     <select id="selectFencePersonRelByworkid" resultType="map">
 
        select a.workid,a.userid,b.name,b,mobile,b.no,b.login_name,b.email
        from fence_person_rel a
        left join  sys_user b on a.userid=b.id where a.workid=#{_parameter}
 
    </select>
    <select id="selectAllfixedareaPerson" resultType="map">
 
        select distinct a.workid,a.personcount
        from fence_person_rel a where a.type='fixedArea'
 
 
    </select>
 
    <select id="selectAllfencePerson" resultType="map">
 
        select distinct a.fname, a.workid,a.personcount
        from fence_person_rel a where a.type='fence'
 
 
    </select>
 
     <select id="selectFenceAndfixedYQArea" resultType="fenceposition">
 
             SELECT gid as fid,substr(rtrim(ST_AsText(geom), ')'), 20) as fenceposition from fence_yq
 
    </select>
 
      <insert id="insertPolygon_yq" parameterType="fenceposition" >
 
        insert into fence_yq(te_type,te_desc,te_height,geom)
        values (#{type},#{fname},#{height},ST_GeomFromText(#{fenceposition}))
 
    </insert>
 
    <select id="selectInformation" parameterType="string" resultType="information">
        select im.starttime,ft.userid as userId,ft.workid as workId from fence_temp ft
        left join information im on im.wtid = ft.workid
        where ft.userid=#{userId} and im.status='out' and ft.workid=#{workId} order by im.starttime desc  limit 1
    </select>
 
    <select id="selectFenceTemp" parameterType="string" resultType="FenceTemp">
        select * from fence_temp ft
        where type='temp'
              <if test="userId !=null and userId!=''">and userid=#{userId}</if>
             and ft.workid=#{workId}
    </select>
    <insert id="insetFenceTemp" parameterType="FenceTemp">
        insert into fence_temp(workid,userid,type) values (#{workId},#{userId},#{type})
    </insert>
 
    <update id="updateFenceTemp" parameterType="string">
        update fence_temp set userid=#{newUserId} where   type='temp' and workid=#{workId}
    </update>
 
    <delete id="deleteFenceTemps" parameterType="string">
        delete fence_temp where  type='temp' and workid=#{workId}
    </delete>
 
    <select id="selectPeopleInSecureCircle" parameterType="string" resultType="map">
        SELECT id ,company_id, org_id, login_name, no, name, email, phone, mobile, user_type, photo, login_ip, login_date, login_flag, create_by, create_date, update_by, update_date, remarks, del_flag, sort, pos_code, token, party_cost, gender, birthday, education, residence, nation
        FROM public.sys_user where org_id='2015';
    </select>
 
    <select id="selectDepartDeputyDirectorByStaffid" parameterType="string" resultType="map">
        SELECT b.user_id as id, b.user_name,  a.orgid,b.pos_name
        FROM public.pg_pos a left join public.pg_pos_user b on a.id=b.pos_id
        where b.pos_name like '%主任'  and a.orgid in (select c.org_id from sys_user c where c.id=#{_parameter})
    </select>
    <select id="selectWorkLeader" parameterType="string" resultType="map">
        select b.* from fence_temp a left join  sys_user b on a.userid=b.id
        where type='temp'
        and a.workid=#{workId}
    </select>
 
 
    <update id="updateFenceAlarmCount" parameterType="string">
        update fence  set  alarmcount=alarmcount+1  where    workid=#{_parameter}
    </update>
 
</mapper>