package com.ruoyi.business.test.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.business.test.domain.TestStudents;
import com.ruoyi.business.test.service.ITestStudentsService;
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/students")
public class TestStudentsController extends BaseController
{
    @Autowired
    private ITestStudentsService testStudentsService;

    /**
     * 查询学生列表
     */
    @SaCheckPermission("business:students:list")
    @GetMapping("/list")
    public TableDataInfo list(TestStudents testStudents)
    {
        startPage();
        List<TestStudents> list = testStudentsService.selectTestStudentsList(testStudents);
        return getDataTable(list);
    }

    /**
     * 导出学生列表
     */
    @SaCheckPermission("business:students:export")
    @Log(title = "学生", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestStudents testStudents)
    {
        List<TestStudents> list = testStudentsService.selectTestStudentsList(testStudents);
        ExcelUtil<TestStudents> util = new ExcelUtil<TestStudents>(TestStudents.class);
        util.exportExcel(response, list, "学生数据");
    }

    /**
     * 获取学生详细信息
     */
    @SaCheckPermission("business:students:query")
    @GetMapping(value = "/{studentId}")
    public AjaxResult getInfo(@PathVariable("studentId") Long studentId)
    {
        return success(testStudentsService.selectTestStudentsByStudentId(studentId));
    }

    /**
     * 新增学生
     */
    @SaCheckPermission("business:students:add")
    @Log(title = "学生", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TestStudents testStudents)
    {
        return toAjax(testStudentsService.insertTestStudents(testStudents));
    }

    /**
     * 修改学生
     */
    @SaCheckPermission("business:students:edit")
    @Log(title = "学生", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestStudents testStudents)
    {
        return toAjax(testStudentsService.updateTestStudents(testStudents));
    }

    /**
     * 删除学生
     */
    @SaCheckPermission("business:students:remove")
    @Log(title = "学生", businessType = BusinessType.DELETE)
	@DeleteMapping("/{studentIds}")
    public AjaxResult remove(@PathVariable Long[] studentIds)
    {
        return toAjax(testStudentsService.deleteTestStudentsByStudentIds(studentIds));
    }
}
