<?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.DmsPlanInspectMapper">
    
    <resultMap type="DmsPlanInspect" id="DmsPlanInspectResult">
        <result property="planInspectId"    column="plan_inspect_id"    />
        <result property="planInspectCode"    column="plan_inspect_code"    />
        <result property="planInspectName"    column="plan_inspect_name"    />
        <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="cyclePeriod"    column="cycle_period"    />
        <result property="performer"    column="performer"    />
        <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="selectDmsPlanInspectVo">
        select plan_inspect_id, plan_inspect_code, plan_inspect_name, inspect_type, inspect_route_id, device_amount, plan_time, cycle_period, performer, is_flag, remark, create_by, create_time, update_by, update_time from dms_plan_inspect
    </sql>

    <select id="selectDmsPlanInspectList" parameterType="DmsPlanInspect" resultMap="DmsPlanInspectResult">
        <include refid="selectDmsPlanInspectVo"/>
        <where>  
            <if test="planInspectCode != null  and planInspectCode != ''"> and plan_inspect_code = #{planInspectCode}</if>
            <if test="planInspectName != null  and planInspectName != ''"> and plan_inspect_name like concat('%', #{planInspectName}, '%')</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="cyclePeriod != null  and cyclePeriod != ''"> and cycle_period = #{cyclePeriod}</if>
            <if test="performer != null  and performer != ''"> and performer = #{performer}</if>
            <if test="isFlag != null  and isFlag != ''"> and is_flag = #{isFlag}</if>
        </where>
    </select>
    
    <select id="selectDmsPlanInspectByPlanInspectId" parameterType="Long" resultMap="DmsPlanInspectResult">
        <include refid="selectDmsPlanInspectVo"/>
        where plan_inspect_id = #{planInspectId}
    </select>
        
    <insert id="insertDmsPlanInspect" parameterType="DmsPlanInspect" useGeneratedKeys="true" keyProperty="planInspectId">
        insert into dms_plan_inspect
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="planInspectCode != null">plan_inspect_code,</if>
            <if test="planInspectName != null">plan_inspect_name,</if>
            <if test="inspectType != null">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="cyclePeriod != null">cycle_period,</if>
            <if test="performer != null">performer,</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="planInspectCode != null">#{planInspectCode},</if>
            <if test="planInspectName != null">#{planInspectName},</if>
            <if test="inspectType != null">#{inspectType},</if>
            <if test="inspectRouteId != null">#{inspectRouteId},</if>
            <if test="deviceAmount != null">#{deviceAmount},</if>
            <if test="planTime != null">#{planTime},</if>
            <if test="cyclePeriod != null">#{cyclePeriod},</if>
            <if test="performer != null">#{performer},</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="updateDmsPlanInspect" parameterType="DmsPlanInspect">
        update dms_plan_inspect
        <trim prefix="SET" suffixOverrides=",">
            <if test="planInspectCode != null">plan_inspect_code = #{planInspectCode},</if>
            <if test="planInspectName != null">plan_inspect_name = #{planInspectName},</if>
            <if test="inspectType != null">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="cyclePeriod != null">cycle_period = #{cyclePeriod},</if>
            <if test="performer != null">performer = #{performer},</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 plan_inspect_id = #{planInspectId}
    </update>

    <delete id="deleteDmsPlanInspectByPlanInspectId" parameterType="Long">
        delete from dms_plan_inspect where plan_inspect_id = #{planInspectId}
    </delete>

    <delete id="deleteDmsPlanInspectByPlanInspectIds" parameterType="String">
        delete from dms_plan_inspect where plan_inspect_id in 
        <foreach item="planInspectId" collection="array" open="(" separator="," close=")">
            #{planInspectId}
        </foreach>
    </delete>
</mapper>