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

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ym.mec.biz.dal.dao.StudentPreRegistrationDao;
import com.ym.mec.biz.dal.dto.StudentPreRegistrationDto;
import com.ym.mec.biz.dal.entity.StudentPreRegistration;
import com.ym.mec.biz.service.StudentPreRegistrationService;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.page.PageInfo;
import com.ym.mec.common.page.QueryInfo;
import com.ym.mec.common.service.impl.BaseServiceImpl;
import com.ym.mec.util.collection.MapUtil;

@Service
public class StudentPreRegistrationServiceImpl extends BaseServiceImpl<Long, StudentPreRegistration>  implements StudentPreRegistrationService {
	
	@Autowired
	private StudentPreRegistrationDao studentPreRegistrationDao;

	@Override
	public BaseDAO<Long, StudentPreRegistration> getDAO() {
		return studentPreRegistrationDao;
	}

	@Override
	public PageInfo<StudentPreRegistrationDto> queryListForPage(QueryInfo queryInfo) {
		PageInfo<StudentPreRegistrationDto> pageInfo = new PageInfo<StudentPreRegistrationDto>(queryInfo.getPage(), queryInfo.getRows());
		Map<String, Object> params = new HashMap<String, Object>();
		MapUtil.populateMap(params, queryInfo);
		
		List<StudentPreRegistrationDto> dataList = null;
		int count = this.findCount(params);
		if (count > 0) {
			pageInfo.setTotal(count);
			params.put("offset", pageInfo.getOffset());
			dataList = studentPreRegistrationDao.queryListForPage(params);
		}
		if (count == 0) {
			dataList = new ArrayList<StudentPreRegistrationDto>();
		}
		pageInfo.setRows(dataList);
		return pageInfo;
	}
	
}