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

import com.ruoyi.project.training.bccnew.domain.TTsFirstplan;
import com.ruoyi.project.training.bccnew.domain.TTsNew;
import com.ruoyi.project.training.bccnew.mapper.TTsFirstplanMapper;
import com.ruoyi.project.training.bccnew.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 进组培训Service业务层处理
 *
 * @author ssy
 * @date 2024-06-17
 */
@Service
public class TTsFirstplanServiceImpl implements ITTsFirstplanService {
    @Autowired
    private TTsFirstplanMapper tTsFirstplanMapper;

    @Autowired
    private ITTsLjplanService tTsLjplanService;

    @Autowired
    private ITTsYsplanService tTsYsplanService;

    @Autowired
    private ITTsFlplanService tTsFlplanService;

    @Autowired
    private ITTsFtplanService tTsFtplanService;

    @Autowired
    private ITTsNewService tTsNewService;

    @Autowired
    private ITTsApproveService tTsApproveService;

    /**
     * 查询进组培训
     *
     * @param id 进组培训ID
     * @return 进组培训
     */
    @Override
    public TTsFirstplan selectTTsFirstplanById(Long id) {
        return tTsFirstplanMapper.selectTTsFirstplanById(id);
    }

    @Override
    public List<TTsFirstplan> selectTTsFirstplanListByNewId(TTsFirstplan tTsFirstplan) {
        return tTsFirstplanMapper.selectTTsFirstplanListByNewId(tTsFirstplan);
    }

    /**
     * 查询进组培训列表
     *
     * @param tTsFirstplan 进组培训
     * @return 进组培训
     */
    @Override
    public List<TTsFirstplan> selectTTsFirstplanList(TTsFirstplan tTsFirstplan) {
        return tTsFirstplanMapper.selectTTsFirstplanList(tTsFirstplan);
    }

    /**
     * 新增进组培训
     *
     * @param tTsFirstplan 进组培训
     * @return 结果
     */
    @Override
    public int insertTTsFirstplan(TTsFirstplan tTsFirstplan) {
        return tTsFirstplanMapper.insertTTsFirstplan(tTsFirstplan);
    }

    /**
     * 修改进组培训
     *
     * @param tTsFirstplan 进组培训
     * @return 结果
     */
    @Override
    public int updateTTsFirstplan(TTsFirstplan tTsFirstplan) {
        TTsFirstplan firstplan = tTsFirstplanMapper.selectTTsFirstplanById(tTsFirstplan.getId());
        if ("合格".equals(tTsFirstplan.getScore1())) {
            tTsFirstplan.setPlanStatus(5L);
        }
        if (("不合格".equals(tTsFirstplan.getScore1())||"不合格".equals(firstplan.getScore1())) && "合格".equals(tTsFirstplan.getScore2())) {
            tTsFirstplan.setPlanStatus(5L);
        }
        if (("不合格".equals(tTsFirstplan.getScore1())||"不合格".equals(firstplan.getScore1()))&& "不合格".equals(tTsFirstplan.getScore2())) {
            tTsFirstplan.setPlanStatus(4L);
        }
        tTsFirstplanMapper.updateTTsFirstplan(tTsFirstplan);
        if (tTsFirstplan.getPlanStatus() != null) {
            if (tTsFirstplan.getPlanStatus() == 5) {
                TTsNew tTsNew = new TTsNew();
                tTsNew.setPlanStatus(5L);
                tTsNew.setNewId(tTsFirstplan.getNewId());
                tTsNewService.updateTTsNew(tTsNew, tTsFirstplan.getUserId(), tTsFirstplan.getNickName());
            } else if (tTsFirstplan.getPlanStatus() == 4) {
                TTsNew tTsNew = new TTsNew();
                tTsNew.setPlanStatus(4L);
                tTsNew.setNewId(tTsFirstplan.getNewId());
                tTsNewService.updateTTsNew(tTsNew, tTsFirstplan.getUserId(), tTsFirstplan.getNickName());
            }
        }
        return 1;
    }

    /**
     * 批量删除进组培训
     *
     * @param ids 需要删除的进组培训ID
     * @return 结果
     */
    @Override
    public int deleteTTsFirstplanByIds(Long[] ids) {
        return tTsFirstplanMapper.deleteTTsFirstplanByIds(ids);
    }

    /**
     * 删除进组培训信息
     *
     * @param id 进组培训ID
     * @return 结果
     */
    @Override
    public int deleteTTsFirstplanById(Long id) {
        return tTsFirstplanMapper.deleteTTsFirstplanById(id);
    }
}
