Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
江名洋
/
linkwe-scrm
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a7519b02
authored
Feb 08, 2021
by
danmo
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
添加redis 过期key监听事件,删除无用活码id
1 parent
46af908d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
1 deletions
linkwe-common/src/main/java/com/linkwechat/common/constant/WeConstans.java
linkwe-framework/src/main/java/com/linkwechat/framework/config/RedisConfig.java
linkwe-framework/src/main/java/com/linkwechat/framework/listener/EmpleCodeExpiredListener.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeEmpleCodeServiceImpl.java
linkwe-common/src/main/java/com/linkwechat/common/constant/WeConstans.java
View file @
a7519b0
...
@@ -44,6 +44,11 @@ public class WeConstans {
...
@@ -44,6 +44,11 @@ public class WeConstans {
*/
*/
public
static
final
String
WE_AGENT_ACCESS_TOKEN
=
"we_agent_access_token"
;
public
static
final
String
WE_AGENT_ACCESS_TOKEN
=
"we_agent_access_token"
;
public
static
final
String
WE_EMPLE_CODE_KEY
=
"we_emple_code_key"
;
/**
/**
* 企业微信接口返回成功code
* 企业微信接口返回成功code
*/
*/
...
...
linkwe-framework/src/main/java/com/linkwechat/framework/config/RedisConfig.java
View file @
a7519b0
package
com
.
linkwechat
.
framework
.
config
;
package
com
.
linkwechat
.
framework
.
config
;
import
com.linkwechat.framework.listener.EmpleCodeExpiredListener
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CachingConfigurerSupport
;
import
org.springframework.cache.annotation.CachingConfigurerSupport
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.listener.PatternTopic
;
import
org.springframework.data.redis.listener.RedisMessageListenerContainer
;
import
org.springframework.data.redis.listener.adapter.MessageListenerAdapter
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
...
@@ -20,6 +25,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
...
@@ -20,6 +25,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@EnableCaching
@EnableCaching
public
class
RedisConfig
extends
CachingConfigurerSupport
public
class
RedisConfig
extends
CachingConfigurerSupport
{
{
@Autowired
private
RedisConnectionFactory
redisConnectionFactory
;
@Bean
@Bean
@SuppressWarnings
(
value
=
{
"unchecked"
,
"rawtypes"
})
@SuppressWarnings
(
value
=
{
"unchecked"
,
"rawtypes"
})
public
RedisTemplate
<
Object
,
Object
>
redisTemplate
(
RedisConnectionFactory
connectionFactory
)
public
RedisTemplate
<
Object
,
Object
>
redisTemplate
(
RedisConnectionFactory
connectionFactory
)
...
@@ -40,4 +49,18 @@ public class RedisConfig extends CachingConfigurerSupport
...
@@ -40,4 +49,18 @@ public class RedisConfig extends CachingConfigurerSupport
template
.
afterPropertiesSet
();
template
.
afterPropertiesSet
();
return
template
;
return
template
;
}
}
@Bean
public
RedisMessageListenerContainer
redisMessageListenerContainer
()
{
RedisMessageListenerContainer
redisMessageListenerContainer
=
new
RedisMessageListenerContainer
();
redisMessageListenerContainer
.
setConnectionFactory
(
redisConnectionFactory
);
return
redisMessageListenerContainer
;
}
@Bean
public
EmpleCodeExpiredListener
codeExpiredListener
()
{
return
new
EmpleCodeExpiredListener
(
this
.
redisMessageListenerContainer
());
}
}
}
linkwe-framework/src/main/java/com/linkwechat/framework/listener/EmpleCodeExpiredListener.java
0 → 100644
View file @
a7519b0
package
com
.
linkwechat
.
framework
.
listener
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.wecom.client.WeExternalContactClient
;
import
com.linkwechat.wecom.domain.WeEmpleCode
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.connection.Message
;
import
org.springframework.data.redis.listener.KeyExpirationEventMessageListener
;
import
org.springframework.data.redis.listener.RedisMessageListenerContainer
;
import
java.nio.charset.StandardCharsets
;
/**
* @author danmo
* @description redis 键值过期监听
* @date 2021/2/8 17:24
**/
public
class
EmpleCodeExpiredListener
extends
KeyExpirationEventMessageListener
{
@Autowired
private
WeExternalContactClient
weExternalContactClient
;
public
EmpleCodeExpiredListener
(
RedisMessageListenerContainer
listenerContainer
)
{
super
(
listenerContainer
);
}
@Override
public
void
onMessage
(
Message
message
,
byte
[]
pattern
)
{
System
.
out
.
println
(
"过期key:"
+
message
.
toString
());
if
(
message
.
toString
().
contains
(
WeConstans
.
WE_EMPLE_CODE_KEY
)){
weExternalContactClient
.
delContactWay
(
message
.
toString
().
split
(
":"
)[
1
]);
}
}
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/WeEmpleCodeServiceImpl.java
View file @
a7519b0
...
@@ -3,6 +3,7 @@ package com.linkwechat.wecom.service.impl;
...
@@ -3,6 +3,7 @@ package com.linkwechat.wecom.service.impl;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.core.redis.RedisCache
;
import
com.linkwechat.common.utils.SecurityUtils
;
import
com.linkwechat.common.utils.SecurityUtils
;
import
com.linkwechat.common.utils.SnowFlakeUtil
;
import
com.linkwechat.common.utils.SnowFlakeUtil
;
import
com.linkwechat.common.utils.StringUtils
;
import
com.linkwechat.common.utils.StringUtils
;
...
@@ -22,6 +23,7 @@ import org.springframework.stereotype.Service;
...
@@ -22,6 +23,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
/**
/**
...
@@ -47,6 +49,9 @@ public class WeEmpleCodeServiceImpl extends ServiceImpl<WeEmpleCodeMapper, WeEmp
...
@@ -47,6 +49,9 @@ public class WeEmpleCodeServiceImpl extends ServiceImpl<WeEmpleCodeMapper, WeEmp
@Autowired
@Autowired
private
IWeMaterialService
materialService
;
private
IWeMaterialService
materialService
;
@Autowired
private
RedisCache
redisCache
;
/**
/**
* 查询员工活码
* 查询员工活码
*
*
...
@@ -237,7 +242,10 @@ public class WeEmpleCodeServiceImpl extends ServiceImpl<WeEmpleCodeMapper, WeEmp
...
@@ -237,7 +242,10 @@ public class WeEmpleCodeServiceImpl extends ServiceImpl<WeEmpleCodeMapper, WeEmp
Long
[]
departmentIdArr
=
Arrays
.
stream
(
departmentIds
.
split
(
","
))
Long
[]
departmentIdArr
=
Arrays
.
stream
(
departmentIds
.
split
(
","
))
.
filter
(
StringUtils:
:
isNotEmpty
)
.
filter
(
StringUtils:
:
isNotEmpty
)
.
map
(
Long:
:
new
).
toArray
(
Long
[]::
new
);
.
map
(
Long:
:
new
).
toArray
(
Long
[]::
new
);
return
getQrcode
(
userIdArr
,
departmentIdArr
);
WeExternalContactDto
qrcode
=
getQrcode
(
userIdArr
,
departmentIdArr
);
//设置24小时过期
redisCache
.
setCacheObject
(
WeConstans
.
WE_EMPLE_CODE_KEY
+
":"
+
qrcode
.
getConfig_id
(),
qrcode
.
getConfig_id
(),
24
,
TimeUnit
.
HOURS
);
return
qrcode
;
}
}
@Override
@Override
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment