<?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.CmcTenderMapper">
    
    <resultMap type="CmcTender" id="CmcTenderResult">
        <result property="tenderId"    column="tender_id"    />
        <result property="projectName"    column="project_name"    />
        <result property="partyAName"    column="party_a_name"    />
        <result property="aPerson"    column="a_person"    />
        <result property="aPhone"    column="a_phone"    />
        <result property="agent"    column="agent"    />
        <result property="agentPerson"    column="agent_person"    />
        <result property="agentPhone"    column="agent_phone"    />
        <result property="place"    column="place"    />
        <result property="dept"    column="dept"    />
        <result property="trustee"    column="trustee"    />
        <result property="budget"    column="budget"    />
        <result property="quote"    column="quote"    />
        <result property="deposit"    column="deposit"    />
        <result property="tenderTime"    column="tender_time"    />
        <result property="bidBuyDeadline"    column="bid_buy_deadline"    />
        <result property="bidWebsite"    column="bid_website"    />
        <result property="bidDocument"    column="bid_document"    />
        <result property="projectBriefly"    column="project_briefly"    />
        <result property="businessWriter"    column="business_writer"    />
        <result property="businessDeadline"    column="business_deadline"    />
        <result property="techWriter"    column="tech_writer"    />
        <result property="techDeadline"    column="tech_deadline"    />
        <result property="tenderCombiner"    column="tender_combiner"    />
        <result property="tenderChecker"    column="tender_checker"    />
        <result property="tenderPrinter"    column="tender_printer"    />
        <result property="tenderDocument"    column="tender_document"    />
        <result property="isWin"    column="is_win"    />
        <association property="trusteeUser"    javaType="SysUser"         resultMap="TrusteeUserResult" />
        <association property="businessUser"    javaType="SysUser"         resultMap="BusinessUserResult" />
        <association property="techUser"    javaType="SysUser"         resultMap="TechUserResult" />
        <association property="combinerUser"    javaType="SysUser"         resultMap="CombinerUserResult" />
        <association property="checkerUser"    javaType="SysUser"         resultMap="CheckerUserResult" />
        <association property="printerUser"    javaType="SysUser"         resultMap="PrinterUserResult" />
        <association property="tenderDept"    javaType="SysDept"         resultMap="SysDeptResult" />
    </resultMap>

    <resultMap type="SysUser" id="TrusteeUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="trustee_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="BusinessUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="business_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="TechUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="tech_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="CombinerUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="combiner_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="CheckerUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="checker_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="PrinterUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="printer_nick_name"    />
    </resultMap>

    <resultMap type="SysDept" id="SysDeptResult">
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
    </resultMap>

    <sql id="selectCmcTenderVo">
        select t.tender_id, t.project_name, t.party_a_name, t.a_person, t.a_phone, t.agent, t.agent_person, t.agent_phone, t.place, t.dept, t.trustee, t.budget, t.quote, t.deposit, t.tender_time,
               t.bid_buy_deadline, t.bid_website, t.bid_document, t.project_briefly, t.business_writer, t.business_deadline, t.tech_writer, t.tech_deadline, t.tender_combiner, t.tender_checker,
               t.tender_printer, t.tender_document, u.nick_name as trustee_nick_name, u1.nick_name as business_nick_name, u2.nick_name as tech_nick_name, u3.nick_name as combiner_nick_name,
               u4.nick_name as checker_nick_name, u5.nick_name as printer_nick_name, d.dept_name, t.is_win from cmc_tender as t
        left join sys_user as u on u.user_id = t.trustee
        left join sys_user as u1 on u1.user_id = t.business_writer
        left join sys_user as u2 on u2.user_id = t.tech_writer
        left join sys_user as u3 on u3.user_id = t.tender_combiner
        left join sys_user as u4 on u4.user_id = t.tender_checker
        left join sys_user as u5 on u5.user_id = t.tender_printer
        left join sys_dept as d on d.dept_id = t.dept
    </sql>

    <select id="selectCmcTenderList" parameterType="CmcTender" resultMap="CmcTenderResult">
        <include refid="selectCmcTenderVo"/>
        <where>  
            <if test="projectName != null  and projectName != ''"> and t.project_name like concat('%', #{projectName}, '%')</if>
            <if test="partyAName != null  and partyAName != ''"> and t.party_a_name like concat('%', #{partyAName}, '%')</if>
            <if test="aPerson != null  and aPerson != ''"> and t.a_person like concat('%', #{aPerson}, '%')</if>
            <if test="aPhone != null  and aPhone != ''"> and t.a_phone like concat('%', #{aPhone}, '%')</if>
            <if test="agent != null  and agent != ''"> and t.agent like concat('%', #{agent}, '%')</if>
            <if test="agentPerson != null  and agentPerson != ''"> and t.agent_person like concat('%', #{agentPerson}, '%')</if>
            <if test="agentPhone != null  and agentPhone != ''"> and t.agent_phone like concat('%', #{agentPhone}, '%')</if>
            <if test="place != null  and place != ''"> and t.place like concat('%', #{place}, '%')</if>
            <if test="dept != null "> and t.dept = #{dept}</if>
            <if test="trustee != null "> and t.trustee = #{trustee}</if>
            <if test="budget != null "> and t.budget = #{budget}</if>
            <if test="quote != null "> and t.quote = #{quote}</if>
            <if test="deposit != null "> and t.deposit = #{deposit}</if>
            <if test="tenderTime != null "> and t.tender_time = #{tenderTime}</if>
            <if test="bidBuyDeadline != null "> and t.bid_buy_deadline = #{bidBuyDeadline}</if>
            <if test="bidWebsite != null  and bidWebsite != ''"> and t.bid_website = #{bidWebsite}</if>
            <if test="bidDocument != null  and bidDocument != ''"> and t.bid_document = #{bidDocument}</if>
            <if test="projectBriefly != null  and projectBriefly != ''"> and t.project_briefly = #{projectBriefly}</if>
            <if test="businessWriter != null "> and t.business_writer = #{businessWriter}</if>
            <if test="businessDeadline != null "> and t.business_deadline = #{businessDeadline}</if>
            <if test="techWriter != null "> and t.tech_writer = #{techWriter}</if>
            <if test="techDeadline != null "> and t.tech_deadline = #{techDeadline}</if>
            <if test="tenderCombiner != null "> and t.tender_combiner = #{tenderCombiner}</if>
            <if test="tenderChecker != null "> and t.tender_checker = #{tenderChecker}</if>
            <if test="tenderPrinter != null "> and t.tender_printer = #{tenderPrinter}</if>
            <if test="tenderDocument != null  and tenderDocument != ''"> and t.tender_document = #{tenderDocument}</if>
            <if test="isWin != null  and isWin != ''"> and t.is_win = #{isWin}</if>
        </where>
        order by t.tender_id desc
    </select>
    
    <select id="selectCmcTenderByTenderId" parameterType="String" resultMap="CmcTenderResult">
        <include refid="selectCmcTenderVo"/>
        where t.tender_id = #{tenderId}
    </select>
        
    <insert id="insertCmcTender" parameterType="CmcTender">
        insert into cmc_tender
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectName != null">project_name,</if>
            <if test="partyAName != null">party_a_name,</if>
            <if test="aPerson != null">a_person,</if>
            <if test="aPhone != null">a_phone,</if>
            <if test="agent != null">agent,</if>
            <if test="agentPerson != null">agent_person,</if>
            <if test="agentPhone != null">agent_phone,</if>
            <if test="place != null">place,</if>
            <if test="dept != null">dept,</if>
            <if test="trustee != null">trustee,</if>
            <if test="budget != null">budget,</if>
            <if test="quote != null">quote,</if>
            <if test="deposit != null">deposit,</if>
            <if test="tenderTime != null">tender_time,</if>
            <if test="bidBuyDeadline != null">bid_buy_deadline,</if>
            <if test="bidWebsite != null">bid_website,</if>
            <if test="bidDocument != null">bid_document,</if>
            <if test="projectBriefly != null">project_briefly,</if>
            <if test="businessWriter != null">business_writer,</if>
            <if test="businessDeadline != null">business_deadline,</if>
            <if test="techWriter != null">tech_writer,</if>
            <if test="techDeadline != null">tech_deadline,</if>
            <if test="tenderCombiner != null">tender_combiner,</if>
            <if test="tenderChecker != null">tender_checker,</if>
            <if test="tenderPrinter != null">tender_printer,</if>
            <if test="tenderDocument != null">tender_document,</if>
            <if test="isWin != null">is_win,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectName != null">#{projectName},</if>
            <if test="partyAName != null">#{partyAName},</if>
            <if test="aPerson != null">#{aPerson},</if>
            <if test="aPhone != null">#{aPhone},</if>
            <if test="agent != null">#{agent},</if>
            <if test="agentPerson != null">#{agentPerson},</if>
            <if test="agentPhone != null">#{agentPhone},</if>
            <if test="place != null">#{place},</if>
            <if test="dept != null">#{dept},</if>
            <if test="trustee != null">#{trustee},</if>
            <if test="budget != null">#{budget},</if>
            <if test="quote != null">#{quote},</if>
            <if test="deposit != null">#{deposit},</if>
            <if test="tenderTime != null">#{tenderTime},</if>
            <if test="bidBuyDeadline != null">#{bidBuyDeadline},</if>
            <if test="bidWebsite != null">#{bidWebsite},</if>
            <if test="bidDocument != null">#{bidDocument},</if>
            <if test="projectBriefly != null">#{projectBriefly},</if>
            <if test="businessWriter != null">#{businessWriter},</if>
            <if test="businessDeadline != null">#{businessDeadline},</if>
            <if test="techWriter != null">#{techWriter},</if>
            <if test="techDeadline != null">#{techDeadline},</if>
            <if test="tenderCombiner != null">#{tenderCombiner},</if>
            <if test="tenderChecker != null">#{tenderChecker},</if>
            <if test="tenderPrinter != null">#{tenderPrinter},</if>
            <if test="tenderDocument != null">#{tenderDocument},</if>
            <if test="isWin != null">#{isWin},</if>
         </trim>
    </insert>

    <update id="updateCmcTender" parameterType="CmcTender">
        update cmc_tender
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectName != null">project_name = #{projectName},</if>
            <if test="partyAName != null">party_a_name = #{partyAName},</if>
            <if test="aPerson != null">a_person = #{aPerson},</if>
            <if test="aPhone != null">a_phone = #{aPhone},</if>
            <if test="agent != null">agent = #{agent},</if>
            <if test="agentPerson != null">agent_person = #{agentPerson},</if>
            <if test="agentPhone != null">agent_phone = #{agentPhone},</if>
            <if test="place != null">place = #{place},</if>
            <if test="dept != null">dept = #{dept},</if>
            <if test="trustee != null">trustee = #{trustee},</if>
            <if test="budget != null">budget = #{budget},</if>
            <if test="quote != null">quote = #{quote},</if>
            <if test="deposit != null">deposit = #{deposit},</if>
            <if test="tenderTime != null">tender_time = #{tenderTime},</if>
            <if test="bidBuyDeadline != null">bid_buy_deadline = #{bidBuyDeadline},</if>
            <if test="bidWebsite != null">bid_website = #{bidWebsite},</if>
            <if test="bidDocument != null">bid_document = #{bidDocument},</if>
            <if test="projectBriefly != null">project_briefly = #{projectBriefly},</if>
            <if test="businessWriter != null">business_writer = #{businessWriter},</if>
            <if test="businessDeadline != null">business_deadline = #{businessDeadline},</if>
            <if test="techWriter != null">tech_writer = #{techWriter},</if>
            <if test="techDeadline != null">tech_deadline = #{techDeadline},</if>
            <if test="tenderCombiner != null">tender_combiner = #{tenderCombiner},</if>
            <if test="tenderChecker != null">tender_checker = #{tenderChecker},</if>
            <if test="tenderPrinter != null">tender_printer = #{tenderPrinter},</if>
            <if test="tenderDocument != null">tender_document = #{tenderDocument},</if>
            <if test="isWin != null">is_win = #{isWin},</if>
        </trim>
        where tender_id = #{tenderId}
    </update>

    <delete id="deleteCmcTenderByTenderId" parameterType="String">
        delete from cmc_tender where tender_id = #{tenderId}
    </delete>

    <delete id="deleteCmcTenderByTenderIds" parameterType="String">
        delete from cmc_tender where tender_id in 
        <foreach item="tenderId" collection="array" open="(" separator="," close=")">
            #{tenderId}
        </foreach>
    </delete>
</mapper>