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.ProjectAdjustmentManage;
import com.ningdatech.pmapi.projectdeclared.manage.PurchaseManage;
import com.ningdatech.pmapi.projectdeclared.model.dto.PurchaseSaveDTO;
import com.ningdatech.pmapi.projectdeclared.model.vo.PurchaseVO;
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;
import java.util.List;

/**
 * @Classname PurchaseController
 * @Description 申报项目-采购结果备案
 * @Date 2023/5/29 09:29
 * @Author PoffyZhang
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/v1/declared/purchase")
@Api(value = "PurchaseController", tags = "申报管理-采购结果备案")
@RequiredArgsConstructor
public class PurchaseController {
    private final PurchaseManage purchaseManage;

    private final ProjectAdjustmentManage projectAdjustmentManage;

    @ApiOperation(value = "待采购结果备案列表", notes = "待采购结果备案列表")
    @GetMapping("/project-list")
    public PageVo<ProjectLibListItemVO> projectlist(@ModelAttribute ProjectListReq req) {
        return purchaseManage.projectLibList(req);
    }

    @ApiOperation(value = "采购结果备案详情", notes = "采购结果备案详情")
    @GetMapping("/detail/{projectId}")
    public List<PurchaseVO> detailByProjectId(@PathVariable Long projectId) {
        return purchaseManage.detailByProjectId(projectId);
    }

    @GetMapping("/export")
    @ApiOperation("待采购结果备案列表导出")
    @WebLog("待采购结果备案列表导出")
    public void exportList(ProjectListReq req, HttpServletResponse response) {
        ExcelDownUtil.downXls(response, req, purchaseManage::exportList);
    }

    @ApiOperation(value = "填写采购结果", notes = "填写采购结果")
    @WebLog("填写采购结果")
    @PostMapping("/submit-result")
    public String submitResult(@Validated @RequestBody PurchaseSaveDTO dto) {
        return purchaseManage.submitResult(dto);
    }

}
