package com.ruoyi.ibs.grid.service.impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.ibs.grid.domain.vo.GridUserVO;
import com.ruoyi.ibs.grid.mapper.GridUserMapper;
import com.ruoyi.ibs.grid.service.SysUserDeptService;
import com.ruoyi.system.mapper.SysDeptMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @Author 吴凯程
 * @Date 2024/10/21
 **/
@Service
public class SysUserDeptServiceImpl implements SysUserDeptService {

    @Resource
    private GridUserMapper gridUserMapper;

    @Resource
    private SysDeptMapper deptMapper;

    /**
     * @param deptIds
     * @return
     */
    @Override
    public List<GridUserVO> getUserListByDeptIds(List<Long> deptIds) {
        deptIds.forEach(deptId -> {
            if (Objects.isNull(deptMapper.checkDeptIdExist(deptId))) {
                throw new ServiceException("该机构不存在：" + deptId);
            }
        });
        return gridUserMapper.selectGridUser(deptIds);
    }
}
