<?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.web.modules.trading.mapper.AppSupplierSettlementMapper">

    <resultMap type="com.ruoyi.web.modules.trading.domain.BizSupplierSettlement" id="BizSupplierSettlementResult">
        <id     property="id"                   column="id"/>
        <result property="settlementNo"         column="settlement_no"/>
        <result property="orderId"              column="order_id"/>
        <result property="orderNo"              column="order_no"/>
        <result property="supplierId"           column="supplier_id"/>
        <result property="supplierName"         column="supplier_name"/>
        <result property="totalHeads"           column="total_heads"/>
        <result property="totalAmount"          column="total_amount"/>
        <result property="feeMethod"            column="fee_method"/>
        <result property="feeStandard"          column="fee_standard"/>
        <result property="transactionFeeRate"   column="transaction_fee_rate"/>
        <result property="managementFeeRate"    column="management_fee_rate"/>
        <result property="serviceFeeAmount"     column="service_fee_amount"/>
        <result property="payableAmount"        column="payable_amount"/>
        <result property="settlementStatus"     column="settlement_status"/>
        <result property="settleVoucherUrl"     column="settle_voucher_url"/>
        <result property="settleVoucherPath"    column="settle_voucher_path"/>
        <result property="settleFinishTime"     column="settle_finish_time"/>
        <result property="delFlag"              column="del_flag"/>
        <result property="createBy"             column="create_by"/>
        <result property="createTime"           column="create_time"/>
        <result property="updateBy"             column="update_by"/>
        <result property="updateTime"           column="update_time"/>
        <result property="remark"               column="remark"/>
    </resultMap>

    <sql id="selectVo">
        select s.id, s.settlement_no, s.order_id, s.order_no, s.supplier_id, sup.supplier_name,
               s.total_heads, s.total_amount, s.fee_method, s.fee_standard,
               s.transaction_fee_rate, s.management_fee_rate,
               s.service_fee_amount, s.payable_amount, s.settlement_status,
               s.settle_voucher_url, s.settle_voucher_path, s.settle_finish_time,
               s.del_flag, s.create_by, s.create_time, s.update_by, s.update_time, s.remark
        from biz_supplier_settlement s
        left join biz_supplier sup on sup.id = s.supplier_id and sup.del_flag = '0'
    </sql>

    <select id="selectPendingSettlementList" resultMap="BizSupplierSettlementResult">
        <include refid="selectVo"/>
        where s.del_flag = '0'
          and s.supplier_id = #{supplierId}
          and s.settlement_status = '0'
        order by s.create_time desc, s.id desc
    </select>

    <select id="selectPendingSettlementById" resultMap="BizSupplierSettlementResult">
        <include refid="selectVo"/>
        where s.del_flag = '0'
          and s.supplier_id = #{supplierId}
          and s.id = #{settlementId}
          and s.settlement_status = '0'
    </select>

</mapper>
