package com.ssj.dao.weixin.sales.dao;

import com.ssj.bean.weixin.sales.domain.LibCommission;
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.math.BigDecimal;


/** 
 * @author  ZhangCaibao 
 * @version 2017年4月24日 上午11:13:35 
 * 类说明 
 */
@Repository
public interface LibCommissionDao  extends JpaRepository<LibCommission, String>{

	 public Page<LibCommission> findAll(Specification<LibCommission> specification, Pageable page);
	 
	 @Query(nativeQuery = true, value = " select count(1) from   tb_lib_commission  where lib_id = ?1  ")
	 public Integer getLibCount(String libId);
	 
	 @Query(nativeQuery = true, value = " INSERT  into   tb_lib_commission ( id,type,new_sign,x_sign,create_time,lib_id)\n" +
			 "SELECT  UUID(),type,new_sign,x_sign ,now(),?1 from  tb_lib_commission where lib_id ='SSJ'")
	 @Modifying
	 public void insertLibCommission(String libId);
	 
	 @Query(nativeQuery = true, value = "update tb_lib_commission set new_sign = ?2  where id = ?1 ")
	 @Modifying
	 public void updateNewSign(String id ,BigDecimal newSign);
	 
	 @Query(nativeQuery = true, value = "update tb_lib_commission set x_sign = ?2  where id = ?1 ")
	 @Modifying
	 public void updateXSign(String id ,BigDecimal xSign);

	 public LibCommission findByTypeAndLibId(String type, String libId);
}
