package com.ningdatech.pmapi.meeting.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ningdatech.pmapi.common.util.BizUtils;
import com.ningdatech.pmapi.common.util.StrUtils;
import com.ningdatech.pmapi.meeting.entity.domain.ExpertInviteAvoidRule;
import com.ningdatech.pmapi.meeting.entity.dto.AvoidRuleDTO;
import com.ningdatech.pmapi.meeting.mapper.ExpertInviteAvoidRuleMapper;
import com.ningdatech.pmapi.meeting.service.IExpertInviteAvoidRuleService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author WendyYang
 * @since 2022-07-26
 */
@Service
public class ExpertInviteAvoidRuleServiceImpl extends ServiceImpl<ExpertInviteAvoidRuleMapper, ExpertInviteAvoidRule> implements IExpertInviteAvoidRuleService {

    @Override
    public ExpertInviteAvoidRule getByMeetingId(Long meetingId) {
        LambdaQueryWrapper<ExpertInviteAvoidRule> query = Wrappers.lambdaQuery(ExpertInviteAvoidRule.class)
                .eq(ExpertInviteAvoidRule::getMeetingId, meetingId);
        return getOne(query);
    }

    @Override
    public AvoidRuleDTO getAvoidInfoDto(Long meetingId) {
        ExpertInviteAvoidRule avoidRule = getByMeetingId(meetingId);
        if (avoidRule == null) {
            return null;
        }
        AvoidRuleDTO avoidInfo = new AvoidRuleDTO();
        avoidInfo.setAvoidOrgIdList(StrUtils.split(avoidRule.getAvoidOrgIds()));
        avoidInfo.setAvoidUnitIdList(StrUtils.split(avoidRule.getAvoidUnitIds()));
        avoidInfo.setExpertIds(BizUtils.splitToLong(avoidRule.getAvoidExpertIds()));
        avoidInfo.setWeekInviteCount(avoidInfo.getWeekInviteCount());
        return avoidInfo;
    }

}
