package com.ssj.service.course.service.impl;

import java.util.List;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.alibaba.dubbo.config.annotation.Service;
import com.ssj.bean.course.domain.CourseSeriesOrder;
import com.ssj.dao.course.dao.CourseSeriesOrderDao;
import com.ssj.framework.basic.utils.DateHelper;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.service.course.service.CourseSeriesOrderService;

/** 
 * @author  ZhangCaibao 
 * @version 2018年10月18日 下午3:31:44 
 * 类说明 
 */
@Transactional
@Service(version="1.0")
public class CourseSeriesOrderServiceImpl  extends BaseServiceImpl<CourseSeriesOrder, String> implements  CourseSeriesOrderService{
    
	@Autowired
	private  CourseSeriesOrderDao  dao;
	@Override
	public PagingAndSortingRepository<CourseSeriesOrder, String> getDao() {
		return dao;
	}
	@Override
	public void saveOrder(CourseSeriesOrder courseSeriesOrder) {
		int orderNo	=dao.findCourseSeriesByOrderNo(courseSeriesOrder.getOrderNo());
		if(orderNo ==0){
			courseSeriesOrder.setStartTime(courseSeriesOrder.getCreateTime());
			courseSeriesOrder.setEndTime(DateHelper.getMonthDate(courseSeriesOrder.getStartTime(), 12));
			courseSeriesOrder.setStat(1);
			this.save(courseSeriesOrder);
		}
	}
	@Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
	public int findCourseSeriesBylibId(String libId, String courseSeriesId) {
		return dao.findCourseSeriesBylibId(libId, courseSeriesId)!=null?1:0;
	}
	@Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
	public CourseSeriesOrder findCourseSeriesService(String libId,
			String courseSeriesId) {
		return dao.findCourseSeriesBylibId(libId, courseSeriesId);
	}
	@Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<CourseSeriesOrder> findByLibId(String libId) {
		return dao.findByLibId(libId);
	}
	@Override
	public int getCurrentCourserSize(String libId) {
		return dao.getCurrentCourserSize(libId);
	}
	@Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
	public int getCurrentStudentSize(String libId) {
		Integer size =dao.getCurrentStudentSize(libId);
		return size!=null?size:0;
	}
	@Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
	public int getCurrentStudentSize(String libId, String courseSeriesId) {
		Integer size =dao.getCurrentStudentSize(libId, courseSeriesId);
		return size!=null?size:0;
	}

}
