<?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.NgUserRechargeRecordsMapper">

    <resultMap type="NgUserRechargeRecords" id="NgUserRechargeRecordsResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="cardNumber"    column="card_number"    />
        <result property="areaCode"    column="area_code"    />
        <result property="type"    column="type"    />
        <result property="amount"    column="amount"    />
        <result property="balance"    column="balance"    />
        <result property="rechargeTime"    column="recharge_time"    />
        <result property="rechargeCode"    column="recharge_code"    />
        <result property="status"    column="status"    />
        <result property="serialNumber"    column="serial_number"    />
        <result property="remark"    column="remark"    />
        <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="deviceNumber"    column="device_number"    />
        <result property="projectId"    column="project_id"    />
        <result property="deptId"    column="dept_id"    />
    </resultMap>

    <sql id="selectNgUserRechargeRecordsVo">
        select id, user_id, user_name, card_number, area_code, type, amount, balance, recharge_time, recharge_code, status, serial_number, remark, create_time, update_time, create_by, update_by, device_number, project_id, dept_id
        from ng_user_recharge_records
    </sql>

    <select id="selectNgUserRechargeRecordsList" parameterType="NgUserRechargeRecords" resultMap="NgUserRechargeRecordsResult">
        <include refid="selectNgUserRechargeRecordsVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="cardNumber != null  and cardNumber != ''"> and card_number = #{cardNumber}</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="amount != null "> and amount = #{amount}</if>
            <if test="balance != null "> and balance = #{balance}</if>
            <if test="rechargeTime != null "> and recharge_time = #{rechargeTime}</if>
            <if test="rechargeCode != null  and rechargeCode != ''"> and recharge_code = #{rechargeCode}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="serialNumber != null  and serialNumber != ''"> and serial_number = #{serialNumber}</if>
            <if test="deviceNumber != null  and deviceNumber != ''"> and device_number = #{deviceNumber}</if>
            <if test="projectId != null "> and project_id = #{projectId}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
        </where>
        <!-- 添加排序 -->
        order by recharge_time desc
    </select>

    <!--<select id="selectNgUserRechargeRecordsByCardNumber" parameterType="String" resultMap="NgUserRechargeRecordsResult">
        <include refid="selectNgUserRechargeRecordsVo"/>
        where card_number = #{cardNumber}
    </select>-->
    <select id="selectNgUserRechargeRecordsByCardNumber" parameterType="String" resultMap="NgUserRechargeRecordsResult">
        <include refid="selectNgUserRechargeRecordsVo"/>
        <where>

            <if test="cardNumber != null  and cardNumber != ''">  card_number = #{cardNumber}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="amount != null "> and amount = #{amount}</if>
            <if test="balance != null "> and balance = #{balance}</if>
            <if test="rechargeTime != null "> and recharge_time = #{rechargeTime}</if>
            <if test="rechargeCode != null  and rechargeCode != ''"> and recharge_code = #{rechargeCode}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="serialNumber != null  and serialNumber != ''"> and serial_number = #{serialNumber}</if>
            <if test="deviceNumber != null  and deviceNumber != ''"> and device_number = #{deviceNumber}</if>
            <if test="projectId != null "> and project_id = #{projectId}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
        </where>
    </select>

    <!--<select id="selectNgUserRechargeRecordsByRechargeCode" parameterType="String" resultMap="NgUserRechargeRecordsResult">
        <include refid="selectNgUserRechargeRecordsVo"/>
        <where>
            recharge_code = #{rechargeCode}
            <if test="cardNumber != null  and cardNumber != ''">  card_number = #{cardNumber}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="amount != null "> and amount = #{amount}</if>
            <if test="balance != null "> and balance = #{balance}</if>
            <if test="rechargeTime != null "> and recharge_time = #{rechargeTime}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="serialNumber != null  and serialNumber != ''"> and serial_number = #{serialNumber}</if>
            <if test="deviceNumber != null  and deviceNumber != ''"> and device_number = #{deviceNumber}</if>
            <if test="projectId != null "> and project_id = #{projectId}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
        </where>
    </select>-->

    <select id="selectNgUserRechargeRecordsBySerialNumber" parameterType="NgUserRechargeRecords" resultMap="NgUserRechargeRecordsResult">
        <include refid="selectNgUserRechargeRecordsVo"/>
        <where>
            <if test="serialNumber != null  and serialNumber != ''"> serial_number = #{serialNumber}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="cardNumber != null  and cardNumber != ''"> and card_number = #{cardNumber}</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="amount != null "> and amount = #{amount}</if>
            <if test="balance != null "> and balance = #{balance}</if>
            <if test="rechargeTime != null "> and recharge_time = #{rechargeTime}</if>
            <if test="rechargeCode != null  and rechargeCode != ''"> and recharge_code = #{rechargeCode}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="deviceNumber != null  and deviceNumber != ''"> and device_number = #{deviceNumber}</if>
            <if test="projectId != null "> and project_id = #{projectId}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
        </where>
    </select>

    <insert id="insertNgUserRechargeRecords" parameterType="NgUserRechargeRecords" useGeneratedKeys="true" keyProperty="id">
        insert into ng_user_recharge_records
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="cardNumber != null and cardNumber != ''">card_number,</if>
            <if test="areaCode != null">area_code,</if>
            <if test="type != null">type,</if>
            <if test="amount != null">amount,</if>
            <if test="balance != null">balance,</if>
            <if test="rechargeTime != null">recharge_time,</if>
            <if test="rechargeCode != null">recharge_code,</if>
            <if test="status != null">status,</if>
            <if test="serialNumber != null and serialNumber != ''">serial_number,</if>
            <if test="remark != null">remark,</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="deviceNumber != null">device_number,</if>
            <if test="projectId != null">project_id,</if>
            <if test="deptId != null">dept_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="cardNumber != null and cardNumber != ''">#{cardNumber},</if>
            <if test="areaCode != null">#{areaCode},</if>
            <if test="type != null">#{type},</if>
            <if test="amount != null">#{amount},</if>
            <if test="balance != null">#{balance},</if>
            <if test="rechargeTime != null">#{rechargeTime},</if>
            <if test="rechargeCode != null">#{rechargeCode},</if>
            <if test="status != null">#{status},</if>
            <if test="serialNumber != null and serialNumber != ''">#{serialNumber},</if>
            <if test="remark != null">#{remark},</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="deviceNumber != null">#{deviceNumber},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="deptId != null">#{deptId},</if>
        </trim>
    </insert>

    <update id="updateNgUserRechargeRecords" parameterType="NgUserRechargeRecords">
        update ng_user_recharge_records
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="cardNumber != null and cardNumber != ''">card_number = #{cardNumber},</if>
            <if test="areaCode != null">area_code = #{areaCode},</if>
            <if test="type != null">type = #{type},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="balance != null">balance = #{balance},</if>
            <if test="rechargeTime != null">recharge_time = #{rechargeTime},</if>
            <if test="rechargeCode != null">recharge_code = #{rechargeCode},</if>
            <if test="status != null">status = #{status},</if>
            <if test="serialNumber != null and serialNumber != ''">serial_number = #{serialNumber},</if>
            <if test="remark != null">remark = #{remark},</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="deviceNumber != null">device_number = #{deviceNumber},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateNgUserRechargeRecordsWechat" parameterType="NgUserRechargeRecords">
        update ng_user_recharge_records
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="cardNumber != null and cardNumber != ''">card_number = #{cardNumber},</if>
            <if test="areaCode != null">area_code = #{areaCode},</if>
            <if test="type != null">type = #{type},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="balance != null">balance = #{balance},</if>
            <if test="rechargeTime != null">recharge_time = #{rechargeTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="serialNumber != null and serialNumber != ''">serial_number = #{serialNumber},</if>
            <if test="remark != null">remark = #{remark},</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="deviceNumber != null">device_number = #{deviceNumber},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where recharge_code = #{rechargeCode}
    </update>

    <delete id="deleteNgUserRechargeRecordsById" parameterType="Long">
        delete from ng_user_recharge_records where id = #{id}
    </delete>

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