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

    <resultMap type="DmsRecordInspect" id="DmsRecordInspectResult">
        <result property="recordInspectId"    column="record_inspect_id"    />
        <result property="billsInspectCode"    column="bills_inspect_code"    />
        <result property="inspectType"    column="inspect_type"    />
        <result property="inspectRouteId"    column="inspect_route_id"    />
        <result property="deviceAmount"    column="device_amount"    />
        <result property="planTime"    column="plan_time"    />
        <result property="realBeginTime"    column="real_begin_time"    />
        <result property="realEndTime"    column="real_end_time"    />
        <result property="performer"    column="performer"    />
        <result property="inspectStatus"    column="inspect_status"    />
        <result property="inspectDuration"    column="inspect_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="selectDmsRecordInspectVo">
        select record_inspect_id, bills_inspect_code, inspect_type, inspect_route_id, device_amount, plan_time, real_begin_time, real_end_time, performer, inspect_status, inspect_duration, is_flag, remark, create_by, create_time, update_by, update_time from dms_record_inspect
    </sql>

    <select id="selectDmsRecordInspectList" parameterType="DmsRecordInspect" resultMap="DmsRecordInspectResult">
        <include refid="selectDmsRecordInspectVo"/>
        <where>
            <if test="billsInspectCode != null  and billsInspectCode != ''"> and bills_inspect_code = #{billsInspectCode}</if>
            <if test="inspectType != null  and inspectType != ''"> and inspect_type = #{inspectType}</if>
            <if test="inspectRouteId != null "> and inspect_route_id = #{inspectRouteId}</if>
            <if test="deviceAmount != null "> and device_amount = #{deviceAmount}</if>
            <if test="planTime != null "> and plan_time = #{planTime}</if>
            <if test="realBeginTime != null "> and   #{realBeginTime}>=real_begin_time</if>
            <if test="realEndTime != null "> and real_end_time >= #{realEndTime}</if>
            <if test="performer != null  and performer != ''"> and performer = #{performer}</if>
            <if test="inspectStatus != null "> and inspect_status = #{inspectStatus}</if>
            <if test="inspectDuration != null "> and inspect_duration = #{inspectDuration}</if>
            <if test="isFlag != null  and isFlag != ''"> and is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectDmsRecordInspectByRecordInspectId" parameterType="Long" resultMap="DmsRecordInspectResult">
        <include refid="selectDmsRecordInspectVo"/>
        where record_inspect_id = #{recordInspectId}
    </select>

    <insert id="insertDmsRecordInspect" parameterType="DmsRecordInspect" useGeneratedKeys="true" keyProperty="recordInspectId">
        insert into dms_record_inspect
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="billsInspectCode != null">bills_inspect_code,</if>
            <if test="inspectType != null and inspectType != ''">inspect_type,</if>
            <if test="inspectRouteId != null">inspect_route_id,</if>
            <if test="deviceAmount != null">device_amount,</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="performer != null">performer,</if>
            <if test="inspectStatus != null">inspect_status,</if>
            <if test="inspectDuration != null">inspect_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="billsInspectCode != null">#{billsInspectCode},</if>
            <if test="inspectType != null and inspectType != ''">#{inspectType},</if>
            <if test="inspectRouteId != null">#{inspectRouteId},</if>
            <if test="deviceAmount != null">#{deviceAmount},</if>
            <if test="planTime != null">#{planTime},</if>
            <if test="realBeginTime != null">#{realBeginTime},</if>
            <if test="realEndTime != null">#{realEndTime},</if>
            <if test="performer != null">#{performer},</if>
            <if test="inspectStatus != null">#{inspectStatus},</if>
            <if test="inspectDuration != null">#{inspectDuration},</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="updateDmsRecordInspect" parameterType="DmsRecordInspect">
        update dms_record_inspect
        <trim prefix="SET" suffixOverrides=",">
            <if test="billsInspectCode != null">bills_inspect_code = #{billsInspectCode},</if>
            <if test="inspectType != null and inspectType != ''">inspect_type = #{inspectType},</if>
            <if test="inspectRouteId != null">inspect_route_id = #{inspectRouteId},</if>
            <if test="deviceAmount != null">device_amount = #{deviceAmount},</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="performer != null">performer = #{performer},</if>
            <if test="inspectStatus != null">inspect_status = #{inspectStatus},</if>
            <if test="inspectDuration != null">inspect_duration = #{inspectDuration},</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_inspect_id = #{recordInspectId}
    </update>

    <delete id="deleteDmsRecordInspectByRecordInspectId" parameterType="Long">
        delete from dms_record_inspect where record_inspect_id = #{recordInspectId}
    </delete>

    <delete id="deleteDmsRecordInspectByRecordInspectIds" parameterType="String">
        delete from dms_record_inspect where record_inspect_id in
        <foreach item="recordInspectId" collection="array" open="(" separator="," close=")">
            #{recordInspectId}
        </foreach>
    </delete>
</mapper>
