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

import com.ym.mec.biz.dal.dao.StudentExtracurricularExercisesSituationDao;
import com.ym.mec.biz.dal.dao.TeacherDao;
import com.ym.mec.biz.dal.dto.StudentExercisesSituationDto;
import com.ym.mec.biz.dal.entity.StudentExtracurricularExercisesSituation;
import com.ym.mec.biz.dal.page.StudentExercisesSituationQueryInfo;
import com.ym.mec.biz.service.StudentExtracurricularExercisesSituationService;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.page.PageInfo;
import com.ym.mec.common.service.impl.BaseServiceImpl;
import com.ym.mec.util.collection.MapUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StudentExtracurricularExercisesSituationServiceImpl extends BaseServiceImpl<Long, StudentExtracurricularExercisesSituation> implements StudentExtracurricularExercisesSituationService {
	
	@Autowired
	private StudentExtracurricularExercisesSituationDao studentExtracurricularExercisesSituationDao;
	@Autowired
	private TeacherDao teacherDao;

	@Override
	public BaseDAO<Long, StudentExtracurricularExercisesSituation> getDAO() {
		return studentExtracurricularExercisesSituationDao;
	}

	@Override
	public PageInfo<StudentExercisesSituationDto> findStudentExtracurricularExercisesSituations(StudentExercisesSituationQueryInfo queryInfo) {
		PageInfo<StudentExercisesSituationDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
		Map<String, Object> params = new HashMap<>();
		MapUtil.populateMap(params, queryInfo);

		List<StudentExercisesSituationDto> dataList = null;
		int count = studentExtracurricularExercisesSituationDao.countExercisesSituations(params);
		if (count > 0) {
			pageInfo.setTotal(count);
			params.put("offset", pageInfo.getOffset());
			dataList = studentExtracurricularExercisesSituationDao.findExercisesSituations(params);
		}
		if (count == 0) {
			dataList = new ArrayList<>();
		}
		pageInfo.setRows(dataList);
		return pageInfo;
	}
}
