package com.srs.web.controller.comprehensive;

import java.util.List;
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 com.srs.comprehensive.domain.SrsKnrdType;
import com.srs.comprehensive.service.ISrsKnrdTypeService;
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-06-05
 */
@RestController
@RequestMapping("/comprehensive/knrdtype")
@Api(value = "困难类型管理", tags = "困难类型管理")
public class SrsKnrdTypeController extends BaseController {
    @Autowired
    private ISrsKnrdTypeService srsKnrdTypeService;

    @Autowired
    private ISysRoleService _roleService;

    @PostMapping("/doImport")
    @ApiOperation("导入")
    public AjaxResult doImport(@RequestBody List<SrsKnrdType> param){
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            return srsKnrdTypeService.doImport(param);
        } else {
            return AjaxResult.error(401, "你无权做这些");
        }
    }


    /**
     * 查询困难类型列表
     */
    @GetMapping("/list")
    @ApiOperation("查询困难类型列表")
    public TableDataInfo list(SrsKnrdType srsKnrdType) {
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            startPage();
            List<SrsKnrdType> list = srsKnrdTypeService.selectSrsKnrdTypeList(srsKnrdType);
            return getDataTable(list);
        } else {
            return null;
        }
    }

    /**
     * 导出困难类型列表
     */
    @Log(title = "困难类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出困难类型列表")
    public void export(HttpServletResponse response, SrsKnrdType srsKnrdType) {
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            List<SrsKnrdType> list = srsKnrdTypeService.selectSrsKnrdTypeList(srsKnrdType);
            ExcelUtil<SrsKnrdType> util = new ExcelUtil<SrsKnrdType>(SrsKnrdType.class);
            util.exportExcel(response, list, "困难类型数据");
        }
    }

    /**
     * 获取困难类型详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取困难类型详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            return success(srsKnrdTypeService.selectSrsKnrdTypeById(id));
        } else {
            return AjaxResult.error(401, "你无权做这些");
        }
    }

    /**
     * 新增困难类型
     */
    @Log(title = "困难类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增困难类型")
    public AjaxResult add(@RequestBody SrsKnrdType srsKnrdType) throws Exception {
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            return toAjax(srsKnrdTypeService.insertSrsKnrdType(srsKnrdType));
        } else {
            return AjaxResult.error(401, "你无权做这些");
        }
    }

    /**
     * 修改困难类型
     */
    @Log(title = "困难类型", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改困难类型")
    public AjaxResult edit(@RequestBody SrsKnrdType srsKnrdType) throws Exception {
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            return toAjax(srsKnrdTypeService.updateSrsKnrdType(srsKnrdType));
        } else {
            return AjaxResult.error(401, "你无权做这些");
        }
    }

    /**
     * 删除困难类型
     */
    @Log(title = "困难类型", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除困难类型")
    public AjaxResult remove(@PathVariable Long[] ids) {
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            return toAjax(srsKnrdTypeService.deleteSrsKnrdTypeByIds(ids));
        } else {
            return AjaxResult.error(401, "你无权做这些");
        }
    }
    @PostMapping(value = "/queryByStuNo")
    @ApiOperation("根据学号查询困难类型")
    public AjaxResult queryByStuNo(@RequestBody SrsKnrdType srsKnrdType) {
//        SrsKnrdType srsKnrdType1 = srsKnrdTypeService.queryByStuNo(srsKnrdType);
        return success(srsKnrdTypeService.queryByStuNo(srsKnrdType));
    }


}
