Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
软件工程实践2022年春W班
Followers
TeamPractice4
提交
446a6be4
T
TeamPractice4
项目概览
软件工程实践2022年春W班
/
Followers
/
TeamPractice4
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TeamPractice4
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
446a6be4
编写于
4月 23, 2022
作者:
IIIllI
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
定时工具类,可传参任务
上级
e2d200f3
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
43 addition
and
20 deletion
+43
-20
backend/src/main/java/com/nav/dao/ParticipantDao.java
backend/src/main/java/com/nav/dao/ParticipantDao.java
+2
-0
backend/src/main/java/com/nav/service/ParticipantService.java
...end/src/main/java/com/nav/service/ParticipantService.java
+3
-0
backend/src/main/java/com/nav/service/ParticipantServiceImp.java
.../src/main/java/com/nav/service/ParticipantServiceImp.java
+6
-0
backend/src/main/java/com/nav/utils/Draw.java
backend/src/main/java/com/nav/utils/Draw.java
+12
-3
backend/src/main/java/com/nav/utils/Quartz.java
backend/src/main/java/com/nav/utils/Quartz.java
+12
-15
backend/src/main/resources/mapper/PaticipantMapper.xml
backend/src/main/resources/mapper/PaticipantMapper.xml
+8
-2
未找到文件。
backend/src/main/java/com/nav/dao/ParticipantDao.java
浏览文件 @
446a6be4
...
...
@@ -15,4 +15,6 @@ public interface ParticipantDao {
public
List
<
Award
>
getAward
(
Long
id
);
public
int
addParticipants
(
Long
userId
,
Long
activityId
);
public
List
<
User
>
getAllParticipants
();
}
backend/src/main/java/com/nav/service/ParticipantService.java
浏览文件 @
446a6be4
...
...
@@ -11,4 +11,7 @@ public interface ParticipantService {
//查询中奖名单 活动id
public
List
<
Award
>
selectAwardList
(
Long
id
);
//参与抽奖
public
void
participateDraw
(
Long
userId
,
Long
activityId
);
}
backend/src/main/java/com/nav/service/ParticipantServiceImp.java
浏览文件 @
446a6be4
...
...
@@ -23,4 +23,10 @@ public class ParticipantServiceImp implements ParticipantService {
public
List
<
Award
>
selectAwardList
(
Long
id
)
{
return
participantDao
.
getAward
(
id
);
}
@Override
public
void
participateDraw
(
Long
userId
,
Long
activityId
)
{
participantDao
.
addParticipants
(
userId
,
userId
);
}
}
backend/src/main/java/com/nav/
pojo
/Draw.java
→
backend/src/main/java/com/nav/
utils
/Draw.java
浏览文件 @
446a6be4
package
com.nav.
pojo
;
package
com.nav.
utils
;
import
org.quartz.JobDataMap
;
import
org.quartz.JobExecutionContext
;
import
org.quartz.JobExecutionException
;
import
org.
springframework.context.annotation.Scope
;
import
org.
quartz.JobKey
;
import
org.springframework.scheduling.quartz.QuartzJobBean
;
import
java.util.Date
;
public
class
Draw
extends
QuartzJobBean
{
@Override
protected
void
executeInternal
(
JobExecutionContext
context
)
throws
JobExecutionException
{
System
.
out
.
println
(
"简单的定时任务执行时间:"
+
new
Date
());
JobKey
jobKey
=
context
.
getJobDetail
().
getKey
();
JobDataMap
jobDataMap
=
context
.
getMergedJobDataMap
();
System
.
out
.
println
(
"id: "
+
jobDataMap
.
getLong
(
"id"
)+
"jobKey: "
+
jobKey
);
}
}
backend/src/main/java/com/nav/
controller/QuartzController
.java
→
backend/src/main/java/com/nav/
utils/Quartz
.java
浏览文件 @
446a6be4
package
com.nav.
controller
;
package
com.nav.
utils
;
import
com.nav.
pojo
.Draw
;
import
com.nav.
utils
.Draw
;
import
org.quartz.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.quartz.SchedulerFactoryBean
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Random
;
@RestController
public
class
QuartzController
{
@Autowired
SchedulerFactoryBean
schedulerFactoryBean
;
public
class
Quartz
{
@GetMapping
(
"/add"
)
public
void
init
()
throws
SchedulerException
,
ParseException
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
Date
date
=
format
.
parse
(
"2022-04-23 17:00:45"
);
//public static SchedulerFactoryBean schedulerFactoryBean;
public
static
void
autoDraw
(
SchedulerFactoryBean
schedulerFactoryBean
,
Date
date
,
Long
activityID
)
throws
SchedulerException
,
ParseException
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
Date
test
=
format
.
parse
(
"2022-04-23 19:45:00"
);
Scheduler
scheduler
=
schedulerFactoryBean
.
getScheduler
();
JobDetail
jobDetail
=
JobBuilder
.
newJob
(
Draw
.
class
)
.
withIdentity
(
createRandomStr
(
10
))
.
usingJobData
(
"id"
,
activityID
)
.
storeDurably
()
.
build
();
Trigger
trigger
=
TriggerBuilder
.
newTrigger
()
Trigger
trigger
=
TriggerBuilder
.
newTrigger
()
.
forJob
(
jobDetail
)
//关联上述的JobDetail
.
withIdentity
(
createRandomStr
(
10
))
//给Trigger起个名字
.
withSchedule
(
SimpleScheduleBuilder
.
simpleSchedule
().
withRepeatCount
(
0
))
// 重复次数 执行一次不重复
...
...
@@ -39,7 +36,7 @@ public class QuartzController {
scheduler
.
scheduleJob
(
jobDetail
,
trigger
);
}
public
static
String
createRandomStr
(
int
length
){
public
static
String
createRandomStr
(
int
length
)
{
String
str
=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
;
Random
random
=
new
Random
();
StringBuffer
stringBuffer
=
new
StringBuffer
();
...
...
backend/src/main/resources/mapper/PaticipantMapper.xml
浏览文件 @
446a6be4
...
...
@@ -5,8 +5,8 @@
<mapper
namespace=
"com.nav.dao.ParticipantDao"
>
<select
id=
"getParticipants"
parameterType=
"long"
resultType=
"com.nav.pojo.User"
>
select *
from
participant
where
activity_id = #{id}
;
from
user
where
id in (select user_id from participant where activity_id = #{1})
;
</select>
<select
id=
"getAward"
parameterType=
"long"
resultType=
"com.nav.pojo.Award"
>
...
...
@@ -17,6 +17,12 @@
and participant.user_id = `user`.id
</select>
<select
id=
"getAllParticipants"
resultType=
"com.nav.pojo.User"
>
select *
from user
where id in (select user_id from participant);
</select>
<insert
id=
"addParticipants"
parameterType=
"long"
>
insert into participant (user_id, activity_id, state)
values (#{userId}, #{activityID}, 0)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录