package com.ssj.dao.kmt.kmt.dao;

import java.util.List;

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.kmt.kmt.domain.KmtArrangeDetail;


@Repository
public interface KmtArrangeDetailDao extends JpaRepository<KmtArrangeDetail, String> {

	/**
	 * 按老师类型，科目,查询当月的日历列表
	 * @param type
	 * @param subject
	 * @return
	 */
	@Query(nativeQuery = true, value = " SELECT * from kmt_arrange_detail t WHERE DATE_FORMAT(t.arrange_date, '%Y%m' ) = DATE_FORMAT(CURDATE(), '%Y%m') AND t.type=?1 AND t.`subject`=?2 AND t.`status`=1 ORDER BY t.arrange_date ASC,t.start_interval asc LIMIT 200 ")
	List<KmtArrangeDetail> findKmtArrangeDetailByCurMonth(String type,String subject);

	/**
	 * 按老师类型，科目，月份,查询当月的日历列表
	 * @param type
	 * @param subject
	 * @return
	 */
	@Query(nativeQuery = true, value = " SELECT * from kmt_arrange_detail t WHERE DATE_FORMAT(t.arrange_date, '%Y%m' ) = DATE_FORMAT(?1, '%Y%m') AND t.type=?2 AND t.`subject`=?3 AND t.`status`=1 ORDER BY t.arrange_date ASC,t.start_interval asc  LIMIT 200")
	List<KmtArrangeDetail> findKmtArrangeDetailByMonth(String month,String type,String subject);
	
	/**
	 * 按月份,查询当月的日历列表,用于25号更新所有的日历数据
	 * @return
	 */
	@Query(nativeQuery = true, value = " SELECT * from kmt_arrange_detail t WHERE DATE_FORMAT(t.arrange_date, '%Y%m' ) = DATE_FORMAT(?1, '%Y%m') ORDER BY t.arrange_date ASC,t.start_interval asc LIMIT 800 ")
	List<KmtArrangeDetail> findKmtArrangeDetailByMonth(String month);
	
	/**
	 * 按id更新已选的总量
	 * @param id
	 * @param haveNum
	 * @return
	 */
	@Modifying
	@Query(nativeQuery = true, value = " update kmt_arrange_detail set have_num=?2 where id=?1 ")
	void updateKmtArrangeDetailToHaveNum(String id,Integer haveNum);

}
