package com.jd.lightapplication.service;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jd.lightapplication.common.lang.R;
import com.jd.lightapplication.model.MeetingInfo;
import com.jd.lightapplication.mapper.MeetingInfoMapper;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jd.lightapplication.model.dto.MeetingInfoQueryDto;
import org.springframework.stereotype.Service;


@Service
public class MeetingInfoService extends ServiceImpl<MeetingInfoMapper, MeetingInfo> {

    public MeetingInfo getNextMeeting() {
        return baseMapper.getNextMeeting();
    }

    public IPage<MeetingInfo> page(Page page, MeetingInfoQueryDto meetingInfoQueryDto) {
        LambdaQueryWrapper<MeetingInfo> wrapper = new LambdaQueryWrapper<>();
        if (StrUtil.isNotBlank(meetingInfoQueryDto.getTitle())) {
            wrapper.like(MeetingInfo::getTitle, meetingInfoQueryDto.getTitle());
        }
        wrapper.orderByAsc(MeetingInfo::getStatus)
                .orderByDesc(MeetingInfo::getCreateTime);
        return this.page(page, wrapper);
    }

    public Boolean updateStatus(Long meetingId, Integer status) {
        return baseMapper.updateStatus(meetingId, status) > 0;
    }
}