<?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.QywxUserMapper">

    <resultMap type="QywxUser" id="QywxUserResult">
        <result property="id"    column="id"    />
        <result property="corpId"    column="corp_id"    />
        <result property="userId"    column="user_id"    />
        <result property="name"    column="name"    />
        <result property="department"    column="department"    />
        <result property="mainDepartment"    column="main_department"    />
        <result property="parentid"    column="parentid"    />
        <result property="position"    column="position"    />
        <result property="gender"    column="gender"    />
        <result property="email"    column="email"    />
        <result property="isLeaderInDept"    column="is_leader_in_dept"    />
        <result property="avatar"    column="avatar"    />
        <result property="thumbAvatar"    column="thumb_avatar"    />
        <result property="telephone"    column="telephone"    />
        <result property="alias"    column="alias"    />
        <result property="address"    column="address"    />
        <result property="openUserid"    column="open_userid"    />

        <result property="qrCode"    column="qr_code"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectQywxUserVo">
        select id, corp_id, user_id, name, parentid, position, gender, email, is_leader_in_dept, avatar, thumb_avatar, telephone, alias, address, open_userid,department, main_department, qr_code, status, create_time, update_time from qywx_user
    </sql>

    <select id="selectQywxUserList" parameterType="QywxUser" resultMap="QywxUserResult">
        <include refid="selectQywxUserVo"/>
        <where>
            <if test="corpId != null  and corpId != ''"> and corp_id = #{corpId}</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="parentid != null "> and parentid = #{parentid}</if>
            <if test="position != null  and position != ''"> and position = #{position}</if>
            <if test="gender != null  and gender != ''"> and gender = #{gender}</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
            <if test="isLeaderInDept != null  and isLeaderInDept != ''"> and is_leader_in_dept = #{isLeaderInDept}</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="address != null  and address != ''"> and address = #{address}</if>
            <if test="department != null  and department != ''"> and department = #{department}</if>
            <if test="mainDepartment != null "> and main_department = #{mainDepartment}</if>
            <if test="qrCode != null  and qrCode != ''"> and qr_code = #{qrCode}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>

    <select id="selectQywxUserById" parameterType="Integer" resultMap="QywxUserResult">
        <include refid="selectQywxUserVo"/>
        where id = #{id}
    </select>

    <insert id="insertQywxUser" parameterType="QywxUser" useGeneratedKeys="true" keyProperty="id">
        insert into qywx_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="corpId != null and corpId != ''">corp_id,</if>
            <if test="userId != null and userId != ''">user_id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="parentid != null">parentid,</if>
            <if test="position != null and position != ''">position,</if>
            <if test="gender != null and gender != ''">gender,</if>
            <if test="email != null and email != ''">email,</if>
            <if test="isLeaderInDept != null and isLeaderInDept != ''">is_leader_in_dept,</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="address != null and address != ''">address,</if>
            <if test="openUserid != null and openUserid != ''">open_userid,</if>
            <if test="department != null  and department != ''"> and department = #{department}</if>
            <if test="mainDepartment != null">main_department,</if>
            <if test="qrCode != null and qrCode != ''">qr_code,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="corpId != null and corpId != ''">#{corpId},</if>
            <if test="userId != null and userId != ''">#{userId},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="parentid != null">#{parentid},</if>
            <if test="position != null and position != ''">#{position},</if>
            <if test="gender != null and gender != ''">#{gender},</if>
            <if test="email != null and email != ''">#{email},</if>
            <if test="isLeaderInDept != null and isLeaderInDept != ''">#{isLeaderInDept},</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="address != null and address != ''">#{address},</if>
            <if test="openUserid != null and openUserid != ''">#{openUserid},</if>
            <if test="department != null and department != ''">#{department},</if>
            <if test="mainDepartment != null">#{mainDepartment},</if>
            <if test="qrCode != null and qrCode != ''">#{qrCode},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateQywxUser" parameterType="QywxUser">
        update qywx_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="corpId != null and corpId != ''">corp_id = #{corpId},</if>
            <if test="userId != null and userId != ''">user_id = #{userId},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="parentid != null">parentid = #{parentid},</if>
            <if test="position != null and position != ''">position = #{position},</if>
            <if test="gender != null and gender != ''">gender = #{gender},</if>
            <if test="email != null and email != ''">email = #{email},</if>
            <if test="isLeaderInDept != null and isLeaderInDept != ''">is_leader_in_dept = #{isLeaderInDept},</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="address != null and address != ''">address = #{address},</if>
            <if test="openUserid != null and openUserid != ''">open_userid = #{openUserid},</if>
            <if test="department != null and department != ''">department = #{department},</if>
            <if test="mainDepartment != null">main_department = #{mainDepartment},</if>
            <if test="qrCode != null and qrCode != ''">qr_code = #{qrCode},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQywxUserById" parameterType="Integer">
        delete from qywx_user where id = #{id}
    </delete>

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