package com.srs.web.controller.comprehensive;

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

import com.srs.comprehensive.domain.KnzzGlApply;
import com.srs.comprehensive.domain.KnzzZzqApply;
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.KnzzZzqApply;
import com.srs.comprehensive.service.IKnzzZzqApplyService;
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-05-12
 */
@RestController
@RequestMapping("/comprehensive/knzzZzqApply")
@Api(value = "自治区人民政府奖学金管理", tags = "自治区人民政府奖学金管理")
public class KnzzZzqApplyController extends BaseController {
    @Autowired
    private IKnzzZzqApplyService knzzZzqApplyService;

    @Autowired
    ISysDeptMapService _deptMap;

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

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

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


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

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


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

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




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


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


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

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

    @PreAuthorize("@ss.hasPermi('comprehensive:knzzZzqApply:doAudit')")
    @PostMapping("/doAudit")
    public AjaxResult doAudit(@RequestBody KnzzZzqApply param) {
        return knzzZzqApplyService.doAudit(param);
    }


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

    /**
     * 查询自治区人民政府奖学金列表
     */
@PreAuthorize("@ss.hasPermi('comprehensive:knzzZzqApply:list')")
@GetMapping("/list")
@ApiOperation("查询自治区人民政府奖学金列表")
    public TableDataInfo list(KnzzZzqApply knzzZzqApply)
    {
        startPage();
        List<KnzzZzqApply> list = knzzZzqApplyService.selectKnzzZzqApplyList(knzzZzqApply);
        return getDataTable(list);
    }

    /**
     * 导出自治区人民政府奖学金列表
     */
//    @PreAuthorize("@ss.hasPermi('comprehensive:knzzZzqApply:export')")
    @Log(title = "自治区人民政府奖学金", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出自治区人民政府奖学金列表")
    public void export(HttpServletResponse response, KnzzZzqApply knzzZzqApply)
    {
        List<KnzzZzqApply> list = knzzZzqApplyService.selectKnzzZzqApplyList(knzzZzqApply);
        ExcelUtil<KnzzZzqApply> util = new ExcelUtil<>(KnzzZzqApply.class);
        util.exportExcel(response, list, "自治区人民政府奖学金数据");

    }

    /**
     * 获取自治区人民政府奖学金详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:knzzZzqApply:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取自治区人民政府奖学金详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(knzzZzqApplyService.selectKnzzZzqApplyById(id));
    }

    /**
     * 新增自治区人民政府奖学金
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:knzzZzqApply:add')")
    @Log(title = "自治区人民政府奖学金", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增自治区人民政府奖学金")
    public AjaxResult add(@RequestBody KnzzZzqApply knzzZzqApply)
    {
        return toAjax(knzzZzqApplyService.insertKnzzZzqApply(knzzZzqApply));
    }

    /**
     * 修改自治区人民政府奖学金
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:knzzZzqApply:edit')")
    @Log(title = "自治区人民政府奖学金", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改自治区人民政府奖学金")
    public AjaxResult edit(@RequestBody KnzzZzqApply knzzZzqApply)
    {
        return toAjax(knzzZzqApplyService.updateKnzzZzqApply(knzzZzqApply));
    }

    /**
     * 删除自治区人民政府奖学金
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:knzzZzqApply:remove')")
    @Log(title = "自治区人民政府奖学金", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除自治区人民政府奖学金")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(knzzZzqApplyService.deleteKnzzZzqApplyByIds(ids));
    }
}
