vince
2024-03-04 070b1e9cc8fccd36e7b65720a778ac46e118c792
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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) {
 
        }
    }
}