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

    <resultMap type="DmsBillsLubeDetail" id="DmsBillsLubeDetailResult">
        <result property="billsLubeDetailId"    column="bills_lube_detail_id"    />
        <result property="lubeInstanceId"    column="lube_instance_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="maintStatus"    column="maint_status"    />
        <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"    />
        <result property="beginTime"    column="begin_time"    />
        <result property="endTime"    column="end_time"    />

        <result property="deviceCode"    column="device_code"    />
        <result property="deviceName"    column="device_name"    />
        <result property="typeName"    column="type_name"    />
        <result property="lubeStationName"    column="lube_station_name"    />
        <result property="lubeProtocol"    column="lube_protocol"    />
    </resultMap>

    <sql id="selectDmsBillsLubeDetailVo">
        select bills_lube_detail_id, lube_instance_id, device_id, lube_station_id, lube_standard_id, operation_description, maint_status, is_flag, remark, create_by, create_time, update_by, update_time from dms_bills_lube_detail
    </sql>

    <select id="selectDmsBillsLubeDetailList" parameterType="DmsBillsLubeDetail" resultMap="DmsBillsLubeDetailResult">
        <include refid="selectDmsBillsLubeDetailVo"/>
        <where>
            <if test="lubeInstanceId != null "> and lube_instance_id = #{lubeInstanceId}</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="maintStatus != null "> and maint_status = #{maintStatus}</if>
            <if test="isFlag != null "> and is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectDmsBillsLubeDetailByBillsLubeDetailId" parameterType="Long" resultMap="DmsBillsLubeDetailResult">
        <include refid="selectDmsBillsLubeDetailVo"/>
        where bills_lube_detail_id = #{billsLubeDetailId}
    </select>

    <insert id="insertDmsBillsLubeDetail" parameterType="DmsBillsLubeDetail" useGeneratedKeys="true" keyProperty="billsLubeDetailId">
        insert into dms_bills_lube_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="lubeInstanceId != null">lube_instance_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="maintStatus != null">maint_status,</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>
            <if test="beginTime != null">begin_time,</if>
            <if test="endTime != null">end_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="lubeInstanceId != null">#{lubeInstanceId},</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="maintStatus != null">#{maintStatus},</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>
            <if test="beginTime != null">#{beginTime},</if>
            <if test="endTime != null">#{endTime},</if>
         </trim>
    </insert>

    <update id="updateDmsBillsLubeDetail" parameterType="DmsBillsLubeDetail">
        update dms_bills_lube_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="lubeInstanceId != null">lube_instance_id = #{lubeInstanceId},</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="maintStatus != null">maint_status = #{maintStatus},</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>
            <if test="beginTime != null">begin_time = #{beginTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
        </trim>
        where bills_lube_detail_id = #{billsLubeDetailId}
    </update>

    <delete id="deleteDmsBillsLubeDetailByBillsLubeDetailId" parameterType="Long">
        delete from dms_bills_lube_detail where bills_lube_detail_id = #{billsLubeDetailId}
    </delete>

    <delete id="deleteDmsBillsLubeDetailByBillsLubeDetailIds" parameterType="String">
        delete from dms_bills_lube_detail where bills_lube_detail_id in
        <foreach item="billsLubeDetailId" collection="array" open="(" separator="," close=")">
            #{billsLubeDetailId}
        </foreach>
    </delete>








    <sql id="selectDmsBillsLubeDetailJoinVo">
        select dbld.bills_lube_detail_id, dbld.lube_instance_id, dbld.device_id, dbld.lube_station_id, dbld.lube_standard_id,
               dbld.operation_description, dbld.maint_status, dbld.create_by, dbld.create_time,
               dbdl.device_code,dbdl.device_name,
               dbdt.type_name,
               dbls.protocol_code,
               dblsd.lube_protocol,dblsd.operation_description as lube_operation_description
        from dms_bills_lube_detail dbld
                 left join dms_base_device_ledger dbdl on dbld.device_id = dbdl.device_id
                 left join dms_base_device_type dbdt on dbdl.device_type_id=dbdt.device_type_id
                 left join dms_base_lube_station dbls on dbld.lube_station_id=dbls.lube_station_id
                 left join dms_base_lube_standard dblsd on dbld.lube_standard_id=dblsd.lube_standard_id

    </sql>

    <select id="selectDmsBillsLubeDetailJoinList" parameterType="DmsBillsLubeDetail" resultMap="DmsBillsLubeDetailResult">
        <include refid="selectDmsBillsLubeDetailJoinVo"/>
        <where>
            <if test="lubeInstanceId != null "> and dbld.lube_instance_id = #{lubeInstanceId}</if>
            <if test="deviceId != null "> and dbld.device_id = #{deviceId}</if>
            <if test="lubeStationId != null "> and dbld.lube_station_id = #{lubeStationId}</if>
            <if test="lubeStandardId != null "> and dbld.lube_standard_id = #{lubeStandardId}</if>
            <if test="operationDescription != null  and operationDescription != ''"> and dbld.operation_description = #{operationDescription}</if>
            <if test="maintStatus != null "> and dbld.maint_status = #{maintStatus}</if>
        </where>
    </select>


</mapper>
