package com.ruoyi.business.test.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.business.test.domain.TestStudentsScores;
import com.ruoyi.business.test.service.ITestStudentsScoresService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 学生成绩Controller
 * 
 * @author Duke_yzl
 * @date 2025-02-18
 */
@RestController
@RequestMapping("/business/studentsScores")
public class TestStudentsScoresController extends BaseController
{
    @Autowired
    private ITestStudentsScoresService testStudentsScoresService;

    /**
     * 查询学生成绩列表
     */
    @SaCheckPermission("business:studentsScores:list")
    @GetMapping("/list")
    public TableDataInfo list(TestStudentsScores testStudentsScores)
    {
        startPage();
        List<TestStudentsScores> list = testStudentsScoresService.selectTestStudentsScoresList(testStudentsScores);
        return getDataTable(list);
    }

    /**
     * 导出学生成绩列表
     */
    @SaCheckPermission("business:studentsScores:export")
    @Log(title = "学生成绩", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestStudentsScores testStudentsScores)
    {
        List<TestStudentsScores> list = testStudentsScoresService.selectTestStudentsScoresList(testStudentsScores);
        ExcelUtil<TestStudentsScores> util = new ExcelUtil<TestStudentsScores>(TestStudentsScores.class);
        util.exportExcel(response, list, "学生成绩数据");
    }

    /**
     * 获取学生成绩详细信息
     */
    @SaCheckPermission("business:studentsScores:query")
    @GetMapping(value = "/{scoreId}")
    public AjaxResult getInfo(@PathVariable("scoreId") Long scoreId)
    {
        return success(testStudentsScoresService.selectTestStudentsScoresByScoreId(scoreId));
    }

    /**
     * 新增学生成绩
     */
    @SaCheckPermission("business:studentsScores:add")
    @Log(title = "学生成绩", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TestStudentsScores testStudentsScores)
    {
        return toAjax(testStudentsScoresService.insertTestStudentsScores(testStudentsScores));
    }

    /**
     * 修改学生成绩
     */
    @SaCheckPermission("business:studentsScores:edit")
    @Log(title = "学生成绩", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestStudentsScores testStudentsScores)
    {
        return toAjax(testStudentsScoresService.updateTestStudentsScores(testStudentsScores));
    }

    /**
     * 删除学生成绩
     */
    @SaCheckPermission("business:studentsScores:remove")
    @Log(title = "学生成绩", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scoreIds}")
    public AjaxResult remove(@PathVariable Long[] scoreIds)
    {
        return toAjax(testStudentsScoresService.deleteTestStudentsScoresByScoreIds(scoreIds));
    }
}
