package com.xiaoniu.system.platformsettings.rule.controller;

import com.xiaoniu.common.core.utils.poi.ExcelUtil;
import com.xiaoniu.common.core.web.controller.BaseController;
import com.xiaoniu.common.core.web.domain.AjaxResult;
import com.xiaoniu.common.core.web.page.TableDataInfo;
import com.xiaoniu.common.log.annotation.Log;
import com.xiaoniu.common.log.enums.BusinessType;
import com.xiaoniu.common.security.annotation.RequiresPermissions;
import com.xiaoniu.system.platformsettings.rule.domain.TbRule;
import com.xiaoniu.system.platformsettings.rule.service.ITbRuleService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 平台规则Controller
 * 
 * @author xiaoniu
 * @date 2024-04-14
 */
@RestController
@RequestMapping("/rule")
public class TbRuleController extends BaseController
{
    @Autowired
    private ITbRuleService tbRuleService;

    /**
     * 查询平台规则列表
     */
    @RequiresPermissions("museum:rule:list")
    @GetMapping("/list")
    public TableDataInfo list(TbRule tbRule)
    {
        startPage();
        List<TbRule> list = tbRuleService.selectTbRuleList(tbRule);
        return getDataTable(list);
    }

    /**
     * 导出平台规则列表
     */
    @RequiresPermissions("museum:rule:export")
    @Log(title = "平台规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbRule tbRule)
    {
        List<TbRule> list = tbRuleService.selectTbRuleList(tbRule);
        ExcelUtil<TbRule> util = new ExcelUtil<TbRule>(TbRule.class);
        util.exportExcel(response, list, "平台规则数据");
    }

    /**
     * 获取平台规则详细信息
     */
    @RequiresPermissions("museum:rule:query")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId)
    {
        return success(tbRuleService.selectTbRuleByRuleId(ruleId));
    }

    /**
     * 新增平台规则
     */
    @RequiresPermissions("museum:rule:add")
    @Log(title = "平台规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbRule tbRule)
    {
        return toAjax(tbRuleService.insertTbRule(tbRule));
    }

    /**
     * 修改平台规则
     */
    @RequiresPermissions("museum:rule:edit")
    @Log(title = "平台规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbRule tbRule)
    {
        return toAjax(tbRuleService.updateTbRule(tbRule));
    }

    /**
     * 删除平台规则
     */
    @RequiresPermissions("museum:rule:remove")
    @Log(title = "平台规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds)
    {
        return toAjax(tbRuleService.deleteTbRuleByRuleIds(ruleIds));
    }
}
