package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.RecordLeaveMapper;
import com.ruoyi.system.domain.RecordLeave;
import com.ruoyi.system.service.IRecordLeaveService;

/**
 * 请假记录信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-02-13
 */
@Service
public class RecordLeaveServiceImpl implements IRecordLeaveService 
{
    @Autowired
    private RecordLeaveMapper recordLeaveMapper;

    /**
     * 查询请假记录信息
     * 
     * @param id 请假记录信息主键
     * @return 请假记录信息
     */
    @Override
    public RecordLeave selectRecordLeaveById(Long id)
    {
        return recordLeaveMapper.selectRecordLeaveById(id);
    }

    /**
     * 查询请假记录信息列表
     * 
     * @param recordLeave 请假记录信息
     * @return 请假记录信息
     */
    @Override
    public List<RecordLeave> selectRecordLeaveList(RecordLeave recordLeave)
    {
        return recordLeaveMapper.selectRecordLeaveList(recordLeave);
    }

    /**
     * 新增请假记录信息
     * 
     * @param recordLeave 请假记录信息
     * @return 结果
     */
    @Override
    public int insertRecordLeave(RecordLeave recordLeave)
    {
        //获取当前人员信息
        SysUser user = SecurityUtils.getLoginUser().getUser();
        recordLeave.setAbsenteeId(String.valueOf(user.getUserId()));
        recordLeave.setAbsenteeName(user.getNickName());
        return recordLeaveMapper.insertRecordLeave(recordLeave);
    }

    /**
     * 修改请假记录信息
     * 
     * @param recordLeave 请假记录信息
     * @return 结果
     */
    @Override
    public int updateRecordLeave(RecordLeave recordLeave)
    {
        return recordLeaveMapper.updateRecordLeave(recordLeave);
    }

    /**
     * 批量删除请假记录信息
     * 
     * @param ids 需要删除的请假记录信息主键
     * @return 结果
     */
    @Override
    public int deleteRecordLeaveByIds(Long[] ids)
    {
        return recordLeaveMapper.deleteRecordLeaveByIds(ids);
    }

    /**
     * 删除请假记录信息信息
     * 
     * @param id 请假记录信息主键
     * @return 结果
     */
    @Override
    public int deleteRecordLeaveById(Long id)
    {
        return recordLeaveMapper.deleteRecordLeaveById(id);
    }

    @Override
    public int audit(Long id, String isPass) {
        //获取当前人员信息
        SysUser user = SecurityUtils.getLoginUser().getUser();

        RecordLeave recordLeave = new RecordLeave();
        recordLeave.setId(id);
        recordLeave.setExaminersId(user.getUserId());
        recordLeave.setExaminersName(user.getNickName());
        recordLeave.setIsPass(isPass);
        return recordLeaveMapper.updateRecordLeave(recordLeave);
    }
}
