Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8timerapiv200
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
8timerv2
8timerapiv200
Commits
0a9791f2
Commit
0a9791f2
authored
4 years ago
by
yuquan.zhu
Committed by
chenzg
3 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入redis实现离职员工block
parent
0ec85b2a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
273 additions
and
7 deletions
+273
-7
pom.xml
+13
-5
src/main/java/cn/timer/api/config/interceptor/RedisSessionInterceptor.java
+20
-1
src/main/java/cn/timer/api/controller/qyxx/CmsController.java
+14
-0
src/main/java/cn/timer/api/controller/yggl/YgglController.java
+10
-1
src/main/java/cn/timer/api/utils/redis/RedisConfig.java
+116
-0
src/main/java/cn/timer/api/utils/redis/RedisUtil.java
+0
-0
src/main/java/cn/timer/api/utils/redis/Status.java
+46
-0
src/main/resources/application-dev.yml
+18
-0
src/main/resources/application-pro.yml
+18
-0
src/main/resources/application-test.yml
+18
-0
No files found.
pom.xml
View file @
0a9791f2
...
...
@@ -111,11 +111,12 @@
</dependency>
<!-- optional这个需要为 true 热部署才有效 -->
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency> -->
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-devtools</artifactId>-->
<!--<optional>true</optional>-->
<!--<scope>runtime</scope>-->
<!--</dependency>-->
<!-- swagger2 -->
<dependency>
...
...
@@ -394,6 +395,13 @@
<version>
3.3.0
</version>
</dependency>
<!--springboot中的redis依赖-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
<version>
1.4.7.RELEASE
</version>
</dependency>
</dependencies>
...
...
This diff is collapsed.
Click to expand it.
src/main/java/cn/timer/api/config/interceptor/RedisSessionInterceptor.java
View file @
0a9791f2
...
...
@@ -2,10 +2,14 @@ package cn.timer.api.config.interceptor;
import
java.io.IOException
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.timer.api.bean.qyzx.QyzxEmpLogin
;
import
cn.timer.api.utils.redis.RedisUtil
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.ModelAndView
;
...
...
@@ -16,7 +20,10 @@ import cn.timer.api.utils.ResponseResult;
//拦截登录失效的请求
@Component
public
class
RedisSessionInterceptor
implements
HandlerInterceptor
{
@Resource
private
RedisUtil
redisUtil
;
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
...
...
@@ -48,6 +55,18 @@ public class RedisSessionInterceptor implements HandlerInterceptor {
response401
(
response
);
return
false
;
}
try
{
QyzxEmpLogin
eld
=
BeanUtil
.
toBean
(
session
.
getAttribute
(
"ui"
),
QyzxEmpLogin
.
class
);
if
(
redisUtil
.
get
(
"BlockUser"
+
eld
.
getId
())!=
null
){
response401
(
response
);
return
false
;
}
}
catch
(
Exception
e
){
response401
(
response
);
return
false
;
}
// response401(response);
return
true
;
...
...
This diff is collapsed.
Click to expand it.
src/main/java/cn/timer/api/controller/qyxx/CmsController.java
View file @
0a9791f2
...
...
@@ -6,8 +6,10 @@ import java.util.List;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
cn.timer.api.utils.redis.RedisUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.bind.annotation.DeleteMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
...
...
@@ -44,6 +46,8 @@ import cn.timer.api.utils.ResultUtil;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
javax.annotation.Resource
;
@RestController
@Api
(
tags
=
"5.0企业讯息"
)
@Transactional
...
...
@@ -56,6 +60,9 @@ public class CmsController {
@Autowired
private
CmsIsReadMapper
cmsIsReadMapper
;
@Resource
private
RedisUtil
redisUtil
;
// @Autowired
// private CmsAnnouncementMapper cmsAnnouncementMapper;
...
...
@@ -85,6 +92,13 @@ public class CmsController {
@GetMapping
(
value
=
"/zxqyxx"
)
@ApiOperation
(
value
=
"获取最新讯息的标题、发布时间"
,
httpMethod
=
"GET"
,
notes
=
"接口发布说明"
)
public
Result
<
List
<
CmsContent
>>
groupbyTime
(
@CurrentUser
UserBean
userBean
)
{
// new RedisUtil(new RedisTemplate<String, Object>()).set("1","2");
redisUtil
.
set
(
"scien"
,
"123123123123333"
);
redisUtil
.
set
(
"scien2"
,
"23"
);
redisUtil
.
set
(
"scien3"
,
"3"
);
redisUtil
.
set
(
"scien4"
,
"455"
);
redisUtil
.
set
(
"scien133"
,
"455"
);
redisUtil
.
set
(
"scien1111"
,
"455"
);
Integer
orgCode
=
userBean
.
getOrgCode
();
QueryWrapper
<
CmsContent
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
select
(
"id"
,
"title"
,
"author"
,
"releasetime"
,
"fmtpath"
).
eq
(
"releasestate"
,
0
)
...
...
This diff is collapsed.
Click to expand it.
src/main/java/cn/timer/api/controller/yggl/YgglController.java
View file @
0a9791f2
...
...
@@ -17,10 +17,12 @@ import java.util.Map;
import
java.util.Map.Entry
;
import
java.util.stream.Collectors
;
import
javax.annotation.Resource
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.transaction.Transactional
;
import
cn.timer.api.utils.redis.RedisUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
...
...
@@ -156,6 +158,12 @@ public class YgglController {
@Autowired
private
YgMzDtoMapper
ygMzDtoMapper
;
@Resource
private
RedisUtil
redisUtil
;
@Value
(
"${server.servlet.session.timeout}"
)
public
Integer
session_timeout
;
/**
* 获取员工档案
*
...
...
@@ -1376,7 +1384,8 @@ public class YgglController {
try
{
realtimeupdate
.
AttendanceTask
(
userBean
.
getOrgCode
(),
empNum
,
2
,
null
);
redisUtil
.
set
(
"BlockUser"
+
empNum
,
"BlockUser"
,
session_timeout
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/cn/timer/api/utils/redis/RedisConfig.java
0 → 100644
View file @
0a9791f2
package
cn
.
timer
.
api
.
utils
.
redis
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.springframework.cache.annotation.CachingConfigurerSupport
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.core.*
;
import
org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
/**
* redis配置类
* @program: springbootdemo
* @Date: 2019/1/25 15:20
* @Author: Mr.Zheng
* @Description:
*/
@Configuration
@EnableCaching
//开启注解
public
class
RedisConfig
extends
CachingConfigurerSupport
{
/**
* retemplate相关配置
* @param factory
* @return
*/
@Bean
public
RedisTemplate
<
String
,
Object
>
redisTemplate
(
RedisConnectionFactory
factory
)
{
RedisTemplate
<
String
,
Object
>
template
=
new
RedisTemplate
<>();
// 配置连接工厂
template
.
setConnectionFactory
(
factory
);
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
Jackson2JsonRedisSerializer
jacksonSeial
=
new
Jackson2JsonRedisSerializer
(
Object
.
class
);
ObjectMapper
om
=
new
ObjectMapper
();
// 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public
om
.
setVisibility
(
PropertyAccessor
.
ALL
,
JsonAutoDetect
.
Visibility
.
ANY
);
// 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常
om
.
enableDefaultTyping
(
ObjectMapper
.
DefaultTyping
.
NON_FINAL
);
jacksonSeial
.
setObjectMapper
(
om
);
// 值采用json序列化
template
.
setValueSerializer
(
jacksonSeial
);
//使用StringRedisSerializer来序列化和反序列化redis的key值
template
.
setKeySerializer
(
new
StringRedisSerializer
());
// 设置hash key 和value序列化模式
template
.
setHashKeySerializer
(
new
StringRedisSerializer
());
template
.
setHashValueSerializer
(
jacksonSeial
);
template
.
afterPropertiesSet
();
return
template
;
}
/**
* 对hash类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
HashOperations
<
String
,
String
,
Object
>
hashOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForHash
();
}
/**
* 对redis字符串类型数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
ValueOperations
<
String
,
Object
>
valueOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForValue
();
}
/**
* 对链表类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
ListOperations
<
String
,
Object
>
listOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForList
();
}
/**
* 对无序集合类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
SetOperations
<
String
,
Object
>
setOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForSet
();
}
/**
* 对有序集合类型的数据操作
*
* @param redisTemplate
* @return
*/
@Bean
public
ZSetOperations
<
String
,
Object
>
zSetOperations
(
RedisTemplate
<
String
,
Object
>
redisTemplate
)
{
return
redisTemplate
.
opsForZSet
();
}
}
This diff is collapsed.
Click to expand it.
src/main/java/cn/timer/api/utils/redis/RedisUtil.java
0 → 100644
View file @
0a9791f2
This diff is collapsed.
Click to expand it.
src/main/java/cn/timer/api/utils/redis/Status.java
0 → 100644
View file @
0a9791f2
package
cn
.
timer
.
api
.
utils
.
redis
;
import
java.util.concurrent.TimeUnit
;
/**
* 状态枚举
* @program: dgpoms-server-root
* @Date: 2018/12/27 11:40
* @Author: Mr.Zheng
* @Description:
*/
public
abstract
class
Status
{
/**
* 过期时间相关枚举
*/
public
static
enum
ExpireEnum
{
//未读消息的有效期为30天
UNREAD_MSG
(
30L
,
TimeUnit
.
DAYS
)
;
/**
* 过期时间
*/
private
Long
time
;
/**
* 时间单位
*/
private
TimeUnit
timeUnit
;
ExpireEnum
(
Long
time
,
TimeUnit
timeUnit
)
{
this
.
time
=
time
;
this
.
timeUnit
=
timeUnit
;
}
public
Long
getTime
()
{
return
time
;
}
public
TimeUnit
getTimeUnit
()
{
return
timeUnit
;
}
}
}
This diff is collapsed.
Click to expand it.
src/main/resources/application-dev.yml
View file @
0a9791f2
...
...
@@ -87,6 +87,24 @@ spring:
height
:
76
# Height of the banner image in chars (default based on image height).
margin
:
2
# Left hand image margin in chars.
invert
:
false
# Whether images should be inverted for dark terminal themes.
redis
:
database
:
4
# Redis数据库索引(默认为0),如果设置为1,那么存入的key-value都存放在select 1中
host
:
47.115.147.241
port
:
7788
password
:
(!0YouLingRcRedis0!)
max-wait
:
30000
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-active
:
100
# 连接池最大连接数(使用负值表示没有限制)
max-idle
:
20
# 连接池中的最大空闲连接
min-idle
:
0
# 连接池中的最小空闲连接
timeout
:
5000
# 连接超时
#password: 123456 # 密码,默认密码为空
#cluster: # 集群配置
#nodes: 127.0.0.1:6381,127.0.0.1:6382,127.0.0.1:6383,127.0.0.1:6384,127.0.0.1:6385,127.0.0.1:6386
#max-redirects: 2 # 最大重定向次数
devtools
:
restart
:
poll-interval
:
3000ms
quiet-period
:
2999ms
mail
:
port
:
465
...
...
This diff is collapsed.
Click to expand it.
src/main/resources/application-pro.yml
View file @
0a9791f2
...
...
@@ -105,6 +105,24 @@ spring:
socketFactory
:
port
:
465
class
:
javax.net.ssl.SSLSocketFactory
redis
:
database
:
5
# Redis数据库索引(默认为0),如果设置为1,那么存入的key-value都存放在select 1中
host
:
47.115.147.241
port
:
7788
password
:
(!0YouLingRcRedis0!)
max-wait
:
30000
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-active
:
100
# 连接池最大连接数(使用负值表示没有限制)
max-idle
:
20
# 连接池中的最大空闲连接
min-idle
:
0
# 连接池中的最小空闲连接
timeout
:
5000
# 连接超时
#password: 123456 # 密码,默认密码为空
#cluster: # 集群配置
#nodes: 127.0.0.1:6381,127.0.0.1:6382,127.0.0.1:6383,127.0.0.1:6384,127.0.0.1:6385,127.0.0.1:6386
#max-redirects: 2 # 最大重定向次数
devtools
:
restart
:
poll-interval
:
3000ms
quiet-period
:
2999ms
# mybatis-plus
mybatis-plus
:
...
...
This diff is collapsed.
Click to expand it.
src/main/resources/application-test.yml
View file @
0a9791f2
...
...
@@ -104,6 +104,24 @@ spring:
socketFactory
:
port
:
465
class
:
javax.net.ssl.SSLSocketFactor
redis
:
database
:
6
# Redis数据库索引(默认为0),如果设置为1,那么存入的key-value都存放在select 1中
host
:
47.115.147.241
port
:
7788
password
:
(!0YouLingRcRedis0!)
max-wait
:
30000
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-active
:
100
# 连接池最大连接数(使用负值表示没有限制)
max-idle
:
20
# 连接池中的最大空闲连接
min-idle
:
0
# 连接池中的最小空闲连接
timeout
:
5000
# 连接超时
#password: 123456 # 密码,默认密码为空
#cluster: # 集群配置
#nodes: 127.0.0.1:6381,127.0.0.1:6382,127.0.0.1:6383,127.0.0.1:6384,127.0.0.1:6385,127.0.0.1:6386
#max-redirects: 2 # 最大重定向次数
devtools
:
restart
:
poll-interval
:
3000ms
quiet-period
:
2999ms
# mybatis-plus
mybatis-plus
:
...
...
This diff is collapsed.
Click to expand it.
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