<?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.StationOilGunMapper">
    
    <resultMap type="StationOilGun" id="StationOilGunResult">
        <result property="oilGunId"    column="oil_gun_id"    />
        <result property="oilGunNo"    column="oil_gun_no"    />
        <result property="oilName"    column="oil_name"    />
        <result property="oilPrice"    column="oil_price"    />
        <result property="stationId"    column="station_id"    />
        <result property="stationName"    column="station_name"    />
        <result property="date"    column="date"    />
        <result property="status"    column="status"    />
        <result property="oilGunType"    column="oil_gun_type"    />
    </resultMap>

    <sql id="selectStationOilGunVo">
        select oil_gun_id, oil_gun_no, oil_name, oil_price, station_id, station_name, date, status, oil_gun_type from station_oil_gun
    </sql>

    <select id="selectStationOilGunList" parameterType="StationOilGun" resultMap="StationOilGunResult">
        <include refid="selectStationOilGunVo"/>
        <where>  
            <if test="oilGunNo != null  and oilGunNo != ''"> and oil_gun_no = #{oilGunNo}</if>
            <if test="oilName != null  and oilName != ''"> and oil_name like concat('%', #{oilName}, '%')</if>
            <if test="oilPrice != null "> and oil_price = #{oilPrice}</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="date != null "> and date = #{date}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="oilGunType != null  and oilGunType != ''"> and oil_gun_type = #{oilGunType}</if>
            <if test="stationIdList != null ">
                and station_id in
                <foreach item="item" index="index" collection="stationIdList"
                         open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>
    
    <select id="selectStationOilGunById" parameterType="Long" resultMap="StationOilGunResult">
        <include refid="selectStationOilGunVo"/>
        where oil_gun_id = #{oilGunId}
    </select>
        
    <insert id="insertStationOilGun" parameterType="StationOilGun" useGeneratedKeys="true" keyProperty="oilGunId">
        insert into station_oil_gun
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="oilGunNo != null">oil_gun_no,</if>
            <if test="oilName != null">oil_name,</if>
            <if test="oilPrice != null">oil_price,</if>
            <if test="stationId != null">station_id,</if>
            <if test="stationName != null">station_name,</if>
            <if test="date != null">date,</if>
            <if test="status != null">status,</if>
            <if test="oilGunType != null">oil_gun_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="oilGunNo != null">#{oilGunNo},</if>
            <if test="oilName != null">#{oilName},</if>
            <if test="oilPrice != null">#{oilPrice},</if>
            <if test="stationId != null">#{stationId},</if>
            <if test="stationName != null">#{stationName},</if>
            <if test="date != null">#{date},</if>
            <if test="status != null">#{status},</if>
            <if test="oilGunType != null">#{oilGunType},</if>
         </trim>
    </insert>

    <update id="updateStationOilGun" parameterType="StationOilGun">
        update station_oil_gun
        <trim prefix="SET" suffixOverrides=",">
            <if test="oilGunNo != null">oil_gun_no = #{oilGunNo},</if>
            <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="stationName != null">station_name = #{stationName},</if>
            <if test="date != null">date = #{date},</if>
            <if test="status != null">status = #{status},</if>
            <if test="oilGunType != null">oil_gun_type = #{oilGunType},</if>
        </trim>
        where oil_gun_id = #{oilGunId}
    </update>

    <delete id="deleteStationOilGunById" parameterType="Long">
        delete from station_oil_gun where oil_gun_id = #{oilGunId}
    </delete>

    <delete id="deleteStationOilGunByIds" parameterType="String">
        delete from station_oil_gun where oil_gun_id in 
        <foreach item="oilGunId" collection="array" open="(" separator="," close=")">
            #{oilGunId}
        </foreach>
    </delete>
    
</mapper>