package com.srs.comprehensive.service.impl;

import java.util.List;

import com.srs.comprehensive.domain.CphCardersStudent;
import com.srs.comprehensive.mapper.CphCardersStudentMapper;
import com.srs.comprehensive.service.ICphCardersStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * 学生干部关联Service业务层处理
 *
 * @author srs
 * @date 2023-09-15
 */
@Service
public class CphCardersStudentServiceImpl extends ServiceImpl<CphCardersStudentMapper,CphCardersStudent> implements ICphCardersStudentService {
    @Autowired
    private CphCardersStudentMapper cphCardersStudentMapper;

    /**
     * 查询学生干部关联
     *
     * @param id 学生干部关联主键
     * @return 学生干部关联
     */
    @Override
    public CphCardersStudent selectCphCardersStudentById(Long id) {
        return cphCardersStudentMapper.selectCphCardersStudentById(id);
    }

    /**
     * 查询学生干部关联列表
     *
     * @param cphCardersStudent 学生干部关联
     * @return 学生干部关联
     */
    @Override
    public List<CphCardersStudent> selectCphCardersStudentList(CphCardersStudent cphCardersStudent) {
        return cphCardersStudentMapper.selectCphCardersStudentList(cphCardersStudent);
    }

    /**
     * 新增学生干部关联
     *
     * @param cphCardersStudent 学生干部关联
     * @return 结果
     */
    @Override
    public int insertCphCardersStudent(CphCardersStudent cphCardersStudent) {
        List<CphCardersStudent> students = lambdaQuery()
                .eq(CphCardersStudent::getStuNo, cphCardersStudent.getStuNo())
                .select(CphCardersStudent::getStuNo)
                .list();
        if (!students.isEmpty()) throw new RuntimeException("操作失败，请刷新页面再重试");
        return cphCardersStudentMapper.insertCphCardersStudent(cphCardersStudent);
    }

    /**
     * 修改学生干部关联
     *
     * @param cphCardersStudent 学生干部关联
     * @return 结果
     */
    @Override
    public int updateCphCardersStudent(CphCardersStudent cphCardersStudent) {
        List<CphCardersStudent> students = lambdaQuery()
                .eq(CphCardersStudent::getId,cphCardersStudent.getId())
                .eq(CphCardersStudent::getStuNo, cphCardersStudent.getStuNo())
                .eq(CphCardersStudent::getCarderId,cphCardersStudent.getCarderId())
                .select(CphCardersStudent::getStuNo)
                .list();
        if (!students.isEmpty()) throw new RuntimeException("操作失败，请不要重复提交相同请求");
        return cphCardersStudentMapper.updateCphCardersStudent(cphCardersStudent);
    }

    /**
     * 批量删除学生干部关联
     *
     * @param ids 需要删除的学生干部关联主键
     * @return 结果
     */
    @Override
    public int deleteCphCardersStudentByIds(Long[] ids) {
        return cphCardersStudentMapper.deleteCphCardersStudentByIds(ids);
    }

    /**
     * 删除学生干部关联信息
     *
     * @param id 学生干部关联主键
     * @return 结果
     */
    @Override
    public int deleteCphCardersStudentById(Long id) {
        return cphCardersStudentMapper.deleteCphCardersStudentById(id);
    }
}
