package com.ktg.iscs.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktg.iscs.domain.IsUserUnit;
import com.ktg.iscs.mapper.IsUserUnitMapper;
import com.ktg.iscs.service.IIsUserUnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 用户与单位关联Service业务层处理
 *
 * @author cgj
 * @date 2024-12-18
 */
@Service
public class IsUserUnitServiceImpl extends ServiceImpl<IsUserUnitMapper, IsUserUnit> implements IIsUserUnitService {

    @Autowired
    private IsUserUnitMapper isUserUnitMapper;

    @Override
    public List<Long> getUnitIds(Long userId) {
        List<IsUserUnit> list = list(Wrappers.<IsUserUnit>lambdaQuery()
                .eq(IsUserUnit::getUserId, userId));
        if (!list.isEmpty()) {
            List<Long> collect = list.stream().map(IsUserUnit::getUnitId).collect(Collectors.toList());
            return collect;
        }
        return null;
    }
}
