记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
Project
Project
Details
Activity
Releases
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
董敬伟
liquidnet-bus-v1
Commits
d59d36ad
Commit
d59d36ad
authored
Apr 15, 2022
by
jiangxiulong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
抽奖概率判断 总概率超过100的;=0;排序
parent
0f0a62a9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
8 deletions
+23
-8
GoblinNftOrderServiceImpl.java
...service/order/service/impl/GoblinNftOrderServiceImpl.java
+22
-7
GoblinNftOrderUtils.java
...om/liquidnet/service/order/utils/GoblinNftOrderUtils.java
+1
-1
No files found.
liquidnet-bus-service/liquidnet-service-order/liquidnet-service-order-impl/src/main/java/com/liquidnet/service/order/service/impl/GoblinNftOrderServiceImpl.java
View file @
d59d36ad
...
...
@@ -245,20 +245,35 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
avgHitRatio
=
new
BigDecimal
(
100
).
subtract
(
sumHitRatio
).
divide
(
new
BigDecimal
(
size
),
2
,
RoundingMode
.
HALF_UP
);
}
// 未设置概率的写入概率
ArrayList
<
GoblinGoodsSkuInfoVo
>
newSkuInfoVos
=
ObjectUtil
.
cloneArrayGoblinGoodsSkuInfoListVo
();
int
skuListSize
=
skuInfoVos
.
size
();
for
(
int
i
=
0
;
i
<
skuListSize
;
i
++)
{
GoblinGoodsSkuInfoVo
infoVo
=
skuInfoVos
.
get
(
i
);
if
(
null
==
infoVo
.
getHitRatio
()
||
infoVo
.
getHitRatio
().
compareTo
(
BigDecimal
.
ZERO
)
<=
0
)
{
skuInfoVos
.
get
(
i
).
setHitRatio
(
avgHitRatio
);
if
(
null
==
infoVo
.
getHitRatio
()
||
infoVo
.
getHitRatio
().
compareTo
(
BigDecimal
.
ZERO
)
<
0
)
{
/**
* 算所得平均概率是0 即中不了 剔除掉
* 但是这么处理会导致前端页面显示有库存 买的时候显示没有
* 所以要么概率加起来必须100 要么前端计算盲盒总概率的时候也要同样处理
*/
if
(
avgHitRatio
.
compareTo
(
BigDecimal
.
ZERO
)
<=
0
)
{
continue
;
}
else
{
infoVo
.
setHitRatio
(
avgHitRatio
);
}
}
// 等于0的最终概率就是设置的值 大于0最终的概率是自己的+上面的
if
(
i
>
0
)
{
skuInfoVos
.
get
(
i
).
setHitRatio
(
skuInfoVos
.
get
(
i
-
1
).
getHitRatio
().
add
(
skuInfoVos
.
get
(
i
)
.
getHitRatio
()));
infoVo
.
setHitRatio
(
skuInfoVos
.
get
(
i
-
1
).
getHitRatio
().
add
(
infoVo
.
getHitRatio
()));
}
newSkuInfoVos
.
add
(
infoVo
);
}
if
(
CollectionUtil
.
isEmpty
(
newSkuInfoVos
))
{
log
.
info
(
"该盲盒概率超过100导致不能卖 skuIdList:{}"
,
skuIdList
);
return
null
;
}
// 按照概率排序
List
<
GoblinGoodsSkuInfoVo
>
listSort
=
s
kuInfoVos
.
stream
().
sorted
(
Comparator
.
comparing
(
GoblinGoodsSkuInfoVo:
:
getHitRatio
)).
collect
(
Collectors
.
toList
());
List
<
BigDecimal
>
hitRatioList
=
listSort
.
stream
().
map
(
GoblinGoodsSkuInfoVo:
:
getHitRatio
).
collect
(
Collectors
.
toList
());
// 按照概率排序
按照上面的运算最后一定是最大的不用排序了
// List<GoblinGoodsSkuInfoVo> listSort = newS
kuInfoVos.stream().sorted(Comparator.comparing(GoblinGoodsSkuInfoVo::getHitRatio)).collect(Collectors.toList());
List
<
BigDecimal
>
hitRatioList
=
newSkuInfoVos
.
stream
().
map
(
GoblinGoodsSkuInfoVo:
:
getHitRatio
).
collect
(
Collectors
.
toList
());
// 根据区块值来获取抽取到的物品索引
double
nextDouble
=
Math
.
random
();
BigDecimal
nextDoubleNew
=
BigDecimal
.
valueOf
(
nextDouble
);
...
...
@@ -269,7 +284,7 @@ public class GoblinNftOrderServiceImpl implements IGoblinNftOrderService {
int
index
=
hitRatioList
.
indexOf
(
nextDoubleNew
);
GoblinGoodsSkuInfoVo
goodsSkuInfoVo
=
listSort
.
get
(
index
);
GoblinGoodsSkuInfoVo
goodsSkuInfoVo
=
newSkuInfoVos
.
get
(
index
);
// 判断库存
int
surplusGeneral
=
nftOrderUtils
.
decrSkuStock
(
goodsSkuInfoVo
.
getSkuId
(),
number
);
if
(
surplusGeneral
<
0
)
{
...
...
liquidnet-bus-service/liquidnet-service-order/liquidnet-service-order-impl/src/main/java/com/liquidnet/service/order/utils/GoblinNftOrderUtils.java
View file @
d59d36ad
...
...
@@ -374,7 +374,7 @@ public class GoblinNftOrderUtils {
return
false
;
}
}
// 根据概率判断是否过滤当前sku
// 根据概率判断是否过滤当前sku
没设置概率或者设置了的返回true
public
boolean
getSkuHitRatio
(
BigDecimal
hitRatio
)
{
if
(
hitRatio
==
null
||
hitRatio
.
compareTo
(
BigDecimal
.
ZERO
)
>
0
)
{
return
true
;
...
...
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