package com.srs.web.controller.comprehensive;

import java.util.List;
import java.util.Map;
import javax.management.relation.Role;
import javax.servlet.http.HttpServletResponse;

import com.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.core.page.TableDataInfo;
import com.srs.common.enums.BusinessType;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.comprehensive.domain.Dto.CphAuditMany;
import com.srs.comprehensive.domain.Dto.CphGoodAuditSubmmit;
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.*;
import io.swagger.annotations.*;
import com.srs.comprehensive.domain.CphGoodAudit;
import com.srs.comprehensive.service.ICphGoodAuditService;
/**
 * 评优审核Controller
 *
 * @author srs
 * @date 2023-09-12
 */
@RestController
@RequestMapping("/comprehensive/goodaudit")
@Api(value = "评优审核管理", tags = "评优审核管理")
public class CphGoodAuditController extends BaseController {
    @Autowired
    private ICphGoodAuditService cphGoodAuditService;

    @Autowired
    ISysPostService _postService;

    @PostMapping("/manyAudit")
    @ApiOperation("一键审核通过")
    public AjaxResult manyAudit(@RequestBody CphAuditMany param){
        boolean hasRole = RoleBool.isJwc(getUserId(),_postService);
        boolean hasRoles=RoleBool.isXw(getUserId(),_postService);
        if(hasRole||hasRoles){
            return cphGoodAuditService.manyAudit(param);
        }else{
            return  AjaxResult.error(401,"你无权做这些");
        }
    }



    @PostMapping("/changeApply")
    @ApiOperation("修改评优申请记录")
    public AjaxResult changeApply(@RequestBody CphGoodAudit param){
        boolean hasRole = RoleBool.isJwc(getUserId(),_postService);
        if(hasRole){
            return cphGoodAuditService.changeApply(param);
        }else{
            return  AjaxResult.error(401,"你无权做这些");
        }
    }


    @PostMapping("/voidApply")
    @ApiOperation("作废评优申请记录")
    public AjaxResult voidApply(@RequestBody CphGoodAudit param){
        boolean hasRole = RoleBool.isJwc(getUserId(),_postService);
        if(hasRole){
            return cphGoodAuditService.voidApply(param);
        }else{
            return  AjaxResult.error(401,"你无权做这些");
        }
    }

    @GetMapping("/jwcCountUnAudit")
    @ApiOperation("学工统计未审核的数量")
    public AjaxResult jwcCountUnAudit(){
        boolean hasRole = RoleBool.isJwc(getUserId(),_postService);
        if(hasRole){
            Map<String,Object> res = cphGoodAuditService.jwcCountUnAudit();
            return AjaxResult.success(res);
        }else{
            return  AjaxResult.error(401,"你无权做这些");
        }
    }

    @GetMapping("/xwCountUnAudit")
    @ApiOperation("学务统计未审核的数量")
    public AjaxResult xwCountUnAudit(){
        boolean hasRole = RoleBool.isXw(getUserId(),_postService);
        if(hasRole){
            Long deptId = getDeptId();
            Map<String,Object> res = cphGoodAuditService.xwCountUnAudit(deptId);
            return AjaxResult.success(res);
        }else{
            return  AjaxResult.error(401,"你无权做这些");
        }
    }

    @GetMapping("/fdyCountUnAudit")
    @ApiOperation("辅导员统计未审核的数量")
    public AjaxResult fdyCountUnAudit(){
        boolean hasRole = RoleBool.isFdy(getUserId(),_postService);
        if(hasRole){
            String tNo = getUsername();
            Map<String,Object> res = cphGoodAuditService.fdyCountUnAudit(tNo);
            return AjaxResult.success(res);
        }else{
            return AjaxResult.error(401,"你无权做这些");
        }
    }

    /**
     * 查询评优审核列表
     */
    //@RequiresPermissions("comprehensive:goodaudit:list")
    @GetMapping("/list")
    @ApiOperation("查询评优审核列表")
    public TableDataInfo list(CphGoodAudit cphGoodAudit)
    {
        startPage();
        List<CphGoodAudit> list = cphGoodAuditService.selectCphGoodAuditList(cphGoodAudit);
        return getDataTable(list);
    }

