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.SmartTemplateRuleMapper;
import com.template.model.evaluate.student.SmartTemplateRule;
import com.template.model.evaluate.student.SmartTemplateRule;
import com.template.model.result.PageUtils;
import com.template.model.vo.TemplateRuleVo;
import com.template.services.SmartTemplateRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 平分项管理 服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2024-03-14
 */
@Service
public class SmartTemplateRuleServiceImpl extends ServiceImpl<SmartTemplateRuleMapper, SmartTemplateRule> implements SmartTemplateRuleService {

    @Autowired
    private SmartTemplateRuleMapper smartTemplateRuleMapper;

    @Override
    public int insertSmartTemplateRule(SmartTemplateRule sa) {
        int result = smartTemplateRuleMapper.insert(sa);
        return result;
    }

    @Override
    public int updateSmartTemplateRule(SmartTemplateRule sa) {
        int result = smartTemplateRuleMapper.updateById(sa);
        return result;
    }

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

    @Override
    public int deleteSmartTemplateRuleById(int id) {
        int result = smartTemplateRuleMapper.deleteById(id);
        return result;
    }

    @Override
    public SmartTemplateRule getSmartTemplateRuleById(int id) {
        SmartTemplateRule result = smartTemplateRuleMapper.selectById(id);
        return result;
    }

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

    @Override
    public List<SmartTemplateRule> getSmartTemplateRuleByKey(QueryWrapper<SmartTemplateRule> queryWrapper) {
        List<SmartTemplateRule> result = smartTemplateRuleMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public List<TemplateRuleVo> queryTemplateRuleByIds(List<Integer> gradeIds, List<Integer> termIds) {
        List<TemplateRuleVo> result = smartTemplateRuleMapper.queryTemplateRuleByIds(gradeIds,termIds);
        return result;
    }

}
