<?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.contract.TqContractLiftMapper">

    <resultMap type="TqContractLift" id="TqContractLiftResult">
        <result property="id"    column="id"    />
        <result property="contractNo"    column="contract_no"    />
        <result property="contractName"    column="contract_name"    />
        <result property="areaId"    column="area_id"    />
        <result property="countryId"    column="country_id"    />
        <result property="city"    column="city"    />
        <result property="salesman"    column="salesman"    />
        <result property="endCustomers"    column="end_customers"    />
        <result property="tradeTerms"    column="trade_terms"    />
        <result property="agentId"    column="agent_id"    />
        <result property="paymentMethod"    column="payment_method"    />
        <result property="currencyId"    column="currency_id"    />
        <result property="amountOfMoney"    column="amount_of_money"    />
        <result property="signingDate"    column="signing_date"    />
        <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"    />
        <result property="permissionChar"    column="permission_char"    />
        <result property="productionOrderNo"    column="production_order_no"    />
        <result property="contractNoVersionNo"    column="contract_no_version_no"    />
        <result property="salesModel"    column="sales_model"    />
        <result property="contractAmendmentDate"    column="contract_amendment_date"    />
        <result property="productCategory"    column="product_category"    />
        <result property="elevatorModel"    column="elevator_model"    />
        <result property="specification"    column="specification"    />
        <result property="count"    column="count"    />
        <result property="unitPrice"    column="unit_price"    />
        <result property="quotationDiscount"    column="quotation_discount"    />
        <result property="expectedProductionScheduleDate"    column="expected_production_schedule_date"    />
        <result property="hopeToScheduleProductionDate"    column="hope_to_schedule_production_date"    />
        <result property="actualProductionScheduleDate"    column="actual_production_schedule_date"    />
        <result property="productionScheduleDate"    column="production_schedule_date"    />
        <result property="reasonForProjectCancellationAndSus"    column="reason_for_project_cancellation_and_sus"    />
        <result property="reasonForDelayedOverdueShipment"    column="reason_for_delayed_overdue_shipment"    />
        <result property="reasonForNonScheduling"    column="reason_for_non_scheduling"    />
        <result property="hopeForDeliveryDate"    column="hope_for_delivery_date"    />
        <result property="actualDeliveryDate"    column="actual_delivery_date"    />
        <result property="port"    column="port"    />
        <result property="productionOrderStatus"    column="production_order_status"    />
        <result property="reviewDiscount"    column="review_discount"    />
        <result property="reviewShippingCosts"    column="review_shipping_costs"    />
        <result property="reviewCommission"    column="review_commission"    />
        <result property="commissionPaymentDate"    column="commission_payment_date"    />
        <result property="payoutDate"    column="payout_date"    />
        <result property="receivingBank"    column="receiving_bank"    />
        <result property="receivedAmount"    column="received_amount"    />
        <result property="paymentRatio"    column="payment_ratio"    />
        <result property="accountsReceivableBalance"    column="accounts_receivable_balance"    />
        <result property="planAdjustmentDate"    column="plan_adjustment_date"    />
        <result property="actualInlandFreightCost"    column="actual_inland_freight_cost"    />
        <result property="actualOceanFreight"    column="actual_ocean_freight"    />
        <result property="invoiceDate"    column="invoice_date"    />
        <result property="customsDeclarationMonth"    column="customs_declaration_month"    />
        <result property="subsequentCollectionOfShippingFees"    column="subsequent_collection_of_shipping_fees"    />
        <result property="collectionDate"    column="collection_date"    />
        <result property="planInlandFreightCost"    column="plan_inland_freight_cost"    />
        <result property="planOceanFreight"    column="plan_ocean_freight"    />
        <result property="projectStatus"    column="project_status"    />
        <result property="rate4ProductionScheduling"    column="rate_4_production_scheduling"    />
        <result property="rate4Shipment"    column="rate_4_shipment"    />
        <result property="rate4SigningContracts"    column="rate_4_signing_contracts"    />
        <result property="elevatorCode"    column="elevator_code"    />
        <result property="origin"    column="origin"    />
        <result property="elevatorType"    column="elevator_type"    />
        <result property="quotationNoVersion"    column="quotation_no_version"    />
        <result property="projectName"    column="project_name"    />
        <result property="quoter"    column="quoter"    />
        <result property="additionalCost"    column="additional_cost"    />
        <result property="otherCost"    column="other_cost"    />
        <result property="liftAmount"    column="lift_amount"    />
        <result property="type"    column="type"    />
    </resultMap>

    <resultMap type="com.ruoyi.project.business.domain.vo.contract.TqContractLiftVo" id="TqContractLiftVoResult" extends="TqContractLiftResult">
        <result property="salesmanName"    column="salesman_name"    />
        <result property="agentName"    column="agent_name"    />
        <result property="endCustomersName"    column="account_name"    />
        <result property="countryName"    column="country_name"    />
        <result property="areaName"    column="area_name"    />
        <result property="quoterName"    column="quoter_name"    />
    </resultMap>

    <sql id="selectTqContractLiftVo">
        select DISTINCT l.*,u.nick_name as salesman_name,ag.agent_name,account.account_name as endCustomersName ,u2.nick_name as quoter_name,
               CASE #{language}
                   WHEN 'chinese' THEN
                       country.country_name
                   WHEN 'english' THEN
                       country.country_nameUS
                   WHEN 'russia' THEN
                       country.country_nameRU
                   WHEN 'spanish' THEN
                       country.country_nameES
                   END AS country_name,
               CASE #{language}
                   WHEN 'chinese' THEN
                       area.area_name
                   WHEN 'english' THEN
                       area.area_nameUS
                   WHEN 'russia' THEN
                       area.area_nameRU
                   WHEN 'spanish' THEN
                       area.area_nameES
                   END AS area_name,
                t1.dict_label as elevatorTypeName
        from tq_contract_lift l
            LEFT JOIN sys_user u on l.salesman = u.user_id  AND l.del_flag = u.del_flag
            LEFT JOIN sys_user u2 on CAST(l.quoter AS SIGNED)  = u2.user_id AND l.del_flag = u2.del_flag
            LEFT JOIN tb_agent ag on l.agent_id = ag.agent_id AND l.del_flag = ag.del_flag
            LEFT JOIN tc_account account on l.end_customers = account.account_id AND l.del_flag = account.del_flag
            LEFT JOIN tb_country country on country.country_id = l.country_id  AND l.del_flag = country.del_flag
            LEFT JOIN tb_area area on area.area_id = l.area_id  AND l.del_flag = area.del_flag
            LEFT JOIN sys_dict_data t1 on t1.dict_type = 'elevator_type' and l.elevator_type = t1.dict_value
            LEFT JOIN tq_contract contract on contract.contract_no = l.contract_no  AND l.del_flag = contract.del_flag
    </sql>

    <select id="selectTqContractLiftList" resultType="com.ruoyi.project.business.domain.vo.contract.TqContractLiftVo">
        <include refid="selectTqContractLiftVo"/>
        <where>
            l.del_flag != '1'
            <if test="version != null  "> and SUBSTRING_INDEX(l.contract_no_version_no, '-', -1)  = #{version}</if>
            <if test="approveStatus != null  and approveStatus != ''"> and (contract.approve_status = #{approveStatus} or CAST(SUBSTRING_INDEX(l.contract_no_version_no, '-', -1) AS UNSIGNED) &lt; contract.version or l.type = 'toVoid')</if>
            <if test="contractNo != null  and contractNo != ''"> and l.contract_no like concat('%', #{contractNo}, '%')</if>
            <if test="contractName != null  and contractName != ''"> and l.contract_name like concat('%', #{contractName}, '%')</if>
            <if test="areaId != null and areaId.size() > 0">
                and l.area_id in
                <foreach collection="areaId" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="countryId != null and countryId.size() > 0">
                and l.country_id in
                <foreach collection="countryId" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="city != null  and city != ''"> and l.city like concat('%', #{city}, '%') </if>
            <if test="salesmanName != null  and salesmanName != ''"> and u.nick_name like  concat('%', #{salesmanName}, '%') </if>
            <if test="endCustomers != null  and endCustomers != ''"> and l.end_customers  like concat('%', #{endCustomers}, '%')</if>
            <if test="tradeTerms != null and tradeTerms.size() > 0">
                and l.trade_terms in
                <foreach collection="tradeTerms" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="agentId != null and agentId.size() > 0">
                and l.agent_id in
                <foreach collection="agentId" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="paymentMethod != null and paymentMethod.size() > 0">
                and l.payment_method in
                <foreach collection="paymentMethod" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="currencyId != null and currencyId.size() > 0">
                and l.currency_id in
                <foreach collection="currencyId" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="amountOfMoney != null "> and l.amount_of_money = #{amountOfMoney}</if>
            <if test="signingDate != null and signingDate.length == 2"> and l.signing_date
                <foreach collection="signingDate" item="item" open="between " separator=" and " >
                    #{item}
                </foreach>
            </if>
            <if test="permissionChar != null  and permissionChar != ''"> and find_in_set(#{permissionChar}, l.permission_char)</if>
            <if test="productionOrderNo != null  and productionOrderNo != ''"> and l.production_order_no like concat('%', #{productionOrderNo},'%')</if>
            <if test="contractNoVersionNo != null  and contractNoVersionNo != ''"> and l.contract_no_version_no  like concat('%', #{contractNoVersionNo},'%') </if>
            <if test="salesModel != null and salesModel.size() > 0">
                and l.sales_model in
                <foreach collection="salesModel" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="contractAmendmentDate != null and contractAmendmentDate.length == 2"> and DATE(l.contract_amendment_date)
                <foreach collection="contractAmendmentDate" item="item" open="between " separator=" and " >
                    #{item}
                </foreach>
            </if>
            <if test="productCategory != null and productCategory.size() > 0">
                and l.product_category in
                <foreach collection="productCategory" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="elevatorModel != null  and elevatorModel != ''"> and l.elevator_model like concat('%',#{elevatorModel},'%') </if>
            <if test="specification != null  and specification != ''"> and l.specification like concat('%',#{specification},'%')  </if>
            <if test="count != null "> and l.count = #{count}</if>
            <if test="unitPrice != null "> and l.unit_price = #{unitPrice}</if>
            <if test="quotationDiscount != null  and quotationDiscount != ''"> and l.quotation_discount = #{quotationDiscount}</if>
            <if test="expectedProductionScheduleDate != null and expectedProductionScheduleDate.length == 2"> and l.expected_production_schedule_date
                <foreach collection="expectedProductionScheduleDate" item="item" open="between " separator=" and " >
                    #{item}
                </foreach>
            </if>
            <if test="hopeToScheduleProductionDate != null and hopeToScheduleProductionDate.length == 2"> and l.hope_to_schedule_production_date
                <foreach collection="hopeToScheduleProductionDate" item="item" open="between " separator=" and " >
                    #{item}
                </foreach>
            </if>
            <if test="actualProductionScheduleDate != null and actualProductionScheduleDate.length == 2"> and l.actual_production_schedule_date
                <foreach collection="actualProductionScheduleDate" item="item" open="between " separator=" and " >
                    #{item}
                </foreach>
            </if>
            <if test="productionScheduleDate != null and productionScheduleDate.length == 2"> and l.production_schedule_date
                <foreach collection="productionScheduleDate" item="item" open="between " separator=" and " >
                    #{item}
                </foreach>
            </if>
            <if test="reasonForProjectCancellationAndSus != null  and reasonForProjectCancellationAndSus != ''"> and l.reason_for_project_cancellation_and_sus = #{reasonForProjectCancellationAndSus}</if>
            <if test="reasonForDelayedOverdueShipment != null  and reasonForDelayedOverdueShipment != ''"> and l.reason_for_delayed_overdue_shipment = #{reasonForDelayedOverdueShipment}</if>
            <if test="reasonForNonScheduling != null  and reasonForNonScheduling != ''"> and l.reason_for_non_scheduling = #{reasonForNonScheduling}</if>
            <if test="hopeForDeliveryDate != null and hopeForDeliveryDate.length == 2"> and l.hope_for_delivery_date
                <foreach collection="hopeForDeliveryDate" item="item" open="between " separator=" and " >
                    #{item}
                </foreach>
            </if>
            <if test="actualDeliveryDate != null and actualDeliveryDate.length == 2"> and l.actual_delivery_date
                <foreach collection="actualDeliveryDate" item="item" open="between " separator=" and " >
                    #{item}
                </foreach>
            </if>
            <if test="port != null  and port != ''"> and l.port = #{port}</if>
            <if test="productionOrderStatus != null  and productionOrderStatus != ''"> and l.production_order_status = #{productionOrderStatus}</if>
            <if test="reviewDiscount != null  and reviewDiscount != ''"> and l.review_discount = #{reviewDiscount}</if>
            <if test="reviewShippingCosts != null "> and l.review_shipping_costs = #{reviewShippingCosts}</if>
            <if test="reviewCommission != null "> and l.review_commission = #{reviewCommission}</if>
            <if test="commissionPaymentDate != null and commissionPaymentDate.length == 2"> and l.commission_payment_date
                <foreach collection="commissionPaymentDate" item="item" open="between " separator=" and " >
                    #{item}
                </foreach>
            </if>
            <if test="payoutDate != null and payoutDate.length == 2"> and l.payout_date
                <foreach collection="payoutDate" item="item" open="between " separator=" and " >
                    #{item}
                </foreach>
            </if>
            <if test="receivingBank != null  and receivingBank != ''"> and l.receiving_bank like concat('%', #{receivingBank},'%')</if>
            <if test="receivedAmount != null "> and l.received_amount = #{receivedAmount}</if>
            <if test="paymentRatio != null and paymentRatio.size() > 0">
                and l.payment_ratio in
                <foreach collection="paymentRatio" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="accountsReceivableBalance != null "> and l.accounts_receivable_balance = #{accountsReceivableBalance}</if>
            <if test="planAdjustmentDate != null and planAdjustmentDate.length == 2"> and l.plan_adjustment_date
                <foreach collection="planAdjustmentDate" item="item" open="between " separator=" and " >
                    #{item}
                </foreach>
            </if>
            <if test="actualInlandFreightCost != null "> and l.actual_inland_freight_cost = #{actualInlandFreightCost}</if>
            <if test="actualOceanFreight != null "> and l.actual_ocean_freight = #{actualOceanFreight}</if>
            <if test="invoiceDate != null and invoiceDate.length == 2"> and l.invoice_date
                <foreach collection="invoiceDate" item="item" open="between " separator=" and " >
                    #{item}
                </foreach>
            </if>
            <if test="customsDeclarationMonth != null  and customsDeclarationMonth != ''"> and l.customs_declaration_month = #{customsDeclarationMonth}</if>
            <if test="subsequentCollectionOfShippingFees != null "> and l.subsequent_collection_of_shipping_fees = #{subsequentCollectionOfShippingFees}</if>
            <if test="collectionDate != null and collectionDate.length == 2"> and l.collection_date
                <foreach collection="collectionDate" item="item" open="between " separator=" and " >
                    #{item}
                </foreach>
            </if>
            <if test="planInlandFreightCost != null "> and l.plan_inland_freight_cost = #{planInlandFreightCost}</if>
            <if test="planOceanFreight != null "> and l.plan_ocean_freight = #{planOceanFreight}</if>
            <if test="projectStatus != null  and projectStatus != ''"> and l.project_status = #{projectStatus}</if>
            <if test="rate4ProductionScheduling != null "> and l.rate_4_production_scheduling = #{rate4ProductionScheduling}</if>
            <if test="rate4Shipment != null "> and l.rate_4_shipment = #{rate4Shipment}</if>
            <if test="rate4SigningContracts != null "> and l.rate_4_signing_contracts = #{rate4SigningContracts}</if>
            <if test="elevatorCode != null  and elevatorCode != ''"> and l.elevator_code = #{elevatorCode}</if>
            <if test="origin != null  and origin != ''"> and l.origin = #{origin}</if>
            <if test="elevatorType != null  and elevatorType != ''"> and l.elevator_type = #{elevatorType}</if>
            <if test="quotationNoVersion != null  and quotationNoVersion != ''"> and l.quotation_no_version = #{quotationNoVersion}</if>
            <if test="projectName != null  and projectName != ''"> and l.project_name like concat('%', #{projectName}, '%')</if>
            <if test="quoter != null  and quoter != ''"> and l.quoter = #{quoter}</if>
            <if test="additionalCost != null "> and l.additional_cost = #{additionalCost}</if>
            <if test="otherCost != null "> and l.other_cost = #{otherCost}</if>

            <if test="endCustomersName != null "> and account.account_name like  concat('%', #{endCustomersName}, '%')</if>

        </where>
        order by id desc
    </select>

    <select id="selectTqContractLiftById" parameterType="Long" resultMap="TqContractLiftResult">
        <include refid="selectTqContractLiftVo"/>
        where l.id = #{id}
    </select>
    <select id="listAllById" resultType="com.ruoyi.project.business.domain.vo.contract.TqContractLiftVo">
        <include refid="selectTqContractLiftVo"/>
        where l.id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
    <select id="selectProductionOrderNo" resultType="java.lang.Integer">
        select count(*) from tq_contract_lift where del_flag = '0' and production_order_no like concat(#{productionOrderNo},'%')
    </select>

    <insert id="insertTqContractLift" parameterType="TqContractLift" useGeneratedKeys="true" keyProperty="id">
        insert into tq_contract_lift
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="contractNo != null">contract_no,</if>
            <if test="contractName != null">contract_name,</if>
            <if test="areaId != null">area_id,</if>
            <if test="countryId != null">country_id,</if>
            <if test="city != null">city,</if>
            <if test="salesman != null">salesman,</if>
            <if test="endCustomers != null">end_customers,</if>
            <if test="tradeTerms != null">trade_terms,</if>
            <if test="agentId != null">agent_id,</if>
            <if test="paymentMethod != null">payment_method,</if>
            <if test="currencyId != null">currency_id,</if>
            <if test="amountOfMoney != null">amount_of_money,</if>
            <if test="signingDate != null">signing_date,</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>
            <if test="permissionChar != null">permission_char,</if>
            <if test="productionOrderNo != null">production_order_no,</if>
            <if test="contractNoVersionNo != null">contract_no_version_no,</if>
            <if test="salesModel != null">sales_model,</if>
            <if test="contractAmendmentDate != null">contract_amendment_date,</if>
            <if test="productCategory != null">product_category,</if>
            <if test="elevatorModel != null">elevator_model,</if>
            <if test="specification != null">specification,</if>
            <if test="count != null">count,</if>
            <if test="unitPrice != null">unit_price,</if>
            <if test="quotationDiscount != null">quotation_discount,</if>
            <if test="expectedProductionScheduleDate != null">expected_production_schedule_date,</if>
            <if test="hopeToScheduleProductionDate != null">hope_to_schedule_production_date,</if>
            <if test="actualProductionScheduleDate != null">actual_production_schedule_date,</if>
            <if test="productionScheduleDate != null">production_schedule_date,</if>
            <if test="reasonForProjectCancellationAndSus != null">reason_for_project_cancellation_and_sus,</if>
            <if test="reasonForDelayedOverdueShipment != null">reason_for_delayed_overdue_shipment,</if>
            <if test="reasonForNonScheduling != null">reason_for_non_scheduling,</if>
            <if test="hopeForDeliveryDate != null">hope_for_delivery_date,</if>
            <if test="actualDeliveryDate != null">actual_delivery_date,</if>
            <if test="port != null">port,</if>
            <if test="productionOrderStatus != null">production_order_status,</if>
            <if test="reviewDiscount != null">review_discount,</if>
            <if test="reviewShippingCosts != null">review_shipping_costs,</if>
            <if test="reviewCommission != null">review_commission,</if>
            <if test="commissionPaymentDate != null">commission_payment_date,</if>
            <if test="payoutDate != null">payout_date,</if>
            <if test="receivingBank != null">receiving_bank,</if>
            <if test="receivedAmount != null">received_amount,</if>
            <if test="paymentRatio != null">payment_ratio,</if>
            <if test="accountsReceivableBalance != null">accounts_receivable_balance,</if>
            <if test="planAdjustmentDate != null">plan_adjustment_date,</if>
            <if test="actualInlandFreightCost != null">actual_inland_freight_cost,</if>
            <if test="actualOceanFreight != null">actual_ocean_freight,</if>
            <if test="invoiceDate != null">invoice_date,</if>
            <if test="customsDeclarationMonth != null">customs_declaration_month,</if>
            <if test="subsequentCollectionOfShippingFees != null">subsequent_collection_of_shipping_fees,</if>
            <if test="collectionDate != null">collection_date,</if>
            <if test="planInlandFreightCost != null">plan_inland_freight_cost,</if>
            <if test="planOceanFreight != null">plan_ocean_freight,</if>
            <if test="projectStatus != null">project_status,</if>
            <if test="rate4ProductionScheduling != null">rate_4_production_scheduling,</if>
            <if test="rate4Shipment != null">rate_4_shipment,</if>
            <if test="rate4SigningContracts != null">rate_4_signing_contracts,</if>
            <if test="elevatorCode != null">elevator_code,</if>
            <if test="origin != null">origin,</if>
            <if test="elevatorType != null">elevator_type,</if>
            <if test="quotationNoVersion != null">quotation_no_version,</if>
            <if test="projectName != null">project_name,</if>
            <if test="quoter != null">quoter,</if>
            <if test="additionalCost != null">additional_cost,</if>
            <if test="otherCost != null">other_cost,</if>

            <if test="liftAmount != null">lift_amount,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="contractNo != null">#{contractNo},</if>
            <if test="contractName != null">#{contractName},</if>
            <if test="areaId != null">#{areaId},</if>
            <if test="countryId != null">#{countryId},</if>
            <if test="city != null">#{city},</if>
            <if test="salesman != null">#{salesman},</if>
            <if test="endCustomers != null">#{endCustomers},</if>
            <if test="tradeTerms != null">#{tradeTerms},</if>
            <if test="agentId != null">#{agentId},</if>
            <if test="paymentMethod != null">#{paymentMethod},</if>
            <if test="currencyId != null">#{currencyId},</if>
            <if test="amountOfMoney != null">#{amountOfMoney},</if>
            <if test="signingDate != null">#{signingDate},</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>
            <if test="permissionChar != null">#{permissionChar},</if>
            <if test="productionOrderNo != null">#{productionOrderNo},</if>
            <if test="contractNoVersionNo != null">#{contractNoVersionNo},</if>
            <if test="salesModel != null">#{salesModel},</if>
            <if test="contractAmendmentDate != null">#{contractAmendmentDate},</if>
            <if test="productCategory != null">#{productCategory},</if>
            <if test="elevatorModel != null">#{elevatorModel},</if>
            <if test="specification != null">#{specification},</if>
            <if test="count != null">#{count},</if>
            <if test="unitPrice != null">#{unitPrice},</if>
            <if test="quotationDiscount != null">#{quotationDiscount},</if>
            <if test="expectedProductionScheduleDate != null">#{expectedProductionScheduleDate},</if>
            <if test="hopeToScheduleProductionDate != null">#{hopeToScheduleProductionDate},</if>
            <if test="actualProductionScheduleDate != null">#{actualProductionScheduleDate},</if>
            <if test="productionScheduleDate != null">#{productionScheduleDate},</if>
            <if test="reasonForProjectCancellationAndSus != null">#{reasonForProjectCancellationAndSus},</if>
            <if test="reasonForDelayedOverdueShipment != null">#{reasonForDelayedOverdueShipment},</if>
            <if test="reasonForNonScheduling != null">#{reasonForNonScheduling},</if>
            <if test="hopeForDeliveryDate != null">#{hopeForDeliveryDate},</if>
            <if test="actualDeliveryDate != null">#{actualDeliveryDate},</if>
            <if test="port != null">#{port},</if>
            <if test="productionOrderStatus != null">#{productionOrderStatus},</if>
            <if test="reviewDiscount != null">#{reviewDiscount},</if>
            <if test="reviewShippingCosts != null">#{reviewShippingCosts},</if>
            <if test="reviewCommission != null">#{reviewCommission},</if>
            <if test="commissionPaymentDate != null">#{commissionPaymentDate},</if>
            <if test="payoutDate != null">#{payoutDate},</if>
            <if test="receivingBank != null">#{receivingBank},</if>
            <if test="receivedAmount != null">#{receivedAmount},</if>
            <if test="paymentRatio != null">#{paymentRatio},</if>
            <if test="accountsReceivableBalance != null">#{accountsReceivableBalance},</if>
            <if test="planAdjustmentDate != null">#{planAdjustmentDate},</if>
            <if test="actualInlandFreightCost != null">#{actualInlandFreightCost},</if>
            <if test="actualOceanFreight != null">#{actualOceanFreight},</if>
            <if test="invoiceDate != null">#{invoiceDate},</if>
            <if test="customsDeclarationMonth != null">#{customsDeclarationMonth},</if>
            <if test="subsequentCollectionOfShippingFees != null">#{subsequentCollectionOfShippingFees},</if>
            <if test="collectionDate != null">#{collectionDate},</if>
            <if test="planInlandFreightCost != null">#{planInlandFreightCost},</if>
            <if test="planOceanFreight != null">#{planOceanFreight},</if>
            <if test="projectStatus != null">#{projectStatus},</if>
            <if test="rate4ProductionScheduling != null">#{rate4ProductionScheduling},</if>
            <if test="rate4Shipment != null">#{rate4Shipment},</if>
            <if test="rate4SigningContracts != null">#{rate4SigningContracts},</if>
            <if test="elevatorCode != null">#{elevatorCode},</if>
            <if test="origin != null">#{origin},</if>
            <if test="elevatorType != null">#{elevatorType},</if>
            <if test="quotationNoVersion != null">#{quotationNoVersion},</if>
            <if test="projectName != null">#{projectName},</if>
            <if test="quoter != null">#{quoter},</if>
            <if test="additionalCost != null">#{additionalCost},</if>
            <if test="otherCost != null">#{otherCost},</if>
            <if test="liftAmount != null">#{liftAmount},</if>
        </trim>
    </insert>

    <insert id="insertTqContractLiftBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
        insert into tq_contract_lift
        (contract_no, contract_name, area_id, country_id, city, salesman, end_customers, trade_terms,
        agent_id, payment_method, currency_id, amount_of_money, signing_date, del_flag, create_time, create_by,
        update_time, update_by, remark, permission_char, production_order_no, contract_no_version_no, sales_model,
        contract_amendment_date, product_category, elevator_model, specification, count,  unit_price,
        quotation_discount, expected_production_schedule_date, hope_to_schedule_production_date, actual_production_schedule_date,
        production_schedule_date, reason_for_project_cancellation_and_sus, reason_for_delayed_overdue_shipment,
        reason_for_non_scheduling, hope_for_delivery_date, actual_delivery_date, port, production_order_status,
        review_discount, review_shipping_costs, review_commission, commission_payment_date, payout_date, receiving_bank,
        received_amount, payment_ratio, accounts_receivable_balance, plan_adjustment_date, actual_inland_freight_cost,
        actual_ocean_freight, invoice_date, customs_declaration_month, subsequent_collection_of_shipping_fees, collection_date,
        plan_inland_freight_cost, plan_ocean_freight, project_status, rate_4_production_scheduling,
        rate_4_shipment,rate_4_signing_contracts, elevator_code,
        origin,elevator_type,quotation_no_version,project_name,quoter,additional_cost,other_cost,lift_amount,type
        )
        values
        <foreach collection="list" item="item"  separator=",">
            (#{item.contractNo},#{item.contractName},#{item.areaId},#{item.countryId},#{item.city},
            #{item.salesman}, #{item.endCustomers},#{item.tradeTerms}, #{item.agentId},#{item.paymentMethod},
            #{item.currencyId},#{item.amountOfMoney},#{item.signingDate},#{item.delFlag},#{item.createTime},
            #{item.createBy},#{item.updateTime},#{item.updateBy},#{item.remark},#{item.permissionChar},
            #{item.productionOrderNo},#{item.contractNoVersionNo},#{item.salesModel},#{item.contractAmendmentDate},
            #{item.productCategory},#{item.elevatorModel},#{item.specification},#{item.count},
            #{item.unitPrice},#{item.quotationDiscount},#{item.expectedProductionScheduleDate},#{item.hopeToScheduleProductionDate},
            #{item.actualProductionScheduleDate},#{item.productionScheduleDate},#{item.reasonForProjectCancellationAndSus},
            #{item.reasonForDelayedOverdueShipment},#{item.reasonForNonScheduling},#{item.hopeForDeliveryDate},
            #{item.actualDeliveryDate},#{item.port},#{item.productionOrderStatus},#{item.reviewDiscount},#{item.reviewShippingCosts},
            #{item.reviewCommission},#{item.commissionPaymentDate},#{item.payoutDate},#{item.receivingBank},#{item.receivedAmount},
            #{item.paymentRatio},#{item.accountsReceivableBalance},#{item.planAdjustmentDate},#{item.actualInlandFreightCost},
            #{item.actualOceanFreight},#{item.invoiceDate},#{item.customsDeclarationMonth},#{item.subsequentCollectionOfShippingFees},
            #{item.collectionDate},#{item.planInlandFreightCost},#{item.planOceanFreight},#{item.projectStatus},
            #{item.rate4ProductionScheduling},#{item.rate4Shipment},
            #{item.rate4SigningContracts},#{item.elevatorCode},
            #{item.origin},#{item.elevatorType},#{item.quotationNoVersion},#{item.projectName},#{item.quoter},#{item.additionalCost},#{item.otherCost},
            #{item.liftAmount},#{item.type}
            )
        </foreach>
    </insert>

    <insert id="updateTqContractLiftBatch" >
        <foreach collection="list" item="item" separator=";">
            update  tq_contract_lift
            set
            contract_no=#{item.contractNo},
            contract_name=#{item.contractName},
            area_id=#{item.areaId},
            country_id=#{item.countryId},
            city=#{item.city},
            salesman=#{item.salesman},
            end_customers=#{item.endCustomers},
            trade_terms=#{item.tradeTerms},
            agent_id=#{item.agentId},
            payment_method=#{item.paymentMethod},
            currency_id=#{item.currencyId},
            amount_of_money=#{item.amountOfMoney},
            signing_date=#{item.signingDate},
            del_flag=#{item.delFlag},
            create_time=#{item.createTime},
            create_by=#{item.createBy},
            update_time=#{item.updateTime},
            update_by=#{item.updateBy},
            remark=#{item.remark},
            permission_char=#{item.permissionChar},
            production_order_no=#{item.productionOrderNo},
            contract_no_version_no=#{item.contractNoVersionNo},
            sales_model=#{item.salesModel},
            contract_amendment_date=#{item.contractAmendmentDate},
            product_category=#{item.productCategory},
            elevator_model=#{item.elevatorModel},
            specification=#{item.specification},
            count=#{item.count},
            unit_price=#{item.unitPrice},
            quotation_discount=#{item.quotationDiscount},
            expected_production_schedule_date=#{item.expectedProductionScheduleDate},
            hope_to_schedule_production_date=#{item.hopeToScheduleProductionDate},
            actual_production_schedule_date=#{item.actualProductionScheduleDate},
            production_schedule_date=#{item.productionScheduleDate},
            reason_for_project_cancellation_and_sus=#{item.reasonForProjectCancellationAndSus},
            reason_for_delayed_overdue_shipment=#{item.reasonForDelayedOverdueShipment},
            reason_for_non_scheduling=#{item.reasonForNonScheduling},
            hope_for_delivery_date=#{item.hopeForDeliveryDate},
            actual_delivery_date=#{item.actualDeliveryDate},
            port=#{item.port},
            production_order_status=#{item.productionOrderStatus},
            review_discount=#{item.reviewDiscount},
            review_shipping_costs=#{item.reviewShippingCosts},
            review_commission=#{item.reviewCommission},
            commission_payment_date=#{item.commissionPaymentDate},
            payout_date=#{item.payoutDate},
            receiving_bank=#{item.receivingBank},
            received_amount=#{item.receivedAmount},
            payment_ratio=#{item.paymentRatio},
            accounts_receivable_balance=#{item.accountsReceivableBalance},
            plan_adjustment_date=#{item.planAdjustmentDate},
            actual_inland_freight_cost=#{item.actualInlandFreightCost},
            actual_ocean_freight=#{item.actualOceanFreight},
            invoice_date=#{item.invoiceDate},
            customs_declaration_month=#{item.customsDeclarationMonth},
            subsequent_collection_of_shipping_fees=#{item.subsequentCollectionOfShippingFees},
            collection_date=#{item.collectionDate},
            plan_inland_freight_cost=#{item.planInlandFreightCost},
            plan_ocean_freight=#{item.planOceanFreight},
            project_status=#{item.projectStatus},
            rate_4_production_scheduling=#{item.rate4ProductionScheduling},
            rate_4_shipment=#{item.rate4Shipment},
            rate_4_signing_contracts=#{item.rate4SigningContracts},
            elevator_code=#{item.elevatorCode},
            origin=#{item.origin},
            elevator_type=#{item.elevatorType},
            quotation_no_version=#{item.quotationNoVersion},
            project_name=#{item.projectName},
            quoter=#{item.quoter},
            additional_cost=#{item.additionalCost},
            other_cost=#{item.otherCost},
            lift_amount=#{item.liftAmount},
            type = #{item.type}
            where id = #{item.id}
        </foreach>
    </insert>


    <update id="updateTqContractLift" parameterType="TqContractLift">
        update tq_contract_lift
        <trim prefix="SET" suffixOverrides=",">
            <if test="contractNo != null">contract_no = #{contractNo},</if>
            <if test="contractName != null">contract_name = #{contractName},</if>
            <if test="areaId != null">area_id = #{areaId},</if>
            <if test="countryId != null">country_id = #{countryId},</if>
            <if test="city != null">city = #{city},</if>
            <if test="salesman != null">salesman = #{salesman},</if>
            <if test="endCustomers != null">end_customers = #{endCustomers},</if>
            <if test="tradeTerms != null">trade_terms = #{tradeTerms},</if>
            <if test="agentId != null">agent_id = #{agentId},</if>
            <if test="paymentMethod != null">payment_method = #{paymentMethod},</if>
            <if test="currencyId != null">currency_id = #{currencyId},</if>
            <if test="amountOfMoney != null">amount_of_money = #{amountOfMoney},</if>
            <if test="signingDate != null">signing_date = #{signingDate},</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>
            <if test="permissionChar != null">permission_char = #{permissionChar},</if>
            <if test="productionOrderNo != null">production_order_no = #{productionOrderNo},</if>
            <if test="contractNoVersionNo != null">contract_no_version_no = #{contractNoVersionNo},</if>
            <if test="salesModel != null">sales_model = #{salesModel},</if>
            <if test="contractAmendmentDate != null">contract_amendment_date = #{contractAmendmentDate},</if>
            <if test="productCategory != null">product_category = #{productCategory},</if>
            <if test="elevatorModel != null">elevator_model = #{elevatorModel},</if>
            <if test="specification != null">specification = #{specification},</if>
            <if test="count != null">count = #{count},</if>
            <if test="unitPrice != null">unit_price = #{unitPrice},</if>
            <if test="quotationDiscount != null">quotation_discount = #{quotationDiscount},</if>
            <if test="expectedProductionScheduleDate != null">expected_production_schedule_date = #{expectedProductionScheduleDate},</if>
            <if test="hopeToScheduleProductionDate != null">hope_to_schedule_production_date = #{hopeToScheduleProductionDate},</if>
            <if test="actualProductionScheduleDate != null">actual_production_schedule_date = #{actualProductionScheduleDate},</if>
            <if test="productionScheduleDate != null">production_schedule_date = #{productionScheduleDate},</if>
            <if test="reasonForProjectCancellationAndSus != null">reason_for_project_cancellation_and_sus = #{reasonForProjectCancellationAndSus},</if>
            <if test="reasonForDelayedOverdueShipment != null">reason_for_delayed_overdue_shipment = #{reasonForDelayedOverdueShipment},</if>
            <if test="reasonForNonScheduling != null">reason_for_non_scheduling = #{reasonForNonScheduling},</if>
            <if test="hopeForDeliveryDate != null">hope_for_delivery_date = #{hopeForDeliveryDate},</if>
            <if test="actualDeliveryDate != null">actual_delivery_date = #{actualDeliveryDate},</if>
            <if test="port != null">port = #{port},</if>
            <if test="productionOrderStatus != null">production_order_status = #{productionOrderStatus},</if>
            <if test="reviewDiscount != null">review_discount = #{reviewDiscount},</if>
            <if test="reviewShippingCosts != null">review_shipping_costs = #{reviewShippingCosts},</if>
            <if test="reviewCommission != null">review_commission = #{reviewCommission},</if>
            <if test="commissionPaymentDate != null">commission_payment_date = #{commissionPaymentDate},</if>
            <if test="payoutDate != null">payout_date = #{payoutDate},</if>
            <if test="receivingBank != null">receiving_bank = #{receivingBank},</if>
            <if test="receivedAmount != null">received_amount = #{receivedAmount},</if>
            <if test="paymentRatio != null">payment_ratio = #{paymentRatio},</if>
            <if test="accountsReceivableBalance != null">accounts_receivable_balance = #{accountsReceivableBalance},</if>
            <if test="planAdjustmentDate != null">plan_adjustment_date = #{planAdjustmentDate},</if>
            <if test="actualInlandFreightCost != null">actual_inland_freight_cost = #{actualInlandFreightCost},</if>
            <if test="actualOceanFreight != null">actual_ocean_freight = #{actualOceanFreight},</if>
            <if test="invoiceDate != null">invoice_date = #{invoiceDate},</if>
            <if test="customsDeclarationMonth != null">customs_declaration_month = #{customsDeclarationMonth},</if>
            <if test="subsequentCollectionOfShippingFees != null">subsequent_collection_of_shipping_fees = #{subsequentCollectionOfShippingFees},</if>
            <if test="collectionDate != null">collection_date = #{collectionDate},</if>
            <if test="planInlandFreightCost != null">plan_inland_freight_cost = #{planInlandFreightCost},</if>
            <if test="planOceanFreight != null">plan_ocean_freight = #{planOceanFreight},</if>
            <if test="projectStatus != null">project_status = #{projectStatus},</if>
            <if test="rate4ProductionScheduling != null">rate_4_production_scheduling = #{rate4ProductionScheduling},</if>
            <if test="rate4Shipment != null">rate_4_shipment = #{rate4Shipment},</if>
            <if test="rate4SigningContracts != null">rate_4_signing_contracts = #{rate4SigningContracts},</if>
            <if test="elevatorCode != null">elevator_code = #{elevatorCode},</if>
            <if test="origin != null">origin = #{origin},</if>
            <if test="elevatorType != null">elevator_type = #{elevatorType},</if>
            <if test="quotationNoVersion != null">quotation_no_version = #{quotationNoVersion},</if>
            <if test="projectName != null">project_name = #{projectName},</if>
            <if test="quoter != null">quoter = #{quoter},</if>
            <if test="additionalCost != null">additional_cost = #{additionalCost},</if>
            <if test="otherCost != null">other_cost = #{otherCost},</if>
            <if test="liftAmount != null">lift_amount = #{liftAmount},</if>
            <if test="type != null">type = #{type},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updateOrderNoBo">
        <foreach collection="list" item="item" open="" close="">
        update tq_contract_lift
        set production_order_no = #{item.productionOrderNo}
        where id = #{item.id};
        </foreach>
    </update>

    <delete id="deleteTqContractLiftById" parameterType="Long">
        delete from tq_contract_lift where id = #{id}
    </delete>

    <delete id="deleteTqContractLiftByIds" parameterType="String">
        update  tq_contract_lift set del_flag = '1' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deleteTqContractLiftByNoId">
        update  tq_contract_lift set del_flag = '1' where contract_no = #{contractNo} AND CAST(SUBSTRING_INDEX(contract_no_version_no, '-', -1) AS UNSIGNED) = #{version} AND  id NOT IN
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>


    <!--*******************************************报表统计***************************************-->
    <sql id="statisticAmount">
        select top.area_id,
               top.area_name,
            cl.signing_date,
            YEAR(cl.signing_date) as `signing_year`,
            MONTH(cl.signing_date) as `signing_month`,
            WEEK(cl.signing_date + INTERVAL -6 DAY, 6) as `signing_week`,
            cl.actual_production_schedule_date,
           YEAR(cl.actual_production_schedule_date) as `production_year`,
           MONTH(cl.actual_production_schedule_date) as `production_month`,
           WEEK(cl.actual_production_schedule_date + INTERVAL -6 DAY, 6) as `production_week`,
            cl.actual_delivery_date,
           YEAR(cl.actual_delivery_date) as `delivery_year`,
           MONTH(cl.actual_delivery_date) as `delivery_month`,
           WEEK(cl.actual_delivery_date + INTERVAL -6 DAY, 6) as `delivery_week`,
            FLOOR(cl.unit_price / cl.rate_4_signing_contracts) as `amount`
        from tq_contract_lift cl
            left join (select a.*, SUBSTRING_INDEX(SUBSTRING_INDEX(a.permission_char, ',', -3), ',', 1) as top_id
            from tb_area a) as area on cl.area_id = area.area_id
            left join tb_area top on area.top_id = top.area_id
        where cl.del_flag = 0
          and cl.unit_price > 0
          and cl.rate_4_signing_contracts > 0
    </sql>
    <select id="countStatistic"  resultType="com.ruoyi.project.business.dto.LiftCount">
        select area_name as `key`,
                SUM(IF(signing_date between #{begin} and #{end}, amount, 0)) as `signCount`,
                SUM(IF(actual_production_schedule_date between #{begin} and #{end}, amount, 0)) as `productionCount`,
                SUM(IF(actual_delivery_date between #{begin} and #{end}, amount, 0)) as `deliveryCount`
        from (<include refid="statisticAmount"/>) T
        group by area_id
        order by area_id
    </select>
    <select id="countStatisticByMonthAll" resultType="com.ruoyi.project.business.dto.LiftCount">
        select `key`,
               SUM(IF(type = 1, amount, 0)) as `signCount`,
               SUM(IF(type = 2, amount, 0)) as `productionCount`,
               SUM(IF(type = 3, amount, 0)) as `deliveryCount`
        from
            (
                select MONTH(signing_date) as `key`, 1 as `type`, FLOOR(unit_price / rate_4_signing_contracts) as `amount` from tq_contract_lift where del_flag = 0 and YEAR(signing_date) = #{year}
                union all
                select MONTH(actual_production_schedule_date) as `key`, 2 as `type`, FLOOR(unit_price / rate_4_signing_contracts) as `amount` from tq_contract_lift where del_flag = 0 and YEAR(actual_production_schedule_date) = #{year}
                union all
                select MONTH(actual_delivery_date) as `key`, 3 as `type`, FLOOR(unit_price / rate_4_signing_contracts) as `amount` from tq_contract_lift where del_flag = 0 and YEAR(actual_delivery_date) = #{year}
            ) T
        group by `key`
        order by `key`
    </select>
    <select id="countStatisticByWeekAll" resultType="com.ruoyi.project.business.dto.LiftCount">
        select `key`,
               SUM(IF(type = 1, amount, 0)) as `signCount`,
               SUM(IF(type = 2, amount, 0)) as `productionCount`,
               SUM(IF(type = 3, amount, 0)) as `deliveryCount`
        from
            (
                select WEEK(signing_date + INTERVAL -6 DAY, 6) as `key`, 1 as `type`, FLOOR(unit_price / rate_4_signing_contracts) as `amount` from tq_contract_lift where del_flag = 0 and YEAR(signing_date) = #{year}
                union all
                select WEEK(actual_production_schedule_date + INTERVAL -6 DAY, 6) as `key`, 2 as `type`, FLOOR(unit_price / rate_4_signing_contracts) as `amount` from tq_contract_lift where del_flag = 0 and YEAR(actual_production_schedule_date) = #{year}
                union all
                select WEEK(actual_delivery_date + INTERVAL -6 DAY, 6) as `key`, 3 as `type`, FLOOR(unit_price / rate_4_signing_contracts) as `amount` from tq_contract_lift where del_flag = 0 and YEAR(actual_delivery_date) = #{year}
            ) T
        group by `key`
        order by `key`
    </select>
    <select id="countSigningStatisticAll" resultType="com.ruoyi.project.business.dto.LiftMonthCount">
        select `area_name` as `key`,
               SUM(IF(`signing_month` = 1, amount, 0)) as `january`,
               SUM(IF(`signing_month` = 2, amount, 0)) as `february`,
               SUM(IF(`signing_month` = 3, amount, 0)) as `march`,
               SUM(IF(`signing_month` = 4, amount, 0)) as `april`,
               SUM(IF(`signing_month` = 5, amount, 0)) as `may`,
               SUM(IF(`signing_month` = 6, amount, 0)) as `june`,
               SUM(IF(`signing_month` = 7, amount, 0)) as `july`,
               SUM(IF(`signing_month` = 8, amount, 0)) as `august`,
               SUM(IF(`signing_month` = 9, amount, 0)) as `september`,
               SUM(IF(`signing_month` = 10, amount, 0)) as `october`,
               SUM(IF(`signing_month` = 11, amount, 0)) as `november`,
               SUM(IF(`signing_month` = 12, amount, 0)) as `december`,
               SUM(amount) as `total`
        from (<include refid="statisticAmount"/>) T
        where `signing_year` = #{year}
        group by area_id
        order by area_id
    </select>
    <select id="countProductionStatisticAll" resultType="com.ruoyi.project.business.dto.LiftMonthCount">
        select `area_name` as `key`,
        SUM(IF(`production_month` = 1, amount, 0)) as `january`,
        SUM(IF(`production_month` = 2, amount, 0)) as `february`,
        SUM(IF(`production_month` = 3, amount, 0)) as `march`,
        SUM(IF(`production_month` = 4, amount, 0)) as `april`,
        SUM(IF(`production_month` = 5, amount, 0)) as `may`,
        SUM(IF(`production_month` = 6, amount, 0)) as `june`,
        SUM(IF(`production_month` = 7, amount, 0)) as `july`,
        SUM(IF(`production_month` = 8, amount, 0)) as `august`,
        SUM(IF(`production_month` = 9, amount, 0)) as `september`,
        SUM(IF(`production_month` = 10, amount, 0)) as `october`,
        SUM(IF(`production_month` = 11, amount, 0)) as `november`,
        SUM(IF(`production_month` = 12, amount, 0)) as `december`,
        SUM(amount) as `total`
        from (<include refid="statisticAmount"/>) T
        where `production_year` = #{year}
        group by area_id
        order by area_id
    </select>
    <select id="countDeliveryStatisticAll" resultType="com.ruoyi.project.business.dto.LiftMonthCount">
        select `area_name` as `key`,
        SUM(IF(`delivery_month` = 1, amount, 0)) as `january`,
        SUM(IF(`delivery_month` = 2, amount, 0)) as `february`,
        SUM(IF(`delivery_month` = 3, amount, 0)) as `march`,
        SUM(IF(`delivery_month` = 4, amount, 0)) as `april`,
        SUM(IF(`delivery_month` = 5, amount, 0)) as `may`,
        SUM(IF(`delivery_month` = 6, amount, 0)) as `june`,
        SUM(IF(`delivery_month` = 7, amount, 0)) as `july`,
        SUM(IF(`delivery_month` = 8, amount, 0)) as `august`,
        SUM(IF(`delivery_month` = 9, amount, 0)) as `september`,
        SUM(IF(`delivery_month` = 10, amount, 0)) as `october`,
        SUM(IF(`delivery_month` = 11, amount, 0)) as `november`,
        SUM(IF(`delivery_month` = 12, amount, 0)) as `december`,
        SUM(amount) as `total`
        from (<include refid="statisticAmount"/>) T
        where `delivery_year` = #{year}
        group by area_id
        order by area_id
    </select>
</mapper>