<?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.FtbCultivateLearnTaskAssignmentMapper">
    <!--批量查询统计任务的学习人数-->
    <select id="groupCountNum" resultType="jnpf.model.cultivate.dto.learn.BatchCommonCountDto">
        SELECT
        F_TaskId selectKey,
        COUNT(*) num
        FROM
        ftb_cultivate_learn_task_assignment
        WHERE
        F_EnableMark = 0
        AND F_TaskId IN
        <foreach collection="taskIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>

        <if test="status == 1">
            and F_StudyStats = 2
        </if>
        GROUP BY F_TaskId
    </select>
    <!--查询任务学习人员列表-->
    <select id="groupListAssignment"
            resultType="jnpf.model.cultivate.po.learn.FtbCultivateLearnTaskAssignment">
        select F_Id as id,F_TaskId as taskId,F_UserId as userId,F_StudyStats as studyStats,F_IssuedCertificate as issuedCertificate from ftb_cultivate_learn_task_assignment where   F_EnableMark = 0
        AND F_TaskId IN
        <foreach collection="taskIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>

    </select>
    <select id="storeMyTaskList" resultType="jnpf.model.cultivate.dto.storestatistics.dto.StoreCultivateTaskDto">
        select a.F_Id as id,t.F_TaskName as taskName,t.F_TaskType as taskType ,t.F_TimeLimitStartTime as timeLimitStartTime,t.F_TimeLimitEndTime as timeLimitEndTime,t.F_Status as status,
               t.F_Id as taskId,a.F_StudyStats as studyStats,a.F_LearningStartTime as learningStartTime,a.F_LearningEndTime as learningEndTime,t.F_CreatorTime as createTime,a.F_LastModifyTime as lastModifyTime
        from ftb_cultivate_learn_task t join ftb_cultivate_learn_task_assignment as a on t.F_Id = a.F_TaskId
                                                               where a.F_EnableMark=0 and t.F_EnableMark=0 and a.F_UserId=#{userId} and t.F_Status >0


    </select>
    <select id="queryTaskNum" resultType="java.lang.Long">
        select count(*) from  ftb_cultivate_learn_task_assignment a
                                                               where a.F_EnableMark=0 and a.F_UserId= #{userId}
        <if test="type == 1">
            and a.F_StudyStats = 1
        </if>
        <if test="type == 2">
            and a.F_StudyStats = 2
        </if>
    </select>


    <insert id="insertBatch" parameterType="java.util.List">
        INSERT INTO ftb_cultivate_learn_task_assignment (
       task_id, user_id, study_stats, creator_time, creator_user_id, last_modify_time, last_modify_user_id, enable_mark
        )
        VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.taskId}, #{item.userId}, #{item.studyStats},
            #{item.creatorTime}, #{item.creatorUserId}, #{item.lastModifyTime},
            #{item.lastModifyUserId}, #{item.enableMark}
            )
        </foreach>
    </insert>



    <!--查看任务详情列表-->
    <select id="queryTaskUserListForManagerApp" resultType="jnpf.model.cultivate.v2.task.vo.V2CultivateTaskFinishUserListVo">
        SELECT
        F_Id id,
        F_TaskId taskId,
        F_UserId userId,
        F_StudyStats completionStatus,
        F_LearningStartTime taskStartTime,
        F_LearningEndTime taskEndTime
        FROM
        ftb_cultivate_learn_task_assignment
        <where>
            F_TaskId = #{taskId}
            and F_EnableMark = 0
        </where>
    </select>
</mapper>