From b1d580117dbb2386bb0502c7a303209bd2513f6c Mon Sep 17 00:00:00 2001 From: "rong.liu" Date: Thu, 11 Mar 2021 11:49:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=88=B0=E7=82=B9=E8=80=83?= =?UTF-8?q?=E6=A0=B8=E4=B8=8D=E8=87=AA=E5=90=AF=E5=8A=A8=E3=80=81=E4=B8=8D?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=BB=93=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/msdw/tms/TmsApplication.java | 2 + .../controller/ClockScheduledController.java | 76 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/main/java/com/msdw/tms/controller/ClockScheduledController.java diff --git a/src/main/java/com/msdw/tms/TmsApplication.java b/src/main/java/com/msdw/tms/TmsApplication.java index 4bf070b..e2715d0 100644 --- a/src/main/java/com/msdw/tms/TmsApplication.java +++ b/src/main/java/com/msdw/tms/TmsApplication.java @@ -4,7 +4,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.scheduling.annotation.EnableScheduling; +@EnableScheduling//定时任务 @SpringBootApplication public class TmsApplication extends SpringBootServletInitializer { diff --git a/src/main/java/com/msdw/tms/controller/ClockScheduledController.java b/src/main/java/com/msdw/tms/controller/ClockScheduledController.java new file mode 100644 index 0000000..a2eb0b4 --- /dev/null +++ b/src/main/java/com/msdw/tms/controller/ClockScheduledController.java @@ -0,0 +1,76 @@ +package com.msdw.tms.controller; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.msdw.tms.entity.ExperimentalTeachingEntity; +import com.msdw.tms.service.ExperimentalTeachingService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; + + +/** + * @ProjectName: gzedu + * @Package: com.huoran.user.controller + * @ClassName: test + * @Description: java类作用描述 + * @Author: Maureen.Rong + * @CreateDate: 2020/12/7 11:35 + * @UpdateDate: 2020/12/7 11:35 + * @Version: 1.0 + */ +@Component +@RestController +public class ClockScheduledController { + + @Autowired + public ExperimentalTeachingService service; + + //考核自启动 + @Scheduled(fixedRate = 1000) + public void timer1() { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("type", 2); + queryWrapper.eq("is_del", 0); + queryWrapper.eq("status", 1); + queryWrapper.last(" AND start_time = now() "); + List list = service.list(queryWrapper); + if (list.size() > 0) { + for (ExperimentalTeachingEntity experimentalTeaching : list) { + //启动考核 + ExperimentalTeachingEntity update = new ExperimentalTeachingEntity(); + update.setStatus(2); + update.setId(experimentalTeaching.getId()); + service.updateById(update); + } + } + + + QueryWrapper queryWrapper1 = new QueryWrapper<>(); + queryWrapper1.eq("type", 2); + queryWrapper1.eq("is_del", 0); + queryWrapper1.eq("status", 2); + queryWrapper1.last(" AND start_time = now() "); + List list1 = service.list(queryWrapper); + if (list1.size() > 0) { + for (ExperimentalTeachingEntity experimentalTeaching : list1) { + //停止考核 + ExperimentalTeachingEntity update = new ExperimentalTeachingEntity(); + update.setStatus(3); + update.setId(experimentalTeaching.getId()); + service.updateById(update); + } + } + + } + + + public static void main(String[] args) { + new ClockScheduledController().timer1(); + } +}