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.FinalAcceptanceManage;
import com.ningdatech.pmapi.projectdeclared.model.dto.DefaultDeclaredDTO;
import com.ningdatech.pmapi.projectdeclared.model.vo.FinalAcceptanceVO;
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;


/**
 * @Classname FinalAcceptanceController
 * @Description 申报项目-终验
 * @Date 2023/6/2 09:29
 * @Author PoffyZhang
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/v1/declared/final-acc")
@Api(value = "FinalAcceptanceController", tags = "申报管理-终验")
@RequiredArgsConstructor
public class FinalAcceptanceController {
    private final FinalAcceptanceManage finalAcceptanceManage;

    @ApiOperation(value = "待终验申报的项目列表", notes = "待终验申报的项目列表")
    @GetMapping("/project-list")
    public PageVo<ProjectLibListItemVO> projectlist(@ModelAttribute ProjectListReq req) {
        return finalAcceptanceManage.projectLibList(req);
    }

    @GetMapping("/export")
    @ApiOperation("待终验申报的项目导出")
    @WebLog("待终验申报的项目导出")
    public void exportList(ProjectListReq req, HttpServletResponse response){
        ExcelDownUtil.downXls(response,req,finalAcceptanceManage::exportList);
    }

    @ApiOperation(value = "待终验申报的项目列表", notes = "待终验申报的项目列表")
    @GetMapping("/detail/{projectId}")
    public FinalAcceptanceVO detailByProjectId(@PathVariable Long projectId) {
        return finalAcceptanceManage.detailByProjectId(projectId);
    }

    @ApiOperation(value = "终验申报", notes = "终验申报")
    @WebLog("终验申报")
    @PostMapping("/start-process")
    public String startTheProcess(@Validated @RequestBody DefaultDeclaredDTO dto) {
        String instanceId = finalAcceptanceManage.startProcess(dto);
        return "终验申报 【" + instanceId + "】 成功";
    }

    @ApiOperation(value = "终验申报重新提交", notes = "终验申报重新提交")
    @WebLog("终验申报重新提交")
    @PostMapping("/restart-process")
    public String restartTheProcess(@Validated @RequestBody DefaultDeclaredDTO dto) {
        String instanceId = finalAcceptanceManage.restartProcess(dto);
        return "终验申报 【" + instanceId + "】 成功";
    }
}
