Toggle navigation
Toggle navigation
This project
Loading...
Sign in
jiujian
/
client-customer-order-service
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
wangyingyang
2024-12-03 14:28:40 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a874c44f3b3fcea89886a5f6d4c49edd4c70de7e
a874c44f
1 parent
555b3281
add scheduled task
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
src/main/java/com/tianting/infoloop/task/ScheduledTask.java
src/main/java/com/tianting/infoloop/task/ScheduledTask.java
0 → 100644
View file @
a874c44
package
com
.
tianting
.
infoloop
.
task
;
import
cn.hutool.core.date.LocalDateTimeUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.infoloop.tianting.clientcustomerorderservice.OrderStatusEnum
;
import
com.tianting.infoloop.mapper.OrderDbMapper
;
import
com.tianting.infoloop.model.db.OrderDb
;
import
com.tianting.infoloop.service.OrderDbService
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
@Component
@EnableScheduling
@RequiredArgsConstructor
(
onConstructor_
=
@Autowired
)
public
class
ScheduledTask
{
private
final
OrderDbService
orderDbService
;
private
final
OrderDbMapper
orderDbMapper
;
// 每5秒执行一次的定时任务
// @Scheduled(fixedRate = 5000)
// public void task1() {
// System.out.println("定时任务1:每5秒执行一次,当前时间:" + System.currentTimeMillis());
// }
// 每天凌晨2点执行一次的定时任务
@Scheduled
(
cron
=
"0 0 1 * * *"
)
public
void
taskForUpdateOrderStatus
()
{
LocalDate
today
=
LocalDate
.
now
();
LocalDateTime
todayZero
=
today
.
atStartOfDay
();
LocalDate
tomorrow
=
today
.
plusDays
(
1
);
LocalDateTime
tomorrowZero
=
tomorrow
.
atStartOfDay
();
LambdaQueryWrapper
<
OrderDb
>
queryWrapper
=
Wrappers
.
lambdaQuery
();
queryWrapper
.
eq
(
OrderDb:
:
getStatus
,
OrderStatusEnum
.
TO_PREPARE
.
getNumber
());
queryWrapper
.
ge
(
OrderDb:
:
getMealTime
,
LocalDateTimeUtil
.
of
(
todayZero
));
queryWrapper
.
le
(
OrderDb:
:
getMealTime
,
LocalDateTimeUtil
.
of
(
tomorrowZero
));
final
var
list
=
orderDbService
.
list
(
queryWrapper
);
for
(
OrderDb
orderDb:
list
)
{
orderDb
.
setStatus
(
OrderStatusEnum
.
PREPARING_VALUE
);
orderDbMapper
.
updateById
(
orderDb
);
}
}
}
\ No newline at end of file
Please
register
or
login
to post a comment