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

    <resultMap id="BaseResultMap" type="com.ho.business.entity.ElecPrice">
        <id property="id" column="id" jdbcType="INTEGER"/>
        <result property="groupId" column="group_id" jdbcType="INTEGER"/>
        <result property="stationId" column="station_id" jdbcType="INTEGER"/>
        <result property="startTime" column="start_time" jdbcType="TIMESTAMP"/>
        <result property="price" column="prices" jdbcType="DECIMAL"/>
        <result property="priceType" column="prices_type" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id
        ,start_time,price,group_id,station_id,
        price_type
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from elec_price
        where id = #{id,jdbcType=INTEGER}
    </select>
    <select id="selectAll" resultType="com.ho.business.entity.ElecPrice">
        select
        <include refid="Base_Column_List"/>
        from elec_price
    </select>

    <select id="selectByStationIdAndTime" resultType="com.ho.business.entity.ElecPrice">
        SELECT
        <include refid="Base_Column_List"/>
        FROM `elec_price`
        <where>
            <if test="groupId!=null">
                and group_id=#{groupId}
            </if>
            <if test="stationId!=null">
                and station_id=#{stationId}
            </if>
            <if test="startTime!=null and startTime!=''">
                and start_time between #{startTime} and #{endTime}
            </if>
        </where>
        ORDER BY start_time
    </select>

    <select id="selectStartTime" resultType="java.lang.String">
        SELECT start_time AS startTime
        FROM `elec_price`
        <where>
            <if test="groupId!=null">
                and group_id = #{groupId}
            </if>
        </where>
        ORDER BY start_time DESC
        LIMIT 1
    </select>

    <select id="selectDayTimes" resultType="java.lang.String">
        SELECT start_time
        FROM `elec_price`
        WHERE start_time between #{stime} and now()
          and station_id = #{id}
        ORDER BY start_time
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete
        from elec_price
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.business.entity.ElecPrice"
            useGeneratedKeys="true">
        insert into elec_price
        ( id, start_time, price, station_id
        , price_type)
        values (#{id,jdbcType=INTEGER},
                #{startTime,jdbcType=TIMESTAMP},
                #{stationId,jdbcType=INTEGER},
                #{price,jdbcType=DECIMAL},
                #{priceType,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ho.business.entity.ElecPrice"
            useGeneratedKeys="true">
        insert into elec_price
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="stationId != null">station_id,</if>
            <if test="startTime != null">start_time,</if>
            <if test="price != null">price,</if>
            <if test="priceType != null">price_type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=INTEGER},</if>
            <if test="stationId != null">#{stationId,jdbcType=INTEGER},</if>
            <if test="startTime != null">#{startTime,jdbcType=DATE},</if>
            <if test="price != null">#{price,jdbcType=DECIMAL},</if>
            <if test="priceType != null">#{priceType,jdbcType=VARCHAR},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.ho.business.entity.ElecPrice">
        update elec_price
        <set>
            <if test="startTime != null">
                start_time = #{startTime,jdbcType=TIMESTAMP},
            </if>
            <if test="stationId != null">
                station_id = #{stationId,jdbcType=INTEGER}
            </if>
            <if test="prices != null">
                price = #{price,jdbcType=DECIMAL},
            </if>
            <if test="pricerType != null">
                price_type = #{priceType,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.ho.business.entity.ElecPrice">
        update elec_price
        set start_time = #{startTime,jdbcType=TIMESTAMP},
            station_id = #{stationId,jdbcType=INTEGER},
            price      = #{price,jdbcType=DECIMAL},
            price_type = #{priceType,jdbcType=VARCHAR}
        where id = #{id,jdbcType=INTEGER}
    </update>
</mapper>
