<?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.project.task.mapper.TTaskInspectionMapper">

    <resultMap type="TTaskInspection" id="TTaskInspectionResult">
        <result property="id"    column="id"    />
        <result property="plantId"    column="plant_id"    />
        <result property="plantName"    column="plant_name"    />
        <result property="planId"    column="plan_id"    />
        <result property="planName"    column="inspection_plan_name"    />
        <result property="taskName"    column="task_name"    />
        <result property="taskCode"    column="task_code"    />
        <result property="taskType"    column="task_type"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="recipient"    column="recipient"    />
        <result property="taskNum"    column="task_num"    />
        <result property="taskDoneNum"    column="task_done_num"    />
        <result property="taskUndoneNum"    column="task_undone_num"    />
        <result property="status"    column="status"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptId"    column="dept_id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
    </resultMap>

    <sql id="selectTTaskInspectionVo">
        select id, plant_id, plan_id, task_name, task_code, task_type, start_time, end_time, recipient, task_num, task_done_num, task_undone_num, status, remarks, dept_id, del_flag, creater_code, createdate, updater_code, updatedate from t_task_inspection
    </sql>

    <select id="selectTTaskInspectionList" parameterType="TTaskInspection" resultMap="TTaskInspectionResult">
        select d.*,ip.inspection_plan_name,bp.plant_name from t_task_inspection d
        left join t_task_inspection_plan ip on d.plan_id=ip.id
        left join t_base_plant bp on d.plant_id=bp.plant_id
        <where>
            <if test="plantId != null "> and d.plant_id = #{plantId}</if>
            <if test="planId != null "> and d.plan_id = #{planId}</if>
            <if test="taskName != null  and taskName != ''"> and task_name like concat('%', #{taskName}, '%')</if>
            <if test="taskCode != null  and taskCode != ''"> and task_code = #{taskCode}</if>
            <if test="taskType != null  and taskType != ''"> and task_type = #{taskType}</if>
            <if test="startTime != null "> and d.start_time = #{startTime}</if>
            <if test="endTime != null "> and d.end_time = #{endTime}</if>
            <if test="recipient != null "> and recipient = #{recipient}</if>
            <if test="taskNum != null  and taskNum != ''"> and task_num = #{taskNum}</if>
            <if test="taskDoneNum != null  and taskDoneNum != ''"> and task_done_num = #{taskDoneNum}</if>
            <if test="taskUndoneNum != null  and taskUndoneNum != ''"> and task_undone_num = #{taskUndoneNum}</if>
            <if test="status != null  and status != ''"> and d.`status` = #{status}</if>
            <if test="remarks != null  and remarks != ''"> and d.remarks = #{remarks}</if>
            <if test="deptId != null "> and d.dept_id = #{deptId}</if>
            <if test="createrCode != null "> and d.creater_code = #{createrCode}</if>
            <if test="createdate != null "> and d.createdate = #{createdate}</if>
            <if test="updaterCode != null "> and d.updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and d.updatedate = #{updatedate}</if>
        and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScopePlant}
    </select>

    <select id="selectTTaskInspectionById" parameterType="Long" resultMap="TTaskInspectionResult">
        <include refid="selectTTaskInspectionVo"/>
        where id = #{id}
    </select>

    <insert id="insertTTaskInspection" parameterType="TTaskInspection" useGeneratedKeys="true" keyProperty="id">
        insert into t_task_inspection
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="plantId != null">plant_id,</if>
            <if test="planId != null">plan_id,</if>
            <if test="taskName != null">task_name,</if>
            <if test="taskCode != null">task_code,</if>
            <if test="taskType != null">task_type,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="recipient != null">recipient,</if>
            <if test="taskNum != null">task_num,</if>
            <if test="taskDoneNum != null">task_done_num,</if>
            <if test="taskUndoneNum != null">task_undone_num,</if>
            <if test="status != null">`status`,</if>
            <if test="remarks != null">remarks,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="plantId != null">#{plantId},</if>
            <if test="planId != null">#{planId},</if>
            <if test="taskName != null">#{taskName},</if>
            <if test="taskCode != null">#{taskCode},</if>
            <if test="taskType != null">#{taskType},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="recipient != null">#{recipient},</if>
            <if test="taskNum != null">#{taskNum},</if>
            <if test="taskDoneNum != null">#{taskDoneNum},</if>
            <if test="taskUndoneNum != null">#{taskUndoneNum},</if>
            <if test="status != null">#{status},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
         </trim>
    </insert>

    <update id="updateTTaskInspection" parameterType="TTaskInspection">
        update t_task_inspection
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantId != null">plant_id = #{plantId},</if>
            <if test="planId != null">plan_id = #{planId},</if>
            <if test="taskName != null">task_name = #{taskName},</if>
            <if test="taskCode != null">task_code = #{taskCode},</if>
            <if test="taskType != null">task_type = #{taskType},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="recipient != null">recipient = #{recipient},</if>
            <if test="taskNum != null">task_num = #{taskNum},</if>
            <if test="taskDoneNum != null">task_done_num = #{taskDoneNum},</if>
            <if test="taskUndoneNum != null">task_undone_num = #{taskUndoneNum},</if>
            <if test="status != null">`status` = #{status},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateTTaskInspectionByIds" parameterType="String">
        update t_task_inspection set `status`=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteTTaskInspectionById" parameterType="Long">
        update t_task_inspection set del_flag=1 where id = #{id}
    </delete>

    <delete id="deleteTTaskInspectionByIds" parameterType="String">
        update t_task_inspection set del_flag=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
