记得上下班打卡 | 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
c7be1e63
Commit
c7be1e63
authored
Dec 10, 2021
by
jiangxiulong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
随机数算法
parent
4d362b3e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
1 deletion
+35
-1
SweetIntegralActivityDrawServiceImpl.java
...et/service/impl/SweetIntegralActivityDrawServiceImpl.java
+35
-1
No files found.
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/service/impl/SweetIntegralActivityDrawServiceImpl.java
View file @
c7be1e63
...
@@ -444,7 +444,7 @@ public class SweetIntegralActivityDrawServiceImpl extends ServiceImpl<SweetInteg
...
@@ -444,7 +444,7 @@ public class SweetIntegralActivityDrawServiceImpl extends ServiceImpl<SweetInteg
/**
/**
* 抽奖方法 计算中哪个奖池的奖品
* 抽奖方法 计算中哪个奖池的奖品
*/
*/
private
boolean
lotteryDraw
(
String
integralActivityId
,
String
uid
)
{
/*
private boolean lotteryDraw(String integralActivityId, String uid) {
// 随机数
// 随机数
double random = Math.random() * 100;
double random = Math.random() * 100;
BigDecimal randomBig = BigDecimal.valueOf(random);
BigDecimal randomBig = BigDecimal.valueOf(random);
...
@@ -474,6 +474,40 @@ public class SweetIntegralActivityDrawServiceImpl extends ServiceImpl<SweetInteg
...
@@ -474,6 +474,40 @@ public class SweetIntegralActivityDrawServiceImpl extends ServiceImpl<SweetInteg
} else {
} else {
return false;
return false;
}
}
}*/
/**
* 抽奖方法 计算中哪个奖池的奖品
*/
private
boolean
lotteryDraw
(
String
integralActivityId
,
String
uid
)
{
int
estimatedNum
=
redisDataUtils
.
getIntegralActivityEstimatedNum
(
integralActivityId
);
if
(
estimatedNum
<=
0
)
{
// 此时百分百中实物
return
true
;
}
// 剩余总库存 添加编辑的时候冗余的总库存省去计算
int
prizeNum
=
redisDataUtils
.
getIntegralActivityTotalPrizeNum
(
integralActivityId
);
BigDecimal
prizeNumBig
=
BigDecimal
.
valueOf
(
prizeNum
);
// 概率
BigDecimal
estimatedNumBig
=
BigDecimal
.
valueOf
(
estimatedNum
);
// 会员概率*2
try
{
ResponseDto
<
Boolean
>
isMemberDto
=
feignAdamBaseClient
.
isMember
(
uid
);
Boolean
isMember
=
isMemberDto
.
getData
();
if
(
isMember
)
{
estimatedNumBig
=
estimatedNumBig
.
divide
(
BigDecimal
.
valueOf
(
2
),
2
,
BigDecimal
.
ROUND_HALF_UP
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"获取用户是否是会员失败 [uid:{}, e:{}]"
,
uid
,
e
);
}
// 随机数
double
random
=
Math
.
random
();
BigDecimal
randomBig
=
BigDecimal
.
valueOf
(
random
);
BigDecimal
randomBigNew
=
randomBig
.
multiply
(
estimatedNumBig
);
// 对比大小
if
(
randomBigNew
.
compareTo
(
prizeNumBig
)
<=
0
)
{
return
true
;
// 0 - 剩余预估人数的随机数 <= 实物剩余总库存 中实物
}
else
{
return
false
;
}
}
}
/*public static void main(String[] args) {
/*public static void main(String[] args) {
...
...
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