package com.keao.edu.user.service.impl;

import com.keao.edu.common.dal.BaseDAO;
import com.keao.edu.common.exception.BizException;
import com.keao.edu.common.page.PageInfo;
import com.keao.edu.common.page.QueryInfo;
import com.keao.edu.common.service.impl.BaseServiceImpl;
import com.keao.edu.user.dao.ExamSongDao;
import com.keao.edu.user.entity.ExamSong;
import com.keao.edu.user.service.ExamSongService;
import com.keao.edu.util.collection.MapUtil;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class ExamSongServiceImpl extends BaseServiceImpl<Integer, ExamSong> implements ExamSongService {
	
	@Autowired
	private ExamSongDao examSongDao;

	@Override
	public BaseDAO<Integer, ExamSong> getDAO() {
		return examSongDao;
	}

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

        List<ExamSong> dataList = new ArrayList<>();
        int count = this.findCount(params);
        if (count > 0) {
            pageInfo.setTotal(count);
            params.put("offset", pageInfo.getOffset());
            dataList = this.getDAO().queryPage(params);
        }
        pageInfo.setRows(dataList);
        return pageInfo;
    }

    @Override
    public List<ExamSong> getWithSubject(Integer subjectId) {
	    if(Objects.isNull(subjectId)){
	        throw new BizException("请选择专业");
        }
        return examSongDao.getWithSubject(subjectId);
    }
}
