<?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.CmcProjectCommentMapper">
    
    <resultMap type="CmcProjectComment" id="CmcProjectCommentResult">
        <result property="projectId"    column="project_id"    />
        <result property="jyComment"    column="jy_comment"    />
        <result property="jyApprover"    column="jy_approver"    />
        <result property="jyApprovalTime"    column="jy_approval_time"    />
        <result property="manageComment"    column="manage_comment"    />
        <result property="manageApprover"    column="manage_approver"    />
        <result property="manageApprovalTime"    column="manage_approval_time"    />
        <result property="scComment"    column="sc_comment"    />
        <result property="scApprover"    column="sc_approver"    />
        <result property="scApprovalTime"    column="sc_approval_time"    />
        <association property="jyUser"    javaType="SysUser"         resultMap="JyUserResult" />
        <association property="managerUser"    javaType="SysUser"         resultMap="ManagerUserResult" />
    </resultMap>

    <resultMap type="SysUser" id="JyUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="jy_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="ManagerUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="manager_nick_name"    />
    </resultMap>

    <sql id="selectCmcProjectCommentVo">
        select pc.project_id, pc.jy_comment, pc.jy_approver, u.nick_name as jy_nick_name, pc.jy_approval_time, pc.manage_comment, pc.manage_approver,
               u1.nick_name as manager_nick_name, pc.manage_approval_time, pc.sc_comment, pc.sc_approver, pc.sc_approval_time from cmc_project_comment as pc
        left join sys_user as u on u.user_id = pc.jy_approver
        left join sys_user as u1 on u1.user_id = pc.manage_approver
    </sql>

    <select id="selectCmcProjectCommentList" parameterType="CmcProjectComment" resultMap="CmcProjectCommentResult">
        <include refid="selectCmcProjectCommentVo"/>
        <where>  
            <if test="projectId != null  and projectId != ''"> and pc.project_id = #{projectId}</if>
            <if test="jyComment != null  and jyComment != ''"> and pc.jy_comment = #{jyComment}</if>
            <if test="jyApprover != null "> and pc.jy_approver = #{jyApprover}</if>
            <if test="jyApprovalTime != null "> and pc.jy_approval_time = #{jyApprovalTime}</if>
            <if test="manageComment != null  and manageComment != ''"> and pc.manage_comment = #{manageComment}</if>
            <if test="manageApprover != null "> and pc.manage_approver = #{manageApprover}</if>
            <if test="manageApprovalTime != null "> and pc.manage_approval_time = #{manageApprovalTime}</if>
            <if test="scComment != null  and scComment != ''"> and pc.sc_comment = #{scComment}</if>
            <if test="scApprover != null  and scApprover != ''"> and pc.sc_approver = #{scApprover}</if>
            <if test="scApprovalTime != null "> and pc.sc_approval_time = #{scApprovalTime}</if>
        </where>
    </select>
    
    <select id="selectCmcProjectCommentByProjectId" parameterType="String" resultMap="CmcProjectCommentResult">
        <include refid="selectCmcProjectCommentVo"/>
        where pc.project_id = #{projectId}
    </select>
        
    <insert id="insertCmcProjectComment" parameterType="CmcProjectComment">
        insert into cmc_project_comment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectId != null">project_id,</if>
            <if test="jyComment != null">jy_comment,</if>
            <if test="jyApprover != null">jy_approver,</if>
            <if test="jyApprovalTime != null">jy_approval_time,</if>
            <if test="manageComment != null">manage_comment,</if>
            <if test="manageApprover != null">manage_approver,</if>
            <if test="manageApprovalTime != null">manage_approval_time,</if>
            <if test="scComment != null">sc_comment,</if>
            <if test="scApprover != null">sc_approver,</if>
            <if test="scApprovalTime != null">sc_approval_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectId != null">#{projectId},</if>
            <if test="jyComment != null">#{jyComment},</if>
            <if test="jyApprover != null">#{jyApprover},</if>
            <if test="jyApprovalTime != null">#{jyApprovalTime},</if>
            <if test="manageComment != null">#{manageComment},</if>
            <if test="manageApprover != null">#{manageApprover},</if>
            <if test="manageApprovalTime != null">#{manageApprovalTime},</if>
            <if test="scComment != null">#{scComment},</if>
            <if test="scApprover != null">#{scApprover},</if>
            <if test="scApprovalTime != null">#{scApprovalTime},</if>
         </trim>
    </insert>

    <update id="updateCmcProjectComment" parameterType="CmcProjectComment">
        update cmc_project_comment
        <trim prefix="SET" suffixOverrides=",">
            <if test="jyComment != null">jy_comment = #{jyComment},</if>
            <if test="jyApprover != null">jy_approver = #{jyApprover},</if>
            <if test="jyApprovalTime != null">jy_approval_time = #{jyApprovalTime},</if>
            <if test="manageComment != null">manage_comment = #{manageComment},</if>
            <if test="manageApprover != null">manage_approver = #{manageApprover},</if>
            <if test="manageApprovalTime != null">manage_approval_time = #{manageApprovalTime},</if>
            <if test="scComment != null">sc_comment = #{scComment},</if>
            <if test="scApprover != null">sc_approver = #{scApprover},</if>
            <if test="scApprovalTime != null">sc_approval_time = #{scApprovalTime},</if>
        </trim>
        where project_id = #{projectId}
    </update>

    <delete id="deleteCmcProjectCommentByProjectId" parameterType="String">
        delete from cmc_project_comment where project_id = #{projectId}
    </delete>

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