<?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.hw.dms.mapper.DmsPlanLubeDetailMapper">
    
    <resultMap type="DmsPlanLubeDetail" id="DmsPlanLubeDetailResult">
        <result property="planLubeDetailId"    column="plan_lube_detail_id"    />
        <result property="planLubeId"    column="plan_lube_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="lubeStationId"    column="lube_station_id"    />
        <result property="lubeStandardId"    column="lube_standard_id"    />
        <result property="operationDescription"    column="operation_description"    />
        <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="selectDmsPlanLubeDetailVo">
        select plan_lube_detail_id, plan_lube_id, device_id, lube_station_id, lube_standard_id, operation_description, is_flag, remark, create_by, create_time, update_by, update_time from dms_plan_lube_detail
    </sql>

    <select id="selectDmsPlanLubeDetailList" parameterType="DmsPlanLubeDetail" resultMap="DmsPlanLubeDetailResult">
        <include refid="selectDmsPlanLubeDetailVo"/>
        <where>  
            <if test="planLubeId != null "> and plan_lube_id = #{planLubeId}</if>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="lubeStationId != null "> and lube_station_id = #{lubeStationId}</if>
            <if test="lubeStandardId != null "> and lube_standard_id = #{lubeStandardId}</if>
            <if test="operationDescription != null  and operationDescription != ''"> and operation_description = #{operationDescription}</if>
            <if test="isFlag != null "> and is_flag = #{isFlag}</if>
        </where>
    </select>
    
    <select id="selectDmsPlanLubeDetailByPlanLubeDetailId" parameterType="Long" resultMap="DmsPlanLubeDetailResult">
        <include refid="selectDmsPlanLubeDetailVo"/>
        where plan_lube_detail_id = #{planLubeDetailId}
    </select>
        
    <insert id="insertDmsPlanLubeDetail" parameterType="DmsPlanLubeDetail" useGeneratedKeys="true" keyProperty="planLubeDetailId">
        insert into dms_plan_lube_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="planLubeId != null">plan_lube_id,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="lubeStationId != null">lube_station_id,</if>
            <if test="lubeStandardId != null">lube_standard_id,</if>
            <if test="operationDescription != null">operation_description,</if>
            <if test="isFlag != null">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="planLubeId != null">#{planLubeId},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="lubeStationId != null">#{lubeStationId},</if>
            <if test="lubeStandardId != null">#{lubeStandardId},</if>
            <if test="operationDescription != null">#{operationDescription},</if>
            <if test="isFlag != null">#{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="updateDmsPlanLubeDetail" parameterType="DmsPlanLubeDetail">
        update dms_plan_lube_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="planLubeId != null">plan_lube_id = #{planLubeId},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="lubeStationId != null">lube_station_id = #{lubeStationId},</if>
            <if test="lubeStandardId != null">lube_standard_id = #{lubeStandardId},</if>
            <if test="operationDescription != null">operation_description = #{operationDescription},</if>
            <if test="isFlag != null">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 plan_lube_detail_id = #{planLubeDetailId}
    </update>

    <delete id="deleteDmsPlanLubeDetailByPlanLubeDetailId" parameterType="Long">
        delete from dms_plan_lube_detail where plan_lube_detail_id = #{planLubeDetailId}
    </delete>

    <delete id="deleteDmsPlanLubeDetailByPlanLubeDetailIds" parameterType="String">
        delete from dms_plan_lube_detail where plan_lube_detail_id in 
        <foreach item="planLubeDetailId" collection="array" open="(" separator="," close=")">
            #{planLubeDetailId}
        </foreach>
    </delete>
</mapper>