<?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.project.business.mapper.quotation.TqBargainPriceMapper">

    <resultMap type="TqBargainPrice" id="TqBargainPriceResult">
        <result property="id" column="id"/>
        <result property="quotationId" column="quotation_id"/>
        <result property="bargainPrice" column="bargain_price"/>
        <result property="acceptPrice" column="accept_price"/>
        <result property="bargainStatus" column="bargain_status"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectTqBargainPriceVo">
        select id,
               quotation_id,
               bargain_price,
               accept_price,
               bargain_status,
               del_flag,
               create_time,
               create_by,
               update_time,
               update_by,
               remark
        from tq_bargain_price
    </sql>

    <select id="selectTqBargainPriceList" parameterType="TqBargainPrice" resultMap="TqBargainPriceResult">
        <include refid="selectTqBargainPriceVo"/>
        <where>
            <if test="quotationId != null ">and quotation_id = #{quotationId}</if>
            <if test="bargainPrice != null ">and bargain_price = #{bargainPrice}</if>
            <if test="acceptPrice != null ">and accept_price = #{acceptPrice}</if>
            <if test="bargainStatus != null  and bargainStatus != ''">and bargain_status = #{bargainStatus}</if>
        </where>
    </select>

    <select id="selectTqBargainPriceById" parameterType="Long" resultMap="TqBargainPriceResult">
        <include refid="selectTqBargainPriceVo"/>
        where id = #{id}
    </select>

    <insert id="insertTqBargainPrice" parameterType="TqBargainPrice" useGeneratedKeys="true" keyProperty="id">
        insert into tq_bargain_price
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="quotationId != null">quotation_id,</if>
            <if test="bargainPrice != null">bargain_price,</if>
            <if test="acceptPrice != null">accept_price,</if>
            <if test="bargainStatus != null">bargain_status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="quotationId != null">#{quotationId},</if>
            <if test="bargainPrice != null">#{bargainPrice},</if>
            <if test="acceptPrice != null">#{acceptPrice},</if>
            <if test="bargainStatus != null">#{bargainStatus},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateTqBargainPrice" parameterType="TqBargainPrice">
        update tq_bargain_price
        <trim prefix="SET" suffixOverrides=",">
            <if test="quotationId != null">quotation_id = #{quotationId},</if>
            <if test="bargainPrice != null">bargain_price = #{bargainPrice},</if>
            <if test="acceptPrice != null">accept_price = #{acceptPrice},</if>
            <if test="bargainStatus != null">bargain_status = #{bargainStatus},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTqBargainPriceById" parameterType="Long">
        delete
        from tq_bargain_price
        where id = #{id}
    </delete>

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