<?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.doc.mapper.DocMapper">
    <resultMap type="Doc" id="DocResult">
        <result property="docId"    column="doc_id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="descs"    column="descs"    />
        <result property="idCard"    column="id_card"    />
        <result property="idCardFront"    column="id_card_front"    />
        <result property="idCardBack"    column="id_card_back"    />
        <result property="sex"    column="sex"    />
        <result property="birthday"    column="birthday"    />
        <result property="headImg"    column="head_img"    />
        <result property="remark"    column="remark"    />
        <result property="tags"    column="tags"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="companyUserIds"    column="company_user_ids"    />
    </resultMap>
    <sql id="selectDocVo">
        select doc_id, user_id, user_name, descs, id_card, id_card_front, id_card_back, sex, birthday, head_img, remark,tags, create_time, update_time,company_user_ids from doc
    </sql>

    <select id="selectDocList" parameterType="Doc" resultMap="DocResult">
        <include refid="selectDocVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="descs != null  and descs != ''"> and descs = #{descs}</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="idCardFront != null  and idCardFront != ''"> and id_card_front = #{idCardFront}</if>
            <if test="idCardBack != null  and idCardBack != ''"> and id_card_back = #{idCardBack}</if>
            <if test="sex != null "> and sex = #{sex}</if>
            <if test="birthday != null "> and birthday = #{birthday}</if>
            <if test="headImg != null  and headImg != ''"> and head_img = #{headImg}</if>
        </where>
    </select>
    
    <select id="selectDocById" parameterType="Long" resultMap="DocResult">
        <include refid="selectDocVo"/>
        where doc_id = #{docId}
    </select>
        
    <insert id="insertDoc" parameterType="Doc" useGeneratedKeys="true" keyProperty="docId">
        insert into doc
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="descs != null">descs,</if>
            <if test="idCard != null">id_card,</if>
            <if test="idCardFront != null">id_card_front,</if>
            <if test="idCardBack != null">id_card_back,</if>
            <if test="sex != null">sex,</if>
            <if test="birthday != null">birthday,</if>
            <if test="headImg != null">head_img,</if>
            <if test="remark != null">remark,</if>
            <if test="tags != null">tags,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="companyUserIds != null">company_user_ids,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="descs != null">#{descs},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="idCardFront != null">#{idCardFront},</if>
            <if test="idCardBack != null">#{idCardBack},</if>
            <if test="sex != null">#{sex},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="headImg != null">#{headImg},</if>
            <if test="remark != null">#{remark},</if>
            <if test="tags != null">#{tags},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="companyUserIds != null">#{companyUserIds},</if>
         </trim>
    </insert>

    <update id="updateDoc" parameterType="Doc">
        update doc
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="descs != null">descs = #{descs},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="idCardFront != null">id_card_front = #{idCardFront},</if>
            <if test="idCardBack != null">id_card_back = #{idCardBack},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="headImg != null">head_img = #{headImg},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="tags != null">tags = #{tags},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="companyUserIds != null">company_user_ids = #{companyUserIds},</if>
        </trim>
        where doc_id = #{docId}
    </update>

    <delete id="deleteDocById" parameterType="Long">
        delete from doc where doc_id = #{docId}
    </delete>

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