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

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
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) {
        String key = params.containsKey("key") ? (String) params.get("key") : null;
        Long meetingId = params.containsKey("meetingId") ? Long.valueOf(params.get("meetingId").toString()) : 0L;
        IPage<MeetingEntity> page = this.page(
                new Query<MeetingEntity>().getPage(params),
                new QueryWrapper<MeetingEntity>().eq("is_del", 0)
                .eq(meetingId != 0L, "pid", meetingId)
                .like(StringUtils.isNotBlank(key),"name", key)
        );

        return new PageUtils(page);
    }

    @Override
    public boolean meetingExist(Long id) {
        MeetingEntity meeting = getOne(new QueryWrapper<MeetingEntity>().eq("id", id).eq("pid", 0).eq("is_del", 0));

        return meeting==null ? false : true;
    }

}