<?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.ems.mapper.AdmOpInspectionTaskMapper">

    <resultMap type="com.ruoyi.ems.domain.AdmOpInspectionTask" id="AdmOpInspectionTaskResult">
        <result property="id" column="id"/>
        <result property="taskCode" column="task_code"/>
        <result property="taskName" column="task_name"/>
        <result property="taskType" column="task_type"/>
        <result property="taskStatus" column="task_status"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="executor" column="executor"/>
        <result property="objType" column="obj_type"/>
        <result property="objCode" column="obj_code"/>
        <result property="objName" column="obj_name"/>
    </resultMap>

    <sql id="selectAdmOpInspectionTaskVo">
        select id,
               task_code,
               task_name,
               task_type,
               task_status,
               start_time,
               end_time,
               executor,
               obj_type,
               obj_code,
               obj_name
        from adm_op_inspection_task
    </sql>

    <select id="selectAdmOpInspectionTaskList" parameterType="com.ruoyi.ems.domain.AdmOpInspectionTask"
            resultMap="AdmOpInspectionTaskResult">
        <include refid="selectAdmOpInspectionTaskVo"/>
        <where>
            <if test="taskCode != null  and taskCode != ''">and task_code = #{taskCode}</if>
            <if test="taskName != null  and taskName != ''">and task_name like concat('%', #{taskName}, '%')</if>
            <if test="taskType != null ">and task_type = #{taskType}</if>
            <if test="taskStatus != null ">and task_status = #{taskStatus}</if>
            <if test="executor != null  and executor != ''">and executor = #{executor}</if>
            <if test="objType != null ">and obj_type = #{objType}</if>
            <if test="objName != null  and objName != ''">and obj_name like concat('%', #{objName}, '%')</if>
        </where>
    </select>

    <select id="selectAdmOpInspectionTaskById" parameterType="Long" resultMap="AdmOpInspectionTaskResult">
        <include refid="selectAdmOpInspectionTaskVo"/>
        where id = #{id}
    </select>

    <insert id="insertAdmOpInspectionTask" parameterType="com.ruoyi.ems.domain.AdmOpInspectionTask"
            useGeneratedKeys="true" keyProperty="id">
        insert into adm_op_inspection_task
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskCode != null and taskCode != ''">task_code,</if>
            <if test="taskName != null and taskName != ''">task_name,</if>
            <if test="taskType != null">task_type,</if>
            <if test="taskStatus != null">task_status,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="executor != null">executor,</if>
            <if test="objType != null">obj_type,</if>
            <if test="objCode != null and objCode != ''">obj_code,</if>
            <if test="objName != null">obj_name,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskCode != null and taskCode != ''">#{taskCode},</if>
            <if test="taskName != null and taskName != ''">#{taskName},</if>
            <if test="taskType != null">#{taskType},</if>
            <if test="taskStatus != null">#{taskStatus},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="executor != null">#{executor},</if>
            <if test="objType != null">#{objType},</if>
            <if test="objCode != null and objCode != ''">#{objCode},</if>
            <if test="objName != null">#{objName},</if>
        </trim>
    </insert>

    <update id="updateAdmOpInspectionTask" parameterType="com.ruoyi.ems.domain.AdmOpInspectionTask">
        update adm_op_inspection_task
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskCode != null and taskCode != ''">task_code = #{taskCode},</if>
            <if test="taskName != null and taskName != ''">task_name = #{taskName},</if>
            <if test="taskType != null">task_type = #{taskType},</if>
            <if test="taskStatus != null">task_status = #{taskStatus},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="executor != null">executor = #{executor},</if>
            <if test="objType != null">obj_type = #{objType},</if>
            <if test="objCode != null and objCode != ''">obj_code = #{objCode},</if>
            <if test="objName != null">obj_name = #{objName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAdmOpInspectionTaskById" parameterType="Long">
        delete
        from adm_op_inspection_task
        where id = #{id}
    </delete>

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