package com.hz.pm.api.projectdeclared.controller;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import com.hz.pm.api.common.util.ExcelDownUtil;
import com.hz.pm.api.projectdeclared.manage.ConstructionPlanManage;
import com.hz.pm.api.projectdeclared.model.dto.ContructionSuggestionsDTO;
import com.hz.pm.api.projectdeclared.model.dto.DefaultDeclaredDTO;
import com.hz.pm.api.projectdeclared.model.req.ConstrctionPlanListReq;
import com.hz.pm.api.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 ConstructionPlanController
 * @Description 建设方案申报
 * @Date 2023/2/13 9:53
 * @Author PoffyZhang
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/v1/construction")
@Api(value = "ConstructionPlan", tags = "申报管理-建设方案申报")
@RequiredArgsConstructor
public class ConstructionPlanController {

    private final ConstructionPlanManage constructionPlanManage;

    @ApiOperation(value = "可申报建设方案项目列表", notes = "可申报建设方案项目列表")
    @GetMapping("/list")
    public PageVo<ProjectLibListItemVO> list(@Validated @ModelAttribute ConstrctionPlanListReq planReq) {
        return constructionPlanManage.projectLibList(planReq);
    }

    @ApiOperation(value = "建设方案申报", notes = "建设方案申报")
    @WebLog("建设方案申报")
    @PostMapping("/start")
    public String startTheProcess(@Validated @RequestBody DefaultDeclaredDTO dto) {
        String instanceId = constructionPlanManage.startTheProcess(dto);
        return "建设方案申报 【" + instanceId + "】 成功";
    }

    @GetMapping("/export")
    @ApiOperation("可申报建设方案项目列表导出")
    @WebLog("可申报建设方案项目列表导出")
    public void exportList(ConstrctionPlanListReq planReq, HttpServletResponse response) {
        ExcelDownUtil.downXls(response, planReq, constructionPlanManage::exportList);
    }

    @ApiOperation(value = "建设方案专家建议", notes = "建设方案专家建议")
    @WebLog("建设方案专家建议")
    @PostMapping("/construction-suggestions")
    public String constructionSuggestions(@Validated @RequestBody ContructionSuggestionsDTO dto) {
        constructionPlanManage.constructionSuggestions(dto);
        return "专家建设方案建议保存成功";
    }
}
