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.validation.annotation.Validated;
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.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.BizIsolationPen;
import com.ruoyi.web.modules.trading.domain.BizIsolationSetting;
import com.ruoyi.web.modules.trading.service.IBizIsolationPenService;
import com.ruoyi.web.modules.trading.service.IBizIsolationSettingService;

/**
 * 隔离圈位管理
 */
@RestController
@RequestMapping("/tradeMarket/isolationPen")
public class BizIsolationPenController extends BaseController
{
    @Autowired
    private IBizIsolationPenService bizIsolationPenService;

    @Autowired
    private IBizIsolationSettingService bizIsolationSettingService;

    @PreAuthorize("@ss.hasPermi('tradeMarket:isolationPen:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizIsolationPen query)
    {
        startPage();
        List<BizIsolationPen> list = bizIsolationPenService.selectBizIsolationPenList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:isolationPen:config')")
    @GetMapping("/setting")
    public AjaxResult getSetting()
    {
        return success(bizIsolationSettingService.getCurrentSetting());
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:isolationPen:config')")
    @Log(title = "隔离圈位-默认隔离天数", businessType = BusinessType.UPDATE)
    @PutMapping("/setting")
    public AjaxResult saveSetting(@Validated @RequestBody BizIsolationSetting row)
    {
        return toAjax(bizIsolationSettingService.saveSetting(row, getUsername()));
    }

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

    @PreAuthorize("@ss.hasPermi('tradeMarket:isolationPen:add')")
    @Log(title = "隔离圈位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizIsolationPen row)
    {
        row.setCreateBy(getUsername());
        return toAjax(bizIsolationPenService.insertBizIsolationPen(row));
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:isolationPen:edit')")
    @Log(title = "隔离圈位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizIsolationPen row)
    {
        row.setUpdateBy(getUsername());
        return toAjax(bizIsolationPenService.updateBizIsolationPen(row));
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:isolationPen:remove')")
    @Log(title = "隔离圈位管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizIsolationPenService.deleteBizIsolationPenByIds(ids, getUsername()));
    }
}
