package com.example.system.mapper;

import com.example.system.model.RegistrationTable;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import javax.persistence.criteria.CriteriaBuilder;
import java.util.List;

@Mapper
public interface RegistrationMapper {
    //插入信息
    @Insert("insert into registration_table" +
            "(student_id, competition_id, team_leader_id, competition_type, registration_time, registration_status) values " +
            "(#{studentId}, #{competitionId}, #{teamLeaderId}, #{competitionType}, #{registrationTime}, #{registrationStatus})")
    Integer creatData(RegistrationTable registration);

    //获取所有报名信息
    @Select("select * from registration_table")
    List<RegistrationTable> getRegistration();

    //修改报名审核状态
    @Update("update registration_table set registration_status= #{status} where registration_id=#{registrationId};")
    Integer updateStatus(Long registrationId, String status);
    //修改获奖等级和证书路径和附加信息
    @Update("update registration_table set " +
            "award_level = #{awardLevel}, " +
            "certificate_path = #{certificatePath},"+
            "additional_info = #{additionalInfo}"+
            "where registration_id=#{registrationId};")
    Integer update(RegistrationTable table);

    //获取获奖人员的参赛记录
    @Select("SELECT * FROM registration_table WHERE award_level IS NOT NULL;")
    List<RegistrationTable> getWinInfo();
    //获取参赛总人数
    @Select("SELECT COUNT(registration_id) FROM registration_table;")
    Integer getCount();

    //获取成功报名并获奖的总人数
    @Select("SELECT COUNT(registration_id) FROM registration_table WHERE award_level IS NOT NULL AND registration_status = '成功报名';")
    Object getWinCount();
    //根据参赛类型获取参赛人数
    @Select("SELECT * FROM registration_table WHERE competition_id=(SELECT competition_id FROM competition_table WHERE competition_name=#{competitionType});")
    Object getCountByCompetitionType(String competitionType);
    //根据获奖等级获取参赛人数
    @Select("SELECT COUNT(*) FROM registration_table WHERE award_level=#{level};")
    Object getCountByLevel(String level);
}
