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

import com.alibaba.dubbo.config.annotation.Service;
import com.ssj.bean.weixin.sales.domain.LibSalesPrice;
import com.ssj.dao.weixin.sales.dao.LibSalesPriceDao;
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.framework.idworker.IdWorker;
import com.ssj.service.weixin.sales.service.LibSalesPriceService;
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 java.math.BigDecimal;
import java.util.List;
import java.util.Map;


/** 
 * @author  ZhangCaibao 
 * @version 2017年4月24日 上午11:12:20 
 * 类说明 
 */
@Service(version="1.0")
@Transactional
public class LibSalesPriceServiceImpl extends BaseServiceImpl<LibSalesPrice, String> implements LibSalesPriceService{
    @Autowired
	private LibSalesPriceDao  libSalesPriceDao;
	@Override
	public PagingAndSortingRepository<LibSalesPrice, String> getDao() {
		return libSalesPriceDao;
	}
	@Override
	public Page<LibSalesPrice> findByPage(Map<String, Object> params,
			Pageable sp) {
		  Map<String, SearchFilter> filters = SearchFilter.parse(params);
			Specification<LibSalesPrice> specification = DynamicSpecifications.bySearchFilter(filters.values(), LibSalesPrice.class);    
       return  libSalesPriceDao.findAll(specification, sp);
	}
	@Override
	public void insertLibSalesPrice(String libId,Integer libtype) {
		Integer count=libSalesPriceDao.getLibCount(libId);
		if(count==0){
		    String id = IdWorker.generateId();
			if(libtype == 1){
				libSalesPriceDao.insertLibSales(libId,"SSJ",id);
		    }else{
		    	libSalesPriceDao.insertLibSales(libId,"SSJGx",id);//共享
		    }
			
		}
		
	}
	@Override
	public void updatePrice(String id, BigDecimal price) {
		libSalesPriceDao.updatePrice(id, price);
	}
	@Override
	public List<LibSalesPrice> findByLibId(String libId) {
		return libSalesPriceDao.findByLibId(libId);
	}
	@Override
	public void updateName(String id, String name) {
		libSalesPriceDao.updateName(id, name);
	}
	@Override
	public LibSalesPrice findByLibIdAndSpeciesAndType(String libId,
			String species, String type) {
		return libSalesPriceDao.findByLibIdAndSpeciesAndType(libId, species, type);
	}

}
