<?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.TFallSolveMapper">

    <resultMap type="TFallSolve" id="TFallSolveResult">
        <result property="id" column="id"/>
        <result property="aid" column="aid"/>
        <result property="uid" column="uid"/>
        <result property="userid" column="userid"/>
        <result property="deviceIdCode" column="device_id_code"/>
        <result property="alarmMsg" column="alarm_msg"/>
        <result property="solve_status" column="solve_status"/>
        <result property="serviceUserid" column="service_userid"/>
        <result property="msg" column="msg"/>
        <result property="createtime" column="createtime"/>
        <result property="name" column="name"/>
        <result property="tel_one" column="tel_one"/>
        <result property="device_model" column="device_model"/>
        <result property="device_id_code" column="device_id_code"/>
        <result property="alarm_type" column="alarm_type"/>
        <result property="address_desc" column="address_desc"/>
        <result property="store_name" column="store_name"/>
        <result property="gps_long" column="gps_long"/>
        <result property="gps_lat" column="gps_lat"/>
    </resultMap>

    <sql id="selectTFallSolveVo">
        select id,
               userid,
               device_id_code,
               alarm_msg,
               solve_status,
               service_userid,
               msg,
               createtime,
               alarmid
        from t_fall_solve
    </sql>

    <select id="selectTFallSolveList" parameterType="TFallSolve" resultMap="TFallSolveResult">
        SELECT a.id as uid, d.id as
        aid,a.name,a.tel_one,b.store_name,c.device_model,d.device_id_code,d.alarm_type,d.createtime,e.address_desc,d.gps_long,d.gps_lat,f.id,f.userid,f.alarm_msg,f.solve_status,f.msg
        FROM `t_user_profile` a
        left join t_service_manage b on a.serviceid=b.id
        left join t_device_list c on a.id=c.userid
        left join t_shouhuan_alarm_list d on d.device_id_code=c.device_id
        left join t_shouhuan_info e on e.id=d.shinfo_id
        left join t_fall_solve f on f.alarmid=d.id
        <where>
            <if test="name != null  and name != ''">and a.name = #{name}</if>
            <if test="solve_status != null">and f.solve_status = #{solve_status}</if>
            and d.alarm_type=21
        </where>
        order by d.createtime desc
    </select>

    <select id="selectTFallSolveById" parameterType="Integer" resultMap="TFallSolveResult">
        <include refid="selectTFallSolveVo"/>
        where id = #{id}
    </select>
    <select id="selectTFallSolveByAid" parameterType="Integer" resultMap="TFallSolveResult">
        <include refid="selectTFallSolveVo"/>
        where alarmid = #{aid}
    </select>

    <insert id="insertTFallSolve" parameterType="TFallSolve" useGeneratedKeys="true" keyProperty="id">
        insert into t_fall_solve
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="uid != null">userid,</if>
            <if test="deviceIdCode != null">device_id_code,</if>
            <if test="alarmMsg != null">alarm_msg,</if>
            <if test="solve_status != null">solve_status,</if>
            <if test="serviceUserid != null">service_userid,</if>
            <if test="msg != null">msg,</if>
            <if test="createTime != null">createtime,</if>
            <if test="aid != null">alarmid,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="uid != null">#{uid},</if>
            <if test="deviceIdCode != null">#{deviceIdCode},</if>
            <if test="alarmMsg != null">#{alarmMsg},</if>
            <if test="solve_status != null">#{solve_status},</if>
            <if test="serviceUserid != null">#{serviceUserid},</if>
            <if test="msg != null">#{msg},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="aid != null">#{aid},</if>
        </trim>
    </insert>

    <update id="updateTFallSolve" parameterType="TFallSolve">
        update t_fall_solve
        <trim prefix="SET" suffixOverrides=",">
            <if test="userid != null">userid = #{userid},</if>
            <if test="deviceIdCode != null">device_id_code = #{deviceIdCode},</if>
            <if test="alarmMsg != null">alarm_msg = #{alarmMsg},</if>
            <if test="solve_status != null">solve_status = #{solve_status},</if>
            <if test="serviceUserid != null">service_userid = #{serviceUserid},</if>
            <if test="msg != null">msg = #{msg},</if>
            <if test="createTime != null">createtime = #{createTime},</if>
            <if test="aid != null">alarmid = #{aid},</if>
        </trim>
        where alarmid = #{aid}
    </update>

    <delete id="deleteTFallSolveById" parameterType="Integer">
        delete
        from t_fall_solve
        where id = #{id}
    </delete>

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