    /**
     * 导出评优审核列表
     */
    //@RequiresPermissions("comprehensive:goodaudit:export")
    @Log(title = "评优审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出评优审核列表")
    public void export(HttpServletResponse response, CphGoodAudit cphGoodAudit)
    {
        List<CphGoodAudit> list = cphGoodAuditService.selectCphGoodAuditList(cphGoodAudit);
        ExcelUtil<CphGoodAudit> util = new ExcelUtil<CphGoodAudit>(CphGoodAudit.class);
        util.exportExcel(response, list, "评优审核数据");
    }

    /**
     * 获取评优审核详细信息
     */
    //@RequiresPermissions("comprehensive:goodaudit:query")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取评优审核详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cphGoodAuditService.selectCphGoodAuditById(id));
    }

    /**
     * 新增评优审核
     */
    //@RequiresPermissions("comprehensive:goodaudit:add")
    @Log(title = "评优审核", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增评优审核")
    public AjaxResult add(@RequestBody CphGoodAudit cphGoodAudit)
    {
        return toAjax(cphGoodAuditService.insertCphGoodAudit(cphGoodAudit));
    }

    /**
     * 修改评优审核
     */
    //@RequiresPermissions("comprehensive:goodaudit:edit")
    @Log(title = "评优审核", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改评优审核")
    public AjaxResult edit(@RequestBody CphGoodAudit cphGoodAudit)
    {
        return toAjax(cphGoodAuditService.updateCphGoodAudit(cphGoodAudit));
    }

    /**
     * 删除评优审核
     */
    //@RequiresPermissions("comprehensive:goodaudit:remove")
    @Log(title = "评优审核", businessType = BusinessType.DELETE)
    @PostMapping("/delete/{ids}")
    @ApiOperation("删除评优审核")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cphGoodAuditService.deleteCphGoodAuditByIds(ids));
    }
    /**
     * 辅导员审核申请
     */
    @Log(title = "评优审核",businessType = BusinessType.UPDATE)
    @ApiOperation("辅导员审核申请表")
    @PostMapping("/fdyAudit")
    public AjaxResult fdyAudit(@RequestBody CphGoodAuditSubmmit param){
        boolean hasRole = RoleBool.isFdy(getUserId(),_postService);
        if(hasRole){
            Long auditId = param.auditId;
            String status = param.status;
            String common = param.common;
            return cphGoodAuditService.fdyAudit(auditId,status,common);
        }else{
            return AjaxResult.error(401,"你无权做这些");
        }
    }

    /**
     * 学院人员审核申请
     */
    @Log(title = "评优审核",businessType = BusinessType.UPDATE)
    @ApiOperation("学院人员审核申请表")
    @PostMapping("/deptAudit")
    public AjaxResult deptAudit(@RequestBody CphGoodAuditSubmmit param){
        boolean hasRole = RoleBool.isXw(getUserId(),_postService);
        if(hasRole){
            Long auditId = param.auditId;
            String status = param.status;
            String common = param.common;
            return cphGoodAuditService.deptAudit(auditId,status,common);
        }else{
            return AjaxResult.error(401,"你无权做这些");
        }

    }

    /**
     * 学工处审核申请
     */
    @Log(title = "评优审核",businessType = BusinessType.UPDATE)
    @ApiOperation("学工处审核申请表")
    @PostMapping("/finalAudit")
    public AjaxResult finalAudit(@RequestBody CphGoodAuditSubmmit param){
        boolean hasRole = RoleBool.isJwc(getUserId(),_postService);
        if(hasRole){
            Long auditId = param.auditId;
            String status = param.status;
            String common = param.common;
            return cphGoodAuditService.finalAudit(auditId,status,common);
        }else{
            return AjaxResult.error(401,"你无权做这些");
        }
    }
}
