package com.ssj.dao.weixin.zuoyb.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.weixin.zyb.domain.ZuoybStudentWorkDetails;


/** 
 * @author  ZhangCaibao 
 * @version 2017年7月18日 上午10:31:59 
 * 类说明 
 */
@Repository
public interface ZuoybStudentWorkDetailsDao extends JpaRepository<ZuoybStudentWorkDetails, String>{
    /**
     * 查询当天已有的数据，
    * @param libId
    * @param vipId
    * @return
    * 创建人：ZhangCaibao 
    * 2017年7月19日 下午4:36:50 
    * @List<ZuoybStudentWorkDetails>
     */
	
	@Query(nativeQuery = true, value = "SELECT  s.* from   zyb_student_work_details  s LEFT JOIN \n" +
			"(SELECT id FROM zyb_student_work  WHERE  lib_id =?1\n" +
			"AND vip_id = ?2\n" +
			"AND TO_DAYS(scoring_time) = TO_DAYS(now())\n" +
			"AND type = 1 \n" +
			"ORDER BY  scoring_time DESC LIMIT 1\n" +
			") as  k  on k.id = s.student_work_id\n" +
			"where  k.id = s.student_work_id and s.num>100")
	public List<ZuoybStudentWorkDetails> getRecentByLibIdAndVipId(String libId,String vipId);
	
	@Query(nativeQuery = true, value = "delete from  zyb_student_work_details  where student_work_id = ?1  ")
	@Modifying
	public void deleteWorkDetalByStudentWorkId(String studentWorkId);

	public ZuoybStudentWorkDetails findByStudentWorkIdAndParentName(String workId, String title);

	/**
	 * 查询作业详情
	 * @param workId
	 * @param num
	 * @return
	 */
	@Query(nativeQuery = true, value = "select * from zyb_student_work_details where student_work_id=?1 and num = ?2 limit 1")
	public ZuoybStudentWorkDetails findByStudentWorkIdAndNum(String workId, int num);

	/**
	 * 查询作业详情
	 * @param workId
	 * @param num
	 * @return
	 */
	@Query(nativeQuery = true, value = "select * from zyb_student_work_details where student_work_id=?1 and num = ?2")
	public List<ZuoybStudentWorkDetails> findByStudentWorkIdAndNumList(String workId, int num);

	/**
	 * 一个范围内子状态等于某个值的某作业的情况
	 * @param workId
	 * @param num1
	 * @param num2
	 * @param childStat
	 * @return
	 */
	public List<ZuoybStudentWorkDetails> findByStudentWorkIdAndNumBetweenAndChildStat(String workId, int num1, int num2, String childStat);

	/**
	 * 查询学习状态
	 * @param workId
	 * @param num1
	 * @param num2
	 * @return
	 */
	public List<ZuoybStudentWorkDetails> findByStudentWorkIdAndNumBetween(String workId, int num1, int num2);
}
