#
Junjie
昨天 b3f70386af87bb9e6bf87270d23ba2a8634c32d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.zy.asrs.task;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zy.asrs.service.PlannerService;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
@Component
public class PlannerScheduler {
 
    @Autowired
    private PlannerService plannerService;
    @Autowired
    private ConfigService configService;
 
    // 每3秒触发一次求解
    @Scheduled(fixedDelay = 3000)
    public void schedulePlanner() {
        try {
            String crnRunMethod = "normal";
            Config crnRunMethodConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "crnRunMethod"));
            if(crnRunMethodConfig != null) {
                crnRunMethod = crnRunMethodConfig.getValue();
            }
 
            if (!crnRunMethod.equals("solver")) {
                return;
            }
            JSONObject result = plannerService.calculateAndSaveSchedule();
            // 日志记录可以根据需要添加,避免过于频繁
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}