package io.renren.modules.admin.service.impl;

import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.admin.dao.LectureDao;
import io.renren.modules.admin.entity.LectureEntity;
import io.renren.modules.admin.service.LectureService;


@Service("lectureService")
public class LectureServiceImpl extends ServiceImpl<LectureDao, LectureEntity> implements LectureService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String meetingId = (String)params.get("meetingId");
        IPage<LectureEntity> page = this.page(
                new Query<LectureEntity>().getPage(params),
                new QueryWrapper<LectureEntity>().eq(StringUtils.isNotBlank(meetingId),"meeting_id", meetingId)
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils myQueryPage(Map<String, Object> params) {
        Long meetingId = Long.valueOf((String) params.get("meetingId"));
        String key = params.containsKey("page") ? (String) params.get("key") : "";
        int page = params.containsKey("page") ? Integer.valueOf(params.get("page").toString()) : 0;
        int limit =  params.containsKey("limit") ? Integer.valueOf(params.get("limit").toString()) : 10;

        List<Map<String, Object>> lectureList=baseMapper.getPageList(meetingId, key, key, page, limit);
        int mc = baseMapper.getCounts(meetingId, key, key);
    

        return new  PageUtils(lectureList, mc, limit, page);
    }

    @Override
    public  List<Map<String, Object>> getBranchList(Long bid) {
        return baseMapper.getBranchList(bid);
    }
}