Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
zhangshaowu
/
pipi-helper
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 1ddc9a15
authored
Oct 15, 2022
by
zhaolianjie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
加入redisUtil
1 parent
610e1206
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
1 deletions
src/main/java/com/pipihelper/project/feishu/dto/RedisPoolConfig.java
src/main/java/com/pipihelper/project/feishu/service/FeiShuApiService.java
src/main/java/com/pipihelper/project/utils/RedisUtil.java
src/main/java/com/pipihelper/project/feishu/dto/RedisPoolConfig.java
0 → 100644
View file @
1ddc9a1
package
com
.
pipihelper
.
project
.
feishu
.
dto
;
import
com.alibaba.fastjson.support.spring.FastJsonRedisSerializer
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
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.RedisTemplate
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
@Configuration
public
class
RedisPoolConfig
{
@Bean
@ConditionalOnMissingBean
(
name
=
"redisTemplate"
)
public
RedisTemplate
<
String
,
Object
>
redisTemplate
(
RedisConnectionFactory
redisConnectionFactory
)
{
RedisTemplate
<
String
,
Object
>
template
=
new
RedisTemplate
<>();
//使用fastjson序列化
FastJsonRedisSerializer
fastJsonRedisSerializer
=
new
FastJsonRedisSerializer
(
Object
.
class
);
// value值的序列化采用fastJsonRedisSerializer
template
.
setValueSerializer
(
fastJsonRedisSerializer
);
template
.
setHashValueSerializer
(
fastJsonRedisSerializer
);
// key的序列化采用StringRedisSerializer
template
.
setKeySerializer
(
new
StringRedisSerializer
());
template
.
setHashKeySerializer
(
new
StringRedisSerializer
());
template
.
setConnectionFactory
(
redisConnectionFactory
);
return
template
;
}
@Bean
@ConditionalOnMissingBean
(
StringRedisTemplate
.
class
)
public
StringRedisTemplate
stringRedisTemplate
(
RedisConnectionFactory
redisConnectionFactory
)
{
StringRedisTemplate
template
=
new
StringRedisTemplate
();
template
.
setConnectionFactory
(
redisConnectionFactory
);
return
template
;
}
}
src/main/java/com/pipihelper/project/feishu/service/FeiShuApiService.java
View file @
1ddc9a1
...
@@ -17,6 +17,7 @@ import com.pipihelper.project.feishu.dto.doc.FieldsDTO;
...
@@ -17,6 +17,7 @@ import com.pipihelper.project.feishu.dto.doc.FieldsDTO;
import
com.pipihelper.project.feishu.dto.employee.FeiShuEmployeeDTO
;
import
com.pipihelper.project.feishu.dto.employee.FeiShuEmployeeDTO
;
import
com.pipihelper.project.feishu.dto.msg.FeiShuBatchMsgDTO
;
import
com.pipihelper.project.feishu.dto.msg.FeiShuBatchMsgDTO
;
import
com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO
;
import
com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO
;
import
com.pipihelper.project.utils.RedisUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
okhttp3.MediaType
;
import
okhttp3.MediaType
;
import
okhttp3.OkHttpClient
;
import
okhttp3.OkHttpClient
;
...
@@ -24,6 +25,7 @@ import okhttp3.Request;
...
@@ -24,6 +25,7 @@ import okhttp3.Request;
import
okhttp3.RequestBody
;
import
okhttp3.RequestBody
;
import
okhttp3.Response
;
import
okhttp3.Response
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpMethod
;
...
@@ -52,7 +54,8 @@ import java.util.List;
...
@@ -52,7 +54,8 @@ import java.util.List;
public
class
FeiShuApiService
{
public
class
FeiShuApiService
{
@Resource
@Resource
private
FeiShuConfig
feiShuConfig
;
private
FeiShuConfig
feiShuConfig
;
@Autowired
private
RedisUtil
redisUtil
;
private
static
ObjectMapper
objectMapper
=
new
ObjectMapper
();
private
static
ObjectMapper
objectMapper
=
new
ObjectMapper
();
...
...
src/main/java/com/pipihelper/project/utils/RedisUtil.java
0 → 100644
View file @
1ddc9a1
package
com
.
pipihelper
.
project
.
utils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Component
;
@Component
public
class
RedisUtil
{
@Autowired
private
RedisTemplate
<
String
,
Object
>
redisTemplate
;
public
Object
get
(
String
key
)
{
return
key
==
null
?
null
:
redisTemplate
.
opsForValue
().
get
(
key
);
}
public
boolean
set
(
String
key
,
Object
value
)
{
try
{
redisTemplate
.
opsForValue
().
set
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
}
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