<?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="jnpf.cultivate.mapper.FtbCultivateLearnTaskIdentificationMapper">

    <!--根据任务id查询关联的认证信息-->
    <select id="queryIdentificationName" resultType="jnpf.model.cultivate.resp.TaskRelationIdentificationVo">
        SELECT
        t.F_TaskId AS taskId,
        t.F_IdentificationId AS identificationId,
        tbl.F_Name AS identificationName,
        tbl.F_Id as tableId
        FROM
        ftb_cultivate_learn_task_identification AS t
        JOIN ftb_cultivate_identify_table AS tbl ON t.F_IdentificationId = tbl.F_Id
        WHERE
        t.F_EnableMark =0
        AND t.F_TaskId IN
        <foreach collection="taskIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <!--更加任务id查询鉴定信息-->
    <select id="queryByTaskId" resultType="jnpf.model.cultivate.po.learn.FtbCultivateLearnTaskIdentification">
        SELECT
            F_Id as id,
            F_TaskId AS taskId,
            F_IsPassComplete as isPassComplete,
            F_IdentificationId AS identificationId,
            F_IdentificationRule as identificationRule
        FROM
        ftb_cultivate_learn_task_identification
        WHERE
        F_TaskId = #{taskId} AND F_EnableMark = 0
    </select>


    <insert id="insertBatch" parameterType="java.util.List">
        INSERT INTO ftb_cultivate_learn_task_identification (
      F_Id,F_TaskId, F_IdentificationId, F_PhaseId,
        F_CreatorTime, F_CreatorUserId, F_LastModifyTime, F_LastModifyUserId
        )
        VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.id},#{item.taskId}, #{item.identificationId}, #{item.phaseId},
            #{item.creatorTime}, #{item.creatorUserId}, #{item.lastModifyTime},
            #{item.lastModifyUserId}
            )
        </foreach>
    </insert>

    <!--根据任务 id 查询关联的鉴定表信息（联表查询）-->
    <select id="listByTaskId" resultType="jnpf.model.cultivate.v2.task.vo.FtbCultivateLearnTaskIdentificationVo">
        SELECT t.F_Id                 as id,
               t.F_TaskId             AS taskId,
               t.F_IdentificationId   AS identificationId,
               t.F_IdentificationRule as identificationRule,
               t.F_EnableMark         as enableMark,
               t.F_IsPassComplete     as isPassComplete,
               t.F_PhaseId            as phaseId,
               tbl.F_Name              AS identificationName
        FROM ftb_cultivate_learn_task_identification AS t
                 INNER JOIN
             ftb_cultivate_identify_table AS tbl ON t.F_IdentificationId = tbl.F_Id
        WHERE t.F_TaskId = #{taskId}
          AND t.F_EnableMark = 0
          and tbl.F_IsAbnormal = 0
          and tbl.F_DeleteMark = 0
    </select>

    <!--根据任务ID和阶段ID查询关联的鉴定表信息（联表查询）-->
    <select id="listByTaskIdAndPhaseId" resultType="jnpf.model.cultivate.v2.task.vo.FtbCultivateLearnTaskIdentificationVo">
        SELECT t.F_Id                 as id,
               t.F_TaskId             AS taskId,
               t.F_IdentificationId   AS identificationId,
               t.F_IdentificationRule as identificationRule,
               t.F_EnableMark         as enableMark,
               t.F_IsPassComplete     as isPassComplete,
               t.F_PhaseId            as phaseId,
               tbl.F_Name              AS identificationName,
               tbl.F_LastModifyTime   AS lastModifyTime,
               tbl.F_CreatorTime       AS creatorTime
        FROM ftb_cultivate_learn_task_identification AS t
                 INNER JOIN
             ftb_cultivate_identify_table AS tbl ON t.F_IdentificationId = tbl.F_Id
        WHERE t.F_TaskId = #{taskId}
          AND t.F_PhaseId = #{phaseId}
          AND t.F_EnableMark = 0
          and tbl.F_IsAbnormal = 0
          and tbl.F_DeleteMark = 0
    </select>

</mapper>