Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
谢明辉
/
vion-label
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 8eea4adc
authored
Dec 15, 2021
by
xmh
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
更改 RLocalCacheMap 使用方式
排除图片访问时的鉴权
1 parent
91096350
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
17 deletions
label-platform/src/main/java/com/viontech/label/platform/config/WebConfig.java
label-platform/src/main/java/com/viontech/label/platform/utils/StorageUtils.java
label-platform/src/main/java/com/viontech/label/platform/config/WebConfig.java
View file @
8eea4ad
...
...
@@ -32,7 +32,7 @@ public class WebConfig implements WebMvcConfigurer {
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
registry
.
addInterceptor
(
authInterceptor
).
addPathPatterns
(
"/**"
).
excludePathPatterns
(
"/users/login"
,
"/reid/upload"
,
"/**/websocket/**"
,
"/users/logout"
);
registry
.
addInterceptor
(
authInterceptor
).
addPathPatterns
(
"/**"
).
excludePathPatterns
(
"/users/login"
,
"/reid/upload"
,
"/**/websocket/**"
,
"/users/logout"
,
"pics/image/**"
);
}
@Bean
...
...
label-platform/src/main/java/com/viontech/label/platform/utils/StorageUtils.java
View file @
8eea4ad
...
...
@@ -34,6 +34,8 @@ import java.util.stream.Collectors;
@Component
@Slf4j
public
class
StorageUtils
{
private
static
RLocalCachedMap
<
Long
,
Storage
>
storageMap
=
null
;
private
static
RLocalCachedMap
<
Long
,
Pack
>
packMap
=
null
;
@Resource
private
PackService
packService
;
@Resource
...
...
@@ -42,13 +44,11 @@ public class StorageUtils {
private
PicService
picService
;
@Resource
private
ObjectMapper
objectMapper
;
@Resource
private
RedissonService
redissonService
;
@Resource
private
RedissonClient
redissonClient
;
public
PicVo
getPic
(
Long
picId
)
{
String
redisKey
=
Constants
.
getRedisKeyPic
(
picId
);
RBucket
<
PicVo
>
picInfoBucket
=
redissonClient
.
getBucket
(
redisKey
);
...
...
@@ -74,21 +74,20 @@ public class StorageUtils {
// 获取并缓存 image
Long
packId
=
picVo
.
getPackId
();
String
picImageKey
=
Constants
.
getRedisKeyPicImage
(
picId
);
RBucket
<
byte
[]>
picImageBucket
=
redissonClient
.
getBucket
(
picImageKey
);
byte
[]
bytes
=
picImageBucket
.
get
();
if
(
bytes
==
null
)
{
//
String picImageKey = Constants.getRedisKeyPicImage(picId);
//
RBucket<byte[]> picImageBucket = redissonClient.getBucket(picImageKey);
//
byte[] bytes = picImageBucket.get();
//
if (bytes == null) {
try
{
bytes
=
getFile
(
packId
,
picVo
.
getName
());
byte
[]
bytes
=
getFile
(
packId
,
picVo
.
getName
());
picVo
.
setImage
(
bytes
);
}
catch
(
Exception
e
)
{
log
.
info
(
""
,
e
);
return
null
;
}
picImageBucket
.
set
(
bytes
);
}
picImageBucket
.
expire
(
4
,
TimeUnit
.
HOURS
);
picVo
.
setImage
(
bytes
);
// picImageBucket.set(bytes);
// }
// picImageBucket.expire(4, TimeUnit.HOURS);
return
picVo
;
}
...
...
@@ -159,7 +158,9 @@ public class StorageUtils {
public
Storage
getStorage
(
Long
storageId
)
{
RLocalCachedMap
<
Long
,
Storage
>
storageMap
=
redissonClient
.
getLocalCachedMap
(
Constants
.
REDIS_KEY_STORAGE_MAP
,
LocalCachedMapOptions
.
defaults
());
if
(
storageMap
==
null
)
{
storageMap
=
redissonClient
.
getLocalCachedMap
(
Constants
.
REDIS_KEY_STORAGE_MAP
,
LocalCachedMapOptions
.
defaults
());
}
if
(!
storageMap
.
isExists
())
{
refreshStorage
();
}
...
...
@@ -176,7 +177,9 @@ public class StorageUtils {
}
public
Pack
getPack
(
Long
packId
)
{
RLocalCachedMap
<
Long
,
Pack
>
packMap
=
redissonClient
.
getLocalCachedMap
(
Constants
.
REDIS_KEY_PACK_MAP
,
LocalCachedMapOptions
.
defaults
());
if
(
packMap
==
null
)
{
packMap
=
redissonClient
.
getLocalCachedMap
(
Constants
.
REDIS_KEY_PACK_MAP
,
LocalCachedMapOptions
.
defaults
());
}
if
(!
packMap
.
isExists
())
{
refreshPack
();
}
...
...
@@ -193,7 +196,6 @@ public class StorageUtils {
public
synchronized
void
refreshStorage
()
{
redissonService
.
lockAndRun
(
"lock:"
+
Constants
.
REDIS_KEY_STORAGE_MAP
,
10L
,
8L
,
()
->
{
RLocalCachedMap
<
Long
,
Storage
>
storageMap
=
redissonClient
.
getLocalCachedMap
(
Constants
.
REDIS_KEY_STORAGE_MAP
,
LocalCachedMapOptions
.
defaults
());
List
<
Storage
>
storages
=
storageService
.
selectByExample
(
new
StorageExample
());
Map
<
Long
,
Storage
>
map
=
storages
.
stream
().
collect
(
Collectors
.
toMap
(
Storage:
:
getId
,
x
->
x
,
(
a
,
b
)
->
a
));
storageMap
.
putAll
(
map
);
...
...
@@ -202,7 +204,6 @@ public class StorageUtils {
public
synchronized
void
refreshPack
()
{
redissonService
.
lockAndRun
(
"lock:"
+
Constants
.
REDIS_KEY_PACK_MAP
,
10L
,
8L
,
()
->
{
RLocalCachedMap
<
Long
,
Pack
>
packMap
=
redissonClient
.
getLocalCachedMap
(
Constants
.
REDIS_KEY_PACK_MAP
,
LocalCachedMapOptions
.
defaults
());
List
<
Pack
>
packs
=
packService
.
selectByExample
(
new
PackExample
());
Map
<
Long
,
Pack
>
map
=
packs
.
stream
().
collect
(
Collectors
.
toMap
(
Pack:
:
getId
,
x
->
x
,
(
a
,
b
)
->
a
));
packMap
.
putAll
(
map
);
...
...
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