Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
base-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SuperHive
back-end
base-service
Commits
8664c071
You need to sign in or sign up before continuing.
Commit
8664c071
authored
Jul 30, 2020
by
huangcb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
设置缓存前缀
parent
a375fce5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
10 deletions
+31
-10
CacheConfig.java
...main/java/com/esv/datacenter/base/config/CacheConfig.java
+22
-0
BaseCityCodeServiceImpl.java
...ase/module/city/service/impl/BaseCityCodeServiceImpl.java
+2
-2
DicTypeServiceImpl.java
...ter/base/module/dict/service/impl/DicTypeServiceImpl.java
+3
-4
GoodsTypeServiceImpl.java
...r/base/module/dict/service/impl/GoodsTypeServiceImpl.java
+2
-2
VehicleTypeServiceImpl.java
...base/module/dict/service/impl/VehicleTypeServiceImpl.java
+2
-2
No files found.
src/main/java/com/esv/datacenter/base/config/CacheConfig.java
View file @
8664c071
...
@@ -3,10 +3,12 @@ package com.esv.datacenter.base.config;
...
@@ -3,10 +3,12 @@ package com.esv.datacenter.base.config;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.CacheManager
;
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.cache.CacheKeyPrefix
;
import
org.springframework.data.redis.cache.RedisCacheConfiguration
;
import
org.springframework.data.redis.cache.RedisCacheConfiguration
;
import
org.springframework.data.redis.cache.RedisCacheManager
;
import
org.springframework.data.redis.cache.RedisCacheManager
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
...
@@ -31,6 +33,9 @@ import java.time.Duration;
...
@@ -31,6 +33,9 @@ import java.time.Duration;
@EnableCaching
@EnableCaching
public
class
CacheConfig
{
public
class
CacheConfig
{
@Value
(
"${spring.application.name}"
)
private
String
applicationName
;
/**
/**
* description 为SpringCache注册缓存管理器
* description 为SpringCache注册缓存管理器
* param [redisConnectionFactory]
* param [redisConnectionFactory]
...
@@ -52,6 +57,7 @@ public class CacheConfig {
...
@@ -52,6 +57,7 @@ public class CacheConfig {
// 配置序列化(解决乱码的问题)
// 配置序列化(解决乱码的问题)
RedisCacheConfiguration
config
=
RedisCacheConfiguration
.
defaultCacheConfig
()
RedisCacheConfiguration
config
=
RedisCacheConfiguration
.
defaultCacheConfig
()
.
computePrefixWith
(
cacheKeyPrefix
())
.
entryTtl
(
Duration
.
ofMinutes
(
timeToLive
))
.
entryTtl
(
Duration
.
ofMinutes
(
timeToLive
))
.
serializeKeysWith
(
RedisSerializationContext
.
SerializationPair
.
fromSerializer
(
redisSerializer
))
.
serializeKeysWith
(
RedisSerializationContext
.
SerializationPair
.
fromSerializer
(
redisSerializer
))
.
serializeValuesWith
(
RedisSerializationContext
.
SerializationPair
.
fromSerializer
(
jackson2JsonRedisSerializer
));
.
serializeValuesWith
(
RedisSerializationContext
.
SerializationPair
.
fromSerializer
(
jackson2JsonRedisSerializer
));
...
@@ -62,6 +68,22 @@ public class CacheConfig {
...
@@ -62,6 +68,22 @@ public class CacheConfig {
return
cacheManager
;
return
cacheManager
;
}
}
/**
* @description 设置缓存key的前缀
* @return org.springframework.data.redis.cache.CacheKeyPrefix
* @author huangChaobin@esvtek.com
* @createTime 2020/07/30 19:49
**/
@Bean
public
CacheKeyPrefix
cacheKeyPrefix
()
{
return
cacheName
->
{
StringBuilder
sBuilder
=
new
StringBuilder
(
8
);
sBuilder
.
append
(
applicationName
).
append
(
"::"
);
sBuilder
.
append
(
cacheName
).
append
(
"::"
);
return
sBuilder
.
toString
();
};
}
/**
/**
* RedisTemplate相关配置
* RedisTemplate相关配置
* @param factory
* @param factory
...
...
src/main/java/com/esv/datacenter/base/module/city/service/impl/BaseCityCodeServiceImpl.java
View file @
8664c071
...
@@ -20,7 +20,7 @@ import java.util.Map;
...
@@ -20,7 +20,7 @@ import java.util.Map;
public
class
BaseCityCodeServiceImpl
extends
ServiceImpl
<
BaseCityCodeDao
,
BaseCityCodeEntity
>
implements
BaseCityCodeService
{
public
class
BaseCityCodeServiceImpl
extends
ServiceImpl
<
BaseCityCodeDao
,
BaseCityCodeEntity
>
implements
BaseCityCodeService
{
@Override
@Override
@Cacheable
(
value
=
"
htwl-base-service::
geo::city"
,
key
=
"'allTree'"
)
@Cacheable
(
value
=
"geo::city"
,
key
=
"'allTree'"
)
public
List
<
JSONObject
>
getAllRegionTree
()
{
public
List
<
JSONObject
>
getAllRegionTree
()
{
// 查询全国行政区划列表
// 查询全国行政区划列表
List
<
BaseCityCodeEntity
>
cityCodeEntityList
=
this
.
baseMapper
.
selectList
(
new
LambdaQueryWrapper
<
BaseCityCodeEntity
>()
List
<
BaseCityCodeEntity
>
cityCodeEntityList
=
this
.
baseMapper
.
selectList
(
new
LambdaQueryWrapper
<
BaseCityCodeEntity
>()
...
@@ -85,7 +85,7 @@ public class BaseCityCodeServiceImpl extends ServiceImpl<BaseCityCodeDao, BaseCi
...
@@ -85,7 +85,7 @@ public class BaseCityCodeServiceImpl extends ServiceImpl<BaseCityCodeDao, BaseCi
}
}
@Override
@Override
@Cacheable
(
value
=
"
htwl-base-service::
geo::city"
,
key
=
"'allMap'"
)
@Cacheable
(
value
=
"geo::city"
,
key
=
"'allMap'"
)
public
Map
<
String
,
String
>
getAllRegionMap
()
{
public
Map
<
String
,
String
>
getAllRegionMap
()
{
// 查询全国行政区划列表
// 查询全国行政区划列表
List
<
BaseCityCodeEntity
>
cityCodeEntityList
=
this
.
baseMapper
.
selectList
(
new
LambdaQueryWrapper
<
BaseCityCodeEntity
>()
List
<
BaseCityCodeEntity
>
cityCodeEntityList
=
this
.
baseMapper
.
selectList
(
new
LambdaQueryWrapper
<
BaseCityCodeEntity
>()
...
...
src/main/java/com/esv/datacenter/base/module/dict/service/impl/DicTypeServiceImpl.java
View file @
8664c071
...
@@ -30,11 +30,10 @@ public class DicTypeServiceImpl implements DicTypeService {
...
@@ -30,11 +30,10 @@ public class DicTypeServiceImpl implements DicTypeService {
}
}
@Override
@Override
@Cacheable
(
value
=
"
htwl-base-service::
dict::type"
,
key
=
"#type"
)
@Cacheable
(
value
=
"dict::type"
,
key
=
"#type"
)
public
List
<
DicEntity
>
getDictByType
(
String
type
)
{
public
List
<
DicEntity
>
getDictByType
(
String
type
)
{
QueryWrapper
<
DicEntity
>
queryWrapper
=
new
QueryWrapper
<>();
QueryWrapper
<
DicEntity
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
queryWrapper
.
select
(
"code"
,
"name"
)
.
select
(
"code"
,
"name"
)
.
eq
(
"type"
,
type
)
.
eq
(
"type"
,
type
)
.
orderByAsc
(
"order_num"
);
.
orderByAsc
(
"order_num"
);
...
@@ -42,7 +41,7 @@ public class DicTypeServiceImpl implements DicTypeService {
...
@@ -42,7 +41,7 @@ public class DicTypeServiceImpl implements DicTypeService {
}
}
@Override
@Override
@Cacheable
(
value
=
"
htwl-base-service::
dict::type"
,
key
=
"'allValid'"
)
@Cacheable
(
value
=
"dict::type"
,
key
=
"'allValid'"
)
public
List
<
String
>
getAllValidType
()
{
public
List
<
String
>
getAllValidType
()
{
return
dicDao
.
selectAllValidType
();
return
dicDao
.
selectAllValidType
();
}
}
...
...
src/main/java/com/esv/datacenter/base/module/dict/service/impl/GoodsTypeServiceImpl.java
View file @
8664c071
...
@@ -22,7 +22,7 @@ import java.util.Map;
...
@@ -22,7 +22,7 @@ import java.util.Map;
public
class
GoodsTypeServiceImpl
extends
ServiceImpl
<
GoodsTypeDao
,
GoodsTypeEntity
>
implements
GoodsTypeService
{
public
class
GoodsTypeServiceImpl
extends
ServiceImpl
<
GoodsTypeDao
,
GoodsTypeEntity
>
implements
GoodsTypeService
{
@Override
@Override
@Cacheable
(
value
=
"
htwl-base-service::
goods-type"
,
key
=
"'allValid'"
)
@Cacheable
(
value
=
"goods-type"
,
key
=
"'allValid'"
)
public
List
<
TreeVO
>
getAllGoodsType
()
{
public
List
<
TreeVO
>
getAllGoodsType
()
{
// 查询
// 查询
QueryWrapper
<
GoodsTypeEntity
>
queryWrapper
=
new
QueryWrapper
<>();
QueryWrapper
<
GoodsTypeEntity
>
queryWrapper
=
new
QueryWrapper
<>();
...
@@ -66,7 +66,7 @@ public class GoodsTypeServiceImpl extends ServiceImpl<GoodsTypeDao, GoodsTypeEnt
...
@@ -66,7 +66,7 @@ public class GoodsTypeServiceImpl extends ServiceImpl<GoodsTypeDao, GoodsTypeEnt
}
}
@Override
@Override
@Cacheable
(
value
=
"
htwl-base-service::
goods-type"
,
key
=
"#code"
)
@Cacheable
(
value
=
"goods-type"
,
key
=
"#code"
)
public
String
getGoodsNameByCode
(
Integer
code
)
{
public
String
getGoodsNameByCode
(
Integer
code
)
{
GoodsTypeEntity
entity
=
new
GoodsTypeEntity
();
GoodsTypeEntity
entity
=
new
GoodsTypeEntity
();
entity
.
setCode
(
code
);
entity
.
setCode
(
code
);
...
...
src/main/java/com/esv/datacenter/base/module/dict/service/impl/VehicleTypeServiceImpl.java
View file @
8664c071
...
@@ -22,7 +22,7 @@ import java.util.Map;
...
@@ -22,7 +22,7 @@ import java.util.Map;
public
class
VehicleTypeServiceImpl
extends
ServiceImpl
<
VehicleTypeDao
,
VehicleTypeEntity
>
implements
VehicleTypeService
{
public
class
VehicleTypeServiceImpl
extends
ServiceImpl
<
VehicleTypeDao
,
VehicleTypeEntity
>
implements
VehicleTypeService
{
@Override
@Override
@Cacheable
(
value
=
"
htwl-base-service::
vehicle-type"
,
key
=
"'allValid'"
)
@Cacheable
(
value
=
"vehicle-type"
,
key
=
"'allValid'"
)
public
List
<
TreeVO
>
getAllVehicleType
()
{
public
List
<
TreeVO
>
getAllVehicleType
()
{
// 查询
// 查询
QueryWrapper
<
VehicleTypeEntity
>
queryWrapper
=
new
QueryWrapper
<>();
QueryWrapper
<
VehicleTypeEntity
>
queryWrapper
=
new
QueryWrapper
<>();
...
@@ -66,7 +66,7 @@ public class VehicleTypeServiceImpl extends ServiceImpl<VehicleTypeDao, VehicleT
...
@@ -66,7 +66,7 @@ public class VehicleTypeServiceImpl extends ServiceImpl<VehicleTypeDao, VehicleT
}
}
@Override
@Override
@Cacheable
(
value
=
"
htwl-base-service::
vehicle-type"
,
key
=
"#code"
)
@Cacheable
(
value
=
"vehicle-type"
,
key
=
"#code"
)
public
String
getVehicleNameByCode
(
Integer
code
)
{
public
String
getVehicleNameByCode
(
Integer
code
)
{
VehicleTypeEntity
entity
=
new
VehicleTypeEntity
();
VehicleTypeEntity
entity
=
new
VehicleTypeEntity
();
entity
.
setCode
(
code
);
entity
.
setCode
(
code
);
...
...
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