yangys
2024-09-05 312fd03ae1ee528892129a10630d44de92c73c37
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
84
85
package com.qianwen.mdc.collect.controller;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
 
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qianwen.mdc.collect.config.IotDBSessionConfig;
import com.qianwen.mdc.collect.mqtt.MqttMessageSender;
import com.qianwen.mdc.collect.service.IOTMqttReceiveService;
import com.qianwen.mdc.collect.service.IotDBCommonService;
 
@RestController
public class MqttController {
    @Autowired
    private MqttMessageSender mqttMessageSender;
    @Autowired
    private IOTMqttReceiveService recService;
    @Autowired
    private IotDBSessionConfig iotdbCfg;
    
    @Autowired
    private IotDBCommonService iotService;
    
    @GetMapping("/send")
    public String send(@RequestParam String topic, @RequestParam String message) {
        mqttMessageSender.sendMessage(topic, message);
        return "Message sent to topic " + topic;
    }
    
    
    @GetMapping("/rec2")
    public void testRec2() {
        //数据格式:{"174":[{"values":{"d1":12},"ts":"1721978780449"}]} 174是应用id
        //多条格式:{"174":[{"values":{"DeviceStatus":2},"ts":"1722478128278"},{"values":{"spindleSpeed":22},"ts":"1722478128281"}]}
        String payload = "{\"174\":[{\"values\":{\"DeviceStatus\":2,\"Output\":34},\"ts\":\"1725247557768\"}]}";
        //payload = "{\"174\":[{\"values\":{\"Output\":11},\"ts\":\"1722478128278\"},{\"values\":{\"SpindleSpeed\":22},\"ts\":\"1722478128281\"}]}";
        recService.handle(payload);
    }
    
    
    @GetMapping("/recalarm")
    public void testAlarm() {
        //数据格式:{"174":[{"values":{"d1":12},"ts":"1721978780449"}]} 174是应用id
        //多条格式:{"174":[{"values":{"DeviceStatus":2},"ts":"1722478128278"},{"values":{"spindleSpeed":22},"ts":"1722478128281"}]}
        String payload = "{\"174\":[{\"values\":{\"Alarm\":\"告警信息1\"},\"ts\":\"1725504995056\"}]}";
        //payload = "{\"174\":[{\"values\":{\"Output\":11},\"ts\":\"1722478128278\"},{\"values\":{\"SpindleSpeed\":22},\"ts\":\"1722478128281\"}]}";
        recService.handle(payload);
    }
    
    @GetMapping("/tpl")
    public Object tpl(String tplname) throws StatementExecutionException, IoTDBConnectionException {
        boolean b = iotdbCfg.getSessionPool().checkTimeseriesExists("root.f2.output_22005.*");
        System.out.print(b);
        List<String> list = iotdbCfg.getSessionPool().showPathsTemplateUsingOn(tplname);
        
        //root.f2.output_22009
        System.out.print(iotdbCfg.getSessionPool().showMeasurementsInTemplate(tplname));
        
        return list;
    }
    @GetMapping("/tpluse")
    public Object tpluse(String tplname,String path) throws StatementExecutionException, IoTDBConnectionException {
        return iotService.isTemplateSetOnPath(tplname, path);
        
    }
    
    @GetMapping("/tpluse2")
    public Object tpluse2(String tplname,String path) throws StatementExecutionException, IoTDBConnectionException {
        return iotdbCfg.getSessionPool().showPathsTemplateSetOn(tplname);
        
    }
    
    
    
    
}