<?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.FtbCultivateChapterTestMapper">
  <resultMap id="chapterTestInfo" type="jnpf.model.cultivate.vo.chapter.FtbCultivateChapterTestResultVO">
    <id column="chapterTestId" property="chapterTestId" jdbcType="VARCHAR"  javaType="java.lang.String"/>
    <result column="topicName" property="topicName" jdbcType="VARCHAR"  javaType="java.lang.String" />
    <result column="answerAnalysis" property="answerAnalysis" jdbcType="VARCHAR"  javaType="java.lang.String" />
    <result column="courseId" property="courseId" jdbcType="VARCHAR"  javaType="java.lang.String" />
    <collection select="getChapterTestResult"  property="chapterTestInfos" column="chapterTestId" ofType="java.util.ArrayList"/>
  </resultMap>
  <!--根据关键词获取章节测试统计信息-->
  <select id="getChapterTestStatistic"
          resultType="jnpf.model.cultivate.vo.chapter.FtbCultivateChapterTestStatisticVO">
    SELECT
    te.F_UserId as userId,
    res.F_RealName as userName,
    co.F_Name as courseName,
    co.F_Id as courseId,
    res.F_SystemWorkerId as systemWorkId,
    te.F_ChapterTestOptions as chapterTestOptions
    FROM
    ftb_cultivate_chapter_test_result AS te
    INNER JOIN ftb_cultivate_course as co ON te.F_CourseId = co.F_Id
    LEFT JOIN base_user as res ON te.F_UserId = res.F_Id
    <where>
      co.F_EnabledMark = 0 and te.F_EnabledMark = 0
      <if test="keyWords != null and keyWords != ''">
        AND (
        res.F_RealName LIKE concat( '%', #{keyWords}, '%' )
        OR res.F_SystemWorkerId LIKE concat( '%', #{keyWords}, '%' )
        OR co.F_Name LIKE concat( '%', #{keyWords}, '%' )
        )
      </if>

    <if test="innerPowerUserIds != null and innerPowerUserIds.size() > 0">
      AND te.F_UserId IN
      <foreach collection="innerPowerUserIds" item="userId" open="("  separator="," close=")" >
        #{userId}
      </foreach>
    </if>
    </where>
    GROUP BY
    te.F_UserId,
    te.F_CourseId
  </select>
  <!--根据课程ID列表获取章节测试信息-->
  <select id="getChapterTestInfos" resultMap="chapterTestInfo">
    SELECT DISTINCT
      te.F_Id as chapterTestId ,
      te.F_CourseId as courseId,
      te.F_TopicName as topicName,
      te.F_AnswerAnalysis as answerAnalysis
    FROM
      ftb_cultivate_chapter_test AS te
        JOIN ftb_cultivate_chapter_test_option AS op ON te.F_Id = op.F_ChapterTestId
    WHERE
    te.F_EnabledMark = 0
    and te.F_CourseId IN
    <foreach collection="courseIds"  item="courseId" open="("  separator="," close=")" >
      #{courseId}
    </foreach>
  </select>
  <!--根据课程ID列表获取章节返回-->
  <select id="getChapterTestResult"
          resultType="jnpf.model.cultivate.vo.chapter.FtbCultivateChapterTestInfo">
    select
    F_IsRightOption isRightOption ,
    F_Content as content,
    F_SortCode sortCode
    from
      ftb_cultivate_chapter_test_option where F_ChapterTestId=#{chapterTestId}
  </select>
</mapper>