package com.srs.web.controller.diagnostic;

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

import com.srs.comprehensive.domain.SrsStudent;
import com.srs.comprehensive.service.ISrsStudentService;
import com.srs.system.service.ISysRoleService;
import com.srs.web.controller.common.RoleBool;
import liquibase.pro.packaged.S;
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.diagnostic.domain.DiaStudentInfo;
import com.srs.diagnostic.service.IDiaStudentInfoService;
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-05-26
 */
@RestController
@RequestMapping("/diagnostic/info")
@Api(value = "学生报信息管理", tags = "学生报信息管理")
public class DiaStudentInfoController extends BaseController {
    @Autowired
    private IDiaStudentInfoService diaStudentInfoService;

    @Autowired
    ISysRoleService _postService;

    @Autowired
    ISrsStudentService iSrsStudentService;


    /**
     * 查询学生报信息列表
     */
    @PreAuthorize("@ss.hasPermi('diagnostic:info:list')")
    @GetMapping("/list")
    @ApiOperation("查询学生报信息列表")
    public TableDataInfo list(DiaStudentInfo diaStudentInfo) {
        startPage();
        List<DiaStudentInfo> list = diaStudentInfoService.selectDiaStudentInfoList(diaStudentInfo);
        return getDataTable(list);
    }


    /**
     * 获取学生报信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('diagnostic:info:query')")
    @GetMapping(value = "/get/{userid}")
    @ApiOperation("获取学生报信息详细信息")
    public AjaxResult getInfo(@PathVariable("userid") Long userid) {
        return success(diaStudentInfoService.selectDiaStudentInfolistid(userid));
    }


    /**
     * 新增学生报信息
     */
    @PreAuthorize("@ss.hasPermi('diagnostic:info:add')")
    @Log(title = "学生报信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增学生报信息")
    public AjaxResult add(@RequestBody DiaStudentInfo diaStudentInfo) {
        //判断是否为学生
        boolean hasRole = RoleBool.isStu(getUserId(), _postService);
        SrsStudent srsStudent = iSrsStudentService.selectSrsStudentByStuNo(getUserId().toString());

        if (hasRole) {
            return toAjax(diaStudentInfoService.insertDiaStudentInfo(diaStudentInfo));
        } else {
            return AjaxResult.success("操作成功");
        }

    }




    /**
     * 导出学生报信息列表
     */
    @PreAuthorize("@ss.hasPermi('diagnostic:info:export')")
    @Log(title = "学生报信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出学生报信息列表")
    public void export(HttpServletResponse response, DiaStudentInfo diaStudentInfo) {
        List<DiaStudentInfo> list = diaStudentInfoService.selectDiaStudentInfoList(diaStudentInfo);
        ExcelUtil<DiaStudentInfo> util = new ExcelUtil<DiaStudentInfo>(DiaStudentInfo.class);
        util.exportExcel(response, list, "学生报信息数据");
    }
}
