From d99dd4b875aff23b2029716cbc6d1cbf559fe860 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期三, 09 二月 2022 14:52:33 +0800
Subject: [PATCH] update 调整oss预览开关 使用前端直接调用更改配置参数

---
 ruoyi-ui/src/api/system/oss.js                                                     |   10 -----
 ruoyi-ui/src/api/system/config.js                                                  |   12 ++++++
 ruoyi-ui/src/main.js                                                               |    3 +
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java    |   18 --------
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java |   11 +++++
 ruoyi-ui/src/views/system/oss/index.vue                                            |    4 +-
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java |    8 +++
 7 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
index 7c38790..8cbea8e 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
@@ -102,6 +102,17 @@
     }
 
     /**
+     * 鏍规嵁鍙傛暟閿悕淇敼鍙傛暟閰嶇疆
+     */
+    @ApiOperation("鏍规嵁鍙傛暟閿悕淇敼鍙傛暟閰嶇疆")
+    @SaCheckPermission("system:config:edit")
+    @Log(title = "鍙傛暟绠$悊", businessType = BusinessType.UPDATE)
+    @PutMapping("/updateByKey")
+    public R<Void> updateByKey(@RequestBody SysConfig config) {
+        return toAjax(configService.updateConfig(config));
+    }
+
+    /**
      * 鍒犻櫎鍙傛暟閰嶇疆
      */
     @ApiOperation("鍒犻櫎鍙傛暟閰嶇疆")
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java
index 15b3075..c36da48 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java
@@ -9,8 +9,8 @@
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.annotation.RepeatSubmit;
 import com.ruoyi.common.core.controller.BaseController;
-import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.domain.PageQuery;
+import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.core.validate.QueryGroup;
 import com.ruoyi.common.enums.BusinessType;
@@ -121,22 +121,6 @@
                                    @NotEmpty(message = "涓婚敭涓嶈兘涓虹┖")
                                    @PathVariable Long[] ossIds) {
         return toAjax(iSysOssService.deleteWithValidByIds(Arrays.asList(ossIds), true) ? 1 : 0);
-    }
-
-    /**
-     * 鍙樻洿鍥剧墖鍒楄〃棰勮鐘舵��
-     */
-    @ApiOperation("鍙樻洿鍥剧墖鍒楄〃棰勮鐘舵��")
-    @SaCheckPermission("system:oss:edit")
-    @Log(title = "OSS瀵硅薄瀛樺偍", businessType = BusinessType.UPDATE)
-    @PutMapping("/changePreviewListResource")
-    public R<Void> changePreviewListResource(@RequestBody String body) {
-        Map<String, Boolean> map = JsonUtils.parseMap(body);
-        SysConfig sysConfig = new SysConfig();
-        sysConfig.setConfigKey(OssConstant.PEREVIEW_LIST_RESOURCE_KEY);
-        SysConfig config = iSysConfigService.getOne(sysConfig);
-        config.setConfigValue(map.get("previewListResource").toString());
-        return toAjax(iSysConfigService.updateConfig(config));
     }
 
 }
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
index 3170700..9e6e6c3 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
@@ -136,7 +136,13 @@
      */
     @Override
     public int updateConfig(SysConfig config) {
-        int row = baseMapper.updateById(config);
+        int row = 0;
+        if (config.getConfigId() != null) {
+            row = baseMapper.updateById(config);
+        } else {
+            row = baseMapper.update(config, new LambdaQueryWrapper<SysConfig>()
+                .eq(SysConfig::getConfigKey, config.getConfigKey()));
+        }
         if (row > 0) {
             RedisUtils.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
         }
diff --git a/ruoyi-ui/src/api/system/config.js b/ruoyi-ui/src/api/system/config.js
index c193284..02f0cfc 100644
--- a/ruoyi-ui/src/api/system/config.js
+++ b/ruoyi-ui/src/api/system/config.js
@@ -43,6 +43,18 @@
   })
 }
 
+// 淇敼鍙傛暟閰嶇疆
+export function updateConfigByKey(key, value) {
+  return request({
+    url: '/system/config/updateByKey',
+    method: 'put',
+    data: {
+      configKey: key,
+      configValue: value
+    }
+  })
+}
+
 // 鍒犻櫎鍙傛暟閰嶇疆
 export function delConfig(configId) {
   return request({
diff --git a/ruoyi-ui/src/api/system/oss.js b/ruoyi-ui/src/api/system/oss.js
index b98bd1f..83adca5 100644
--- a/ruoyi-ui/src/api/system/oss.js
+++ b/ruoyi-ui/src/api/system/oss.js
@@ -17,13 +17,3 @@
   })
 }
 
-export function changePreviewListResource(previewListResource) {
-  const data = {
-    previewListResource
-  }
-  return request({
-    url: '/system/oss/changePreviewListResource',
-    method: 'put',
-    data: data
-  })
-}
diff --git a/ruoyi-ui/src/main.js b/ruoyi-ui/src/main.js
index 13c6cf2..1e0144f 100644
--- a/ruoyi-ui/src/main.js
+++ b/ruoyi-ui/src/main.js
@@ -17,7 +17,7 @@
 import './assets/icons' // icon
 import './permission' // permission control
 import { getDicts } from "@/api/system/dict/data";
-import { getConfigKey } from "@/api/system/config";
+import { getConfigKey, updateConfigByKey } from "@/api/system/config";
 import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree } from "@/utils/ruoyi";
 // 鍒嗛〉缁勪欢
 import Pagination from "@/components/Pagination";
@@ -41,6 +41,7 @@
 // 鍏ㄥ眬鏂规硶鎸傝浇
 Vue.prototype.getDicts = getDicts
 Vue.prototype.getConfigKey = getConfigKey
+Vue.prototype.updateConfigByKey = updateConfigByKey
 Vue.prototype.parseTime = parseTime
 Vue.prototype.resetForm = resetForm
 Vue.prototype.addDateRange = addDateRange
diff --git a/ruoyi-ui/src/views/system/oss/index.vue b/ruoyi-ui/src/views/system/oss/index.vue
index fdfed16..ac8b029 100644
--- a/ruoyi-ui/src/views/system/oss/index.vue
+++ b/ruoyi-ui/src/views/system/oss/index.vue
@@ -187,7 +187,7 @@
 </template>
 
 <script>
-import { listOss, delOss, changePreviewListResource } from "@/api/system/oss";
+import { listOss, delOss } from "@/api/system/oss";
 
 export default {
   name: "Oss",
@@ -344,7 +344,7 @@
     handlePreviewListResource(previewListResource) {
       let text = previewListResource ? "鍚敤" : "鍋滅敤";
       this.$modal.confirm('纭瑕�"' + text + '""棰勮鍒楄〃鍥剧墖"閰嶇疆鍚�?').then(() => {
-        return changePreviewListResource(previewListResource);
+        return this.updateConfigByKey("sys.oss.previewListResource", previewListResource);
       }).then(() => {
         this.getList()
         this.$modal.msgSuccess(text + "鎴愬姛");

--
Gitblit v1.9.3