package com.ruoyi.hezhi.controller;

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.common.utils.poi.ExcelUtil;
import com.ruoyi.hezhi.domain.TbConfig;
import com.ruoyi.hezhi.service.ITbConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 相关设置Controller
 *
 * @author ruoyi
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/hezhi/config")
public class TbConfigController extends BaseController
{
    @Autowired
    private ITbConfigService tbConfigService;

    /**
     * 查询相关设置列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbConfig tbConfig)
    {
        startPage();
        List<TbConfig> list = tbConfigService.selectTbConfigList(tbConfig);
        return getDataTable(list);
    }

    /**
     * 导出相关设置列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:config:export')")
    @Log(title = "相关设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbConfig tbConfig)
    {
        List<TbConfig> list = tbConfigService.selectTbConfigList(tbConfig);
        ExcelUtil<TbConfig> util = new ExcelUtil<TbConfig>(TbConfig.class);
        util.exportExcel(response, list, "相关设置数据");
    }

    /**
     * 获取相关设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:config:query')")
    @GetMapping(value = "/{configId}")
    public AjaxResult getInfo(@PathVariable("configId") Long configId)
    {
        return success(tbConfigService.selectTbConfigByConfigId(configId));
    }

    /**
     * 新增相关设置
     */
    @PreAuthorize("@ss.hasPermi('hezhi:config:add')")
    @Log(title = "相关设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbConfig tbConfig)
    {
        return toAjax(tbConfigService.insertTbConfig(tbConfig));
    }

    /**
     * 修改相关设置
     */
    @PreAuthorize("@ss.hasPermi('hezhi:config:edit')")
    @Log(title = "相关设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbConfig tbConfig)
    {
        return toAjax(tbConfigService.updateTbConfig(tbConfig));
    }

    /**
     * 删除相关设置
     */
    @PreAuthorize("@ss.hasPermi('hezhi:config:remove')")
    @Log(title = "相关设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{configIds}")
    public AjaxResult remove(@PathVariable Long[] configIds)
    {
        return toAjax(tbConfigService.deleteTbConfigByConfigIds(configIds));
    }
}
