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

    <resultMap type="NgWaterPumpUsageRecords" id="NgWaterPumpUsageRecordsResult">
        <result property="id"    column="id"    />
        <result property="pumpStartTime"    column="pump_start_time"    />
        <result property="pumpStopTime"    column="pump_stop_time"    />
        <result property="deviceNumber"    column="device_number"    />
        <result property="messageContent"    column="message_content"    />
    </resultMap>

    <sql id="selectNgWaterPumpUsageRecordsVo">
        select id, pump_start_time, pump_stop_time, device_number, message_content from ng_water_pump_usage_records
    </sql>

    <select id="selectNgWaterPumpUsageRecordsList" parameterType="NgWaterPumpUsageRecords" resultMap="NgWaterPumpUsageRecordsResult">
        <include refid="selectNgWaterPumpUsageRecordsVo"/>
        <where>
            <if test="pumpStartTime != null "> and pump_start_time = #{pumpStartTime}</if>
            <if test="pumpStopTime != null "> and pump_stop_time = #{pumpStopTime}</if>
            <if test="deviceNumber != null  and deviceNumber != ''"> and device_number = #{deviceNumber}</if>
            <if test="messageContent != null  and messageContent != ''"> and message_content = #{messageContent}</if>
        </where>
        order by pump_start_time desc
    </select>

    <select id="selectNgWaterPumpUsageRecordsById" parameterType="Long" resultMap="NgWaterPumpUsageRecordsResult">
        <include refid="selectNgWaterPumpUsageRecordsVo"/>
        where id = #{id}
    </select>

    <insert id="insertNgWaterPumpUsageRecords" parameterType="NgWaterPumpUsageRecords" useGeneratedKeys="true" keyProperty="id">
        insert into ng_water_pump_usage_records
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pumpStartTime != null">pump_start_time,</if>
            <if test="pumpStopTime != null">pump_stop_time,</if>
            <if test="deviceNumber != null and deviceNumber != ''">device_number,</if>
            <if test="messageContent != null">message_content,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="pumpStartTime != null">#{pumpStartTime},</if>
            <if test="pumpStopTime != null">#{pumpStopTime},</if>
            <if test="deviceNumber != null and deviceNumber != ''">#{deviceNumber},</if>
            <if test="messageContent != null">#{messageContent},</if>
        </trim>
    </insert>

    <update id="updateNgWaterPumpUsageRecords" parameterType="NgWaterPumpUsageRecords">
        update ng_water_pump_usage_records
        <trim prefix="SET" suffixOverrides=",">
            <if test="pumpStartTime != null">pump_start_time = #{pumpStartTime},</if>
            <if test="pumpStopTime != null">pump_stop_time = #{pumpStopTime},</if>
            <if test="deviceNumber != null and deviceNumber != ''">device_number = #{deviceNumber},</if>
            <if test="messageContent != null">message_content = #{messageContent},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNgWaterPumpUsageRecordsById" parameterType="Long">
        delete from ng_water_pump_usage_records where id = #{id}
    </delete>

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