package com.ningdatech.pmapi.todocenter.controller;


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

import com.ningdatech.pmapi.projectdeclared.model.dto.DefaultDeclaredDTO;
import com.ningdatech.pmapi.todocenter.model.dto.AdjustHandleDTO;
import com.ningdatech.pmapi.todocenter.model.vo.ProcessProgressDetailVo;
import com.ningdatech.pmapi.todocenter.model.req.ProcessDetailReq;
import com.ningdatech.pmapi.todocenter.model.req.ToBeProcessedExportReq;
import com.wflow.workflow.bean.dto.ReqProcessHandlerDTO;
import io.swagger.annotations.ApiOperation;
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.req.ToBeProcessedReq;
import com.ningdatech.pmapi.todocenter.model.vo.ResToBeProcessedVO;

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("/todo-list/{isTemporaryAugment}")
    public PageVo<ResToBeProcessedVO> todoList(@ModelAttribute ToBeProcessedReq param,
                                               @PathVariable Integer isTemporaryAugment){
        param.setIsTemporaryAugment(isTemporaryAugment);
        return todoCenterManage.todoProjectList(param);
    }

    /**
     * 待办中心-待我处理项目列表导出
     * 
     * @param param
     * @param response
     * @return void
     */
    @PostMapping("/todo-list/export/{isTemporaryAugment}")
    public void exportPendingProjectList(@Valid @RequestBody ToBeProcessedExportReq param,
                                         HttpServletResponse response,@PathVariable Integer isTemporaryAugment){
        param.setIsTemporaryAugment(isTemporaryAugment);
        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")
    public Object handler(@Valid @RequestBody ReqProcessHandlerDTO param) {
        todoCenterManage.handler(param);
        return "操作成功";
    }

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

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

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

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

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

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