解决到点考核不自启动、不自动结束

hehai
rong.liu 4 years ago
parent fd9a20a400
commit b1d580117d
  1. 2
      src/main/java/com/msdw/tms/TmsApplication.java
  2. 76
      src/main/java/com/msdw/tms/controller/ClockScheduledController.java

@ -4,7 +4,9 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling//定时任务
@SpringBootApplication @SpringBootApplication
public class TmsApplication extends SpringBootServletInitializer { public class TmsApplication extends SpringBootServletInitializer {

@ -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<ExperimentalTeachingEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("type", 2);
queryWrapper.eq("is_del", 0);
queryWrapper.eq("status", 1);
queryWrapper.last(" AND start_time = now() ");
List<ExperimentalTeachingEntity> 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<ExperimentalTeachingEntity> queryWrapper1 = new QueryWrapper<>();
queryWrapper1.eq("type", 2);
queryWrapper1.eq("is_del", 0);
queryWrapper1.eq("status", 2);
queryWrapper1.last(" AND start_time = now() ");
List<ExperimentalTeachingEntity> 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();
}
}
Loading…
Cancel
Save