<?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.xinda.itsm.mapper.InspectionPlanMapper">
    
    <resultMap type="InspectionPlan" id="InspectionPlanResult">
        <result property="id"    column="id"    />
        <result property="planName"    column="plan_name"    />
        <result property="planContent"    column="plan_content"    />
        <result property="projectName"    column="project_name"    />
        <result property="startDate"    column="start_date"    />
        <result property="endDate"    column="end_date"    />
        <result property="inspectionCycle"    column="inspection_cycle"    />
        <result property="inspectionPerson"    column="inspection_person"    />
        <result property="userId"    column="user_id"    />
        <result property="setDate"    column="set_date"    />
        <result property="setTime"    column="set_time"    />
        <result property="status"    column="status"    />
        <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="selectInspectionPlanVo">
        select id, plan_name, plan_content, project_name, start_date, end_date, inspection_cycle, inspection_person, user_id, set_date, set_time, status, create_by, create_time, update_by, update_time from inspection_plan
    </sql>

    <select id="selectInspectionPlanList" parameterType="InspectionPlan" resultMap="InspectionPlanResult">
        <include refid="selectInspectionPlanVo"/>
        <where>  
            <if test="planName != null  and planName != ''"> and plan_name like concat('%', #{planName}, '%')</if>
            <if test="planContent != null  and planContent != ''"> and plan_content = #{planContent}</if>
            <if test="projectName != null  and projectName != ''"> and project_name like concat('%', #{projectName}, '%')</if>
            <if test="startDate != null "> and start_date = #{startDate}</if>
            <if test="endDate != null "> and end_date = #{endDate}</if>
            <if test="inspectionCycle != null  and inspectionCycle != ''"> and inspection_cycle = #{inspectionCycle}</if>
            <if test="inspectionPerson != null  and inspectionPerson != ''"> and inspection_person = #{inspectionPerson}</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="setDate != null  and setDate != ''"> and set_date = #{setDate}</if>
            <if test="setTime != null  and setTime != ''"> and set_time = #{setTime}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectInspectionPlanById" parameterType="Long" resultMap="InspectionPlanResult">
        <include refid="selectInspectionPlanVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertInspectionPlan" parameterType="InspectionPlan">
        insert into inspection_plan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="planName != null">plan_name,</if>
            <if test="planContent != null">plan_content,</if>
            <if test="projectName != null">project_name,</if>
            <if test="startDate != null">start_date,</if>
            <if test="endDate != null">end_date,</if>
            <if test="inspectionCycle != null">inspection_cycle,</if>
            <if test="inspectionPerson != null">inspection_person,</if>
            <if test="userId != null">user_id,</if>
            <if test="setDate != null">set_date,</if>
            <if test="setTime != null">set_time,</if>
            <if test="status != null">status,</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="id != null">#{id},</if>
            <if test="planName != null">#{planName},</if>
            <if test="planContent != null">#{planContent},</if>
            <if test="projectName != null">#{projectName},</if>
            <if test="startDate != null">#{startDate},</if>
            <if test="endDate != null">#{endDate},</if>
            <if test="inspectionCycle != null">#{inspectionCycle},</if>
            <if test="inspectionPerson != null">#{inspectionPerson},</if>
            <if test="userId != null">#{userId},</if>
            <if test="setDate != null">#{setDate},</if>
            <if test="setTime != null">#{setTime},</if>
            <if test="status != null">#{status},</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="updateInspectionPlan" parameterType="InspectionPlan">
        update inspection_plan
        <trim prefix="SET" suffixOverrides=",">
            <if test="planName != null">plan_name = #{planName},</if>
            <if test="planContent != null">plan_content = #{planContent},</if>
            <if test="projectName != null">project_name = #{projectName},</if>
            <if test="startDate != null">start_date = #{startDate},</if>
            <if test="endDate != null">end_date = #{endDate},</if>
            <if test="inspectionCycle != null">inspection_cycle = #{inspectionCycle},</if>
            <if test="inspectionPerson != null">inspection_person = #{inspectionPerson},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="setDate != null">set_date = #{setDate},</if>
            <if test="setTime != null">set_time = #{setTime},</if>
            <if test="status != null">status = #{status},</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 id = #{id}
    </update>

    <delete id="deleteInspectionPlanById" parameterType="Long">
        delete from inspection_plan where id = #{id}
    </delete>

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