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

/**
 * 隔离巡查登记
 */
@RestController
@RequestMapping("/tradeMarket/isolationPatrol")
public class BizIsolationPatrolController extends BaseController
{
    @Autowired
    private IBizIsolationPatrolService bizIsolationPatrolService;

    @PreAuthorize("@ss.hasPermi('tradeMarket:isolationPatrol:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizIsolationPatrol query)
    {
        startPage();
        List<BizIsolationPatrol> list = bizIsolationPatrolService.selectBizIsolationPatrolList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:isolationPatrol:list')")
    @GetMapping("/penOptions")
    public AjaxResult penOptions()
    {
        return success(bizIsolationPatrolService.selectInStockPenOptions());
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:isolationPatrol:list')")
    @GetMapping("/penEarTags")
    public AjaxResult penEarTags(@RequestParam("penId") Long penId)
    {
        return success(bizIsolationPatrolService.selectPenEarTags(penId));
    }

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

    @PreAuthorize("@ss.hasPermi('tradeMarket:isolationPatrol:add')")
    @Log(title = "隔离巡查登记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizIsolationPatrol row)
    {
        row.setCreateBy(getUsername());
        return toAjax(bizIsolationPatrolService.insertBizIsolationPatrol(row));
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:isolationPatrol:edit')")
    @Log(title = "隔离巡查登记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizIsolationPatrol row)
    {
        row.setUpdateBy(getUsername());
        return toAjax(bizIsolationPatrolService.updateBizIsolationPatrol(row));
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:isolationPatrol:remove')")
    @Log(title = "隔离巡查登记", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizIsolationPatrolService.deleteBizIsolationPatrolByIds(ids, getUsername()));
    }
}
