<?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.cool.store.mapper.LinePayMapper">
    <resultMap id="BaseResultMap" type="com.cool.store.entity.LinePayDO">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="partner_id" jdbcType="VARCHAR" property="partnerId"/>
        <result column="shop_id" jdbcType="BIGINT" property="shopId"/>
        <result column="line_id" jdbcType="BIGINT" property="lineId"/>
        <result column="pay_status" jdbcType="TINYINT" property="payStatus"/>
        <result column="pay_type" jdbcType="TINYINT" property="payType"/>
        <result column="pay_user_name" jdbcType="VARCHAR" property="payUserName"/>
        <result column="pay_account" jdbcType="VARCHAR" property="payAccount"/>
        <result column="bank_code" jdbcType="VARCHAR" property="bankCode"/>
        <result column="bank_name" jdbcType="VARCHAR" property="bankName"/>
        <result column="branch_bank_code" jdbcType="VARCHAR" property="branchBankCode"/>
        <result column="branch_bank_name" jdbcType="VARCHAR" property="branchBankName"/>
        <result column="pay_time" jdbcType="TIMESTAMP" property="payTime"/>
        <result column="pay_pic" jdbcType="VARCHAR" property="payPic"/>
        <result column="promise_pic" jdbcType="VARCHAR" property="promisePic"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="create_user_id" jdbcType="VARCHAR" property="createUserId"/>
        <result column="update_user_id" jdbcType="VARCHAR" property="updateUserId"/>
        <result column="deleted" jdbcType="BIT" property="deleted"/>
        <result column="pay_business_type" jdbcType="TINYINT" property="payBusinessType"/>
        <result column="amount" jdbcType="DECIMAL" property="amount"/>
    </resultMap>
    <sql id="Base_Column_List">
        id,shop_id, partner_id, line_id, pay_status, pay_type, pay_user_name, pay_account, bank_code,
    bank_name, branch_bank_code, branch_bank_name, pay_time, pay_pic, promise_pic, create_time, 
    update_time, create_user_id, update_user_id, deleted,pay_business_type,amount
    </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from xfsg_line_pay
        where id = #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete
        from xfsg_line_pay
        where id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insertSelective" parameterType="com.cool.store.entity.LinePayDO">
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into xfsg_line_pay
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="partnerId != null">
                partner_id,
            </if>
            <if test="lineId != null">
                line_id,
            </if>
            <if test="payStatus != null">
                pay_status,
            </if>
            <if test="payType != null">
                pay_type,
            </if>
            <if test="payUserName != null">
                pay_user_name,
            </if>
            <if test="payAccount != null">
                pay_account,
            </if>
            <if test="bankCode != null">
                bank_code,
            </if>
            <if test="bankName != null">
                bank_name,
            </if>
            <if test="branchBankCode != null">
                branch_bank_code,
            </if>
            <if test="branchBankName != null">
                branch_bank_name,
            </if>
            <if test="payTime != null">
                pay_time,
            </if>
            <if test="payPic != null">
                pay_pic,
            </if>
            <if test="promisePic != null">
                promise_pic,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="createUserId != null">
                create_user_id,
            </if>
            <if test="updateUserId != null">
                update_user_id,
            </if>
            <if test="deleted != null">
                deleted,
            </if>
            <if test="payBusinessType !=null">
                pay_business_type,
            </if>
            <if test="shopId !=null">
                shop_id,
            </if>
            <if test="amount != null">
                amount,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="partnerId != null">
                #{partnerId,jdbcType=VARCHAR},
            </if>
            <if test="lineId != null">
                #{lineId,jdbcType=BIGINT},
            </if>
            <if test="payStatus != null">
                #{payStatus,jdbcType=TINYINT},
            </if>
            <if test="payType != null">
                #{payType,jdbcType=TINYINT},
            </if>
            <if test="payUserName != null">
                #{payUserName,jdbcType=VARCHAR},
            </if>
            <if test="payAccount != null">
                #{payAccount,jdbcType=VARCHAR},
            </if>
            <if test="bankCode != null">
                #{bankCode,jdbcType=VARCHAR},
            </if>
            <if test="bankName != null">
                #{bankName,jdbcType=VARCHAR},
            </if>
            <if test="branchBankCode != null">
                #{branchBankCode,jdbcType=VARCHAR},
            </if>
            <if test="branchBankName != null">
                #{branchBankName,jdbcType=VARCHAR},
            </if>
            <if test="payTime != null">
                #{payTime,jdbcType=TIMESTAMP},
            </if>
            <if test="payPic != null">
                #{payPic,jdbcType=VARCHAR},
            </if>
            <if test="promisePic != null">
                #{promisePic,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="createUserId != null">
                #{createUserId,jdbcType=VARCHAR},
            </if>
            <if test="updateUserId != null">
                #{updateUserId,jdbcType=VARCHAR},
            </if>
            <if test="deleted != null">
                #{deleted,jdbcType=BIT},
            </if>
            <if test="payBusinessType !=null">
                #{payBusinessType,jdbcType=TINYINT},
            </if>
            <if test="shopId !=null">
                #{shopId},
            </if>
            <if test="amount !=null">
                #{amount},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.cool.store.entity.LinePayDO">
        update xfsg_line_pay
        <set>
            <if test="partnerId != null">
                partner_id = #{partnerId,jdbcType=VARCHAR},
            </if>
            <if test="lineId != null">
                line_id = #{lineId,jdbcType=BIGINT},
            </if>
            <if test="payStatus != null">
                pay_status = #{payStatus,jdbcType=TINYINT},
            </if>
            <if test="payType != null">
                pay_type = #{payType,jdbcType=TINYINT},
            </if>
            <if test="payUserName != null">
                pay_user_name = #{payUserName,jdbcType=VARCHAR},
            </if>
            <if test="payAccount != null">
                pay_account = #{payAccount,jdbcType=VARCHAR},
            </if>
            <if test="bankCode != null">
                bank_code = #{bankCode,jdbcType=VARCHAR},
            </if>
            <if test="bankName != null">
                bank_name = #{bankName,jdbcType=VARCHAR},
            </if>
            <if test="branchBankCode != null">
                branch_bank_code = #{branchBankCode,jdbcType=VARCHAR},
            </if>
            <if test="branchBankName != null">
                branch_bank_name = #{branchBankName,jdbcType=VARCHAR},
            </if>
            <if test="payTime != null">
                pay_time = #{payTime,jdbcType=TIMESTAMP},
            </if>
            <if test="payPic != null">
                pay_pic = #{payPic,jdbcType=VARCHAR},
            </if>
            <if test="promisePic != null">
                promise_pic = #{promisePic,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="createUserId != null">
                create_user_id = #{createUserId,jdbcType=VARCHAR},
            </if>
            <if test="updateUserId != null">
                update_user_id = #{updateUserId,jdbcType=VARCHAR},
            </if>
            <if test="deleted != null">
                deleted = #{deleted,jdbcType=BIT},
            </if>
            <if test="amount != null">
                amount = #{amount,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPidAndLid">
        update xfsg_line_pay
        set audit_id = #{auditId}
        where line_id = #{lineId}
          and partner_id = #{partnerId}
    </update>
    <sql id="dynamicQuery">
        <trim prefix="WHERE" prefixOverrides="AND | OR">
            <if test="null != id">
                and t.id = #{id,jdbcType=BIGINT}
            </if>
            <if test="null != partnerId">
                and t.partner_id = #{partnerId,jdbcType=VARCHAR}
            </if>
            <if test="null != lineId">
                and t.line_id = #{lineId,jdbcType=BIGINT}
            </if>
            <if test="null != payStatus">
                and t.pay_status = #{payStatus,jdbcType=TINYINT}
            </if>
            <if test="null != payType">
                and t.pay_type = #{payType,jdbcType=TINYINT}
            </if>
            <if test="null != payUserName">
                and t.pay_user_name = #{payUserName,jdbcType=VARCHAR}
            </if>
            <if test="null != payAccount">
                and t.pay_account = #{payAccount,jdbcType=VARCHAR}
            </if>
            <if test="null != bankCode">
                and t.bank_code = #{bankCode,jdbcType=VARCHAR}
            </if>
            <if test="null != bankName">
                and t.bank_name = #{bankName,jdbcType=VARCHAR}
            </if>
            <if test="null != branchBankCode">
                and t.branch_bank_code = #{branchBankCode,jdbcType=VARCHAR}
            </if>
            <if test="null != branchBankName">
                and t.branch_bank_name = #{branchBankName,jdbcType=VARCHAR}
            </if>
            <if test="null != payTime">
                and t.pay_time = #{payTime,jdbcType=TIMESTAMP}
            </if>
            <if test="null != payPic">
                and t.pay_pic = #{payPic,jdbcType=VARCHAR}
            </if>
            <if test="null != promisePic">
                and t.promise_pic = #{promisePic,jdbcType=VARCHAR}
            </if>
            <if test="null != createTime">
                and t.create_time = #{createTime,jdbcType=TIMESTAMP}
            </if>
            <if test="null != updateTime">
                and t.update_time = #{updateTime,jdbcType=TIMESTAMP}
            </if>
            <if test="null != createUserId">
                and t.create_user_id = #{createUserId,jdbcType=VARCHAR}
            </if>
            <if test="null != updateUserId">
                and t.update_user_id = #{updateUserId,jdbcType=VARCHAR}
            </if>
            <if test="null != deleted">
                and t.deleted = #{deleted,jdbcType=BIT}
            </if>
        </trim>
    </sql>

    <select id="getLinePayByLineId" resultMap="BaseResultMap">
        select *
        from xfsg_line_pay
        where line_id = #{lineId}
          and deleted = '0' limit 1
    </select>

    <select id="getByLineIdAndPayTypeAndShopId" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from xfsg_line_pay
        <where>
             deleted = '0'
            and pay_business_type = #{payBusinessType}
            <if test="lineId != null and lineId != ''">
                and line_id = #{lineId}
            </if>
            <if test="shopId != null and shopId != ''">
                and shop_id = #{shopId}
            </if>
        </where>
    </select>

    <select id="getLinePayByLineIds" resultMap="BaseResultMap">
        select * from xfsg_line_pay where deleted = 0
        <if test="businessType!=null">
            and pay_business_type = #{businessType}
        </if>
        <if test="lineIds !=null and lineIds.size>0">
            <foreach collection="lineIds" item="lineId" open="and line_id in (" close=")" separator=",">
                #{lineId}
            </foreach>
        </if>
        <if test="shopIds !=null and shopIds.size>0">
            <foreach collection="shopIds" item="shopId" open="and shop_id in (" close=")" separator=",">
                #{shopId}
            </foreach>
        </if>
    </select>
</mapper>