<?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.ylx.massage.mapper.TBankUserMapper">

    <resultMap type="com.ylx.massage.domain.TBankUser" id="TBankUserMap">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="bankId" column="bank_id" jdbcType="VARCHAR"/>
        <result property="openId" column="open_id" jdbcType="VARCHAR"/>
        <result property="openingBank" column="opening_bank" jdbcType="VARCHAR"/>
        <result property="bankCardNum" column="bank_card_num" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="isDelete" column="is_delete" jdbcType="INTEGER"/>
    </resultMap>

    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="" useGeneratedKeys="true">
        insert into ry-vue.t_bank_user(idbank_idopen_idopening_bankbank_card_numcreate_timeupdate_timeis_delete)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.id}#{entity.bankId}#{entity.openId}#{entity.openingBank}#{entity.bankCardNum}#{entity.createTime}#{entity.updateTime}#{entity.isDelete})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="" useGeneratedKeys="true">
        insert into ry-vue.t_bank_user(idbank_idopen_idopening_bankbank_card_numcreate_timeupdate_timeis_delete)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.id}#{entity.bankId}#{entity.openId}#{entity.openingBank}#{entity.bankCardNum}#{entity.createTime}#{entity.updateTime}#{entity.isDelete})
        </foreach>
        on duplicate key update
        id = values(id) bank_id = values(bank_id) open_id = values(open_id) opening_bank = values(opening_bank)
        bank_card_num = values(bank_card_num) create_time = values(create_time) update_time = values(update_time)
        is_delete = values(is_delete)
    </insert>

    <update id="deleteBank">
        update t_bank_user  set is_delete = 1 where id = #{id}
    </update>

    <select id="myBank" resultType="com.ylx.massage.domain.vo.BankVo">
        SELECT
            bu.open_id,
            bu.opening_bank,
            bu.bank_card_num,
            bu.bank_id,
            b.bank_name,
            b.bank_logo,
            b.id
        FROM
            t_bank_user bu
                LEFT JOIN t_bank b ON bu.bank_id = b.id
        WHERE
            bu.is_delete = 0
            AND b.is_delete = 0
            AND bu.open_id = #{openId}
    </select>

</mapper>

