package com.srs.teacher.service.impl;

import java.util.List;

import com.srs.common.exception.ServiceException;
import com.srs.common.utils.SecurityUtils;
import com.srs.teacher.domain.SysTeacherKpiFilling;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.srs.teacher.mapper.SysTeacherKpiFillingBusinessWorkMapper;
import com.srs.teacher.domain.SysTeacherKpiFillingBusinessWork;
import com.srs.teacher.service.ISysTeacherKpiFillingBusinessWorkService;

/**
 * 个人填报-业务工作Service业务层处理
 *
 * @author chc
 * @date 2024-06-07
 */
@Service
public class SysTeacherKpiFillingBusinessWorkServiceImpl extends ServiceImpl<SysTeacherKpiFillingBusinessWorkMapper, SysTeacherKpiFillingBusinessWork> implements ISysTeacherKpiFillingBusinessWorkService {
    @Autowired
    private SysTeacherKpiFillingBusinessWorkMapper sysTeacherKpiFillingBusinessWorkMapper;

    /**
     * 查询个人填报-业务工作
     *
     * @param id 个人填报-业务工作主键
     * @return 个人填报-业务工作
     */
    @Override
    public SysTeacherKpiFillingBusinessWork selectSysTeacherKpiFillingBusinessWorkById(Long id) {
        return sysTeacherKpiFillingBusinessWorkMapper.selectSysTeacherKpiFillingBusinessWorkById(id);
    }

    /**
     * 查询个人填报-业务工作列表
     *
     * @param sysTeacherKpiFillingBusinessWork 个人填报-业务工作
     * @return 个人填报-业务工作
     */
    @Override
    public List<SysTeacherKpiFillingBusinessWork> selectSysTeacherKpiFillingBusinessWorkList(SysTeacherKpiFillingBusinessWork sysTeacherKpiFillingBusinessWork) {
        sysTeacherKpiFillingBusinessWork.setFdyName(SecurityUtils.getLoginUser().getUser().getNickName());
        return sysTeacherKpiFillingBusinessWorkMapper.selectSysTeacherKpiFillingBusinessWorkList(sysTeacherKpiFillingBusinessWork);
    }

    /**
     * 根据辅导员名称、年份 月份 查询
     *
     * @param fdyName 辅导员名称主键
     * @return 个人填报-业务工作集合
     */
    @Override
    public List<SysTeacherKpiFillingBusinessWork> selectSysTeacherKpiFillingBusinessWorkByFdyName(String fdyName, String fillingYear, String fillingMonth, String classType) {
        return sysTeacherKpiFillingBusinessWorkMapper.selectSysTeacherKpiFillingBusinessWorkByFdyName(fdyName, fillingYear, fillingMonth, classType);
    }

    /**
     * 新增个人填报-业务工作
     *
     * @param sysTeacherKpiFillingBusinessWork 个人填报-业务工作
     * @return 结果
     */
    @Override
    public int insertSysTeacherKpiFillingBusinessWork(SysTeacherKpiFillingBusinessWork sysTeacherKpiFillingBusinessWork) {
        sysTeacherKpiFillingBusinessWork.setFdyName(SecurityUtils.getLoginUser().getUser().getNickName());
        if (sysTeacherKpiFillingBusinessWork.getId() != null) {
            return sysTeacherKpiFillingBusinessWorkMapper.updateSysTeacherKpiFillingBusinessWork(sysTeacherKpiFillingBusinessWork);
        }
        return sysTeacherKpiFillingBusinessWorkMapper.insertSysTeacherKpiFillingBusinessWork(sysTeacherKpiFillingBusinessWork);
    }

    /**
     * 修改个人填报-业务工作
     *
     * @param sysTeacherKpiFillingBusinessWork 个人填报-业务工作
     * @return 结果
     */
    @Override
    public int updateSysTeacherKpiFillingBusinessWork(SysTeacherKpiFillingBusinessWork sysTeacherKpiFillingBusinessWork) {
//        sysTeacherKpiFillingBusinessWork.setFdyName(SecurityUtils.getLoginUser().getUser().getNickName());
        // 判断填报记录是否填报
        /*List<SysTeacherKpiFillingBusinessWork> sysTeacherKpiFillingBusinessWorkList = sysTeacherKpiFillingBusinessWorkMapper.selectSysTeacherKpiFillingBusinessWorkByFdyName(sysTeacherKpiFillingBusinessWork.getFdyName(), sysTeacherKpiFillingBusinessWork.getFillingYear(), sysTeacherKpiFillingBusinessWork.getFillingMonth(), sysTeacherKpiFillingBusinessWork.getClassType());
        if (sysTeacherKpiFillingBusinessWorkList != null && !sysTeacherKpiFillingBusinessWorkList.isEmpty()) {
            throw new ServiceException("已提交，请勿重复提交", 500);
        }*/
        return sysTeacherKpiFillingBusinessWorkMapper.updateSysTeacherKpiFillingBusinessWork(sysTeacherKpiFillingBusinessWork);
    }

    /**
     * 批量删除个人填报-业务工作
     *
     * @param ids 需要删除的个人填报-业务工作主键
     * @return 结果
     */
    @Override
    public int deleteSysTeacherKpiFillingBusinessWorkByIds(Long[] ids) {
        return sysTeacherKpiFillingBusinessWorkMapper.deleteSysTeacherKpiFillingBusinessWorkByIds(ids);
    }

    /**
     * 删除个人填报-业务工作信息
     *
     * @param id 个人填报-业务工作主键
     * @return 结果
     */
    @Override
    public int deleteSysTeacherKpiFillingBusinessWorkById(Long id) {
        return sysTeacherKpiFillingBusinessWorkMapper.deleteSysTeacherKpiFillingBusinessWorkById(id);
    }
}
