<?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.DmsRecordLubeMapper">

    <resultMap type="DmsRecordLube" id="DmsRecordLubeResult">
        <result property="recordLubeId"    column="record_lube_id"    />
        <result property="billsLubeCode"    column="bills_lube_code"    />
        <result property="deviceId"    column="device_id"    />
        <result property="lubeLevel"    column="lube_level"    />
        <result property="lubeGroup"    column="lube_group"    />
        <result property="planTime"    column="plan_time"    />
        <result property="realBeginTime"    column="real_begin_time"    />
        <result property="realEndTime"    column="real_end_time"    />
        <result property="lubeStatus"    column="lube_status"    />
        <result property="operationsDescription"    column="operations_description"    />
        <result property="lubeDuration"    column="lube_duration"    />
        <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="selectDmsRecordLubeVo">
        select record_lube_id, bills_lube_code, device_id, lube_level, lube_group, plan_time, real_begin_time, real_end_time, lube_status, operations_description, lube_duration, is_flag, remark, create_by, create_time, update_by, update_time from dms_record_lube
    </sql>

    <select id="selectDmsRecordLubeList" parameterType="DmsRecordLube" resultMap="DmsRecordLubeResult">
        select a.record_lube_id, a.bills_lube_code, a.device_id, a.lube_level, a.lube_group, a.plan_time, a.real_begin_time, a.real_end_time, a.lube_status, a.operations_description, a.lube_duration, a.is_flag, a.remark, a.create_by, a.create_time, a.update_by, a.update_time
        from dms_record_lube a
        left join dms_base_device_ledger b on a.device_id = b.device_id
        <where>
            <if test="billsLubeCode != null  and billsLubeCode != ''"> and a.bills_lube_code = #{billsLubeCode}</if>
            <if test="deviceId != null "> and a.device_id = #{deviceId}</if>
            <if test="deviceName != null "> and b.device_name like concat('%', #{deviceName},'%')</if>
            <if test="lubeLevel != null  and lubeLevel != ''"> and a.lube_level = #{lubeLevel}</if>
            <if test="lubeGroup != null  and lubeGroup != ''"> and a.lube_group = #{lubeGroup}</if>
            <if test="planTime != null "> and a.plan_time = #{planTime}</if>
            <if test="realBeginTime != null "> and a.real_begin_time >= #{realBeginTime}</if>
            <if test="realEndTime != null "> and #{realEndTime} >=  a.real_end_time </if>
            <if test="lubeStatus != null  and lubeStatus != ''"> and a.lube_status = #{lubeStatus}</if>
            <if test="operationsDescription != null  and operationsDescription != ''"> and a.operations_description = #{operationsDescription}</if>
            <if test="lubeDuration != null  and lubeDuration != ''"> and a.lube_duration = #{lubeDuration}</if>
            <if test="isFlag != null  and isFlag != ''"> and a.is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectDmsRecordLubeByRecordLubeId" parameterType="Long" resultMap="DmsRecordLubeResult">
        <include refid="selectDmsRecordLubeVo"/>
        where record_lube_id = #{recordLubeId}
    </select>

    <insert id="insertDmsRecordLube" parameterType="DmsRecordLube" useGeneratedKeys="true" keyProperty="recordLubeId">
        insert into dms_record_lube
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="billsLubeCode != null">bills_lube_code,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="lubeLevel != null">lube_level,</if>
            <if test="lubeGroup != null">lube_group,</if>
            <if test="planTime != null">plan_time,</if>
            <if test="realBeginTime != null">real_begin_time,</if>
            <if test="realEndTime != null">real_end_time,</if>
            <if test="lubeStatus != null">lube_status,</if>
            <if test="operationsDescription != null">operations_description,</if>
            <if test="lubeDuration != null">lube_duration,</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="billsLubeCode != null">#{billsLubeCode},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="lubeLevel != null">#{lubeLevel},</if>
            <if test="lubeGroup != null">#{lubeGroup},</if>
            <if test="planTime != null">#{planTime},</if>
            <if test="realBeginTime != null">#{realBeginTime},</if>
            <if test="realEndTime != null">#{realEndTime},</if>
            <if test="lubeStatus != null">#{lubeStatus},</if>
            <if test="operationsDescription != null">#{operationsDescription},</if>
            <if test="lubeDuration != null">#{lubeDuration},</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="updateDmsRecordLube" parameterType="DmsRecordLube">
        update dms_record_lube
        <trim prefix="SET" suffixOverrides=",">
            <if test="billsLubeCode != null">bills_lube_code = #{billsLubeCode},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="lubeLevel != null">lube_level = #{lubeLevel},</if>
            <if test="lubeGroup != null">lube_group = #{lubeGroup},</if>
            <if test="planTime != null">plan_time = #{planTime},</if>
            <if test="realBeginTime != null">real_begin_time = #{realBeginTime},</if>
            <if test="realEndTime != null">real_end_time = #{realEndTime},</if>
            <if test="lubeStatus != null">lube_status = #{lubeStatus},</if>
            <if test="operationsDescription != null">operations_description = #{operationsDescription},</if>
            <if test="lubeDuration != null">lube_duration = #{lubeDuration},</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 record_lube_id = #{recordLubeId}
    </update>

    <delete id="deleteDmsRecordLubeByRecordLubeId" parameterType="Long">
        delete from dms_record_lube where record_lube_id = #{recordLubeId}
    </delete>

    <delete id="deleteDmsRecordLubeByRecordLubeIds" parameterType="String">
        delete from dms_record_lube where record_lube_id in
        <foreach item="recordLubeId" collection="array" open="(" separator="," close=")">
            #{recordLubeId}
        </foreach>
    </delete>
</mapper>
