Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
map-parent
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
常超
map-parent
Commits
2b35e38b
Commit
2b35e38b
authored
Mar 29, 2023
by
yangyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
湖南用户10分钟未操作处理(湖南)
parent
86987cb8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
122 additions
and
8 deletions
+122
-8
common/common_utils/src/main/java/com/founder/commonutils/model/newPublicEntity/Token.java
+7
-1
common/service_base/src/main/java/com/founder/servicebase/config/RedisConfig.java
+27
-0
common/service_base/src/main/java/com/founder/servicebase/config/TwoRedisConfig.java
+44
-0
common/service_base/src/main/java/com/founder/servicebase/controller/SysUserController.java
+10
-4
common/service_base/src/main/java/com/founder/servicebase/logs/SysLogAspect.java
+23
-1
service/publicapi/src/main/java/com/founder/publicapi/PublicapiApplication.java
+2
-2
service/publicapi/src/main/resources/bootstrap-dev.properties
+5
-0
service/publicapi/src/main/resources/bootstrap-prod.properties
+4
-0
No files found.
common/common_utils/src/main/java/com/founder/commonutils/model/newPublicEntity/Token.java
View file @
2b35e38b
...
@@ -21,17 +21,23 @@ public class Token {
...
@@ -21,17 +21,23 @@ public class Token {
* 密码
* 密码
*/
*/
private
String
password
;
private
String
password
;
/**
* 证件号码
*/
private
String
identitycard
;
public
Token
(){}
public
Token
(){}
public
Token
(
String
username
,
String
ip
,
String
password
){
public
Token
(
String
username
,
String
ip
,
String
password
,
String
identitycard
){
this
.
username
=
username
;
this
.
username
=
username
;
this
.
ip
=
ip
;
this
.
ip
=
ip
;
this
.
password
=
password
;
this
.
password
=
password
;
this
.
identitycard
=
identitycard
;
}
}
public
Token
(
JSONObject
object
)
{
public
Token
(
JSONObject
object
)
{
this
.
username
=
(
String
)
object
.
get
(
"username"
);
this
.
username
=
(
String
)
object
.
get
(
"username"
);
this
.
ip
=(
String
)
object
.
get
(
"ip"
);
this
.
ip
=(
String
)
object
.
get
(
"ip"
);
this
.
password
=(
String
)
object
.
get
(
"password"
);
this
.
password
=(
String
)
object
.
get
(
"password"
);
this
.
identitycard
=(
String
)
object
.
get
(
"identitycard"
);
}
}
}
}
common/service_base/src/main/java/com/founder/servicebase/config/RedisConfig.java
0 → 100644
View file @
2b35e38b
package
com
.
founder
.
servicebase
.
config
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.connection.RedisPassword
;
import
org.springframework.data.redis.connection.RedisStandaloneConfiguration
;
import
org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory
;
@Configuration
public
class
RedisConfig
{
/**
* 创建redis连接工厂
*/
public
RedisConnectionFactory
connectionFactory
(
String
hostName
,
int
port
,
String
password
,
int
index
)
{
RedisStandaloneConfiguration
configuration
=
new
RedisStandaloneConfiguration
();
configuration
.
setHostName
(
hostName
);
configuration
.
setPort
(
port
);
configuration
.
setPassword
(
RedisPassword
.
of
(
password
));
configuration
.
setDatabase
(
index
);
LettuceConnectionFactory
factory
=
new
LettuceConnectionFactory
(
configuration
);
factory
.
afterPropertiesSet
();
return
factory
;
}
}
common/service_base/src/main/java/com/founder/servicebase/config/TwoRedisConfig.java
0 → 100644
View file @
2b35e38b
package
com
.
founder
.
servicebase
.
config
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.connection.RedisPassword
;
import
org.springframework.data.redis.connection.RedisStandaloneConfiguration
;
import
org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.RedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
//@EnableCaching
@Configuration
public
class
TwoRedisConfig
extends
RedisConfig
{
@Value
(
"${spring.redis2.database}"
)
private
int
dbIndex
;
@Value
(
"${spring.redis2.host}"
)
private
String
host
;
@Value
(
"${spring.redis2.port}"
)
private
int
port
;
@Value
(
"${spring.redis2.password}"
)
private
String
password
;
/**
* 配置redisTemplate 注入方式使用@Resource(name="") 方式注入
*/
@Bean
(
name
=
"twoRedisTemplate"
)
public
StringRedisTemplate
redisTemplate
()
{
StringRedisTemplate
redisTemplate
=
new
StringRedisTemplate
();
redisTemplate
.
setConnectionFactory
(
connectionFactory
(
host
,
port
,
password
,
dbIndex
));
redisTemplate
.
afterPropertiesSet
();
return
redisTemplate
;
}
}
common/service_base/src/main/java/com/founder/servicebase/controller/SysUserController.java
View file @
2b35e38b
...
@@ -12,6 +12,8 @@ import com.founder.servicebase.logs.OperationType;
...
@@ -12,6 +12,8 @@ import com.founder.servicebase.logs.OperationType;
import
com.founder.servicebase.service.SysUserService
;
import
com.founder.servicebase.service.SysUserService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
@@ -23,6 +25,7 @@ import java.text.SimpleDateFormat;
...
@@ -23,6 +25,7 @@ import java.text.SimpleDateFormat;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
import
static
com
.
founder
.
commonutils
.
util
.
AesEncryptUtil
.
desEncrypt
;
import
static
com
.
founder
.
commonutils
.
util
.
AesEncryptUtil
.
desEncrypt
;
...
@@ -41,7 +44,8 @@ public class SysUserController extends ApiController {
...
@@ -41,7 +44,8 @@ public class SysUserController extends ApiController {
*/
*/
@Resource
@Resource
private
SysUserService
sysUserService
;
private
SysUserService
sysUserService
;
@Resource
(
name
=
"twoRedisTemplate"
)
private
StringRedisTemplate
redisTemplate
;
@ApiOperation
(
value
=
"登录"
)
@ApiOperation
(
value
=
"登录"
)
@OperLog
(
message
=
"登录"
,
operation
=
OperationType
.
LOGIN
)
@OperLog
(
message
=
"登录"
,
operation
=
OperationType
.
LOGIN
)
...
@@ -79,7 +83,7 @@ public class SysUserController extends ApiController {
...
@@ -79,7 +83,7 @@ public class SysUserController extends ApiController {
JwtUser
util
=
new
JwtUser
();
JwtUser
util
=
new
JwtUser
();
String
ip
=
request
.
getRemoteAddr
();
String
ip
=
request
.
getRemoteAddr
();
//密码加密与刑专一致
//密码加密与刑专一致
Token
tokenEntity
=
new
Token
(
one
.
getUsername
(),
one
.
getIp
(),
DigestUtil
.
encrypt
(
password
));
Token
tokenEntity
=
new
Token
(
one
.
getUsername
(),
one
.
getIp
(),
DigestUtil
.
encrypt
(
password
)
,
one
.
getIdentitycard
()
);
JSONObject
jsonObject
=
(
JSONObject
)
JSONObject
.
toJSON
(
tokenEntity
);
JSONObject
jsonObject
=
(
JSONObject
)
JSONObject
.
toJSON
(
tokenEntity
);
//用户JWT生成token
//用户JWT生成token
String
token
=
util
.
createJWT
(
jsonObject
.
toString
());
String
token
=
util
.
createJWT
(
jsonObject
.
toString
());
...
@@ -121,11 +125,13 @@ public class SysUserController extends ApiController {
...
@@ -121,11 +125,13 @@ public class SysUserController extends ApiController {
if
(
one
==
null
)
{
if
(
one
==
null
)
{
return
MapRestResult
.
build
(
500
,
"该用户不存在"
,
null
);
return
MapRestResult
.
build
(
500
,
"该用户不存在"
,
null
);
}
}
// 十分钟未操作
String
key
=
"userIdleTime:"
+
identityCard
;
redisTemplate
.
opsForValue
().
set
(
key
,
"1"
,
10
,
TimeUnit
.
MINUTES
);
// 拿到真实ip
// 拿到真实ip
one
.
setIp
(
NetworkUtil
.
getIpAddr
(
request
));
one
.
setIp
(
NetworkUtil
.
getIpAddr
(
request
));
JwtUser
util
=
new
JwtUser
();
JwtUser
util
=
new
JwtUser
();
String
ip
=
request
.
getRemoteAddr
();
Token
tokenEntity
=
new
Token
(
one
.
getUsername
(),
one
.
getIp
(),
one
.
getPassword
(),
one
.
getIdentitycard
());
Token
tokenEntity
=
new
Token
(
one
.
getUsername
(),
one
.
getIp
(),
one
.
getPassword
());
JSONObject
jsonObject
=
(
JSONObject
)
JSONObject
.
toJSON
(
tokenEntity
);
JSONObject
jsonObject
=
(
JSONObject
)
JSONObject
.
toJSON
(
tokenEntity
);
// 用户JWT生成token
// 用户JWT生成token
String
token
=
util
.
createJWT
(
jsonObject
.
toString
());
String
token
=
util
.
createJWT
(
jsonObject
.
toString
());
...
...
common/service_base/src/main/java/com/founder/servicebase/logs/SysLogAspect.java
View file @
2b35e38b
...
@@ -10,6 +10,7 @@ import com.founder.commonutils.model.newPublicEntity.Token;
...
@@ -10,6 +10,7 @@ import com.founder.commonutils.model.newPublicEntity.Token;
import
com.founder.commonutils.util.JwtUser
;
import
com.founder.commonutils.util.JwtUser
;
import
com.founder.commonutils.util.KeyUtil
;
import
com.founder.commonutils.util.KeyUtil
;
import
com.founder.commonutils.util.NetworkUtil
;
import
com.founder.commonutils.util.NetworkUtil
;
import
com.founder.commonutils.util.ResultUtil
;
import
com.founder.servicebase.logs.mapper.mysqlMapper.SkSysLogMapper
;
import
com.founder.servicebase.logs.mapper.mysqlMapper.SkSysLogMapper
;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.Claims
;
import
lombok.SneakyThrows
;
import
lombok.SneakyThrows
;
...
@@ -23,17 +24,21 @@ import org.aspectj.lang.reflect.MethodSignature;
...
@@ -23,17 +24,21 @@ import org.aspectj.lang.reflect.MethodSignature;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
import
static
com
.
founder
.
commonutils
.
util
.
AesEncryptUtil
.
desEncrypt
;
import
static
com
.
founder
.
commonutils
.
util
.
AesEncryptUtil
.
desEncrypt
;
...
@@ -49,7 +54,8 @@ public class SysLogAspect {
...
@@ -49,7 +54,8 @@ public class SysLogAspect {
@Autowired
@Autowired
private
SkSysLogMapper
sysLogMapper
;
private
SkSysLogMapper
sysLogMapper
;
private
static
Logger
LOG
=
LoggerFactory
.
getLogger
(
SysLogAspect
.
class
);
private
static
Logger
LOG
=
LoggerFactory
.
getLogger
(
SysLogAspect
.
class
);
@Resource
(
name
=
"twoRedisTemplate"
)
private
StringRedisTemplate
redisTemplate
;
//定义切点 @Pointcut
//定义切点 @Pointcut
//在注解的位置切入代码
//在注解的位置切入代码
//@Pointcut("@within(OperLog)")
//@Pointcut("@within(OperLog)")
...
@@ -138,6 +144,15 @@ public class SysLogAspect {
...
@@ -138,6 +144,15 @@ public class SysLogAspect {
System
.
out
.
println
(
"token===>"
+
token
);
System
.
out
.
println
(
"token===>"
+
token
);
sysLog
.
setUserid
(
token
.
getUsername
());
sysLog
.
setUserid
(
token
.
getUsername
());
sysLog
.
setLx
(
"1"
);
sysLog
.
setLx
(
"1"
);
String
key
=
"userIdleTime:"
+
token
.
getIdentitycard
();
System
.
out
.
println
(
"userIdleTime:key=="
+
key
+
"&&value=="
+
redisTemplate
.
opsForValue
().
get
(
key
));
if
(!
redisTemplate
.
hasKey
(
key
)){
String
msg
=
"用户10分钟未操作!"
;
Map
<
String
,
Object
>
mapResult
=
getMap
(
401
,
msg
);
ResultUtil
.
responseJson
(
attributes
.
getResponse
(),
mapResult
);
return
false
;
}
redisTemplate
.
opsForValue
().
set
(
key
,
"1"
,
10
,
TimeUnit
.
MINUTES
);
//存入redis并设置过期时间
}
catch
(
}
catch
(
TokenException
e
)
{
TokenException
e
)
{
sysLog
.
setUserid
(
"error"
);
sysLog
.
setUserid
(
"error"
);
...
@@ -247,4 +262,11 @@ public class SysLogAspect {
...
@@ -247,4 +262,11 @@ public class SysLogAspect {
"\n------------------\n\n"
);
"\n------------------\n\n"
);
return
content
;
return
content
;
}
}
public
Map
<
String
,
Object
>
getMap
(
Integer
status
,
String
msg
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"code"
,
status
);
map
.
put
(
"msg"
,
msg
);
return
map
;
}
}
}
service/publicapi/src/main/java/com/founder/publicapi/PublicapiApplication.java
View file @
2b35e38b
...
@@ -30,8 +30,8 @@ public class PublicapiApplication {
...
@@ -30,8 +30,8 @@ public class PublicapiApplication {
@Bean
@Bean
public
RestTemplate
restTemplate
(){
public
RestTemplate
restTemplate
(){
SimpleClientHttpRequestFactory
factory
=
new
SimpleClientHttpRequestFactory
();
SimpleClientHttpRequestFactory
factory
=
new
SimpleClientHttpRequestFactory
();
factory
.
setConnectTimeout
(
10000
);
factory
.
setConnectTimeout
(
10000
0
);
factory
.
setReadTimeout
(
10000
);
factory
.
setReadTimeout
(
10000
0
);
RestTemplate
restTemplate
=
new
RestTemplate
(
factory
);
RestTemplate
restTemplate
=
new
RestTemplate
(
factory
);
return
restTemplate
;
return
restTemplate
;
}
}
...
...
service/publicapi/src/main/resources/bootstrap-dev.properties
View file @
2b35e38b
...
@@ -27,6 +27,11 @@ spring.redis.host=47.92.225.109
...
@@ -27,6 +27,11 @@ spring.redis.host=47.92.225.109
spring.redis.port
=
3001
spring.redis.port
=
3001
spring.redis.password
=
CcXzxt
spring.redis.password
=
CcXzxt
spring.redis2.host
=
47.92.225.109
spring.redis2.port
=
3001
spring.redis2.password
=
CcXzxt
spring.redis2.database
=
10
#\u6570\u636E\u5206\u6790\u4E0A\u4F20\u7684\u8DEF\u5F84
#\u6570\u636E\u5206\u6790\u4E0A\u4F20\u7684\u8DEF\u5F84
hnkshFilePath
=
/data/excel/kshExcel/
hnkshFilePath
=
/data/excel/kshExcel/
#\u6570\u636E\u5206\u6790\u4E0B\u8F7D\u7684\u8DEF\u5F84
#\u6570\u636E\u5206\u6790\u4E0B\u8F7D\u7684\u8DEF\u5F84
...
...
service/publicapi/src/main/resources/bootstrap-prod.properties
View file @
2b35e38b
...
@@ -26,6 +26,10 @@ spring.redis.port=4379
...
@@ -26,6 +26,10 @@ spring.redis.port=4379
spring.redis.database
=
5
spring.redis.database
=
5
spring.redis.password
=
ENC(LDz9F1qeGmbTMTtoQj7ADA==)
spring.redis.password
=
ENC(LDz9F1qeGmbTMTtoQj7ADA==)
spring.redis2.host
=
10.142.16.189
spring.redis2.port
=
4379
spring.redis2.password
=
ENC(UobMbjASghUGMb9FBnhnCg==)
spring.redis2.database
=
0
#\u6570\u636E\u5206\u6790\u4E0A\u4F20\u7684\u8DEF\u5F84
#\u6570\u636E\u5206\u6790\u4E0A\u4F20\u7684\u8DEF\u5F84
hnkshFilePath
=
/data/excel/kshExcel/
hnkshFilePath
=
/data/excel/kshExcel/
#\u6570\u636E\u5206\u6790\u4E0B\u8F7D\u7684\u8DEF\u5F84
#\u6570\u636E\u5206\u6790\u4E0B\u8F7D\u7684\u8DEF\u5F84
...
...
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