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

    <resultMap id="BaseResultMap" type="com.ho.business.entity.ElecStationValue">
            <id property="id" column="id" jdbcType="INTEGER"/>
            <result property="groupId" column="group_id" jdbcType="INTEGER"/>
            <result property="deptId" column="dept_id" jdbcType="INTEGER"/>
            <result property="stationId" column="station_id" jdbcType="INTEGER"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="type" column="type" jdbcType="INTEGER"/>
            <result property="digital" column="digital" jdbcType="DECIMAL"/>
            <result property="day" column="day" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,group_id,dept_id,src_id,pid,
        station_id,create_time,type,
        digital,day
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from elec_station_value
        where  id = #{id,jdbcType=INTEGER} 
    </select>
    <select id="underElectricityCollection" resultType="com.ho.business.vo.resp.StatisticsRespVO">
        select day as date,digital
        from elec_station_value
        <where>
            <if test="beginTime != null ">
                and day &gt;=  #{beginTime}
            </if>
            <if test="endTime != null">
                and day &lt;= #{endTime}
            </if>
            <if test="groupId !=null">
                and  group_id = #{groupId}
            </if>
            <if test="deptId != null">
                and dept_id = #{deptId}
            </if>
            <if test="stationId != null">
                and   station_id = #{stationId}
            </if>
            <if test="type !=null">
                and type = #{type}
            </if>
        </where>
        order by day
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from elec_station_value
        where  id = #{id,jdbcType=INTEGER} 
    </delete>

    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.business.entity.ElecStationValue" useGeneratedKeys="true">
        insert into elec_station_value
        ( id,group_id,dept_id,pid,src_id
        ,station_id,create_time,type
        ,digital,day)
        values (#{id,jdbcType=INTEGER},#{groupId,jdbcType=INTEGER},#{deptId,jdbcType=INTEGER}
        ,#{stationId,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{type,jdbcType=INTEGER}
        ,#{digital,jdbcType=DECIMAL},#{day,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ho.business.entity.ElecStationValue" useGeneratedKeys="true">
        insert into elec_station_value
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="id != null">id,</if>
                <if test="groupId != null">group_id,</if>
                <if test="deptId != null">dept_id,</if>
                <if test="stationId != null">station_id,</if>
                <if test="createTime != null">create_time,</if>
                <if test="type != null">type,</if>
                <if test="digital != null">digital,</if>
                <if test="day != null">day,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="id != null">#{id,jdbcType=INTEGER},</if>
                <if test="groupId != null">#{groupId,jdbcType=INTEGER},</if>
                <if test="deptId != null">#{deptId,jdbcType=INTEGER},</if>
                <if test="stationId != null">#{stationId,jdbcType=INTEGER},</if>
                <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
                <if test="type != null">#{type,jdbcType=INTEGER},</if>
                <if test="digital != null">#{digital,jdbcType=DECIMAL},</if>
                <if test="day != null">#{day,jdbcType=VARCHAR},</if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective" parameterType="com.ho.business.entity.ElecStationValue">
        update elec_station_value
        <set>
                <if test="groupId != null">
                    group_id = #{groupId,jdbcType=INTEGER},
                </if>
                <if test="deptId != null">
                    dept_id = #{deptId,jdbcType=INTEGER},
                </if>
                <if test="stationId != null">
                    station_id = #{stationId,jdbcType=INTEGER},
                </if>
                <if test="createTime != null">
                    create_time = #{createTime,jdbcType=TIMESTAMP},
                </if>
                <if test="type != null">
                    type = #{type,jdbcType=INTEGER},
                </if>
                <if test="digital != null">
                    digital = #{digital,jdbcType=DECIMAL},
                </if>
                <if test="day != null">
                    day = #{day,jdbcType=VARCHAR},
                </if>
        </set>
        where   id = #{id,jdbcType=INTEGER} 
    </update>
    <update id="updateByPrimaryKey" parameterType="com.ho.business.entity.ElecStationValue">
        update elec_station_value
        set 
            group_id =  #{groupId,jdbcType=INTEGER},
            dept_id =  #{deptId,jdbcType=INTEGER},
            station_id =  #{stationId,jdbcType=INTEGER},
            create_time =  #{createTime,jdbcType=TIMESTAMP},
            type =  #{type,jdbcType=INTEGER},
            digital =  #{digital,jdbcType=DECIMAL},
            day =  #{day,jdbcType=VARCHAR}
        where   id = #{id,jdbcType=INTEGER} 
    </update>

<!--    <insert id="insertBatch">-->
<!--        INSERT INTO elec_station_value (-->
<!--        <if test="groupId != null">group_id,</if>-->
<!--        <if test="deptId != null">dept_id,</if>-->
<!--        <if test="stationId != null">station_id,</if>-->
<!--        <if test="createTime != null">create_time,</if>-->
<!--        <if test="type != null">type,</if>-->
<!--        <if test="digital != null">digital,</if>-->
<!--        <if test="day != null">day,</if>-->
<!--        <if test="srcId != null">src_id,</if>-->
<!--        <if test="pid != null">pid,</if>-->
<!--          )-->
<!--        VALUES-->
<!--        <foreach item="item" collection="list" index="index" separator=",">-->
<!--            values (-->
<!--            <if test="groupId != null">#{item.groupId,jdbcType=INTEGER},</if>-->
<!--            <if test="deptId != null">#{item.deptId,jdbcType=INTEGER},</if>-->
<!--            <if test="stationId != null">#{item.stationId,jdbcType=INTEGER},</if>-->
<!--            <if test="createTime != null">#{item.createTime,jdbcType=TIMESTAMP},</if>-->
<!--            <if test="type != null">#{item.type,jdbcType=INTEGER},</if>-->
<!--            <if test="digital != null">#{item.digital,jdbcType=DECIMAL},</if>-->
<!--            <if test="day != null">#{item.day,jdbcType=VARCHAR},</if>-->
<!--            <if test="srcId != null">#{item.src_id},</if>-->
<!--            <if test="pid != null">#{item.pid},</if>-->

<!--            )-->
<!--        </foreach>-->
<!--    </insert>-->


    <insert id="insertBatch">
        INSERT INTO elec_station_value (
        group_id,dept_id,pid,src_id
        ,station_id,create_time,type,digital,day
        )
        VALUES
        <foreach item="item" collection="list" index="index" separator=",">
            (
             #{item.groupId,jdbcType=INTEGER},#{item.deptId,jdbcType=INTEGER},
             #{item.stationId,jdbcType=INTEGER},now(),#{item.type,jdbcType=INTEGER},
             #{item.digital,jdbcType=DECIMAL},#{item.day,jdbcType=VARCHAR},
             #{item.pid,jdbcType=INTEGER},#{item.srcId,jdbcType=INTEGER}
            )
        </foreach>
    </insert>

    <delete id="deleteByDay">
        delete
        from elec_station_value
        <where>
            and day = #{day}
            <if test="typeList !=null and typeList.size() !=0">
                and type in
                <foreach collection="typeList" item = "item" open="(" close=")" separator="," >
                    #{item}
                </foreach>
            </if>
        </where>
    </delete>

</mapper>
