package com.ruoyi.web.modules.trading.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.modules.trading.domain.BizTradeOrder;
import com.ruoyi.web.modules.trading.service.IBizTradeOrderService;

/**
 * 交易订单管理
 */
@RestController
@RequestMapping("/tradeMarket/tradeOrder")
public class BizTradeOrderController extends BaseController
{
    @Autowired
    private IBizTradeOrderService bizTradeOrderService;

    @PreAuthorize("@ss.hasPermi('tradeMarket:tradeOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizTradeOrder query)
    {
        startPage();
        List<BizTradeOrder> list = bizTradeOrderService.selectBizTradeOrderList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:tradeOrder:list')")
    @GetMapping("/supplierEarTags")
    public AjaxResult supplierEarTags(@RequestParam("supplierId") Long supplierId)
    {
        return success(bizTradeOrderService.selectSupplierEarTags(supplierId));
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:tradeOrder:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizTradeOrderService.selectBizTradeOrderById(id));
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:tradeOrder:add')")
    @Log(title = "交易订单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizTradeOrder row)
    {
        row.setCreateBy(getUsername());
        return toAjax(bizTradeOrderService.insertBizTradeOrder(row));
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:tradeOrder:edit')")
    @Log(title = "交易订单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizTradeOrder row)
    {
        row.setUpdateBy(getUsername());
        return toAjax(bizTradeOrderService.updateBizTradeOrder(row));
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:tradeOrder:remove')")
    @Log(title = "交易订单管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizTradeOrderService.deleteBizTradeOrderByIds(ids, getUsername()));
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:tradeOrder:pay')")
    @Log(title = "交易订单管理", businessType = BusinessType.UPDATE)
    @PutMapping("/completePay")
    public AjaxResult completePay(@RequestBody BizTradeOrder payRequest)
    {
        BizTradeOrder result = bizTradeOrderService.completePay(payRequest, getUsername());
        return success(result);
    }
}
