package com.ningdatech.pmapi.projectdeclared.controller;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import com.ningdatech.pmapi.common.util.ExcelDownUtil;
import com.ningdatech.pmapi.projectdeclared.manage.DelayedApplyManage;
import com.ningdatech.pmapi.projectdeclared.model.dto.DelayedApplyDTO;
import com.ningdatech.pmapi.projectdeclared.model.vo.DelayedApplyVO;
import com.ningdatech.pmapi.projectlib.model.req.ProjectListReq;
import com.ningdatech.pmapi.projectlib.model.vo.ProjectLibListItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Classname DelayedProjectController
 * @Description
 * @Date 2023/6/7 18:50
 * @Author PoffyZhang
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/v1/declared/delayed")
@Api(value = "DelayedProjectController", tags = "申报管理-延期项目")
@RequiredArgsConstructor
public class DelayedApplyController {

    private final DelayedApplyManage delayedApplyManage;

    @ApiOperation(value = "过期的项目列表", notes = "过期的项目列表")
    @GetMapping("/project-list")
    public PageVo<ProjectLibListItemVO> projectlist(@ModelAttribute ProjectListReq req) {
        return delayedApplyManage.projectLibList(req);
    }

    @ApiOperation(value = "查看某个项目的延期列表", notes = "查看某个项目的延期列表")
    @GetMapping("/delay-list/{projectId}")
    public List<DelayedApplyVO> delayList(@PathVariable Long projectId) {
        return delayedApplyManage.delayList(projectId);
    }

    @ApiOperation(value = "延期的内容详情", notes = "延期的内容详情")
    @GetMapping("/detail/{projectId}")
    public DelayedApplyVO detailByProjectId(@PathVariable Long projectId) {
        return delayedApplyManage.detailByProjectId(projectId);
    }

    @GetMapping("/export")
    @ApiOperation("过期的项目列表导出")
    @WebLog("过期的项目列表导出")
    public void exportList(ProjectListReq req, HttpServletResponse response){
        ExcelDownUtil.downXls(response,req,delayedApplyManage::exportList);
    }

    @ApiOperation(value = "延期申报", notes = "延期申报")
    @WebLog("延期申报")
    @PostMapping("/apply")
    public String delayedApply(@Validated @RequestBody DelayedApplyDTO dto) {
        String instanceId = delayedApplyManage.startDelayedApplyProcess(dto);
        return "启动延期申请流程实例 【" + instanceId + "】 成功";
    }
}
