<?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.fs.qw.mapper.QwContactWayUserMapper">
    
    <resultMap type="QwContactWayUser" id="QwContactWayUserResult">
        <result property="id"    column="id"    />
        <result property="wayId"    column="way_id"    />
        <result property="qwUserId"    column="qw_user_id"    />
        <result property="userId"    column="user_id"    />
        <result property="limitCount"    column="limit_count"    />
        <result property="dayCount"    column="day_count"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>

    <sql id="selectQwContactWayUserVo">
        select id, way_id, qw_user_id, user_id, limit_count, day_count, company_id from qw_contact_way_user
    </sql>

    <select id="selectQwContactWayUserList" parameterType="QwContactWayUser" resultMap="QwContactWayUserResult">
        <include refid="selectQwContactWayUserVo"/>
        <where>  
            <if test="wayId != null "> and way_id = #{wayId}</if>
            <if test="qwUserId != null "> and qw_user_id = #{qwUserId}</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="limitCount != null "> and limit_count = #{limitCount}</if>
            <if test="dayCount != null "> and day_count = #{dayCount}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectQwContactWayUserById" parameterType="Long" resultMap="QwContactWayUserResult">
        <include refid="selectQwContactWayUserVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertQwContactWayUser" parameterType="QwContactWayUser" useGeneratedKeys="true" keyProperty="id">
        insert into qw_contact_way_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="wayId != null">way_id,</if>
            <if test="qwUserId != null">qw_user_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="limitCount != null">limit_count,</if>
            <if test="dayCount != null">day_count,</if>
            <if test="companyId != null">company_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="wayId != null">#{wayId},</if>
            <if test="qwUserId != null">#{qwUserId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="limitCount != null">#{limitCount},</if>
            <if test="dayCount != null">#{dayCount},</if>
            <if test="companyId != null">#{companyId},</if>
         </trim>
    </insert>

    <update id="updateQwContactWayUser" parameterType="QwContactWayUser">
        update qw_contact_way_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="wayId != null">way_id = #{wayId},</if>
            <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="limitCount != null">limit_count = #{limitCount},</if>
            <if test="dayCount != null">day_count = #{dayCount},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwContactWayUserById" parameterType="Long">
        delete from qw_contact_way_user where id = #{id}
    </delete>

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