package com.keao.edu.user.controller;

import com.keao.edu.auth.api.client.SysUserFeignService;
import com.keao.edu.auth.api.entity.SysUser;
import com.keao.edu.common.controller.BaseController;
import com.keao.edu.common.entity.HttpResponseResult;
import com.keao.edu.common.page.PageInfo;
import com.keao.edu.common.page.QueryInfo;
import com.keao.edu.user.dto.ExamReviewDto;
import com.keao.edu.user.dto.ExamReviewRecordDto;
import com.keao.edu.user.entity.Employee;
import com.keao.edu.user.entity.ExamReview;
import com.keao.edu.user.page.ExamReviewQueryInfo;
import com.keao.edu.user.page.ExamReviewRecordQueryInfo;
import com.keao.edu.user.service.EmployeeService;
import com.keao.edu.user.service.ExamReviewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

@RestController
@RequestMapping("examReview")
@Api(tags = "评审服务")
public class ExamReviewController extends BaseController {

    @Autowired
    private ExamReviewService examReviewService;
    @Autowired
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private EmployeeService employeeService;

    @ApiOperation("分页查询评审结果")
    @GetMapping(value = "/list")
    public HttpResponseResult<PageInfo<ExamReviewDto>> getList(ExamReviewQueryInfo queryInfo) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(!sysUser.getIsSuperAdmin()){
            Employee employee = employeeService.get(sysUser.getId());
            if(Objects.nonNull(employee)){
                queryInfo.setOrganId(employee.getOrganId());
            }
        }
        return succeed(examReviewService.findExamResult(queryInfo));
    }

    @ApiOperation("监考页面分页查询评审结果")
    @GetMapping(value = "/queryExamReviewRecordList")
    public HttpResponseResult<PageInfo<ExamReviewRecordDto>> queryExamReviewRecordList(ExamReviewRecordQueryInfo queryInfo) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        queryInfo.setTeacherId(sysUser.getId());
        return succeed(examReviewService.queryExamReviewRecordList(queryInfo));
    }

    @ApiOperation("修改评审结果")
    @PostMapping(value = "/update")
    public HttpResponseResult update(ExamReview examReview){
        examReviewService.update(examReview);
        return succeed();
    }

    @ApiOperation("老师评审")
    @PostMapping(value = "/createExamReview")
    public HttpResponseResult createExamReview(ExamReview examReview){
        examReviewService.add(examReview);
        return succeed();
    }
}
