<?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.CmcSafeMapper">
    
    <resultMap type="CmcSafe" id="CmcSafeResult">
        <result property="safeId"    column="safe_id"    />
        <result property="projectId"    column="project_id"    />
        <result property="disclosureAccepter"    column="disclosure_accepter"    />
        <result property="disclosurer"    column="disclosurer"    />
        <result property="environmentComment"    column="environment_comment"    />
        <result property="outsideComment"    column="outside_comment"    />
        <result property="insideComment"    column="inside_comment"    />
        <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="selectCmcSafeVo">
        select s.safe_id, s.project_id, p.project_number, p.project_name, s.disclosure_accepter, u.nick_name as accepter_nick_name, s.disclosurer, u1.nick_name as disclosurer_nick_name,
               s.environment_comment, s.outside_comment, s.inside_comment, s.disclosure_comment, s.accept_comment, s.disclosure_time, s.accept_time from cmc_safe as s
        left join sys_user as u on u.user_id = s.disclosure_accepter
        left join sys_user as u1 on u1.user_id = s.disclosurer
        left join cmc_project as p on p.project_id = s.project_id
    </sql>

    <select id="selectCmcSafeList" parameterType="CmcSafe" resultMap="CmcSafeResult">
        <include refid="selectCmcSafeVo"/>
        <where>  
            <if test="projectId != null  and projectId != ''"> and s.project_id = #{projectId}</if>
            <if test="disclosureAccepter != null "> and s.disclosure_accepter = #{disclosureAccepter}</if>
            <if test="disclosurer != null "> and s.disclosurer = #{disclosurer}</if>
            <if test="environmentComment != null  and environmentComment != ''"> and s.environment_comment = #{environmentComment}</if>
            <if test="outsideComment != null  and outsideComment != ''"> and s.outside_comment = #{outsideComment}</if>
            <if test="insideComment != null  and insideComment != ''"> and s.inside_comment = #{insideComment}</if>
            <if test="disclosureComment != null  and disclosureComment != ''"> and s.disclosure_comment = #{disclosureComment}</if>
            <if test="disclosureTime != null "> and s.disclosure_time = #{disclosureTime}</if>
            <if test="acceptTime != null "> and s.accept_time = #{acceptTime}</if>
        </where>
        order by s.disclosure_time desc
    </select>
    
    <select id="selectCmcSafeBySafeId" parameterType="String" resultMap="CmcSafeResult">
        <include refid="selectCmcSafeVo"/>
        where s.safe_id = #{safeId}
    </select>
        
    <insert id="insertCmcSafe" parameterType="CmcSafe">
        insert into cmc_safe
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="safeId != null">safe_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="disclosureAccepter != null">disclosure_accepter,</if>
            <if test="disclosurer != null">disclosurer,</if>
            <if test="environmentComment != null">environment_comment,</if>
            <if test="outsideComment != null">outside_comment,</if>
            <if test="insideComment != null">inside_comment,</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="safeId != null">#{safeId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="disclosureAccepter != null">#{disclosureAccepter},</if>
            <if test="disclosurer != null">#{disclosurer},</if>
            <if test="environmentComment != null">#{environmentComment},</if>
            <if test="outsideComment != null">#{outsideComment},</if>
            <if test="insideComment != null">#{insideComment},</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="updateCmcSafe" parameterType="CmcSafe">
        update cmc_safe
        <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="environmentComment != null">environment_comment = #{environmentComment},</if>
            <if test="outsideComment != null">outside_comment = #{outsideComment},</if>
            <if test="insideComment != null">inside_comment = #{insideComment},</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 safe_id = #{safeId}
    </update>

    <delete id="deleteCmcSafeBySafeId" parameterType="String">
        delete from cmc_safe where safe_id = #{safeId}
    </delete>

    <delete id="deleteCmcSafeBySafeIds" parameterType="String">
        delete from cmc_safe where safe_id in 
        <foreach item="safeId" collection="array" open="(" separator="," close=")">
            #{safeId}
        </foreach>
    </delete>
</mapper>