package com.ssj.dao.weixin.order.dao;

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 com.ssj.bean.weixin.order.domain.LessonServiceSales;

import java.util.List;

@Repository
public interface LessonServiceSalesDao extends JpaRepository<LessonServiceSales, String> {
	
	
	//通过kmt_course_id查询tb_lesson_service_sales
	@Query(nativeQuery = true, value = " SELECT * from tb_lesson_service_sales t where t.kmt_course_id=?1  ")
	public List<LessonServiceSales> findLessonServiceSalesByCourse(String courseId);
	
	
	//批量更新掉老师的teacher_pay_business_id
	@Query(nativeQuery = true, value = "update tb_lesson_service_sales set teacher_pay_business_id = ?1 , update_time=NOW()  where id in (?2) ")
	@Modifying
	public void updateTeacherPayBusinessIdByIds(String teacherPayBusinessId,List<String> ids);
	
	
	//批量更新掉图书馆的lib_pay_business_id
	@Query(nativeQuery = true, value = "update tb_lesson_service_sales set lib_pay_business_id = ?1 , update_time=NOW() where id in (?2) ")
	@Modifying
	public void updateLibPayBusinessIdIdByIds(String libPayBusinessId,List<String> ids);
	
	
	//批量更新掉sd的sd_pay_business_id
	@Query(nativeQuery = true, value = "update tb_lesson_service_sales set sd_pay_business_id = ?1 , update_time=NOW() where id in (?2) ")
	@Modifying
	public void updateSdPayBusinessIdIdByIds(String sdPayBusinessId,List<String> ids);

	@Query(nativeQuery = true, value = "select s.* from tb_lesson_service_sales s , tb_lib_join j " +
			"where s.lib_id = j.id " +
			"  and s.state = 1 " +
			"  and date(s.finish_time) between ?1 and ?2 " +
			"  and j.libtype in (2, 3)")
	List<LessonServiceSales> findListNeedCompute(String startTime, String endTime);
}
