package com.srs.web.controller.comprehensive;

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

import com.srs.comprehensive.domain.KnzzZsgApply;
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.KnzzZsgApply;
import com.srs.comprehensive.service.IKnzzZsgApplyService;
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/knzzZsgApply")
@Api(value = "中职升高职补助管理", tags = "中职升高职补助管理")
public class KnzzZsgApplyController extends BaseController {
    @Autowired
    private IKnzzZsgApplyService knzzZsgApplyService;

    @Autowired
    ISysDeptMapService _deptMap;

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

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

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


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

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


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

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




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

//填写中职升高职申请表
    @PostMapping("/doApply")
    public AjaxResult doApply(@RequestBody KnzzZsgApply param) {
        return knzzZsgApplyService.doApply(param);
    }


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

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

    @PreAuthorize("@ss.hasPermi('comprehensive:knzzZsgApply:doAudit')")
    @PostMapping("/doAudit")
    public AjaxResult doAudit(@RequestBody KnzzZsgApply param) {
        return knzzZsgApplyService.doAudit(param);
    }


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


    /**
     * 查询中职升高职补助列表
     */
@PreAuthorize("@ss.hasPermi('comprehensive:knzzZsgApply:list')")
@GetMapping("/list")
@ApiOperation("查询中职升高职补助列表")
    public TableDataInfo list(KnzzZsgApply knzzZsgApply)
    {
        startPage();
        List<KnzzZsgApply> list = knzzZsgApplyService.selectKnzzZsgApplyList(knzzZsgApply);
        return getDataTable(list);
    }
    /**
     * 导出中职升高职补助列表
     */
//    @PreAuthorize("@ss.hasPermi('comprehensive:knzzZsgApply:export')")
    @Log(title = "中职升高职补助", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出中职升高职补助          列表")
    public void export(HttpServletResponse response, KnzzZsgApply knzzZsgApply)
    {
        List<KnzzZsgApply> list = knzzZsgApplyService.selectKnzzZsgApplyList(knzzZsgApply);
        ExcelUtil<KnzzZsgApply> util = new ExcelUtil<>(KnzzZsgApply.class);
        util.exportExcel(response, list, "中职升高职补助数据");
    }

    /**
     * 获取中职升高职补助详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:knzzZsgApply:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取中职升高职补助详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(knzzZsgApplyService.selectKnzzZsgApplyById(id));
    }

    /**
     * 新增中职升高职补助
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:knzzZsgApply:add')")
    @Log(title = "中职升高职补助", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增中职升高职补助")
    public AjaxResult add(@RequestBody KnzzZsgApply knzzZsgApply)
    {
        return toAjax(knzzZsgApplyService.insertKnzzZsgApply(knzzZsgApply));
    }

    /**
     * 修改中职升高职补助
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:knzzZsgApply:edit')")
    @Log(title = "中职升高职补助", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改中职升高职补助")
    public AjaxResult edit(@RequestBody KnzzZsgApply knzzZsgApply)
    {
        return toAjax(knzzZsgApplyService.updateKnzzZsgApply(knzzZsgApply));
    }

    /**
     * 删除中职升高职补助
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:knzzZsgApply:remove')")
    @Log(title = "中职升高职补助", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除中职升高职补助")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(knzzZsgApplyService.deleteKnzzZsgApplyByIds(ids));
    }
}
