<?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.StationOilPriceAdjustMapper">
    
    <resultMap type="StationOilPriceAdjust" id="StationOilPriceAdjustResult">
        <result property="adjustPriceId"    column="adjust_price_id"    />
        <result property="oilName"    column="oil_name"    />
        <result property="oilAdjustPrice"    column="oil_adjust_price"    />
        <result property="takeEffectStatus"    column="take_effect_status"    />
        <result property="takeEffectDate"    column="take_effect_date"    />
        <result property="adjustDate"    column="adjust_date"    />
        <result property="stationId"    column="station_id"    />
        <result property="stationName"    column="station_name"    />
        <result property="operator"    column="operator"    />
        <result property="status"    column="status"    />
        <result property="oilPriceId"    column="oil_price_id"    />
    </resultMap>

    <sql id="selectStationOilPriceAdjustVo">
        select adjust_price_id, oil_name, oil_adjust_price, take_effect_status, take_effect_date, adjust_date, station_id, station_name, operator, status, oil_price_id from station_oil_price_adjust
    </sql>

    <select id="selectStationOilPriceAdjustList" parameterType="StationOilPriceAdjust" resultMap="StationOilPriceAdjustResult">
        <include refid="selectStationOilPriceAdjustVo"/>
        <where>  
            <if test="oilName != null  and oilName != ''"> and oil_name like concat('%', #{oilName}, '%')</if>
            <if test="oilAdjustPrice != null  and oilAdjustPrice != ''"> and oil_adjust_price = #{oilAdjustPrice}</if>
            <if test="takeEffectStatus != null  and takeEffectStatus != ''"> and take_effect_status = #{takeEffectStatus}</if>
            <if test="takeEffectDate != null "> and take_effect_date = #{takeEffectDate}</if>
            <if test="adjustDate != null "> and adjust_date = #{adjustDate}</if>
            <if test="stationId != null "> and station_id = #{stationId}</if>
            <if test="stationName != null  and stationName != ''"> and station_name like concat('%', #{stationName}, '%')</if>
            <if test="operator != null  and operator != ''"> and operator = #{operator}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="oilPriceId != null "> and oil_price_id = #{oilPriceId}</if>
            <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
                AND date_format(take_effect_date,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{endTime},'%Y-%m-%d %H:%i:%s')
            </if>
            <if test="stationIdList != null ">
                and station_id in
                <foreach item="item" index="index" collection="stationIdList"
                         open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        order by adjust_price_id desc
    </select>
    
    <select id="selectStationOilPriceAdjustById" parameterType="Long" resultMap="StationOilPriceAdjustResult">
        <include refid="selectStationOilPriceAdjustVo"/>
        where adjust_price_id = #{adjustPriceId}
    </select>
        
    <insert id="insertStationOilPriceAdjust" parameterType="StationOilPriceAdjust" useGeneratedKeys="true" keyProperty="adjustPriceId">
        insert into station_oil_price_adjust
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="oilName != null">oil_name,</if>
            <if test="oilAdjustPrice != null">oil_adjust_price,</if>
            <if test="takeEffectStatus != null">take_effect_status,</if>
            <if test="takeEffectDate != null">take_effect_date,</if>
            <if test="adjustDate != null">adjust_date,</if>
            <if test="stationId != null">station_id,</if>
            <if test="stationName != null">station_name,</if>
            <if test="operator != null">operator,</if>
            <if test="status != null">status,</if>
            <if test="oilPriceId != null">oil_price_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="oilName != null">#{oilName},</if>
            <if test="oilAdjustPrice != null">#{oilAdjustPrice},</if>
            <if test="takeEffectStatus != null">#{takeEffectStatus},</if>
            <if test="takeEffectDate != null">#{takeEffectDate},</if>
            <if test="adjustDate != null">#{adjustDate},</if>
            <if test="stationId != null">#{stationId},</if>
            <if test="stationName != null">#{stationName},</if>
            <if test="operator != null">#{operator},</if>
            <if test="status != null">#{status},</if>
            <if test="oilPriceId != null">#{oilPriceId},</if>
         </trim>
    </insert>

    <update id="updateStationOilPriceAdjust" parameterType="StationOilPriceAdjust">
        update station_oil_price_adjust
        <trim prefix="SET" suffixOverrides=",">
            <if test="oilName != null">oil_name = #{oilName},</if>
            <if test="oilAdjustPrice != null">oil_adjust_price = #{oilAdjustPrice},</if>
            <if test="takeEffectStatus != null">take_effect_status = #{takeEffectStatus},</if>
            <if test="takeEffectDate != null">take_effect_date = #{takeEffectDate},</if>
            <if test="adjustDate != null">adjust_date = #{adjustDate},</if>
            <if test="stationId != null">station_id = #{stationId},</if>
            <if test="stationName != null">station_name = #{stationName},</if>
            <if test="operator != null">operator = #{operator},</if>
            <if test="status != null">status = #{status},</if>
            <if test="oilPriceId != null">oil_price_id = #{oilPriceId},</if>
        </trim>
        where adjust_price_id = #{adjustPriceId}
    </update>

    <delete id="deleteStationOilPriceAdjustById" parameterType="Long">
        delete from station_oil_price_adjust where adjust_price_id = #{adjustPriceId}
    </delete>

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