<?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.StationInfoMapper">
    
    <resultMap type="StationInfo" id="StationInfoResult">
        <result property="stationId"    column="station_id"    />
        <result property="stationName"    column="station_name"    />
        <result property="stationAddress"    column="station_address"    />
        <result property="oilGunNum"    column="oil_gun_num"    />
        <result property="contacts"    column="contacts"    />
        <result property="phone"    column="phone"    />
        <result property="stationGroupId"    column="station_group_id"    />
        <result property="stationGroupName"    column="station_group_name"    />
        <result property="stationPic"    column="station_pic"    />
        <result property="stationLongitude"    column="station_longitude"    />
        <result property="stationLatitude"    column="station_latitude"    />
        <result property="mno"    column="mno"    />
    </resultMap>

    <sql id="selectStationInfoVo">
        select station_id, station_name, station_address, oil_gun_num, contacts, phone, station_group_id, station_group_name, station_pic, station_longitude, station_latitude, mno from station_info
    </sql>

    <select id="selectStationInfoList" parameterType="StationInfo" resultMap="StationInfoResult">
        <include refid="selectStationInfoVo"/>
        <where>  
            <if test="stationName != null  and stationName != ''"> and station_name like concat('%', #{stationName}, '%')</if>
            <if test="stationAddress != null  and stationAddress != ''"> and station_address = #{stationAddress}</if>
            <if test="oilGunNum != null "> and oil_gun_num = #{oilGunNum}</if>
            <if test="contacts != null  and contacts != ''"> and contacts = #{contacts}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="stationGroupId != null "> and station_group_id = #{stationGroupId}</if>
            <if test="stationGroupName != null  and stationGroupName != ''"> and station_group_name like concat('%', #{stationGroupName}, '%')</if>
            <if test="stationPic != null  and stationPic != ''"> and station_pic = #{stationPic}</if>
            <if test="stationLongitude != null  and stationLongitude != ''"> and station_longitude = #{stationLongitude}</if>
            <if test="stationLatitude != null  and stationLatitude != ''"> and station_latitude = #{stationLatitude}</if>
            <if test="mno != null "> and mno = #{mno}</if>
        </where>
    </select>
    
    <select id="selectStationInfoById" parameterType="Long" resultMap="StationInfoResult">
        <include refid="selectStationInfoVo"/>
        where station_id = #{stationId}
    </select>
        
    <insert id="insertStationInfo" parameterType="StationInfo">
        insert into station_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stationId != null">station_id,</if>
            <if test="stationName != null">station_name,</if>
            <if test="stationAddress != null">station_address,</if>
            <if test="oilGunNum != null">oil_gun_num,</if>
            <if test="contacts != null">contacts,</if>
            <if test="phone != null">phone,</if>
            <if test="stationGroupId != null">station_group_id,</if>
            <if test="stationGroupName != null">station_group_name,</if>
            <if test="stationPic != null">station_pic,</if>
            <if test="stationLongitude != null">station_longitude,</if>
            <if test="stationLatitude != null">station_latitude,</if>
            <if test="mno != null">mno,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stationId != null">#{stationId},</if>
            <if test="stationName != null">#{stationName},</if>
            <if test="stationAddress != null">#{stationAddress},</if>
            <if test="oilGunNum != null">#{oilGunNum},</if>
            <if test="contacts != null">#{contacts},</if>
            <if test="phone != null">#{phone},</if>
            <if test="stationGroupId != null">#{stationGroupId},</if>
            <if test="stationGroupName != null">#{stationGroupName},</if>
            <if test="stationPic != null">#{stationPic},</if>
            <if test="stationLongitude != null">#{stationLongitude},</if>
            <if test="stationLatitude != null">#{stationLatitude},</if>
            <if test="mno != null">#{mno},</if>
         </trim>
    </insert>

    <update id="updateStationInfo" parameterType="StationInfo">
        update station_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="stationName != null">station_name = #{stationName},</if>
            <if test="stationAddress != null">station_address = #{stationAddress},</if>
            <if test="oilGunNum != null">oil_gun_num = #{oilGunNum},</if>
            <if test="contacts != null">contacts = #{contacts},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="stationGroupId != null">station_group_id = #{stationGroupId},</if>
            <if test="stationGroupName != null">station_group_name = #{stationGroupName},</if>
            <if test="stationPic != null">station_pic = #{stationPic},</if>
            <if test="stationLongitude != null">station_longitude = #{stationLongitude},</if>
            <if test="stationLatitude != null">station_latitude = #{stationLatitude},</if>
            <if test="mno != null">mno = #{mno},</if>
        </trim>
        where station_id = #{stationId}
    </update>

    <delete id="deleteStationInfoById" parameterType="Long">
        delete from station_info where station_id = #{stationId}
    </delete>

    <delete id="deleteStationInfoByIds" parameterType="String">
        delete from station_info where station_id in 
        <foreach item="stationId" collection="array" open="(" separator="," close=")">
            #{stationId}
        </foreach>
    </delete>
    
</mapper>