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/equipment/mapper/EquipmentMapper.xml |  296 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 274 insertions(+), 22 deletions(-)

diff --git a/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipment/mapper/EquipmentMapper.xml b/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipment/mapper/EquipmentMapper.xml
index ea812e9..943b8c7 100644
--- a/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipment/mapper/EquipmentMapper.xml
+++ b/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipment/mapper/EquipmentMapper.xml
@@ -27,6 +27,9 @@
         <result column="province" property="province"/>
         <result column="city" property="city"/>
         <result column="district" property="district"/>
+        <result column="state" property="state"/>
+        <result column="reason" property="reason"/>
+        <result column="jtype" property="jtype"/>
     </resultMap>
 
     <resultMap id="treeNodeResultMap" type="org.springblade.core.tool.node.TreeNode">
@@ -47,7 +50,6 @@
         <result column="ownerId" property="ownerId"/>
         <result column="devicestate" property="devicestate"/>
         <result column="stime" property="stime"/>
-        <result column="coordinate" property="coordinate"/>
         <result column="parent_id" property="parentId"/>
         <result column="jd" property="jd"/>
         <result column="wd" property="wd"/>
@@ -61,20 +63,56 @@
 
 
     <select id="selectEquipmentPage" resultMap="equipmentResultMap">
