package com.ruoyi.cms.service.impl;

import com.ruoyi.cms.domain.EmployeeConfirm;
import com.ruoyi.cms.domain.Job;
import com.ruoyi.cms.domain.JobApply;
import com.ruoyi.cms.domain.Notice;
import com.ruoyi.cms.mapper.EmployeeConfirmMapper;
import com.ruoyi.cms.mapper.JobApplyMapper;
import com.ruoyi.cms.mapper.JobMapper;
import com.ruoyi.cms.mapper.NoticeMapper;
import com.ruoyi.cms.service.EmployeeConfirmService;
import com.ruoyi.cms.util.notice.NoticeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;


@Service
public class EmployeeConfirmServiceImpl implements EmployeeConfirmService {

    @Autowired
    EmployeeConfirmMapper employeeConfirmMapper;
    @Autowired
    private JobApplyMapper jobApplyMapper;
    @Autowired
    private NoticeMapper noticeMapper;
    @Autowired
    private JobMapper jobMapper;

    @Override
    public List<EmployeeConfirm> getEmployeeConfirmList(EmployeeConfirm employeeConfirm) {
        return employeeConfirmMapper.getEmployeeConfirmList(employeeConfirm);
    }

    @Override
    public int insertEmployeeConfirm(EmployeeConfirm employeeConfirm) {
        int t=employeeConfirmMapper.insert(employeeConfirm);
        if(t>0){
            JobApply apply=new JobApply();
            apply.setId(employeeConfirm.getApplyId());
            apply.setHire("0");
            jobApplyMapper.updateById(apply);
        }
        Job job=jobMapper.getJobInfo(employeeConfirm.getJobId());
        //添加消息
        Notice notice=NoticeUtils.createLytzNotice(employeeConfirm,job);
        noticeMapper.insert(notice);
        return t;
    }

    @Override
    public int updateEmployeeConfirm(EmployeeConfirm employeeConfirm) {
        return employeeConfirmMapper.updateById(employeeConfirm);
    }

    @Override
    public int deleteEmployeeConfirmIds(Long[] ids) {
        return employeeConfirmMapper.deleteBatchIds(Arrays.asList(ids));
    }
}
