<?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.DocRecordMapper">
    
    <resultMap type="DocRecord" id="DocRecordResult">
        <result property="recordId"    column="record_id"    />
        <result property="docId"    column="doc_id"    />
        <result property="userId"    column="user_id"    />
        <result property="recordType"    column="record_type"    />
        <result property="title"    column="title"    />
        <result property="content"    column="content"    />
        <result property="images"    column="images"    />
        <result property="jsonInfo"    column="json_info"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyUserId"    column="company_user_id"    />
    </resultMap>

    <sql id="selectDocRecordVo">
        select record_id, doc_id,user_id, record_type, title, content,images, json_info, remark, create_time, update_time, company_id, company_user_id from doc_record
    </sql>

    <select id="selectDocRecordList" parameterType="DocRecord" resultMap="DocRecordResult">
        <include refid="selectDocRecordVo"/>
        <where>  
            <if test="docId != null "> and doc_id = #{docId}</if>
            <if test="recordType != null "> and record_type = #{recordType}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="jsonInfo != null  and jsonInfo != ''"> and json_info = #{jsonInfo}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
        </where>
    </select>
    
    <select id="selectDocRecordById" parameterType="Long" resultMap="DocRecordResult">
        <include refid="selectDocRecordVo"/>
        where record_id = #{recordId}
    </select>
        
    <insert id="insertDocRecord" parameterType="DocRecord" useGeneratedKeys="true" keyProperty="recordId">
        insert into doc_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="docId != null">doc_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="recordType != null">record_type,</if>
            <if test="title != null">title,</if>
            <if test="content != null">content,</if>
            <if test="images != null">images,</if>
            <if test="jsonInfo != null">json_info,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="companyId != null">company_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="docId != null">#{docId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="recordType != null">#{recordType},</if>
            <if test="title != null">#{title},</if>
            <if test="content != null">#{content},</if>
            <if test="images != null">#{images},</if>
            <if test="jsonInfo != null">#{jsonInfo},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
         </trim>
    </insert>

    <update id="updateDocRecord" parameterType="DocRecord">
        update doc_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="docId != null">doc_id = #{docId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="recordType != null">record_type = #{recordType},</if>
            <if test="title != null">title = #{title},</if>
            <if test="content != null">content = #{content},</if>
            <if test="images != null">images = #{images},</if>
            <if test="jsonInfo != null">json_info = #{jsonInfo},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
        </trim>
        where record_id = #{recordId}
    </update>

    <delete id="deleteDocRecordById" parameterType="Long">
        delete from doc_record where record_id = #{recordId}
    </delete>

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