package com.ssj.dao.weixin.problem.dao;

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


@Repository
public interface ProblemDao  extends JpaRepository<Problem, String>{
	
	public Page<Problem> findAll(Specification<Problem> specification, Pageable page);
	/**
	 * 
	* 创建人:zhanglin
	* @param @param id
	* @param @param num       
	* 方法说明：修改排序
	 * @date 2017年8月25日 上午9:31:01
	 */
	 @Query(nativeQuery = true, value = "update tb_lib_problem set  num =?2  where id = ?1 ")
	 @Modifying
	 public void updatenum(String id, Integer num);
	 @Query(nativeQuery = true, value = "select * from   tb_lib_problem   where type = ?1 and stat =?2 ")
	 List<Problem> findByProblem(int type,int stat);
	 
	 @Query(nativeQuery = true, value = "update zyb_student_bg set vip_id=?2  where vip_id=?1")
	 @Modifying
	 public void updateZybStudentBg(String id, String ids);
	 
	 @Query(nativeQuery = true, value = "update zyb_student_push set vip_id=?2 where vip_id=?1")
	 @Modifying
	 public void updateZybStudentPush(String id, String ids);
	 
	 @Query(nativeQuery = true, value = "update zyb_student_work set vip_id=?2 where vip_id=?1")
	 @Modifying
	 public void updateZybStudentWork(String id, String ids);
	 
	 
	 @Query(nativeQuery = true, value = "update tb_lib_user_history set vip_id=?2 where vip_id=?1")
	 @Modifying
	 public void updateLibUserHistory(String id, String ids);
	 
	 @Query(nativeQuery = true, value = "update tb_order_details set vip_id=?2 where vip_id=?1")
	 @Modifying
	 public void updateOrderDetails(String id, String ids);
	
	 @Query(nativeQuery = true, value = "update tb_lib_book_detail set vip_id=?2  where vip_id=?1")
	 @Modifying
	 public void updateLibBookDetails(String id, String ids);
	 
	 @Query(nativeQuery = true, value = "update tb_lib_vip_service set vip_id=?2  WHERE vip_id=?1")
	 @Modifying
	 public void updateLibVipService (String id, String ids);
	 
	 @Query(nativeQuery = true, value = "update tb_lib_order_details set vip_id=?2  WHERE vip_id=?1")
	 @Modifying
	 public void updateLibOrderDetails (String id, String ids);
	 
	 @Query(nativeQuery = true, value = "UPDATE tb_lib_vip t1,\n" +
			 " tb_lib_vip t2\n" +
			 "SET t1.user_id = t2.user_id,\n" +
			 " t1.activate_time = t2.activate_time,\n" +
			 " t1.sex = t2.sex,\n" +
			 " t1.`name` = t2.`name`,\n" +
			 " t1.vipno = t2.vipno,\n" +
			 " t1.parent_name = t2.parent_name,\n" +
			 " t1.child_name = t2.child_name,\n" +
			 " t1.phone = t2.phone,\n" +
			 " t1.school = t2.school,\n" +
			 " t1.counseling = t2.counseling,\n" +
			 " t1.img_url = t2.img_url,\n" +
			 " t1.is_update = t2.is_update,\n" +
			 " t1.birthday = t2.birthday,\n" +
			 " t1.grade = t2.grade,\n" +
			 " t1.family = t2.family,\n" +
			 " t1.order_user = t2.order_user,\n" +
			 " t1.order_time = t2.order_time\n" +
			 "WHERE\n" +
			 "	t1.id =?1\n" +
			 "AND t2.id =?2")
		 @Modifying
		 public void updateLibVip(String id, String ids);
	 
	 @Query(nativeQuery = true, value = "update tb_lib_subscribe set vip_id=?2  WHERE vip_id=?1")
	 @Modifying
	 public void updateLibSubscribe (String id, String ids);

}
