package com.srs.web.controller.comprehensive;

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

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.SrsSportTestStudent;
import com.srs.comprehensive.domain.Vo.stuYearStudentUser;
import com.srs.comprehensive.service.ISrsSportTestService;
import com.srs.comprehensive.service.ISumSportTestService;
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
 */
@RestController
@RequestMapping("/system/sportTest")
public class SrsSportTestController extends BaseController
{
    @Autowired
    private ISrsSportTestService srsSportTestService;
    @Autowired
    private ISumSportTestService sumSportTestService;



    @PostMapping("/editStuScore")
    @ApiOperation("更新学生体测成绩")
    public AjaxResult editStuScore(@RequestBody SrsSportTest param){
        return srsSportTestService.editStuScore(param);
    }


    /**
     * 查询体能测试列表
     */
//    @PreAuthorize("@ss.hasPermi('system:sportTest:list')")
    @GetMapping("/list")
    public TableDataInfo list(SrsSportTest srsSportTest)
    {
        startPage();
        List<SrsSportTest> list = srsSportTestService.selectSrsSportTestList(srsSportTest);
        return getDataTable(list);
    }

    /**
     * 导出体能测试列表
     */
//    @PreAuthorize("@ss.hasPermi('system:sportTest:export')")
    @Log(title = "体能测试", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrsSportTest srsSportTest, stuYearStudentUser stuYearStudentUser)
    {
        if (stuYearStudentUser != null) {
            srsSportTest.setStuYearId(stuYearStudentUser.getStuYearId());
            SrsStudent srsStudent = new SrsStudent();
            if (stuYearStudentUser.getClassId() != null){
                srsStudent.setClassId(stuYearStudentUser.getClassId());
            }
            if (stuYearStudentUser.getStuNo() != null){
                srsStudent.setStuNo(stuYearStudentUser.getStuNo());
            }
            if (stuYearStudentUser.getName() != null){
                srsStudent.setName("%" + stuYearStudentUser.getName() + "%");
            }
            srsSportTest.setStudent(srsStudent);
            // 添加学院和专业的查询条件
            srsSportTest.setDeptId(stuYearStudentUser.getDeptId());
            srsSportTest.setMajorId(stuYearStudentUser.getMajorId());
        }
        List<SrsSportTest> list = srsSportTestService.selectSrsSportTestList(srsSportTest);
        ExcelUtil<SrsSportTest> util = new ExcelUtil<SrsSportTest>(SrsSportTest.class);
        util.exportExcel(response, list, "体能测试数据");
    }

    /**
     * 获取体能测试详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:sportTest:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(srsSportTestService.selectSrsSportTestById(id));
    }

    /**
     * 新增体能测试
     */
//    @PreAuthorize("@ss.hasPermi('system:sportTest:add')")
    @Log(title = "体能测试", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrsSportTest srsSportTest)
    {
        return toAjax(srsSportTestService.insertSrsSportTest(srsSportTest));
    }

    /**
     * 修改体能测试
     */
//    @PreAuthorize("@ss.hasPermi('system:sportTest:edit')")
    @Log(title = "体能测试", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody SrsSportTest srsSportTest)
    {
        return toAjax(srsSportTestService.updateSrsSportTest(srsSportTest));
    }

    /**
     * 删除体能测试
     */
//    @PreAuthorize("@ss.hasPermi('system:sportTest:remove')")
    @Log(title = "体能测试", businessType = BusinessType.DELETE)
	@PostMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(srsSportTestService.deleteSrsSportTestByIds(ids));
    }
    /**
     * 体能测试批量新增
     */
    @ApiOperation("批量导入体能测试成绩")
    @PostMapping("/addSrsCourseScore")
    public AjaxResult adds(@RequestBody List<SrsSportTestStudent> srsSportTestStudent){
        return toAjax(srsSportTestService.insertSrsSportTestStudent(srsSportTestStudent));
    }
    /**
     * 体能测试中间表添加接口
     */
    @ApiOperation("体能测试中间表添加")
    @PostMapping("/addSumTest")
    public AjaxResult addSumTest(){
        List<String> strings = srsSportTestService.addSrsSportTest();
        return success("解析成功").put("添加失败的学号： ", strings);
    }
}
