package com.ningdatech.pmapi.todocenter.controller;


import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.ningdatech.log.annotation.WebLog;
import com.ningdatech.pmapi.todocenter.model.vo.NotSealedInfoVO;
import com.ningdatech.pmapi.todocenter.model.vo.TodoNumVO;
import com.wflow.workflow.bean.dto.ReqAuditOpinionSaveDTO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.pmapi.todocenter.manage.TodoCenterManage;
import com.ningdatech.pmapi.todocenter.model.dto.AdjustHandleDTO;
import com.ningdatech.pmapi.todocenter.model.dto.SealInfoDTO;
import com.ningdatech.pmapi.todocenter.model.req.ProcessDetailReq;
import com.ningdatech.pmapi.todocenter.model.req.ToBeProcessedExportReq;
import com.ningdatech.pmapi.todocenter.model.req.ToBeProcessedReq;
import com.ningdatech.pmapi.todocenter.model.vo.ProcessProgressDetailVo;
import com.ningdatech.pmapi.todocenter.model.vo.ResToBeProcessedVO;
import com.wflow.workflow.bean.dto.ReqProcessHandlerDTO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;

/**
 * <p>
 *  待办中心 前端控制器
 * </p>
 *
 * @author CMM
 * @since 2023-01-12
 */
@RestController
@AllArgsConstructor
@Api(tags = "待办中心控制器")
@RequestMapping("/api/v1/todo-center")
public class TodoCenterController {

    private final TodoCenterManage todoCenterManage;

    /**
     * 实时取当前操作人 某个工作流的下一个操作taskId
     */
    @GetMapping("/todo/taskId/{instanceId}")
    public String todoTaskId(@PathVariable String instanceId){
        return todoCenterManage.todoTaskId(instanceId);
    }

    /**
     * 待办中心-待我处理项目列表查询
     * @param param
     * @return
     */
    @GetMapping("/todo-list")
    public PageVo<ResToBeProcessedVO> todoList(@Valid @ModelAttribute ToBeProcessedReq param){
        return todoCenterManage.todoProjectList(param);
    }

    /**
     * 待办中心-待我处理项目列表导出
     * 
     * @param param
     * @param response
     * @return void
     */
    @PostMapping("/todo-list/export")
    @WebLog("待办中心-待我处理项目列表导出")
    public void exportPendingProjectList(@Valid @RequestBody ToBeProcessedExportReq param,
                                         HttpServletResponse response){
        todoCenterManage.exportTodoList(response,param);
    }

    /**
     * 查询流程表单数据及审批的进度步骤
     * @param request 请求参数
     * @return 流程进度及表单详情
     */
    @GetMapping("/progress/detail")
    public ProcessProgressDetailVo getProcessDetail(@Valid @ModelAttribute ProcessDetailReq request) {
        return todoCenterManage.getProcessDetail(request);
    }

    /**
     * 审核通过，盖章并通过、退回、撤回、驳回等操作
     * @param param 操作参数
     * @return 操作结果
     */
    @PostMapping("/handler")
    @WebLog("审核通过，盖章并通过、退回、撤回、驳回等操作")
    public Object handler(@Valid @RequestBody ReqProcessHandlerDTO param) {
        String nextTaskId = todoCenterManage.handler(param);
        return nextTaskId;
    }

    /**
     * 保存盖章审核提交的审核意见
     * @param param 操作参数
     * @return 操作结果
     */
    @PostMapping("/saveAuditOpinion")
    @WebLog("保存盖章审核提交的审核意见")
    public Object saveAuditOpinion(@Valid @RequestBody ReqAuditOpinionSaveDTO param) {
        return todoCenterManage.saveAuditOpinion(param);
    }



    /**
     * 待办中心-我已处理项目列表查询
     * @param param
     * @return
     */
    @GetMapping("/ido-list")
    public PageVo<ResToBeProcessedVO> idoList(@ModelAttribute ToBeProcessedReq param){
        return todoCenterManage.idoList(param);
    }
    /**
     * 待办中心-我已处理项目列表导出
     *
     * @param param
     * @param response
     * @return void
     */
    @PostMapping("/ido-list/export")
    public void exportHandledProjectList(@RequestBody ToBeProcessedExportReq param,
                                         HttpServletResponse response){
        todoCenterManage.idoExport(response,param);
    }

    /**
     * 待办中心-我发起的项目列表查询
     * @param param
     * @return
     */
    @GetMapping("/my-submitted-list")
    public PageVo<ResToBeProcessedVO> mySubmittedList(@ModelAttribute ToBeProcessedReq param){
        return todoCenterManage.mySubmittedList(param);
    }

    /**
     * 待办中心-我发起的项目列表导出
     *
     * @param param
     * @param response
     * @return void
     */
    @PostMapping("/my-submitted-list/export")
    public void exportMySubmittedList(@RequestBody ToBeProcessedExportReq param,
                                             HttpServletResponse response){
        todoCenterManage.exportMySubmittedList(response,param);
    }

    /**
     * 待办中心-抄送我的项目列表查询
     * @param param
     * @return
     */
    @GetMapping("/ccme-list")
    public PageVo<ResToBeProcessedVO> ccmeList(@Valid @ModelAttribute ToBeProcessedReq param){
        return todoCenterManage.ccmeList(param);
    }

    /**
     * 待办中心-抄送我的项目列表导出
     *
     * @param param
     * @param response
     * @return void
     */
    @PostMapping("/ccme-list/export")
    public void exportCcMeProjectList(@Valid @RequestBody ToBeProcessedExportReq param, HttpServletResponse response){
        todoCenterManage.exportCcMeProjectList(response,param);
    }

    @ApiOperation(value = "被退回项目内容调整并通过", notes = "被退回项目内容调整并通过")
    @PostMapping("/adjustAndHandle")
    @WebLog("被退回项目内容调整并通过")
    public String startTheProcess(@Validated @RequestBody AdjustHandleDTO dto) {
        String instanceId = todoCenterManage.adjustmentAndHandle(dto);
        return "退回项目内容调整并且重新通过 【" + instanceId + "】 成功";
    }

    @ApiOperation("获取未签章的pdf文件")
    @WebLog("获取未签章的pdf文件")
    @PostMapping("/getNotSealedPdf")
    public NotSealedInfoVO getNotSealedPdf (@Valid @RequestBody SealInfoDTO req){
        return todoCenterManage.getNotSealedPdf(req);
    }

    @ApiOperation("获取签章后的pdf文件")
    @WebLog("获取签章后的pdf文件")
    @PostMapping("/getSealedPdf")
    public Long getSealedPdf(@Valid @RequestBody SealInfoDTO req){
        return todoCenterManage.getSealedPdf(req);
    }

    @ApiOperation("待办中心待我处理数量统计")
    @GetMapping("/getTodoNums")
    public TodoNumVO getTodoNums(@Valid @ModelAttribute ToBeProcessedReq param){
        return todoCenterManage.getTodoNums(param);
    }
}
