package com.ssj.dao.sys.lesson.dao;


import com.ssj.bean.sys.lesson.domain.LessonServiceApply;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface LessonServiceApplyDao extends JpaRepository<LessonServiceApply, String> {

	@Query(nativeQuery=true,value="select * from tb_lesson_service_apply where kmt_course_id = ?1 and type=?2 and is_delete=0 and status = 0 ")
	LessonServiceApply findInfoByCourseId(String courseId, int type);
	
	@Query(nativeQuery = true, value = "update tb_lesson_service_apply set is_delete = 1 where `status` = 0 and date_add(create_time, interval 12 hour) < NOW()")
	@Modifying
	public void updateApplyInvalid();
	
	public LessonServiceApply findFirstByKmtCourseIdAndTypeAndIsDeleteOrderByCreateTimeDesc(String kmtCourseId,int type,int isDelete);
	
	@Query(nativeQuery = true, value = "select * from tb_lesson_service_apply where (kmt_course_id = ?1 or kmt_course_id = ?2) and `status` = 1 ORDER BY create_time desc limit 1")
	public LessonServiceApply findHistoryApplyByKmtCourseIdOrLessonServiceIdOrderByCreateTimeDesc(String kmtCourseId,String lessonServiceId);
	/**
	 * @param kmtCourseId
	 * @param type
	 * @param status
	 * @param isDelete
	 * @return
	
	 * 方法说明:查询换老师申请
	
	 * 创立日期:2018年8月7日 下午4:59:40
	 * 创建人:yangcan
	
	 */
	public LessonServiceApply findByKmtCourseIdAndTypeAndStatusAndIsDelete(String kmtCourseId,int type,int status,int isDelete);
	

	
	@Query(nativeQuery = true, value = "select kmt_course_id from tb_lesson_service_apply where type = 2 and is_delete = 0 and `status` = 0 "
			+ "and date_add(create_time, interval 10 hour) < NOW()")
	public List<String> findApplyTeacherInvalid();
	
}
