Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
xunj
/
festival-activites
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 17ac7f96
authored
Jan 28, 2021
by
xunj
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
红包雨-抢红包
1 parent
8a62f969
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
301 additions
and
3 deletions
activity-admin/src/main/java/com/polysoft/activity/mapper/ActivityMapper.java
activity-admin/src/main/java/com/polysoft/activity/model/dto/AddRedRainDto.java
activity-admin/src/main/java/com/polysoft/activity/model/dto/QueryRedRainDto.java
activity-admin/src/main/java/com/polysoft/activity/model/param/AddRedRainParam.java
activity-admin/src/main/java/com/polysoft/activity/model/vo/RedRainVO.java
activity-admin/src/main/java/com/polysoft/activity/service/impl/ActItemServiceImpl.java
activity-admin/src/main/java/com/polysoft/activity/task/InitRedPackageTask.java
activity-admin/src/main/resources/mapper/ActivityMapper.xml
activity-admin/src/main/java/com/polysoft/activity/mapper/ActivityMapper.java
View file @
17ac7f9
...
@@ -3,7 +3,9 @@ package com.polysoft.activity.mapper;
...
@@ -3,7 +3,9 @@ package com.polysoft.activity.mapper;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.polysoft.activity.model.dto.ActItemDto
;
import
com.polysoft.activity.model.dto.ActItemDto
;
import
com.polysoft.activity.model.dto.AddRedRainDto
;
import
com.polysoft.activity.model.dto.AddRedRainDto
;
import
com.polysoft.activity.model.dto.QueryRedRainDto
;
import
com.polysoft.activity.model.vo.ActItemVO
;
import
com.polysoft.activity.model.vo.ActItemVO
;
import
com.polysoft.activity.model.vo.RedRainVO
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.Mapper
;
...
@@ -19,4 +21,6 @@ public interface ActivityMapper extends BaseMapper<ActItemDto> {
...
@@ -19,4 +21,6 @@ public interface ActivityMapper extends BaseMapper<ActItemDto> {
List
<
ActItemVO
>
queryActivityInfo
();
List
<
ActItemVO
>
queryActivityInfo
();
int
updateActStatus
(
@Param
(
"id"
)
Long
id
,
@Param
(
"status"
)
int
status
);
int
updateActStatus
(
@Param
(
"id"
)
Long
id
,
@Param
(
"status"
)
int
status
);
int
saveRedRain
(
@Param
(
"list"
)
List
<
AddRedRainDto
>
list
);
int
saveRedRain
(
@Param
(
"list"
)
List
<
AddRedRainDto
>
list
);
List
<
RedRainVO
>
queryRedRainList
(
QueryRedRainDto
dto
);
int
updateRedPackage
(
List
<
AddRedRainDto
>
dto
);
}
}
activity-admin/src/main/java/com/polysoft/activity/model/dto/AddRedRainDto.java
View file @
17ac7f9
...
@@ -17,12 +17,14 @@ public class AddRedRainDto {
...
@@ -17,12 +17,14 @@ public class AddRedRainDto {
//红包金额
//红包金额
private
String
redAmount
;
private
String
redAmount
;
//红包类型 0 普通红包 1 牛牌
//红包类型 0 普通红包 1 牛牌
private
Long
redType
;
private
int
redType
;
//牛牌主键
//牛牌主键
private
Long
cattleBrandId
;
private
Long
cattleBrandId
;
private
String
createTime
;
private
String
createTime
;
//0 未结算 1 已结算
//0 未结算 1 已结算
private
int
isEnble
;
private
int
isEnble
;
//红包雨批次号
private
int
batchNum
;
public
void
setCreateTime
(
Date
date
)
{
public
void
setCreateTime
(
Date
date
)
{
this
.
createTime
=
DateUtil
.
format
(
date
,
"yyyy-MM-dd HH:mm:ss"
);
this
.
createTime
=
DateUtil
.
format
(
date
,
"yyyy-MM-dd HH:mm:ss"
);
...
...
activity-admin/src/main/java/com/polysoft/activity/model/dto/QueryRedRainDto.java
0 → 100644
View file @
17ac7f9
package
com
.
polysoft
.
activity
.
model
.
dto
;
import
lombok.Data
;
/**
* @author lvyp
* @date 2021/1/28
*/
@Data
public
class
QueryRedRainDto
{
//用户主键
private
Long
userId
;
//红包类型 0 普通红包 1 牛牌
private
Long
redType
;
//0 未结算 1 已结算
private
int
isEnble
;
//红包雨批次号
private
int
batchNum
;
}
activity-admin/src/main/java/com/polysoft/activity/model/param/AddRedRainParam.java
View file @
17ac7f9
...
@@ -11,4 +11,5 @@ import lombok.Data;
...
@@ -11,4 +11,5 @@ import lombok.Data;
public
class
AddRedRainParam
{
public
class
AddRedRainParam
{
private
Long
userId
;
private
Long
userId
;
private
int
redNum
;
private
int
redNum
;
private
int
batchNum
;
}
}
activity-admin/src/main/java/com/polysoft/activity/model/vo/RedRainVO.java
0 → 100644
View file @
17ac7f9
package
com
.
polysoft
.
activity
.
model
.
vo
;
import
cn.hutool.core.date.DateUtil
;
import
lombok.Data
;
import
java.util.Date
;
/**
* @author lvyp
* @date 2021/1/28
*/
@Data
public
class
RedRainVO
{
private
Long
redId
;
//用户主键
private
Long
userId
;
//红包金额
private
String
redAmount
;
//红包类型 0 普通红包 1 牛牌
private
int
redType
;
//牛牌主键
private
Long
cattleBrandId
;
//0 未结算 1 已结算
private
int
isEnble
;
//红包雨批次号
private
int
batchNum
;
}
activity-admin/src/main/java/com/polysoft/activity/service/impl/ActItemServiceImpl.java
View file @
17ac7f9
...
@@ -61,6 +61,7 @@ public class ActItemServiceImpl implements ActItemService{
...
@@ -61,6 +61,7 @@ public class ActItemServiceImpl implements ActItemService{
dto
.
setRedId
(
SnowFlakeUtil
.
nextId
());
dto
.
setRedId
(
SnowFlakeUtil
.
nextId
());
dto
.
setUserId
(
param
.
getUserId
());
dto
.
setUserId
(
param
.
getUserId
());
dto
.
setCreateTime
(
date
);
dto
.
setCreateTime
(
date
);
dto
.
setBatchNum
(
param
.
getBatchNum
());
list
.
add
(
dto
);
list
.
add
(
dto
);
}
}
activityMapper
.
saveRedRain
(
list
);
activityMapper
.
saveRedRain
(
list
);
...
...
activity-admin/src/main/java/com/polysoft/activity/task/InitRedPackageTask.java
View file @
17ac7f9
package
com
.
polysoft
.
activity
.
task
;
package
com
.
polysoft
.
activity
.
task
;
import
cn.hutool.core.date.DateUtil
;
import
com.polysoft.activity.common.log.LoggerHelper
;
import
com.polysoft.activity.common.log.LoggerHelper
;
import
com.polysoft.activity.common.utils.BeanTransferUtils
;
import
com.polysoft.activity.mapper.ActivityMapper
;
import
com.polysoft.activity.model.dto.AddRedRainDto
;
import
com.polysoft.activity.model.dto.QueryRedRainDto
;
import
com.polysoft.activity.model.vo.RedRainVO
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.text.DecimalFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Random
;
/**
/**
* @author lvyp
* @author lvyp
...
@@ -15,14 +29,191 @@ import org.springframework.stereotype.Component;
...
@@ -15,14 +29,191 @@ import org.springframework.stereotype.Component;
@EnableScheduling
@EnableScheduling
public
class
InitRedPackageTask
{
public
class
InitRedPackageTask
{
@Resource
private
ActivityMapper
activityMapper
;
// @Scheduled(initialDelay = 10000, fixedRate = 1*15*60*1000)
// @Scheduled(initialDelay = 10000, fixedRate = 1*15*60*1000)
@Scheduled
(
cron
=
"20 59 17 * * ? "
)
public
void
execute
()
{
public
void
execute
()
{
sendWechat
();
sendWechat
();
}
}
private
void
sendWechat
(){
private
void
sendWechat
(){
//红包雨开始时间
// Long batch1 = DateUtil.parse("2021-02-11 20:00:00","yyyy-MM-dd HH:mm:ss").getTime()/1000;
// Long batch2 = DateUtil.parse("2021-02-11 22:00:00","yyyy-MM-dd HH:mm:ss").getTime()/1000;
// Long batch3 = DateUtil.parse("2021-02-12 00:00:00","yyyy-MM-dd HH:mm:ss").getTime()/1000;
// Long currentTime = System.currentTimeMillis()/1000;
// int batchNum = 0;
// if(currentTime < batch1){
// return;
// }
// if(currentTime > batch1 && currentTime<batch2){
// batchNum = 1;
// }
// if(currentTime > batch2 && currentTime<batch3){
// batchNum = 2;
// }
// if(currentTime > batch3 ){
// batchNum = 3;
// }
//查询出没有初始化的红包
//查询出没有初始化的红包
int
batchNum
=
1
;
double
totalMoney
=
5000.00
;
if
(
1
==
1
){
QueryRedRainDto
dto
=
new
QueryRedRainDto
();
List
<
AddRedRainDto
>
batchList
=
new
ArrayList
<>();
dto
.
setIsEnble
(
0
);
dto
.
setBatchNum
(
batchNum
);
List
<
RedRainVO
>
list
=
activityMapper
.
queryRedRainList
(
dto
);
//前10%红包
int
redNum
=
(
int
)(
list
.
size
()*
0.1
);
double
[]
redAmount
=
getMoney
(
5000.00
*
0.25
,
redNum
);
HashSet
<
Integer
>
set
=
getLuckUser
(
redNum
,
list
.
size
());
int
i
=
0
;
for
(
Integer
s
:
set
)
{
AddRedRainDto
addRedRainDto
=
BeanTransferUtils
.
transfer
(
list
.
get
(
s
),
AddRedRainDto
.
class
);
addRedRainDto
.
setRedAmount
(
redAmount
[
i
]+
""
);
addRedRainDto
.
setRedType
(
1
);
addRedRainDto
.
setIsEnble
(
1
);
batchList
.
add
(
addRedRainDto
);
i
++;
}
activityMapper
.
updateRedPackage
(
batchList
);
}
//20%红包
if
(
2
==
2
){
//获取红包总数
QueryRedRainDto
dto
=
new
QueryRedRainDto
();
List
<
AddRedRainDto
>
batchList
=
new
ArrayList
<>();
dto
.
setBatchNum
(
batchNum
);
List
<
RedRainVO
>
list
=
activityMapper
.
queryRedRainList
(
dto
);
//获取未结算的红包数
QueryRedRainDto
dto2
=
new
QueryRedRainDto
();
List
<
AddRedRainDto
>
batchList2
=
new
ArrayList
<>();
dto2
.
setIsEnble
(
0
);
dto2
.
setBatchNum
(
batchNum
);
List
<
RedRainVO
>
list2
=
activityMapper
.
queryRedRainList
(
dto
);
//前20%红包
int
redNum
=
(
int
)(
list
.
size
()*
0.2
);
double
[]
redAmount
=
getMoney
(
5000.00
*
0.25
,
redNum
);
HashSet
<
Integer
>
set
=
getLuckUser
(
redNum
,
list2
.
size
());
int
i
=
0
;
for
(
Integer
s
:
set
)
{
AddRedRainDto
addRedRainDto
=
BeanTransferUtils
.
transfer
(
list
.
get
(
s
),
AddRedRainDto
.
class
);
addRedRainDto
.
setRedAmount
(
redAmount
[
i
]+
""
);
addRedRainDto
.
setRedType
(
1
);
addRedRainDto
.
setIsEnble
(
1
);
batchList2
.
add
(
addRedRainDto
);
i
++;
}
activityMapper
.
updateRedPackage
(
batchList2
);
}
if
(
3
==
3
){
//获取红包总数
QueryRedRainDto
dto
=
new
QueryRedRainDto
();
List
<
AddRedRainDto
>
batchList
=
new
ArrayList
<>();
dto
.
setBatchNum
(
batchNum
);
List
<
RedRainVO
>
list
=
activityMapper
.
queryRedRainList
(
dto
);
//获取未结算的红包数
QueryRedRainDto
dto2
=
new
QueryRedRainDto
();
List
<
AddRedRainDto
>
batchList2
=
new
ArrayList
<>();
dto2
.
setIsEnble
(
0
);
dto2
.
setBatchNum
(
batchNum
);
List
<
RedRainVO
>
list2
=
activityMapper
.
queryRedRainList
(
dto
);
//前65%红包
int
redNum
=
(
int
)(
list
.
size
()*
0.65
);
double
[]
redAmount
=
getMoney
(
5000.00
*
0.4
,
redNum
);
HashSet
<
Integer
>
set
=
getLuckUser
(
redNum
,
list2
.
size
());
int
i
=
0
;
for
(
Integer
s
:
set
)
{
AddRedRainDto
addRedRainDto
=
BeanTransferUtils
.
transfer
(
list
.
get
(
s
),
AddRedRainDto
.
class
);
addRedRainDto
.
setRedAmount
(
redAmount
[
i
]+
""
);
addRedRainDto
.
setRedType
(
1
);
addRedRainDto
.
setIsEnble
(
1
);
batchList2
.
add
(
addRedRainDto
);
i
++;
}
activityMapper
.
updateRedPackage
(
batchList2
);
}
if
(
4
==
4
){
//获取红包总数
QueryRedRainDto
dto
=
new
QueryRedRainDto
();
List
<
AddRedRainDto
>
batchList
=
new
ArrayList
<>();
dto
.
setBatchNum
(
batchNum
);
List
<
RedRainVO
>
list
=
activityMapper
.
queryRedRainList
(
dto
);
//获取未结算的红包数
QueryRedRainDto
dto2
=
new
QueryRedRainDto
();
List
<
AddRedRainDto
>
batchList2
=
new
ArrayList
<>();
dto2
.
setIsEnble
(
0
);
dto2
.
setBatchNum
(
batchNum
);
List
<
RedRainVO
>
list2
=
activityMapper
.
queryRedRainList
(
dto
);
//前5%红包
int
redNum
=
list2
.
size
();
double
[]
redAmount
=
getMoney
(
5000.00
*
0.10
,
redNum
);
HashSet
<
Integer
>
set
=
getLuckUser
(
redNum
,
list2
.
size
());
int
i
=
0
;
for
(
Integer
s
:
set
)
{
AddRedRainDto
addRedRainDto
=
BeanTransferUtils
.
transfer
(
list
.
get
(
s
),
AddRedRainDto
.
class
);
addRedRainDto
.
setRedAmount
(
redAmount
[
i
]+
""
);
addRedRainDto
.
setRedType
(
1
);
addRedRainDto
.
setIsEnble
(
1
);
batchList2
.
add
(
addRedRainDto
);
i
++;
}
activityMapper
.
updateRedPackage
(
batchList2
);
}
}
private
HashSet
<
Integer
>
getLuckUser
(
int
count
,
int
random
){
HashSet
<
Integer
>
has
=
new
HashSet
<
Integer
>();
Integer
i
=
0
;
for
(
int
j
=
1
;
j
!=
0
;
j
++)
{
i
=
new
Random
().
nextInt
(
random
);
has
.
add
(
i
);
if
(
count
==
has
.
size
())
{
break
;
}
}
return
has
;
}
private
double
[]
getMoney
(
double
money
,
int
num
){
Random
r
=
new
Random
();
DecimalFormat
format
=
new
DecimalFormat
(
".##"
);
double
middle
=
Double
.
parseDouble
(
format
.
format
(
money
/
num
));
double
[]
dou
=
new
double
[
num
];
double
redMoney
=
0
;
double
nextMoney
=
money
;
double
sum
=
0
;
int
index
=
0
;
for
(
int
i
=
num
;
i
>
0
;
i
--){
if
(
i
==
1
){
dou
[
index
]
=
nextMoney
;
}
else
{
while
(
true
){
String
str
=
format
.
format
(
r
.
nextDouble
()*
nextMoney
);
redMoney
=
Double
.
parseDouble
(
str
);
if
(
redMoney
>
0
&&
redMoney
<
middle
){
break
;
}
}
nextMoney
=
Double
.
parseDouble
(
format
.
format
(
nextMoney
-
redMoney
));
sum
=
sum
+
redMoney
;
dou
[
index
]
=
redMoney
;
middle
=
Double
.
parseDouble
(
format
.
format
(
nextMoney
/(
i
-
1
)));
index
++;
}
}
return
dou
;
}
public
static
void
main
(
String
[]
args
)
{
double
[]
ss
=
new
InitRedPackageTask
().
getMoney
(
5000.00
*
0.25
,
100
);
for
(
double
s
:
ss
)
{
System
.
out
.
println
(
s
);
}
}
}
}
}
activity-admin/src/main/resources/mapper/ActivityMapper.xml
View file @
17ac7f9
...
@@ -5,13 +5,15 @@
...
@@ -5,13 +5,15 @@
INSERT into t_red_rain (
INSERT into t_red_rain (
red_id,
red_id,
user_id,
user_id,
create_time
create_time,
batch_num
)VALUES
)VALUES
<foreach
collection=
"list"
item=
"item"
index=
"index"
separator =
","
>
<foreach
collection=
"list"
item=
"item"
index=
"index"
separator =
","
>
(
(
#{item.redId},
#{item.redId},
#{item.userId},
#{item.userId},
#{item.createTime}
#{item.createTime},
#{item.batchNum}
)
)
</foreach>
</foreach>
</insert>
</insert>
...
@@ -20,6 +22,31 @@
...
@@ -20,6 +22,31 @@
set activity_status=#{status}
set activity_status=#{status}
where id =#{id}
where id =#{id}
</update>
</update>
<update
id=
"updateRedPackage"
parameterType=
"java.util.List"
>
update t_red_rain
<trim
prefix=
"set"
suffixOverrides=
","
>
<trim
prefix=
" red_amount = case"
suffix=
"end,"
>
<foreach
collection=
"list"
item=
"item"
index=
"index"
>
when red_id=#{item.redId} then #{item.redAmount}
</foreach>
</trim>
<trim
prefix=
" red_type = case"
suffix=
"end,"
>
<foreach
collection=
"list"
item=
"item"
index=
"index"
>
when red_id=#{item.redId} then #{item.redType}
</foreach>
</trim>
<trim
prefix=
" is_enble = case"
suffix=
"end,"
>
<foreach
collection=
"list"
item=
"item"
index=
"index"
>
when red_id=#{item.redId} then #{item.isEnble}
</foreach>
</trim>
</trim>
<where>
<foreach
collection=
"list"
separator=
"or"
item=
"item"
index=
"index"
>
red_id=#{item.redId}
</foreach>
</where>
</update>
<select
id=
"queryActivityInfo"
resultType=
"com.polysoft.activity.model.vo.ActItemVO"
>
<select
id=
"queryActivityInfo"
resultType=
"com.polysoft.activity.model.vo.ActItemVO"
>
SELECT
SELECT
...
@@ -32,5 +59,28 @@
...
@@ -32,5 +59,28 @@
act_item ORDER by id asc
act_item ORDER by id asc
</select>
</select>
<select
id=
"queryRedRainList"
resultType=
"com.polysoft.activity.model.vo.RedRainVO"
parameterType=
"com.polysoft.activity.model.dto.QueryRedRainDto"
>
select
red_id,
user_id,
red_amount,
red_type,
is_enble
from t_red_rain where
<if
test=
"isEnble !=null and isEnble !='' "
>
is_enble = #{isEnble}
</if>
<if
test=
"userId !=null and userId !='' "
>
user_id = #{userId}
</if>
<if
test=
"redType !=null and redType !='' "
>
red_type = #{redType}
</if>
<if
test=
"batchNum !=null and batchNum !='' "
>
batch_num = #{batchNum}
</if>
order by red_id asc
</select>
</mapper>
</mapper>
Write
Preview
Markdown
is supported
Attach a file
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 post a comment