<?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.testor.module.hazard.dao.THazardWorkPlanMonitoringRecordDao">
    <!-- 开启二级缓存 -->
    <!-- <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> -->

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.testor.module.hazard.model.domain.THazardWorkPlanMonitoringRecord">
        <id column="id" property="id"/>
        <result column="plan_id" property="planId"/>
        <result column="detection_position" property="detectionPosition"/>
        <result column="conclusion" property="conclusion"/>
        <result column="scene_photo" property="scenePhoto"/>
        <result column="status" property="status"/>
        <result column="inspector_signature" property="inspectorSignature"/>
        <result column="inspector_time" property="inspectorTime"/>

        <!-- 继承父类的字段 -->
        <result column="create_by" property="createBy"/>
        <result column="create_date" property="createDate"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_date" property="updateDate"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, plan_id, detection_position, conclusion, scene_photo, status,
        inspector_signature, inspector_time, create_by, create_date, update_by,
        update_date
    </sql>

    <!-- 查询待办列表 -->
    <select id="selectToDoList" resultType="com.tongtech.tfw.workflow.apis.task.model.dto.TodoTask">
        SELECT
            t.id as taskId,
            t.name as taskName,
            t.proc_inst_id as processInstanceId,
            t.proc_def_id as processDefinitionId,
            t.create_time as createTime,
            t.assignee as assignee,
            i.business_key as businessKey
        FROM act_ru_task t
                 LEFT JOIN act_ru_execution i ON t.proc_inst_id_ = i.id_
        WHERE t.assignee_ = #{todo.userId}
        ORDER BY t.create_time_ DESC
    </select>

    <!-- 根据计划ID查询监测记录 -->
    <select id="selectByPlanId" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_hazard_work_plan_monitoring_record
        WHERE plan_id = #{planId}
        ORDER BY create_date DESC
    </select>

    <!-- 根据计划ID列表查询监测记录 -->
    <select id="selectByPlanIds" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_hazard_work_plan_monitoring_record
        WHERE plan_id IN
        <foreach collection="planIds" item="planId" open="(" separator="," close=")">
            #{planId}
        </foreach>
        ORDER BY create_date DESC
    </select>

    <!-- 批量插入监测记录 -->
    <insert id="insertBatch">
        INSERT INTO t_hazard_work_plan_monitoring_record (
        id, plan_id, detection_position, conclusion, scene_photo, status,
        inspector_signature, inspector_time, create_by, create_date, update_by, update_date
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.id}, #{item.planId}, #{item.detectionPosition}, #{item.conclusion},
            #{item.scenePhoto}, #{item.status}, #{item.inspectorSignature},
            #{item.inspectorTime}, #{item.createBy}, #{item.createDate},
            #{item.updateBy}, #{item.updateDate}
            )
        </foreach>
    </insert>
</mapper>