package com.ym.mec.web.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.page.CourseHomeWorkTemplateQueryInfo;
import com.ym.mec.biz.dal.page.StudentCourseHomeWorkQueryInfo;
import com.ym.mec.biz.service.CourseHomeworkService;
import com.ym.mec.biz.service.OrganizationService;
import com.ym.mec.biz.service.StudentCourseHomeworkService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import com.ym.mec.util.date.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author zouxuan
 * @Date 2020/11/17
 */
@RequestMapping("webCurseHomework")
@Api(tags = "课后作业")
@RestController
public class WebCourseHomeworkController extends BaseController {

    @Autowired
    private CourseHomeworkService courseHomeworkService;
    @Autowired
    private OrganizationService organizationService;
    @Autowired
    private StudentCourseHomeworkService studentCourseHomeworkService;

    @ApiOperation(value = "分页查询作业列表")
    @GetMapping(value = "/queryHomePage")
    public Object queryPage(CourseHomeWorkTemplateQueryInfo queryInfo){
        queryInfo.setOrganId(organizationService.getEmployeeOrgan(queryInfo.getOrganId()));
        return succeed(courseHomeworkService.queryHomePage(queryInfo));
    }


    @ApiOperation(value = "获取学生作业记录")
    @GetMapping(value = "/getStudentHomeWorks")
    @PreAuthorize("@pcs.hasPermissions('webCurseHomework/getStudentHomeWorks')")
    public HttpResponseResult getStudentHomeWorks(StudentCourseHomeWorkQueryInfo queryInfo){
        if (queryInfo.getStartTime() != null) {
            queryInfo.setStartTime(DateUtil.trunc(queryInfo.getStartTime()));
        }
        if (queryInfo.getEndTime() != null) {
            queryInfo.setEndTime(DateUtil.getLastTimeWithDay(queryInfo.getEndTime()));
        }
        return succeed(studentCourseHomeworkService.getStudentHomeWorks(queryInfo));
    }

}
