<?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.ruoyi.oa.mapper.CmcContractCommentMapper">
    
    <resultMap type="CmcContractComment" id="CmcContractCommentResult">
        <result property="commentId"    column="comment_id"    />
        <result property="contractId"    column="contract_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="userId"    column="user_id"    />
        <result property="comment"    column="comment"    />
        <result property="document"    column="document"    />
        <result property="commentTime"    column="comment_time"    />
        <association property="commentUser"    javaType="SysUser"         resultMap="CommentUserResult" />
    </resultMap>

    <resultMap type="SysUser" id="CommentUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="nick_name"    />
    </resultMap>

    <sql id="selectCmcContractCommentVo">
        select cc.comment_id, cc.contract_id, cc.dept_id, cc.user_id, u.nick_name, cc.comment, cc.document, cc.comment_time from cmc_contract_comment as cc
        left join sys_user as u on u.user_id = cc.user_id
    </sql>

    <select id="selectCmcContractCommentList" parameterType="CmcContractComment" resultMap="CmcContractCommentResult">
        <include refid="selectCmcContractCommentVo"/>
        <where>
            <if test="contractId != null  and contractId != ''"> and contract_id like concat('%', #{contractId}, '%')</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="comment != null  and comment != ''"> and comment = #{comment}</if>
            <if test="document != null  and document != ''"> and document = #{document}</if>
            <if test="commentTime != null "> and comment_time = #{commentTime}</if>
        </where>
    </select>

    <select id="selectCmcContractCommentByContractId" parameterType="String" resultMap="CmcContractCommentResult">
        <include refid="selectCmcContractCommentVo"/>
        where cc.contract_id = #{contractId}
    </select>

    <insert id="insertCmcContractComment" parameterType="CmcContractComment">
        insert into cmc_contract_comment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="commentId != null">comment_id,</if>
            <if test="contractId != null">contract_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="comment != null">comment,</if>
            <if test="document != null">document,</if>
            <if test="commentTime != null">comment_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="commentId != null">#{commentId},</if>
            <if test="contractId != null">#{contractId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="comment != null">#{comment},</if>
            <if test="document != null">#{document},</if>
            <if test="commentTime != null">#{commentTime},</if>
         </trim>
    </insert>

    <update id="updateCmcContractComment" parameterType="CmcContractComment">
        update cmc_contract_comment
        <trim prefix="SET" suffixOverrides=",">
            <if test="contractId != null">contract_id = #{contractId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="comment != null">comment = #{comment},</if>
            <if test="document != null">document = #{document},</if>
            <if test="commentTime != null">comment_time = #{commentTime},</if>
        </trim>
        where comment_id = #{commentId}
    </update>

    <delete id="deleteCmcContractCommentByContractId" parameterType="String">
        delete from cmc_contract_comment where contract_id = #{contractId}
    </delete>

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