<?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.dgtly.wxportal.mapper.WxQyUserMapper">
    
    <resultMap type="WxQyUser" id="WxQyUserResult">
        <result property="userid"    column="userid"    />
        <result property="name"    column="name"    />
        <result property="mobile"    column="mobile"    />
        <result property="gender"    column="gender"    />
        <result property="email"    column="email"    />
        <result property="avatar"    column="avatar"    />
        <result property="thumbAvatar"    column="thumb_avatar"    />
        <result property="telephone"    column="telephone"    />
        <result property="alias"    column="alias"    />
        <result property="status"    column="status"    />
        <result property="qrCode"    column="qr_code"    />
        <result property="address"    column="address"    />
        <result property="openUserid"    column="open_userid"    />
        <result property="sysUserId"    column="sys_user_id"    />
        <result property="json"    column="json"    />
    </resultMap>

    <sql id="selectWxQyUserVo">
        select userid, name, mobile, gender, email, avatar, thumb_avatar, telephone, alias, status, qr_code,
         address, open_userid,  sys_user_id,json from wx_qy_user
    </sql>

    <select id="selectWxQyUserList" parameterType="WxQyUser" resultMap="WxQyUserResult">
        <include refid="selectWxQyUserVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
           <if test="gender != null  and gender != ''"> and gender = #{gender}</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
           <if test="avatar != null  and avatar != ''"> and avatar = #{avatar}</if>
            <if test="thumbAvatar != null  and thumbAvatar != ''"> and thumb_avatar = #{thumbAvatar}</if>
            <if test="telephone != null  and telephone != ''"> and telephone = #{telephone}</if>
            <if test="alias != null  and alias != ''"> and alias = #{alias}</if>
           <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="qrCode != null  and qrCode != ''"> and qr_code = #{qrCode}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="openUserid != null  and openUserid != ''"> and open_userid = #{openUserid}</if>
            <if test="sysUserId != null "> and sys_user_id = #{sysUserId}</if>

        </where>
    </select>
    
    <select id="selectWxQyUserById" parameterType="String" resultMap="WxQyUserResult">
        <include refid="selectWxQyUserVo"/>
        where userid = #{userid}
    </select>
        
    <insert id="insertWxQyUser" parameterType="WxQyUser">
        insert into wx_qy_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userid != null  and userid != ''">userid,</if>
            <if test="name != null  and name != ''">name,</if>
            <if test="mobile != null  and mobile != ''">mobile,</if>
            <if test="gender != null  and gender != ''">gender,</if>
            <if test="email != null  and email != ''">email,</if>
            <if test="avatar != null  and avatar != ''">avatar,</if>
            <if test="thumbAvatar != null  and thumbAvatar != ''">thumb_avatar,</if>
            <if test="telephone != null  and telephone != ''">telephone,</if>
            <if test="alias != null  and alias != ''">alias,</if>
            <if test="status != null  and status != ''">status,</if>
            <if test="qrCode != null  and qrCode != ''">qr_code,</if>
            <if test="address != null  and address != ''">address,</if>
            <if test="openUserid != null  and openUserid != ''">open_userid,</if>
            <if test="sysUserId != null ">sys_user_id,</if>
            <if test="json != null ">json,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userid != null  and userid != ''">#{userid},</if>
            <if test="name != null  and name != ''">#{name},</if>
            <if test="mobile != null  and mobile != ''">#{mobile},</if>
            <if test="gender != null  and gender != ''">#{gender},</if>
            <if test="email != null  and email != ''">#{email},</if>
            <if test="avatar != null  and avatar != ''">#{avatar},</if>
            <if test="thumbAvatar != null  and thumbAvatar != ''">#{thumbAvatar},</if>
            <if test="telephone != null  and telephone != ''">#{telephone},</if>
            <if test="alias != null  and alias != ''">#{alias},</if>
            <if test="status != null  and status != ''">#{status},</if>
            <if test="qrCode != null  and qrCode != ''">#{qrCode},</if>
            <if test="address != null  and address != ''">#{address},</if>
            <if test="openUserid != null  and openUserid != ''">#{openUserid},</if>
            <if test="sysUserId != null ">#{sysUserId},</if>
            <if test="json != null ">#{json},</if>
         </trim>
    </insert>

    <update id="updateWxQyUser" parameterType="WxQyUser">
        update wx_qy_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null  and name != ''">name = #{name},</if>
            <if test="mobile != null  and mobile != ''">mobile = #{mobile},</if>
            <if test="gender != null  and gender != ''">gender = #{gender},</if>
            <if test="email != null  and email != ''">email = #{email},</if>
            <if test="avatar != null  and avatar != ''">avatar = #{avatar},</if>
            <if test="thumbAvatar != null  and thumbAvatar != ''">thumb_avatar = #{thumbAvatar},</if>
            <if test="telephone != null  and telephone != ''">telephone = #{telephone},</if>
            <if test="alias != null  and alias != ''">alias = #{alias},</if>
            <if test="status != null  and status != ''">status = #{status},</if>
            <if test="qrCode != null  and qrCode != ''">qr_code = #{qrCode},</if>
            <if test="address != null  and address != ''">address = #{address},</if>
            <if test="openUserid != null  and openUserid != ''">open_userid = #{openUserid},</if>
            <if test="sysUserId != null ">sys_user_id = #{sysUserId},</if>
            <if test="json != null "> json = #{json},</if>
        </trim>
        where userid = #{userid}
    </update>

    <delete id="deleteWxQyUserById" parameterType="String">
        delete from wx_qy_user where userid = #{userid}
    </delete>

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

    <update id="bondedSysUserBySysUserId" parameterType="Long">
        update wx_qy_user
        set sys_user_id = null
        where sys_user_id = #{sysUserId}
    </update>

    <select id="selectWxQyUserBySysUserId" parameterType="String" resultMap="WxQyUserResult">
        <include refid="selectWxQyUserVo"/>
        where sys_user_id = #{sysUserId}
    </select>
    
</mapper>