<?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.ruoyi.system.mapper.TShouhuanAlarmListMapper">

    <resultMap type="TShouhuanAlarmList" id="TShouhuanAlarmListResult">
        <result property="id" column="id"/>
        <result property="facilityId" column="facility_id"/>
        <result property="shinfoId" column="shinfo_id"/>
        <result property="deviceIdCode" column="device_id_code"/>
        <result property="gpsLong" column="gps_long"/>
        <result property="gpsLat" column="gps_lat"/>
        <result property="speed" column="speed"/>
        <result property="direction" column="direction"/>
        <result property="poster" column="poster"/>
        <result property="electricQuantity" column="electric_quantity"/>
        <result property="stepNumber" column="step_number"/>
        <result property="rollNumber" column="roll_number"/>
        <result property="statusType" column="status_type"/>
        <result property="alarmType" column="alarm_type"/>
        <result property="terminalStatus" column="terminal_status"/>
        <result property="createTime" column="createtime"/>
        <result property="alarmFromType" column="alarm_from_type"/>
        <result property="msg" column="msg"/>
        <result property="isSend" column="is_send"/>
        <result property="sendTime" column="send_time"/>
    </resultMap>

    <sql id="selectTShouhuanAlarmListVo">
        select id,
               facility_id,
               shinfo_id,
               device_id_code,
               gps_long,
               gps_lat,
               speed,
               direction,
               poster,
               electric_quantity,
               step_number,
               roll_number,
               status_type,
               alarm_type,
               terminal_status,
               createtime,
               alarm_from_type,
               msg,
               is_send,
               send_time
        from t_shouhuan_alarm_list
    </sql>

    <select id="selectTShouhuanAlarmListList" parameterType="TShouhuanAlarmList" resultMap="TShouhuanAlarmListResult">
        <include refid="selectTShouhuanAlarmListVo"/>
        <where>
            <if test="facilityId != null ">and facility_id = #{facilityId}</if>
            <if test="shinfoId != null ">and shinfo_id = #{shinfoId}</if>
            <if test="deviceIdCode != null  and deviceIdCode != ''">and device_id_code = #{deviceIdCode}</if>
            <if test="gpsLong != null ">and gps_long = #{gpsLong}</if>
            <if test="gpsLat != null ">and gps_lat = #{gpsLat}</if>
            <if test="speed != null ">and speed = #{speed}</if>
            <if test="direction != null ">and direction = #{direction}</if>
            <if test="poster != null ">and poster = #{poster}</if>
            <if test="electricQuantity != null ">and electric_quantity = #{electricQuantity}</if>
            <if test="stepNumber != null ">and step_number = #{stepNumber}</if>
            <if test="rollNumber != null ">and roll_number = #{rollNumber}</if>
            <if test="statusType != null ">and status_type = #{statusType}</if>
            <if test="alarmType != null ">and alarm_type = #{alarmType}</if>
            <if test="terminalStatus != null  and terminalStatus != ''">and terminal_status = #{terminalStatus}</if>
            <if test="createTime != null ">and createtime = #{createTime}</if>
            <if test="alarmFromType != null ">and alarm_from_type = #{alarmFromType}</if>
            <if test="msg != null  and msg != ''">and msg = #{msg}</if>
            <if test="isSend != null ">and is_send = #{isSend}</if>
            <if test="sendTime != null ">and send_time = #{sendTime}</if>
        </where>
    </select>

    <select id="selectTShouhuanAlarmListById" parameterType="Integer" resultMap="TShouhuanAlarmListResult">
        <include refid="selectTShouhuanAlarmListVo"/>
        where id = #{id}
    </select>
    <select id="selectTShouhuanAlarmList" resultType="com.ruoyi.system.domain.dto.DataAlarmListDto">
        SELECT c.name,
               c.tel_one,
               a.gps_long,
               a.gps_lat,
               a.use_gps_long,
               a.use_gps_lat,
               a.location,
               a.createtime,
               a.status_type,
               a.alarm_type
        FROM `t_shouhuan_alarm_list` a
                 left join t_device_list b on a.device_id_code = b.device_id
                 left join t_user_profile c on c.id = b.userid
    </select>
    <select id="selectTShouhuanAlarmListCount" resultType="java.lang.Integer">
        select IFNULL(count(*), 0)
        from t_shouhuan_alarm_list
    </select>
    <select id="selectTShouhuanAlarmSOS" resultType="java.lang.Integer">
        SELECT IFNULL(count(*), 0)
        FROM `t_shouhuan_alarm_list`
        where alarm_type = 16
    </select>
    <select id="selectTShouhuanAlarmSOSSolve" resultType="java.lang.Integer">
        SELECT IFNULL(count(*), 0)
        FROM `t_sos_solve`
        where solve_status = 1
    </select>
    <select id="selectTShouhuanAlarmRail" resultType="java.lang.Integer">
        SELECT IFNULL(count(*), 0)
        FROM `t_shouhuan_alarm_list`
        where status_type = 2
    </select>
    <select id="selectTShouhuanAlarmRailSolve" resultType="java.lang.Integer">
        SELECT IFNULL(count(*), 0)
        FROM `t_rail_solve`
        where solve_status = 1
    </select>
    <select id="selectTShouhuanAlarmHeart" resultType="java.lang.Integer">
        SELECT IFNULL(count(*), 0)
        FROM `t_shouhuan_alarm_list`
        where alarm_type = 22
    </select>
    <select id="selectTShouhuanAlarmHeartSolve" resultType="java.lang.Integer">
        SELECT IFNULL(count(*), 0)
        FROM `t_health_solve`
        where solve_status = 1
    </select>
    <select id="selectTShouhuanAlarmFall" resultType="java.lang.Integer">
        SELECT IFNULL(count(*), 0)
        FROM `t_shouhuan_alarm_list`
        where alarm_type = 21
    </select>
    <select id="selectTShouhuanAlarmFallSolve" resultType="java.lang.Integer">
        SELECT IFNULL(count(*), 0)
        FROM `t_fall_solve`
        where solve_status = 1
    </select>
    <select id="selectTShouhuanAlarmLow" resultType="java.lang.Integer">
        SELECT IFNULL(count(*), 0)
        FROM `t_shouhuan_alarm_list`
        where alarm_type = 17
    </select>
    <select id="selectTShouhuanAlarmLowSolve" resultType="java.lang.Integer">
        SELECT IFNULL(count(*), 0)
        FROM `t_other_solve` a
                 left join t_shouhuan_alarm_list b
                           on a.alarmid = b.id
        where b.alarm_type = 17
    </select>
    <select id="selectTShouhuanAlarmStatus" resultType="java.lang.Integer">
        SELECT IFNULL(count(*), 0)
        FROM `t_shouhuan_info`
        where online_statis = 1
    </select>
    <select id="selectTShouhuanAlarmStatusSolve" resultType="java.lang.Integer">
        SELECT IFNULL(count(*), 0)
        FROM `t_shouhuan_info`
        where online_statis = 0
    </select>
    <select id="selectTShouhuanAlarmOtherSolve" resultType="java.lang.Integer">
        SELECT IFNULL(count(*), 0)
        FROM `t_other_solve`
        where solve_status = 1
    </select>
    <select id="selectAlarmStatusListDto" resultType="com.ruoyi.system.domain.dto.AlarmStatusListDto">
        SELECT a.id,
               c.name,
               a.location,
               a.use_gps_long,
               a.use_gps_lat,
               a.facility_id as facilityId,
               a.device_id_code,
               a.createtime,
               a.alarm_type
        FROM `t_shouhuan_alarm_list` a
                 left join t_device_list b on a.device_id_code = b.device_id
                 left join t_user_profile c on c.id = b.userid
    </select>

    <insert id="insertTShouhuanAlarmList" parameterType="TShouhuanAlarmList" useGeneratedKeys="true" keyProperty="id">
        insert into t_shouhuan_alarm_list
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="facilityId != null">facility_id,</if>
            <if test="shinfoId != null">shinfo_id,</if>
            <if test="deviceIdCode != null">device_id_code,</if>
            <if test="gpsLong != null">gps_long,</if>
            <if test="gpsLat != null">gps_lat,</if>
            <if test="useGpsLong != null">use_gps_long,</if>
            <if test="useGpsLat != null">use_gps_lat,</if>
            <if test="location != null">location,</if>
            <if test="speed != null">speed,</if>
            <if test="direction != null">direction,</if>
            <if test="poster != null">poster,</if>
            <if test="electricQuantity != null">electric_quantity,</if>
            <if test="stepNumber != null">step_number,</if>
            <if test="rollNumber != null">roll_number,</if>
            <if test="statusType != null">status_type,</if>
            <if test="alarmType != null">alarm_type,</if>
            <if test="terminalStatus != null">terminal_status,</if>
            <if test="createTime != null">createtime,</if>
            <if test="alarmFromType != null">alarm_from_type,</if>
            <if test="msg != null">msg,</if>
            <if test="isSend != null">is_send,</if>
            <if test="sendTime != null">send_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="facilityId != null">#{facilityId},</if>
            <if test="shinfoId != null">#{shinfoId},</if>
            <if test="deviceIdCode != null">#{deviceIdCode},</if>
            <if test="gpsLong != null">#{gpsLong},</if>
            <if test="gpsLat != null">#{gpsLat},</if>
            <if test="useGpsLong != null">use_gps_long,</if>
            <if test="useGpsLat != null">use_gps_lat,</if>
            <if test="location != null">location,</if>
            <if test="speed != null">#{speed},</if>
            <if test="direction != null">#{direction},</if>
            <if test="poster != null">#{poster},</if>
            <if test="electricQuantity != null">#{electricQuantity},</if>
            <if test="stepNumber != null">#{stepNumber},</if>
            <if test="rollNumber != null">#{rollNumber},</if>
            <if test="statusType != null">#{statusType},</if>
            <if test="alarmType != null">#{alarmType},</if>
            <if test="terminalStatus != null">#{terminalStatus},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="alarmFromType != null">#{alarmFromType},</if>
            <if test="msg != null">#{msg},</if>
            <if test="isSend != null">#{isSend},</if>
            <if test="sendTime != null">#{sendTime},</if>
        </trim>
    </insert>

    <update id="updateTShouhuanAlarmList" parameterType="TShouhuanAlarmList">
        update t_shouhuan_alarm_list
        <trim prefix="SET" suffixOverrides=",">
            <if test="facilityId != null">facility_id = #{facilityId},</if>
            <if test="shinfoId != null">shinfo_id = #{shinfoId},</if>
            <if test="deviceIdCode != null">device_id_code = #{deviceIdCode},</if>
            <if test="gpsLong != null">gps_long = #{gpsLong},</if>
            <if test="gpsLat != null">gps_lat = #{gpsLat},</if>
            <if test="speed != null">speed = #{speed},</if>
            <if test="direction != null">direction = #{direction},</if>
            <if test="poster != null">poster = #{poster},</if>
            <if test="electricQuantity != null">electric_quantity = #{electricQuantity},</if>
            <if test="stepNumber != null">step_number = #{stepNumber},</if>
            <if test="rollNumber != null">roll_number = #{rollNumber},</if>
            <if test="statusType != null">status_type = #{statusType},</if>
            <if test="alarmType != null">alarm_type = #{alarmType},</if>
            <if test="terminalStatus != null">terminal_status = #{terminalStatus},</if>
            <if test="createTime != null">createtime = #{createTime},</if>
            <if test="alarmFromType != null">alarm_from_type = #{alarmFromType},</if>
            <if test="msg != null">msg = #{msg},</if>
            <if test="isSend != null">is_send = #{isSend},</if>
            <if test="sendTime != null">send_time = #{sendTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTShouhuanAlarmListById" parameterType="Integer">
        delete
        from t_shouhuan_alarm_list
        where id = #{id}
    </delete>

    <delete id="deleteTShouhuanAlarmListByIds" parameterType="String">
        delete from t_shouhuan_alarm_list where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>