package com.younike.merchant;

import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.core.page.TableDataInfo;
import com.younike.common.enums.BusinessType;
import com.younike.common.utils.poi.ExcelUtil;
import com.younike.framework.config.AnonymousAccess;
import com.younike.system.domain.PublishQuote;
import com.younike.system.param.PublishQuoteParam;
import com.younike.system.service.IPublishQuoteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.younike.common.annotation.Log;

import java.util.List;

/**
 * 需求报价Controller
 *
 * @author jubs
 * @date 2022-01-24
 */
@Api("需求报价接口")
@RestController
@RequestMapping("/merchant/quote")
public class MerchantPublishQuoteController extends BaseController {
    @Autowired
    private IPublishQuoteService publishQuoteService;

    /**
     * 查询需求报价列表
     */
    @ApiOperation("查询需求报价列表")
    @GetMapping("/list")
    public TableDataInfo list(PublishQuote publishQuote) {
        startPage();
        List<PublishQuote> list = publishQuoteService.selectPublishQuoteList(publishQuote);
        return getDataTable(list);
    }

    /**
     * 导出需求报价列表
     */
    @ApiOperation("导出需求报价列表")
    @Log(title = "需求报价", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PublishQuote publishQuote) {
        List<PublishQuote> list = publishQuoteService.selectPublishQuoteList(publishQuote);
        ExcelUtil<PublishQuote> util = new ExcelUtil<PublishQuote>(PublishQuote.class);
        return util.exportExcel(list, "需求报价数据");
    }

    /**
     * 获取需求报价详细信息
     */
    @ApiOperation("获取需求报价详细信息")
    @PreAuthorize("@ss.hasPermi('system:quote:query')")
    @GetMapping(value = "/{quoteId}")
    public AjaxResult getInfo(@PathVariable("quoteId") Long quoteId) {
        return AjaxResult.success(publishQuoteService.selectPublishQuoteByQuoteId(quoteId));
    }

    /**
     * 删除报价
     */
    @ApiOperation("删除报价")
    @DeleteMapping("/{quoteId}")
    public AjaxResult deleteQuote(@PathVariable Long quoteId) {
        return publishQuoteService.deleteQuote(quoteId);
    }

    /**
     * 提交报价
     */
    @ApiOperation("提交报价")
    @PostMapping("/addQuote")
    public AjaxResult addQuote(@RequestBody PublishQuoteParam param) {
        if(ObjectUtils.isEmpty(param)
                || param.getPublishId()==null
                || param.getServerUserId() == null
                ||param.getQuoteUnit() == null
                || param.getSinglePrice() == null
                || param.getQuoteCounts() == null){
            return AjaxResult.error("参数错误");
        }
        return publishQuoteService.AddQuote(param);
    }

    /**
     * 提交报价
     */
    @ApiOperation("修改报价")
    @PostMapping("/editQuote")
    public AjaxResult editQuote(@RequestBody PublishQuoteParam param) {
        if(ObjectUtils.isEmpty(param) || param.getQuoteId()==null ||param.getQuoteUnit() == null || param.getSinglePrice() == null || param.getQuoteCounts() == null){
            return AjaxResult.error("参数错误");
        }
        return publishQuoteService.editQuote(param);
    }
}
