package com.ld.igds.timer;
|
|
import com.bstek.dorado.annotation.Expose;
|
import com.ld.igds.common.CoreCommonService;
|
import com.ld.igds.es.dto.EsParam;
|
import com.ld.igds.es.manager.EsManager;
|
import com.ld.igds.es.service.CoreEsService;
|
import com.ld.igds.io.constant.OrderRespEnum;
|
import com.ld.igds.io.response.BaseResponse;
|
import com.ld.igds.models.DepotConf;
|
import com.ld.igds.util.ContextUtil;
|
import com.ld.igds.util.DateUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 能耗数据获取,当前协议为自动调用,系统每间隔1个小时获取一次
|
* <p>
|
* 由于加载的优先级问题,这里直接用Resource引入,并且指定实现类
|
*/
|
@Slf4j
|
@Component(EsScheduled.BEAN_ID)
|
public class EsScheduled {
|
|
public static final String BEAN_ID = "basic.esScheduled";
|
|
@Resource(name = CoreCommonService.BEAN_ID)
|
private CoreCommonService coreCommonService;
|
|
@Resource(name = CoreEsService.BEAN_ID)
|
private CoreEsService coreEsService;
|
|
|
@Resource
|
private EsManager esManager;
|
|
/**
|
* @Scheduled(cron = "1 0 * * * ?")
|
* 能耗获取定时器,每小时执行一次,执行时间为每个小时的第一秒
|
* @Scheduled(cron = "0 0 8,20 * * ?")
|
* 每天的早上8点和晚上8点执行两次
|
*/
|
@Scheduled(cron = "1 0 * * * ?")
|
public void scheduled() {
|
doExe(null);
|
}
|
|
|
|
/**
|
* 大屏页面能耗信息推送,每天早上9点更新并推送
|
*/
|
@Scheduled(cron = "0 0 9 * * ?")
|
public void scheduled2() {
|
log.info("===================系统定时推送能耗信息=======================");
|
EsParam esParam = new EsParam();
|
esParam.setCompanyId(ContextUtil.getDefaultCompanyId());
|
esParam.setStart(DateUtil.getNewByDay(new Date(), -15));
|
|
coreEsService.queryScreenEsChart(esParam, true);
|
}
|
|
public void doExe(String companyId) {
|
log.info("===================系统定时能耗检测=======================");
|
|
if(null == companyId){
|
companyId = ContextUtil.getDefaultCompanyId();
|
}
|
|
List<DepotConf> list = coreCommonService.getCacheDepotConf(companyId);
|
|
if (null == list || list.isEmpty()) return;
|
|
BaseResponse response;
|
for (DepotConf depotConf : list) {
|
|
if(null == depotConf.getEsSer()) continue;
|
response = esManager.checkEsByConf(depotConf);
|
|
if (!OrderRespEnum.ORDER_SUCCESS.getCode().equals(response.getCode())) {
|
log.error("----自动调用能耗执行失败,仓库={},失败原因={}", depotConf.getDepotName(), response.getMsg());
|
}
|
}
|
}
|
|
|
/**
|
*
|
* basic.esScheduled#doExeByHand
|
* 手动触发检测
|
*/
|
@Expose
|
public void doExeByHand() {
|
|
log.info("----------------------手动触发能耗统一检测----------------{}",ContextUtil.getLoginUserName());
|
String companyId = ContextUtil.getCompanyId();
|
doExe(companyId);
|
}
|
}
|