<?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.aucma.dms.mapper.DmsBaseLubeStationMapper">
    
    <resultMap type="DmsBaseLubeStation" id="DmsBaseLubeStationResult">
        <result property="lubeStationId"    column="lube_station_id"    />
        <result property="deviceTypeId"    column="device_type_id"    />
        <result property="lubeStationCode"    column="lube_station_code"    />
        <result property="lubeStationName"    column="lube_station_name"    />
        <result property="protocolCode"    column="protocol_code"    />
        <result property="isFlag"    column="is_flag"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectDmsBaseLubeStationVo">
        select lube_station_id, device_type_id, lube_station_code, lube_station_name, protocol_code, is_flag, remark, create_by, create_time, update_by, update_time from dms_base_lube_station
    </sql>

    <select id="selectDmsBaseLubeStationList" parameterType="DmsBaseLubeStation" resultMap="DmsBaseLubeStationResult">
        <include refid="selectDmsBaseLubeStationVo"/>
        <where>  
            <if test="deviceTypeId != null "> and device_type_id = #{deviceTypeId}</if>
            <if test="lubeStationCode != null  and lubeStationCode != ''"> and lube_station_code = #{lubeStationCode}</if>
            <if test="lubeStationName != null  and lubeStationName != ''"> and lube_station_name like concat('%', #{lubeStationName}, '%')</if>
            <if test="protocolCode != null  and protocolCode != ''"> and protocol_code = #{protocolCode}</if>
            <if test="isFlag != null  and isFlag != ''"> and is_flag = #{isFlag}</if>
        </where>
    </select>
    
    <select id="selectDmsBaseLubeStationByLubeStationId" parameterType="Long" resultMap="DmsBaseLubeStationResult">
        <include refid="selectDmsBaseLubeStationVo"/>
        where lube_station_id = #{lubeStationId}
    </select>
        
    <insert id="insertDmsBaseLubeStation" parameterType="DmsBaseLubeStation">
        <selectKey keyProperty="lubeStationId" resultType="long" order="BEFORE">
            SELECT SEQ_DMS_LUBE_STATION.NEXTVAL FROM DUAL
        </selectKey>
        insert into dms_base_lube_station
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="lubeStationId != null">lube_station_id,</if>
            <if test="deviceTypeId != null">device_type_id,</if>
            <if test="lubeStationCode != null">lube_station_code,</if>
            <if test="lubeStationName != null and lubeStationName != ''">lube_station_name,</if>
            <if test="protocolCode != null">protocol_code,</if>
            <if test="isFlag != null and isFlag != ''">is_flag,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="lubeStationId != null">#{lubeStationId},</if>
            <if test="deviceTypeId != null">#{deviceTypeId},</if>
            <if test="lubeStationCode != null">#{lubeStationCode},</if>
            <if test="lubeStationName != null and lubeStationName != ''">#{lubeStationName},</if>
            <if test="protocolCode != null">#{protocolCode},</if>
            <if test="isFlag != null and isFlag != ''">#{isFlag},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateDmsBaseLubeStation" parameterType="DmsBaseLubeStation">
        update dms_base_lube_station
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceTypeId != null">device_type_id = #{deviceTypeId},</if>
            <if test="lubeStationCode != null">lube_station_code = #{lubeStationCode},</if>
            <if test="lubeStationName != null and lubeStationName != ''">lube_station_name = #{lubeStationName},</if>
            <if test="protocolCode != null">protocol_code = #{protocolCode},</if>
            <if test="isFlag != null and isFlag != ''">is_flag = #{isFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where lube_station_id = #{lubeStationId}
    </update>

    <delete id="deleteDmsBaseLubeStationByLubeStationId" parameterType="Long">
        delete from dms_base_lube_station where lube_station_id = #{lubeStationId}
    </delete>

    <delete id="deleteDmsBaseLubeStationByLubeStationIds" parameterType="String">
        delete from dms_base_lube_station where lube_station_id in 
        <foreach item="lubeStationId" collection="array" open="(" separator="," close=")">
            #{lubeStationId}
        </foreach>
    </delete>
</mapper>