package com.ruoyi.frequency.platformrules.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.enums.BusinessType;
import com.ruoyi.frequency.platformrules.entity.PlatformRules;
import com.ruoyi.frequency.platformrules.service.PlatformRulesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 平台规则Controller
 *
 * @author liwenlong
 * @date 2024-01-24
 */
@RestController
@RequestMapping("/frequency/platformrules")
public class PlatformRulesController extends BaseController
{
    @Autowired
    private PlatformRulesService platformRulesService;

    /**
     * 查询平台规则列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:platformrules:list')")
    @PostMapping("/list")
    public TableDataInfo<PlatformRules> list(@RequestBody PlatformRules platformRules)
    {
        startPage();
        List<PlatformRules> list = platformRulesService.selectPlatformRulesList(platformRules);
        return getDataTable(list);
    }

    /**
     * 导出平台规则列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:platformrules:export')")
    @Log(title = "平台规则", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PlatformRules platformRules)
    {
        List<PlatformRules> list = platformRulesService.selectPlatformRulesList(platformRules);
        ExcelUtil<PlatformRules> util = new ExcelUtil<PlatformRules>(PlatformRules.class);
        return util.exportExcel(list, "平台规则数据");
    }

    /**
     * 获取平台规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:platformrules:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<PlatformRules> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(platformRulesService.selectPlatformRulesById(id));
    }

    /**
     * 新增平台规则
     */
    @PreAuthorize("@ss.hasPermi('frequency:platformrules:add')")
    @Log(title = "平台规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlatformRules platformRules)
    {
        return toAjax(platformRulesService.insertPlatformRules(platformRules));
    }

    /**
     * 修改平台规则
     */
    @PreAuthorize("@ss.hasPermi('frequency:platformrules:edit')")
    @Log(title = "平台规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlatformRules platformRules)
    {
        return toAjax(platformRulesService.updatePlatformRules(platformRules));
    }

    /**
     * 删除平台规则
     */
    @PreAuthorize("@ss.hasPermi('frequency:platformrules:remove')")
    @Log(title = "平台规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(platformRulesService.deletePlatformRulesByIds(ids,delFlag));
    }
}
