package com.keao.edu.user.controller;

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.user.dto.BaseUserInfoDto;
import com.keao.edu.user.dto.ExamTeacherSalaryDto;
import com.keao.edu.user.dto.ExamTeacherSalaryStaticsInfo;
import com.keao.edu.user.dto.TeacherDto;
import com.keao.edu.user.entity.ExamTeacherSalary;
import com.keao.edu.user.page.ExamTeacherSalaryQueryInfo;
import com.keao.edu.user.service.ExamTeacherSalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @Author Joburgess
 * @Date 2020.07.01
 */
@RestController
@RequestMapping("examTeacherSalary")
@Api(tags = "考级项目教师服务")
public class ExamTeacherSalaryController extends BaseController {

    @Autowired
    private ExamTeacherSalaryService examTeacherSalaryService;

    @ApiOperation("分页查询")
    @GetMapping(value = "/list")
    public HttpResponseResult<PageInfo<ExamTeacherSalaryDto>> getList(ExamTeacherSalaryQueryInfo queryInfo) {
        return succeed(examTeacherSalaryService.queryExamTeacherSalary(queryInfo));
    }

    @ApiOperation("新增")
    @PostMapping(value = "/add")
    public HttpResponseResult add(ExamTeacherSalary examTeacherSalary) {
        examTeacherSalary.setTotalInvigilationNum(0);
        examTeacherSalary.setTotalInvigilationStudentNum(0);
        examTeacherSalary.setTotalSettlementCost(BigDecimal.ZERO);
        examTeacherSalaryService.insert(examTeacherSalary);
        return succeed();
    }

    @ApiOperation("新增考级教师")
    @PostMapping(value = "/addExamTeacherSalary")
    public HttpResponseResult addExamTeacherSalary(Long examId, String teacherIdsStr) {
        examTeacherSalaryService.addExamTeacherSalary(examId, teacherIdsStr);
        return succeed();
    }

    @ApiOperation("获取指定考级项目可排考教师")
    @GetMapping(value = "/getExamTeachers")
    public HttpResponseResult<List<BaseUserInfoDto>> getExamTeachers(Integer examId){
        return succeed(examTeacherSalaryService.getExamTeachers(examId));
    }

    @ApiOperation("更新")
    @PostMapping(value = "/update")
    public HttpResponseResult update(ExamTeacherSalary examTeacherSalary) {
        examTeacherSalary.setUpdateTime(new Date());
        examTeacherSalaryService.updateExamTeacherSalary(examTeacherSalary);
        return succeed();
    }

    @ApiOperation("删除")
    @PostMapping(value = "/del")
    public HttpResponseResult add(Long id) {
        examTeacherSalaryService.deleteExamTeacherSalary(id);
        return succeed();
    }

    @ApiOperation("获取与考级项目无关的教师")
    @GetMapping(value = "/getUnRelatedWithExamTeachers")
    public HttpResponseResult<PageInfo<TeacherDto>> getUnRelatedWithExamTeachers(ExamTeacherSalaryQueryInfo queryInfo){
        return succeed(examTeacherSalaryService.getUnRelatedWithExamTeachers(queryInfo));
    }

    @ApiOperation("获取考级项目关联教师统计信息")
    @GetMapping(value = "/getExamTeacherSalaryStaticsInfo")
    public HttpResponseResult<ExamTeacherSalaryStaticsInfo> getExamTeacherSalaryStaticsInfo(Integer examId){
        return succeed(examTeacherSalaryService.getExamTeacherSalaryStaticsInfo(examId));
    }

}