-        select id,deviceName,deviceNumber,deviceType,ownership,ownerId,devicestate,stime,ST_ASTEXT (coordinate ) AS
-        coordinate,dtype,heartbeat,expireTime,pay,
-        parent_id,
-        jd ,
-        wd ,
-        street,
-        addvcd,pay,expireTime from sys_equipment where 1=1
+        select equipment.id,equipment.deviceName,equipment.deviceNumber,equipment.deviceType,equipment.ownership
+        ,equipment.ownerId,equipment.devicestate,equipment.stime,equipment.dtype,equipment.heartbeat,equipment.expireTime,
+        equipment.parent_id,equipment.district,equipment.province,equipment.city,equipment.serialNumber,equipment.channelNumber,
+        equipment.jd ,
+        equipment.wd ,
+        equipment.state,equipment.reason,
+        equipment.street,catalog.pid,
+        equipment.oneContacts,equipment.onePhone,equipment.oneId,
+        equipment.twoContacts,equipment.twoPhone,equipment.twoId,
+        equipment.ThreeContacts,equipment.ThreePhone,equipment.threeId,
+        equipment.deptId,
+        equipment.addvcd,equipment.pay,equipment.expireTime from sys_equipment equipment
+        left join sys_catalog catalog on catalog.eqid = equipment.deviceNumber
+        LEFT JOIN (
+        SELECT
+        count( id ) AS jtype,
+        deviceNumber as deviceN
+        FROM
+        sys_alarm
+        WHERE
+        waringType = "紧急求救"
+        AND jtype = 0
+        OR jtype = 1
+        GROUP BY
+        deviceNumber
+        ) alarm ON alarm.deviceN = equipment.deviceNumber
+        where 1=1
+
         <if test="equipment.deviceName!=null">
             and (deviceName like concat('%',#{equipment.deviceName},'%') or deviceNumber like
             concat('%',#{equipment.deviceName},'%'))
         </if>
-        <if test="equipment.addvcd!=null">
-            and addvcd=#{equipment.addvcd}
+
+        <if test="equipment.beginTime!=null and equipment.beginTime!=''">
+            and expireTime&gt;=#{equipment.beginTime}
         </if>
+        <if test="equipment.endTime!=null and equipment.endTime!=''">
+            and expireTime&lt;=#{equipment.endTime}
+        </if>
+
+        <if test="equipment.district!=null">
+            and district like concat('%',#{equipment.district},'%')
+        </if>
+        <if test="equipment.province!=null">
+            and province like concat('%',#{equipment.province},'%')
+        </if>
+        <if test="equipment.city!=null">
+            and city like concat('%',#{equipment.city},'%')
+        </if>
+
         <if test="equipment.devicestate!=null">
             and devicestate =#{equipment.devicestate}
         </if>
@@ -82,6 +120,96 @@
         <if test="equipment.dtype!=null">
             and dtype=#{equipment.dtype}
         </if>
+
+        <if test="childList!=null and childList.size>0">
+            and deviceNumber in
+            <foreach collection="childList" index="index" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+
+    </select>
+
+    <select id="selectDeptPages" resultMap="equipmentResultMap">
+        select IF
+        ( alarm.jtype IS NULL, 0, 1 ) AS jtype,equipment.id,equipment.deviceName,equipment.deviceNumber,equipment.deviceType,equipment.ownership
+        ,equipment.ownerId,equipment.devicestate,equipment.stime,equipment.dtype,equipment.heartbeat,equipment.expireTime,
+        equipment.parent_id,equipment.district,equipment.province,equipment.city,equipment.serialNumber,equipment.channelNumber,
+        equipment.jd ,
+        equipment.wd ,
+        equipment.state,equipment.reason,
+        equipment.street,catalog.pid,
+        equipment.oneContacts,equipment.onePhone,equipment.oneId,
+        equipment.twoContacts,equipment.twoPhone,equipment.twoId,
+        equipment.ThreeContacts,equipment.ThreePhone,equipment.threeId,
+        equipment.deptId,
+        equipment.addvcd,equipment.pay,equipment.expireTime from sys_equipment equipment
+        left join sys_catalog catalog on catalog.eqid = equipment.deviceNumber
+        LEFT JOIN (
+        SELECT
+        count( id ) AS jtype,
+        deviceNumber as deviceN
+        FROM
+        sys_alarm
+        WHERE
+        waringType = "紧急求救"
+        AND jtype = 0
+        OR jtype = 1
+        GROUP BY
+        deviceNumber
+        ) alarm ON alarm.deviceN = equipment.deviceNumber
+        where 1=1
+
+        <if test="equipment.deviceName!=null">
+            and (deviceName like concat('%',#{equipment.deviceName},'%') or deviceNumber like
+            concat('%',#{equipment.deviceName},'%'))
+        </if>
+
+        <if test="equipment.beginTime!=null and equipment.beginTime!=''">
+            and expireTime&gt;=#{equipment.beginTime}
+        </if>
+        <if test="equipment.endTime!=null and equipment.endTime!=''">
+            and expireTime&lt;=#{equipment.endTime}
+        </if>
+
+        <if test="equipment.district!=null">
+            and district like concat('%',#{equipment.district},'%')
+        </if>
+        <if test="equipment.province!=null">
+            and province like concat('%',#{equipment.province},'%')
+        </if>
+        <if test="equipment.city!=null">
+            and city like concat('%',#{equipment.city},'%')
+        </if>
+
+        <if test="equipment.devicestate!=null">
+            and devicestate =#{equipment.devicestate}
+        </if>
+
+        <if test="equipment.dtype!=null">
+            and dtype=#{equipment.dtype}
+        </if>
+
+        <if test="dxtype!=null and dxtype == 0">
+            and heartbeat &lt; DATE_SUB(NOW(),INTERVAL 1 DAY)
+        </if>
+        <if test="dxtype!=null and dxtype == 1">
+            and heartbeat >= DATE_SUB(NOW(),INTERVAL 1 DAY)
+        </if>
+        <if test="dxtype!=null and dxtype == 2">
+            and alarm.jtype IS NOT NULL
+        </if>
+        <if test="dxtype!=null and dxtype == 3">
+            and heartbeat >= DATE_SUB(NOW(),INTERVAL 1 DAY) and state!=null
+        </if>
+
+        <if test="childList!=null and childList.size>0">
+            and deptId in
+            <foreach collection="childList" index="index" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+
     </select>
 
     <!--新增-->
@@ -89,8 +217,98 @@
        INSERT INTO sys_equipment (deviceName,deviceNumber,deviceType,ownership,ownerId,devicestate,stime,coordinate,parent_id,jd,wd,addvcd,street,dtype) VALUES (#{deviceName},#{deviceNumber},#{deviceType},#{ownership},#{yname},#{devicestate},#{stime},POINT(#{jd},#{wd}),#{parentId},#{jd},#{wd},#{addvcd},#{streeName},#{dtype})
     </insert>
 
+    <!--新增-->
+    <insert id="saveImg" parameterType="org.springblade.jfpt.equipment.entity.Equipment">
+       INSERT INTO sys_depl (deviceName,deviceNumber,contacts,calls,paddress,deploymentTime) VALUES (#{deviceName},#{deviceNumber},#{contacts},#{call},#{paddress},#{deploymentTime})
+    </insert>
+
     <select id="tree" resultMap="treeNodeResultMap">
           select id, parent_id, deviceName as title, id as "value", id as "key" from sys_equipment
+    </select>
+
+    <select id="listAll" resultMap="equipmentResultMap">
+        SELECT
+        IF
+        ( alarm.jtype IS NULL, 0, 1 ) AS jtype,
+        equipment.id,
+        equipment.deviceName,
+        equipment.deviceNumber,
+        equipment.deviceType,
+        equipment.ownership,
+        equipment.ownerId,
+        equipment.devicestate,
+        equipment.stime,
+        equipment.dtype,
+        equipment.heartbeat,
+        equipment.expireTime,
+        equipment.parent_id,
+        equipment.district,
+        equipment.province,
+        equipment.city,
+        equipment.serialNumber,
+        equipment.channelNumber,
+        equipment.jd,
+        equipment.wd,
+        equipment.state,
+        equipment.reason,
+        equipment.street,
+        catalog.pid,
+        equipment.oneContacts,
+        equipment.onePhone,
+        equipment.oneId,
+        equipment.twoContacts,
+        equipment.twoPhone,
+        equipment.twoId,
+        equipment.ThreeContacts,
+        equipment.ThreePhone,
+        equipment.threeId,
+        equipment.deptId,
+        equipment.addvcd,
+        equipment.pay,
+        equipment.expireTime
+        FROM
+        sys_equipment equipment
+        LEFT JOIN sys_catalog catalog ON catalog.eqid = equipment.deviceNumber
+        LEFT JOIN (
+        SELECT
+        count( id ) AS jtype,
+        deviceNumber as deviceN
+        FROM
+        sys_alarm
+        WHERE
+        waringType = "紧急求救"
+        AND jtype = 0
+        OR jtype = 1
+        GROUP BY
+        deviceNumber
+        ) alarm ON alarm.deviceN = equipment.deviceNumber
+        WHERE
+        1 =1
+
+        <if test="equipment.deviceName!=null and equipment.deviceName!=''">
+            and (
+            deviceName like concat('%',#{equipment.deviceName},'%')
+            or deviceNumber like concat('%',#{equipment.deviceName},'%')
+            or street like concat('%',#{equipment.deviceName},'%')
+            )
+        </if>
+    </select>
+
+    <select id="listAlls" resultMap="equipmentResultMap">
+          select equipment.id,equipment.deviceName,equipment.deviceNumber,equipment.deviceType,equipment.ownership
+        ,equipment.ownerId,equipment.devicestate,equipment.stime,equipment.dtype,equipment.heartbeat,equipment.expireTime,
+        equipment.parent_id,equipment.district,equipment.province,equipment.city,equipment.serialNumber,equipment.channelNumber,
+        equipment.jd ,
+        equipment.wd ,
+        equipment.state,equipment.reason,
+        equipment.street,catalog.pid,
+        equipment.oneContacts,equipment.onePhone,equipment.oneId,
+        equipment.twoContacts,equipment.twoPhone,equipment.twoId,
+        equipment.ThreeContacts,equipment.ThreePhone,equipment.threeId,
+        equipment.deptId,
+        equipment.addvcd,equipment.pay,equipment.expireTime from sys_equipment equipment
+        left join sys_catalog catalog on catalog.eqid = equipment.deviceNumber
+        where 1=1
     </select>
 
 
@@ -146,20 +364,16 @@
         update sys_equipment SET devicestate = 0 where id in (${arr})
     </update>
 
-    <update id="updateOnes" parameterType="org.springblade.jfpt.equipment.entity.Equipment">
-    update sys_equipment SET deviceName=#{deviceName},deviceNumber=#{deviceNumber},deviceType=#{deviceType},
-    ownership=#{ownership},ownerId=#{yname},devicestate=#{devicestate},stime=#{stime},
-    coordinate=POINT(#{jd},#{wd}),parent_id=#{parentId},jd=#{jd},wd=#{wd},addvcd=#{addvnm},street=#{streeName},dtype=#{dtype} where id=#{id}
-</update>
-
-
     <select id="selectInfo" resultMap="deptVOResultMap"
             parameterType="org.springblade.jfpt.equipment.entity.Equipment">
         SELECT
-        dept.id,dept.deviceName,dept.deviceNumber,dept.deviceType,dept.ownership,
-        dept.ownerId,dept.devicestate,dept.stime,
-        ST_ASTEXT(dept.coordinate) as coordinate,dept.dtype,dept.expireTime,dept.heartbeat,
-        dept.parent_id,dept.jd,dept.wd,dept.street,u.yname,d.addvnm,dept.addvcd,
+        dept.deptId,dept.id,dept.deviceName,dept.deviceNumber,dept.deviceType,dept.ownership,
+        dept.ownerId,dept.devicestate,dept.stime,dept.district,dept.province,dept.city,
+        ST_ASTEXT(dept.coordinate) as coordinate,dept.dtype,dept.expireTime,dept.heartbeat, dept.state,dept.reason,
+        dept.parent_id,dept.jd,dept.wd,dept.street,u.yname,d.addvnm,dept.addvcd,dept.serialNumber,dept.channelNumber,
+        dept.oneContacts,dept.onePhone,dept.oneId,
+        dept.twoContacts,dept.twoPhone,dept.twoId,
+        dept.ThreeContacts,dept.ThreePhone,dept.threeId,
         (
         SELECT
         CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
@@ -174,7 +388,7 @@
     </select>
 
     <select id="selectList" resultMap="deptVOResultMap">
-        SELECT e.id,e.deviceName,e.deviceNumber,e.deviceType,e.ownership,
+        SELECT e.id,e.deviceName,e.deviceNumber,e.deviceType,e.ownership,e.state,e.reason,
         e.ownerId,e.devicestate,e.stime,e.street as streeName,
         ST_ASTEXT(e.coordinate) as coordinate,e.dtype,
         e.parent_id,e.jd,e.wd,e.addvcd,
@@ -203,6 +417,7 @@
    dept.parent_id,
    dept.jd,
    dept.wd,
+   dept.state,dept.reason,
    dept.street AS streeName,
    u.yname,
    dept.addvcd,
@@ -219,4 +434,41 @@
     update sys_equipment SET heartbeat=#{heartbeat} where deviceNumber=#{deviceNumber}
 </update>
 
+    <update id="updateexpireTime">
+        update sys_equipment SET expireTime=#{expireTime} where deviceNumber=#{deviceNumber}
+    </update>
+
+    <update id="updateExstate">
+        update sys_equipment SET state=#{state},reason=#{reason}  where deviceNumber=#{deviceNumber}
+    </update>
+
+    <!--查询设备在线数量-->
+    <select id="selectEqCz" resultType="Integer">
+        select COUNT(*) from sys_equipment where heartbeat >= DATE_SUB(NOW(),INTERVAL 1 DAY)
+    </select>
+
+    <!--查询设备掉线数量-->
+    <select id="selectEqCd" resultType="Integer">
+        select COUNT(*) from sys_equipment where heartbeat &lt; DATE_SUB(NOW(),INTERVAL 1 DAY)
+    </select>
+
+    <!--查询预警设备数量-->
+    <select id="selectEqCy" resultType="java.util.HashMap">
+        SELECT
+            count( id ) AS jtype,
+            deviceNumber
+        FROM
+            sys_alarm
+        WHERE
+            waringType = "紧急求救"
+            AND jtype = 0
+            OR jtype = 1
+        GROUP BY
+            deviceNumber
+    </select>
+
+    <!--查询设故障数量-->
+    <select id="selectEqCg" resultType="Integer">
+        select COUNT(*) from sys_equipment where heartbeat >= DATE_SUB(NOW(),INTERVAL 1 DAY) and state!=null
+    </select>
 </mapper>

--
Gitblit v1.9.3