Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cnooc_zydeepen-cggl_expert-manage-miniapp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙德龙
cnooc_zydeepen-cggl_expert-manage-miniapp
Commits
1c11ee63
Commit
1c11ee63
authored
Nov 14, 2025
by
刘红梅
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
错误计数器完善
parent
a55fa2ba
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
6 deletions
+14
-6
src/main/java/com/cnooc/expert/auth/service/AccountLockService.java
+14
-6
No files found.
src/main/java/com/cnooc/expert/auth/service/AccountLockService.java
View file @
1c11ee63
...
...
@@ -5,6 +5,9 @@ import org.springframework.stereotype.Service;
import
java.time.LocalDateTime
;
import
java.util.concurrent.TimeUnit
;
import
java.time.LocalTime
;
import
java.time.temporal.ChronoUnit
;
import
java.time.format.DateTimeFormatter
;
@Service
public
class
AccountLockService
{
...
...
@@ -35,7 +38,7 @@ public class AccountLockService {
private
void
lockAccount
(
String
account
,
int
lockMinutes
)
{
String
lockKey
=
getLockKey
(
account
);
String
lockValue
=
LocalDateTime
.
now
().
toString
()
+
"|"
+
lockMinutes
;
redisTemplate
.
opsForValue
().
set
(
lockKey
,
lockValue
,
lockMinutes
,
TimeUnit
.
MINUTE
S
);
//这个超时时间需要考虑一下
redisTemplate
.
opsForValue
().
set
(
lockKey
,
lockValue
,
lockMinutes
*
60
,
TimeUnit
.
SECOND
S
);
//这个超时时间需要考虑一下
}
/**
* 手动解锁账号
...
...
@@ -72,11 +75,13 @@ public class AccountLockService {
//long failureCount = jedis.incr(attemptKey);
String
failureCountStr
=
redisTemplate
.
opsForValue
().
get
(
attemptKey
)!=
null
?
redisTemplate
.
opsForValue
().
get
(
attemptKey
).
toString
():
"0"
;
long
failureCount
=
Long
.
parseLong
(
failureCountStr
)+
1
;
redisTemplate
.
opsForValue
().
set
(
attemptKey
,
String
.
valueOf
(
failureCount
));
LocalDateTime
now
=
LocalDateTime
.
now
();
LocalDateTime
midnight
=
now
.
toLocalDate
().
atTime
(
LocalTime
.
MAX
);
redisTemplate
.
opsForValue
().
set
(
attemptKey
,
String
.
valueOf
(
failureCount
),
ChronoUnit
.
SECONDS
.
between
(
now
,
midnight
),
TimeUnit
.
SECONDS
);
// 设置计数过期时间(避免无限增长)
if
(
failureCount
==
1
)
{
redisTemplate
.
expire
(
attemptKey
,
24
*
60
,
TimeUnit
.
MINUTE
S
);
// 24小时过期
redisTemplate
.
expire
(
attemptKey
,
24
*
60
*
60
,
TimeUnit
.
SECOND
S
);
// 24小时过期
}
// 根据失败次数确定锁定时间
...
...
@@ -98,13 +103,16 @@ public class AccountLockService {
/**
* 获取锁定剩余时间
*/
public
lo
ng
getLockRemainingTime
(
String
account
)
{
public
Stri
ng
getLockRemainingTime
(
String
account
)
{
String
lockKey
=
getLockKey
(
account
);
boolean
isExist
=
Boolean
.
TRUE
.
equals
(
redisTemplate
.
hasKey
(
lockKey
));
if
(
isExist
){
return
redisTemplate
.
getExpire
(
lockKey
,
TimeUnit
.
MINUTES
);
LocalDateTime
now
=
LocalDateTime
.
now
();
LocalDateTime
futureTime
=
now
.
plusSeconds
(
redisTemplate
.
getExpire
(
lockKey
,
TimeUnit
.
SECONDS
));
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy/MM/dd HH:mm:ss"
);
return
futureTime
.
format
(
formatter
);
}
else
{
return
0
;
return
""
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment