package com.fzzy.protocol;
|
|
import com.fzzy.api.data.GatewayDeviceProtocol;
|
import com.fzzy.gateway.GatewayUtils;
|
import com.fzzy.gateway.data.BaseReqData;
|
import com.fzzy.gateway.entity.GatewayDevice;
|
import com.fzzy.protocol.zldz.service.ZldzGatewayGrainService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.util.Collection;
|
import java.util.Date;
|
|
|
/**
|
* 协议相关的定时器,全局定时器,包含所有的协议,逻辑处理是否执行
|
*/
|
@Slf4j
|
@Component(ProtocolScheduled.BEAN_ID)
|
public class ProtocolScheduled {
|
|
public static final String BEAN_ID = "protocol.Scheduled";
|
|
|
@Resource
|
private ZldzGatewayGrainService zldzGatewayGrainService;
|
|
|
/**
|
* 从6-19点每小时执行一次
|
* cron = "0 0 6-19 * * ? *"
|
*/
|
@Scheduled(cron = "0 0 6-19 * * ? ")
|
public void scheduled() {
|
|
Date cur = new Date();
|
|
log.info("--------------系统执行定时数据同步操作--------------");
|
|
//正来电子协议-定时任务
|
this.scheduledZldz(cur);
|
|
|
}
|
|
/**
|
* 正来电子定时任务
|
*
|
* @param cur
|
*/
|
private void scheduledZldz(Date cur) {
|
|
//获取设备列表
|
Collection<GatewayDevice> list = GatewayUtils.allCacheDevice();
|
|
try {
|
BaseReqData reqData;
|
for (GatewayDevice device : list) {
|
|
if (null == device.getSyncProtocol()) continue;
|
|
if (!GatewayDeviceProtocol.GRAIN_FZZY_ZLDZ_WEB.getCode().equals(device.getSyncProtocol())) {
|
continue;
|
}
|
|
reqData = new BaseReqData();
|
reqData.setDeviceId(device.getDeviceId());
|
reqData.setProductId(device.getProductId());
|
reqData.setDeviceName(device.getDeviceName());
|
reqData.setDevice(device);
|
|
zldzGatewayGrainService.syncGrainTh(reqData);
|
|
Thread.sleep(500);
|
}
|
|
} catch (Exception e) {
|
|
}
|
}
|
|
|
}
|