<?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.zehong.system.mapper.TYehuaqiuserSafetyDeviceInfoMapper">
    
    <resultMap type="TYehuaqiuserSafetyDeviceInfo" id="TYehuaqiuserSafetyDeviceInfoResult">
        <result property="fSafetyDeviceId"    column="f_safety_device_id"    />
        <result property="fRelationUserId"    column="f_relation_user_id"    />
        <result property="fRelationDeviceType"    column="f_relation_device_type"    />
        <result property="fDeviceName"    column="f_device_name"    />
        <result property="fDeviceModel"    column="f_device_model"    />
        <result property="fIotNo"    column="f_iot_no"    />
        <result property="fDetectionMedium"    column="f_detection_medium"    />
        <result property="fDeviceInstallTime"    column="f_device_install_time"    />
        <result property="fDeviceInstallPosition"    column="f_device_install_position"    />
        <result property="fHead"    column="f_head"    />
        <result property="fPhone"    column="f_phone"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectTYehuaqiuserSafetyDeviceInfoVo">
        select f_safety_device_id, f_relation_user_id, f_relation_device_type, f_device_name, f_device_model, f_iot_no, f_detection_medium, f_device_install_time, f_device_install_position, f_head, f_phone, is_del from t_yehuaqiuser_safety_device_info
    </sql>

    <select id="selectTYehuaqiuserSafetyDeviceInfoList" parameterType="TYehuaqiuserSafetyDeviceInfo" resultMap="TYehuaqiuserSafetyDeviceInfoResult">
        <include refid="selectTYehuaqiuserSafetyDeviceInfoVo"/>
        <where>  
            <if test="fRelationUserId != null "> and f_relation_user_id = #{fRelationUserId}</if>
            <if test="fRelationDeviceType != null  and fRelationDeviceType != ''"> and f_relation_device_type = #{fRelationDeviceType}</if>
            <if test="fDeviceName != null  and fDeviceName != ''"> and f_device_name like concat('%', #{fDeviceName}, '%')</if>
            <if test="fDeviceModel != null  and fDeviceModel != ''"> and f_device_model = #{fDeviceModel}</if>
            <if test="fIotNo != null  and fIotNo != ''"> and f_iot_no = #{fIotNo}</if>
            <if test="fDetectionMedium != null  and fDetectionMedium != ''"> and f_detection_medium = #{fDetectionMedium}</if>
            <if test="fDeviceInstallTime != null "> and f_device_install_time = #{fDeviceInstallTime}</if>
            <if test="fDeviceInstallPosition != null  and fDeviceInstallPosition != ''"> and f_device_install_position = #{fDeviceInstallPosition}</if>
            <if test="fHead != null  and fHead != ''"> and f_head = #{fHead}</if>
            <if test="fPhone != null  and fPhone != ''"> and f_phone = #{fPhone}</if>
            <if test="isDel != null  and isDel != ''"> and is_del = #{isDel}</if>
        </where>
    </select>
    
    <select id="selectTYehuaqiuserSafetyDeviceInfoById" parameterType="Long" resultMap="TYehuaqiuserSafetyDeviceInfoResult">
        <include refid="selectTYehuaqiuserSafetyDeviceInfoVo"/>
        where f_safety_device_id = #{fSafetyDeviceId}
    </select>
    <select id="queryDeviceInfoByUserId" parameterType="Long" resultMap="TYehuaqiuserSafetyDeviceInfoResult">
        <include refid="selectTYehuaqiuserSafetyDeviceInfoVo"/>
        where f_relation_user_id = #{userId}
    </select>
        
    <insert id="insertTYehuaqiuserSafetyDeviceInfo" parameterType="TYehuaqiuserSafetyDeviceInfo" useGeneratedKeys="true" keyProperty="fSafetyDeviceId">
        insert into t_yehuaqiuser_safety_device_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fRelationUserId != null">f_relation_user_id,</if>
            <if test="fRelationDeviceType != null">f_relation_device_type,</if>
            <if test="fDeviceName != null">f_device_name,</if>
            <if test="fDeviceModel != null">f_device_model,</if>
            <if test="fIotNo != null">f_iot_no,</if>
            <if test="fDetectionMedium != null">f_detection_medium,</if>
            <if test="fDeviceInstallTime != null">f_device_install_time,</if>
            <if test="fDeviceInstallPosition != null">f_device_install_position,</if>
            <if test="fHead != null">f_head,</if>
            <if test="fPhone != null">f_phone,</if>
            <if test="isDel != null">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fRelationUserId != null">#{fRelationUserId},</if>
            <if test="fRelationDeviceType != null">#{fRelationDeviceType},</if>
            <if test="fDeviceName != null">#{fDeviceName},</if>
            <if test="fDeviceModel != null">#{fDeviceModel},</if>
            <if test="fIotNo != null">#{fIotNo},</if>
            <if test="fDetectionMedium != null">#{fDetectionMedium},</if>
            <if test="fDeviceInstallTime != null">#{fDeviceInstallTime},</if>
            <if test="fDeviceInstallPosition != null">#{fDeviceInstallPosition},</if>
            <if test="fHead != null">#{fHead},</if>
            <if test="fPhone != null">#{fPhone},</if>
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <insert id="insertBatch" parameterType="list">
        insert into t_yehuaqiuser_safety_device_info (f_relation_user_id, f_relation_device_type, f_device_name,
        f_device_model, f_iot_no,f_detection_medium, f_device_install_time,
        f_device_install_position,f_head,f_phone)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.fRelationUserId}, #{item.fRelationDeviceType,jdbcType=VARCHAR},
            #{item.fDeviceName,jdbcType=VARCHAR}, #{item.fDeviceModel,jdbcType=VARCHAR}, #{item.fIotNo,jdbcType=VARCHAR},
            #{item.fDetectionMedium,jdbcType=DECIMAL}, #{item.fDeviceInstallTime,jdbcType=DECIMAL},
            #{item.fDeviceInstallPosition,jdbcType=VARCHAR},#{item.fHead,jdbcType=VARCHAR}, #{item.fPhone,jdbcType=TIMESTAMP}
            )
        </foreach>
    </insert>
    <delete id="deleteBatchSafetyDeviceByUserIds" parameterType="list">
        delete from t_yehuaqiuser_safety_device_info where f_relation_user_id in
        <foreach collection="list" close=")" separator="," open="(" item="item" index="i">
            #{item}
        </foreach>

    </delete>

    <update id="updateTYehuaqiuserSafetyDeviceInfo" parameterType="TYehuaqiuserSafetyDeviceInfo">
        update t_yehuaqiuser_safety_device_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="fRelationUserId != null">f_relation_user_id = #{fRelationUserId},</if>
            <if test="fRelationDeviceType != null">f_relation_device_type = #{fRelationDeviceType},</if>
            <if test="fDeviceName != null">f_device_name = #{fDeviceName},</if>
            <if test="fDeviceModel != null">f_device_model = #{fDeviceModel},</if>
            <if test="fIotNo != null">f_iot_no = #{fIotNo},</if>
            <if test="fDetectionMedium != null">f_detection_medium = #{fDetectionMedium},</if>
            <if test="fDeviceInstallTime != null">f_device_install_time = #{fDeviceInstallTime},</if>
            <if test="fDeviceInstallPosition != null">f_device_install_position = #{fDeviceInstallPosition},</if>
            <if test="fHead != null">f_head = #{fHead},</if>
            <if test="fPhone != null">f_phone = #{fPhone},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where f_safety_device_id = #{fSafetyDeviceId}
    </update>

    <delete id="deleteTYehuaqiuserSafetyDeviceInfoById" parameterType="Long">
        delete from t_yehuaqiuser_safety_device_info where f_safety_device_id = #{fSafetyDeviceId}
    </delete>

    <select id="deleteYehuaqiuserSafetyDeviceInfoUserId" parameterType="Long">
        delete from t_yehuaqiuser_safety_device_info where f_relation_user_id = #{userId}
    </select>

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