package com.srs.web.controller.comprehensive;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.srs.comprehensive.domain.SrsCourseScore;
import com.srs.comprehensive.domain.SrsSportTest;
import com.srs.comprehensive.domain.SrsStudent;
import com.srs.comprehensive.domain.Vo.SreCourseScoreStudent;
import com.srs.comprehensive.domain.Vo.SrsCourseScoreStudentStuYear;
import com.srs.comprehensive.domain.Vo.stuYearStudentUser;
import com.srs.comprehensive.service.ISrsCourseScoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.enums.BusinessType;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.core.page.TableDataInfo;

/**
 * 【课程学习】Controller
 *
 * @author srs
 * @date 2023-06-28
 */
@Api("课程学习")
@RestController
@RequestMapping("/system/score")
public class SrsCourseScoreController extends BaseController {
    @Autowired
    private ISrsCourseScoreService srsCourseScoreService;

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SrsCourseScore srsCourseScore) {
        startPage();
        List<SrsCourseScore> list = srsCourseScoreService.selectSrsCourseScoreList(srsCourseScore);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrsCourseScore srsCourseScore) {
        List<SrsCourseScore> list = srsCourseScoreService.selectSrsCourseScoreList(srsCourseScore);
        ExcelUtil<SrsCourseScore> util = new ExcelUtil<SrsCourseScore>(SrsCourseScore.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(srsCourseScoreService.selectSrsCourseScoreById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrsCourseScore srsCourseScore) {
        return toAjax(srsCourseScoreService.insertSrsCourseScore(srsCourseScore));
    }

    /**
     * 学生课程批量新增
     */
    @ApiOperation("批量导入学生课表")
    @PostMapping("/addSrsCourseScore")
    public AjaxResult adds(@RequestBody List<SreCourseScoreStudent> sreCourseScoreStudent) {
        return toAjax(srsCourseScoreService.forInsertSrsCourseScore(sreCourseScoreStudent));
    }

    /**
     * 修改【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody SrsCourseScore srsCourseScore) {
        return toAjax(srsCourseScoreService.updateSrsCourseScore(srsCourseScore));
    }

    /**
     * 删除【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(srsCourseScoreService.deleteSrsCourseScoreByIds(ids));
    }

    /**
     * 课堂学习连表查询
     */
    @ApiOperation("科学文化素质连表查询")
    @GetMapping("/selectSrsCourseScoreStudentStuYear")
    public TableDataInfo selectSrsCourseScoreStudentStuYear(stuYearStudentUser cphIamStudentUser) {
        startPage();
        SrsCourseScore srsCourseScore = new SrsCourseScore();
        srsCourseScore.setStuYearId(cphIamStudentUser.getStuYearId());
        SrsStudent srsStudent = new SrsStudent();
        if (cphIamStudentUser.getClassId() != null){
            srsStudent.setClassId(cphIamStudentUser.getClassId());
        }
        if (cphIamStudentUser.getStuNo()!= null){
            srsStudent.setStuNo(cphIamStudentUser.getStuNo());
        }
        if (cphIamStudentUser.getName()!= null){
            cphIamStudentUser.setName("%"+cphIamStudentUser.getName()+"%");
            srsStudent.setName(cphIamStudentUser.getName());
        }
        srsCourseScore.setStudent(srsStudent);
        if (cphIamStudentUser.getAvgScoreFrom()!= null) {
            srsCourseScore.setAvgScoreFrom(cphIamStudentUser.getAvgScoreFrom());
        }
        if (cphIamStudentUser.getAvgScoreTo() != null){
            srsCourseScore.setAvgScoreTo(cphIamStudentUser.getAvgScoreTo());
        }

        List<SrsCourseScoreStudentStuYear> srsCourseScoreStudentStuYears = srsCourseScoreService.selectSrsCourseScoreStudentStuYear(srsCourseScore);
        return getDataTable(srsCourseScoreStudentStuYears);
    }

    /*
      体能测试连表查询
     */
    @ApiOperation("体能测试连表查询")
    @GetMapping("/selectSrsSportTestStudentStuYear")
    public TableDataInfo selectSrsSportTestStudentStuYear(stuYearStudentUser cphIamStudentUser) {
        startPage();
        SrsSportTest srsSportTest = new SrsSportTest();
        srsSportTest.setStuYearId(cphIamStudentUser.getStuYearId());
        SrsStudent srsStudent = new SrsStudent();
        if (cphIamStudentUser.getClassId() != null){
            srsStudent.setClassId(cphIamStudentUser.getClassId());
        }
        if (cphIamStudentUser.getStuNo()!= null){
            srsStudent.setStuNo(cphIamStudentUser.getStuNo());
        }
        if (cphIamStudentUser.getName()!= null){
            cphIamStudentUser.setName("%"+cphIamStudentUser.getName()+"%");
            srsStudent.setName(cphIamStudentUser.getName());
        }
        srsSportTest.setStudent(srsStudent);
        if (cphIamStudentUser.getTestScoreFrom()!= null) {
            srsSportTest.setTestScoreFrom(cphIamStudentUser.getTestScoreFrom());
        }
        if (cphIamStudentUser.getTestScoreTo() != null){
            srsSportTest.setTestScoreTo(cphIamStudentUser.getTestScoreTo());
        }
        return getDataTable(srsCourseScoreService.selectSrsSportTestStudentStuYear(srsSportTest));
    }

    /**
     * 课堂学习连表查询
     */
    @ApiOperation("课程学习连表查询")
    @PostMapping("/serectStuYearCourseScoreStudent")
    public TableDataInfo selectTable() {
        startPage();
        return getDataTable(srsCourseScoreService.selectStuYearStudent());
    }

    @ApiOperation(value = "课程学习成绩排名", notes = "组合查询条件，如果什么都不填就是查询全部\n"
            + "请求示例：\n"
            + "{\n"
            + "  \"params\": {\n"
            + "    \"sortType\": 0, // 排序方式 0 倒序 1 正序\n"
            + "    \"stuId\": 0, // 学生id\n"
            + "    \"classId\": 0, // 班级id\n"
            + "    \"deptId\": 0, // 学院id\n"
            + "    \"gradeId\": 0, // 年级id\n"
            + "    \"stuYearId\": 0, // 学年id\n"
            + "    \"majorId\": 0 // 专业id\n"
            + "  }\n"
            + "}")
    @PostMapping("/gradeRanking")
    public TableDataInfo gradeRanking(@RequestBody SrsCourseScore srsCourseScore) {
        startPage();
        return getDataTable(srsCourseScoreService.gradeRanking(srsCourseScore));
    }

    @ApiOperation("课程学习中间表数据添加到本地")
    @PostMapping("/addCourseScoreData")
    public AjaxResult addCourseScore(){
        return success("解析成功").put("添加失败的学号： ", srsCourseScoreService.addCourseScoreData());
    }
}
