package com.bonus.canteen.core.supply.purchase.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bonus.canteen.core.supply.purchase.domain.param.*;
import com.bonus.canteen.core.supply.purchase.domain.vo.DrpFinalBidsQuotePageVO;
import com.bonus.canteen.core.supply.purchase.domain.vo.DrpInquiryAddVO;
import com.bonus.canteen.core.supply.purchase.domain.vo.DrpInquiryPageVO;
import com.bonus.canteen.core.supply.purchase.service.DrpInquiryService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.security.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

@RestController
@Api(
   value = "ffc_询价接口",
   tags = {"ffc_询价接口"}
)
@RequestMapping({"/api/v1/drpinquiry"})
public class DrpInquiryController extends BaseController {
   private static final Logger log = LoggerFactory.getLogger(DrpInquiryController.class);
   @Autowired
   @Lazy
   private DrpInquiryService drpInquiryService;

   @PostMapping({"/save"})
   @ApiOperation("新增/编辑保存询价单")
   public AjaxResult saveInquiry(@RequestBody @Valid DrpInquiryAddDTO request) {
      DrpInquiryAddVO result = this.drpInquiryService.saveInquiryAndDetails(request);
      return AjaxResult.success(result);
   }

   @PostMapping({"/commit"})
   @ApiOperation("新增/编辑提交询价单")
   public AjaxResult commitInquiry(@RequestBody @Valid DrpInquiryAddDTO request) {
      DrpInquiryAddVO result = this.drpInquiryService.commitInquiryAndDetails(request);
      return AjaxResult.success(result);
   }

   @PostMapping({"/page"})
   @ApiOperation("分页查询询价单")
   public TableDataInfo queryInquiry(@RequestBody @Valid DrpInquiryPageDTO request) {
      startPage();
      List<DrpInquiryPageVO> result = this.drpInquiryService.queryInquiry(request);
      return getDataTable(result);
   }

   @PostMapping({"/delete"})
   @ApiOperation("删除待提交的询价单")
   public AjaxResult deleteNotCommitInquiry(@RequestBody DrpInquiryAddVO request) {
      this.drpInquiryService.deleteNotCommitInquiry(request);
      return AjaxResult.success();
   }

   /** @deprecated */
   @PostMapping({"/cancel"})
   @ApiOperation("取消询价")
   public AjaxResult cancelInquiry(@RequestBody DrpInquiryAddVO request) {
      this.drpInquiryService.cancelInquiry(request);
      return AjaxResult.success();
   }

   @PostMapping({"/list/supplier-quote/{inquiryId}"})
   @ApiOperation("查询询价单报价总详情")
   public AjaxResult listSupplierQuote(@PathVariable("inquiryId") String inquiryId) {
      return AjaxResult.success(this.drpInquiryService.listSupplierQuote(inquiryId));
   }

   @PostMapping({"/finalBidsQuote"})
   @ApiOperation("查询各个供应商报价明细")
   public AjaxResult finalBidsQuote(@RequestBody DrpFinalBidsDTO request) {
      List<DrpFinalBidsQuotePageVO> result = this.drpInquiryService.finalBidsQuote(request);
      return AjaxResult.success(result);
   }

   @PostMapping({"/commitFinalBids"})
   @ApiOperation("采购决标")
   public AjaxResult commitFinalBids(@RequestBody @Valid DrpCommitFinalBidsDTO request) {
      this.drpInquiryService.commitFinalBids(request);
      return AjaxResult.success();
   }

   @PostMapping({"/query/supplier-quote/detail/{inquirySupplierId}"})
   @ApiOperation("查看供应商报价详情")
   public AjaxResult querySupplierQuoteDetail(@PathVariable("inquirySupplierId") Long inquirySupplierId) {
      return AjaxResult.success(this.drpInquiryService.querySupplierQuoteDetail(inquirySupplierId));
   }

   @PostMapping({"/sendNotice/{inquiryId}"})
   @ApiOperation("手动通知")
   public AjaxResult sendNotice(@PathVariable("inquiryId") String inquiryId) {
      this.drpInquiryService.sendNotice(inquiryId);
      return AjaxResult.success();
   }

   @PostMapping({"/upload"})
   @ApiOperation("采购询价和货品招标上传")
   public AjaxResult upload(@RequestBody @Valid DrpQuoteInquiryPicDTO request) {
      this.drpInquiryService.upload(request);
      return AjaxResult.success();
   }
}
