package com.template.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.template.mapper.SmartSubjectManageMapper;
import com.template.model.evaluate.student.SmartSubjectManage;
import com.template.model.result.PageUtils;
import com.template.services.SmartSubjectManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 平分项管理 服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2024-01-08
 */
@Service
public class SmartSubjectManageServiceImpl extends ServiceImpl<SmartSubjectManageMapper, SmartSubjectManage> implements SmartSubjectManageService {

    @Autowired
    private SmartSubjectManageMapper smartSubjectManageMapper;

    @Override
    public int insertSmartSubjectManage(SmartSubjectManage sa) {
        int result = smartSubjectManageMapper.insert(sa);
        return result;
    }

    @Override
    public int updateSmartSubjectManage(SmartSubjectManage sa) {
        int result = smartSubjectManageMapper.updateById(sa);
        return result;
    }

    @Override
    public PageUtils<SmartSubjectManage> queryPageSmartSubjectManage(int currentPage, int pageCount, QueryWrapper<SmartSubjectManage> queryWrapper) {
        Page<SmartSubjectManage> page = new Page<>(currentPage, pageCount);
        IPage<SmartSubjectManage> result = smartSubjectManageMapper.selectPage(page,queryWrapper);
        return new PageUtils<>(result);
    }

    @Override
    public int deleteSmartSubjectManageById(int id) {
        int result = smartSubjectManageMapper.deleteById(id);
        return result;
    }

    @Override
    public SmartSubjectManage getSmartSubjectManageById(int id) {
        SmartSubjectManage result = smartSubjectManageMapper.selectById(id);
        return result;
    }

    @Override
    public List<SmartSubjectManage> getSmartSubjectManageList() {
        QueryWrapper<SmartSubjectManage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted", 0);
        List<SmartSubjectManage> result = smartSubjectManageMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public List<SmartSubjectManage> getSmartSubjectManageByKey(QueryWrapper<SmartSubjectManage> queryWrapper) {
        List<SmartSubjectManage> result = smartSubjectManageMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public String getMaxTerm(){
        return smartSubjectManageMapper.getMaxTerm();
    }
}
