package com.keyware.shandan.bianmu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.keyware.shandan.bianmu.entity.DirectoryMembersVo;
import com.keyware.shandan.bianmu.mapper.DirectoryMembersMapper;
import com.keyware.shandan.bianmu.service.DirectoryMembersService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.Collection;
import java.util.List;

/**
 * @author Administrator
 */
@Service
public class DirectoryMemberServiceImpl extends ServiceImpl<DirectoryMembersMapper, DirectoryMembersVo> implements DirectoryMembersService {

    @Override
    public List<DirectoryMembersVo> listByDirId(String dirId) {
        Assert.hasText(dirId, "dirId不能为空");
        QueryWrapper<DirectoryMembersVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("directory_id", dirId);
        return list(queryWrapper);
    }

    @Override
    public void removeByMemberId(String memberId) {
        Assert.hasText(memberId, "memberId不能为空");
        QueryWrapper<DirectoryMembersVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("member_id", memberId);
        remove(queryWrapper);
    }

    @Override
    public void removeByMemberIds(Collection<String> memberIds) {
        if (memberIds == null || memberIds.isEmpty()) {
            return;
        }
        QueryWrapper<DirectoryMembersVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("member_id", memberIds);
        remove(queryWrapper);
    }

    @Override
    public List<DirectoryMembersVo> listByUserId(String userId) {
        QueryWrapper<DirectoryMembersVo> wrapper = new QueryWrapper<>();
        wrapper.eq("MEMBER_ID", userId).eq("MEMBER_TYPE", "USER");
        return list(wrapper);
    }

    @Override
    public List<DirectoryMembersVo> listByOrgId(String orgId) {
        QueryWrapper<DirectoryMembersVo> wrapper = new QueryWrapper<>();
        wrapper.eq("MEMBER_ID", orgId).eq("MEMBER_TYPE", "ORG");
        return list(wrapper);
    }
}
