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
package com.ruoyi.iot.util.quartz;
 
import com.alibaba.fastjson.JSON;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.iot.domain.DeviceJob;
import com.ruoyi.iot.model.Action;
import com.ruoyi.iot.model.ThingsModels.IdentityAndName;
import com.ruoyi.iot.mqtt.EmqxService;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 任务执行工具
 *
 * @author kerwincui
 */
public class JobInvokeUtil {
    /**
     * 执行方法
     *
     * @param deviceJob 系统任务
     */
    public static void invokeMethod(DeviceJob deviceJob) throws Exception {
        if (deviceJob.getJobType() == 1) {
            System.out.println("------------------------执行定时任务-----------------------------");
            List<Action> actions = JSON.parseArray(deviceJob.getActions(), Action.class);
            List<IdentityAndName> propertys = new ArrayList<>();
            List<IdentityAndName> functions = new ArrayList<>();
            for (int i = 0; i < actions.size(); i++) {
                IdentityAndName model = new IdentityAndName();
                model.setId(actions.get(i).getId());
                model.setValue(actions.get(i).getValue());
                if (actions.get(i).getType() == 1) {
                    propertys.add(model);
                } else if (actions.get(i).getType() == 2) {
                    functions.add(model);
                }
            }
            EmqxService emqxService = SpringUtils.getBean(EmqxService.class);
            // 发布属性
            if (propertys.size() > 0) {
                emqxService.publishProperty(deviceJob.getProductId(), deviceJob.getSerialNumber(), propertys);
            }
            // 发布功能
            if (functions.size() > 0) {
                emqxService.publishFunction(deviceJob.getProductId(), deviceJob.getSerialNumber(), functions);
            }
 
        } else if (deviceJob.getJobType() == 2) {
            // 告警
 
            System.out.println("------------------------执行告警-----------------------------");
        } else if (deviceJob.getJobType() == 3) {
            // 场景联动
 
            System.out.println("------------------------执行场景联动-----------------------------");
        }
    }
 
 
}