package com.dcsoft.system.service.impl;

import java.util.List;
import com.dcsoft.common.core.utils.DateUtils;
import com.dcsoft.system.domain.SysPeople;
import com.dcsoft.system.mapper.SysPeopleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dcsoft.system.mapper.SysPeopleLeaveMapper;
import com.dcsoft.system.domain.SysPeopleLeave;
import com.dcsoft.system.service.ISysPeopleLeaveService;

/**
 * 离职管理Service业务层处理
 *
 * @author nichun
 * @date 2023-09-09
 */
@Service
public class SysPeopleLeaveServiceImpl implements ISysPeopleLeaveService
{
    @Autowired
    private SysPeopleLeaveMapper sysPeopleLeaveMapper;

    @Autowired
    private SysPeopleMapper sysPeopleMapper;

    /**
     * 查询离职管理
     *
     * @param id 离职管理主键
     * @return 离职管理
     */
    @Override
    public SysPeopleLeave selectSysPeopleLeaveById(Long id)
    {
        return sysPeopleLeaveMapper.selectSysPeopleLeaveById(id);
    }

    /**
     * 查询离职管理列表
     *
     * @param sysPeopleLeave 离职管理
     * @return 离职管理
     */
    @Override
    public List<SysPeopleLeave> selectSysPeopleLeaveList(SysPeopleLeave sysPeopleLeave)
    {
        return sysPeopleLeaveMapper.selectSysPeopleLeaveList(sysPeopleLeave);
    }

    /**
     * 新增离职管理
     *
     * @param sysPeopleLeave 离职管理
     * @return 结果
     */
    @Override
    public int insertSysPeopleLeave(SysPeopleLeave sysPeopleLeave)
    {
        sysPeopleLeave.setCreateTime(DateUtils.getNowDate());
        return sysPeopleLeaveMapper.insertSysPeopleLeave(sysPeopleLeave);
    }

    /**
     * 修改离职管理
     *
     * @param sysPeopleLeave 离职管理
     * @return 结果
     */
    @Override
    public int updateSysPeopleLeave(SysPeopleLeave sysPeopleLeave)
    {
        sysPeopleLeave.setUpdateTime(DateUtils.getNowDate());
        return sysPeopleLeaveMapper.updateSysPeopleLeave(sysPeopleLeave);
    }

    /**
     * 批量删除离职管理
     *
     * @param ids 需要删除的离职管理主键
     * @return 结果
     */
    @Override
    public int deleteSysPeopleLeaveByIds(Long[] ids)
    {
       for(Long peopleId:ids){
           SysPeopleLeave peopleLeave =sysPeopleLeaveMapper.selectSysPeopleLeaveById(peopleId);
           if(peopleLeave.getPeopleId()!=null){
               SysPeople people=new SysPeople();
               people.setId(peopleLeave.getPeopleId());
               people.setDelFlag(0L);
               sysPeopleMapper.updateSysPeople(people);
           }
       }
        return sysPeopleLeaveMapper.deleteSysPeopleLeaveByIds(ids);
    }

    /**
     * 删除离职管理信息
     *
     * @param id 离职管理主键
     * @return 结果
     */
    @Override
    public int deleteSysPeopleLeaveById(Long id)
    {
        SysPeopleLeave peopleLeave =sysPeopleLeaveMapper.selectSysPeopleLeaveById(id);
        if(peopleLeave.getPeopleId()!=null){
            SysPeople people=new SysPeople();
            people.setId(peopleLeave.getPeopleId());
            people.setDelFlag(0L);
            sysPeopleMapper.updateSysPeople(people);
        }
        return sysPeopleLeaveMapper.deleteSysPeopleLeaveById(id);
    }
}
