RuoYi
2024-05-29 4b699cd34c729f36a6ad4bb9ddcc0520c4bf3e61
src/main/java/com/ruoyi/project/system/controller/SysConfigController.java
@@ -1,6 +1,7 @@
package com.ruoyi.project.system.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
@@ -12,8 +13,6 @@
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.constant.UserConstants;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
@@ -49,12 +48,12 @@
    @Log(title = "参数管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping("/export")
    public AjaxResult export(SysConfig config)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysConfig config)
    {
        List<SysConfig> list = configService.selectConfigList(config);
        ExcelUtil<SysConfig> util = new ExcelUtil<SysConfig>(SysConfig.class);
        return util.exportExcel(list, "参数数据");
        util.exportExcel(response, list, "参数数据");
    }
    /**
@@ -64,7 +63,7 @@
    @GetMapping(value = "/{configId}")
    public AjaxResult getInfo(@PathVariable Long configId)
    {
        return AjaxResult.success(configService.selectConfigById(configId));
        return success(configService.selectConfigById(configId));
    }
    /**
@@ -73,7 +72,7 @@
    @GetMapping(value = "/configKey/{configKey}")
    public AjaxResult getConfigKey(@PathVariable String configKey)
    {
        return AjaxResult.success(configService.selectConfigByKey(configKey));
        return success(configService.selectConfigByKey(configKey));
    }
    /**
@@ -84,11 +83,11 @@
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysConfig config)
    {
        if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config)))
        if (!configService.checkConfigKeyUnique(config))
        {
            return AjaxResult.error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
            return error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
        }
        config.setCreateBy(SecurityUtils.getUsername());
        config.setCreateBy(getUsername());
        return toAjax(configService.insertConfig(config));
    }
@@ -100,11 +99,11 @@
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysConfig config)
    {
        if (UserConstants.NOT_UNIQUE.equals(configService.checkConfigKeyUnique(config)))
        if (!configService.checkConfigKeyUnique(config))
        {
            return AjaxResult.error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
            return error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
        }
        config.setUpdateBy(SecurityUtils.getUsername());
        config.setUpdateBy(getUsername());
        return toAjax(configService.updateConfig(config));
    }
@@ -116,18 +115,19 @@
    @DeleteMapping("/{configIds}")
    public AjaxResult remove(@PathVariable Long[] configIds)
    {
        return toAjax(configService.deleteConfigByIds(configIds));
        configService.deleteConfigByIds(configIds);
        return success();
    }
    /**
     * 清空缓存
     * 刷新参数缓存
     */
    @PreAuthorize("@ss.hasPermi('system:config:remove')")
    @Log(title = "参数管理", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clearCache")
    public AjaxResult clearCache()
    @DeleteMapping("/refreshCache")
    public AjaxResult refreshCache()
    {
        configService.clearCache();
        return AjaxResult.success();
        configService.resetConfigCache();
        return success();
    }
}