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.SrsKnrdTime;
import com.srs.comprehensive.service.ISrsKnrdTimeService;
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/knrdtime")
@Api(value = "困难认定审核时间管理", tags = "困难认定审核时间管理")
public class SrsKnrdTimeController extends BaseController {
    @Autowired
    private ISrsKnrdTimeService srsKnrdTimeService;

    @Autowired
    private ISysRoleService _roleService;


    @PostMapping("/doImport")
    @ApiOperation("导入困难认定审核时间列表")
    public AjaxResult doImport(@RequestBody List<SrsKnrdTime> param){
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            return srsKnrdTimeService.doImport(param);
        } else {
            return AjaxResult.error(401, "你无权做这些");
        }
    }

    /**
     * 查询困难认定审核时间列表
     */
    @GetMapping("/list")
    @ApiOperation("查询困难认定审核时间列表")
    public TableDataInfo list(SrsKnrdTime srsKnrdTime) {
        startPage();
        List<SrsKnrdTime> list = srsKnrdTimeService.selectSrsKnrdTimeList(srsKnrdTime);
        return getDataTable(list);
//        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
//        if (hasRole) {
//
//        } else {
//            return null;
//        }
    }

    /**
     * 导出困难认定审核时间列表
     */
    @Log(title = "困难认定审核时间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出困难认定审核时间列表")
    public void export(HttpServletResponse response, SrsKnrdTime srsKnrdTime) {
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            List<SrsKnrdTime> list = srsKnrdTimeService.selectSrsKnrdTimeList(srsKnrdTime);
            ExcelUtil<SrsKnrdTime> util = new ExcelUtil<SrsKnrdTime>(SrsKnrdTime.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(srsKnrdTimeService.selectSrsKnrdTimeById(id));
        } else {
            return AjaxResult.error(401, "你无权做这些");
        }
    }

    /**
     * 新增困难认定审核时间
     */
    @Log(title = "困难认定审核时间", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增困难认定审核时间")
    public AjaxResult add(@RequestBody SrsKnrdTime srsKnrdTime) {
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            return toAjax(srsKnrdTimeService.insertSrsKnrdTime(srsKnrdTime));
        } else {
            return AjaxResult.error(401, "你无权做这些");
        }
    }

    /**
     * 修改困难认定审核时间
     */
    @Log(title = "困难认定审核时间", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改困难认定审核时间")
    public AjaxResult edit(@RequestBody SrsKnrdTime srsKnrdTime) {
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            return toAjax(srsKnrdTimeService.updateSrsKnrdTime(srsKnrdTime));
        } 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(srsKnrdTimeService.deleteSrsKnrdTimeByIds(ids));
        } else {
            return AjaxResult.error(401, "你无权做这些");
        }
    }
}
