package com.hz.pm.api.meeting.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ningdatech.basic.util.CollUtils;
import com.hz.pm.api.common.model.entity.CountGroupByDTO;
import com.hz.pm.api.meeting.entity.domain.Meeting;
import com.hz.pm.api.meeting.entity.enumeration.MeetingStatusByDashboard;
import com.hz.pm.api.meeting.mapper.MeetingMapper;
import com.hz.pm.api.meeting.service.IMeetingService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 会议 服务实现类
 * </p>
 *
 * @author WendyYang
 * @since 2022-07-26
 */
@Service
public class MeetingServiceImpl extends ServiceImpl<MeetingMapper, Meeting> implements IMeetingService {

    @Override
    public void stopRandomInvite(Long meetingId) {
        LambdaUpdateWrapper<Meeting> update = Wrappers.lambdaUpdate(Meeting.class)
                .eq(Meeting::getId, meetingId)
                .set(Meeting::getInviteStatus, Boolean.TRUE);
        update(update);
    }

    @Override
    public Map<MeetingStatusByDashboard, Integer> meetingCountSummary(Long createBy) {
        List<CountGroupByDTO<String>> meetingCountSummary = baseMapper.meetingCountSummary(createBy);
        return CollUtils.listToMap(meetingCountSummary, w -> MeetingStatusByDashboard.valueOf(w.getGroupKey()),
                CountGroupByDTO::getTotal);
    }

}
