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

import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
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.MeetingDao;
import io.renren.modules.admin.entity.MeetingEntity;
import io.renren.modules.admin.service.MeetingService;


@Service("meetingService")
public class MeetingServiceImpl extends ServiceImpl<MeetingDao, MeetingEntity> implements MeetingService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MeetingEntity> page = this.page(
                new Query<MeetingEntity>().getPage(params),
                new QueryWrapper<MeetingEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils myQueryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        int page = params.containsKey("page") ? Integer.valueOf((String) params.get("page")) - 1 : 0;
        int limit = params.containsKey("limit") ? Integer.valueOf((String) params.get("limit")) : 10;
        if (page < 0) {
            page = 0;
        }
        int startLimt = page * limit;
        int endLimt = startLimt + limit;        
        List<Map<String, Object>> mList=baseMapper.getPageList(startLimt, endLimt, key, key);
        Integer mc = baseMapper.getCounts(key, key);

        return new PageUtils(mList, mc, limit, page+1);
    }

    @Override
    public int updateStatus(Long id, Integer isCheck) {
        return  baseMapper.updateStatus(id, isCheck);
    }
}
