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.template.mapper.SmartExamtypeMapper;
import com.template.model.pojo.SmartExamtype;
import com.template.model.result.PageUtils;
import com.template.services.SmartExamtypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 考试类型表 服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2024-03-12
 */
@Service
public class SmartExamtypeServiceImpl extends ServiceImpl<SmartExamtypeMapper, SmartExamtype> implements SmartExamtypeService {
    @Autowired
    private SmartExamtypeMapper smartExamtypeMapper;

    @Override
    public int insertSmartExamtype(SmartExamtype sa) {
        int result = smartExamtypeMapper.insert(sa);
        return result;
    }

    @Override
    public int updateSmartExamtype(SmartExamtype sa) {
        int result = smartExamtypeMapper.updateById(sa);
        return result;
    }

    @Override
    public PageUtils<SmartExamtype> queryPageSmartExamtypes(int currentPage, int pageCount, String name, Integer gradeId) {
        Page<SmartExamtype> page = new Page<>(currentPage, pageCount);
        QueryWrapper<SmartExamtype> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.hasText(name), "name", name);
        queryWrapper.like(gradeId != null, "grade_id", gradeId);
        IPage<SmartExamtype> result = smartExamtypeMapper.selectPage(page,queryWrapper);
        return new PageUtils<>(result);
    }

    @Override
    public int deleteSmartExamtypeById(int id) {
        int result = smartExamtypeMapper.deleteById(id);
        return result;
    }

    @Override
    public SmartExamtype getSmartById(int id) {
        SmartExamtype result = smartExamtypeMapper.selectById(id);
        return result;
    }

    @Override
    public List<SmartExamtype> getSmartByGradeId(int gradeId) {
        QueryWrapper<SmartExamtype> query = new QueryWrapper<>();
        query.eq(gradeId > 0, "grade_id", gradeId);
        List<SmartExamtype> result = smartExamtypeMapper.selectList(query);
        return result;
    }

    @Override
    public List<SmartExamtype> getSmartByIds(List<String> ids) {
        QueryWrapper<SmartExamtype> query = new QueryWrapper<>();
        query.in(ids != null && ids.size() > 0, "id", ids);
        List<SmartExamtype> result = smartExamtypeMapper.selectList(query);
        return result;
    }

    @Override
    public List<SmartExamtype> getSmartByIdes(List<Integer> ids) {
        QueryWrapper<SmartExamtype> query = new QueryWrapper<>();
        query.in(ids != null && ids.size() > 0, "id", ids);
        List<SmartExamtype> result = smartExamtypeMapper.selectList(query);
        return result;
    }
}
