package com.ktg.iscs.service.impl;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktg.common.core.text.Convert;
import com.ktg.iscs.domain.IsUserWorkstation;
import com.ktg.iscs.mapper.IsUserWorkstationMapper;
import com.ktg.iscs.service.IIsUserWorkstationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 用户与mars岗位关联Service业务层处理
 *
 * @author cgj
 * @date 2024-12-16
 */
@Service
public class IsUserWorkstationServiceImpl extends ServiceImpl<IsUserWorkstationMapper, IsUserWorkstation> implements IIsUserWorkstationService
{
    @Autowired
    private IsUserWorkstationMapper isUserWorkstationMapper;

    /**
     * 查询用户与mars岗位关联
     *
     * @param userId 用户与mars岗位关联主键
     * @return 用户与mars岗位关联
     */
    @Override
    public IsUserWorkstation selectIsUserWorkstationByUserId(Long userId)
    {
        return isUserWorkstationMapper.selectIsUserWorkstationByUserId(userId);
    }

    /**
     * 查询用户与mars岗位关联列表
     *
     * @param isUserWorkstation 用户与mars岗位关联
     * @return 用户与mars岗位关联
     */
    @Override
    public List<IsUserWorkstation> selectIsUserWorkstationList(IsUserWorkstation isUserWorkstation)
    {
        return isUserWorkstationMapper.selectIsUserWorkstationList(isUserWorkstation);
    }

    /**
     * 新增用户与mars岗位关联
     *
     * @param isUserWorkstation 用户与mars岗位关联
     * @return 结果
     */
    @Override
    public int insertIsUserWorkstation(IsUserWorkstation isUserWorkstation)
    {
        return isUserWorkstationMapper.insertIsUserWorkstation(isUserWorkstation);
    }

    /**
     * 修改用户与mars岗位关联
     *
     * @param isUserWorkstation 用户与mars岗位关联
     * @return 结果
     */
    @Override
    public int updateIsUserWorkstation(IsUserWorkstation isUserWorkstation)
    {
        return isUserWorkstationMapper.updateIsUserWorkstation(isUserWorkstation);
    }

    /**
     * 批量删除用户与mars岗位关联
     *
     * @param userIds 需要删除的用户与mars岗位关联主键
     * @return 结果
     */
    @Override
    public int deleteIsUserWorkstationByUserIds(String userIds)
    {
        Assert.notBlank(userIds, "请选择需要删除的数据!");
        Long[] longIds = Convert.toLongArray(userIds);
        return isUserWorkstationMapper.deleteIsUserWorkstationByUserIds(longIds);
    }

    /**
     * 删除用户与mars岗位关联信息
     *
     * @param userId 用户与mars岗位关联主键
     * @return 结果
     */
    @Override
    public int deleteIsUserWorkstationByUserId(Long userId)
    {
        return isUserWorkstationMapper.deleteIsUserWorkstationByUserId(userId);
    }

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