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