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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
21 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 {
...
@@ -32,7 +32,7 @@ public class WebConfig implements WebMvcConfigurer {
@Override
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
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
@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;
...
@@ -34,6 +34,8 @@ import java.util.stream.Collectors;
@Component
@Component
@Slf4j
@Slf4j
public
class
StorageUtils
{
public
class
StorageUtils
{
private
static
RLocalCachedMap
<
Long
,
Storage
>
storageMap
=
null
;
private
static
RLocalCachedMap
<
Long
,
Pack
>
packMap
=
null
;
@Resource
@Resource
private
PackService
packService
;
private
PackService
packService
;
@Resource
@Resource
...
@@ -42,13 +44,11 @@ public class StorageUtils {
...
@@ -42,13 +44,11 @@ public class StorageUtils {
private
PicService
picService
;
private
PicService
picService
;
@Resource
@Resource
private
ObjectMapper
objectMapper
;
private
ObjectMapper
objectMapper
;
@Resource
@Resource
private
RedissonService
redissonService
;
private
RedissonService
redissonService
;
@Resource
@Resource
private
RedissonClient
redissonClient
;
private
RedissonClient
redissonClient
;
public
PicVo
getPic
(
Long
picId
)
{
public
PicVo
getPic
(
Long
picId
)
{
String
redisKey
=
Constants
.
getRedisKeyPic
(
picId
);
String
redisKey
=
Constants
.
getRedisKeyPic
(
picId
);
RBucket
<
PicVo
>
picInfoBucket
=
redissonClient
.
getBucket
(
redisKey
);
RBucket
<
PicVo
>
picInfoBucket
=
redissonClient
.
getBucket
(
redisKey
);
...
@@ -74,21 +74,20 @@ public class StorageUtils {
...
@@ -74,21 +74,20 @@ public class StorageUtils {
// 获取并缓存 image
// 获取并缓存 image
Long
packId
=
picVo
.
getPackId
();
Long
packId
=
picVo
.
getPackId
();
String
picImageKey
=
Constants
.
getRedisKeyPicImage
(
picId
);
// String picImageKey = Constants.getRedisKeyPicImage(picId);
RBucket
<
byte
[]>
picImageBucket
=
redissonClient
.
getBucket
(
picImageKey
);
// RBucket<byte[]> picImageBucket = redissonClient.getBucket(picImageKey);
byte
[]
bytes
=
picImageBucket
.
get
();
// byte[] bytes = picImageBucket.get();
if
(
bytes
==
null
)
{
// if (bytes == null) {
try
{
try
{
bytes
=
getFile
(
packId
,
picVo
.
getName
());
byte
[]
bytes
=
getFile
(
packId
,
picVo
.
getName
());
}
catch
(
Exception
e
)
{
picVo
.
setImage
(
bytes
);
log
.
info
(
""
,
e
);
}
catch
(
Exception
e
)
{
return
null
;
log
.
info
(
""
,
e
);
}
return
null
;
picImageBucket
.
set
(
bytes
);
}
}
picImageBucket
.
expire
(
4
,
TimeUnit
.
HOURS
);
// picImageBucket.set(bytes
);
picVo
.
setImage
(
bytes
);
// }
// picImageBucket.expire(4, TimeUnit.HOURS);
return
picVo
;
return
picVo
;
}
}
...
@@ -159,7 +158,9 @@ public class StorageUtils {
...
@@ -159,7 +158,9 @@ public class StorageUtils {
public
Storage
getStorage
(
Long
storageId
)
{
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
())
{
if
(!
storageMap
.
isExists
())
{
refreshStorage
();
refreshStorage
();
}
}
...
@@ -176,7 +177,9 @@ public class StorageUtils {
...
@@ -176,7 +177,9 @@ public class StorageUtils {
}
}
public
Pack
getPack
(
Long
packId
)
{
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
())
{
if
(!
packMap
.
isExists
())
{
refreshPack
();
refreshPack
();
}
}
...
@@ -193,7 +196,6 @@ public class StorageUtils {
...
@@ -193,7 +196,6 @@ public class StorageUtils {
public
synchronized
void
refreshStorage
()
{
public
synchronized
void
refreshStorage
()
{
redissonService
.
lockAndRun
(
"lock:"
+
Constants
.
REDIS_KEY_STORAGE_MAP
,
10L
,
8L
,
()
->
{
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
());
List
<
Storage
>
storages
=
storageService
.
selectByExample
(
new
StorageExample
());
Map
<
Long
,
Storage
>
map
=
storages
.
stream
().
collect
(
Collectors
.
toMap
(
Storage:
:
getId
,
x
->
x
,
(
a
,
b
)
->
a
));
Map
<
Long
,
Storage
>
map
=
storages
.
stream
().
collect
(
Collectors
.
toMap
(
Storage:
:
getId
,
x
->
x
,
(
a
,
b
)
->
a
));
storageMap
.
putAll
(
map
);
storageMap
.
putAll
(
map
);
...
@@ -202,7 +204,6 @@ public class StorageUtils {
...
@@ -202,7 +204,6 @@ public class StorageUtils {
public
synchronized
void
refreshPack
()
{
public
synchronized
void
refreshPack
()
{
redissonService
.
lockAndRun
(
"lock:"
+
Constants
.
REDIS_KEY_PACK_MAP
,
10L
,
8L
,
()
->
{
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
());
List
<
Pack
>
packs
=
packService
.
selectByExample
(
new
PackExample
());
Map
<
Long
,
Pack
>
map
=
packs
.
stream
().
collect
(
Collectors
.
toMap
(
Pack:
:
getId
,
x
->
x
,
(
a
,
b
)
->
a
));
Map
<
Long
,
Pack
>
map
=
packs
.
stream
().
collect
(
Collectors
.
toMap
(
Pack:
:
getId
,
x
->
x
,
(
a
,
b
)
->
a
));
packMap
.
putAll
(
map
);
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