<?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.InspectionRecordMapper">
    
    <resultMap type="InspectionRecord" id="InspectionRecordResult">
        <result property="id"    column="id"    />
        <result property="planId"    column="plan_id"    />
        <result property="planName"    column="plan_name"    />
        <result property="planContent"    column="plan_content"    />
        <result property="projectName"    column="project_name"    />
        <result property="planTime"    column="plan_time"    />
        <result property="inspectionTime"    column="inspection_time"    />
        <result property="inspectionPerson"    column="inspection_person"    />
        <result property="userId"    column="user_id"    />
        <result property="inspectionCycle"    column="inspection_cycle"    />
        <result property="cycle"    column="cycle"    />
        <result property="inspectionStatus"    column="inspection_status"    />
        <result property="inspectionRemark"    column="inspection_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="selectInspectionRecordVo">
        select id, plan_id, plan_name, plan_content, project_name, plan_time, inspection_time, inspection_person, user_id, inspection_cycle, cycle, inspection_status, inspection_remark, create_by, create_time, update_by, update_time from inspection_record
    </sql>

    <select id="selectInspectionRecordList" parameterType="InspectionRecord" resultMap="InspectionRecordResult">
        <include refid="selectInspectionRecordVo"/>
        <where>  
            <if test="planId != null "> and plan_id = #{planId}</if>
            <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="planTime != null "> and plan_time = #{planTime}</if>
            <if test="inspectionTime != null "> and inspection_time = #{inspectionTime}</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="inspectionCycle != null  and inspectionCycle != ''"> and inspection_cycle = #{inspectionCycle}</if>
            <if test="cycle != null  and cycle != ''"> and cycle = #{cycle}</if>
            <if test="inspectionStatus != null  and inspectionStatus != ''"> and inspection_status = #{inspectionStatus}</if>
            <if test="inspectionRemark != null  and inspectionRemark != ''"> and inspection_remark = #{inspectionRemark}</if>
        </where>
    </select>
    
    <select id="selectInspectionRecordById" parameterType="Long" resultMap="InspectionRecordResult">
        <include refid="selectInspectionRecordVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertInspectionRecord" parameterType="InspectionRecord">
        insert into inspection_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="planId != null">plan_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="planTime != null">plan_time,</if>
            <if test="inspectionTime != null">inspection_time,</if>
            <if test="inspectionPerson != null">inspection_person,</if>
            <if test="userId != null">user_id,</if>
            <if test="inspectionCycle != null">inspection_cycle,</if>
            <if test="cycle != null">cycle,</if>
            <if test="inspectionStatus != null">inspection_status,</if>
            <if test="inspectionRemark != null">inspection_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="id != null">#{id},</if>
            <if test="planId != null">#{planId},</if>
            <if test="planName != null">#{planName},</if>
            <if test="planContent != null">#{planContent},</if>
            <if test="projectName != null">#{projectName},</if>
            <if test="planTime != null">#{planTime},</if>
            <if test="inspectionTime != null">#{inspectionTime},</if>
            <if test="inspectionPerson != null">#{inspectionPerson},</if>
            <if test="userId != null">#{userId},</if>
            <if test="inspectionCycle != null">#{inspectionCycle},</if>
            <if test="cycle != null">#{cycle},</if>
            <if test="inspectionStatus != null">#{inspectionStatus},</if>
            <if test="inspectionRemark != null">#{inspectionRemark},</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="updateInspectionRecord" parameterType="InspectionRecord">
        update inspection_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="planId != null">plan_id = #{planId},</if>
            <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="planTime != null">plan_time = #{planTime},</if>
            <if test="inspectionTime != null">inspection_time = #{inspectionTime},</if>
            <if test="inspectionPerson != null">inspection_person = #{inspectionPerson},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="inspectionCycle != null">inspection_cycle = #{inspectionCycle},</if>
            <if test="cycle != null">cycle = #{cycle},</if>
            <if test="inspectionStatus != null">inspection_status = #{inspectionStatus},</if>
            <if test="inspectionRemark != null">inspection_remark = #{inspectionRemark},</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="deleteInspectionRecordById" parameterType="Long">
        delete from inspection_record where id = #{id}
    </delete>

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