Преглед изворни кода

Merge branch 'redis清除新' into prd

zxfqwert пре 4 месеци
родитељ
комит
c36d957d74

+ 28 - 0
suishenbang-admin/src/main/java/com/dgtly/web/controller/monitor/clearStorageController.java

@@ -0,0 +1,28 @@
+package com.dgtly.web.controller.monitor;
+
+import com.dgtly.common.core.controller.BaseController;
+import com.dgtly.framework.web.domain.Server;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ * 缓存清理
+ * 
+ * @author ruoyi
+ */
+@Controller
+@RequestMapping("/monitor/clearStorage")
+public class clearStorageController extends BaseController
+{
+    private String prefix = "monitor/clearStorage";
+
+    @RequiresPermissions("monitor:clearStorage:view")
+    @GetMapping()
+    public String clearStorage()
+    {
+        return prefix + "/clearStorage";
+    }
+}

+ 94 - 0
suishenbang-admin/src/main/resources/templates/monitor/clearStorage/clearStorage.html

@@ -0,0 +1,94 @@
+<!DOCTYPE html>
+<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
+<head>
+    <th:block th:include="include :: header('缓存清理')" />
+</head>
+<body class="gray-bg">
+<div class="wrapper wrapper-content">
+    <div class="col-sm-12">
+        <div class="row">
+            <label class="col-sm-1 control-label"></label>
+            <div class="col-sm-10">
+                <label class="check-box">
+                    <input type="checkbox" value="0" id="inlineCheckbox0" name="checkboxGroupName">0</label>
+                <label class="check-box">
+                    <input type="checkbox" value="1" id="inlineCheckbox1" name="checkboxGroupName">1</label>
+                <label class="check-box">
+                    <input type="checkbox" value="2" id="inlineCheckbox2" name="checkboxGroupName">2</label>
+                <label class="check-box">
+                    <input type="checkbox" value="3" id="inlineCheckbox3" name="checkboxGroupName">3</label>
+                <label class="check-box">
+                    <input type="checkbox" value="4" id="inlineCheckbox4" name="checkboxGroupName">4</label>
+                <label class="check-box">
+                    <input type="checkbox" value="5" id="inlineCheckbox5" name="checkboxGroupName">5</label>
+                <label class="check-box">
+                    <input type="checkbox" value="6" id="inlineCheckbox6" name="checkboxGroupName">6</label>
+                <label class="check-box">
+                    <input type="checkbox" value="7" id="inlineCheckbox7" name="checkboxGroupName">7</label>
+                <label class="check-box">
+                    <input type="checkbox" value="8" id="inlineCheckbox8" name="checkboxGroupName">8</label>
+                <label class="check-box">
+                    <input type="checkbox" value="9" id="inlineCheckbox9" name="checkboxGroupName">9</label>
+                <label class="check-box">
+                    <input type="checkbox" value="10" id="inlineCheckbox10" name="checkboxGroupName">10</label>
+                <label class="check-box">
+                    <input type="checkbox" value="11" id="inlineCheckbox11" name="checkboxGroupName">11</label>
+                <label class="check-box">
+                    <input type="checkbox" value="12" id="inlineCheckbox12" name="checkboxGroupName">12</label>
+                <label class="check-box">
+                    <input type="checkbox" value="13" id="inlineCheckbox13" name="checkboxGroupName">13</label>
+                <label class="check-box">
+                    <input type="checkbox" value="14" id="inlineCheckbox14" name="checkboxGroupName">14</label>
+                <label class="check-box">
+                    <input type="checkbox" value="15" id="inlineCheckbox15" name="checkboxGroupName">15</label>
+            </div>
+        </div>
+        <div class="row" style="margin-top: 10px;">
+            <label class="col-sm-1 control-label" style="text-align: right;padding: 0;">清空单体:</label>
+            <div class="col-sm-8">
+                <input type="text" id="keyName" name="" class="form-control" placeholder="">
+            </div>
+        </div>
+        <div class="row" style="margin-top: 10px;">
+            <label class="col-sm-1 control-label"></label>
+            <button id="applyBtn" class="btn btn-success">
+                提交
+            </button>
+        </div>
+    </div>
+</div>
+</body>
+<th:block th:include="include :: footer" />
+<script type="text/javascript">
+    var domain = window.location.host;
+    var ht = domain.indexOf('localhost') != -1 ? 'http://' : 'https://';
+    var prefixEdit = ht + domain + "/oneportal/wxportal/magnet";
+    // var prefixEdit = 'https://suishenbangtest.nipponpaint.com.cn/oneportal/wxportal/magnet';
+
+    $('#applyBtn').on('click', function (res) {
+        var selectedValues = [];
+        $('input[name="checkboxGroupName"]:checked').each(function() {
+            selectedValues.push($(this).val()*1);
+        });
+        var keyNameValue = $('#keyName').val();
+        var data = {
+            redisDb:selectedValues,
+            keyName:keyNameValue
+        }
+        console.log(1,data);
+        $.ajax({
+            url: prefixEdit + '/cleanRedisByDb',
+            type: "post",
+            contentType: 'application/json',
+            data: JSON.stringify(data),
+            success: function (result) {
+                if (result.code == 0) {
+                    $.modal.alertWarning('提交成功');
+                } else {
+                    $.modal.alertWarning(result.msg);
+                }
+            }
+        })
+    })
+</script>
+</html>

+ 1 - 1
suishenbang-system/src/main/java/com/dgtly/system/domain/SysDictData.java

@@ -86,7 +86,7 @@ public class SysDictData extends BaseEntity
     }
 
     @NotBlank(message = "字典键值不能为空")
