package com.sqx.modules.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.course.dao.CourseClassificationDao;
import com.sqx.modules.course.entity.CourseClassification;
import com.sqx.modules.course.response.ClassificationResponse;
import com.sqx.modules.course.service.CourseClassificationService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CourseClassificationServiceImpl extends ServiceImpl<CourseClassificationDao, CourseClassification> implements CourseClassificationService {
    @Override
    public Result insertCourseClassification(CourseClassification course) {
        course.setIsDelete(0);
        baseMapper.insert(course);
        return Result.success("操作成功！");
    }

    @Override
    public Result updateCourseClassification(CourseClassification course) {
        baseMapper.updateById(course);
        return Result.success("操作成功！");
    }

    @Override
    public Result updateDelete(Long id) {
        baseMapper.updateDelete(id);
        return Result.success("操作成功！");
    }

    @Override
    public Result selectCourseClassification(Integer page, Integer limit, String classificationName) {
        if (page == null) {
            page = 1;
        }
        if (limit == null) {
            limit = 10;
        }
        PageHelper.startPage(page, limit);
        List<Map<String, Object>> list = baseMapper.selectCourseClassificationList(classificationName);
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
        return Result.success().put("data", PageUtils.page(pageInfo));
    }

    @Override
    public CourseClassification selectCourseClassificationById(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    public List<Map<String, Object>> selectClassification() {
        return baseMapper.selectMaps(new QueryWrapper<CourseClassification>().eq("is_delete",0));
    }

    /**
     * 查询短剧的分类信息
     *
     * @return
     */
    @Override
    public List<ClassificationResponse> queryClassification() {
        return baseMapper.queryClassification();
    }


}
