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.SmartEvaluateTdetailMapper;
import com.template.model.evaluate.teacher.SmartEvaluateTdetail;
import com.template.model.result.PageUtils;
import com.template.services.SmartEvaluateTdetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 评分表 服务实现类
 * </p>
 *
 * @author ceshi
 * @since 2024-01-02
 */
@Service
public class SmartEvaluateTdetailServiceImpl extends ServiceImpl<SmartEvaluateTdetailMapper, SmartEvaluateTdetail> implements SmartEvaluateTdetailService {

    @Autowired
    private SmartEvaluateTdetailMapper smartEvaluateTdetailMapper;

    @Override
    public int insertSmartEvaluateTdetail(SmartEvaluateTdetail sa) {
        int result = smartEvaluateTdetailMapper.insert(sa);
        return result;
    }

    @Override
    public int updateSmartEvaluateTdetail(SmartEvaluateTdetail sa) {
        int result = smartEvaluateTdetailMapper.updateById(sa);
        return result;
    }

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

    @Override
    public int deleteSmartEvaluateTdetailById(int id) {
        int result = smartEvaluateTdetailMapper.deleteById(id);
        return result;
    }

    @Override
    public SmartEvaluateTdetail getSmartEvaluateTdetailById(int id) {
        SmartEvaluateTdetail result = smartEvaluateTdetailMapper.selectById(id);
        return result;
    }

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

    @Override
    public List<SmartEvaluateTdetail> getEvaluateTdetailByKey(QueryWrapper<SmartEvaluateTdetail> queryWrapper) {
        List<SmartEvaluateTdetail> result = smartEvaluateTdetailMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public Double getAvgEvaluateScore(String term, String scoreItem){
        return smartEvaluateTdetailMapper.getAvgEvaluateScore(term, scoreItem);
    }
}
