<?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="org.jeecg.modules.projectManagement.mapper.FdProjectQuotationTemplateMapper">
    <select id="getByQuotationId" resultType="org.jeecg.modules.projectManagement.entity.FdProjectQuotationTemplate">
       SELECT
            a.id,
            a.quotation_template_id,
            a.fee_category1_title,
            a.fee_category2_title,
            a.totsl_discount_rate1,
            a.totsl_discount_rate2,
            a.discount_rate,
            a.discount_price,
            a.originalsubtotal1,
            a.originalsubtotal2,
            a.subtotal_fee_category1,
            a.subtotal_fee_category2,
            a.taxation_fee_category1,
            a.taxation_fee_category2,
            a.totle_fee_category1,
            a.totle_fee_category2,
            a.final_price1,
            a.final_price2,
            b.type as type,
            a.name as name,
            a.sort,
            a.is_project_details,
            a.cost_column_number,
            a.colspan,
            a.originalsubtotal1_c,
            a.originalsubtotal2_c,
            a.subtotal_fee_category1_c,
            a.subtotal_fee_category2_c,
            a.taxation_fee_category1_c,
            a.taxation_fee_category2_c,
            a.totle_fee_category1_c,
            a.totle_fee_category2_c,
            a.final_price1_c,
            a.final_price2_c
        FROM
            fd_project_quotation_template a
            LEFT JOIN fd_quotation_template b ON a.quotation_template_id = b.id
        WHERE
            a.del_flag='0' and
            a.quotation_id =#{0}
        ORDER BY a.sort ASC
    </select>


    <select id="getByQuotationId1" resultType="org.jeecg.modules.projectManagement.entity.FdProjectQuotationTemplate">
        SELECT
            a.project_quotation_template_id,
            a.fee_category1 + a.fee_category2 AS fee,
            b.type AS type
        FROM
            fd_project_quotation_template_item a
            LEFT JOIN fd_quotation_template b ON a.project_quotation_template_id = b.id
        WHERE
            a.quotation_id =#{0}
    </select>


    <update id="updateDelFlagByQuotationId">
        UPDATE fd_project_quotation_template SET del_flag='1' WHERE quotation_id=#{quotationId}
    </update>
    
    <update id="updateTotleBatch" parameterType="java.util.List">
        <foreach collection="list" item="temp" index="index" open="" close="" separator=";">
            UPDATE fd_project_quotation_template
            <set>
                originalsubtotal1_c = #{temp.originalsubtotal1C},
                originalsubtotal2_c=#{temp.originalsubtotal2C},
                subtotal_fee_category1_c=#{temp.subtotalFeeCategory1C},
                subtotal_fee_category2_c=#{temp.subtotalFeeCategory2C},
                taxation_fee_category1_c=#{temp.taxationFeeCategory1C},
                taxation_fee_category2_c=#{temp.taxationFeeCategory2C},
                totle_fee_category1_c=#{temp.totleFeeCategory1C},
                totle_fee_category2_c=#{temp.totleFeeCategory2C},
                final_price1_c=#{temp.finalPrice1C},
                final_price2_c=#{temp.finalPrice2C},
            </set>
            WHERE
            id = #{temp.id}
        </foreach>
    </update>
</mapper>