<?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.sckw.payment.dao.KwpSettlementWalletMapper">
    <resultMap id="BaseResultMap" type="com.sckw.payment.model.KwpSettlementWallet">
        <!--@mbg.generated-->
        <!--@Table kwp_settlement_wallet-->
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="ent_id" jdbcType="BIGINT" property="entId"/>
        <result column="settlement_id" jdbcType="BIGINT" property="settlementId"/>
        <result column="order_type" jdbcType="INTEGER" property="orderType"/>
        <result column="channel" jdbcType="VARCHAR" property="channel"/>
        <result column="pay_time" jdbcType="TIMESTAMP" property="payTime"/>
        <result column="pay_price" jdbcType="DECIMAL" property="payPrice"/>
        <result column="topay_price" jdbcType="DECIMAL" property="topayPrice"/>
        <result column="type" jdbcType="INTEGER" property="type"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
        <result column="create_by" jdbcType="BIGINT" property="createBy"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_by" jdbcType="BIGINT" property="updateBy"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="del_flag" jdbcType="INTEGER" property="delFlag"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,
        ent_id,
        settlement_id,
        order_type,
        channel,
        pay_time,
        pay_price,
        topay_price,
        `type`,
        remark,
        `status`,
        create_by,
        create_time,
        update_by,
        update_time,
        del_flag
    </sql>


    <sql id="Join_Column_List">
        w.id,
        w.ent_id,
        w.settlement_id,
        w.order_type,
        w.channel,
        w.pay_time,
        w.pay_price,
        w.topay_price,
        w.`type`,
        w.remark,
        w.`status`,
        w.create_by,
        w.create_time,
        w.update_by,
        w.update_time,
        w.del_flag
    </sql>

    <select id="pageListLogisticsPayment" resultType="com.sckw.payment.model.dto.SettlementWalletDto">
        select
        <include refid="Join_Column_List"/>
        from kwp_settlement_wallet w
        <where>
            w.type = #{settlementWalletReq.payType}
        </where>
        order by w.update_time desc
    </select>

    <select id="detailLogisticsPayment" resultType="com.sckw.payment.model.dto.SettlementWalletDto">
        select
        <include refid="Base_Column_List"/>
        from kwp_settlement_wallet
        where id = #{id,jdbcType=BIGINT}
    </select>

    <select id="confirmLogisticsPayment" resultType="java.lang.Integer">
        insert into kwp_settlement_wallet ( <include refid="Base_Column_List"/>) value ();
    </select>

    <select id="pageList" resultType="com.sckw.payment.model.dto.SettlementWalletDto">
        select ksw.id,
               ksw.ent_id,
               ksw.settlement_id,
               ksw.order_type,
               ksw.channel,
               ksw.order_type,
               ksw.pay_time,
               ksw.pay_price,
               ksw.topay_price,
               ksw.type,
               ksw.remark,
               ksw.create_by,
               ksw.create_time,
               ksw.update_by,
               ksw.update_time
        from kwp_settlement_wallet ksw
        <where>
            ksw.del_flag = 0
            <if test="walletReq.id != null and walletReq.id != ''">
                and ksw.settlement_id = #{walletReq.id,jdbcType=INTEGER}
            </if>
            <if test="walletReq.orderType != null">
                and ksw.order_type = #{walletReq.orderType,jdbcType=INTEGER}
            </if>
            <if test="walletReq.payType != null">
                and ksw.type = #{walletReq.payType,jdbcType=INTEGER}
            </if>
        </where>
    </select>
</mapper>