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

import cn.com.qmth.stmms.biz.report.model.ReportSubjectTeacher;
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-16
 */
public interface ReportSubjectTeacherDao extends PagingAndSortingRepository<ReportSubjectTeacher, Integer>,
        JpaSpecificationExecutor<ReportSubjectTeacher> {

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

    @Modifying
    @Query("update ReportSubjectTeacher 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 ReportSubjectTeacher r where r.examId=?1 and r.subjectCode=?2")
    void deleteByExamIdAndSubjectCode(Integer examId, String subjectCode);
}
