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

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;

import cn.com.qmth.stmms.biz.report.model.ReportSubjectTeacherClass;

/**
 * 课程老师班级成绩分析 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);

}
