package com.ruoyi.web.controller.system;

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.system.domain.SysRuleManagement;
import com.ruoyi.system.service.ISysRuleManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 物资规则管理Controller
 *
 * @author
 * @date
 */
@RestController
@RequestMapping("/system/ruleManagement")
public class SysRuleManagementController extends BaseController
{

    @Autowired
    private ISysRuleManagementService iSysRuleManagement;

    /**
     * 物资规则管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:ruleManagement:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRuleManagement sysRuleManagement)
    {
        startPage();
        List<SysRuleManagement> list = iSysRuleManagement.list(sysRuleManagement);
        return getDataTable(list);
    }

    /**
     * 获取规则详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ruleManagement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        System.out.println("从前端接收到的id是"+id);
        return AjaxResult.success(iSysRuleManagement.selectExcelById(id));
    }

    /**
     * 新增规则
     */
    @PreAuthorize("@ss.hasPermi('system:ruleManagement:add')")
    @Log(title = "规则详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysRuleManagement sysRuleManagement)
    {
        return toAjax(iSysRuleManagement.add(sysRuleManagement));
    }

    /**
     * 修改规则
     */
    @PreAuthorize("@ss.hasPermi('system:ruleManagement:edit')")
    @Log(title = "规则详情", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody SysRuleManagement sysRuleManagement)
    {
        return toAjax(iSysRuleManagement.updateRule(sysRuleManagement));
    }

    /**
     * 删除规则
     */
    @PreAuthorize("@ss.hasPermi('system:ruleManagement:remove')")
    @Log(title = "规则详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(iSysRuleManagement.deleteRuleById(id));
    }


}
