记得上下班打卡 | 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
ec888aaa
Commit
ec888aaa
authored
Aug 18, 2021
by
胡佳晨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
抽奖修改数据库
parent
e673bff3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
18 deletions
+33
-18
RandomUtil.java
...main/java/com/liquidnet/commons/lang/util/RandomUtil.java
+8
-0
SweetConstant.java
...a/com/liquidnet/service/sweet/constant/SweetConstant.java
+3
-4
SweetDataController.java
...quidnet/service/sweet/controller/SweetDataController.java
+1
-1
RedisDataUtils.java
...ava/com/liquidnet/service/sweet/utils/RedisDataUtils.java
+21
-13
No files found.
liquidnet-bus-common/liquidnet-common-base/src/main/java/com/liquidnet/commons/lang/util/RandomUtil.java
View file @
ec888aaa
...
@@ -35,6 +35,14 @@ public class RandomUtil {
...
@@ -35,6 +35,14 @@ public class RandomUtil {
return
getRandom
().
nextInt
(
max
-
min
)
+
min
;
return
getRandom
().
nextInt
(
max
-
min
)
+
min
;
}
}
/**
* 从[min,max)中随机一个整数
*/
public
static
int
getRandomIntTime
(
int
min
,
int
max
)
{
Random
random
=
new
Random
(
System
.
currentTimeMillis
()-(
new
Random
().
nextInt
()));
return
random
.
nextInt
(
max
-
min
)
+
min
;
}
/**
/**
* 获取随机boolean型
* 获取随机boolean型
*
*
...
...
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/constant/SweetConstant.java
View file @
ec888aaa
...
@@ -13,11 +13,10 @@ public class SweetConstant {
...
@@ -13,11 +13,10 @@ public class SweetConstant {
public
final
static
String
REDIS_KEY_SWEET_ARTISTS_RELATION
=
"sweet:artists:relation:uid:"
;
public
final
static
String
REDIS_KEY_SWEET_ARTISTS_RELATION
=
"sweet:artists:relation:uid:"
;
public
final
static
String
REDIS_KEY_SWEET_ARTISTS_DETAILS
=
"sweet:artists:details:"
;
public
final
static
String
REDIS_KEY_SWEET_ARTISTS_DETAILS
=
"sweet:artists:details:"
;
public
final
static
String
REDIS_KEY_SWEET_SHOP
=
"sweet:artists:shop:manual:"
;
public
final
static
String
REDIS_KEY_SWEET_SHOP
=
"sweet:artists:shop:manual:"
;
public
final
static
String
REDIS_KEY_SWEET_LUCK_DRAW
=
"sweet:artists:luckDraw:uid:"
;
public
final
static
String
REDIS_KEY_SWEET_LUCK_DRAW_SURPLUS
=
"sweet:artists:luckDraw:surplus:num:"
;
//中奖库存
public
final
static
String
REDIS_KEY_SWEET_LUCK_DRAW_ALL
=
"sweet:artists:luckDraw:all:num:"
;
//中奖总量
public
final
static
String
REDIS_KEY_SWEET_LUCK_DRAW
=
"sweet:luckDraw:mobile:"
;
public
final
static
String
REDIS_KEY_SWEET_LUCK_DRAW_SURPLUS
=
"sweet:luckDraw:num:"
;
//中奖库存
public
final
static
String
REDIS_KEY_SWEET_LUCK_DRAW_ALL
=
"sweet:luckDraw:num:"
;
//中奖总量
public
final
static
String
REDIS_KEY_SWEET_LUCK_DRAW_PRESENT_MOBILE
=
"sweet:luckDraw:present:mobile:"
;
//中奖库存
public
final
static
String
REDIS_KEY_SWEET_LUCK_DRAW_PRESENT_MOBILE
=
"sweet:luckDraw:present:mobile:"
;
//中奖库存
public
final
static
String
REDIS_KEY_SWEET_WECHAT_USER_INFO
=
"sweet:wechatUser:unionId:"
;
public
final
static
String
REDIS_KEY_SWEET_WECHAT_USER_INFO
=
"sweet:wechatUser:unionId:"
;
...
...
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/controller/SweetDataController.java
View file @
ec888aaa
...
@@ -76,7 +76,7 @@ public class SweetDataController {
...
@@ -76,7 +76,7 @@ public class SweetDataController {
@ApiOperation
(
"增加可中奖数量1最大6(20210820)"
)
@ApiOperation
(
"增加可中奖数量1最大6(20210820)"
)
public
ResponseDto
<
Boolean
>
luckDrawAllAdd
()
{
public
ResponseDto
<
Boolean
>
luckDrawAllAdd
()
{
try
{
try
{
String
redisKey
=
SweetConstant
.
REDIS_KEY_SWEET_LUCK_DRAW_ALL
.
concat
(
"20210820"
);
String
redisKey
=
SweetConstant
.
REDIS_KEY_SWEET_LUCK_DRAW_ALL
.
concat
(
"20210820"
)
.
concat
(
":all"
)
;
int
count
=
(
int
)
redisUtil
.
get
(
redisKey
);
int
count
=
(
int
)
redisUtil
.
get
(
redisKey
);
if
(
count
>=
6
)
{
if
(
count
>=
6
)
{
redisUtil
.
set
(
redisKey
,
6
);
redisUtil
.
set
(
redisKey
,
6
);
...
...
liquidnet-bus-service/liquidnet-service-sweet/src/main/java/com/liquidnet/service/sweet/utils/RedisDataUtils.java
View file @
ec888aaa
...
@@ -17,6 +17,7 @@ import com.liquidnet.service.sweet.vo.SweetAnswerVo;
...
@@ -17,6 +17,7 @@ import com.liquidnet.service.sweet.vo.SweetAnswerVo;
import
com.liquidnet.service.sweet.vo.SweetArtistsRelationVo
;
import
com.liquidnet.service.sweet.vo.SweetArtistsRelationVo
;
import
com.liquidnet.service.sweet.vo.SweetPrizeVo
;
import
com.liquidnet.service.sweet.vo.SweetPrizeVo
;
import
com.liquidnet.service.sweet.vo.SweetRemindVo
;
import
com.liquidnet.service.sweet.vo.SweetRemindVo
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -27,6 +28,7 @@ import static com.liquidnet.service.sweet.constant.SweetConstant.REDIS_KEY_SWEET
...
@@ -27,6 +28,7 @@ import static com.liquidnet.service.sweet.constant.SweetConstant.REDIS_KEY_SWEET
import
static
com
.
liquidnet
.
service
.
sweet
.
constant
.
SweetConstant
.
REDIS_KEY_SWEET_LUCK_DRAW_SURPLUS
;
import
static
com
.
liquidnet
.
service
.
sweet
.
constant
.
SweetConstant
.
REDIS_KEY_SWEET_LUCK_DRAW_SURPLUS
;
@Component
@Component
@Slf4j
public
class
RedisDataUtils
{
public
class
RedisDataUtils
{
@Autowired
@Autowired
...
@@ -393,7 +395,13 @@ public class RedisDataUtils {
...
@@ -393,7 +395,13 @@ public class RedisDataUtils {
//获取抽奖状态
//获取抽奖状态
public
int
getLuckDrawStatus
(
String
mobile
,
String
luckDrawNum
)
{
public
int
getLuckDrawStatus
(
String
mobile
,
String
luckDrawNum
)
{
String
redisKey
=
SweetConstant
.
REDIS_KEY_SWEET_LUCK_DRAW
.
concat
(
mobile
).
concat
(
":luckDrawNum:"
+
luckDrawNum
);
String
redisKey
=
SweetConstant
.
REDIS_KEY_SWEET_LUCK_DRAW
.
concat
(
mobile
).
concat
(
":luckDrawNum:"
+
luckDrawNum
);
return
(
int
)
redisUtil
.
get
(
redisKey
);
Object
obj
=
redisUtil
.
get
(
redisKey
);
if
(
obj
==
null
){
redisUtil
.
set
(
redisKey
,
0
);
return
0
;
}
else
{
return
(
int
)
redisUtil
.
get
(
redisKey
);
}
}
}
//修改抽奖状态
//修改抽奖状态
...
@@ -405,22 +413,22 @@ public class RedisDataUtils {
...
@@ -405,22 +413,22 @@ public class RedisDataUtils {
SweetPrizeVo
vo
=
SweetPrizeVo
.
getNew
();
SweetPrizeVo
vo
=
SweetPrizeVo
.
getNew
();
String
redisKey
=
SweetConstant
.
REDIS_KEY_SWEET_LUCK_DRAW
.
concat
(
mobile
).
concat
(
":luckDrawNum:"
+
luckDrawNum
);
String
redisKey
=
SweetConstant
.
REDIS_KEY_SWEET_LUCK_DRAW
.
concat
(
mobile
).
concat
(
":luckDrawNum:"
+
luckDrawNum
);
String
redisSurplus
=
SweetConstant
.
REDIS_KEY_SWEET_LUCK_DRAW_SURPLUS
.
concat
(
luckDrawNum
);
String
redisSurplus
=
SweetConstant
.
REDIS_KEY_SWEET_LUCK_DRAW_SURPLUS
.
concat
(
luckDrawNum
)
.
concat
(
":surplus"
)
;
String
redisAll
=
SweetConstant
.
REDIS_KEY_SWEET_LUCK_DRAW_ALL
.
concat
(
luckDrawNum
);
String
redisAll
=
SweetConstant
.
REDIS_KEY_SWEET_LUCK_DRAW_ALL
.
concat
(
luckDrawNum
)
.
concat
(
":all"
)
;
String
redisPresent
=
SweetConstant
.
REDIS_KEY_SWEET_LUCK_DRAW_PRESENT_MOBILE
.
concat
(
mobile
);
String
redisPresent
=
SweetConstant
.
REDIS_KEY_SWEET_LUCK_DRAW_PRESENT_MOBILE
.
concat
(
mobile
);
int
surplus
=
(
int
)
redisUtil
.
get
(
redisSurplus
);
//当前中奖数量
int
surplus
=
(
int
)
redisUtil
.
get
(
redisSurplus
);
//当前中奖数量
int
prize
=
(
int
)
redisUtil
.
get
(
redisAll
)
;
//总量
int
prize
=
0
;
//总量
int
prizeALl
=
(
int
)
redisUtil
.
get
(
redisAll
)
+
1
;
//不变的总量
int
prizeALl
=
(
int
)
redisUtil
.
get
(
redisAll
);
//不变的总量
int
count
=
(
int
)
redisUtil
.
incr
(
redisKey
,
1
);
int
count
=
(
int
)
redisUtil
.
incr
(
redisKey
,
1
);
if
(
count
>
2
)
{
if
(
count
>
2
)
{
vo
.
setPrize
(
prize
ALl
);
vo
.
setPrize
(
prize
);
vo
.
setPrizeAll
(
prizeALl
);
vo
.
setPrizeAll
(
prizeALl
);
return
vo
;
return
vo
;
}
}
if
(
surplus
<
prize
)
{
if
(
surplus
<
prize
ALl
)
{
//随机算法
//随机算法
Object
obj
=
redisUtil
.
get
(
redisPresent
);
Object
obj
=
redisUtil
.
get
(
redisPresent
);
int
present
;
int
present
;
...
@@ -429,12 +437,12 @@ public class RedisDataUtils {
...
@@ -429,12 +437,12 @@ public class RedisDataUtils {
}
else
{
}
else
{
present
=
(
int
)
obj
;
present
=
(
int
)
obj
;
}
}
int
random1
=
RandomUtil
.
getRandomInt
(
present
,
100
);
int
random1
=
RandomUtil
.
getRandomInt
Time
(
present
,
101
);
int
random2
=
RandomUtil
.
getRandomInt
(
present
,
100
);
int
random2
=
RandomUtil
.
getRandomInt
Time
(
present
,
101
);
if
(
random1
==
random2
)
{
if
(
random1
==
random2
)
{
surplus
=
(
int
)
redisUtil
.
get
(
redisSurplus
);
surplus
=
(
int
)
redisUtil
.
get
(
redisSurplus
);
if
(
surplus
<
prize
)
{
if
(
surplus
<
prize
ALl
)
{
surplus
=
(
int
)
redisUtil
.
incr
(
redisSurplus
,
1
);
prize
=
(
int
)
redisUtil
.
incr
(
redisSurplus
,
1
);
redisUtil
.
set
(
redisKey
,
2
);
redisUtil
.
set
(
redisKey
,
2
);
}
}
}
}
...
@@ -442,12 +450,12 @@ public class RedisDataUtils {
...
@@ -442,12 +450,12 @@ public class RedisDataUtils {
sqls
.
add
(
SqlMapping
.
get
(
"sweet_luck_draw.insert"
));
sqls
.
add
(
SqlMapping
.
get
(
"sweet_luck_draw.insert"
));
sqlsDataA
.
add
(
new
Object
[]{
sqlsDataA
.
add
(
new
Object
[]{
mobile
,
unionId
,
luckDrawNum
,
surplus
,
prize
,
now
mobile
,
unionId
,
luckDrawNum
,
prize
,
prizeALl
,
now
});
});
queueUtils
.
sendMsgByRedis
(
MQConst
.
SweetQueue
.
LUCK_DRAW
.
getKey
(),
queueUtils
.
sendMsgByRedis
(
MQConst
.
SweetQueue
.
LUCK_DRAW
.
getKey
(),
SqlMapping
.
gets
(
sqls
,
sqlsDataA
));
SqlMapping
.
gets
(
sqls
,
sqlsDataA
));
vo
.
setPrize
(
surplus
);
vo
.
setPrize
(
prize
);
vo
.
setPrizeAll
(
prizeALl
);
vo
.
setPrizeAll
(
prizeALl
);
return
vo
;
return
vo
;
}
}
...
...
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