package cn.com.qmth.stmms.biz.report.dao;

import cn.com.qmth.stmms.biz.report.model.ReportSubjectTeacherClass;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

/**
 * 课程总评机组成绩分析 Dao
 *
 * @author xuwenjin
 * @date 2019-04-17
 */
public interface ReportSubjectTeacherClassDao extends PagingAndSortingRepository<ReportSubjectTeacherClass, Integer>,
        JpaSpecificationExecutor<ReportSubjectTeacherClass> {

    @Modifying
    @Query("delete from ReportSubjectTeacherClass r where r.examId=?1 ")
    void deleteByExamId(Integer exmaId);

    @Modifying
    @Query("update ReportSubjectTeacherClass r set r.relativeAvgScore = (r.avgScore - (select s.avgScore from ReportSubject s where s.subjectCode = r.subjectCode and s.examId = r.examId )) where r.examId=?1  ")
    void updateRelativeAvgScore(Integer examId);

    @Modifying
    @Query("delete from ReportSubjectTeacherClass r where r.examId=?1 and r.subjectCode=?2")
    void deleteByExamIdAndSubjectCode(Integer examId, String subjectCode);
}
