Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-store
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
base_platform_enterprise
gic-store
Commits
024b3d6a
Commit
024b3d6a
authored
Jun 05, 2020
by
陶光胜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
门店控件增加接口
parent
960a7ac6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
15 deletions
+40
-15
ProvincesApiServiceImpl.java
...gic/store/service/outer/impl/ProvincesApiServiceImpl.java
+40
-15
No files found.
gic-store-service/src/main/java/com/gic/store/service/outer/impl/ProvincesApiServiceImpl.java
View file @
024b3d6a
...
...
@@ -14,6 +14,9 @@ import com.gic.store.entity.TabProvince;
import
com.gic.store.service.ProvincesApiService
;
import
com.gic.store.service.ProvincesService
;
import
com.gic.store.service.StoreService
;
import
com.google.common.cache.CacheBuilder
;
import
com.google.common.cache.CacheLoader
;
import
com.google.common.cache.LoadingCache
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.logging.log4j.LogManager
;
...
...
@@ -21,6 +24,7 @@ import org.apache.logging.log4j.Logger;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.PostConstruct
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
...
...
@@ -31,30 +35,55 @@ import java.util.stream.Collectors;
@Service
(
"provincesApiService"
)
public
class
ProvincesApiServiceImpl
implements
ProvincesApiService
{
private
static
final
Logger
log
=
LogManager
.
getLogger
(
ProvincesApiServiceImpl
.
class
);
private
LoadingCache
<
String
,
List
<
ProvinceDTO
>>
provinceCache
=
null
;
private
LoadingCache
<
String
,
List
<
CityDTO
>>
cityCache
=
null
;
private
LoadingCache
<
String
,
List
<
CountyDTO
>>
countyCache
=
null
;
private
static
final
int
EXPIRE_SECONDS
=
7
;
@Autowired
private
ProvincesService
provincesService
;
@Autowired
private
StoreService
storeService
;
@PostConstruct
public
void
init
(){
provinceCache
=
CacheBuilder
.
newBuilder
().
maximumSize
(
10
).
expireAfterAccess
(
EXPIRE_SECONDS
,
TimeUnit
.
DAYS
)
.
build
(
new
CacheLoader
<
String
,
List
<
ProvinceDTO
>>()
{
@Override
public
List
<
ProvinceDTO
>
load
(
String
key
)
{
return
EntityUtil
.
changeEntityListByJSON
(
ProvinceDTO
.
class
,
provincesService
.
selectAllProvince
());
}
});
cityCache
=
CacheBuilder
.
newBuilder
().
maximumSize
(
10
).
expireAfterAccess
(
EXPIRE_SECONDS
,
TimeUnit
.
DAYS
)
.
build
(
new
CacheLoader
<
String
,
List
<
CityDTO
>>()
{
@Override
public
List
<
CityDTO
>
load
(
String
key
)
{
return
EntityUtil
.
changeEntityListByJSON
(
CityDTO
.
class
,
provincesService
.
selectAllCity
());
}
});
countyCache
=
CacheBuilder
.
newBuilder
().
maximumSize
(
10
).
expireAfterAccess
(
EXPIRE_SECONDS
,
TimeUnit
.
DAYS
)
.
build
(
new
CacheLoader
<
String
,
List
<
CountyDTO
>>()
{
@Override
public
List
<
CountyDTO
>
load
(
String
key
)
{
return
EntityUtil
.
changeEntityListByJSON
(
CountyDTO
.
class
,
provincesService
.
selectAllCounty
());
}
});
}
@Override
public
ServiceResponse
<
List
<
ProvinceDTO
>>
selectAllProvince
()
{
String
key
=
"enterprise:province"
;
List
<
ProvinceDTO
>
list
=
(
List
<
ProvinceDTO
>)
RedisUtil
.
getCache
(
key
);
if
(
CollectionUtils
.
isEmpty
(
list
)){
list
=
EntityUtil
.
changeEntityListByJSON
(
ProvinceDTO
.
class
,
this
.
provincesService
.
selectAllProvince
());
RedisUtil
.
setCache
(
key
,
list
,
6
*
30
l
,
TimeUnit
.
DAYS
);
}
List
<
ProvinceDTO
>
list
=
provinceCache
.
getUnchecked
(
key
);
return
ServiceResponse
.
success
(
list
);
}
@Override
public
ServiceResponse
<
List
<
CityDTO
>>
selectAllCity
()
{
String
key
=
"enterprise:city"
;
List
<
CityDTO
>
list
=
(
List
<
CityDTO
>)
RedisUtil
.
getCache
(
key
);
if
(
CollectionUtils
.
isEmpty
(
list
)){
list
=
EntityUtil
.
changeEntityListByJSON
(
CityDTO
.
class
,
this
.
provincesService
.
selectAllCity
());
RedisUtil
.
setCache
(
key
,
list
,
6
*
30
l
,
TimeUnit
.
DAYS
);
}
List
<
CityDTO
>
list
=
cityCache
.
getUnchecked
(
key
);
log
.
info
(
"allcity:{}"
,
list
.
size
());
return
ServiceResponse
.
success
(
list
);
}
...
...
@@ -95,11 +124,7 @@ public class ProvincesApiServiceImpl implements ProvincesApiService {
@Override
public
ServiceResponse
<
List
<
CountyDTO
>>
selectAllCounty
()
{
String
key
=
"enterprise:county"
;
List
<
CountyDTO
>
list
=
(
List
<
CountyDTO
>)
RedisUtil
.
getCache
(
key
);
if
(
CollectionUtils
.
isEmpty
(
list
)){
list
=
EntityUtil
.
changeEntityListByJSON
(
CountyDTO
.
class
,
this
.
provincesService
.
selectAllCounty
());
RedisUtil
.
setCache
(
key
,
list
,
6
*
30
l
,
TimeUnit
.
DAYS
);
}
List
<
CountyDTO
>
list
=
countyCache
.
getUnchecked
(
key
);
return
ServiceResponse
.
success
(
list
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment