package com.ningdatech.pmapi.projectdeclared.controller;

import javax.servlet.http.HttpServletResponse;

import com.ningdatech.log.annotation.WebLog;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.pmapi.common.util.ExcelDownUtil;
import com.ningdatech.pmapi.projectdeclared.manage.PrequalificationDeclaredProjectManage;
import com.ningdatech.pmapi.projectdeclared.model.dto.DefaultDeclaredDTO;
import com.ningdatech.pmapi.projectdeclared.model.req.PrequalificationDeclaredListReq;
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;

/**
 * @Classname PrequalificationDeclaredController
 * @Description 预审申报
 * @Date 2023/2/12 9:03
 * @Author PoffyZhang
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/v1/prequalification")
@Api(value = "Prequalification", tags = "申报管理-预审申报")
@RequiredArgsConstructor
public class PrequalificationDeclaredController {

    private final PrequalificationDeclaredProjectManage prequalificationDeclaredProjectManage;

    @ApiOperation(value = "可预审申报项目列表", notes = "可预审申报项目列表")
    @GetMapping("/list")
    public PageVo<ProjectLibListItemVO> list(@Validated @ModelAttribute PrequalificationDeclaredListReq preReq) {
        return prequalificationDeclaredProjectManage.pageInfo(preReq);
    }

    @ApiOperation(value = "申报预审", notes = "申报预审")
    @WebLog("申报预审")
    @PostMapping("/start")
    public String startTheProcess(@Validated @RequestBody DefaultDeclaredDTO dto) {
        return prequalificationDeclaredProjectManage.startTheProcess(dto);
    }

    @GetMapping("/export")
    @ApiOperation("可预审申报项目列表导出")
    @WebLog("可预审申报项目列表导出")
    public void exportList(PrequalificationDeclaredListReq preReq, HttpServletResponse response){
        ExcelDownUtil.downXls(response,preReq,prequalificationDeclaredProjectManage::exportList);
    }
}
