From 45df1673158d274adfd4916a817f840ffede2885 Mon Sep 17 00:00:00 2001
From: Shikong <919411476@qq.com>
Date: Mon, 8 May 2023 10:47:44 +0800
Subject: [PATCH] =?UTF-8?q?cn.skcks.matrix.v2.config=20=E6=B7=BB=E5=8A=A0?=
=?UTF-8?q?=20casbin=20=E6=9D=83=E9=99=90=E6=A3=80=E6=9F=A5=20=E6=97=A5?=
=?UTF-8?q?=E5=BF=97=E7=BA=A7=E5=88=AB=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/sk-matrix-service/.idea/compiler.xml | 4 +-
.../sk-matrix-service/.idea/encodings.xml | 1 +
.../matrix/v2/utils/json/JsonResponse.java | 8 +
.../matrix/v2/utils/redis/RedisUtil.java | 476 +++++++++---------
backend/java/sk-matrix-service/model/pom.xml | 60 +++
.../main/java/cn/skcks/matrix/v2/Main.java | 7 +
backend/java/sk-matrix-service/pom.xml | 1 +
.../cn/skcks/matrix/v2/config/WebConfig.java | 37 +-
.../starter/src/main/resources/logback.xml | 54 ++
9 files changed, 406 insertions(+), 242 deletions(-)
create mode 100644 backend/java/sk-matrix-service/model/pom.xml
create mode 100644 backend/java/sk-matrix-service/model/src/main/java/cn/skcks/matrix/v2/Main.java
create mode 100644 backend/java/sk-matrix-service/starter/src/main/resources/logback.xml
diff --git a/backend/java/sk-matrix-service/.idea/compiler.xml b/backend/java/sk-matrix-service/.idea/compiler.xml
index ee9777e..509a652 100644
--- a/backend/java/sk-matrix-service/.idea/compiler.xml
+++ b/backend/java/sk-matrix-service/.idea/compiler.xml
@@ -20,9 +20,10 @@
-
+
+
@@ -37,6 +38,7 @@
+
diff --git a/backend/java/sk-matrix-service/.idea/encodings.xml b/backend/java/sk-matrix-service/.idea/encodings.xml
index cc254ad..1e3f8eb 100644
--- a/backend/java/sk-matrix-service/.idea/encodings.xml
+++ b/backend/java/sk-matrix-service/.idea/encodings.xml
@@ -8,6 +8,7 @@
+
diff --git a/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/json/JsonResponse.java b/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/json/JsonResponse.java
index 59ea51a..11b1555 100644
--- a/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/json/JsonResponse.java
+++ b/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/json/JsonResponse.java
@@ -38,10 +38,18 @@ public class JsonResponse {
return JsonResponse.build(data, ResponseStatus.INTERNAL_SERVER_ERROR.getCode(), message);
}
+ public static JsonResponse build(ResponseStatus status) {
+ return new JsonResponse<>(status.getCode(), status.getMessage(),null);
+ }
+
public static JsonResponse build(T data, ResponseStatus status) {
return new JsonResponse<>(status.getCode(), status.getMessage(), data);
}
+ public static JsonResponse build(ResponseStatus status,String message) {
+ return new JsonResponse<>(status.getCode(), message, null);
+ }
+
public static JsonResponse build(T data, int status, String msg) {
return new JsonResponse<>(status, msg, data);
}
diff --git a/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/redis/RedisUtil.java b/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/redis/RedisUtil.java
index 281acd2..6c256c0 100644
--- a/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/redis/RedisUtil.java
+++ b/backend/java/sk-matrix-service/common/src/main/java/cn/skcks/matrix/v2/utils/redis/RedisUtil.java
@@ -75,10 +75,10 @@ public class RedisUtil implements ApplicationContextAware {
* @return 删除是否成功
*/
public static boolean delete(String key) {
- log.info("delete(...) => key -> {}", key);
+ log.debug("delete(...) => key -> {}", key);
// 返回值只可能为true/false, 不可能为null
Boolean result = redisTemplate.delete(key);
- log.info("delete(...) => result -> {}", result);
+ log.debug("delete(...) => result -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -96,9 +96,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return 删除了的key-value个数
*/
public static long delete(Collection keys) {
- log.info("delete(...) => keys -> {}", keys);
+ log.debug("delete(...) => keys -> {}", keys);
Long count = redisTemplate.delete(keys);
- log.info("delete(...) => count -> {}", count);
+ log.debug("delete(...) => count -> {}", count);
if (count == null) {
throw new RedisOpsResultIsNullException();
}
@@ -116,9 +116,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return 序列化后的value值
*/
public static byte[] dump(String key) {
- log.info("dump(...) =>key -> {}", key);
+ log.debug("dump(...) =>key -> {}", key);
byte[] result = redisTemplate.dump(key);
- log.info("dump(...) => result -> {}", result);
+ log.debug("dump(...) => result -> {}", result);
return result;
}
@@ -148,7 +148,7 @@ public class RedisUtil implements ApplicationContextAware {
* @throws RedisSystemException 如果redis中已存在同样的key, 且replace为false时,抛出此异常
*/
public static void restore(String key, byte[] value, long timeout, TimeUnit unit, boolean replace) {
- log.info("restore(...) => key -> {}, value -> {}, timeout -> {}, unit -> {}, replace -> {}",
+ log.debug("restore(...) => key -> {}, value -> {}, timeout -> {}, unit -> {}, replace -> {}",
key, value, timeout, unit, replace);
redisTemplate.restore(key, value, timeout, unit, replace);
}
@@ -160,9 +160,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return 是否存在对应的key-value
*/
public static boolean hasKey(String key) {
- log.info("hasKey(...) => key -> {}", key);
+ log.debug("hasKey(...) => key -> {}", key);
Boolean result = redisTemplate.hasKey(key);
- log.info("hasKey(...) => result -> {}", result);
+ log.debug("hasKey(...) => result -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -181,9 +181,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return 操作是否成功
*/
public static boolean expire(String key, long timeout, TimeUnit unit) {
- log.info("expire(...) => key -> {}, timeout -> {}, unit -> {}", key, timeout, unit);
+ log.debug("expire(...) => key -> {}, timeout -> {}, unit -> {}", key, timeout, unit);
Boolean result = redisTemplate.expire(key, timeout, unit);
- log.info("expire(...) => result is -> {}", result);
+ log.debug("expire(...) => result is -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -201,9 +201,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return 操作是否成功
*/
public static boolean expireAt(String key, Date date) {
- log.info("expireAt(...) => key -> {}, date -> {}", key, date);
+ log.debug("expireAt(...) => key -> {}, date -> {}", key, date);
Boolean result = redisTemplate.expireAt(key, date);
- log.info("expireAt(...) => result is -> {}", result);
+ log.debug("expireAt(...) => result is -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -222,9 +222,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return 匹配pattern的key的集合。 可能为null。
*/
public static Set keys(String pattern) {
- log.info("keys(...) => pattern -> {}", pattern);
+ log.debug("keys(...) => pattern -> {}", pattern);
Set keys = redisTemplate.keys(pattern);
- log.info("keys(...) => keys -> {}", keys);
+ log.debug("keys(...) => keys -> {}", keys);
return keys;
}
@@ -241,9 +241,9 @@ public class RedisUtil implements ApplicationContextAware {
* 注: 若目标db下,已存在相同的key, 那么move会失败,返回false。
*/
public static boolean move(String key, int dbIndex) {
- log.info("move(...) => key -> {}, dbIndex -> {}", key, dbIndex);
+ log.debug("move(...) => key -> {}, dbIndex -> {}", key, dbIndex);
Boolean result = redisTemplate.move(key, dbIndex);
- log.info("move(...) =>result -> {}", result);
+ log.debug("move(...) =>result -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -260,9 +260,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return 操作是否成功
*/
public static boolean persist(String key) {
- log.info("persist(...) => key -> {}", key);
+ log.debug("persist(...) => key -> {}", key);
Boolean result = redisTemplate.persist(key);
- log.info("persist(...) => result -> {}", result);
+ log.debug("persist(...) => result -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -295,9 +295,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return 过期时间(单位unit)
*/
public static long getExpire(String key, TimeUnit unit) {
- log.info("getExpire(...) =>key -> {}, unit is -> {}", key, unit);
+ log.debug("getExpire(...) =>key -> {}, unit is -> {}", key, unit);
Long result = redisTemplate.getExpire(key, unit);
- log.info("getExpire(...) => result -> {}", result);
+ log.debug("getExpire(...) => result -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -313,7 +313,7 @@ public class RedisUtil implements ApplicationContextAware {
*/
public static String randomKey() {
String result = redisTemplate.randomKey();
- log.info("randomKey(...) => result is -> {}", result);
+ log.debug("randomKey(...) => result is -> {}", result);
return result;
}
@@ -332,7 +332,7 @@ public class RedisUtil implements ApplicationContextAware {
* @throws RedisSystemException 若oldKey不存在时, 抛出此异常
*/
public static void rename(String oldKey, String newKey) {
- log.info("rename(...) => oldKey -> {}, newKey -> {}", oldKey, newKey);
+ log.debug("rename(...) => oldKey -> {}, newKey -> {}", oldKey, newKey);
redisTemplate.rename(oldKey, newKey);
}
@@ -347,9 +347,9 @@ public class RedisUtil implements ApplicationContextAware {
* @throws RedisSystemException 若oldKey不存在时, 抛出此异常
*/
public static boolean renameIfAbsent(String oldKey, String newKey) {
- log.info("renameIfAbsent(...) => oldKey -> {}, newKey -> {}", oldKey, newKey);
+ log.debug("renameIfAbsent(...) => oldKey -> {}, newKey -> {}", oldKey, newKey);
Boolean result = redisTemplate.renameIfAbsent(oldKey, newKey);
- log.info("renameIfAbsent(...) => result -> {}", result);
+ log.debug("renameIfAbsent(...) => result -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -365,9 +365,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return key对应的value的数据类型
*/
public static DataType type(String key) {
- log.info("type(...) => key -> {}", key);
+ log.debug("type(...) => key -> {}", key);
DataType result = redisTemplate.type(key);
- log.info("type(...) => result -> {}", result);
+ log.debug("type(...) => result -> {}", result);
return result;
}
}
@@ -391,7 +391,7 @@ public class RedisUtil implements ApplicationContextAware {
* @param value key对应的value
*/
public static void set(String key, String value) {
- log.info("set(...) => key -> {}, value -> {}", key, value);
+ log.debug("set(...) => key -> {}, value -> {}", key, value);
redisTemplate.opsForValue().set(key, value);
}
@@ -415,9 +415,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return set是否成功
*/
public static boolean setBit(String key, long offset, boolean value) {
- log.info("setBit(...) => key -> {}, offset -> {}, value -> {}", key, offset, value);
+ log.debug("setBit(...) => key -> {}, offset -> {}, value -> {}", key, offset, value);
Boolean result = redisTemplate.opsForValue().setBit(key, offset, value);
- log.info("setBit(...) => result -> {}", result);
+ log.debug("setBit(...) => result -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -435,7 +435,7 @@ public class RedisUtil implements ApplicationContextAware {
* @param unit timeout的单位
*/
public static void setEx(String key, String value, long timeout, TimeUnit unit) {
- log.info("setEx(...) => key -> {}, value -> {}, timeout -> {}, unit -> {}",
+ log.debug("setEx(...) => key -> {}, value -> {}, timeout -> {}, unit -> {}",
key, value, timeout, unit);
redisTemplate.opsForValue().set(key, value, timeout, unit);
}
@@ -449,9 +449,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return set是否成功
*/
public static boolean setIfAbsent(String key, String value) {
- log.info("setIfAbsent(...) => key -> {}, value -> {}", key, value);
+ log.debug("setIfAbsent(...) => key -> {}, value -> {}", key, value);
Boolean result = redisTemplate.opsForValue().setIfAbsent(key, value);
- log.info("setIfAbsent(...) => result -> {}", result);
+ log.debug("setIfAbsent(...) => result -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -469,9 +469,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return set是否成功
*/
public static boolean setIfAbsent(String key, String value, long timeout, TimeUnit unit) {
- log.info("setIfAbsent(...) => key -> {}, value -> {}, key -> {}, value -> {}", key, value, timeout, unit);
+ log.debug("setIfAbsent(...) => key -> {}, value -> {}, key -> {}, value -> {}", key, value, timeout, unit);
Boolean result = redisTemplate.opsForValue().setIfAbsent(key, value, timeout, unit);
- log.info("setIfAbsent(...) => result -> {}", result);
+ log.debug("setIfAbsent(...) => result -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -498,7 +498,7 @@ public class RedisUtil implements ApplicationContextAware {
* @param offset 起始位置
*/
public static void setRange(String key, String replaceValue, long offset) {
- log.info("setRange(...) => key -> {}, replaceValue -> {}, offset -> {}", key, replaceValue, offset);
+ log.debug("setRange(...) => key -> {}, replaceValue -> {}, offset -> {}", key, replaceValue, offset);
redisTemplate.opsForValue().set(key, replaceValue, offset);
}
@@ -512,9 +512,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return value的长度
*/
public static long size(String key) {
- log.info("size(...) => key -> {}", key);
+ log.debug("size(...) => key -> {}", key);
Long result = redisTemplate.opsForValue().size(key);
- log.info("size(...) => result -> {}", result);
+ log.debug("size(...) => result -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -529,7 +529,7 @@ public class RedisUtil implements ApplicationContextAware {
* @param maps key-value 集
*/
public static void multiSet(Map maps) {
- log.info("multiSet(...) => maps -> {}", maps);
+ log.debug("multiSet(...) => maps -> {}", maps);
redisTemplate.opsForValue().multiSet(maps);
}
@@ -549,9 +549,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return 操作是否成功
*/
public static boolean multiSetIfAbsent(Map maps) {
- log.info("multiSetIfAbsent(...) => maps -> {}", maps);
+ log.debug("multiSetIfAbsent(...) => maps -> {}", maps);
Boolean result = redisTemplate.opsForValue().multiSetIfAbsent(maps);
- log.info("multiSetIfAbsent(...) => result -> {}", result);
+ log.debug("multiSetIfAbsent(...) => result -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -571,9 +571,9 @@ public class RedisUtil implements ApplicationContextAware {
* @throws RedisSystemException key对应的value值不支持增/减操作时
*/
public static long incrBy(String key, long increment) {
- log.info("incrBy(...) => key -> {}, increment -> {}", key, increment);
+ log.debug("incrBy(...) => key -> {}, increment -> {}", key, increment);
Long result = redisTemplate.opsForValue().increment(key, increment);
- log.info("incrBy(...) => result -> {}", result);
+ log.debug("incrBy(...) => result -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -597,9 +597,9 @@ public class RedisUtil implements ApplicationContextAware {
* @throws RedisSystemException key对应的value值不支持增/减操作时
*/
public static double incrByFloat(String key, double increment) {
- log.info("incrByFloat(...) => key -> {}, increment -> {}", key, increment);
+ log.debug("incrByFloat(...) => key -> {}, increment -> {}", key, increment);
Double result = redisTemplate.opsForValue().increment(key, increment);
- log.info("incrByFloat(...) => result -> {}", result);
+ log.debug("incrByFloat(...) => result -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -616,9 +616,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return 追加后, 整个value的长度
*/
public static int append(String key, String value) {
- log.info("append(...) => key -> {}, value -> {}", key, value);
+ log.debug("append(...) => key -> {}, value -> {}", key, value);
Integer result = redisTemplate.opsForValue().append(key, value);
- log.info("append(...) => result -> {}", result);
+ log.debug("append(...) => result -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -633,9 +633,9 @@ public class RedisUtil implements ApplicationContextAware {
* 注: 若key不存在, 则返回null。
*/
public static String get(String key) {
- log.info("get(...) => key -> {}", key);
+ log.debug("get(...) => key -> {}", key);
String result = redisTemplate.opsForValue().get(key);
- log.info("get(...) => result -> {} ", result);
+ log.debug("get(...) => result -> {} ", result);
return result;
}
@@ -651,9 +651,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return 截取后的字符串
*/
public static String getRange(String key, long start, long end) {
- log.info("getRange(...) => kry -> {}", key);
+ log.debug("getRange(...) => kry -> {}", key);
String result = redisTemplate.opsForValue().get(key, start, end);
- log.info("getRange(...) => result -> {} ", result);
+ log.debug("getRange(...) => result -> {} ", result);
return result;
}
@@ -667,9 +667,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return 旧的value值
*/
public static String getAndSet(String key, String newValue) {
- log.info("getAndSet(...) => key -> {}, value -> {}", key, newValue);
+ log.debug("getAndSet(...) => key -> {}, value -> {}", key, newValue);
String oldValue = redisTemplate.opsForValue().getAndSet(key, newValue);
- log.info("getAndSet(...) => oldValue -> {}", oldValue);
+ log.debug("getAndSet(...) => oldValue -> {}", oldValue);
return oldValue;
}
@@ -688,9 +688,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return offset位置对应的bit的值(true - 1, false - 0)
*/
public static boolean getBit(String key, long offset) {
- log.info("getBit(...) => key -> {}, offset -> {}", key, offset);
+ log.debug("getBit(...) => key -> {}, offset -> {}", key, offset);
Boolean result = redisTemplate.opsForValue().getBit(key, offset);
- log.info("getBit(...) => result -> {}", result);
+ log.debug("getBit(...) => result -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -706,9 +706,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return value值集合
*/
public static List multiGet(Collection keys) {
- log.info("multiGet(...) => keys -> {}", keys);
+ log.debug("multiGet(...) => keys -> {}", keys);
List result = redisTemplate.opsForValue().multiGet(keys);
- log.info("multiGet(...) => result -> {}", result);
+ log.debug("multiGet(...) => result -> {}", result);
return result;
}
}
@@ -735,7 +735,7 @@ public class RedisUtil implements ApplicationContextAware {
* @param entryValue 要向hash中增加的键值对里的 值
*/
public static void hPut(String key, String entryKey, String entryValue) {
- log.info("hPut(...) => key -> {}, entryKey -> {}, entryValue -> {}", key, entryKey, entryValue);
+ log.debug("hPut(...) => key -> {}, entryKey -> {}, entryValue -> {}", key, entryKey, entryValue);
redisTemplate.opsForHash().put(key, entryKey, entryValue);
}
@@ -749,7 +749,7 @@ public class RedisUtil implements ApplicationContextAware {
* @param maps 要向hash中增加的键值对集
*/
public static void hPutAll(String key, Map maps) {
- log.info("hPutAll(...) => key -> {}, maps -> {}", key, maps);
+ log.debug("hPutAll(...) => key -> {}, maps -> {}", key, maps);
redisTemplate.opsForHash().putAll(key, maps);
}
@@ -763,10 +763,10 @@ public class RedisUtil implements ApplicationContextAware {
* @return 操作是否成功。
*/
public static boolean hPutIfAbsent(String key, String entryKey, String entryValue) {
- log.info("hPutIfAbsent(...) => key -> {}, entryKey -> {}, entryValue -> {}",
+ log.debug("hPutIfAbsent(...) => key -> {}, entryKey -> {}, entryValue -> {}",
key, entryKey, entryValue);
Boolean result = redisTemplate.opsForHash().putIfAbsent(key, entryKey, entryValue);
- log.info("hPutIfAbsent(...) => result -> {}", result);
+ log.debug("hPutIfAbsent(...) => result -> {}", result);
if (result == null) {
throw new RedisOpsResultIsNullException();
}
@@ -784,9 +784,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return key对应的hash里的entryKey对应的entryValue值
*/
public static Object hGet(String key, String entryKey) {
- log.info("hGet(...) => key -> {}, entryKey -> {}", key, entryKey);
+ log.debug("hGet(...) => key -> {}, entryKey -> {}", key, entryKey);
Object entryValue = redisTemplate.opsForHash().get(key, entryKey);
- log.info("hGet(...) => entryValue -> {}", entryValue);
+ log.debug("hGet(...) => entryValue -> {}", entryValue);
return entryValue;
}
@@ -799,9 +799,9 @@ public class RedisUtil implements ApplicationContextAware {
* @return key对应的hash。
*/
public static Map