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

    <resultMap type="DmsBillsMaintDetail" id="DmsBillsMaintDetailResult">
        <result property="billsMaintDetailId"    column="bills_maint_detail_id"    />
        <result property="maintInstanceId"    column="maint_instance_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="stationId"    column="station_id"    />
        <result property="maintStandardId"    column="maint_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="maintStationName"    column="maint_station_name"    />
        <result property="maintProtocol"    column="maint_protocol"    />
        <result property="maintOperationDescription"    column="maint_operation_description"    />

    </resultMap>


    <sql id="selectDmsBillsMaintDetailVo">
        select bills_maint_detail_id, maint_instance_id, device_id, station_id, maint_standard_id, operation_description, maint_status, is_flag, remark, create_by, create_time, update_by, update_time from dms_bills_maint_detail
    </sql>

    <select id="selectDmsBillsMaintDetailList" parameterType="DmsBillsMaintDetail" resultMap="DmsBillsMaintDetailResult">
        <include refid="selectDmsBillsMaintDetailVo"/>
        <where>
            <if test="maintInstanceId != null "> and maint_instance_id = #{maintInstanceId}</if>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="stationId != null "> and station_id = #{stationId}</if>
            <if test="maintStandardId != null "> and maint_standard_id = #{maintStandardId}</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="selectDmsBillsMaintDetailByBillsMaintDetailId" parameterType="Long" resultMap="DmsBillsMaintDetailResult">
        <include refid="selectDmsBillsMaintDetailVo"/>
        where bills_maint_detail_id = #{billsMaintDetailId}
    </select>

    <insert id="insertDmsBillsMaintDetail" parameterType="DmsBillsMaintDetail" useGeneratedKeys="true" keyProperty="billsMaintDetailId">
        insert into dms_bills_maint_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="maintInstanceId != null">maint_instance_id,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="stationId != null">station_id,</if>
            <if test="maintStandardId != null">maint_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="maintInstanceId != null">#{maintInstanceId},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="stationId != null">#{stationId},</if>
            <if test="maintStandardId != null">#{maintStandardId},</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="updateDmsBillsMaintDetail" parameterType="DmsBillsMaintDetail">
        update dms_bills_maint_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="maintInstanceId != null">maint_instance_id = #{maintInstanceId},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="stationId != null">station_id = #{stationId},</if>
            <if test="maintStandardId != null">maint_standard_id = #{maintStandardId},</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_maint_detail_id = #{billsMaintDetailId}
    </update>

    <delete id="deleteDmsBillsMaintDetailByBillsMaintDetailId" parameterType="Long">
        delete from dms_bills_maint_detail where bills_maint_detail_id = #{billsMaintDetailId}
    </delete>

    <delete id="deleteDmsBillsMaintDetailByBillsMaintDetailIds" parameterType="String">
        delete from dms_bills_maint_detail where bills_maint_detail_id in
        <foreach item="billsMaintDetailId" collection="array" open="(" separator="," close=")">
            #{billsMaintDetailId}
        </foreach>
    </delete>




    <sql id="selectDmsBillsMaintDetailJoinVo">
        select dbmd.bills_maint_detail_id, dbmd.maint_instance_id, dbmd.device_id, dbmd.station_id, dbmd.maint_standard_id,
               dbmd.operation_description, dbmd.maint_status,
               dbdl.device_code,dbdl.device_name,
               dbdt.type_name,
               dbms.maint_station_name,
               dbmsd.maint_protocol,dbmsd.operation_description as maint_operation_description
        from dms_bills_maint_detail dbmd
            left join dms_base_device_ledger dbdl on dbmd.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_maint_station dbms on dbmd.station_id = dbms.maint_station_id
            left join dms_base_maint_standard dbmsd on dbmd.maint_standard_id = dbmsd.maint_standard_id
    </sql>

    <select id="selectDmsBillsMaintDetailJoinList" parameterType="DmsBillsMaintDetail" resultMap="DmsBillsMaintDetailResult">
        <include refid="selectDmsBillsMaintDetailJoinVo"/>
        <where>
            <if test="maintInstanceId != null "> and dbmd.maint_instance_id = #{maintInstanceId}</if>
            <if test="deviceId != null "> and dbmd.device_id = #{deviceId}</if>
            <if test="stationId != null "> and dbmd.station_id = #{stationId}</if>
            <if test="maintStandardId != null "> and dbmd.maint_standard_id = #{maintStandardId}</if>
            <if test="maintStatus != null "> and dbmd.maint_status = #{maintStatus}</if>
        </where>
    </select>

</mapper>
