<?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.CmcTechnicalMapper">
    
    <resultMap type="CmcTechnical" id="CmcTechnicalResult">
        <result property="technicalId"    column="technical_id"    />
        <result property="projectId"    column="project_id"    />
        <result property="disclosureAccepter"    column="disclosure_accepter"    />
        <result property="disclosurer"    column="disclosurer"    />
        <result property="content"    column="content"    />
        <result property="document"    column="document"    />
        <result property="disclosureComment"    column="disclosure_comment"    />
        <result property="acceptComment"    column="accept_comment"    />
        <result property="disclosureTime"    column="disclosure_time"    />
        <result property="acceptTime"    column="accept_time"    />
        <association property="accepterUser"    javaType="SysUser"         resultMap="AccepterUserResult" />
        <association property="disclosurerUser"    javaType="SysUser"         resultMap="DisclosurerUserResult" />
        <association property="project"    javaType="CmcProject"         resultMap="CmcProjectResult" />
    </resultMap>

    <resultMap type="SysUser" id="AccepterUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="accepter_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="DisclosurerUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="disclosurer_nick_name"    />
    </resultMap>

    <resultMap type="CmcProject" id="CmcProjectResult">
        <result property="projectId"    column="project_id"    />
        <result property="projectNumber"    column="project_number"    />
        <result property="projectName"    column="project_name"    />
    </resultMap>

    <sql id="selectCmcTechnicalVo">
        select t.technical_id, t.project_id, p.project_number, p.project_name, t.disclosure_accepter, u.nick_name as accepter_nick_name, t.disclosurer, 
        u1.nick_name as disclosurer_nick_name, t.content, t.document, t.disclosure_comment, t.accept_comment, t.disclosure_time, t.accept_time from cmc_technical as t
        left join sys_user as u on u.user_id = t.disclosure_accepter
        left join sys_user as u1 on u1.user_id = t.disclosurer
        left join cmc_project as p on p.project_id = t.project_id
    </sql>

    <select id="selectCmcTechnicalList" parameterType="CmcTechnical" resultMap="CmcTechnicalResult">
        <include refid="selectCmcTechnicalVo"/>
        <where>  
            <if test="projectId != null  and projectId != ''"> and t.project_id = #{projectId}</if>
            <if test="disclosureAccepter != null "> and t.disclosure_accepter = #{disclosureAccepter}</if>
            <if test="disclosurer != null "> and t.disclosurer = #{disclosurer}</if>
            <if test="content != null  and content != ''"> and t.content = #{content}</if>
            <if test="document != null  and document != ''"> and t.document = #{document}</if>
            <if test="disclosureComment != null  and disclosureComment != ''"> and t.disclosure_comment = #{disclosureComment}</if>
            <if test="acceptComment != null  and acceptComment != ''"> and t.accept_comment = #{acceptComment}</if>
            <if test="disclosureTime != null "> and t.disclosure_time = #{disclosureTime}</if>
            <if test="acceptTime != null "> and t.accept_time = #{acceptTime}</if>
        </where>
        order by t.disclosure_time desc
    </select>
    
    <select id="selectCmcTechnicalByTechnicalId" parameterType="String" resultMap="CmcTechnicalResult">
        <include refid="selectCmcTechnicalVo"/>
        where t.technical_id = #{technicalId}
    </select>
        
    <insert id="insertCmcTechnical" parameterType="CmcTechnical">
        insert into cmc_technical
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="technicalId != null">technical_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="disclosureAccepter != null">disclosure_accepter,</if>
            <if test="disclosurer != null">disclosurer,</if>
            <if test="content != null">content,</if>
            <if test="document != null">document,</if>
            <if test="disclosureComment != null">disclosure_comment,</if>
            <if test="acceptComment != null">accept_comment,</if>
            <if test="disclosureTime != null">disclosure_time,</if>
            <if test="acceptTime != null">accept_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="technicalId != null">#{technicalId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="disclosureAccepter != null">#{disclosureAccepter},</if>
            <if test="disclosurer != null">#{disclosurer},</if>
            <if test="content != null">#{content},</if>
            <if test="document != null">#{document},</if>
            <if test="disclosureComment != null">#{disclosureComment},</if>
            <if test="acceptComment != null">#{acceptComment},</if>
            <if test="disclosureTime != null">#{disclosureTime},</if>
            <if test="acceptTime != null">#{acceptTime},</if>
         </trim>
    </insert>

    <update id="updateCmcTechnical" parameterType="CmcTechnical">
        update cmc_technical
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="disclosureAccepter != null">disclosure_accepter = #{disclosureAccepter},</if>
            <if test="disclosurer != null">disclosurer = #{disclosurer},</if>
            <if test="content != null">content = #{content},</if>
            <if test="document != null">document = #{document},</if>
            <if test="disclosureComment != null">disclosure_comment = #{disclosureComment},</if>
            <if test="acceptComment != null">accept_comment = #{acceptComment},</if>
            <if test="disclosureTime != null">disclosure_time = #{disclosureTime},</if>
            <if test="acceptTime != null">accept_time = #{acceptTime},</if>
        </trim>
        where technical_id = #{technicalId}
    </update>

    <delete id="deleteCmcTechnicalByTechnicalId" parameterType="String">
        delete from cmc_technical where technical_id = #{technicalId}
    </delete>

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