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.BizMarketEntry;
import com.ruoyi.web.modules.trading.service.IBizMarketEntryService;

/**
 * 市场进栏登记
 */
@RestController
@RequestMapping("/tradeMarket/marketEntry")
public class BizMarketEntryController extends BaseController
{
    @Autowired
    private IBizMarketEntryService bizMarketEntryService;

    @PreAuthorize("@ss.hasPermi('tradeMarket:marketEntry:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizMarketEntry query)
    {
        startPage();
        List<BizMarketEntry> list = bizMarketEntryService.selectBizMarketEntryList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:marketEntry:list')")
    @GetMapping("/stallOptions")
    public AjaxResult stallOptions()
    {
        return success(bizMarketEntryService.selectStallOptions());
    }

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

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

    @PreAuthorize("@ss.hasPermi('tradeMarket:marketEntry:add')")
    @Log(title = "市场进栏登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizMarketEntry row)
    {
        row.setCreateBy(getUsername());
        return toAjax(bizMarketEntryService.insertBizMarketEntry(row));
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:marketEntry:edit')")
    @Log(title = "市场进栏登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizMarketEntry row)
    {
        row.setUpdateBy(getUsername());
        return toAjax(bizMarketEntryService.updateBizMarketEntry(row));
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:marketEntry:remove')")
    @Log(title = "市场进栏登记", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizMarketEntryService.deleteBizMarketEntryByIds(ids, getUsername()));
    }
}
