package com.ym.mec.biz.service.impl;

import com.ym.mec.biz.dal.dao.CourseHomeworkTemplateDao;
import com.ym.mec.biz.dal.dao.CourseScheduleDao;
import com.ym.mec.biz.dal.entity.CourseHomeworkTemplate;
import com.ym.mec.biz.dal.page.CourseHomeWorkTemplateQueryInfo;
import com.ym.mec.biz.service.CourseHomeworkTemplateService;
import com.ym.mec.common.page.PageInfo;
import com.ym.mec.common.page.QueryInfo;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.service.impl.BaseServiceImpl;

import java.util.List;

@Service
public class CourseHomeworkTemplateServiceImpl extends BaseServiceImpl<Integer, CourseHomeworkTemplate>  implements CourseHomeworkTemplateService {
	
	@Autowired
	private CourseHomeworkTemplateDao courseHomeworkTemplateDao;
	@Autowired
	private CourseScheduleDao courseScheduleDao;

	@Override
	public BaseDAO<Integer, CourseHomeworkTemplate> getDAO() {
		return courseHomeworkTemplateDao;
	}

	@Override
	public PageInfo<CourseHomeworkTemplate> queryPage(QueryInfo queryInfo) {
		CourseHomeWorkTemplateQueryInfo templateQueryInfo= (CourseHomeWorkTemplateQueryInfo) queryInfo;
		if(null!=templateQueryInfo.getCourseScheduleID()){
			String subjectIDs = courseHomeworkTemplateDao.getSubjectIDs(templateQueryInfo.getCourseScheduleID());
			if(!StringUtils.isEmpty(subjectIDs)) {
				templateQueryInfo.setSubjectIDs(subjectIDs.split(","));
			}
		}
		return super.queryPage(templateQueryInfo);
	}

	@Override
	public List<CourseHomeworkTemplate> findByClassType(CourseHomeWorkTemplateQueryInfo queryInfo) {
		CourseHomeWorkTemplateQueryInfo templateQueryInfo=  queryInfo;
		if(null!=templateQueryInfo.getCourseScheduleID()){
			String classType=courseScheduleDao.findClassTypeByCourse(templateQueryInfo.getCourseScheduleID());
			queryInfo.setClassType(classType);
		}
		return super.queryPage(templateQueryInfo).getRows();
	}
}