Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
KnowledgePlanet
road-map
xfg-frame-archetype-lite
提交
e47b895b
xfg-frame-archetype-lite
项目概览
KnowledgePlanet
/
road-map
/
xfg-frame-archetype-lite
通知
1164
Star
58
Fork
71
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
xfg-frame-archetype-lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
e47b895b
编写于
4月 25, 2024
作者:
H
hudingrong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rule_stock
上级
b87fe01f
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
41 addition
and
2 deletion
+41
-2
xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/service/rule/tree/impl/RuleStockLogicTreeNode.java
...rategy/service/rule/tree/impl/RuleStockLogicTreeNode.java
+35
-1
xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/repository/StrategyRepository.java
...rastructure/persistent/repository/StrategyRepository.java
+6
-1
未找到文件。
xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/service/rule/tree/impl/RuleStockLogicTreeNode.java
浏览文件 @
e47b895b
package
cn.bugstack.domain.strategy.service.rule.tree.impl
;
import
cn.bugstack.domain.strategy.model.valobj.RuleLogicCheckTypeVO
;
import
cn.bugstack.domain.strategy.model.valobj.StrategyAwardStockKeyVO
;
import
cn.bugstack.domain.strategy.repository.IStrategyRepository
;
import
cn.bugstack.domain.strategy.service.armory.IStrategyDispatch
;
import
cn.bugstack.domain.strategy.service.rule.tree.ILogicTreeNode
;
import
cn.bugstack.domain.strategy.service.rule.tree.factory.DefaultTreeFactory
;
import
lombok.extern.slf4j.Slf4j
;
import
org.checkerframework.checker.units.qual.C
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
/**
* @description: 库存扣减节点
* @author: hdr
...
...
@@ -16,11 +21,40 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
(
"rule_stock"
)
public
class
RuleStockLogicTreeNode
implements
ILogicTreeNode
{
@Resource
private
IStrategyDispatch
strategyDispatch
;
@Resource
private
IStrategyRepository
strategyRepository
;
@Override
public
DefaultTreeFactory
.
TreeActionEntity
logic
(
String
userId
,
Long
strategyId
,
Integer
awardId
,
String
ruleValue
)
{
log
.
info
(
"规则过滤-库存扣减 userId:{} strategyId:{} awardId:{}"
,
userId
,
strategyId
,
awardId
);
// 扣减库存
Boolean
status
=
strategyDispatch
.
subtractionAwardStock
(
strategyId
,
awardId
);
// true;库存扣减成功,TAKE_OVER 规则节点接管,返回奖品ID,奖品规则配置
if
(
status
)
{
log
.
info
(
"规则过滤-库存扣减-成功 userId:{} strategyId:{} awardId:{}"
,
userId
,
strategyId
,
awardId
);
// 写入延迟队列,延迟消费更新数据库记录。【在trigger的job;UpdateAwardStockJob 下消费队列,更新数据库记录】
strategyRepository
.
awardStockConsumeSendQueue
(
StrategyAwardStockKeyVO
.
builder
()
.
strategyId
(
strategyId
)
.
awardId
(
awardId
)
.
build
());
return
DefaultTreeFactory
.
TreeActionEntity
.
builder
()
.
ruleLogicCheckType
(
RuleLogicCheckTypeVO
.
TAKE_OVER
)
.
strategyAwardVO
(
DefaultTreeFactory
.
StrategyAwardVO
.
builder
()
.
awardId
(
awardId
)
.
awardRuleValue
(
ruleValue
)
.
build
())
.
build
();
}
// 如果库存不足,则直接返回放行
log
.
warn
(
"规则过滤-库存扣减-告警,库存不足。userId:{} strategyId:{} awardId:{}"
,
userId
,
strategyId
,
awardId
);
return
DefaultTreeFactory
.
TreeActionEntity
.
builder
()
.
ruleLogicCheckType
(
RuleLogicCheckTypeVO
.
ALLOW
)
.
build
();
}
}
xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/repository/StrategyRepository.java
浏览文件 @
e47b895b
...
...
@@ -273,9 +273,12 @@ public class StrategyRepository implements IStrategyRepository {
@Override
public
void
awardStockConsumeSendQueue
(
StrategyAwardStockKeyVO
strategyAwardStockKeyVO
)
{
String
cacheKey
=
Constants
.
RedisKey
.
STRATEGY_AWARD_COUNT_QUERY_KEY
;
RBlockingQueue
<
StrategyAwardStockKeyVO
>
blockingQueue
=
redisService
.
getBlockingQueue
(
cacheKey
);
RDelayedQueue
<
StrategyAwardStockKeyVO
>
delayedQueue
=
redisService
.
getDelayedQueue
(
blockingQueue
);
delayedQueue
.
offer
(
strategyAwardStockKeyVO
,
3
,
TimeUnit
.
SECONDS
);
log
.
info
(
"抽到奖品了---------------"
);
}
...
...
@@ -283,7 +286,9 @@ public class StrategyRepository implements IStrategyRepository {
public
StrategyAwardStockKeyVO
takeQueueValue
()
throws
InterruptedException
{
String
cacheKey
=
Constants
.
RedisKey
.
STRATEGY_AWARD_COUNT_QUERY_KEY
;
RBlockingQueue
<
StrategyAwardStockKeyVO
>
destinationQueue
=
redisService
.
getBlockingQueue
(
cacheKey
);
return
destinationQueue
.
poll
();
StrategyAwardStockKeyVO
poll
=
destinationQueue
.
poll
();
log
.
info
(
"队列数据:{}"
,
poll
);
return
poll
;
}
@Override
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录