<?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.mall.mapper.OfflinePaymentMapper">
    
    <resultMap type="OfflinePayment" id="OfflinePaymentResult">
        <result property="id"    column="id"    />
        <result property="bankcardNum"    column="bankcard_num"    />
        <result property="bankName"    column="bank_name"    />
        <result property="merchantPaycode"    column="merchant_paycode"    />
    </resultMap>

    <sql id="selectOfflinePaymentVo">
        select id, bankcard_num, bank_name, merchant_paycode from offline_payment
    </sql>

    <select id="selectOfflinePaymentList" parameterType="OfflinePayment" resultMap="OfflinePaymentResult">
        <include refid="selectOfflinePaymentVo"/>
        <where>  
            <if test="bankcardNum != null "> and bankcard_num = #{bankcardNum}</if>
            <if test="bankName != null  and bankName != ''"> and bank_name like concat('%', #{bankName}, '%')</if>
            <if test="merchantPaycode != null  and merchantPaycode != ''"> and merchant_paycode = #{merchantPaycode}</if>
        </where>
    </select>
    
    <select id="selectOfflinePaymentById" parameterType="Long" resultMap="OfflinePaymentResult">
        <include refid="selectOfflinePaymentVo"/>
        where id = #{id}
    </select>

    <insert id="insertOfflinePayment" parameterType="OfflinePayment" useGeneratedKeys="true" keyProperty="id">
        insert into offline_payment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="bankcardNum != null">bankcard_num,</if>
            <if test="bankName != null">bank_name,</if>
            <if test="merchantPaycode != null">merchant_paycode,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="bankcardNum != null">#{bankcardNum},</if>
            <if test="bankName != null">#{bankName},</if>
            <if test="merchantPaycode != null">#{merchantPaycode},</if>
         </trim>
    </insert>

    <update id="updateOfflinePayment" parameterType="OfflinePayment">
        update offline_payment
        <trim prefix="SET" suffixOverrides=",">
            <if test="bankcardNum != null">bankcard_num = #{bankcardNum},</if>
            <if test="bankName != null">bank_name = #{bankName},</if>
            <if test="merchantPaycode != null">merchant_paycode = #{merchantPaycode},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOfflinePaymentById" parameterType="Long">
        delete from offline_payment where id = #{id}
    </delete>

    <delete id="deleteOfflinePaymentByIds" parameterType="String">
        delete from offline_payment where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>