package com.srs.web.controller.comprehensive;

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

import com.srs.comprehensive.domain.SrsZxjApply;
import com.srs.comprehensive.domain.SrsZxjApprovalRecord;
import com.srs.comprehensive.domain.Vo.CphSearch;
import com.srs.comprehensive.service.ISrsZxjApplyService;
import com.srs.comprehensive.service.ISrsZxjApprovalRecordService;

import com.srs.system.service.ISysPostService;
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.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-03-17
 */
@RestController
@RequestMapping("/comprehensive/apply/record")
@Api(value = "【贫困生审核记录】管理", tags = "【贫困生审核记录】管理")
public class SrsZxjApprovalRecordController extends BaseController {
    @Autowired
    private ISrsZxjApprovalRecordService srsZxjApprovalRecordService;

    @Autowired
    ISysPostService _postService;

    @Autowired
    private ISrsZxjApplyService srsZxjApplyService;
    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    @ApiOperation("查询【贫困生审核记录】列表")
    public TableDataInfo list(SrsZxjApprovalRecord srsZxjApprovalRecord)
    {

//        startPage();
        List<SrsZxjApprovalRecord> list = srsZxjApprovalRecordService.selectSrsZxjApprovalRecordList(srsZxjApprovalRecord);
        return getDataTable(list);
    }
    //辅导员审批记录查询
    @GetMapping("/listView")
    @ApiOperation("查询【助学金审批记录记录】列表")
    public TableDataInfo listView(CphSearch param)
    {
        //辅导员
        boolean hasFdy = RoleBool.isFdy(getUserId(),_postService);
        //学务
        boolean hasXw = RoleBool.isXw(getUserId(),_postService);
        boolean isEjxysj = RoleBool.isEjxysj(getUserId(),_postService);
        //学工
        boolean hasJwc = RoleBool.isJwc(getUserId(),_postService);
        if(hasFdy || hasXw || hasJwc || isEjxysj){
            List<SrsZxjApply> list = this.queryList(param);
            return getDataTable(list);
        }

        List<String> list = new ArrayList<>();
        return getDataTable(list);
    }


