Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
asset-distribution
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data-spider
asset-distribution
Commits
07de323a
Commit
07de323a
authored
Aug 31, 2021
by
shihuajun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
规则service
parent
bb1154cc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
0 deletions
+108
-0
IProductRuleService.java
...ribution/service/newrule/service/IProductRuleService.java
+25
-0
ProductRuleServiceImpl.java
...ution/service/newrule/service/ProductRuleServiceImpl.java
+83
-0
No files found.
src/main/java/com/quantgroup/asset/distribution/service/newrule/service/IProductRuleService.java
0 → 100644
View file @
07de323a
package
com
.
quantgroup
.
asset
.
distribution
.
service
.
newrule
.
service
;
import
com.quantgroup.asset.distribution.service.jpa.entity.ProductRuleEntity
;
import
java.util.List
;
/**
* @author shihuajun
* @date 2021/8/28 10:53
* @ describing
*/
public
interface
IProductRuleService
{
/**
* 获取产品规则配置
* @param ruleMame
* @return
*/
ProductRuleEntity
getProductRuleEntityByRuleMame
(
String
ruleMame
);
ProductRuleEntity
getProductRuleEntityById
(
Long
id
);
List
<
ProductRuleEntity
>
getAll
();
}
src/main/java/com/quantgroup/asset/distribution/service/newrule/service/ProductRuleServiceImpl.java
0 → 100644
View file @
07de323a
package
com
.
quantgroup
.
asset
.
distribution
.
service
.
newrule
.
service
;
import
com.google.common.base.Stopwatch
;
import
com.google.common.collect.Lists
;
import
com.quantgroup.asset.distribution.service.jpa.entity.ProductRuleEntity
;
import
com.quantgroup.asset.distribution.service.jpa.repository.IProductRuleRepository
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.locks.Lock
;
import
java.util.concurrent.locks.ReentrantReadWriteLock
;
/**
* @author shihuajun
* @date 2021/8/28 10:53
* @ describing 读写锁全量缓存
*/
@Slf4j
@Service
public
class
ProductRuleServiceImpl
implements
IProductRuleService
{
@Resource
private
IProductRuleRepository
productRuleRepository
;
private
static
List
<
ProductRuleEntity
>
CACHE
=
Lists
.
newArrayList
();
private
static
ReentrantReadWriteLock
RW
=
new
ReentrantReadWriteLock
();
private
static
Lock
R
=
RW
.
readLock
();
@PostConstruct
public
void
loadProductRule
(){
CACHE
=
productRuleRepository
.
findAll
();
log
.
info
(
"产品规则加载完毕,数量是 {}"
,
CACHE
.
size
());
}
@Override
public
ProductRuleEntity
getProductRuleEntityByRuleMame
(
String
ruleMame
)
{
Stopwatch
stopwatch
=
Stopwatch
.
createStarted
();
if
(
StringUtils
.
isBlank
(
ruleMame
)){
throw
new
RuntimeException
(
"获取产品配置参数错误"
);
}
ProductRuleEntity
productRuleEntity
=
null
;
R
.
lock
();
try
{
productRuleEntity
=
CACHE
.
stream
().
filter
(
p
->
p
.
getRuleName
().
equals
(
ruleMame
)).
findFirst
().
get
();
}
catch
(
Exception
e
){
log
.
error
(
"产品配置执行有点问题"
,
e
);
}
finally
{
R
.
unlock
();
}
log
.
info
(
"获取产品配置耗时 {},返回值为空?{}"
,
stopwatch
.
elapsed
(
TimeUnit
.
MILLISECONDS
),
productRuleEntity
==
null
);
return
productRuleEntity
;
}
@Override
public
ProductRuleEntity
getProductRuleEntityById
(
Long
id
)
{
Stopwatch
stopwatch
=
Stopwatch
.
createStarted
();
if
(
id
==
null
){
throw
new
RuntimeException
(
"获取产品配置参数错误"
);
}
ProductRuleEntity
productRuleEntity
=
null
;
R
.
lock
();
try
{
productRuleEntity
=
CACHE
.
stream
().
filter
(
p
->
p
.
getId
()
==
(
id
)).
findFirst
().
get
();
}
catch
(
Exception
e
){
log
.
error
(
"产品配置执行有点问题"
,
e
);
}
finally
{
R
.
unlock
();
}
log
.
info
(
"获取产品配置耗时 {},返回值为空?{}"
,
stopwatch
.
elapsed
(
TimeUnit
.
MILLISECONDS
),
productRuleEntity
==
null
);
return
productRuleEntity
;
}
@Override
public
List
<
ProductRuleEntity
>
getAll
()
{
return
CACHE
;
}
}
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