package com.srs.web.controller.comprehensive;

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

import com.srs.comprehensive.domain.SrsKnrdTime;
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.comprehensive.domain.SrsZxjTime;
import com.srs.comprehensive.service.ISrsZxjTimeService;
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/zxjtime")
@Api(value = "助学金审核时间管理", tags = "助学金审核时间管理")
public class SrsZxjTimeController extends BaseController {
    @Autowired
    private ISrsZxjTimeService srsZxjTimeService;

    @Autowired
    private ISysRoleService _roleService;


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


    /**
     * 查询助学金审核时间列表
     */
    @GetMapping("/list")
    @ApiOperation("查询助学金审核时间列表")
    public TableDataInfo list(SrsZxjTime srsZxjTime) {
        startPage();
        List<SrsZxjTime> list = srsZxjTimeService.selectSrsZxjTimeList(srsZxjTime);
        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, SrsZxjTime srsZxjTime) {
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            List<SrsZxjTime> list = srsZxjTimeService.selectSrsZxjTimeList(srsZxjTime);
            ExcelUtil<SrsZxjTime> util = new ExcelUtil<SrsZxjTime>(SrsZxjTime.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(srsZxjTimeService.selectSrsZxjTimeById(id));
        } else {
            return AjaxResult.error(401, "你无权做这些");
        }
    }

    /**
     * 新增助学金审核时间
     */
    @Log(title = "助学金审核时间", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增助学金审核时间")
    public AjaxResult add(@RequestBody SrsZxjTime srsZxjTime) {
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            return toAjax(srsZxjTimeService.insertSrsZxjTime(srsZxjTime));
        } else {
            return AjaxResult.error(401, "你无权做这些");
        }
    }

    /**
     * 修改助学金审核时间
     */
    @Log(title = "助学金审核时间", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改助学金审核时间")
    public AjaxResult edit(@RequestBody SrsZxjTime srsZxjTime) {
        boolean hasRole = RoleBool.notStu(getUserId(), _roleService);
        if (hasRole) {
            return toAjax(srsZxjTimeService.updateSrsZxjTime(srsZxjTime));
        } 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(srsZxjTimeService.deleteSrsZxjTimeByIds(ids));
        } else {
            return AjaxResult.error(401, "你无权做这些");
        }
    }
}
