package com.ningdatech.pmapi.projectlib.controller;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import com.ningdatech.pmapi.projectlib.manage.AnnualPlanLibManage;
import com.ningdatech.pmapi.projectlib.model.dto.ProjectDTO;
import com.ningdatech.pmapi.projectlib.model.req.ProjectApprovedReq;
import com.ningdatech.pmapi.projectlib.model.req.ProjectIdReq;
import com.ningdatech.pmapi.projectlib.model.req.ProjectListReq;
import com.ningdatech.pmapi.projectlib.model.req.StartProjectDeclareReq;
import com.ningdatech.pmapi.projectlib.model.vo.AnnualPlanListItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

/**
 * <p>
 * AnnualPlanController
 * </p>
 *
 * @author WendyYang
 * @since 14:07 2023/2/11
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "年度计划库")
@RequestMapping("/api/v1/annualPlan")
public class AnnualPlanController {

    private final AnnualPlanLibManage annualPlanLibManage;

    @GetMapping("/list")
    @ApiOperation("年段计划库列表")
    public PageVo<AnnualPlanListItemVO> annualPlanLibList(ProjectListReq req) {
        return annualPlanLibManage.annulPlanLibList(req);
    }

    @PostMapping("/startProjectDeclared")
    @ApiOperation("开启项目申报")
    @WebLog("开启项目申报")
    public void startProjectDeclared(@RequestBody @Valid StartProjectDeclareReq req) {
        annualPlanLibManage.startProjectDeclared(req);
    }

    @PostMapping("/projectApproved")
    @ApiOperation("立项批复")
    @WebLog("立项批复")
    public void projectApproved(@RequestBody @Valid ProjectApprovedReq req) throws Exception {
        annualPlanLibManage.projectApproved(req);
    }

    @PostMapping("/suspendAnnualPlan")
    @ApiOperation("暂缓年度计划")
    @WebLog("暂缓年度计划")
    public void suspendAnnualPlan(@RequestBody @Valid ProjectIdReq req) throws Exception {
        annualPlanLibManage.suspendAnnualPlan(req);
    }

    @PostMapping("/importAnnualPlan")
    @ApiOperation("导入年度计划")
    @WebLog("导入年度计划")
    public void importAnnualPlan(MultipartFile file) {
        annualPlanLibManage.importAnnualPlan(file);
    }

    @GetMapping("/modify")
    @ApiOperation("年度计划编辑")
    @WebLog("年度计划编辑")
    public void modify(@RequestBody ProjectDTO req) {
        annualPlanLibManage.updateAnnualPlan(req);
    }
    @PostMapping("/exportList")
    @ApiOperation("项目库【列表|编辑表】导出")
    public void exportList(@Valid @RequestBody ProjectListReq param, HttpServletResponse response){
        annualPlanLibManage.exportList(param,response);
    }

}
