package com.ningdatech.pmapi.todocenter.controller;


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

import com.ningdatech.pmapi.common.util.ExcelDownUtil;
import com.ningdatech.pmapi.todocenter.bean.vo.ProcessProgressDetailVo;
import com.ningdatech.pmapi.todocenter.model.dto.req.ReqProcessHandlerDTO;
import org.springframework.web.bind.annotation.*;

import com.ningdatech.basic.model.ApiResponse;
import com.ningdatech.basic.model.PageVo;
import com.ningdatech.pmapi.todocenter.manage.TodoCenterManage;
import com.ningdatech.pmapi.todocenter.model.dto.req.ReqToBeProcessedDTO;
import com.ningdatech.pmapi.todocenter.model.dto.res.ResToBeProcessedDTO;

import io.swagger.annotations.Api;
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;

    /**
     * 待办中心-待我处理项目列表查询
     * @param param
     * @return
     */
    @GetMapping("/query-todo-list")
    public ApiResponse<PageVo<ResToBeProcessedDTO>> queryPendingProjectList(@Valid @ModelAttribute ReqToBeProcessedDTO param){
        PageVo<ResToBeProcessedDTO> result = todoCenterManage.queryPendingProjectList(param);
        return ApiResponse.ofSuccess(result);
    }

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

    /**
     * 查询流程表单数据及审批的进度步骤
     * @param instanceId 流程实例ID
     * @param nodeId 当前获取流程人员关联的流程节点ID
     * @return 流程进度及表单详情
     */
    @GetMapping("/progress/{instanceId}/{nodeId}")
    public ApiResponse<ProcessProgressDetailVo> getProcessDetail(@PathVariable String instanceId,
                                                                 @PathVariable(required = false) String nodeId) {
        return ApiResponse.ofSuccess(todoCenterManage.getProcessDetail(nodeId, instanceId));
    }

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

    /**
     * 待办中心-我已处理项目列表查询
     * @param param
     * @return
     */
    @GetMapping("/query-do-list")
    public ApiResponse<PageVo<ResToBeProcessedDTO>> queryHandledProjectList(@Valid @ModelAttribute ReqToBeProcessedDTO param){
        PageVo<ResToBeProcessedDTO> result = todoCenterManage.queryHandledProjectList(param);
        return ApiResponse.ofSuccess(result);
    }
    /**
     * 待办中心-我已处理项目列表导出
     *
     * @param param
     * @param response
     * @return void
     */
    @PostMapping("/exportHandled")
    public void exportHandledProjectList(@Valid @RequestBody ReqToBeProcessedDTO param, HttpServletResponse response){
        todoCenterManage.exportHandledProjectList(response,param);
    }

    /**
     * 待办中心-我发起的项目列表查询
     * @param param
     * @return
     */
    @GetMapping("/query-mySubmitted-list")
    public ApiResponse<PageVo<ResToBeProcessedDTO>> queryMySubmittedProjectList(@Valid @ModelAttribute ReqToBeProcessedDTO param){
        PageVo<ResToBeProcessedDTO> result = todoCenterManage.queryMySubmittedProjectList(param);
        return ApiResponse.ofSuccess(result);
    }

    /**
     * 待办中心-我发起的项目列表导出
     *
     * @param param
     * @param response
     * @return void
     */
    @PostMapping("/exportMySubmitted")
    public void exportMySubmittedProjectList(@Valid @RequestBody ReqToBeProcessedDTO param, HttpServletResponse response){
        todoCenterManage.exportMySubmittedProjectList(response,param);
    }

    /**
     * 待办中心-抄送我的项目列表查询
     * @param param
     * @return
     */
    @GetMapping("/query-CcMe-list")
    public ApiResponse<PageVo<ResToBeProcessedDTO>> queryCcMeProjectList(@Valid @ModelAttribute ReqToBeProcessedDTO param){
        PageVo<ResToBeProcessedDTO> result = todoCenterManage.queryCcMeProjectList(param);
        return ApiResponse.ofSuccess(result);
    }

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