Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
KnowledgePlanet
road-map
xfg-frame-archetype-lite
提交
123912c3
xfg-frame-archetype-lite
项目概览
KnowledgePlanet
/
road-map
/
xfg-frame-archetype-lite
通知
1355
Star
69
Fork
81
代码
文件
提交
分支
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看板
提交
123912c3
编写于
4月 26, 2024
作者:
H
hudingrong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rule_controller
上级
e47b895b
变更
23
隐藏空白更改
内联
并排
Showing
23 changed file
with
524 addition
and
11 deletion
+524
-11
pom.xml
pom.xml
+1
-0
xfg-frame-archetype-lite-app/src/main/resources/application-dev.yml
...archetype-lite-app/src/main/resources/application-dev.yml
+8
-0
xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/strategy_award_mapper.xml
...c/main/resources/mybatis/mapper/strategy_award_mapper.xml
+6
-1
xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/model/entity/RaffleAwardEntity.java
...stack/domain/strategy/model/entity/RaffleAwardEntity.java
+5
-0
xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/model/entity/StrategyAwardEntity.java
...ack/domain/strategy/model/entity/StrategyAwardEntity.java
+15
-0
xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/repository/IStrategyRepository.java
...stack/domain/strategy/repository/IStrategyRepository.java
+9
-0
xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/service/AbstractRaffleStrategy.java
...stack/domain/strategy/service/AbstractRaffleStrategy.java
+11
-6
xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/service/IRaffleAward.java
...ava/cn/bugstack/domain/strategy/service/IRaffleAward.java
+21
-0
xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/service/raffle/DefaultRaffleStrategy.java
...domain/strategy/service/raffle/DefaultRaffleStrategy.java
+11
-1
xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/service/rule/tree/factory/engine/impl/DecisionTreeEngine.java
...ice/rule/tree/factory/engine/impl/DecisionTreeEngine.java
+1
-1
xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/dao/IStrategyAwardDao.java
...tack/infrastructure/persistent/dao/IStrategyAwardDao.java
+7
-0
xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/repository/StrategyRepository.java
...rastructure/persistent/repository/StrategyRepository.java
+40
-1
xfg-frame-archetype-lite-trigger/pom.xml
xfg-frame-archetype-lite-trigger/pom.xml
+6
-0
xfg-frame-archetype-lite-trigger/src/main/java/cn/bugstack/trigger/http/RaffleController.java
.../main/java/cn/bugstack/trigger/http/RaffleController.java
+158
-0
xfg-frame-archetype-lite-types/pom.xml
xfg-frame-archetype-lite-types/pom.xml
+17
-0
xfg-frame-archetype-lite-types/src/main/java/cn/bugstack/types/enums/ResponseCode.java
...s/src/main/java/cn/bugstack/types/enums/ResponseCode.java
+2
-1
xfg-frame-archetype-lite-types/src/main/java/cn/bugstack/types/model/Response.java
...types/src/main/java/cn/bugstack/types/model/Response.java
+25
-0
xfg-frame-market-api/pom.xml
xfg-frame-market-api/pom.xml
+35
-0
xfg-frame-market-api/src/main/java/cn/bugstack/trigger/api/IRaffleService.java
...src/main/java/cn/bugstack/trigger/api/IRaffleService.java
+43
-0
xfg-frame-market-api/src/main/java/cn/bugstack/trigger/api/dto/RaffleAwardListRequestDTO.java
...n/bugstack/trigger/api/dto/RaffleAwardListRequestDTO.java
+18
-0
xfg-frame-market-api/src/main/java/cn/bugstack/trigger/api/dto/RaffleAwardListResponseDTO.java
.../bugstack/trigger/api/dto/RaffleAwardListResponseDTO.java
+39
-0
xfg-frame-market-api/src/main/java/cn/bugstack/trigger/api/dto/RaffleRequestDTO.java
...in/java/cn/bugstack/trigger/api/dto/RaffleRequestDTO.java
+18
-0
xfg-frame-market-api/src/main/java/cn/bugstack/trigger/api/dto/RaffleResponseDTO.java
...n/java/cn/bugstack/trigger/api/dto/RaffleResponseDTO.java
+28
-0
未找到文件。
pom.xml
浏览文件 @
123912c3
...
...
@@ -13,6 +13,7 @@
<module>
xfg-frame-archetype-lite-trigger
</module>
<module>
xfg-frame-archetype-lite-infrastructure
</module>
<module>
xfg-frame-archetype-lite-types
</module>
<module>
xfg-frame-market-api
</module>
</modules>
<properties>
...
...
xfg-frame-archetype-lite-app/src/main/resources/application-dev.yml
浏览文件 @
123912c3
...
...
@@ -12,6 +12,14 @@ thread:
block-queue-size
:
5000
policy
:
CallerRunsPolicy
app
:
config
:
# 版本,方便通过接口版本升级
api-version
:
v1
# 跨域,开发阶段可以设置为 * 不限制
cross-origin
:
'
*'
# 数据库配置;启动时配置数据库资源信息
spring
:
datasource
:
...
...
xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/strategy_award_mapper.xml
浏览文件 @
123912c3
...
...
@@ -29,7 +29,7 @@
</select>
<select
id=
"queryStrategyAwardListByStrategyId"
resultMap=
"dataMap"
>
select strategy_id, award_id, award_
count, award_count_surplus,award_rate
select strategy_id, award_id, award_
title, award_subtitle, award_count, award_count_surplus, award_rate, sort
from strategy_award
where strategy_id = #{strategyId}
</select>
...
...
@@ -37,5 +37,10 @@
select rule_models from strategy_award
where strategy_id = #{strategyId} and award_id = #{awardId}
</select>
<select
id=
"queryStrategyAward"
resultType=
"cn.bugstack.infrastructure.persistent.po.StrategyAward"
>
select strategy_id, award_id, award_title, award_subtitle, award_count, award_count_surplus, award_rate, rule_models, sort
from strategy_award
where strategy_id = #{strategyId} and award_id = #{awardId}
</select>
</mapper>
xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/model/entity/RaffleAwardEntity.java
浏览文件 @
123912c3
...
...
@@ -41,4 +41,9 @@ public class RaffleAwardEntity {
* 奖品内容描述
*/
private
String
awardDesc
;
/**
* 抽奖顺序号
*/
private
Integer
sort
;
}
xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/model/entity/StrategyAwardEntity.java
浏览文件 @
123912c3
...
...
@@ -29,4 +29,19 @@ public class StrategyAwardEntity implements Serializable {
private
Integer
awardCountSurplus
;
/** 奖品中奖概率 */
private
BigDecimal
awardRate
;
/**
* 抽奖奖品标题
*/
private
String
awardTitle
;
/**
* 抽奖奖品副标题
*/
private
String
awardSubtitle
;
/**
* 排序
*/
private
Integer
sort
;
}
xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/repository/IStrategyRepository.java
浏览文件 @
123912c3
...
...
@@ -137,4 +137,13 @@ public interface IStrategyRepository {
* @param awardId 奖品ID
*/
void
updateStrategyAwardStock
(
Long
strategyId
,
Integer
awardId
);
/**
* 根据策略ID+奖品ID的唯一值组合,查询奖品信息
*
* @param strategyId 策略ID
* @param awardId 奖品ID
* @return 奖品信息
*/
StrategyAwardEntity
queryStrategyAwardEntity
(
Long
strategyId
,
Integer
awardId
);
}
xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/service/AbstractRaffleStrategy.java
浏览文件 @
123912c3
...
...
@@ -2,6 +2,7 @@ package cn.bugstack.domain.strategy.service;
import
cn.bugstack.domain.strategy.model.entity.RaffleAwardEntity
;
import
cn.bugstack.domain.strategy.model.entity.RaffleFactorEntity
;
import
cn.bugstack.domain.strategy.model.entity.StrategyAwardEntity
;
import
cn.bugstack.domain.strategy.repository.IStrategyRepository
;
import
cn.bugstack.domain.strategy.service.IRaffleStrategy
;
import
cn.bugstack.domain.strategy.service.armory.IStrategyDispatch
;
...
...
@@ -19,7 +20,7 @@ import org.apache.commons.lang3.StringUtils;
* @DATE: 2024/4/23
*/
@Slf4j
public
abstract
class
AbstractRaffleStrategy
implements
IRaffleStrategy
,
IRaffleStock
{
public
abstract
class
AbstractRaffleStrategy
implements
IRaffleStrategy
{
// 策略仓储服务 -> domain层像一个大厨,仓储层提供米面粮油
protected
IStrategyRepository
repository
;
// 策略调度服务 -> 只负责抽奖处理,通过新增接口的方式,隔离职责,不需要使用方关心或者调用抽奖的初始化
...
...
@@ -49,9 +50,7 @@ public abstract class AbstractRaffleStrategy implements IRaffleStrategy, IRaffle
DefaultChainFactory
.
StrategyAwardVO
chainStrategyAwardVO
=
raffleLogicChain
(
userId
,
strategyId
);
log
.
info
(
"抽奖策略计算-责任链 {} {} {} {}"
,
userId
,
strategyId
,
chainStrategyAwardVO
.
getAwardId
(),
chainStrategyAwardVO
.
getLogicModel
());
if
(!
DefaultChainFactory
.
LogicModel
.
RULE_DEFAULT
.
getCode
().
equals
(
chainStrategyAwardVO
.
getLogicModel
()))
{
return
RaffleAwardEntity
.
builder
()
.
awardId
(
chainStrategyAwardVO
.
getAwardId
())
.
build
();
return
buildRaffleAwardEntity
(
strategyId
,
chainStrategyAwardVO
.
getAwardId
(),
null
);
}
// 3. 规则树抽奖过滤【奖品ID,会根据抽奖次数判断、库存判断、兜底兜里返回最终的可获得奖品信息】
...
...
@@ -59,9 +58,15 @@ public abstract class AbstractRaffleStrategy implements IRaffleStrategy, IRaffle
log
.
info
(
"抽奖策略计算-规则树 {} {} {} {}"
,
userId
,
strategyId
,
treeStrategyAwardVO
.
getAwardId
(),
treeStrategyAwardVO
.
getAwardRuleValue
());
// 4. 返回抽奖结果
return
buildRaffleAwardEntity
(
strategyId
,
treeStrategyAwardVO
.
getAwardId
(),
treeStrategyAwardVO
.
getAwardRuleValue
());
}
private
RaffleAwardEntity
buildRaffleAwardEntity
(
Long
strategyId
,
Integer
awardId
,
String
awardConfig
)
{
StrategyAwardEntity
strategyAward
=
repository
.
queryStrategyAwardEntity
(
strategyId
,
awardId
);
return
RaffleAwardEntity
.
builder
()
.
awardId
(
treeStrategyAwardVO
.
getAwardId
())
.
awardConfig
(
treeStrategyAwardVO
.
getAwardRuleValue
())
.
awardId
(
awardId
)
.
awardConfig
(
awardConfig
)
.
sort
(
strategyAward
.
getSort
())
.
build
();
}
...
...
xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/service/IRaffleAward.java
0 → 100644
浏览文件 @
123912c3
package
cn.bugstack.domain.strategy.service
;
import
cn.bugstack.domain.strategy.model.entity.StrategyAwardEntity
;
import
java.util.List
;
/**
* @description:
* @author: hdr
* @PACKAGE_NAME: cn.bugstack.domain.strategy.service
* @DATE: 2024/4/25
*/
public
interface
IRaffleAward
{
/**
* 根据策略ID查询抽奖奖品列表配置
*
* @param strategyId 策略ID
* @return 奖品列表
*/
List
<
StrategyAwardEntity
>
queryRaffleStrategyAwardList
(
Long
strategyId
);
}
xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/service/raffle/DefaultRaffleStrategy.java
浏览文件 @
123912c3
package
cn.bugstack.domain.strategy.service.raffle
;
import
cn.bugstack.domain.strategy.model.entity.StrategyAwardEntity
;
import
cn.bugstack.domain.strategy.model.valobj.RuleTreeVO
;
import
cn.bugstack.domain.strategy.model.valobj.StrategyAwardRuleModelVO
;
import
cn.bugstack.domain.strategy.model.valobj.StrategyAwardStockKeyVO
;
import
cn.bugstack.domain.strategy.repository.IStrategyRepository
;
import
cn.bugstack.domain.strategy.service.IRaffleAward
;
import
cn.bugstack.domain.strategy.service.IRaffleStock
;
import
cn.bugstack.domain.strategy.service.armory.IStrategyDispatch
;
import
cn.bugstack.domain.strategy.service.AbstractRaffleStrategy
;
import
cn.bugstack.domain.strategy.service.rule.chain.ILogicChain
;
...
...
@@ -13,6 +16,8 @@ import cn.bugstack.domain.strategy.service.rule.tree.factory.engine.IDecisionTre
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
* @description:
* @author: hdr
...
...
@@ -21,7 +26,7 @@ import org.springframework.stereotype.Service;
*/
@Slf4j
@Service
public
class
DefaultRaffleStrategy
extends
AbstractRaffleStrategy
{
public
class
DefaultRaffleStrategy
extends
AbstractRaffleStrategy
implements
IRaffleAward
,
IRaffleStock
{
public
DefaultRaffleStrategy
(
IStrategyRepository
repository
,
IStrategyDispatch
strategyDispatch
,
DefaultChainFactory
defaultChainFactory
,
DefaultTreeFactory
defaultTreeFactory
)
{
super
(
repository
,
strategyDispatch
,
defaultChainFactory
,
defaultTreeFactory
);
...
...
@@ -59,4 +64,9 @@ public class DefaultRaffleStrategy extends AbstractRaffleStrategy {
public
void
updateStrategyAwardStock
(
Long
strategyId
,
Integer
awardId
)
{
repository
.
updateStrategyAwardStock
(
strategyId
,
awardId
);
}
@Override
public
List
<
StrategyAwardEntity
>
queryRaffleStrategyAwardList
(
Long
strategyId
)
{
return
repository
.
queryStrategyAwardList
(
strategyId
);
}
}
xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/service/rule/tree/factory/engine/impl/DecisionTreeEngine.java
浏览文件 @
123912c3
...
...
@@ -66,7 +66,7 @@ public class DecisionTreeEngine implements IDecisionTreeEngine {
return
nodeLine
.
getRuleNodeTo
();
}
}
throw
new
RuntimeException
(
"决策树引擎,nextNode 计算失败,未找到可执行节点!"
)
;
return
null
;
}
private
boolean
decisionLogic
(
String
matterValue
,
RuleTreeNodeLineVO
nodeLine
)
{
...
...
xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/dao/IStrategyAwardDao.java
浏览文件 @
123912c3
...
...
@@ -35,4 +35,11 @@ public interface IStrategyAwardDao {
* @param strategyAward
*/
void
updateStrategyAwardStock
(
StrategyAward
strategyAward
);
/**
*
* @param strategyAwardReq
* @return
*/
StrategyAward
queryStrategyAward
(
StrategyAward
strategyAwardReq
);
}
xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/repository/StrategyRepository.java
浏览文件 @
123912c3
package
cn.bugstack.infrastructure.persistent.repository
;
import
cn.bugstack.domain.strategy.model.entity.RaffleAwardEntity
;
import
cn.bugstack.domain.strategy.model.entity.StrategyAwardEntity
;
import
cn.bugstack.domain.strategy.model.entity.StrategyEntity
;
import
cn.bugstack.domain.strategy.model.entity.StrategyRuleEntity
;
...
...
@@ -9,6 +10,8 @@ import cn.bugstack.infrastructure.persistent.dao.*;
import
cn.bugstack.infrastructure.persistent.po.*
;
import
cn.bugstack.infrastructure.persistent.redis.IRedisService
;
import
cn.bugstack.types.common.Constants
;
import
cn.bugstack.types.enums.ResponseCode
;
import
cn.bugstack.types.exception.AppException
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -83,6 +86,9 @@ public class StrategyRepository implements IStrategyRepository {
strategyAwardEntity
.
setAwardCount
(
item
.
getAwardCount
());
strategyAwardEntity
.
setAwardRate
(
item
.
getAwardRate
());
strategyAwardEntity
.
setAwardCountSurplus
(
item
.
getAwardCountSurplus
());
strategyAwardEntity
.
setAwardTitle
(
item
.
getAwardTitle
());
strategyAwardEntity
.
setAwardSubtitle
(
item
.
getAwardSubtitle
());
strategyAwardEntity
.
setSort
(
strategyAwardEntity
.
getSort
());
return
strategyAwardEntity
;
}).
collect
(
Collectors
.
toList
());
...
...
@@ -166,7 +172,12 @@ public class StrategyRepository implements IStrategyRepository {
@Override
public
int
getRateRange
(
String
key
)
{
return
redisService
.
getValue
(
Constants
.
RedisKey
.
STRATEGY_RATE_RANGE_KEY
+
key
);
String
cacheKey
=
Constants
.
RedisKey
.
STRATEGY_RATE_RANGE_KEY
+
key
;
if
(!
redisService
.
isExists
(
cacheKey
))
{
throw
new
AppException
(
ResponseCode
.
UN_ASSEMBLED_STRATEGY_ARMORY
.
getCode
(),
cacheKey
+
Constants
.
COLON
+
ResponseCode
.
UN_ASSEMBLED_STRATEGY_ARMORY
.
getInfo
());
}
return
redisService
.
getValue
(
cacheKey
);
//return redisService.getValue(Constants.RedisKey.STRATEGY_RATE_RANGE_KEY + key);
}
@Override
...
...
@@ -299,4 +310,32 @@ public class StrategyRepository implements IStrategyRepository {
strategyAwardDao
.
updateStrategyAwardStock
(
strategyAward
);
}
@Override
public
StrategyAwardEntity
queryStrategyAwardEntity
(
Long
strategyId
,
Integer
awardId
)
{
// 优先从缓存获取
String
cacheKey
=
Constants
.
RedisKey
.
STRATEGY_AWARD_KEY
+
strategyId
+
Constants
.
UNDERLINE
+
awardId
;
StrategyAwardEntity
strategyAwardEntity
=
redisService
.
getValue
(
cacheKey
);
if
(
null
!=
strategyAwardEntity
)
return
strategyAwardEntity
;
// 查询数据
StrategyAward
strategyAwardReq
=
new
StrategyAward
();
strategyAwardReq
.
setStrategyId
(
strategyId
);
strategyAwardReq
.
setAwardId
(
awardId
);
StrategyAward
strategyAwardRes
=
strategyAwardDao
.
queryStrategyAward
(
strategyAwardReq
);
// 转换数据
strategyAwardEntity
=
StrategyAwardEntity
.
builder
()
.
strategyId
(
strategyAwardRes
.
getStrategyId
())
.
awardId
(
strategyAwardRes
.
getAwardId
())
.
awardTitle
(
strategyAwardRes
.
getAwardTitle
())
.
awardSubtitle
(
strategyAwardRes
.
getAwardSubtitle
())
.
awardCount
(
strategyAwardRes
.
getAwardCount
())
.
awardCountSurplus
(
strategyAwardRes
.
getAwardCountSurplus
())
.
awardRate
(
strategyAwardRes
.
getAwardRate
())
.
sort
(
strategyAwardRes
.
getSort
())
.
build
();
// 缓存结果
redisService
.
setValue
(
cacheKey
,
strategyAwardEntity
);
// 返回数据
return
strategyAwardEntity
;
}
}
xfg-frame-archetype-lite-trigger/pom.xml
浏览文件 @
123912c3
...
...
@@ -36,6 +36,12 @@
<groupId>
cn.bugstack
</groupId>
<artifactId>
xfg-frame-archetype-lite-domain
</artifactId>
</dependency>
<dependency>
<groupId>
cn.bugstack
</groupId>
<artifactId>
xfg-frame-market-api
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependencies>
<build>
...
...
xfg-frame-archetype-lite-trigger/src/main/java/cn/bugstack/trigger/http/RaffleController.java
0 → 100644
浏览文件 @
123912c3
package
cn.bugstack.trigger.http
;
import
cn.bugstack.domain.strategy.model.entity.RaffleAwardEntity
;
import
cn.bugstack.domain.strategy.model.entity.RaffleFactorEntity
;
import
cn.bugstack.domain.strategy.model.entity.StrategyAwardEntity
;
import
cn.bugstack.domain.strategy.service.IRaffleAward
;
import
cn.bugstack.domain.strategy.service.IRaffleStrategy
;
import
cn.bugstack.domain.strategy.service.armory.IStrategyArmory
;
import
cn.bugstack.trigger.api.IRaffleService
;
import
cn.bugstack.trigger.api.dto.RaffleAwardListRequestDTO
;
import
cn.bugstack.trigger.api.dto.RaffleAwardListResponseDTO
;
import
cn.bugstack.trigger.api.dto.RaffleRequestDTO
;
import
cn.bugstack.trigger.api.dto.RaffleResponseDTO
;
import
cn.bugstack.types.enums.ResponseCode
;
import
cn.bugstack.types.exception.AppException
;
import
cn.bugstack.types.model.Response
;
import
com.alibaba.fastjson.JSON
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.*
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @description: 营销抽奖服务
* @author: hdr
* @PACKAGE_NAME: cn.bugstack.trigger.http
* @DATE: 2024/4/25
*/
@Slf4j
@RestController
@CrossOrigin
(
"${app.config.cross-origin}"
)
@RequestMapping
(
"/api/${app.config.api-version}/raffle/"
)
public
class
RaffleController
implements
IRaffleService
{
@Resource
private
IRaffleAward
raffleAward
;
@Resource
private
IRaffleStrategy
raffleStrategy
;
@Resource
private
IStrategyArmory
strategyArmory
;
/**
* 策略装配,将策略信息装配到缓存中
* <a href="http://localhost:8091/api/v1/raffle/strategy_armory">/api/v1/raffle/strategy_armory</a>
*
* @param strategyId 策略ID
* @return 装配结果
*/
@RequestMapping
(
value
=
"strategy_armory"
,
method
=
RequestMethod
.
GET
)
@Override
public
Response
<
Boolean
>
strategyArmory
(
@RequestParam
Long
strategyId
)
{
try
{
log
.
info
(
"抽奖策略装配开始 strategyId:{}"
,
strategyId
);
boolean
armoryStatus
=
strategyArmory
.
assembleLotteryStrategy
(
strategyId
);
Response
<
Boolean
>
response
=
new
Response
<>();
response
.
setCode
(
ResponseCode
.
SUCCESS
.
getCode
());
response
.
setInfo
(
ResponseCode
.
SUCCESS
.
getInfo
());
response
.
setData
(
armoryStatus
);
return
response
;
}
catch
(
Exception
e
)
{
log
.
error
(
"抽奖策略装配失败 strategyId:{}"
,
strategyId
,
e
);
return
Response
.<
Boolean
>
builder
()
.
code
(
ResponseCode
.
UN_ERROR
.
getCode
())
.
info
(
ResponseCode
.
UN_ERROR
.
getInfo
())
.
build
();
}
}
/**
* 查询奖品列表
* <a href="http://localhost:8091/api/v1/raffle/query_raffle_award_list">/api/v1/raffle/query_raffle_award_list</a>
* 请求参数 raw json
*
* @param requestDTO {"strategyId":1000001}
* @return 奖品列表
*/
@RequestMapping
(
value
=
"query_raffle_award_list"
,
method
=
RequestMethod
.
POST
)
@Override
public
Response
<
List
<
RaffleAwardListResponseDTO
>>
queryRaffleAwardList
(
@RequestBody
RaffleAwardListRequestDTO
requestDTO
)
{
try
{
log
.
info
(
"查询抽奖奖品列表配开始 strategyId:{}"
,
requestDTO
.
getStrategyId
());
// 查询奖品配置
List
<
StrategyAwardEntity
>
strategyAwardEntities
=
raffleAward
.
queryRaffleStrategyAwardList
(
requestDTO
.
getStrategyId
());
List
<
RaffleAwardListResponseDTO
>
raffleAwardListResponseDTOS
=
new
ArrayList
<>(
strategyAwardEntities
.
size
());
for
(
StrategyAwardEntity
strategyAwardEntity
:
strategyAwardEntities
)
{
raffleAwardListResponseDTOS
.
add
(
RaffleAwardListResponseDTO
.
builder
()
.
awardId
(
strategyAwardEntity
.
getAwardId
())
.
awardTitle
(
strategyAwardEntity
.
getAwardTitle
())
.
awardSubtitle
(
strategyAwardEntity
.
getAwardSubtitle
())
.
sort
(
strategyAwardEntity
.
getSort
())
.
build
());
}
Response
<
List
<
RaffleAwardListResponseDTO
>>
response
=
Response
.<
List
<
RaffleAwardListResponseDTO
>>
builder
()
.
code
(
ResponseCode
.
SUCCESS
.
getCode
())
.
info
(
ResponseCode
.
SUCCESS
.
getInfo
())
.
data
(
raffleAwardListResponseDTOS
)
.
build
();
log
.
info
(
"查询抽奖奖品列表配置完成 strategyId:{} response: {}"
,
requestDTO
.
getStrategyId
(),
JSON
.
toJSONString
(
response
));
// 返回结果
return
response
;
}
catch
(
Exception
e
)
{
log
.
error
(
"查询抽奖奖品列表配置失败 strategyId:{}"
,
requestDTO
.
getStrategyId
(),
e
);
return
Response
.<
List
<
RaffleAwardListResponseDTO
>>
builder
()
.
code
(
ResponseCode
.
UN_ERROR
.
getCode
())
.
info
(
ResponseCode
.
UN_ERROR
.
getInfo
())
.
build
();
}
}
/**
* 随机抽奖接口
* <a href="http://localhost:8091/api/v1/raffle/random_raffle">/api/v1/raffle/random_raffle</a>
*
* @param requestDTO 请求参数 {"strategyId":1000001}
* @return 抽奖结果
*/
@RequestMapping
(
value
=
"random_raffle"
,
method
=
RequestMethod
.
POST
)
@Override
public
Response
<
RaffleResponseDTO
>
randomRaffle
(
@RequestBody
RaffleRequestDTO
requestDTO
)
{
try
{
log
.
info
(
"随机抽奖开始 strategyId: {}"
,
requestDTO
.
getStrategyId
());
// 调用抽奖接口
RaffleAwardEntity
raffleAwardEntity
=
raffleStrategy
.
performRaffle
(
RaffleFactorEntity
.
builder
()
.
userId
(
"system"
)
.
strategyId
(
requestDTO
.
getStrategyId
())
.
build
());
// 封装返回结果
Response
<
RaffleResponseDTO
>
response
=
Response
.<
RaffleResponseDTO
>
builder
()
.
code
(
ResponseCode
.
SUCCESS
.
getCode
())
.
info
(
ResponseCode
.
SUCCESS
.
getInfo
())
.
data
(
RaffleResponseDTO
.
builder
()
.
awardId
(
raffleAwardEntity
.
getAwardId
())
.
awardIndex
(
raffleAwardEntity
.
getSort
())
.
build
())
.
build
();
log
.
info
(
"随机抽奖完成 strategyId: {} response: {}"
,
requestDTO
.
getStrategyId
(),
JSON
.
toJSONString
(
response
));
return
response
;
}
catch
(
AppException
e
)
{
log
.
error
(
"随机抽奖失败 strategyId:{} {}"
,
requestDTO
.
getStrategyId
(),
e
.
getInfo
());
return
Response
.<
RaffleResponseDTO
>
builder
()
.
code
(
e
.
getCode
())
.
info
(
e
.
getInfo
())
.
build
();
}
catch
(
Exception
e
)
{
log
.
error
(
"随机抽奖失败 strategyId:{}"
,
requestDTO
.
getStrategyId
(),
e
);
return
Response
.<
RaffleResponseDTO
>
builder
()
.
code
(
ResponseCode
.
UN_ERROR
.
getCode
())
.
info
(
ResponseCode
.
UN_ERROR
.
getInfo
())
.
build
();
}
}
}
xfg-frame-archetype-lite-types/pom.xml
浏览文件 @
123912c3
...
...
@@ -30,6 +30,23 @@
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
</dependency>
<!-- 系统其他模块 -->
<dependency>
<groupId>
cn.bugstack
</groupId>
<artifactId>
xfg-frame-market-api
</artifactId>
</dependency>
<dependency>
<artifactId>
xfg-frame-archetype-lite
</artifactId>
<groupId>
cn.bugstack
</groupId>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
cn.bugstack
</groupId>
<artifactId>
xfg-frame-archetype-lite-domain
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<scope>
compile
</scope>
</dependency>
</dependencies>
<build>
...
...
xfg-frame-archetype-lite-types/src/main/java/cn/bugstack/types/enums/ResponseCode.java
浏览文件 @
123912c3
...
...
@@ -12,7 +12,8 @@ public enum ResponseCode {
SUCCESS
(
"0000"
,
"成功"
),
UN_ERROR
(
"0001"
,
"未知失败"
),
ILLEGAL_PARAMETER
(
"0002"
,
"非法参数"
),
STRATEGY_RULE_WEIGHT_IS_NULL
(
"ERR_BIZ_001"
,
"业务异常,策略规则中 rule_weight 权重规则已适用但未配置"
)
STRATEGY_RULE_WEIGHT_IS_NULL
(
"ERR_BIZ_001"
,
"业务异常,策略规则中 rule_weight 权重规则已适用但未配置"
),
UN_ASSEMBLED_STRATEGY_ARMORY
(
"ERR_BIZ_002"
,
"抽奖策略配置未装配,请通过IStrategyArmory完成装配"
),
;
private
String
code
;
...
...
xfg-frame-archetype-lite-types/src/main/java/cn/bugstack/types/model/Response.java
0 → 100644
浏览文件 @
123912c3
package
cn.bugstack.types.model
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.io.Serializable
;
/**
* @description:
* @author: hdr
* @PACKAGE_NAME: cn.bugstack.types.model
* @DATE: 2024/4/25
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public
class
Response
<
T
>
implements
Serializable
{
private
String
code
;
private
String
info
;
private
T
data
;
}
xfg-frame-market-api/pom.xml
0 → 100644
浏览文件 @
123912c3
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
xfg-frame-archetype-lite
</artifactId>
<groupId>
cn.bugstack
</groupId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
xfg-frame-market-api
</artifactId>
<properties>
<maven.compiler.source>
8
</maven.compiler.source>
<maven.compiler.target>
8
</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
</dependency>
<dependency>
<groupId>
jakarta.validation
</groupId>
<artifactId>
jakarta.validation-api
</artifactId>
</dependency>
<!-- 系统model -->
<dependency>
<groupId>
cn.bugstack
</groupId>
<artifactId>
xfg-frame-archetype-lite-types
</artifactId>
</dependency>
</dependencies>
</project>
xfg-frame-market-api/src/main/java/cn/bugstack/trigger/api/IRaffleService.java
0 → 100644
浏览文件 @
123912c3
package
cn.bugstack.trigger.api
;
import
cn.bugstack.trigger.api.dto.RaffleAwardListRequestDTO
;
import
cn.bugstack.trigger.api.dto.RaffleAwardListResponseDTO
;
import
cn.bugstack.trigger.api.dto.RaffleRequestDTO
;
import
cn.bugstack.trigger.api.dto.RaffleResponseDTO
;
import
cn.bugstack.types.model.Response
;
import
java.util.List
;
/**
* @description: 抽奖服务接口
* @author: hdr
* @PACKAGE_NAME: cn.bugstack.trigger.api
* @DATE: 2024/4/25
*/
public
interface
IRaffleService
{
/**
* 策略装配接口
*
* @param strategyId 策略ID
* @return 装配结果
*/
Response
<
Boolean
>
strategyArmory
(
Long
strategyId
);
/**
* 查询抽奖奖品列表配置
*
* @param requestDTO 抽奖奖品列表查询请求参数
* @return 抽奖奖品列表数据
*/
Response
<
List
<
RaffleAwardListResponseDTO
>>
queryRaffleAwardList
(
RaffleAwardListRequestDTO
requestDTO
);
/**
* 随机抽奖接口
*
* @param requestDTO 请求参数
* @return 抽奖结果
*/
Response
<
RaffleResponseDTO
>
randomRaffle
(
RaffleRequestDTO
requestDTO
);
}
xfg-frame-market-api/src/main/java/cn/bugstack/trigger/api/dto/RaffleAwardListRequestDTO.java
0 → 100644
浏览文件 @
123912c3
package
cn.bugstack.trigger.api.dto
;
import
lombok.Data
;
/**
* @description: 抽奖奖品列表,请求对象
* @author: hdr
* @PACKAGE_NAME: cn.bugstack.trigger.api.dto
* @DATE: 2024/4/25
*/
@Data
public
class
RaffleAwardListRequestDTO
{
/**
* 抽奖策略ID
*/
private
Long
strategyId
;
}
xfg-frame-market-api/src/main/java/cn/bugstack/trigger/api/dto/RaffleAwardListResponseDTO.java
0 → 100644
浏览文件 @
123912c3
package
cn.bugstack.trigger.api.dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* @description: 抽奖奖品列表,应答对象
* @author: hdr
* @PACKAGE_NAME: cn.bugstack.trigger.api.dto
* @DATE: 2024/4/25
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public
class
RaffleAwardListResponseDTO
{
/**
* 奖品ID
*/
private
Integer
awardId
;
/**
* 奖品标题
*/
private
String
awardTitle
;
/**
* 建工副标题【抽奖1次后解锁】
*/
private
String
awardSubtitle
;
/**
* 排序编号
*/
private
Integer
sort
;
}
xfg-frame-market-api/src/main/java/cn/bugstack/trigger/api/dto/RaffleRequestDTO.java
0 → 100644
浏览文件 @
123912c3
package
cn.bugstack.trigger.api.dto
;
import
lombok.Data
;
/**
* @description: 抽奖请求参数
* @author: hdr
* @PACKAGE_NAME: cn.bugstack.trigger.api.dto
* @DATE: 2024/4/25
*/
@Data
public
class
RaffleRequestDTO
{
/**
* 抽奖策略ID
*/
private
Long
strategyId
;
}
xfg-frame-market-api/src/main/java/cn/bugstack/trigger/api/dto/RaffleResponseDTO.java
0 → 100644
浏览文件 @
123912c3
package
cn.bugstack.trigger.api.dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* @description: 抽奖应答结果
* @author: hdr
* @PACKAGE_NAME: cn.bugstack.trigger.api.dto
* @DATE: 2024/4/25
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public
class
RaffleResponseDTO
{
/**
* 奖品ID
*/
private
Integer
awardId
;
/**
* 排序编号【策略奖品配置的奖品顺序编号】
*/
private
Integer
awardIndex
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录