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

import com.ssj.bean.weixin.zyb.domain.ZuoybKnowHowDetailsKd;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
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 2018年5月1日 上午11:09:00 
 * 类说明 
 */
@Repository
public interface ZuoybKnowHowDetailsKdDao extends JpaRepository<ZuoybKnowHowDetailsKd, String>{

	@Query(nativeQuery = true, value = "select *  from  zyb_know_how_details_kd  where how_details_id = ?1   ")
	public List<ZuoybKnowHowDetailsKd> findByHowDetailsId(String howDetailsId);
	
	 public Page<ZuoybKnowHowDetailsKd> findAll(Specification<ZuoybKnowHowDetailsKd> specification, Pageable page);
	 @Query(nativeQuery = true, value = "update zyb_know_how_details_kd set num = ?2 where id =?1 ")
	 @Modifying
	  public void  updateKnowHowDetailKdNum(String id,Integer num);
	 
	 
	 @Query(nativeQuery = true, value = "SELECT\n" +
			 "	 d.`id`,\n" +
			 "	d.`how_details_id`,\n" +
			 "	t.alias as `name`,\n" +
			 "	d.`create_time`,\n" +
			 "	d.`how_id`,\n" +
			 "	d.`ydsl`,\n" +
			 "	d.`img`,\n" +
			 "	t.num ,\n" +
			 "	d.`label`,\n" +
			 "	d.`level` " +
			 "FROM\n" +
			 "	zyb_know_how_details_kd d\n" +
			 " JOIN zyb_know_how_details_sort t ON d.id = t.how_details_kd_id\n" +
			 "AND t.stat = 3\n" +
			 "WHERE\n" +
			 "	t.lib_id =?1\n" +
			 "AND t.type = ?5\n" +
			 "AND t.course_name =?2\n" +
			 "AND t.grade =?3\n" +
			 "AND t.semester = ?4\n" +
			 "and t.how_details_id = ?6 order by t.num ")
	 public List<ZuoybKnowHowDetailsKd> getHowDetailsKdIds(String libId, String courseName,String grade, String semester, String type,
			 String detailsId);
}
