<?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.ho.business.mapper.ElecMeterConfigMapper">

    <sql id="Base_Column_List">
        id,station_id,user_id,begin_time,end_time,create_time,update_time
    </sql>

    <insert id="insertElecMeterConfig" parameterType="com.ho.business.entity.ElecMeterConfig">
        insert into elec_meter_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stationId != null">station_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="beginTime != null">begin_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stationId != null">#{stationId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="beginTime != null">#{beginTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <update id="updateById" parameterType="com.ho.business.entity.ElecMeterConfig">
        update elec_meter_config
        <set>
            <if test="beginTime != null">
                begin_time = #{beginTime},
            </if>
            <if test="endTime != null">
                end_time = #{endTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
        </set>
        where id = #{id}
    </update>

    <select id="selectByParam" resultType="com.ho.business.entity.ElecMeterConfig">
        SELECT <include refid="Base_Column_List"/>
        FROM elec_meter_config
        <where>
            <if test="userId != null">
                and user_id = #{userId}
            </if>
            <if test="stationId != null">
                and station_id = #{stationId}
            </if>
        </where>
        limit 1
    </select>

</mapper>
