package com.srs.web.controller.comprehensive;

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

import com.srs.comprehensive.domain.KnzzTufaApply;
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.KnzzGlApply;
import com.srs.comprehensive.service.IKnzzGlApplyService;
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-04-26
 */
@RestController
@RequestMapping("/comprehensive/knzzGlApply")
@Api(value = "国家励志奖学金管理", tags = "国家励志奖学金管理")
public class KnzzGlApplyController extends BaseController {
    @Autowired
    private IKnzzGlApplyService knzzGlApplyService;

    @Autowired
    ISysDeptMapService _deptMap;

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

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

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


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

    @PreAuthorize("@ss.hasPermi('comprehensive:knzzGlApply:listXw')")
    @GetMapping("/listXw")
    @ApiOperation("学务查询学生突发困难资助申请列表")
    public TableDataInfo listXw(KnzzGlApply 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<KnzzGlApply> list = knzzGlApplyService.listView(param);
        return getDataTable(list);
    }


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

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




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



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

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

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

    //@PreAuthorize("@ss.hasPermi('comprehensive:knzzGlApply:doAudit')")
    @PostMapping("/doAudit")
    public AjaxResult doAudit(@RequestBody KnzzGlApply param) {
        return knzzGlApplyService.doAudit(param);
    }

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




    /**
     * 查询国家励志奖学金列表
     */
@PreAuthorize("@ss.hasPermi('comprehensive:knzzGlApply:list')")
@GetMapping("/list")
@ApiOperation("查询国家励志奖学金列表")
    public TableDataInfo list(KnzzGlApply knzzGlApply)
    {
        startPage();
        List<KnzzGlApply> list = knzzGlApplyService.selectKnzzGlApplyList(knzzGlApply);
        return getDataTable(list);
    }

    /**
     * 导出国家励志奖学金列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:knzzGlApply:export')")
    @Log(title = "国家励志奖学金", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出国家励志奖学金列表")
    public void export(HttpServletResponse response, KnzzGlApply knzzGlApply)
    {
        List<KnzzGlApply> list = knzzGlApplyService.selectKnzzGlApplyList(knzzGlApply);
        ExcelUtil<KnzzGlApply> util = new ExcelUtil<KnzzGlApply>(KnzzGlApply.class);
        util.exportExcel(response, list, "国家励志奖学金数据");
    }

    /**
     * 获取国家励志奖学金详细信息
     */
//    @PreAuthorize("@ss.hasPermi('comprehensive:knzzGlApply:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取国家励志奖学金详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(knzzGlApplyService.selectKnzzGlApplyById(id));
    }

    /**
     * 新增国家励志奖学金
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:knzzGlApply:add')")
    @Log(title = "国家励志奖学金", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增国家励志奖学金")
    public AjaxResult add(@RequestBody KnzzGlApply knzzGlApply)
    {
        return toAjax(knzzGlApplyService.insertKnzzGlApply(knzzGlApply));
    }

    /**
     * 修改国家励志奖学金
     */
//    @PreAuthorize("@ss.hasPermi('comprehensive:knzzGlApply:edit')")
    @Log(title = "国家励志奖学金", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改国家励志奖学金")
    public AjaxResult edit(@RequestBody KnzzGlApply knzzGlApply)
    {
        return toAjax(knzzGlApplyService.updateKnzzGlApply(knzzGlApply));
    }

    /**
     * 删除国家励志奖学金
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:knzzGlApply:remove')")
    @Log(title = "国家励志奖学金", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除国家励志奖学金")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(knzzGlApplyService.deleteKnzzGlApplyByIds(ids));
    }
}
