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

import com.ym.mec.biz.dal.dao.CourseScheduleDao;
import com.ym.mec.biz.dal.page.GroupCourseScheduleQueryInfo;
import com.ym.mec.biz.service.GroupCourseScheduleService;
import com.ym.mec.common.page.PageInfo;
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;

/**
 * @Author Joburgess
 * @Date 2020/3/8
 */
@Service
public class GroupCourseScheduleServiceImpl implements GroupCourseScheduleService {

    @Autowired
    private CourseScheduleDao courseScheduleDao;

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

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