jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.ld.igds.timer;
 
import com.bstek.bdf2.core.model.DefaultCompany;
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.view.manager.TempManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * 粮情管理模块的定时器配置:
 * 1、每间隔1个小时获取下所有分机配置的温湿度信息
 */
@Slf4j
@Component(ThScheduled.BEAN_ID)
public class ThScheduled {
 
    public static final String BEAN_ID = "basic.grainScheduled";
 
    @Resource
    private TempManager thManager;
 
    @Resource
    private CoreCommonService coreCommonService;
 
 
    /**
     * 每小时执行一次,执行时间为每个小时的第一秒
     * 2022年6月27日 11:05:31 修改为20 分钟执行一次
     */
    @Scheduled(cron = "0 0/20 * * * ?")
    public void scheduled() {
        List<DefaultCompany> list = coreCommonService.getCompanyList();
        if (null == list || list.isEmpty()) return;
 
        for (DefaultCompany company : list) {
            doExe(company.getId());
            try {
                Thread.sleep(500);
            } catch (Exception e) {
                e.getStackTrace();
            }
        }
 
    }
 
 
    public void doExe(String companyId) {
        log.info("===================系统定时获取分机下的温湿度信息-{}=======================", companyId);
        thManager.scheduledCheck(companyId);
    }
}