From a4ff2b571be305e2641c9dd67797f4102e795ebb Mon Sep 17 00:00:00 2001
From: tangzy <tangzy123456>
Date: Sun, 25 Apr 2021 10:47:56 +0800
Subject: [PATCH] 1.App警情反馈接口调整 2.租户接口新增

---
 blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/alarm/mapper/AlarmMapper.xml |  455 +++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 365 insertions(+), 90 deletions(-)

diff --git a/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/alarm/mapper/AlarmMapper.xml b/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/alarm/mapper/AlarmMapper.xml
index c13c9d9..52ccd43 100644
--- a/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/alarm/mapper/AlarmMapper.xml
+++ b/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/alarm/mapper/AlarmMapper.xml
@@ -33,23 +33,15 @@
         <result column="cid" property="cid"/>
         <result column="vaddress" property="vaddress"/>
         <result column="aaddress" property="aaddress"/>
+        <result column="uids" property="uids"/>
+        <result column="securityArr" property="securityArr"/>
+        <result column="securityId" property="securityId"/>
     </resultMap>
 
-
-    <select id="selectAlarmPage" resultMap="alarmResultMap">
-        select
-        a.id,a.alarmType,a.alarmPeople,a.alarmTime,a.galarmPeople,a.sex,a.phoneNumber,a.place,a.content,a.waringType,a.bz,
-        a.deviceNumber,a.region,a.district,a.vaddress,a.aaddress,
-        a.alarmId,a.LEVEL,e.jd,e.wd,a.jtype,a.rname,a.jjTime,a.province,a.city,a.cid,
-        e.serialNumber,e.oneContacts,e.ThreeContacts,e.twoContacts,e.onePhone,e.twoPhone,e.ThreePhone,
-        e.stype,
-        e.oneId,
-        e.twoId,
-        e.threeId,
-        e.deptId,
-        e.channelNumber from sys_alarm a
-        LEFT JOIN sys_equipment e on e.deviceNumber=a.deviceNumber
-        where 1=1
+    <sql id="alarmCondition">
+        <if test="alarm.id!=null">
+            and a.id = #{alarm.id}
+        </if>
         <if test="alarm.jtype!=null">
             and a.jtype like concat('%',#{alarm.jtype},'%')
         </if>
@@ -80,9 +72,136 @@
         <if test="alarm.endTime!=null and alarm.endTime!=''">
             and a.alarmTime&lt;=#{alarm.endTime}
         </if>
+        <if test="alarm.timeDesc!=null and alarm.timeDesc!=''">
+            <if test="alarm.timeDesc=='30分钟以上'">
+                and czTime-alarmTime>1800
+            </if>
+            <if test="alarm.timeDesc=='10-30分钟'">
+                and czTime-alarmTime>600 and czTime-alarmTime &lt;1800
+            </if>
+            <if test="alarm.timeDesc=='5-10分钟'">
+                and czTime-alarmTime>300 and czTime-alarmTime &lt;600
+            </if>
+            <if test="alarm.timeDesc=='小于5分钟'">
+                and czTime-alarmTime>0 and czTime-alarmTime &lt;300
+            </if>
+            <if test="alarm.timeDesc=='0-2'">
+                and hour(alarmTime)>=0 and hour(alarmTime) &lt;2
+            </if>
+            <if test="alarm.timeDesc=='2-4'">
+                and hour(alarmTime)>=2 and hour(alarmTime) &lt;4
+            </if>
+            <if test="alarm.timeDesc=='4-6'">
+                and hour(alarmTime)>=4 and hour(alarmTime) &lt;6
+            </if>
+            <if test="alarm.timeDesc=='6-8'">
+                and hour(alarmTime)>=6 and hour(alarmTime) &lt;8
+            </if>
+            <if test="alarm.timeDesc=='8-10'">
+                and hour(alarmTime)>=8 and hour(alarmTime) &lt;10
+            </if>
+            <if test="alarm.timeDesc=='10-12'">
+                and hour(alarmTime)>=10 and hour(alarmTime) &lt;12
+            </if>
+            <if test="alarm.timeDesc=='12-14'">
+                and hour(alarmTime)>=12 and hour(alarmTime) &lt;14
+            </if>
+            <if test="alarm.timeDesc=='14-16'">
+                and hour(alarmTime)>=14 and hour(alarmTime) &lt;16
+            </if>
+            <if test="alarm.timeDesc=='16-18'">
+                and hour(alarmTime)>=16 and hour(alarmTime) &lt;18
+            </if>
+            <if test="alarm.timeDesc=='18-20'">
+                and hour(alarmTime)>=18 and hour(alarmTime) &lt;20
+            </if>
+            <if test="alarm.timeDesc=='20-22'">
+                and hour(alarmTime)>=20 and hour(alarmTime) &lt;22
+            </if>
+            <if test="alarm.timeDesc=='22-24'">
+                and hour(alarmTime)>=22 and hour(alarmTime) &lt;24
+            </if>
+        </if>
+    </sql>
+    <sql id="alarmConditionPie">
+        <if test="alarm.beginTime!=null and alarm.beginTime!=''">
+            and DATE_FORMAT(a.alarmTime,'%Y-%m-%d')&gt;=#{alarm.beginTime}
+        </if>
+        <if test="alarm.endTime!=null and alarm.endTime!=''">
+            and DATE_FORMAT(a.alarmTime,'%Y-%m-%d')&lt;=#{alarm.endTime}
+        </if>
+        <if test="alarm.timeDesc!=null and alarm.timeDesc!=''">
+            <if test="alarm.timeDesc=='30分钟以上'">
+                and czTime-alarmTime>1800
+            </if>
+            <if test="alarm.timeDesc=='10-30分钟'">
+                and czTime-alarmTime>600 and czTime-alarmTime &lt;1800
+            </if>
+            <if test="alarm.timeDesc=='5-10分钟'">
+                and czTime-alarmTime>300 and czTime-alarmTime &lt;600
+            </if>
+            <if test="alarm.timeDesc=='小于5分钟'">
+                and czTime-alarmTime>0 and czTime-alarmTime &lt;300
+            </if>
+            <if test="alarm.timeDesc=='0-2'">
+                and hour(alarmTime)>=0 and hour(alarmTime) &lt;2
+            </if>
+            <if test="alarm.timeDesc=='2-4'">
+                and hour(alarmTime)>=2 and hour(alarmTime) &lt;4
+            </if>
+            <if test="alarm.timeDesc=='4-6'">
+                and hour(alarmTime)>=4 and hour(alarmTime) &lt;6
+            </if>
+            <if test="alarm.timeDesc=='6-8'">
+                and hour(alarmTime)>=6 and hour(alarmTime) &lt;8
+            </if>
+            <if test="alarm.timeDesc=='8-10'">
+                and hour(alarmTime)>=8 and hour(alarmTime) &lt;10
+            </if>
+            <if test="alarm.timeDesc=='10-12'">
+                and hour(alarmTime)>=10 and hour(alarmTime) &lt;12
+            </if>
+            <if test="alarm.timeDesc=='12-14'">
+                and hour(alarmTime)>=12 and hour(alarmTime) &lt;14
+            </if>
+            <if test="alarm.timeDesc=='14-16'">
+                and hour(alarmTime)>=14 and hour(alarmTime) &lt;16
+            </if>
+            <if test="alarm.timeDesc=='16-18'">
+                and hour(alarmTime)>=16 and hour(alarmTime) &lt;18
+            </if>
+            <if test="alarm.timeDesc=='18-20'">
+                and hour(alarmTime)>=18 and hour(alarmTime) &lt;20
+            </if>
+            <if test="alarm.timeDesc=='20-22'">
+                and hour(alarmTime)>=20 and hour(alarmTime) &lt;22
+            </if>
+            <if test="alarm.timeDesc=='22-24'">
+                and hour(alarmTime)>=22 and hour(alarmTime) &lt;24
+            </if>
+        </if>
+    </sql>
 
+
+    <select id="selectAlarmPage" resultMap="alarmResultMap">
+        select
+        a.id,a.alarmType,a.alarmPeople,a.alarmTime,a.galarmPeople,a.sex,a.phoneNumber,a.content,a.waringType,a.bz,
+        a.deviceNumber,a.region,a.district,a.vaddress,a.aaddress,
+        a.alarmId,a.LEVEL,e.jd,e.wd,a.jtype,a.rname,a.jjTime,a.province,a.city,a.cid,
+        a.securityArr,a.securityId,
+        e.serialNumber,e.oneContacts,e.ThreeContacts,e.twoContacts,e.onePhone,e.twoPhone,e.ThreePhone,
+        e.stype,
+        e.oneId,
+        e.twoId,
+        e.threeId,
+        e.deptId,
+        e.street as place,
+        e.channelNumber from sys_alarm a
+        LEFT JOIN
+        sys_equipment e on e.deviceNumber=a.deviceNumber
+        where 1=1
+        <include refid="alarmCondition"></include>
         and a.waringType IN("紧急求救")
-
         ORDER BY
         a.jtype ASC,
         a.alarmTime DESC
@@ -253,40 +372,49 @@
 
 
     <select id="selectListSe" resultMap="alarmResultMap">
-
         SELECT
-        a.id,
-        a.alarmType,
-        a.alarmPeople,
-        a.alarmTime,
-        a.galarmPeople,
-        a.sex,
-        a.phoneNumber,
-        a.place,
-        a.content,
-        a.waringType,
-        a.deviceNumber,
-        a.region,
-        a.district,
-        a.alarmId,
-        a.LEVEL,
-        a.jd,
-        a.cid,
-        a.wd,
-        a.jtype,
-        a.rname,
-        e.serialNumber,
+        a.id,a.alarmType,a.alarmPeople,a.alarmTime,a.galarmPeople,a.sex,a.phoneNumber,a.place,a.content,a.waringType,a.bz,
+        a.deviceNumber,a.region,a.district,a.vaddress,a.aaddress,
+        a.alarmId,a.LEVEL,e.jd,e.wd,a.jtype,a.rname,a.jjTime,a.province,a.city,a.cid,
+        e.serialNumber,e.oneContacts,e.ThreeContacts,e.twoContacts,e.onePhone,e.twoPhone,e.ThreePhone,
         e.stype,
+        e.oneId,
+        e.twoId,
+        e.threeId,
+        e.deptId,
         e.channelNumber,
         jfpth.blade_region.`name` as addvnm
         FROM
-        sys_alarm a LEFT JOIN sys_equipment e on e.deviceNumber=a.deviceNumber LEFT JOIN jfpth.blade_region on jfpth.blade_region.`code`=a.district where
-        DATE_FORMAT(alarmTime,'%Y-%m-%d') &gt;=#{beginTime} and DATE_FORMAT(alarmTime,'%Y-%m-%d') &lt;=#{endTime} and a.waringType NOT IN("系统测试","主机重新上电") ORDER BY alarmTime desc
+        sys_alarm a
+        LEFT JOIN sys_equipment e
+        on
+        e.deviceNumber=a.deviceNumber
+        LEFT JOIN
+        jfpth.blade_region
+        on
+        jfpth.blade_region.`code`=a.district
+        where
+        DATE_FORMAT(alarmTime,'%Y-%m-%d') &gt;=#{beginTime}
+        and DATE_FORMAT(alarmTime,'%Y-%m-%d') &lt;=#{endTime}
+        and a.waringType  IN("紧急求救")
+        ORDER BY
+        a.jtype ASC,
+        a.alarmTime DESC
     </select>
 
 
     <update id="updateJtype">
-        update sys_alarm SET jtype=#{jtype},bz=#{bz} where id=#{id}
+        update sys_alarm SET jtype=#{jtype}
+
+        <if test="bz!=null and bz!=''">
+            ,bz=#{bz}
+        </if>
+
+        <if test="securityArr!=null and id!=''">
+            ,securityArr =#{securityArr}
+        </if>
+
+        where id=#{id}
     </update>
 
     <update id="updatePoliceStatus">
@@ -296,10 +424,14 @@
     <!--查询当天警情总数-->
     <select id="selectAlarmCount" resultType="java.lang.Integer">
         SELECT count(*) FROM `sys_alarm`
-            where
+        where
         waringType = '紧急求救'
-            and
-        to_days(alarmTime) = to_days(curdate())
+        <if test="conditionVo.status==0">
+            and to_days(alarmTime) = to_days(curdate())
+        </if>
+        <if test="conditionVo.startTime!=null and conditionVo.startTime!='' and conditionVo.endTime!=null and conditionVo.endTime!=''">
+            and alarmTime between #{conditionVo.startTime} and #{conditionVo.endTime}
+        </if>
     </select>
 
 
@@ -332,46 +464,26 @@
 		 order by a.click_date asc
     </select>
 
-    <!--查询警情当前时间段内每天的数据-->
-    <select id="selectTimeAlarmData" resultType="java.lang.Integer">
-       select a.days, ifnull(count,0) count from
-            (
-                SELECT @date := DATE_ADD( @date, INTERVAL + 1 DAY ) days FROM
-                (
-                    SELECT @date := DATE_ADD( #{conditionVo.startTime}, INTERVAL - 1 DAY ) FROM sys_date
-                ) time
-                    WHERE to_days( @date ) &lt; to_days( #{conditionVo.endTime} )
-            ) a
-            left join
-            (
-            select DATE_FORMAT(alarmTime,'%Y-%m-%d') as datetime, count(*) as count from sys_alarm
-            where waringType = '紧急求救'
-            group by DATE_FORMAT(alarmTime,'%Y-%m-%d')
-            ) b
-            on
-            a.days = b.datetime
-    </select>
-
-<!--    &lt;!&ndash;查询本日,本周,本月 主动报警的数量&ndash;&gt;-->
-<!--    <select id="selectAlarmSum" resultType="java.util.HashMap">-->
-<!--        select sa.alarmType name,IFNULL(sb.count, 0) value from (select alarmType from sys_alarm GROUP BY alarmType) sa-->
-<!--        left join-->
-<!--        ( select alarmType,count(*) count from sys_alarm-->
-<!--        where 1=1-->
-<!--        <if test="conditionVo.status==0">-->
-<!--            and to_days(alarmTime) = to_days(now())-->
-<!--        </if>-->
-<!--        <if test="conditionVo.status==1">-->
-<!--            and YEARWEEK(date_format(alarmTime,'%Y-%m-%d'),1) = YEARWEEK(now(),1)-->
-<!--        </if>-->
-<!--        <if test="conditionVo.status==2">-->
-<!--            and date_format(alarmTime,'%Y%m') = date_format(now(),'%Y%m')-->
-<!--        </if>-->
-<!--        group by alarmType-->
-<!--        ) sb-->
-<!--        on-->
-<!--        sa.alarmType = sb.alarmType-->
-<!--    </select>-->
+    <!--    &lt;!&ndash;查询本日,本周,本月 主动报警的数量&ndash;&gt;-->
+    <!--    <select id="selectAlarmSum" resultType="java.util.HashMap">-->
+    <!--        select sa.alarmType name,IFNULL(sb.count, 0) value from (select alarmType from sys_alarm GROUP BY alarmType) sa-->
+    <!--        left join-->
+    <!--        ( select alarmType,count(*) count from sys_alarm-->
+    <!--        where 1=1-->
+    <!--        <if test="conditionVo.status==0">-->
+    <!--            and to_days(alarmTime) = to_days(now())-->
+    <!--        </if>-->
+    <!--        <if test="conditionVo.status==1">-->
+    <!--            and YEARWEEK(date_format(alarmTime,'%Y-%m-%d'),1) = YEARWEEK(now(),1)-->
+    <!--        </if>-->
+    <!--        <if test="conditionVo.status==2">-->
+    <!--            and date_format(alarmTime,'%Y%m') = date_format(now(),'%Y%m')-->
+    <!--        </if>-->
+    <!--        group by alarmType-->
+    <!--        ) sb-->
+    <!--        on-->
+    <!--        sa.alarmType = sb.alarmType-->
+    <!--    </select>-->
 
     <!--查询本日,本周,本月 主动报警的数量-->
     <select id="selectAlarmSum" resultType="java.util.HashMap">
@@ -409,13 +521,13 @@
     <select id="queryPoliceTime" resultType="java.util.HashMap">
 
         SELECT
-            a.alarmPeople,
-            a.alarmId,
-            max( a.jjTime ) AS jjTime
+        a.alarmPeople,
+        a.alarmId,
+        max( a.jjTime ) AS jjTime
         FROM
-            sys_alarm a
+        sys_alarm a
         WHERE
-            1 =1
+        1 =1
 
         <if test="policeIdArr!=null and policeIdArr.size>0">
             and alarmId in
@@ -451,8 +563,123 @@
         AND role_id = "1370562810882502657"
     </select>
 
+    <select id="getAlarm" resultType="java.util.HashMap">
+        SELECT
+            a.id,
+            a.alarmType,
+            a.alarmPeople,
+            a.alarmTime,
+            a.galarmPeople,
+            a.sex,
+            a.phoneNumber,
+            a.content,
+            a.waringType,
+            a.bz,
+            a.deviceNumber,
+            a.region,
+            a.district,
+            a.vaddress,
+            a.aaddress,
+            a.alarmId,
+            a.LEVEL,
+            e.jd,
+            e.wd,
+            a.jtype,
+            a.rname,
+            a.jjTime,
+            a.province,
+            a.city,
+            a.cid,
+            e.serialNumber,
+            e.oneContacts,
+            e.ThreeContacts,
+            e.twoContacts,
+            e.onePhone,
+            e.twoPhone,
+            e.ThreePhone,
+            e.stype,
+            e.oneId,
+            e.twoId,
+            e.threeId,
+            e.deptId,
+            e.street AS place,
+            e.channelNumber
+        FROM
+            sys_alarm a
+            LEFT JOIN sys_equipment e ON e.deviceNumber = a.deviceNumber
+        WHERE
+
+            <if test="alarm.securityArr!=null and alarm.securityArr!=''">
+                securityId IS NULL
+                AND securityArr LIKE concat('%',#{alarm.securityArr},'%')
+            </if>
+
+            <if test="alarm.id!=null and alarm.id!=''">
+                a.id = #{alarm.id}
+            </if>
+
+
+    </select>
+
+    <select id="getAlarming" resultType="java.util.HashMap">
+        SELECT
+            a.id,
+            a.alarmType,
+            a.alarmPeople,
+            a.alarmTime,
+            a.galarmPeople,
+            a.sex,
+            a.phoneNumber,
+            a.content,
+            a.waringType,
+            a.bz,
+            a.deviceNumber,
+            a.region,
+            a.district,
+            a.vaddress,
+            a.aaddress,
+            a.alarmId,
+            a.LEVEL,
+            e.jd,
+            e.wd,
+            a.jtype,
+            a.rname,
+            a.jjTime,
+            a.province,
+            a.city,
+            a.cid,
+            e.serialNumber,
+            e.oneContacts,
+            e.ThreeContacts,
+            e.twoContacts,
+            e.onePhone,
+            e.twoPhone,
+            e.ThreePhone,
+            e.stype,
+            e.oneId,
+            e.twoId,
+            e.threeId,
+            e.deptId,
+            e.street AS place,
+            e.channelNumber
+        FROM
+            sys_alarm a
+            LEFT JOIN sys_equipment e ON e.deviceNumber = a.deviceNumber
+        WHERE
+            securityId =#{alarm.securityId}
+
+    </select>
+
+    <update id="setAlarm">
+        update sys_alarm SET securityId=#{alarm.securityId} where id=#{alarm.id}
+    </update>
+
     <update id="updateVaddress">
-        update sys_alarm SET vaddress=#{vaddress} where id=#{jid}
+        update sys_alarm SET vaddress=#{vaddress},uids=#{uids} where id=#{jid}
+    </update>
+
+    <update id="updateAaddress">
+        update sys_alarm SET aaddress=#{aaddress} where id=#{jid}
     </update>
 
 
@@ -494,4 +721,52 @@
         on
         a.days = b.datetime
     </select>
+
+
+    <!--查询本年所有月份的预警数量-->
+    <select id="queryYearAlarm" resultType="java.util.HashMap">
+
+        <if test="childList!=null and childList.size>0">
+
+            <foreach collection="childList" index="index" item="item" open="" separator="union all" close="">
+                SELECT
+                #{item} as month,count(ce.id) as count
+                FROM
+                sys_alarm as ce
+                WHERE
+                YEAR ( alarmTime ) = date_format(now(),'%Y%')
+                AND MONTH ( alarmTime ) = #{item}
+
+                AND waringType = "紧急求救"
+                AND deviceNumber = #{deviceNumber}
+
+            </foreach>
+        </if>
+
+    </select>
+
+    <!--查询符合条件的数据并导出-->
+    <select id="exportAlarm" resultType="org.springblade.common.entity.AlarmExcel">
+        select
+        a.id,a.alarmType,a.alarmPeople,a.alarmTime,a.galarmPeople,a.sex,a.phoneNumber,a.place,a.content,a.waringType,a.bz,
+        a.deviceNumber,a.region,a.district,a.vaddress,a.aaddress,
+        a.alarmId,a.LEVEL,e.jd,e.wd,a.jtype,a.rname,a.jjTime,a.province,a.city,
+        e.serialNumber,e.oneContacts,e.ThreeContacts,e.twoContacts,e.onePhone,e.twoPhone,e.ThreePhone
+        from sys_alarm a
+        LEFT JOIN sys_equipment e on e.deviceNumber=a.deviceNumber
+        where 1=1
+        <include refid="alarmCondition"></include>
+        and a.waringType IN("紧急求救")
+        ORDER BY
+        a.jtype ASC,
+        a.alarmTime DESC
+    </select>
+
+    <!--获取实时警情图表统计数据-->
+    <select id="getAlarmPie" resultType="org.springblade.common.entity.ReportReturnData">
+        select if(1=1,"紧急求救",0) type,ifnull(count(*),0) count from sys_alarm
+        where waringType="紧急求救"
+        <include refid="alarmConditionPie"></include>
+    </select>
+
 </mapper>

--
Gitblit v1.9.3