package com.ruoyi.project.training.newstaff.service.impl;

import java.util.List;

import com.ruoyi.project.training.newstaff.domain.TTnFirstplanTmpl;
import com.ruoyi.project.training.newstaff.domain.TTnSchoolplanTmpl;
import com.ruoyi.project.training.newstaff.domain.TTnTransferplanTmpl;
import com.ruoyi.project.training.newstaff.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.training.newstaff.domain.TTnNew;
import com.ruoyi.project.training.newstaff.service.ITTnNewService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 新员工培训Service业务层处理
 *
 * @author ruoyi
 * @date 2023-06-29
 */
@Service
public class TTnNewServiceImpl implements ITTnNewService
{
    @Resource
    private TTnNewMapper tTnNewMapper;
    @Resource
    private TTnFirstplanMapper tTnFirstplanMapper;
    @Resource
    private TTnFirstplanTmplMapper tTnFirstplanTmplMapper;
    @Resource
    private TTnSchoolplanMapper tTnSchoolplanMapper;
    @Resource
    private TTnSchoolplanTmplMapper tTnSchoolplanTmplMapper;
    @Resource
    private TTnTransferplanMapper tTnTransferplanMapper;
    @Resource
    private TTnTransferplanTmplMapper tTnTransferplanTmplMapper;
    /**
     * 查询新员工培训
     *
     * @param newId 新员工培训ID
     * @return 新员工培训
     */
    @Override
    public TTnNew selectTTnNewById(Long newId)
    {
        return tTnNewMapper.selectTTnNewById(newId);
    }

    /**
     * 查询新员工培训列表
     *
     * @param tTnNew 新员工培训
     * @return 新员工培训
     */
    @Override
    public List<TTnNew> selectTTnNewList(TTnNew tTnNew)
    {
        return tTnNewMapper.selectTTnNewList(tTnNew);
    }

    /**
     * 新增新员工培训
     *
     * @param tTnNew 新员工培训
     * @return 结果
     */
    @Override
    @Transactional
    public int insertTTnNew(TTnNew tTnNew)
    {
        tTnNewMapper.insertTTnNew(tTnNew);
        // 进组
        TTnFirstplanTmpl tTnFirstplanTmpl = new TTnFirstplanTmpl();
        tTnFirstplanTmpl.setDeptId(tTnNew.getDeptId());
        List<TTnFirstplanTmpl> firstplanTmplList = tTnFirstplanTmplMapper.selectTTnFirstplanTmplList(tTnFirstplanTmpl);
        for (TTnFirstplanTmpl t: firstplanTmplList
        ) {
            t.setNewId(tTnNew.getNewId());
            tTnFirstplanMapper.insertTTnFirstplanTmpl(t);
        }
        //新员工
        if (tTnNew.getPlanType() == 1) {
            TTnSchoolplanTmpl tTnSchoolplanTmpl = new TTnSchoolplanTmpl();
            tTnSchoolplanTmpl.setDeptId(tTnNew.getDeptId());
            List<TTnSchoolplanTmpl> schoolplanTmplList = tTnSchoolplanTmplMapper.selectTTnSchoolplanTmplList(tTnSchoolplanTmpl);
            for (TTnSchoolplanTmpl t: schoolplanTmplList
            ) {
                t.setNewId(tTnNew.getNewId());
                tTnSchoolplanMapper.insertTTnSchoolplanTmpl(t);
            }
        }
        //转岗
        if (tTnNew.getPlanType() == 2) {
            TTnTransferplanTmpl tTnTransferplanTmpl = new TTnTransferplanTmpl();
            tTnTransferplanTmpl.setDeptId(tTnNew.getDeptId());
            List<TTnTransferplanTmpl> tTnTransferplanTmplList = tTnTransferplanTmplMapper.selectTTnTransferplanTmplList(tTnTransferplanTmpl);
            for (TTnTransferplanTmpl t: tTnTransferplanTmplList
            ) {
                t.setNewId(tTnNew.getNewId());
                tTnTransferplanMapper.insertTTnTransferplanTmpl(t);
            }

        }
        return 1;

    }

    /**
     * 修改新员工培训
     *
     * @param tTnNew 新员工培训
     * @return 结果
     */
    @Override
    public int updateTTnNew(TTnNew tTnNew)
    {
        return tTnNewMapper.updateTTnNew(tTnNew);
    }

    /**
     * 批量删除新员工培训
     *
     * @param newIds 需要删除的新员工培训ID
     * @return 结果
     */
    @Override
    public int deleteTTnNewByIds(Long[] newIds)
    {
        return tTnNewMapper.deleteTTnNewByIds(newIds);
    }

    /**
     * 删除新员工培训信息
     *
     * @param newId 新员工培训ID
     * @return 结果
     */
    @Override
    public int deleteTTnNewById(Long newId)
    {
        return tTnNewMapper.deleteTTnNewById(newId);
    }
}
