package com.ssj.service.weixin.sales.service.impl;

import java.math.BigDecimal;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.ssj.bean.weixin.sales.domain.LibCommission;
import com.ssj.dao.weixin.sales.dao.LibCommissionDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.framework.core.persistence.DynamicSpecifications;
import com.ssj.framework.core.persistence.SearchFilter;
import com.ssj.service.weixin.sales.service.LibCommissionService;

/** 
 * @author  ZhangCaibao 
 * @version 2017年4月24日 上午11:12:20 
 * 类说明 
 */
@Service(version="1.0")
@Transactional
public class LibCommissionServiceImpl extends BaseServiceImpl<LibCommission, String> implements LibCommissionService{
    @Autowired
	private LibCommissionDao  libCommissionDao;
	@Override
	public PagingAndSortingRepository<LibCommission, String> getDao() {
		return libCommissionDao;
	}
	@Override
	public Page<LibCommission> findByPage(Map<String, Object> params,
			Pageable sp) {
		 Map<String, SearchFilter> filters = SearchFilter.parse(params);
			Specification<LibCommission> specification = DynamicSpecifications.bySearchFilter(filters.values(), LibCommission.class);    
         return  libCommissionDao.findAll(specification, sp);
	}
	@Override
	public void insertCommission(String libId) {
		Integer count=libCommissionDao.getLibCount(libId);
		if(count==0){
			libCommissionDao.insertLibCommission(libId);
		}
		
	}
	@Override
	public void updateNewSign(String id, BigDecimal newSign) {
		libCommissionDao.updateNewSign(id, newSign);		
	}
	@Override
	public void updateXSign(String id, BigDecimal xSign) {
		libCommissionDao.updateXSign(id, xSign);	
		
	}
	@Override
	public LibCommission findByTypeAndLibId(String type, String libId) {
		
		return libCommissionDao.findByTypeAndLibId(type,libId);
	}

}
