提交 fd7ec799 编写于 作者: wangxinxu's avatar wangxinxu

处理token续命以及token清除问题

上级 42c58b11
流水线 #30121 已失败 于阶段
in 0 second
......@@ -3,6 +3,8 @@ package com.pica.cloud.account.account.server.mapper;
import com.pica.cloud.account.account.server.entity.LogLoginEntity;
import java.util.List;
public interface LogLoginMapper {
int deleteByPrimaryKey(Integer id);
......@@ -16,4 +18,6 @@ public interface LogLoginMapper {
int updateByPrimaryKeySelective(LogLoginEntity record);
int updateByPrimaryKey(LogLoginEntity record);
List<String> selectTokenByAcctId(Integer id);
}
\ No newline at end of file
......@@ -5,7 +5,9 @@ import com.pica.cloud.account.account.server.entity.Account;
import com.pica.cloud.account.account.server.entity.Doctor;
import com.pica.cloud.account.account.server.enums.SourceTypeEnum;
import com.pica.cloud.account.account.server.mapper.DoctorMapper;
import com.pica.cloud.account.account.server.mapper.LogLoginMapper;
import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.utils.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -14,10 +16,7 @@ import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import java.util.*;
/**
* Token工具类
......@@ -32,6 +31,8 @@ public class TokenUtils {
@Autowired
private DoctorMapper doctorMapper;
@Autowired
private LogLoginMapper logLoginMapper;
/**
* 校验token的状态
*
......@@ -80,9 +81,9 @@ public class TokenUtils {
return false;
}
try {
cacheClient.set(key, value, expiredSeconds);
cacheClient.expire(key, expiredSeconds);
logger.info("tokenContinueTime-{} key: {} value: {}", id, key, value);
cacheClient.set(value + "-" + sourceTypeRedis, key, expiredSeconds);
cacheClient.expire(value + "-" + sourceTypeRedis, expiredSeconds);
return true;
} catch (Exception e) {
logger.error("tokenContinueTime-Exception-{}" + e.getMessage(), e);
......@@ -111,6 +112,15 @@ public class TokenUtils {
if (StringUtils.isNotBlank(oldToken)) {
Long del = cacheClient.del(oldToken);
logger.info("oldToken: {} num: {}", oldToken, del);
// log_login 中查询出所有的token,并删除
List<String> tokenList = logLoginMapper.selectTokenByAcctId(account.getAcctId());
if (StringUtil.isNotEmptyList(tokenList)) {
for (int i = 0 ; i < tokenList.size(); i++) {
del = cacheClient.del(oldToken);
logger.info("oldToken: {} num: {} i:{}", oldToken, del, i);
}
}
}
// 根据不同的产品线设置token有效期
int expiredSeconds = 24 * 60 * 60;
......
......@@ -202,4 +202,15 @@
delete_flag = #{deleteFlag,jdbcType=TINYINT}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectTokenByAcctId" resultType="java.lang.String" parameterType="java.lang.Integer" >
select
token
from log_login
where acct_id = #{id,jdbcType=INTEGER}
and delete_flag = 1
and source_type in (1,2)
and login_type in (1,2,3,5,6,7)
and create_time > date_add(create_time, interval -3 month)
</select>
</mapper>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册