Commit d190c149 by Administrator

Merge branch 'develop_zyq' into 'develop'

Develop zyq

See merge request 8timerv2/8timerapiv200!393
parents 9ff4824b 4c3ddfe4
......@@ -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>
......
......@@ -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,19 @@ 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){
redisUtil.del("BlockUser"+eld.getId());
response302(response);
return false;
}
}catch (Exception e){
response401(response);
return false;
}
// response401(response);
return true;
......@@ -63,6 +83,16 @@ public class RedisSessionInterceptor implements HandlerInterceptor {
}
}
private void response302(HttpServletResponse response) {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
try {
response.getWriter().print(new JSONObject(new ResponseResult().kickOut()).toString());
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
......
......@@ -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)
......
......@@ -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();
}
......
......@@ -35,7 +35,7 @@ public class ResponseResult extends LinkedHashMap<String, Object> implements Ser
private static final String MESSAGE_FAIL = "操作失败";
private static final String MESSAGE_ERROR = "操作错误";
private static final String MESSAGE_UNLOGIN = "会话超时,请重新登录";
private static final String MESSAGE_KICKOUT = "当前账户已在其他地方登录,请重新登录";
private static final String MESSAGE_KICKOUT = "你已被管理员移出公司,请重新登录";
private static final String MESSAGE_PARAMERROR = "参数错误";
private static final String MESSAGE_UNAUTHORIZED = "授权错误";
private static final String MESSAGE_UNAUTHENTICATED = "认证错误";
......
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:
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
......
......@@ -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:
......
......@@ -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:
......
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