<?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.fastbee.rechargecard.mapper.UserRechargeCardsMapper">

    <resultMap type="UserRechargeCards" id="UserRechargeCardsResult">
        <result property="id"    column="id"    />
        <result property="userName"    column="user_name"    />
        <result property="name"    column="name"    />
        <result property="phone"    column="phone"    />
        <result property="projectId"    column="project_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="balance"    column="balance"    />
        <result property="cardNumber"    column="card_number"    />
        <result property="cardPassword"    column="card_password"    />
        <result property="issueDate"    column="issue_date"    />
        <result property="expirationDate"    column="expiration_date"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="userId"    column="user_id"    />
    </resultMap>

    <sql id="selectUserRechargeCardsVo">
        select id, user_name, name, phone, project_id, dept_id, balance, card_number, card_password, issue_date, expiration_date, status, create_time, update_time, create_by, update_by, del_flag, user_id from user_recharge_cards
    </sql>

    <select id="selectUserRechargeCardsList" parameterType="UserRechargeCards" resultMap="UserRechargeCardsResult">
        <include refid="selectUserRechargeCardsVo"/>
        <where>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="projectId != null "> and project_id = #{projectId}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="balance != null "> and balance = #{balance}</if>
            <if test="cardNumber != null  and cardNumber != ''"> and card_number = #{cardNumber}</if>
            <if test="cardPassword != null  and cardPassword != ''"> and card_password = #{cardPassword}</if>
            <if test="issueDate != null "> and issue_date = #{issueDate}</if>
            <if test="expirationDate != null "> and expiration_date = #{expirationDate}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
        </where>
    </select>

    <select id="selectUserRechargeCardsById" parameterType="Long" resultMap="UserRechargeCardsResult">
        <include refid="selectUserRechargeCardsVo"/>
        where id = #{id}
    </select>

    <insert id="insertUserRechargeCards" parameterType="UserRechargeCards" useGeneratedKeys="true" keyProperty="id">
        insert into user_recharge_cards
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userName != null">user_name,</if>
            <if test="name != null">name,</if>
            <if test="phone != null">phone,</if>
            <if test="projectId != null">project_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="balance != null">balance,</if>
            <if test="cardNumber != null">card_number,</if>
            <if test="cardPassword != null">card_password,</if>
            <if test="issueDate != null">issue_date,</if>
            <if test="expirationDate != null">expiration_date,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="userId != null">user_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userName != null">#{userName},</if>
            <if test="name != null">#{name},</if>
            <if test="phone != null">#{phone},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="balance != null">#{balance},</if>
            <if test="cardNumber != null">#{cardNumber},</if>
            <if test="cardPassword != null">#{cardPassword},</if>
            <if test="issueDate != null">#{issueDate},</if>
            <if test="expirationDate != null">#{expirationDate},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="userId != null">#{userId},</if>
        </trim>
    </insert>

    <update id="updateUserRechargeCards" parameterType="UserRechargeCards">
        update user_recharge_cards
        <trim prefix="SET" suffixOverrides=",">
            <if test="userName != null">user_name = #{userName},</if>
            <if test="name != null">name = #{name},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="balance != null">balance = #{balance},</if>
            <if test="cardNumber != null">card_number = #{cardNumber},</if>
            <if test="cardPassword != null">card_password = #{cardPassword},</if>
            <if test="issueDate != null">issue_date = #{issueDate},</if>
            <if test="expirationDate != null">expiration_date = #{expirationDate},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="userId != null">user_id = #{userId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUserRechargeCardsById" parameterType="Long">
        delete from user_recharge_cards where user_id = #{id}
    </delete>

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