    private List<SrsZxjApply> queryListExport(CphSearch param){
        //辅导员
        boolean hasFdy = RoleBool.isFdy(getUserId(),_postService);
        if(hasFdy){
            param.setTNo(getUsername());
            //param.setStep(2+"");
            //startPage();
            List<SrsZxjApply> list = srsZxjApplyService.listRecordView(param);
            return list;
        }

        //学务
        boolean hasXw = RoleBool.isXw(getUserId(),_postService);
        boolean isEjxysj = RoleBool.isEjxysj(getUserId(),_postService);
        if(hasXw || isEjxysj){
            param.setDeptId(getDeptId());
            //param.setStep(3+"");
            //startPage();
            List<SrsZxjApply> list = srsZxjApplyService.listRecordView(param);
            return list;
        }
        //学工
        boolean hasJwc = RoleBool.isJwc(getUserId(),_postService);
        if(hasJwc){
            //param.setStep(4+"");
            //startPage();
            List<SrsZxjApply> list = srsZxjApplyService.listRecordView(param);
            return list;
        }
        List<SrsZxjApply> list = new ArrayList<>();
        return list;
    }
    private List<SrsZxjApply> queryList(CphSearch param){
        //辅导员
        boolean hasFdy = RoleBool.isFdy(getUserId(),_postService);
        if(hasFdy){
            param.setTNo(getUsername());
            //param.setStep(2+"");
            startPage();
            List<SrsZxjApply> list = srsZxjApplyService.listRecordView(param);
            return list;
        }

        //学务
        boolean hasXw = RoleBool.isXw(getUserId(),_postService);
        boolean isEjxysj = RoleBool.isEjxysj(getUserId(),_postService);
        if(hasXw || isEjxysj){
            param.setDeptId(getDeptId());
            //param.setStep(3+"");
            startPage();
            List<SrsZxjApply> list = srsZxjApplyService.listRecordView(param);
            return list;
        }
        //学工
        boolean hasJwc = RoleBool.isJwc(getUserId(),_postService);
        if(hasJwc){
            //param.setStep(4+"");
            startPage();
            List<SrsZxjApply> list = srsZxjApplyService.listRecordView(param);
            return list;
        }
        List<SrsZxjApply> list = new ArrayList<>();
        return list;
    }
    /**
     * 导出【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "【贫困生审核记录】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出【请填写功能名称】列表")
    public void export(HttpServletResponse response, CphSearch param)
    {
        List<SrsZxjApply> list = this.queryListExport(param);
        for (SrsZxjApply srsZxjApply : list) {

            if("1".equals(srsZxjApply.getPenaltyStatus0())){
                srsZxjApply.setIsExist("正在处分");
            }
            else if("1".equals(srsZxjApply.getPenaltyStatus1())){
                srsZxjApply.setIsExist("处分解除");
            }
            else if("1".equals(srsZxjApply.getPenaltyStatus3())){
                srsZxjApply.setIsExist("正在申请处分");
            }else{
                srsZxjApply.setIsExist("无处分记录");
            }
        }
        ExcelUtil<SrsZxjApply> util = new ExcelUtil<SrsZxjApply>(SrsZxjApply.class);
        util.exportExcel(response, list, "【贫困生审核记录】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取【贫困生审核记录】详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {

        return success(srsZxjApprovalRecordService.selectSrsZxjApprovalRecordById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "【贫困生审核记录】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增【贫困生审核记录】")
    public AjaxResult add(@RequestBody SrsZxjApprovalRecord srsZxjApprovalRecord)
    {
        return toAjax(srsZxjApprovalRecordService.insertSrsZxjApprovalRecord(srsZxjApprovalRecord));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "【贫困生审核记录】", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改【贫困生审核记录】")
    public AjaxResult edit(@RequestBody SrsZxjApprovalRecord srsZxjApprovalRecord)
    {
        return toAjax(srsZxjApprovalRecordService.updateSrsZxjApprovalRecord(srsZxjApprovalRecord));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "【贫困生审核记录】", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除【贫困生审核记录】")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(srsZxjApprovalRecordService.deleteSrsZxjApprovalRecordByIds(ids));
    }


    //辅导员审核记录查询
    @GetMapping("/listFdyView")
    @ApiOperation("查询【助学金审批记录记录】列表")
    public TableDataInfo listFdyView(CphSearch param)
    {
        boolean hasFdy = RoleBool.isFdy(getUserId(),_postService);
        if(hasFdy){
            param.setTNo(getUsername());
            //param.setStep(2+"");
            startPage();
            List<SrsZxjApply> list = srsZxjApplyService.listRecordView(param);
            return getDataTable(list);
        }

        List<String> list = new ArrayList<>();
        return getDataTable(list);
    }

    //二级学院审核记录查询
    @GetMapping("/listEjxyView")
    @ApiOperation("查询【助学金审批记录记录】列表")
    public TableDataInfo listEjxyView(CphSearch param)
    {
        boolean hasXw = RoleBool.isXw(getUserId(),_postService);
        boolean isEjxysj = RoleBool.isEjxysj(getUserId(),_postService);
        if(hasXw || isEjxysj){
            param.setDeptId(getDeptId());
            //param.setStep(3+"");
            startPage();
            List<SrsZxjApply> list = srsZxjApplyService.listRecordView(param);
            return getDataTable(list);
        }

        List<String> list = new ArrayList<>();
        return getDataTable(list);
    }

    @GetMapping("/listJwcView")
    @ApiOperation("查询【助学金审批记录记录】列表")
    public TableDataInfo listJwcView(CphSearch param)
    {
        boolean hasJwc = RoleBool.isJwc(getUserId(),_postService);
        if(hasJwc){
            //param.setStep(4+"");
            startPage();
            List<SrsZxjApply> list = srsZxjApplyService.listRecordView(param);
            return getDataTable(list);
        }

        List<String> list = new ArrayList<>();
        return getDataTable(list);
    }
}
