From 689278e511803497b2733ddc498009868ad94c6a Mon Sep 17 00:00:00 2001 From: faysalmehmood Date: Sun, 18 Sep 2022 21:58:59 +0500 Subject: [PATCH 1/4] =?UTF-8?q?#309=20=E4=BF=AE=E5=A4=8D=E6=97=B6=E5=8C=BA?= =?UTF-8?q?=E4=B8=AD=E6=96=AD=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=E7=9A=84?= =?UTF-8?q?=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/SaTokenListenerForConsolePrint.java | 9 ++++++--- .../main/java/cn/dev33/satoken/util/SaFoxUtil.java | 11 +++++++++++ .../cn/dev33/satoken/core/util/SaFoxUtilTest.java | 8 ++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/sa-token-core/src/main/java/cn/dev33/satoken/listener/SaTokenListenerForConsolePrint.java b/sa-token-core/src/main/java/cn/dev33/satoken/listener/SaTokenListenerForConsolePrint.java index fc52dac8..4a7362a3 100644 --- a/sa-token-core/src/main/java/cn/dev33/satoken/listener/SaTokenListenerForConsolePrint.java +++ b/sa-token-core/src/main/java/cn/dev33/satoken/listener/SaTokenListenerForConsolePrint.java @@ -1,6 +1,8 @@ package cn.dev33.satoken.listener; -import java.util.Date; +import java.time.Instant; +import java.time.ZoneId; +import java.time.ZonedDateTime; import cn.dev33.satoken.SaManager; import cn.dev33.satoken.stp.SaLoginModel; @@ -50,8 +52,9 @@ public class SaTokenListenerForConsolePrint implements SaTokenListener { */ @Override public void doDisable(String loginType, Object loginId, String service, int level, long disableTime) { - Date date = new Date(System.currentTimeMillis() + disableTime * 1000); - println("账号[" + loginId + "] " + service + " 服务被封禁,封禁等级=" + level + " (解封时间: " + SaFoxUtil.formatDate(date) + ")"); + Instant instant = Instant.ofEpochMilli(System.currentTimeMillis() + disableTime * 1000); + ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, ZoneId.systemDefault()); + println("账号[" + loginId + "] " + service + " 服务被封禁,封禁等级=" + level + " (解封时间: " + SaFoxUtil.formatDate(zonedDateTime) + ")"); } /** diff --git a/sa-token-core/src/main/java/cn/dev33/satoken/util/SaFoxUtil.java b/sa-token-core/src/main/java/cn/dev33/satoken/util/SaFoxUtil.java index ae2bf386..b17ac13a 100644 --- a/sa-token-core/src/main/java/cn/dev33/satoken/util/SaFoxUtil.java +++ b/sa-token-core/src/main/java/cn/dev33/satoken/util/SaFoxUtil.java @@ -4,6 +4,8 @@ import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; import java.text.SimpleDateFormat; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -106,6 +108,15 @@ public class SaFoxUtil { public static String formatDate(Date date){ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date); } + + /** + * 将日期格式化 (yyyy-MM-dd HH:mm:ss) + * @param zonedDateTime 日期 + * @return 格式化后的时间 + */ + public static String formatDate(ZonedDateTime zonedDateTime) { + return zonedDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + } /** * 从集合里查询数据 diff --git a/sa-token-test/sa-token-springboot-test/src/test/java/cn/dev33/satoken/core/util/SaFoxUtilTest.java b/sa-token-test/sa-token-springboot-test/src/test/java/cn/dev33/satoken/core/util/SaFoxUtilTest.java index a25175f3..e39abdf3 100644 --- a/sa-token-test/sa-token-springboot-test/src/test/java/cn/dev33/satoken/core/util/SaFoxUtilTest.java +++ b/sa-token-test/sa-token-springboot-test/src/test/java/cn/dev33/satoken/core/util/SaFoxUtilTest.java @@ -1,8 +1,10 @@ package cn.dev33.satoken.core.util; +import java.time.Instant; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Arrays; -import java.util.Date; import java.util.List; import org.junit.jupiter.api.Assertions; @@ -51,7 +53,9 @@ public class SaFoxUtilTest { @Test public void formatDate() { - String formatDate = SaFoxUtil.formatDate(new Date(1644328600364L)); + Instant instant = Instant.ofEpochMilli(1644328600364L); + ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, ZoneId.of("Asia/Shanghai")); + String formatDate = SaFoxUtil.formatDate(zonedDateTime); Assertions.assertEquals(formatDate, "2022-02-08 21:56:40"); } From 874f1d15e95d6e2dff228e558fa3bbb5a6ba21a2 Mon Sep 17 00:00:00 2001 From: faysalmehmood Date: Sun, 18 Sep 2022 22:06:32 +0500 Subject: [PATCH 2/4] #309 indentation fix. --- .../java/cn/dev33/satoken/core/util/SaFoxUtilTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sa-token-test/sa-token-springboot-test/src/test/java/cn/dev33/satoken/core/util/SaFoxUtilTest.java b/sa-token-test/sa-token-springboot-test/src/test/java/cn/dev33/satoken/core/util/SaFoxUtilTest.java index e39abdf3..2c5f980c 100644 --- a/sa-token-test/sa-token-springboot-test/src/test/java/cn/dev33/satoken/core/util/SaFoxUtilTest.java +++ b/sa-token-test/sa-token-springboot-test/src/test/java/cn/dev33/satoken/core/util/SaFoxUtilTest.java @@ -51,13 +51,13 @@ public class SaFoxUtilTest { Assertions.assertNotEquals(SaFoxUtil.getMarking28(), SaFoxUtil.getMarking28()); } - @Test - public void formatDate() { + @Test + public void formatDate() { Instant instant = Instant.ofEpochMilli(1644328600364L); ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, ZoneId.of("Asia/Shanghai")); String formatDate = SaFoxUtil.formatDate(zonedDateTime); - Assertions.assertEquals(formatDate, "2022-02-08 21:56:40"); - } + Assertions.assertEquals(formatDate, "2022-02-08 21:56:40"); + } @Test public void searchList() { From 6e4baec90f9801bbd88166c85b36af6bc259b4d6 Mon Sep 17 00:00:00 2001 From: Faisal Mehmood Date: Sun, 18 Sep 2022 22:09:43 +0500 Subject: [PATCH 3/4] Fixing again, the indentation issue. --- .../cn/dev33/satoken/core/util/SaFoxUtilTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sa-token-test/sa-token-springboot-test/src/test/java/cn/dev33/satoken/core/util/SaFoxUtilTest.java b/sa-token-test/sa-token-springboot-test/src/test/java/cn/dev33/satoken/core/util/SaFoxUtilTest.java index 2c5f980c..4c2f9404 100644 --- a/sa-token-test/sa-token-springboot-test/src/test/java/cn/dev33/satoken/core/util/SaFoxUtilTest.java +++ b/sa-token-test/sa-token-springboot-test/src/test/java/cn/dev33/satoken/core/util/SaFoxUtilTest.java @@ -51,13 +51,13 @@ public class SaFoxUtilTest { Assertions.assertNotEquals(SaFoxUtil.getMarking28(), SaFoxUtil.getMarking28()); } - @Test - public void formatDate() { - Instant instant = Instant.ofEpochMilli(1644328600364L); - ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, ZoneId.of("Asia/Shanghai")); - String formatDate = SaFoxUtil.formatDate(zonedDateTime); - Assertions.assertEquals(formatDate, "2022-02-08 21:56:40"); - } + @Test + public void formatDate() { + Instant instant = Instant.ofEpochMilli(1644328600364L); + ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, ZoneId.of("Asia/Shanghai")); + String formatDate = SaFoxUtil.formatDate(zonedDateTime); + Assertions.assertEquals(formatDate, "2022-02-08 21:56:40"); + } @Test public void searchList() { From e95a58706c135e7c71af1203d0d8a22872845c1e Mon Sep 17 00:00:00 2001 From: mrexgo Date: Mon, 19 Sep 2022 12:49:22 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sa-token-doc/doc/api/stp-util.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sa-token-doc/doc/api/stp-util.md b/sa-token-doc/doc/api/stp-util.md index c3132c4a..e7f3e5b2 100644 --- a/sa-token-doc/doc/api/stp-util.md +++ b/sa-token-doc/doc/api/stp-util.md @@ -47,9 +47,9 @@ StpUtil.logout(); // 会话注销 StpUtil.logout(10001); // 会话注销,根据账号id StpUtil.logout(10001, "PC"); // 会话注销,根据账号id 和 设备类型 StpUtil.logoutByTokenValue(token); // 指定 Token 强制注销 -StpUtil.kickout(10001); // 踢人下线 -StpUtil.kickout(10001, "PC"); // 踢人下线,根据账号id -StpUtil.kickoutByTokenValue(token); // 踢人下线,根据账号id 和 设备类型 +StpUtil.kickout(10001); // 踢人下线,根据账号id +StpUtil.kickout(10001, "PC"); // 踢人下线,根据账号id 和 设备类型 +StpUtil.kickoutByTokenValue(token); // 踢人下线,根据token ``` @@ -152,7 +152,7 @@ StpUtil.searchTokenSessionId(keyword, start, size, sortType); // 根据条件 ### 11、账号封禁 ``` java -StpUtil.disable(10001, 1200); // 封禁:指定账号 +StpUtil.disable(10001, 1200); // 封禁:指定账号 指定时间(单位s) StpUtil.isDisable(10001); // 判断:指定账号是否已被封禁 (true=已被封禁, false=未被封禁) StpUtil.checkDisable(10001); // 校验:指定账号是否已被封禁,如果被封禁则抛出异常 `DisableServiceException` StpUtil.getDisableTime(10001); // 获取:指定账号剩余封禁时间,单位:秒(-1=永久封禁,-2=未被封禁) @@ -160,9 +160,9 @@ StpUtil.untieDisable(loginId); // 解封:指定账号 ``` -### 12、分类封禁 +### 12、分类封禁 (version >= 1.31.0) ``` java -StpUtil.disable(10001, "<业务标识>", 86400); // 封禁:指定账号的指定服务 +StpUtil.disable(10001, "<业务标识>", 86400); // 封禁:指定账号的指定服务 指定时间(单位s) StpUtil.isDisable(10001, "<业务标识>"); // 判断:指定账号的指定服务 是否已被封禁 (true=已被封禁, false=未被封禁) StpUtil.checkDisable(10001, "<业务标识>"); // 校验:指定账号的指定服务 是否已被封禁,如果被封禁则抛出异常 `DisableServiceException` StpUtil.getDisableTime(10001, "<业务标识>"); // 获取:指定账号的指定服务 剩余封禁时间,单位:秒(-1=永久封禁,-2=未被封禁) @@ -170,7 +170,7 @@ StpUtil.untieDisable(loginId, "<业务标识>"); // 解封:指定账号的 ``` -### 13、阶梯封禁 +### 13、阶梯封禁 (version >= 1.31.0) ``` java StpUtil.disableLevel(10001, "comment", 3, 10000); // 分类阶梯封禁,参数:封禁账号、封禁服务、封禁级别、封禁时间 StpUtil.getDisableLevel(10001, "comment"); // 获取:指定账号的指定服务 封禁的级别 (如果此账号未被封禁则返回 -2)