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

    <resultMap type="UserConsumptionDetails" id="UserConsumptionDetailsResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="deviceNumber"    column="device_number"    />
        <result property="cardNumber"    column="card_number"    />
        <result property="projectId"    column="project_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="billingType"    column="billing_type"    />
        <result property="pumpTime"    column="pump_time"    />
        <result property="unitPrice"    column="unit_price"    />
        <result property="totalPrice"    column="total_price"    />
        <result property="discount"    column="discount"    />
        <result property="taxAmount"    column="tax_amount"    />
        <result property="amountDue"    column="amount_due"    />
        <result property="billingPeriodUnit"    column="billing_period_unit"    />
        <result property="billingPeriodDuration"    column="billing_period_duration"    />
        <result property="billingDate"    column="billing_date"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="paymentStatus"    column="payment_status"    />
        <result property="paymentMethod"    column="payment_method"    />
        <result property="paymentTime"    column="payment_time"    />
        <result property="status"    column="status"    />
        <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="areaCode"    column="area_code"    />
    </resultMap>

    <sql id="selectUserConsumptionDetailsVo">
        select id, user_id, device_number, card_number, project_id, dept_id, billing_type, pump_time, unit_price, total_price, discount, tax_amount, amount_due, billing_period_unit, billing_period_duration, billing_date, start_time, end_time, payment_status, payment_method, payment_time, status, remark, create_time, update_time, create_by, update_by, area_code from user_consumption_details
    </sql>

    <select id="selectUserConsumptionDetailsList" parameterType="UserConsumptionDetails" resultMap="UserConsumptionDetailsResult">
        <include refid="selectUserConsumptionDetailsVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="deviceNumber != null  and deviceNumber != ''"> and device_number = #{deviceNumber}</if>
            <!--<if test="cardNumber != null  and cardNumber != ''"> and card_number = #{cardNumber}</if>-->
            <if test="cardNumber != null  and cardNumber != ''"> and card_number LIKE CONCAT('%',#{cardNumber},'%')</if>
            <if test="projectId != null "> and project_id = #{projectId}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="billingType != null "> and billing_type = #{billingType}</if>
            <if test="pumpTime != null "> and pump_time = #{pumpTime}</if>
            <if test="unitPrice != null "> and unit_price = #{unitPrice}</if>
            <if test="totalPrice != null "> and total_price = #{totalPrice}</if>
            <if test="discount != null "> and discount = #{discount}</if>
            <if test="taxAmount != null "> and tax_amount = #{taxAmount}</if>
            <if test="amountDue != null "> and amount_due = #{amountDue}</if>
            <if test="billingPeriodUnit != null "> and billing_period_unit = #{billingPeriodUnit}</if>
            <if test="billingPeriodDuration != null "> and billing_period_duration = #{billingPeriodDuration}</if>
            <if test="billingDate != null "> and billing_date = #{billingDate}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="paymentStatus != null "> and payment_status = #{paymentStatus}</if>
            <if test="paymentMethod != null "> and payment_method = #{paymentMethod}</if>
            <if test="paymentTime != null "> and payment_time = #{paymentTime}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
        </where>
    </select>

    <select id="selectUserConsumptionDetailsById" parameterType="Long" resultMap="UserConsumptionDetailsResult">
        <include refid="selectUserConsumptionDetailsVo"/>
        where id = #{id}
    </select>

    <select id="selectUserConsumptionDetailsListById" parameterType="String" resultMap="UserConsumptionDetailsResult">
        <include refid="selectUserConsumptionDetailsVo"/>
        where
            card_number = #{cardNumber}
    </select>

    <select id="selectUserConsumptionDetailsSwipListByCardNumber" parameterType="UserConsumptionDetails" resultMap="UserConsumptionDetailsResult">
        <include refid="selectUserConsumptionDetailsVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="deviceNumber != null  and deviceNumber != ''"> and device_number = #{deviceNumber}</if>
            <if test="cardNumber != null  and cardNumber != ''"> and card_number = #{cardNumber}</if>
            <!--<if test="cardNumber != null  and cardNumber != ''"> and card_number LIKE CONCAT('%',#{cardNumber},'%')</if>-->
            <if test="projectId != null "> and project_id = #{projectId}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="billingType != null "> and billing_type = #{billingType}</if>
            <if test="pumpTime != null "> and pump_time = #{pumpTime}</if>
            <if test="unitPrice != null "> and unit_price = #{unitPrice}</if>
            <if test="totalPrice != null "> and total_price = #{totalPrice}</if>
            <if test="discount != null "> and discount = #{discount}</if>
            <if test="taxAmount != null "> and tax_amount = #{taxAmount}</if>
            <if test="amountDue != null "> and amount_due = #{amountDue}</if>
            <if test="billingPeriodUnit != null "> and billing_period_unit = #{billingPeriodUnit}</if>
            <if test="billingPeriodDuration != null "> and billing_period_duration = #{billingPeriodDuration}</if>
            <if test="billingDate != null "> and billing_date = #{billingDate}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="paymentStatus != null "> and payment_status = #{paymentStatus}</if>
            <if test="paymentMethod != null "> and payment_method = #{paymentMethod}</if>
            <if test="paymentTime != null "> and payment_time = #{paymentTime}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
        </where>
    </select>

    <insert id="insertUserConsumptionDetails" parameterType="UserConsumptionDetails" useGeneratedKeys="true" keyProperty="id">
        insert into user_consumption_details
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="deviceNumber != null">device_number,</if>
            <if test="cardNumber != null">card_number,</if>
            <if test="projectId != null">project_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="billingType != null">billing_type,</if>
            <if test="pumpTime != null">pump_time,</if>
            <if test="unitPrice != null">unit_price,</if>
            <if test="totalPrice != null">total_price,</if>
            <if test="discount != null">discount,</if>
            <if test="taxAmount != null">tax_amount,</if>
            <if test="amountDue != null">amount_due,</if>
            <if test="billingPeriodUnit != null">billing_period_unit,</if>
            <if test="billingPeriodDuration != null">billing_period_duration,</if>
            <if test="billingDate != null">billing_date,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="paymentStatus != null">payment_status,</if>
            <if test="paymentMethod != null">payment_method,</if>
            <if test="paymentTime != null">payment_time,</if>
            <if test="status != null">status,</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="areaCode != null">area_code,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="deviceNumber != null">#{deviceNumber},</if>
            <if test="cardNumber != null">#{cardNumber},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="billingType != null">#{billingType},</if>
            <if test="pumpTime != null">#{pumpTime},</if>
            <if test="unitPrice != null">#{unitPrice},</if>
            <if test="totalPrice != null">#{totalPrice},</if>
            <if test="discount != null">#{discount},</if>
            <if test="taxAmount != null">#{taxAmount},</if>
            <if test="amountDue != null">#{amountDue},</if>
            <if test="billingPeriodUnit != null">#{billingPeriodUnit},</if>
            <if test="billingPeriodDuration != null">#{billingPeriodDuration},</if>
            <if test="billingDate != null">#{billingDate},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="paymentStatus != null">#{paymentStatus},</if>
            <if test="paymentMethod != null">#{paymentMethod},</if>
            <if test="paymentTime != null">#{paymentTime},</if>
            <if test="status != null">#{status},</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="areaCode != null">#{areaCode},</if>
        </trim>
    </insert>

    <update id="updateUserConsumptionDetails" parameterType="UserConsumptionDetails">
        update user_consumption_details
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="deviceNumber != null">device_number = #{deviceNumber},</if>
            <if test="cardNumber != null">card_number = #{cardNumber},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="billingType != null">billing_type = #{billingType},</if>
            <if test="pumpTime != null">pump_time = #{pumpTime},</if>
            <if test="unitPrice != null">unit_price = #{unitPrice},</if>
            <if test="totalPrice != null">total_price = #{totalPrice},</if>
            <if test="discount != null">discount = #{discount},</if>
            <if test="taxAmount != null">tax_amount = #{taxAmount},</if>
            <if test="amountDue != null">amount_due = #{amountDue},</if>
            <if test="billingPeriodUnit != null">billing_period_unit = #{billingPeriodUnit},</if>
            <if test="billingPeriodDuration != null">billing_period_duration = #{billingPeriodDuration},</if>
            <if test="billingDate != null">billing_date = #{billingDate},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="paymentStatus != null">payment_status = #{paymentStatus},</if>
            <if test="paymentMethod != null">payment_method = #{paymentMethod},</if>
            <if test="paymentTime != null">payment_time = #{paymentTime},</if>
            <if test="status != null">status = #{status},</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="areaCode != null">area_code = #{areaCode},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUserConsumptionDetailsById" parameterType="Long">
        delete from user_consumption_details where id = #{id}
    </delete>

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