<?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="cn.wisenergy.mapper.BankInfoMapper">
    <resultMap id="bankMap" type="cn.wisenergy.model.app.BankInfo">
        <id column="id" property="id"/>
        <result column="user_id" property="userId"/>
        <result column="name" property="name"/>
        <result column="id_card_no" property="idCardNo"/>
        <result column="bank_name" property="bankName"/>
        <result column="card_number" property="cardNumber"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="table">
        bank_info
    </sql>

    <sql id="cols_all">
        id,
        <include refid="cols_exclude_id"/>
    </sql>

    <sql id="cols_exclude_id">
        user_id,name,id_card_no,bank_name,card_number,create_time,update_time
    </sql>

    <sql id="vals">
        #{userId},#{name},#{idCardNo},#{bankName},#{cardNumber},now(),now()
    </sql>

    <sql id="updateCondition">
        <if test="userId != null">user_id = #{userId},</if>
        <if test="name != null">name = #{name},</if>
        <if test="idCardNo != null">id_card_no = #{idCardNo},</if>
        <if test="bankName != null">bank_name =#{bankName},</if>
        <if test="cardNumber != null">card_number =#{cardNumber},</if>
        update_time =now()
    </sql>

    <sql id="criteria">
        <if test="id != null">id = #{id}</if>
        <if test="userId != null">and user_id = #{userId}</if>
        <if test="name != null">and name = #{name}</if>
        <if test="idCardNo != null">and id_card_no = #{idCardNo}</if>
        <if test="bankName != null">and bank_name =#{bankName}</if>
        <if test="cardNumber != null">and card_number =#{cardNumber}</if>
        <if test="createTime != null">and create_time &gt;= #{createTime}</if>
        <if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
    </sql>

    <insert id="add" parameterType="cn.wisenergy.model.app.BankInfo" keyProperty="id" useGeneratedKeys="true">
        insert into
        <include refid="table"/>
        (<include refid="cols_exclude_id"/>)
        value(
        <include refid="vals"/>
        )
    </insert>

    <update id="edit" parameterType="cn.wisenergy.model.app.BankInfo">
        UPDATE
        <include refid="table"/>
        <set>
            <include refid="updateCondition"/>
        </set>
        <where>
            id = #{id}
        </where>
    </update>

    <delete id="delById" parameterType="java.lang.Integer">
        delete from
        <include refid="table"/>
        where id = #{id}
    </delete>

    <select id="getByUserId" resultType="cn.wisenergy.model.app.BankInfo">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            user_id=#{userId}
        </where>
    </select>

</mapper>