<?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.ym.mec.biz.dal.dao.SysUserBankCardDao">

    <resultMap type="com.ym.mec.biz.dal.entity.SysUserBankCard" id="SysUserBankCard">
        <result column="id_" property="id"/>
        <result column="user_id_" property="userId"/>
        <result column="is_default_" property="isDefault"/>
        <result column="bank_name_" property="bankName"/>
        <result column="bank_code_" property="bankCode"/>
        <result column="card_no_" property="cardNo"/>
        <result column="province_" property="province"/>
        <result column="city_" property="city"/>
        <result column="address" property="address"/>
        <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="create_on_" property="createOn"/>
        <result column="modify_on_" property="modifyOn"/>
        <result column="is_quick_" property="isQuick" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
        <result column="mobile_phone_" property="mobilePhone"/>
        <result column="trans_no_" property="transNo"/>
        <result column="id_card_no_" property="idCardNo"/>
        <result column="real_name_" property="realName"/>
        <result column="tenant_id_" property="tenantId"/>
    </resultMap>
    <delete id="del">
        UPDATE sys_user_bank_card SET status_ = 0 WHERE id_ = #{id} AND user_id_ = #{userId}
    </delete>

    <!-- 根据主键查询一条记录 -->
    <select id="get" resultMap="SysUserBankCard">
		SELECT * FROM sys_user_bank_card WHERE id_ = #{id} AND status_ != 0
	</select>

    <!-- 全查询 -->
    <select id="findAll" resultMap="SysUserBankCard">
		SELECT * FROM sys_user_bank_card WHERE status_ != 0 and tenant_id_ = #{tenantId} ORDER BY id_
	</select>

    <!-- 向数据库增加一条记录 -->
    <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.SysUserBankCard" useGeneratedKeys="true" keyColumn="id"
            keyProperty="id">
        <!--
        <selectKey resultClass="int" keyProperty="id" >
        SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL
        </selectKey>
        -->
        INSERT INTO sys_user_bank_card
        (id_,user_id_,is_default_,bank_name_,bank_code_,card_no_,province_,city_,address,create_on_,modify_on_,is_quick_,mobile_phone_,trans_no_,real_name_,id_card_no_,tenant_id_)
        VALUES(#{id},#{userId},#{isDefault},#{bankName},#{bankCode},#{cardNo},#{province},
        #{city},#{address},now(),now(),#{isQuick,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{mobilePhone},#{transNo},#{realName},#{idCardNo},#{tenantId})
    </insert>

    <!-- 根据主键查询一条记录 -->
    <update id="update" parameterType="com.ym.mec.biz.dal.entity.SysUserBankCard">
        UPDATE sys_user_bank_card
        <set>
            <if test="mobilePhone != null">
                mobile_phone_ = #{mobilePhone},
            </if>
            <if test="status != null">
                status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            </if>
            <if test="modifyOn != null">
                modify_on_ = #{modifyOn},
            </if>
            <if test="address != null">
                address = #{address},
            </if>
            <if test="isDefault != null">
                is_default_ = #{isDefault},
            </if>
            <if test="bankCode != null">
                bank_code_ = #{bankCode},
            </if>
            <if test="cardNo != null">
                card_no_ = #{cardNo},
            </if>
            <if test="bankName != null">
                bank_name_ = #{bankName},
            </if>
            <if test="province != null">
                province_ = #{province},
            </if>
            <if test="city != null">
                city_ = #{city},
            </if>
            <if test="userId != null">
                user_id_ = #{userId},
            </if>
            <if test="isQuick != null">
                is_quick_ = #{isQuick,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
            </if>
            <if test="transNo != null">
                trans_no_ = #{transNo},
            </if>
            <if test="idCardNo != null">
                id_card_no_ = #{idCardNo},
            </if>
            <if test="realName != null">
                real_name_ = #{realName},
            </if>
        </set>
        WHERE id_ = #{id} and tenant_id_ = #{tenantId}
    </update>

    <!-- 根据主键删除一条记录 -->
    <update id="delete">
		UPDATE sys_user_bank_card SET status_ = 0 WHERE id_ = #{id}
	</update>

    <update id="setDefault">
        UPDATE sys_user_bank_card SET is_default_ = 1 WHERE id_ = #{bankCardId} AND user_id_ = #{userId}
    </update>
    <update id="setNotDefault">
        UPDATE sys_user_bank_card SET is_default_ = 0 WHERE user_id_ = #{userId}
    </update>

    <!-- 分页查询 -->
    <select id="queryPage" resultMap="SysUserBankCard" parameterType="map">
        SELECT * FROM sys_user_bank_card where status_ != 0 AND user_id_ = #{userId}
        ORDER BY id_
        <include refid="global.limit"/>
    </select>

    <!-- 查询当前表的总记录数 -->
    <select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM sys_user_bank_card where status_ != 0 and tenant_id_ = #{tenantId}
	</select>

    <select id="findByUser" resultMap="SysUserBankCard">
        SELECT * FROM sys_user_bank_card where status_ != 0 AND user_id_ = #{userId}
    </select>
</mapper>
