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(); + } +}