<?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.MaWatereleRecordMapper">
    
    <resultMap type="com.fastbee.waterele.domain.MaWatereleRecord" id="MaWatereleRecordResult">
        <result property="id"    column="id"    />
        <result property="devSn"    column="dev_sn"    />
        <result property="workstate"    column="workState"    />
        <result property="usersumflow"    column="userSumFlow"    />
        <result property="usersumele"    column="userSumEle"    />
        <result property="userbalance"    column="userBalance"    />
        <result property="sumflow"    column="sumFlow"    />
        <result property="sumele"    column="sumEle"    />
        <result property="mcusn"    column="mcuSn"    />
        <result property="inspower"    column="insPower"    />
        <result property="insflow"    column="insFlow"    />
        <result property="curflow"    column="curFlow"    />
        <result property="curele"    column="curEle"    />
        <result property="metersum"    column="meterSum"    />
        <result property="meterins"    column="meterIns"    />
        <result property="cardid"    column="cardId"    />
        <result property="areacode"    column="areaCode"    />
        <result property="action"    column="action"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectMaWatereleRecordVo">
        select id, dev_sn, workState, userSumFlow, userSumEle, userBalance, sumFlow, sumEle, mcuSn, insPower, insFlow, curFlow, curEle, meterSum, meterIns, cardId, areaCode, action, create_time, update_time from ma_waterele_record
    </sql>

    <select id="selectMaWatereleRecordList" parameterType="MaWatereleRecord" resultMap="MaWatereleRecordResult">
        <include refid="selectMaWatereleRecordVo"/>
        <where>  
            <if test="devSn != null  and devSn != ''"> and dev_sn = #{devSn}</if>
            <if test="workstate != null "> and workState = #{workstate}</if>
            <if test="usersumflow != null  and usersumflow != ''"> and userSumFlow = #{usersumflow}</if>
            <if test="usersumele != null  and usersumele != ''"> and userSumEle = #{usersumele}</if>
            <if test="userbalance != null  and userbalance != ''"> and userBalance = #{userbalance}</if>
            <if test="sumflow != null  and sumflow != ''"> and sumFlow = #{sumflow}</if>
            <if test="sumele != null  and sumele != ''"> and sumEle = #{sumele}</if>
            <if test="mcusn != null  and mcusn != ''"> and mcuSn = #{mcusn}</if>
            <if test="inspower != null  and inspower != ''"> and insPower = #{inspower}</if>
            <if test="insflow != null  and insflow != ''"> and insFlow = #{insflow}</if>
            <if test="curflow != null  and curflow != ''"> and curFlow = #{curflow}</if>
            <if test="curele != null  and curele != ''"> and curEle = #{curele}</if>
            <if test="metersum != null  and metersum != ''"> and meterSum = #{metersum}</if>
            <if test="meterins != null  and meterins != ''"> and meterIns = #{meterins}</if>
            <if test="cardid != null  and cardid != ''"> and cardId = #{cardid}</if>
            <if test="areacode != null  and areacode != ''"> and areaCode = #{areacode}</if>
            <if test="action != null  and action != ''"> and action = #{action}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(create_time ,'%y%m%d%H%i%s') &gt;= date_format(#{params.beginTime},'%y%m%d%H%i%s')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND date_format(create_time ,'%y%m%d%H%i%s') &lt;= date_format(#{params.endTime},'%y%m%d%H%i%s')
            </if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectMaWatereleRecordById" parameterType="Long" resultMap="MaWatereleRecordResult">
        <include refid="selectMaWatereleRecordVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertMaWatereleRecord" parameterType="MaWatereleRecord" useGeneratedKeys="true" keyProperty="id">
        insert into ma_waterele_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="devSn != null">dev_sn,</if>
            <if test="workstate != null">workState,</if>
            <if test="usersumflow != null">userSumFlow,</if>
            <if test="usersumele != null">userSumEle,</if>
            <if test="userbalance != null">userBalance,</if>
            <if test="sumflow != null">sumFlow,</if>
            <if test="sumele != null">sumEle,</if>
            <if test="mcusn != null">mcuSn,</if>
            <if test="inspower != null">insPower,</if>
            <if test="insflow != null">insFlow,</if>
            <if test="curflow != null">curFlow,</if>
            <if test="curele != null">curEle,</if>
            <if test="metersum != null">meterSum,</if>
            <if test="meterins != null">meterIns,</if>
            <if test="cardid != null">cardId,</if>
            <if test="areacode != null">areaCode,</if>
            <if test="action != null">action,</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="workstate != null">#{workstate},</if>
            <if test="usersumflow != null">#{usersumflow},</if>
            <if test="usersumele != null">#{usersumele},</if>
            <if test="userbalance != null">#{userbalance},</if>
            <if test="sumflow != null">#{sumflow},</if>
            <if test="sumele != null">#{sumele},</if>
            <if test="mcusn != null">#{mcusn},</if>
            <if test="inspower != null">#{inspower},</if>
            <if test="insflow != null">#{insflow},</if>
            <if test="curflow != null">#{curflow},</if>
            <if test="curele != null">#{curele},</if>
            <if test="metersum != null">#{metersum},</if>
            <if test="meterins != null">#{meterins},</if>
            <if test="cardid != null">#{cardid},</if>
            <if test="areacode != null">#{areacode},</if>
            <if test="action != null">#{action},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateMaWatereleRecord" parameterType="MaWatereleRecord">
        update ma_waterele_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="devSn != null">dev_sn = #{devSn},</if>
            <if test="workstate != null">workState = #{workstate},</if>
            <if test="usersumflow != null">userSumFlow = #{usersumflow},</if>
            <if test="usersumele != null">userSumEle = #{usersumele},</if>
            <if test="userbalance != null">userBalance = #{userbalance},</if>
            <if test="sumflow != null">sumFlow = #{sumflow},</if>
            <if test="sumele != null">sumEle = #{sumele},</if>
            <if test="mcusn != null">mcuSn = #{mcusn},</if>
            <if test="inspower != null">insPower = #{inspower},</if>
            <if test="insflow != null">insFlow = #{insflow},</if>
            <if test="curflow != null">curFlow = #{curflow},</if>
            <if test="curele != null">curEle = #{curele},</if>
            <if test="metersum != null">meterSum = #{metersum},</if>
            <if test="meterins != null">meterIns = #{meterins},</if>
            <if test="cardid != null">cardId = #{cardid},</if>
            <if test="areacode != null">areaCode = #{areacode},</if>
            <if test="action != null">action = #{action},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMaWatereleRecordById" parameterType="Long">
        delete from ma_waterele_record where id = #{id}
    </delete>

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