package com.taais.demo.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.taais.common.core.core.domain.CommonResult;
import com.taais.common.core.utils.poi.ExcelUtil;
import com.taais.common.web.core.BaseController;
import com.taais.demo.domain.DemoStudent;
import com.taais.demo.service.IDemoStudentService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 学生信息单表(mb)Controller
 *
 * @author wgk
 * 2023-07-11
 */
@RestController
@RequestMapping("/demo/student")
public class DemoStudentController extends BaseController {
    @Resource
    private IDemoStudentService demoStudentService;

    /**
     * 查询学生信息单表(mb)列表
     */
    @SaCheckPermission("demo:student:list")
    @GetMapping("/list")
    public CommonResult<List<DemoStudent>> list(DemoStudent demoStudent) {
        List<DemoStudent> list = demoStudentService.selectDemoStudentList(demoStudent);
        return CommonResult.success(list);
    }

    /**
     * 导出学生信息单表(mb)列表
     */
    @SaCheckPermission("demo:student:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, DemoStudent demoStudent) {
        List<DemoStudent> list = demoStudentService.selectDemoStudentList(demoStudent);
        ExcelUtil<DemoStudent> util = new ExcelUtil<>(DemoStudent.class);
        util.exportExcel(response, list, "学生信息单表(mb)数据");
    }

    /**
     * 获取学生信息单表(mb)详细信息
     */
    @SaCheckPermission("demo:student:query")
    @GetMapping(value = "/{studentId}")
    public CommonResult<DemoStudent> getInfo(@PathVariable("studentId") Long studentId) {
        return CommonResult.success(demoStudentService.selectDemoStudentByStudentId(studentId));
    }

    /**
     * 新增学生信息单表(mb)
     */
    @SaCheckPermission("demo:student:add")
    @PostMapping
    public CommonResult<Integer> add(@RequestBody DemoStudent demoStudent) {
        return CommonResult.success(demoStudentService.insertDemoStudent(demoStudent));
    }

    /**
     * 修改学生信息单表(mb)
     */
    @SaCheckPermission("demo:student:edit")
    @PutMapping
    public CommonResult<Integer> edit(@RequestBody DemoStudent demoStudent) {
        return CommonResult.success(demoStudentService.updateDemoStudent(demoStudent));
    }

    /**
     * 删除学生信息单表(mb)
     */
    @SaCheckPermission("demo:student:remove")
    @DeleteMapping("/{studentIds}")
    public CommonResult<Integer> remove(@PathVariable Long[] studentIds) {
        return CommonResult.success(demoStudentService.deleteDemoStudentByStudentIds(studentIds));
    }
}
