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_n\":2,\"Output\":38},\"ts\":\""+System.currentTimeMillis()+"\"}]}";
|
//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\":\""+System.currentTimeMillis()+"\"}]}";
|
//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);
|
|
}
|
|
|
|
|
}
|