package com.ningdatech.pmapi.projectlib.controller;


import com.ningdatech.basic.model.PageVo;
import com.ningdatech.pmapi.common.util.ExcelDownUtil;
import com.ningdatech.pmapi.projectlib.manage.ProjectRenewalFundManage;
import com.ningdatech.pmapi.projectlib.model.dto.ProjectRenewalFundDeclarationDTO;
import com.ningdatech.pmapi.projectlib.model.req.ProjectRenewalAuditReq;
import com.ningdatech.pmapi.projectlib.model.req.ProjectRenewalListReq;
import com.ningdatech.pmapi.projectlib.model.vo.ProjectRenewalFundDeclarationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 续建项目资金申请表 前端控制器
 * </p>
 *
 * @author WendyYang
 * @since 2023-02-15
 */
@RestController
@RequestMapping("/api/v1/project/renewal")
@AllArgsConstructor
@Api(tags = "续建项目资金库")
public class ProjectRenewalFundDeclarationController {
    private final ProjectRenewalFundManage projectRenewalFundManage;

    @GetMapping("/list")
    @ApiOperation("项目续建资金库")
    public PageVo<ProjectRenewalFundDeclarationVO> list(ProjectRenewalListReq req) {
        return projectRenewalFundManage.list(req);
    }

    @GetMapping("/{id}")
    @ApiOperation("项目续建资金详情")
    private ProjectRenewalFundDeclarationVO detail (@PathVariable Long id){
        return projectRenewalFundManage.detail(id);
    }

    @PostMapping("/declared")
    @ApiOperation("项目续建资金申请")
    private Long declared (@Validated @RequestBody ProjectRenewalFundDeclarationDTO dto){
        return projectRenewalFundManage.declared(dto);
    }

    @PostMapping("/audit")
    @ApiOperation("续建项目审核")
    private Long audit(@Validated @RequestBody ProjectRenewalAuditReq param){
        return projectRenewalFundManage.audit(param);
    }

    @DeleteMapping("/delete/{projectRenewalId}")
    @ApiOperation("续建项目删除")
    private Long delete(@PathVariable("projectRenewalId") Long projectRenewalId){
        return projectRenewalFundManage.delete(projectRenewalId);
    }

    @GetMapping("/export")
    @ApiOperation("续建项目列表导出")
    private void exportList(ProjectRenewalListReq req, HttpServletResponse response){
        ExcelDownUtil.downXls(response,req,projectRenewalFundManage::exportList);
    }

}
