<?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.yijia.station.mapper.StationOilPriceMapper">
    
    <resultMap type="StationOilPrice" id="StationOilPriceResult">
        <result property="oilPriceId"    column="oil_price_id"    />
        <result property="oilName"    column="oil_name"    />
        <result property="oilPrice"    column="oil_price"    />
        <result property="stationId"    column="station_id"    />
        <result property="stationNanme"    column="station_nanme"    />
        <result property="date"    column="date"    />
    </resultMap>

    <sql id="selectStationOilPriceVo">
        select oil_price_id, oil_name, oil_price, station_id, station_nanme, date from station_oil_price
    </sql>

    <select id="selectStationOilPriceList" parameterType="StationOilPrice" resultMap="StationOilPriceResult">
        <include refid="selectStationOilPriceVo"/>
        <where>  
            <if test="oilName != null  and oilName != ''"> and oil_name like concat('%', #{oilName}, '%')</if>
            <if test="oilPrice != null  and oilPrice != ''"> and oil_price = #{oilPrice}</if>
            <if test="stationId != null "> and station_id = #{stationId}</if>
            <if test="stationNanme != null  and stationNanme != ''"> and station_nanme = #{stationNanme}</if>
            <if test="date != null "> and date = #{date}</if>
        </where>
    </select>
    
    <select id="selectStationOilPriceById" parameterType="Long" resultMap="StationOilPriceResult">
        <include refid="selectStationOilPriceVo"/>
        where oil_price_id = #{oilPriceId}
    </select>
        
    <insert id="insertStationOilPrice" parameterType="StationOilPrice" useGeneratedKeys="true" keyProperty="oilPriceId">
        insert into station_oil_price
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="oilName != null">oil_name,</if>
            <if test="oilPrice != null">oil_price,</if>
            <if test="stationId != null">station_id,</if>
            <if test="stationNanme != null">station_nanme,</if>
            <if test="date != null">date,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="oilName != null">#{oilName},</if>
            <if test="oilPrice != null">#{oilPrice},</if>
            <if test="stationId != null">#{stationId},</if>
            <if test="stationNanme != null">#{stationNanme},</if>
            <if test="date != null">#{date},</if>
         </trim>
    </insert>

    <update id="updateStationOilPrice" parameterType="StationOilPrice">
        update station_oil_price
        <trim prefix="SET" suffixOverrides=",">
            <if test="oilName != null">oil_name = #{oilName},</if>
            <if test="oilPrice != null">oil_price = #{oilPrice},</if>
            <if test="stationId != null">station_id = #{stationId},</if>
            <if test="stationNanme != null">station_nanme = #{stationNanme},</if>
            <if test="date != null">date = #{date},</if>
        </trim>
        where oil_price_id = #{oilPriceId}
    </update>

    <delete id="deleteStationOilPriceById" parameterType="Long">
        delete from station_oil_price where oil_price_id = #{oilPriceId}
    </delete>

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