<?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.qywx.mapper.QywxCustomUserMapper">
    
    <resultMap type="QywxCustomUser" id="QywxCustomUserResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="remark"    column="remark"    />
        <result property="description"    column="description"    />
        <result property="tagId"    column="tag_id"    />
        <result property="remarkMobiles"    column="remark_mobiles"    />
        <result property="remarkCorpName"    column="remark_corp_name"    />
        <result property="addWay"    column="add_way"    />
        <result property="operUserid"    column="oper_userid"    />
        <result property="externalUserid"    column="external_userid"    />
        <result property="name"    column="name"    />
        <result property="type"    column="type"    />
    </resultMap>

    <sql id="selectQywxCustomUserVo">
        select id, user_id, remark, description, tag_id, remark_mobiles, remark_corp_name, add_way, oper_userid, external_userid, name, type from qywx_custom_user
    </sql>

    <select id="selectQywxCustomUserList" parameterType="QywxCustomUser" resultMap="QywxCustomUserResult">
        <include refid="selectQywxCustomUserVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="tagId != null "> and tag_id = #{tagId}</if>
            <if test="remarkMobiles != null  and remarkMobiles != ''"> and remark_mobiles = #{remarkMobiles}</if>
            <if test="remarkCorpName != null  and remarkCorpName != ''"> and remark_corp_name like concat('%', #{remarkCorpName}, '%')</if>
            <if test="addWay != null "> and add_way = #{addWay}</if>
            <if test="operUserid != null  and operUserid != ''"> and oper_userid = #{operUserid}</if>
            <if test="externalUserid != null  and externalUserid != ''"> and external_userid = #{externalUserid}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
        </where>
    </select>
    
    <select id="selectQywxCustomUserById" parameterType="Long" resultMap="QywxCustomUserResult">
        <include refid="selectQywxCustomUserVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertQywxCustomUser" parameterType="QywxCustomUser">
        insert into qywx_custom_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userId != null">user_id,</if>
            <if test="remark != null">remark,</if>
            <if test="description != null">description,</if>
            <if test="tagId != null">tag_id,</if>
            <if test="remarkMobiles != null">remark_mobiles,</if>
            <if test="remarkCorpName != null">remark_corp_name,</if>
            <if test="addWay != null">add_way,</if>
            <if test="operUserid != null">oper_userid,</if>
            <if test="externalUserid != null">external_userid,</if>
            <if test="name != null">name,</if>
            <if test="type != null">type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="userId != null">#{userId},</if>
            <if test="remark != null">#{remark},</if>
            <if test="description != null">#{description},</if>
            <if test="tagId != null">#{tagId},</if>
            <if test="remarkMobiles != null">#{remarkMobiles},</if>
            <if test="remarkCorpName != null">#{remarkCorpName},</if>
            <if test="addWay != null">#{addWay},</if>
            <if test="operUserid != null">#{operUserid},</if>
            <if test="externalUserid != null">#{externalUserid},</if>
            <if test="name != null">#{name},</if>
            <if test="type != null">#{type},</if>
         </trim>
    </insert>

    <update id="updateQywxCustomUser" parameterType="QywxCustomUser">
        update qywx_custom_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="description != null">description = #{description},</if>
            <if test="tagId != null">tag_id = #{tagId},</if>
            <if test="remarkMobiles != null">remark_mobiles = #{remarkMobiles},</if>
            <if test="remarkCorpName != null">remark_corp_name = #{remarkCorpName},</if>
            <if test="addWay != null">add_way = #{addWay},</if>
            <if test="operUserid != null">oper_userid = #{operUserid},</if>
            <if test="externalUserid != null">external_userid = #{externalUserid},</if>
            <if test="name != null">name = #{name},</if>
            <if test="type != null">type = #{type},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQywxCustomUserById" parameterType="Long">
        delete from qywx_custom_user where id = #{id}
    </delete>

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