package com.ym.mec.education.controller;

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.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.ym.mec.education.base.BaseResponse;
import com.ym.mec.education.base.PageResponse;
import com.ym.mec.education.entity.StudentCourseHomework;
import com.ym.mec.education.entity.SysUser;
import com.ym.mec.education.enums.ReturnCodeEnum;
import com.ym.mec.education.req.HomeWorkDetailReq;
import com.ym.mec.education.req.HomeWorkReq;
import com.ym.mec.education.req.MusicGroupReq;
import com.ym.mec.education.resp.HomeWrokResp;
import com.ym.mec.education.service.IStudentCourseHomeworkService;
import com.ym.mec.education.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @version V1.0
 * @Description: TODO
 * @date Date : 2019年09月27日 19:31
 */

@RestController
@RequestMapping("/api/homeWork")
@DefaultProperties(defaultFallback = "defaultFallback")
@Slf4j
public class HomeWorkController {


    @Autowired
    private IStudentCourseHomeworkService studentCourseHomeworkService;

    /**
     * 服务降级处理
     *
     * @return
     */
    private BaseResponse defaultFallback() {
        BaseResponse response = new BaseResponse();
        response.setReturnCode(500);
        response.setMessage("太拥挤了, 请稍后再试!");
        return response;
    }


    /**
     *
     * @param req
     * @return
     */
    @PostMapping(value = "/workList")
    public PageResponse workList(@RequestBody HomeWorkReq req) {

        return studentCourseHomeworkService.workList(req);
    }


    /**
     *
     * @param req
     * @return
     */
    @PostMapping(value = "/workDetail")
    public BaseResponse workDetail(@RequestBody HomeWorkDetailReq req) {
        BaseResponse baseResponse = new BaseResponse();
        if(req == null || req.getWorkId() == null){
            baseResponse.setReturnCode(ReturnCodeEnum.CODE_206.getCode());
            baseResponse.setMessage(ReturnCodeEnum.CODE_206.getValue());
            return baseResponse;
        }
        return studentCourseHomeworkService.getHomeWorkDetail(req);
    }


    /**
     *
     * @param req
     * @return
     */
    @PostMapping(value = "/homeWorkList")
    public PageResponse homeWorkList(@RequestBody HomeWorkReq req) {

       return studentCourseHomeworkService.homeWorkList(req);
    }
}
