package com.ruoyi.cms.service.impl;

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

import com.ruoyi.cms.domain.Job;
import com.ruoyi.cms.mapper.JobMapper;
import com.ruoyi.cms.mapper.JobTitleMapper;
import com.ruoyi.common.core.domain.entity.JobTitle;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.ruoyi.cms.mapper.AppUserMapper;
import com.ruoyi.cms.domain.AppUser;
import com.ruoyi.cms.service.IAppUserService;

/**
 * APP用户Service业务层处理
 *
 * @author lishundong
 * @date 2024-09-03
 */
@Service
public class AppUserServiceImpl extends ServiceImpl<AppUserMapper,AppUser> implements IAppUserService
{
    @Autowired
    private AppUserMapper appUserMapper;
    @Autowired
    private JobTitleMapper jobTitleMapper;
    /**
     * 查询APP用户
     *
     * @param userId APP用户主键
     * @return APP用户
     */
    @Override
    public AppUser selectAppUserByUserId(Long userId)
    {
        AppUser appUser = appUserMapper.selectById(userId);
        if(StringUtils.isNotEmpty(appUser.getJobTitleId())){
            List<String> list = Arrays.asList(appUser.getJobTitleId().split(","));
            List<Long> collect = list.stream().map(Long::valueOf).collect(Collectors.toList());
            List<JobTitle> jobs = jobTitleMapper.selectBatchIds(collect);
            appUser.setJobTitle(jobs.stream().map(JobTitle::getJobName).collect(Collectors.toList()));
        }
        return appUser;
    }

    /**
     * 查询APP用户列表
     *
     * @param appUser APP用户
     * @return APP用户
     */
    @Override
    public List<AppUser> selectAppUserList(AppUser appUser)
    {
        return appUserMapper.selectAppUserList(appUser);
    }

    /**
     * 新增APP用户
     *
     * @param appUser APP用户
     * @return 结果
     */
    @Override
    public int insertAppUser(AppUser appUser)
    {
        return appUserMapper.insert(appUser);
    }

    /**
     * 修改APP用户
     *
     * @param appUser APP用户
     * @return 结果
     */
    @Override
    public int updateAppUser(AppUser appUser)
    {
        return appUserMapper.updateById(appUser);
    }

    /**
     * 批量删除APP用户
     *
     * @param userIds 需要删除的APP用户主键
     * @return 结果
     */
    @Override
    public int deleteAppUserByUserIds(Long[] userIds)
    {
        return appUserMapper.deleteBatchIds(Arrays.asList(userIds));
    }

}
