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.model.pojo.SmartSubject;
import com.template.model.pojo.SmartSubject;
import com.template.mapper.SmartSubjectMapper;
import com.template.model.pojo.SmartUser;
import com.template.model.result.PageUtils;
import com.template.model.vo.TimeGroupVo;
import com.template.services.SmartSubjectService;
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-07
 */
@Service
public class SmartSubjectServiceImpl extends ServiceImpl<SmartSubjectMapper, SmartSubject> implements SmartSubjectService {
    @Autowired
    private SmartSubjectMapper smartSubjectMapper;

    @Override
    public int insertSmartSubject(SmartSubject sa) {
        int result = smartSubjectMapper.insert(sa);
        return result;
    }

    @Override
    public int updateSmartSubject(SmartSubject sa) {
        int result = smartSubjectMapper.updateById(sa);
        return result;
    }

    @Override
    public SmartSubject querySubjectByName(String name){
        QueryWrapper<SmartSubject> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name);
        SmartSubject result = smartSubjectMapper.selectOne(queryWrapper);
        return result;
    }

    @Override
    public PageUtils<SmartSubject> queryPageSmartSubjects(int currentPage, int pageCount, String name) {
        Page<SmartSubject> page = new Page<>(currentPage, pageCount);
        QueryWrapper<SmartSubject> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.hasText(name), "name", name);
        IPage<SmartSubject> result = smartSubjectMapper.selectPage(page,queryWrapper);
        return new PageUtils<>(result);
    }

    @Override
    public int deleteSmartSubjectById(int id) {
        int result = smartSubjectMapper.deleteById(id);
        return result;
    }

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

    @Override
    public List<SmartSubject> queryAppletSubjects() {
        QueryWrapper<SmartSubject> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne("category", "管理后台");
        List<SmartSubject> result = smartSubjectMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public List<SmartSubject> getSmartSubjectIds(List<String> ids) {
        QueryWrapper<SmartSubject> queryWrapper = new QueryWrapper();
        queryWrapper.in("id", ids);
        List<SmartSubject> result = smartSubjectMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public List<SmartSubject> getSmartSubjectId(List<Integer> ids) {
        QueryWrapper<SmartSubject> queryWrapper = new QueryWrapper();
        queryWrapper.in("id", ids);
        List<SmartSubject> result = smartSubjectMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public List<TimeGroupVo> queryGradeSubjects(String grade) {

        List<TimeGroupVo> subjects = smartSubjectMapper.queryGradeSubjects(grade);
        return subjects;
    }
}
