package com.srs.teacher.service.impl;

import java.util.List;

import com.srs.common.exception.ServiceException;
import com.srs.common.utils.SecurityUtils;
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.SysPerformanceMapper;
import com.srs.teacher.domain.SysPerformance;
import com.srs.teacher.service.ISysPerformanceService;

/**
 * 综合绩效Service业务层处理
 *
 * @author srs
 * @date 2024-06-17
 */
@Service
public class SysPerformanceServiceImpl extends ServiceImpl<SysPerformanceMapper, SysPerformance> implements ISysPerformanceService {
    @Autowired
    private SysPerformanceMapper sysPerformanceMapper;

    /**
     * 查询综合绩效
     *
     * @param id 综合绩效主键
     * @return 综合绩效
     */
    @Override
    public SysPerformance selectSysPerformanceById(Long id) {
        return sysPerformanceMapper.selectSysPerformanceById(id);
    }

    /**
     * 查询综合绩效列表
     *
     * @param sysPerformance 综合绩效
     * @return 综合绩效
     */
    @Override
    public List<SysPerformance> selectSysPerformanceList(SysPerformance sysPerformance) {
        return sysPerformanceMapper.selectSysPerformanceList(sysPerformance);
    }

    /**
     * 新增综合绩效
     *
     * @param sysPerformance 综合绩效
     * @return 结果
     */
    @Override
    public int insertSysPerformance(SysPerformance sysPerformance) {

        sysPerformance.setCreditPass(SecurityUtils.getLoginUser().getUser().getUserName());
        //2025 6-21 改：前端传的部门名称不对，改用后端写
        sysPerformance.setCollege(SecurityUtils.getLoginUser().getUser().getDept().getDeptName());
        sysPerformance.setFdName(SecurityUtils.getLoginUser().getUser().getNickName());
//       判断年份数据是否已存在
        SysPerformance sysPerformance1 = sysPerformanceMapper.selectSysPerformanceByYears(sysPerformance.getYears(), sysPerformance.getFdName());
        if (sysPerformance1 != null) {
            throw new ServiceException("申请已提交，请勿重复提交", 500);
        }

        return sysPerformanceMapper.insertSysPerformance(sysPerformance);
    }

    /**
     * 修改综合绩效
     *
     * @param sysPerformance 综合绩效
     * @return 结果
     */
    @Override
    public int updateSysPerformance(SysPerformance sysPerformance) {
        return sysPerformanceMapper.updateSysPerformance(sysPerformance);
    }

    /**
     * 批量删除综合绩效
     *
     * @param ids 需要删除的综合绩效主键
     * @return 结果
     */
    @Override
    public int deleteSysPerformanceByIds(Long[] ids) {
        return sysPerformanceMapper.deleteSysPerformanceByIds(ids);
    }

    /**
     * 删除综合绩效信息
     *
     * @param id 综合绩效主键
     * @return 结果
     */
    @Override
    public int deleteSysPerformanceById(Long id) {
        return sysPerformanceMapper.deleteSysPerformanceById(id);
    }
}
