package com.ssj.dao.weixin.zuoyb.dao;

import com.ssj.bean.weixin.zyb.domain.ZuoybStudentWorkHow;
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;


/** 
 * @author  ZhangCaibao 
 * @version 2017年11月1日 下午2:32:32 
 * 类说明 
 */
@Repository
public interface ZuoybStudentWorkHowDao extends JpaRepository<ZuoybStudentWorkHow, String>{
	
	@Query(nativeQuery = true, value = "delete from  zyb_student_work_how  where student_work_id = ?1 ")
    @Modifying
	public void deleteByStudentWorkId(String studentWorkId);
	
	
	@Query(nativeQuery = true, value = "SELECT \n" +
			"h.id,h.how_id,h.how_name,h.num,h.create_time,h.module,h.type, \n" +
			"k.course_name as student_work_id\n" +
			"  from  \n" +
			"zyb_student_work  k  JOIN \n" +
			"zyb_student_work_how  h  on k.id = h.student_work_id\n" +
			"where k.vip_id=?1 and k.stat = 3 \n" +
			"and TO_DAYS(k.scoring_time) >= TO_DAYS(?2) and TO_DAYS(k.scoring_time) <TO_DAYS(?3) \n" +
			"ORDER BY  k.num asc , k.scoring_time asc , h.num asc ")
	 public List<ZuoybStudentWorkHow> getStartAndEndWorkHow(String vipId,String start,String end);
	@Query(nativeQuery = true, value = "SELECT \n" +
			"h.id,h.how_id,h.how_name,h.num,h.create_time,h.module,h.type, \n" +
			"k.course_name as student_work_id\n" +
			"  from  \n" +
			"zyb_student_work  k  JOIN \n" +
			"zyb_student_work_how  h  on k.id = h.student_work_id\n" +
			"where k.vip_id=?1 and k.stat = 3 \n" +
			"and TO_DAYS(k.scoring_time) >= TO_DAYS(?2) and TO_DAYS(k.scoring_time) <=TO_DAYS(?3) and k.course_name=?4 \n" +
			"ORDER BY  k.num asc , k.scoring_time asc , h.num asc ")
	public List<ZuoybStudentWorkHow> getStartAndEndWorkHowAndCourse(String vipId,String start,String end,String course);

	@Query(nativeQuery = true, value = "select * from zyb_student_work_how where student_work_id = ?1 and how_id in (?2) and type=?3")
	public List<ZuoybStudentWorkHow> findByStudentWorkIdAndHowIdIn(String zybWorkId, List<String> howIds, int type);

	
}
