<?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.wxUser.mapper.CompanyWxUserMapper">
    
    <resultMap type="CompanyWxUser" id="CompanyWxUserResult">
        <result property="userId"    column="user_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="nickName"    column="nick_name"    />
        <result property="weixinId"    column="weixin_id"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="avatar"    column="avatar"    />
        <result property="groupId"    column="group_id"    />
        <result property="fsUserId"    column="fs_user_id"    />
    </resultMap>

    <sql id="selectCompanyWxUserVo">
        select user_id, company_id, company_user_id, nick_name, weixin_id, status, remark, create_time, avatar,group_id,fs_user_id from company_wx_user
    </sql>

    <select id="selectCompanyWxUserList" parameterType="CompanyWxUser" resultMap="CompanyWxUserResult">
        <include refid="selectCompanyWxUserVo"/>
        <where>  
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="nickName != null  and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
            <if test="weixinId != null  and weixinId != ''"> and weixin_id = #{weixinId}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="avatar != null  and avatar != ''"> and avatar = #{avatar}</if>
            <if test="groupId != null  and groupId != ''"> and group_id = #{groupId}</if>
            <if test="fsUserId != null  and fsUserId != ''"> and fs_user_id = #{fsUserId}</if>
        </where>
    </select>
    
    <select id="selectCompanyWxUserByUserId" parameterType="Long" resultMap="CompanyWxUserResult">
        <include refid="selectCompanyWxUserVo"/>
        where user_id = #{userId}
    </select>
        
    <insert id="insertCompanyWxUser" parameterType="CompanyWxUser" useGeneratedKeys="true" keyProperty="userId">
        insert into company_wx_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="nickName != null">nick_name,</if>
            <if test="weixinId != null">weixin_id,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="avatar != null">avatar,</if>
            <if test="groupId != null">group_id,</if>
            <if test="fsUserId != null">fs_user_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="nickName != null">#{nickName},</if>
            <if test="weixinId != null">#{weixinId},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="avatar != null">#{avatar},</if>
            <if test="groupId != null">#{groupId},</if>
            <if test="fsUserId != null">#{fsUserId},</if>
         </trim>
    </insert>

    <update id="updateCompanyWxUser" parameterType="CompanyWxUser">
        update company_wx_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="nickName != null">nick_name = #{nickName},</if>
            <if test="weixinId != null">weixin_id = #{weixinId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="avatar != null">avatar = #{avatar},</if>
            <if test="groupId != null">group_id = #{groupId},</if>
            <if test="fsUserId != null">fs_user_id = #{fsUserId},</if>
        </trim>
        where user_id = #{userId}
    </update>

    <delete id="deleteCompanyWxUserByUserId" parameterType="Long">
        delete from company_wx_user where user_id = #{userId}
    </delete>

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