<?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.waterele.mapper.MaGuangaiRecordMapper">
    
    <resultMap type="com.fastbee.waterele.domain.MaGuangaiRecord" id="MaGuangaiRecordResult">
        <result property="id"    column="id"    />
        <result property="devSn"    column="dev_sn"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="lastTime"    column="last_time"    />
        <result property="cardId"    column="card_id"    />
        <result property="areaCode"    column="area_code"    />
        <result property="userBalance"    column="user_balance"    />
        <result property="curFlow"    column="cur_flow"    />
        <result property="curEle"    column="cur_ele"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectMaGuangaiRecordVo">
        select id, dev_sn, start_time, end_time, last_time, card_id, area_code, user_balance, cur_flow, cur_ele, status, create_time, update_time from ma_guangai_record
    </sql>

    <select id="selectMaGuangaiRecordList" parameterType="MaGuangaiRecord" resultMap="MaGuangaiRecordResult">
        <include refid="selectMaGuangaiRecordVo"/>
        <where>  
            <if test="devSn != null  and devSn != ''"> and dev_sn = #{devSn}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="lastTime != null "> and last_time = #{lastTime}</if>
            <if test="cardId != null  and cardId != ''"> and card_id = #{cardId}</if>
            <if test="areaCode != null  and areaCode != ''"> and area_code = #{areaCode}</if>
            <if test="userBalance != null  and userBalance != ''"> and user_balance = #{userBalance}</if>
            <if test="curFlow != null  and curFlow != ''"> and cur_flow = #{curFlow}</if>
            <if test="curEle != null  and curEle != ''"> and cur_ele = #{curEle}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="params.beginCreateTime != null and params.beginCreateTime != ''
            and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
        </where>
    </select>
    
    <select id="selectMaGuangaiRecordById" parameterType="Long" resultMap="MaGuangaiRecordResult">
        <include refid="selectMaGuangaiRecordVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertMaGuangaiRecord" parameterType="MaGuangaiRecord" useGeneratedKeys="true" keyProperty="id">
        insert into ma_guangai_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="devSn != null">dev_sn,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="lastTime != null">last_time,</if>
            <if test="cardId != null">card_id,</if>
            <if test="areaCode != null">area_code,</if>
            <if test="userBalance != null">user_balance,</if>
            <if test="curFlow != null">cur_flow,</if>
            <if test="curEle != null">cur_ele,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="devSn != null">#{devSn},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="lastTime != null">#{lastTime},</if>
            <if test="cardId != null">#{cardId},</if>
            <if test="areaCode != null">#{areaCode},</if>
            <if test="userBalance != null">#{userBalance},</if>
            <if test="curFlow != null">#{curFlow},</if>
            <if test="curEle != null">#{curEle},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateMaGuangaiRecord" parameterType="MaGuangaiRecord">
        update ma_guangai_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="devSn != null">dev_sn = #{devSn},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="lastTime != null">last_time = #{lastTime},</if>
            <if test="cardId != null">card_id = #{cardId},</if>
            <if test="areaCode != null">area_code = #{areaCode},</if>
            <if test="userBalance != null">user_balance = #{userBalance},</if>
            <if test="curFlow != null">cur_flow = #{curFlow},</if>
            <if test="curEle != null">cur_ele = #{curEle},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMaGuangaiRecordById" parameterType="Long">
        delete from ma_guangai_record where id = #{id}
    </delete>

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