package com.ruoyi.dxp.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.dxp.dto.UserCompanyDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.dxp.mapper.UserCompanyMapper;
import com.ruoyi.dxp.domain.UserCompany;
import com.ruoyi.dxp.service.IUserCompanyService;

/**
 * 外部用户Service业务层处理
 * 
 * @author jy
 * @date 2022-11-07
 */
@Service
public class UserCompanyServiceImpl implements IUserCompanyService 
{
    @Autowired
    private UserCompanyMapper userCompanyMapper;

    /**
     * 查询外部用户
     * 
     * @param userId 外部用户主键
     * @return 外部用户
     */
    @Override
    public UserCompanyDto selectUserCompanyByUserId(Long userId)
    {
        return userCompanyMapper.selectUserCompanyByUserId(userId);
    }

    /**
     * 查询外部用户列表
     * 
     * @param userCompany 外部用户
     * @return 外部用户
     */
    @Override
    public List<UserCompanyDto> selectUserCompanyList(UserCompanyDto userCompany)
    {
        return userCompanyMapper.selectUserCompanyList(userCompany);
    }

    /**
     * 新增外部用户
     * 
     * @param userCompany 外部用户
     * @return 结果
     */
    @Override
    public int insertUserCompany(UserCompany userCompany)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        userCompany.setCreateBy(loginUser.getUsername());
        userCompany.setCreateTime(DateUtils.getNowDate());
        return userCompanyMapper.insertUserCompany(userCompany);
    }

    /**
     * 修改外部用户
     * 
     * @param userCompany 外部用户
     * @return 结果
     */
    @Override
    public int updateUserCompany(UserCompany userCompany)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        userCompany.setUpdateBy(loginUser.getUsername());
        userCompany.setUpdateTime(DateUtils.getNowDate());
        return userCompanyMapper.updateUserCompany(userCompany);
    }

    /**
     * 批量删除外部用户
     * 
     * @param userIds 需要删除的外部用户主键
     * @return 结果
     */
    @Override
    public int deleteUserCompanyByUserIds(Long[] userIds)
    {
        return userCompanyMapper.deleteUserCompanyByUserIds(userIds);
    }

    /**
     * 删除外部用户信息
     * 
     * @param userId 外部用户主键
     * @return 结果
     */
    @Override
    public int deleteUserCompanyByUserId(Long userId)
    {
        return userCompanyMapper.deleteUserCompanyByUserId(userId);
    }
}