-    @Size(min = 0, max = 100, message = "字典键值长度不能超过100个字符")
+    @Size(min = 0, max = 500, message = "字典键值长度不能超过500个字符")
     public String getDictValue()
     {
         return dictValue;

+ 6 - 0
suishenbang-wxportal/suishenbang-wxportal-common/pom.xml

@@ -47,5 +47,11 @@
             <artifactId>itext-asian</artifactId>
             <version>5.2.0</version>
         </dependency>
+
+        <dependency>
+            <groupId>redis.clients</groupId>
+            <artifactId>jedis</artifactId>
+            <version>5.0.2</version>
+        </dependency>
     </dependencies>
 </project>

+ 13 - 0
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/domain/RedisDbParam.java

@@ -0,0 +1,13 @@
+package com.dgtly.wxportal.domain;
+
+
+import lombok.Data;
+
+@Data
+public class RedisDbParam {
+    // redis库数组
+    private Integer[]  redisDb;
+    // 具体key值
+    private String keyName;
+
+}

+ 50 - 0
suishenbang-wxportal/suishenbang-wxportal-common/src/main/java/com/dgtly/wxportal/utils/JedisPoolUtil.java

@@ -0,0 +1,50 @@
+package com.dgtly.wxportal.utils;
+
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.JedisPoolConfig;
+
+
+
+public class JedisPoolUtil {
+    private static volatile JedisPool jedisPool = null;
+    private static final String HOST="127.0.0.1" ;
+    private static final int PORT = 6379;
+    private static final String PASSWORD = "Ssbprod#1207";
+    private static final int TIMEOUT = 2000;
+
+
+    private JedisPoolUtil() {}
+    public static JedisPool getPool() {
+        if (jedisPool == null) {
+            synchronized (JedisPoolUtil.class) {
+                if (jedisPool == null) {
+                    JedisPoolConfig config = new JedisPoolConfig();
+                    config.setMaxTotal(200);       // 最大连接数
+                    config.setMaxIdle(50);         // 最大空闲连接
+                    config.setMinIdle(10);         // 最小空闲连接
+                    config.setTestOnBorrow(true);  // 借出连接时校验
+                    config.setTestOnReturn(true);  // 归还连接时校验
+                    config.setMaxWaitMillis(1000); // 等待连接超时时间(ms)
+
+                    jedisPool = new JedisPool(
+                            config, HOST, PORT, TIMEOUT, PASSWORD
+                    );
+                }
+            }
+        }
+        return jedisPool;
+    }
+
+    public static Jedis getResource() {
+        return getPool().getResource();
+    }
+
+    public static void close(Jedis jedis) {
+        if (jedis != null) {
+            jedis.close();
+        }
+    }
+}
+
+

+ 5 - 0
suishenbang-wxportal/suishenbang-wxportal-manager/pom.xml

@@ -44,6 +44,11 @@
             <groupId>com.dgtly</groupId>
             <artifactId>suishenbang-system</artifactId>
         </dependency>
+        <dependency>
+            <groupId>redis.clients</groupId>
+            <artifactId>jedis</artifactId>
+            <version>5.0.2</version>
+        </dependency>
 
 
     </dependencies>

+ 34 - 0
suishenbang-wxportal/suishenbang-wxportal-manager/src/main/java/com/dgtly/wxportal/controller/WxMagnetController.java

@@ -10,18 +10,24 @@ import com.dgtly.common.core.domain.Ztree;
 import com.dgtly.common.core.page.TableDataInfo;
 import com.dgtly.common.enums.BusinessType;
 import com.dgtly.common.exception.BusinessException;
+import com.dgtly.common.utils.StringUtils;
 import com.dgtly.framework.util.ShiroUtils;
 import com.dgtly.system.domain.SysRole;
 import com.dgtly.system.domain.SysUser;
 import com.dgtly.wxportal.domain.HomeIconConfig;
+import com.dgtly.wxportal.domain.RedisDbParam;
 import com.dgtly.wxportal.domain.WxMagnet;
 import com.dgtly.wxportal.service.IWxMagnetService;
+import com.dgtly.wxportal.utils.JedisPoolUtil;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
+import redis.clients.jedis.Jedis;
 
 import java.io.IOException;
 import java.util.List;
@@ -37,6 +43,8 @@ import java.util.Map;
 @RequestMapping("/wxportal/magnet")
 public class WxMagnetController extends BaseController
 {
+    private static final Logger log = LoggerFactory.getLogger(WxMagnetController.class);
+
     private String prefix = "wxportal/magnet";
 
     @Autowired
@@ -206,6 +214,32 @@ public class WxMagnetController extends BaseController
     }
 
 
+    @Log(title = "redis缓存清除", businessType = BusinessType.UPDATE)
+    @PostMapping("/cleanRedisByDb")
+    @ResponseBody
+    public AjaxResult cleanRedisByDb(@RequestBody RedisDbParam redisDbParam)
+    {
+        if(redisDbParam.getRedisDb().length==0){
+            return AjaxResult.error(201,"redis库未指定!");
+        }
+        for (int db : redisDbParam.getRedisDb()) {
+            try (Jedis jedis = JedisPoolUtil.getResource()) {
+                jedis.select(db);
+                if(StringUtils.isNotBlank(redisDbParam.getKeyName())){
+                    jedis.del(redisDbParam.getKeyName());
+                    log.info("清空库" + db+"下的"+redisDbParam.getKeyName());
+                }
+                else{
+                    jedis.flushDB();
+                    log.info("清空库" + db);
+                }
+            }
+        }
+        return AjaxResult.success("操作成功!");
+    }
+
+
+
     /**
      * 加载角色磁贴列表树
      */