<?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.ruoyi.manage.mapper.RecordInspectionTaskMapper">
    
    <resultMap type="RecordInspectionTask" id="RecordInspectionTaskResult">
        <result property="objid"    column="objid"    />
        <result property="inspectionId"    column="inspection_id"    />
        <result property="areaId"    column="area_id"    />
        <result property="areaName"    column="area_name"    />
        <result property="planePosition"    column="plane_position"    />
        <result property="taskState"    column="task_state"    />
    </resultMap>

    <sql id="selectRecordInspectionTaskVo">
        select objid, inspection_id, area_id, area_name, plane_position, task_state from record_inspection_task
    </sql>

    <select id="selectRecordInspectionTaskList" parameterType="RecordInspectionTask" resultMap="RecordInspectionTaskResult">
        <include refid="selectRecordInspectionTaskVo"/>
        <where>  
            <if test="inspectionId != null "> and inspection_id = #{inspectionId}</if>
            <if test="areaName != null  and areaName != ''"> and area_name like concat('%', #{areaName}, '%')</if>
            <if test="planePosition != null  and planePosition != ''"> and plane_position = #{planePosition}</if>
            <if test="taskState != null  and taskState != ''"> and task_state = #{taskState}</if>
        </where>
    </select>
    
    <select id="selectRecordInspectionTaskByObjid" parameterType="Long" resultMap="RecordInspectionTaskResult">
        <include refid="selectRecordInspectionTaskVo"/>
        where objid = #{objid}
    </select>
        
    <insert id="insertRecordInspectionTask" parameterType="RecordInspectionTask" useGeneratedKeys="true" keyProperty="objid">
        insert into record_inspection_task
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inspectionId != null">inspection_id,</if>
            <if test="areaId != null">area_id,</if>
            <if test="areaName != null">area_name,</if>
            <if test="planePosition != null">plane_position,</if>
            <if test="taskState != null">task_state,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="inspectionId != null">#{inspectionId},</if>
            <if test="areaId != null">#{areaId},</if>
            <if test="areaName != null">#{areaName},</if>
            <if test="planePosition != null">#{planePosition},</if>
            <if test="taskState != null">#{taskState},</if>
         </trim>
    </insert>

    <update id="updateRecordInspectionTask" parameterType="RecordInspectionTask">
        update record_inspection_task
        <trim prefix="SET" suffixOverrides=",">
            <if test="inspectionId != null">inspection_id = #{inspectionId},</if>
            <if test="areaId != null">area_id = #{areaId},</if>
            <if test="areaName != null">area_name = #{areaName},</if>
            <if test="planePosition != null">plane_position = #{planePosition},</if>
            <if test="taskState != null">task_state = #{taskState},</if>
        </trim>
        where objid = #{objid}
    </update>

    <delete id="deleteRecordInspectionTaskByObjid" parameterType="Long">
        delete from record_inspection_task where objid = #{objid}
    </delete>

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

</mapper>