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

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;
import com.hz.pm.api.common.model.constant.BizConst;
import com.hz.pm.api.meeting.entity.domain.MeetingExpertJudge;
import com.ningdatech.basic.util.CollUtils;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务类
 * </p>
 *
 * @author CMM
 * @since 2023-07-31
 */
public interface IMeetingExpertJudgeService extends IService<MeetingExpertJudge> {

    default List<Long> listExistsMeetingExpertIds(Collection<Long> meetingExpertIds) {
        if (CollUtil.isEmpty(meetingExpertIds)) {
            return Collections.emptyList();
        }
        LambdaQueryWrapper<MeetingExpertJudge> query = Wrappers.lambdaQuery(MeetingExpertJudge.class)
                .in(MeetingExpertJudge::getMeetingExpertId, meetingExpertIds);
        return CollUtils.fieldList(list(query), MeetingExpertJudge::getMeetingExpertId);
    }

    default MeetingExpertJudge getByMeetingExpertId(Long meetingExpertId) {
        Wrapper<MeetingExpertJudge> query = Wrappers.lambdaQuery(MeetingExpertJudge.class)
                .eq(MeetingExpertJudge::getMeetingExpertId, meetingExpertId)
                .last(BizConst.LIMIT_1);
        return getOne(query);
    }

    default Map<Long, Long> getExpertJudgeIdMap(Long meetingId) {
        LambdaQueryWrapper<MeetingExpertJudge> query = Wrappers.lambdaQuery(MeetingExpertJudge.class)
                .select(MeetingExpertJudge::getExpertId, MeetingExpertJudge::getId)
                .eq(MeetingExpertJudge::getMeetingId, meetingId);
        return CollUtils.listToMap(list(query), MeetingExpertJudge::getExpertId, MeetingExpertJudge::getId);
    }

    default List<MeetingExpertJudge> listByMeetingExpertIds(Collection<Long> meetingExpertIds) {
        LambdaQueryWrapper<MeetingExpertJudge> query = Wrappers.lambdaQuery(MeetingExpertJudge.class)
                .in(MeetingExpertJudge::getMeetingExpertId, meetingExpertIds);
        return list(query);
    }

}
