package com.xjrsoft.module.assessment.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.xjrsoft.module.assessment.dto.AssessmentTemplatePlanSureDto;
import com.xjrsoft.module.assessment.entity.AssessmentPlanAnswerStudent;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
* @title: 考核计划答题参与学生
* @Author dzx
* @Date: 2024-04-01
* @Version 1.0
*/
@Mapper
public interface AssessmentPlanAnswerStudentMapper extends MPJBaseMapper<AssessmentPlanAnswerStudent> {

    @Update("update assessment_plan_answer_student set delete_mark = 1,modify_date = now(),modify_user_id = #{loginId} WHERE assessment_template_plan_id = #{planId}")
    Boolean deleteByPlanId(Long planId, Long loginId);

    @Update("UPDATE assessment_plan_answer_student t1 " +
            " LEFT JOIN base_student_school_roll t2 ON t1.student_user_id = t2.user_id" +
            " LEFT JOIN base_class t3 ON t2.class_id = t3.id" +
            " SET t1.is_confirm = 1,t1.modify_date = NOW(),t1.modify_user_id = #{loginId}" +
            " WHERE t1.assessment_template_plan_id = #{dto.id} and t3.teacher_id = #{loginId}" +
            " AND t3.id = #{dto.classId}")
    Boolean sure(AssessmentTemplatePlanSureDto dto, Long loginId);


    @Update("UPDATE assessment_plan_answer_student set submit_status = 1,modify_date = NOW() where assessment_template_plan_id = #{id} and student_user_id = #{loginId}")
    Boolean submitAnswer(Long id, Long loginId);

    @Select("SELECT COUNT(*) FROM assessment_plan_answer_student WHERE delete_mark = 0 AND assessment_template_plan_id = #{id}")
    Integer getStudentCount(Long id);

    @Select("SELECT submit_status FROM assessment_plan_answer_student WHERE delete_mark = 0 AND assessment_template_plan_id = #{id} and student_user_id = #{loginId}")
    Integer getSubmitStatus(Long id, Long loginId);
}
