package com.srs.web.controller.routine;

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

import com.srs.system.service.ISysRoleService;
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.routine.domain.RtClassMettingStuUpload;
import com.srs.routine.service.IRtClassMettingStuUploadService;
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 2025-02-09
 */
@RestController
@RequestMapping("/routine/stuUpload")
@Api(value = "指定学生上传管理", tags = "指定学生上传管理")
public class RtClassMettingStuUploadController extends BaseController {
    @Autowired
    private IRtClassMettingStuUploadService rtClassMettingStuUploadService;

    @Autowired
    ISysRoleService _roleService;


    @GetMapping("/boolStuHasUploadRole")
    @ApiOperation("辅导员查询指定学生上传列表")
    public AjaxResult boolStuHasUploadRole(){
        return rtClassMettingStuUploadService.boolStuHasUploadRole();
    }


    @GetMapping("/listOwnClass")
    public AjaxResult listOwnClass(){
        List<Map< String, Object >> list = rtClassMettingStuUploadService.listStuClass(getUsername());
        return AjaxResult.success(list);
    }

    @PostMapping("/cancelStu/{stuNo}")
    public AjaxResult cancelStu(@PathVariable String stuNo) {
        return rtClassMettingStuUploadService.cancelStu(stuNo);
    }

    @GetMapping("/listFdyStuUpload")
    @ApiOperation("辅导员查询指定学生上传列表")
    public AjaxResult listFdyStuUpload(){
        List<Map< String, Object >> list = rtClassMettingStuUploadService.listFdyStuUpload();
        return AjaxResult.success(list);
    }

    @PostMapping("/fdyAdd/{stuNo}")
    @ApiOperation("辅导员指定学生上传")
    public AjaxResult fdyAdd(@PathVariable("stuNo") String stuNo){
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            return rtClassMettingStuUploadService.fdyAdd(stuNo);
        } else {
            return AjaxResult.error(401, "你无权做这些");
        }
    }


    /**
     * 查询指定学生上传列表
     */
@PreAuthorize("@ss.hasPermi('routine:stuUpload:list')")
@GetMapping("/list")
@ApiOperation("查询指定学生上传列表")
    public TableDataInfo list(RtClassMettingStuUpload rtClassMettingStuUpload)
    {
        startPage();
        List<RtClassMettingStuUpload> list = rtClassMettingStuUploadService.selectRtClassMettingStuUploadList(rtClassMettingStuUpload);
        return getDataTable(list);
    }

    /**
     * 导出指定学生上传列表
     */
    @PreAuthorize("@ss.hasPermi('routine:stuUpload:export')")
    @Log(title = "指定学生上传", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出指定学生上传列表")
    public void export(HttpServletResponse response, RtClassMettingStuUpload rtClassMettingStuUpload)
    {
        List<RtClassMettingStuUpload> list = rtClassMettingStuUploadService.selectRtClassMettingStuUploadList(rtClassMettingStuUpload);
        ExcelUtil<RtClassMettingStuUpload> util = new ExcelUtil<RtClassMettingStuUpload>(RtClassMettingStuUpload.class);
        util.exportExcel(response, list, "指定学生上传数据");
    }

    /**
     * 获取指定学生上传详细信息
     */
    @PreAuthorize("@ss.hasPermi('routine:stuUpload:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取指定学生上传详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rtClassMettingStuUploadService.selectRtClassMettingStuUploadById(id));
    }

    /**
     * 新增指定学生上传
     */
    @PreAuthorize("@ss.hasPermi('routine:stuUpload:add')")
    @Log(title = "指定学生上传", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增指定学生上传")
    public AjaxResult add(@RequestBody RtClassMettingStuUpload rtClassMettingStuUpload)
    {
        return toAjax(rtClassMettingStuUploadService.insertRtClassMettingStuUpload(rtClassMettingStuUpload));
    }

    /**
     * 修改指定学生上传
     */
    @PreAuthorize("@ss.hasPermi('routine:stuUpload:edit')")
    @Log(title = "指定学生上传", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改指定学生上传")
    public AjaxResult edit(@RequestBody RtClassMettingStuUpload rtClassMettingStuUpload)
    {
        return toAjax(rtClassMettingStuUploadService.updateRtClassMettingStuUpload(rtClassMettingStuUpload));
    }

    /**
     * 删除指定学生上传
     */
    @PreAuthorize("@ss.hasPermi('routine:stuUpload:remove')")
    @Log(title = "指定学生上传", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除指定学生上传")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rtClassMettingStuUploadService.deleteRtClassMettingStuUploadByIds(ids));
    }
}
