package com.hotwj.platform.resourceManagement.company.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hotwj.platform.resourceManagement.company.domain.SysUserLoginPort;
import com.hotwj.platform.resourceManagement.company.domain.vo.SysUserLoginPortVo;
import com.hotwj.platform.resourceManagement.company.mapper.SysUserLoginPortMapper;
import com.hotwj.platform.resourceManagement.company.service.ISysUserLoginPortService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.utils.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户-企业-登录端口关联关系Service业务层处理
 *
 * @author shihongwei
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class SysUserLoginPortServiceImpl extends ServiceImpl<SysUserLoginPortMapper, SysUserLoginPort> implements ISysUserLoginPortService {

    /**
     * 查询用户-企业-登录端口关联关系列表（根据端口）
     *
     * @param userId 用户ID
     * @return 用户-企业-登录端口关联关系
     */
    @Override
    public List<SysUserLoginPortVo> selectLoginPortListByPort(Long userId, String port) {
        List<SysUserLoginPortVo> sysUserLoginPortVos = baseMapper.selectLoginPortListByPort(userId, port);

        return sysUserLoginPortVos;
    }

    @Override
    public List<String> selectUserLoginPorts(Long userId) {
        LambdaQueryWrapper<SysUserLoginPort> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(SysUserLoginPort::getLoginPort)
                .eq(SysUserLoginPort::getUserId, userId);
        List<SysUserLoginPort> sysUserLoginPorts = baseMapper.selectList(wrapper);
        return sysUserLoginPorts.stream()
                .map(SysUserLoginPort::getLoginPort)
                .filter(StringUtils::isNotBlank)
                .distinct()
                .collect(Collectors.toList());
    }

}
