package org.jeecg.modules.ctop.controller;

import cn.com.ctop.manage.modules.edu.entity.EduLesson;
import cn.com.ctop.manage.modules.edu.service.IEduLessonService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

@Slf4j
@Api(tags="在线培训")
@RestController
@RequestMapping("/ctop/edu")
public class EduLessonController {
    @Autowired
    private IEduLessonService eduLessonService;
    @GetMapping(value = "/kuaishou/lesson")
    public Result<List<String>> getKuaishouLessonList(){
        Result<List<String>> result = new Result<>();
        List<String> list = eduLessonService.getTitleList("快手大学");
        result.setResult(list);
        result.setSuccess(true);
        return result;
    }
    @GetMapping(value = "/kuaishou/topic")
    public Result<List<String>> getKuaishouTopicList(String title){
        Result<List<String>> result = new Result<>();
        List<String> list = eduLessonService.getTopicList("快手大学",title);
        result.setResult(list);
        result.setSuccess(true);
        return result;
    }

    @GetMapping(value = "/system/lesson")
    public Result<List<String>> getSystemLessonList() {
        Result<List<String>> result = new Result<>();
        List<String> list = eduLessonService.getTitleList("汇创视频培训");
        result.setResult(list);
        result.setSuccess(true);
        return result;
    }

    @GetMapping(value = "/system/topic")
    public Result<List<String>> getSystemTopicList(String title) {
        Result<List<String>> result = new Result<>();
        List<String> list = eduLessonService.getTopicList("汇创视频培训", title);
        result.setResult(list);
        result.setSuccess(true);
        return result;
    }

    @GetMapping(value = "/ocean/lesson")
    public Result<List<String>> getOceanLessonList(){
        Result<List<String>> result = new Result<>();
        List<String> list = eduLessonService.getTitleList("巨量引擎");
        result.setResult(list);
        result.setSuccess(true);
        return result;
    }
    @GetMapping(value = "/ocean/topic")
    public Result<List<String>> getOceanTopicList(String title){
        Result<List<String>> result = new Result<>();
        List<String> list = eduLessonService.getTopicList("巨量引擎",title);
        result.setResult(list);
        result.setSuccess(true);
        return result;
    }
    @GetMapping(value = "/detail")
    public Result<EduLesson> detail(Long id){
        Result<EduLesson> result = new Result<>();
        EduLesson eduLesson = eduLessonService.getById(id);
        result.setResult(eduLesson);
        result.setSuccess(true);
        return result;
    }

    @GetMapping(value = "/lesson/list")
    public Result<List<EduLesson>> lessonList(String media, String title, String topic){
        Result<List<EduLesson>> result = new Result<>();
        QueryWrapper<EduLesson> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("media",media);
        queryWrapper.eq("title",title);
        queryWrapper.eq("topic",topic);
        List<EduLesson> list = eduLessonService.list(queryWrapper);
        result.setResult(list);
        result.setSuccess(true);
        return result;
    }

    @PostMapping(value = "/lesson/upload")
    public Result<Map<String, String>> updaloadLesson(@RequestBody EduLesson eduLesson) {
        Result<Map<String, String>> result = new Result();
        Map<String, String> resultMap = new HashMap<>();

        if (StringUtils.isBlank(eduLesson.getMedia()) || StringUtils.isBlank(eduLesson.getTitle()) ||
                StringUtils.isBlank(eduLesson.getTopic()) || StringUtils.isBlank(eduLesson.getName()) ||
                StringUtils.isBlank(eduLesson.getOssFileUrl()) || StringUtils.isBlank(eduLesson.getFileType())
        ) {
            result.error500("参数不可为空");
            return result;
        }
        String lessonId = eduLessonService.uploadLesson(eduLesson);

        resultMap.put("lessonId", lessonId);
        result.setResult(resultMap);
        result.setSuccess(true);

        return result;
    }
}
