package com.srs.web.controller.comprehensive;

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

import com.srs.system.service.ISysPostService;
import com.srs.web.controller.common.RoleBool;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;

import com.srs.comprehensive.domain.ViewStuInfo;
import com.srs.comprehensive.service.IViewStuInfoService;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.enums.BusinessType;
import com.srs.common.annotation.Log;
import com.srs.common.core.page.TableDataInfo;

/**
 * 学生信息视图Controller
 *
 * @author srs
 * @date 2024-04-07
 */
@RestController
@RequestMapping("/comprehensive/stuInfoView")
@Api(value = "学生信息视图管理", tags = "学生信息视图管理")
public class ViewStuInfoController extends BaseController {
    @Autowired
    private IViewStuInfoService viewStuInfoService;

    @Autowired
    ISysPostService _postService;

    @GetMapping("/getStuInfo/{stuNo}")
    @ApiOperation("查询学生自己的信息视图")
    public AjaxResult getStuInfo(@PathVariable("stuNo") String stuNo) {
        boolean hasRole = RoleBool.isHigh(getUserId(), _postService);
        if (hasRole) {
            ViewStuInfo res = viewStuInfoService.getStuInfo(stuNo);
            return AjaxResult.success(res);
        } else {
            return AjaxResult.error(401, "你无权做这些");
        }
    }

    @GetMapping("/getOwnInfo")
    @ApiOperation("查询学生自己的信息视图")
    public AjaxResult getOwnInfo() {
        ViewStuInfo res = viewStuInfoService.getStuInfo(getUsername());
        return AjaxResult.success(res);
    }


    /**
     * 查询学生信息视图列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:stuInfoView:list')")
    @GetMapping("/list")
    @ApiOperation("查询学生信息视图列表")
    public TableDataInfo list(ViewStuInfo viewStuInfo) {
        startPage();
        List<ViewStuInfo> list = viewStuInfoService.selectViewStuInfoList(viewStuInfo);
        return getDataTable(list);
    }

    /**
     * 导出学生信息视图列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:stuInfoView:export')")
    @Log(title = "学生信息视图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出学生信息视图列表")
    public void export(HttpServletResponse response, ViewStuInfo viewStuInfo) {
        List<ViewStuInfo> list = viewStuInfoService.selectViewStuInfoList(viewStuInfo);
        ExcelUtil<ViewStuInfo> util = new ExcelUtil<ViewStuInfo>(ViewStuInfo.class);
        util.exportExcel(response, list, "学生信息视图数据");
    }

    /**
     * 获取学生信息视图详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:stuInfoView:query')")
    @GetMapping(value = "/{stuId}")
    @ApiOperation("获取学生信息视图详细信息")
    public AjaxResult getInfo(@PathVariable("stuId") Long stuId) {
        return success(viewStuInfoService.selectViewStuInfoByStuId(stuId));
    }

    /**
     * 新增学生信息视图
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:stuInfoView:add')")
    @Log(title = "学生信息视图", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增学生信息视图")
    public AjaxResult add(@RequestBody ViewStuInfo viewStuInfo) {
        return toAjax(viewStuInfoService.insertViewStuInfo(viewStuInfo));
    }

    /**
     * 修改学生信息视图
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:stuInfoView:edit')")
    @Log(title = "学生信息视图", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改学生信息视图")
    public AjaxResult edit(@RequestBody ViewStuInfo viewStuInfo) {
        return toAjax(viewStuInfoService.updateViewStuInfo(viewStuInfo));
    }

    /**
     * 删除学生信息视图
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:stuInfoView:remove')")
    @Log(title = "学生信息视图", businessType = BusinessType.DELETE)
    @PostMapping("/{stuIds}")
    @ApiOperation("删除学生信息视图")
    public AjaxResult remove(@PathVariable Long[] stuIds) {
        return toAjax(viewStuInfoService.deleteViewStuInfoByStuIds(stuIds));
    }
}
