<?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.api.alipay.dao.AlipayDao">
    <insert id="createAlipayMentOrder" parameterType="com.api.model.alipay.AliPaymentOrder">
        insert into alipay_order(
            club_order_id,
            out_trade_no,
            trade_status,
            total_amount,
            receipt_amount,
            invoice_amount,
            buyer_pay_amount,
            refund_fee
        ) values (
            #{clubOrderId},
            #{outTradeNo},
            #{tradeStatus},
            #{totalAmount},
            #{receiptAmount},
            #{invoiceAmount},
            #{buyerPayAmount},
            #{refundFee}
        )
    </insert>

    <select id="selectByOutTradeNo" parameterType="java.lang.Integer" resultType="com.api.model.alipay.AliPaymentOrder">
        select * from alipay_order where out_trade_no = #{outTradeNo}
    </select>

    <update id="updateByPrimaryKey" parameterType="com.api.model.alipay.AliPaymentOrder">
        update alipay_order
        <set>
            notity_time = #{notityTime},
            gmt_create = #{gmtCreate},
            gmt_payment = #{gmtPayment},
            gmt_refund = #{gmtRefund},
            gmt_close = #{gmtClose},
            trade_no = #{tradeNo},
            out_biz_no = #{outBizNo},
            buyer_logon_id = #{buyerLogonId},
            seller_id = #{sellerId},
            seller_email = #{sellerEmail},
            total_amount = #{totalAmount},
            receipt_amount = #{receiptAmount},
            invoice_amount = #{invoiceAmount},
            buyer_pay_amount = #{buyerPayAmount}
        </set>
        where id = #{id}
    </update>

    <insert id="insertAdvancePaymentOrder" parameterType="com.api.model.alipay.SysAdvancePaymentOrder">
        insert into sys_advance_payment_order(
            estate_id,
            code,
            name,
            tel,
            pay_type,
            pay_price,
            create_id,
            create_date,
            status
        )values (
            #{estateId},
            #{code},
            #{name},
            #{tel},
            #{payType},
            #{payPrice},
            #{createId},
            #{createDate},
            #{status}
        )
    </insert>

    <select id="findSysAdvancePaymentOrderByCode" parameterType="java.lang.String" resultType="com.api.model.alipay.SysAdvancePaymentOrder">
        select * from sys_advance_payment_order where code = #{outTradeNo}
    </select>

    <update id="updateAdvancePaymentOrderStatusByCode" parameterType="com.api.model.alipay.SysAdvancePaymentOrder">
        update sys_advance_payment_order
        set status = #{status}
        where code = #{code}
    </update>

    <select id="findAPPByEstateId" parameterType="java.lang.Integer" resultType="java.math.BigDecimal">
        select advance_payment_price from cpm_building_unit_estate where id = #{estateId}
    </select>

    <update id="updateAdvancePaymentPriceByEstateId" parameterType="com.api.model.alipay.EstateIdAndAdvancePaymentPrice">
        update cpm_building_unit_estate
        set advance_payment_price = #{advancePaymentPrice}
        where id = #{estateId}
    </update>

    <insert id="insertHousekeepingServiceOrder" parameterType="com.api.model.alipay.SysHousekeepingServiceOrder">
        insert into sys_housekeeping_service_order(
            housekeeping_service_id,
            code,
            name,
            tel,
            pay_type,
            pay_price,
            create_id,
            create_date,
            remake,
            status
        )values (
            #{housekeepingServiceId},
            #{code},
            #{name},
            #{tel},
            #{payType},
            #{payPrice},
            #{createId},
            #{createDate},
            #{remake},
            #{status}
        )
    </insert>
    <insert id="insertShareDetailsOrder" parameterType="com.api.model.alipay.SysMeterReadingShareDetailsOrder">
        insert into sys_meter_reading_share_details_order(
            code,
            name,
            tel,
            pay_type,
            pay_price,
            create_id,
            create_date,
            status
        )values (
            #{code},
            #{name},
            #{tel},
            #{payType},
            #{payPrice},
            #{createId},
            #{createDate},
            #{status}
        )
        <selectKey keyProperty="id" resultType="java.lang.Integer">
            select LAST_INSERT_ID() AS id
        </selectKey>
    </insert>

    <select id="findSysHousekeepingServiceOrderByCode" parameterType="java.lang.String"
            resultType="com.api.model.alipay.SysHousekeepingServiceOrder">
        select * from sys_housekeeping_service_order where code = #{outTradeNo}
    </select>
    <select id="findShareDetailsOrderOrderByCode" parameterType="java.lang.String"
            resultType="com.api.model.alipay.SysMeterReadingShareDetailsOrder">
        select * from sys_meter_reading_share_details_order where code = #{outTradeNo}
    </select>

    <update id="updateHousekeepingServiceOrderStatusByCode" parameterType="com.api.model.alipay.SysHousekeepingServiceOrder">
        update sys_housekeeping_service_order
        set status = #{status}
        where code = #{code}
    </update>
    <update id="updateShareDetailsOrderStatusByCode" parameterType="com.api.model.alipay.SysMeterReadingShareDetailsOrder">
        update sys_meter_reading_share_details_order
        set status = #{status}
        where code = #{code}
    </update>


</mapper>