Commit 143b2d3e by yuquan.zhu

加入redis实现离职员工block

parent 9fc0f401
...@@ -111,11 +111,12 @@ ...@@ -111,11 +111,12 @@
</dependency> </dependency>
<!-- optional这个需要为 true 热部署才有效 --> <!-- optional这个需要为 true 热部署才有效 -->
<!-- <dependency> <!--<dependency>-->
<groupId>org.springframework.boot</groupId> <!--<groupId>org.springframework.boot</groupId>-->
<artifactId>spring-boot-devtools</artifactId> <!--<artifactId>spring-boot-devtools</artifactId>-->
<optional>true</optional> <!--<optional>true</optional>-->
</dependency> --> <!--<scope>runtime</scope>-->
<!--</dependency>-->
<!-- swagger2 --> <!-- swagger2 -->
<dependency> <dependency>
...@@ -394,6 +395,13 @@ ...@@ -394,6 +395,13 @@
<version>3.3.0</version> <version>3.3.0</version>
</dependency> </dependency>
<!--springboot中的redis依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>1.4.7.RELEASE</version>
</dependency>
</dependencies> </dependencies>
......
...@@ -2,10 +2,14 @@ package cn.timer.api.config.interceptor; ...@@ -2,10 +2,14 @@ package cn.timer.api.config.interceptor;
import java.io.IOException; import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; 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.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
...@@ -16,7 +20,10 @@ import cn.timer.api.utils.ResponseResult; ...@@ -16,7 +20,10 @@ import cn.timer.api.utils.ResponseResult;
//拦截登录失效的请求 //拦截登录失效的请求
@Component @Component
public class RedisSessionInterceptor implements HandlerInterceptor { public class RedisSessionInterceptor implements HandlerInterceptor {
@Resource
private RedisUtil redisUtil;
@Override @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception { throws Exception {
...@@ -48,6 +55,18 @@ public class RedisSessionInterceptor implements HandlerInterceptor { ...@@ -48,6 +55,18 @@ public class RedisSessionInterceptor implements HandlerInterceptor {
response401(response); response401(response);
return false; 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); // response401(response);
return true; return true;
......
...@@ -6,8 +6,10 @@ import java.util.List; ...@@ -6,8 +6,10 @@ import java.util.List;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import cn.timer.api.utils.redis.RedisUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -44,6 +46,8 @@ import cn.timer.api.utils.ResultUtil; ...@@ -44,6 +46,8 @@ import cn.timer.api.utils.ResultUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
@RestController @RestController
@Api(tags = "5.0企业讯息") @Api(tags = "5.0企业讯息")
@Transactional @Transactional
...@@ -56,6 +60,9 @@ public class CmsController { ...@@ -56,6 +60,9 @@ public class CmsController {
@Autowired @Autowired
private CmsIsReadMapper cmsIsReadMapper; private CmsIsReadMapper cmsIsReadMapper;
@Resource
private RedisUtil redisUtil;
// @Autowired // @Autowired
// private CmsAnnouncementMapper cmsAnnouncementMapper; // private CmsAnnouncementMapper cmsAnnouncementMapper;
...@@ -85,6 +92,13 @@ public class CmsController { ...@@ -85,6 +92,13 @@ public class CmsController {
@GetMapping(value = "/zxqyxx") @GetMapping(value = "/zxqyxx")
@ApiOperation(value = "获取最新讯息的标题、发布时间", httpMethod = "GET", notes = "接口发布说明") @ApiOperation(value = "获取最新讯息的标题、发布时间", httpMethod = "GET", notes = "接口发布说明")
public Result<List<CmsContent>> groupbyTime(@CurrentUser UserBean userBean) { 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(); Integer orgCode = userBean.getOrgCode();
QueryWrapper<CmsContent> queryWrapper = new QueryWrapper<>(); QueryWrapper<CmsContent> queryWrapper = new QueryWrapper<>();
queryWrapper.select("id", "title", "author", "releasetime", "fmtpath").eq("releasestate", 0) queryWrapper.select("id", "title", "author", "releasetime", "fmtpath").eq("releasestate", 0)
......
...@@ -17,10 +17,12 @@ import java.util.Map; ...@@ -17,10 +17,12 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import cn.timer.api.utils.redis.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.transaction.interceptor.TransactionAspectSupport;
...@@ -156,6 +158,12 @@ public class YgglController { ...@@ -156,6 +158,12 @@ public class YgglController {
@Autowired @Autowired
private YgMzDtoMapper ygMzDtoMapper; private YgMzDtoMapper ygMzDtoMapper;
@Resource
private RedisUtil redisUtil;
@Value("${server.servlet.session.timeout}")
public Integer session_timeout;
/** /**
* 获取员工档案 * 获取员工档案
* *
...@@ -1376,7 +1384,8 @@ public class YgglController { ...@@ -1376,7 +1384,8 @@ public class YgglController {
try { try {
realtimeupdate.AttendanceTask(userBean.getOrgCode(), empNum, 2,null); realtimeupdate.AttendanceTask(userBean.getOrgCode(), empNum, 2,null);
redisUtil.set("BlockUser"+empNum,"BlockUser",session_timeout);
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
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();
}
}
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;
}
}
}
...@@ -87,6 +87,24 @@ spring: ...@@ -87,6 +87,24 @@ spring:
height: 76 # Height of the banner image in chars (default based on image height). height: 76 # Height of the banner image in chars (default based on image height).
margin: 2 # Left hand image margin in chars. margin: 2 # Left hand image margin in chars.
invert: false # Whether images should be inverted for dark terminal themes. 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: mail:
port: 465 port: 465
......
...@@ -105,6 +105,24 @@ spring: ...@@ -105,6 +105,24 @@ spring:
socketFactory: socketFactory:
port: 465 port: 465
class: javax.net.ssl.SSLSocketFactory 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
mybatis-plus: mybatis-plus:
......
...@@ -104,6 +104,24 @@ spring: ...@@ -104,6 +104,24 @@ spring:
socketFactory: socketFactory:
port: 465 port: 465
class: javax.net.ssl.SSLSocketFactor 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
mybatis-plus: mybatis-plus:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment