package com.srs.web.controller.comprehensive;

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

import com.srs.system.domain.SysDeptMap;
import com.srs.system.service.ISysDeptMapService;
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.KnzzTufaApply;
import com.srs.comprehensive.service.IKnzzTufaApplyService;
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 zhy
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/comprehensive/knzzTufaApply")
@Api(value = "学生突发困难资助申请管理", tags = "学生突发困难资助申请管理")
public class KnzzTufaApplyController extends BaseController {
    @Autowired
    private IKnzzTufaApplyService knzzTufaApplyService;

    @Autowired
    ISysDeptMapService _deptMap;

    @PostMapping("/doReApply")
    public AjaxResult doReApply(@RequestBody KnzzTufaApply param){
        return knzzTufaApplyService.doReApply(param);
    }


    @PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:listLeaderAll')")
    @GetMapping("/listLeaderAll")
    @ApiOperation("学工查询学生突发困难资助申请列表")
    public TableDataInfo listLeaderAll(KnzzTufaApply param)
    {
        startPage();
        List<KnzzTufaApply> list = knzzTufaApplyService.listView(param);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:listLeader')")
    @GetMapping("/listLeader")
    @ApiOperation("学工查询学生突发困难资助申请列表")
    public TableDataInfo listLeader(KnzzTufaApply param)
    {
        param.setApplyStatus("4");
        startPage();
        List<KnzzTufaApply> list = knzzTufaApplyService.listView(param);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:listXgAll')")
    @GetMapping("/listXgAll")
    @ApiOperation("学工查询学生突发困难资助申请列表")
    public TableDataInfo listXgAll(KnzzTufaApply param)
    {
        startPage();
        List<KnzzTufaApply> list = knzzTufaApplyService.listView(param);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:listXg')")
    @GetMapping("/listXg")
    @ApiOperation("学工查询学生突发困难资助申请列表")
    public TableDataInfo listXg(KnzzTufaApply param)
    {
        param.setApplyStatus("3");
        startPage();
        List<KnzzTufaApply> list = knzzTufaApplyService.listView(param);
        return getDataTable(list);
    }

    @Log(title = "突发困难资助申请", businessType = BusinessType.EXPORT)
    @PostMapping("/exportXgAll")
    @ApiOperation("学工导出学生突发困难资助申请列表")
    public void exportXg(HttpServletResponse response, KnzzTufaApply knzzTufaApply)
    {
        List<KnzzTufaApply> list = knzzTufaApplyService.selectKnzzTufaApplyList(knzzTufaApply);
        ExcelUtil<KnzzTufaApply> util = new ExcelUtil<KnzzTufaApply>(KnzzTufaApply.class);
        util.exportExcel(response, list, "突发困难资助申请数据");
    }

    @PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:listXwAll')")
    @GetMapping("/listXwAll")
    @ApiOperation("学务查询学生突发困难资助申请列表")
    public TableDataInfo listXwAll(KnzzTufaApply param)
    {
        Long oldId = getDeptId();
        SysDeptMap dept = _deptMap.getOldDeptByNewId(oldId);
        Long deptId = null;
        if (dept != null) {
            deptId = dept.getOldDeptId();
        }
        param.setDeptId(deptId);
        startPage();
        List<KnzzTufaApply> list = knzzTufaApplyService.listView(param);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:listXw')")
    @GetMapping("/listXw")
    @ApiOperation("学务查询学生突发困难资助申请列表")
    public TableDataInfo listXw(KnzzTufaApply param)
    {
        Long oldId = getDeptId();
        SysDeptMap dept = _deptMap.getOldDeptByNewId(oldId);
        Long deptId = null;
        if (dept != null) {
            deptId = dept.getOldDeptId();
        }
        param.setDeptId(deptId);
        param.setApplyStatus("2");
        startPage();
        List<KnzzTufaApply> list = knzzTufaApplyService.listView(param);
        return getDataTable(list);
    }

    @Log(title = "突发困难资助申请", businessType = BusinessType.EXPORT)
    @PostMapping("/exportXwAll")
    @ApiOperation("学务导出学生突发困难资助申请列表")
    public void exportXw(HttpServletResponse response, KnzzTufaApply knzzTufaApply)
    {
        List<KnzzTufaApply> list = knzzTufaApplyService.selectKnzzTufaApplyList(knzzTufaApply);
        ExcelUtil<KnzzTufaApply> util = new ExcelUtil<KnzzTufaApply>(KnzzTufaApply.class);
        util.exportExcel(response, list, "突发困难资助申请数据");
    }


    @PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:doAudit')")
    @PostMapping("/doMany")
    public AjaxResult doMany(@RequestBody List<KnzzTufaApply> param) {
        return knzzTufaApplyService.doMany(param);
    }


    @PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:doAudit')")
    @PostMapping("/doAudit")
    public AjaxResult doAudit(@RequestBody KnzzTufaApply param) {
        return knzzTufaApplyService.doAudit(param);
    }


    @PostMapping("/doCancel/{id}")
    public AjaxResult doCancel(@PathVariable("id") Long id){
        return knzzTufaApplyService.doCancel(id);
    }

    @PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:listFdyAll')")
    @GetMapping("/listFdyAll")
    @ApiOperation("辅导员查询学生突发困难资助申请列表")
    public TableDataInfo listFdyAll(KnzzTufaApply param)
    {
        param.setFdyNo(getUsername());
        startPage();
        List<KnzzTufaApply> list = knzzTufaApplyService.listView(param);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:listFdy')")
    @GetMapping("/listFdy")
    @ApiOperation("辅导员查询学生突发困难资助申请列表")
    public TableDataInfo listFdy(KnzzTufaApply param)
    {
        param.setFdyNo(getUsername());
        param.setApplyStatus("1");
        startPage();
        List<KnzzTufaApply> list = knzzTufaApplyService.listView(param);
        return getDataTable(list);
    }
   
    //@PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:exportfdyall')")
    @Log(title = "突发困难资助申请", businessType = BusinessType.EXPORT)
    @PostMapping("/exportFdyAll")
    @ApiOperation("辅导员导出学生突发困难资助申请列表")
    public void exportFdy(HttpServletResponse response, KnzzTufaApply knzzTufaApply)
    {
        List<KnzzTufaApply> list = knzzTufaApplyService.selectKnzzTufaApplyList(knzzTufaApply);
        ExcelUtil<KnzzTufaApply> util = new ExcelUtil<KnzzTufaApply>(KnzzTufaApply.class);
        util.exportExcel(response, list, "突发困难资助申请数据");
    }


    @GetMapping("/listStu")
    @ApiOperation("学生查询学生突发困难资助申请列表")
    public TableDataInfo listStu(KnzzTufaApply param)
    {
        param.setStuNo(getUsername());
        startPage();
        List<KnzzTufaApply> list = knzzTufaApplyService.listView(param);
        return getDataTable(list);
    }


    @PostMapping("/doEdit")
    public AjaxResult doEdit(@RequestBody KnzzTufaApply param){
        return knzzTufaApplyService.doEdit(param);
    }


    @PostMapping("/doApply")
    public AjaxResult doApply(@RequestBody KnzzTufaApply param){
        return knzzTufaApplyService.doApply(param);
    }

    @GetMapping("/getOwnFamily")
    public AjaxResult getOwnFamily(){
        return knzzTufaApplyService.getOwnFamily();
    }

    @GetMapping("/getOwnKnrd")
    public AjaxResult getOwnKnrd(){
        return knzzTufaApplyService.getOwnKnrd();
    }



    /**
     * 查询学生突发困难资助申请列表
     */
@PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:list')")
@GetMapping("/list")
@ApiOperation("查询学生突发困难资助申请列表")
    public TableDataInfo list(KnzzTufaApply knzzTufaApply)
    {
        startPage();
        List<KnzzTufaApply> list = knzzTufaApplyService.selectKnzzTufaApplyList(knzzTufaApply);
        return getDataTable(list);
    }

    /**
     * 导出学生突发困难资助申请列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:export')")
    @Log(title = "学生突发困难资助申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出学生突发困难资助申请列表")
    public void export(HttpServletResponse response, KnzzTufaApply knzzTufaApply)
    {
        List<KnzzTufaApply> list = knzzTufaApplyService.selectKnzzTufaApplyList(knzzTufaApply);
        ExcelUtil<KnzzTufaApply> util = new ExcelUtil<KnzzTufaApply>(KnzzTufaApply.class);
        util.exportExcel(response, list, "学生突发困难资助申请数据");
    }

    /**
     * 获取学生突发困难资助申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取学生突发困难资助申请详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(knzzTufaApplyService.selectKnzzTufaApplyById(id));
    }

    /**
     * 新增学生突发困难资助申请
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:add')")
    @Log(title = "学生突发困难资助申请", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增学生突发困难资助申请")
    public AjaxResult add(@RequestBody KnzzTufaApply knzzTufaApply)
    {
        return toAjax(knzzTufaApplyService.insertKnzzTufaApply(knzzTufaApply));
    }

    /**
     * 修改学生突发困难资助申请
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:edit')")
    @Log(title = "学生突发困难资助申请", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改学生突发困难资助申请")
    public AjaxResult edit(@RequestBody KnzzTufaApply knzzTufaApply)
    {
        return toAjax(knzzTufaApplyService.updateKnzzTufaApply(knzzTufaApply));
    }

    /**
     * 删除学生突发困难资助申请
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:knzzTufaApply:remove')")
    @Log(title = "学生突发困难资助申请", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除学生突发困难资助申请")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(knzzTufaApplyService.deleteKnzzTufaApplyByIds(ids));
    }
}
