|
@@ -158,22 +158,20 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
|
|
|
String topicType = requestVO.getTopicType();
|
|
|
|
|
|
if (topicType == null) {
|
|
|
-
|
|
|
if (StringUtils.isBlank(productCode)) {
|
|
|
throw new BusinessException("产品编码“productCode”不能为空!");
|
|
|
} else if (StringUtils.isBlank(deviceId)) {
|
|
|
throw new BusinessException("设备编号“deviceId”不能为空!");
|
|
|
- }
|
|
|
-/* else if (StringUtils.isBlank(deviceUuid)) {
|
|
|
+ } else if (StringUtils.isBlank(deviceUuid)) {
|
|
|
throw new BusinessException("设备uuid“deviceUuid“不能为空!");
|
|
|
- }*/
|
|
|
+ }
|
|
|
|
|
|
-/* DmpTopicResponseVO add = new DmpTopicResponseVO();
|
|
|
+ DmpTopicResponseVO add = new DmpTopicResponseVO();
|
|
|
add.setTopic("/" + productCode + "/" + deviceId + "/" + TopicInfo.ADD_REMARKS.getLetter());
|
|
|
add.setPublisher(TopicInfo.GATEWAY_DEVICE.getValue());
|
|
|
add.setSubscriber(TopicInfo.IOT_PLATFORM.getValue());
|
|
|
add.setRemarks(TopicInfo.ADD_REMARKS.getValue());
|
|
|
- responseVOList.add(add);*/
|
|
|
+ responseVOList.add(add);
|
|
|
|
|
|
DmpTopicResponseVO info = new DmpTopicResponseVO();
|
|
|
info.setTopic("/" + productCode + "/" + deviceId + "/" + TopicInfo.INFO_REMARKS.getLetter());
|
|
@@ -182,88 +180,111 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
|
|
|
info.setRemarks(TopicInfo.INFO_REMARKS.getValue());
|
|
|
responseVOList.add(info);
|
|
|
|
|
|
- /* DmpTopicResponseVO control = new DmpTopicResponseVO();
|
|
|
- control.setTopic("/" + deviceUuid + "/" + TopicInfo.CONTROL_REMARKS.getLetter());
|
|
|
- control.setSubscriber(TopicInfo.GATEWAY_DEVICE.getValue());
|
|
|
- control.setPublisher(TopicInfo.IOT_PLATFORM.getValue());
|
|
|
- control.setRemarks(TopicInfo.CONTROL_REMARKS.getValue());
|
|
|
- responseVOList.add(control);
|
|
|
-
|
|
|
- DmpTopicResponseVO controlResponse = new DmpTopicResponseVO();
|
|
|
- controlResponse.setTopic("/" + deviceUuid + "/" + TopicInfo.CONTROL_RESPONSE_REMARKS.getLetter());
|
|
|
- controlResponse.setPublisher(TopicInfo.GATEWAY_DEVICE.getValue());
|
|
|
- controlResponse.setSubscriber(TopicInfo.IOT_PLATFORM.getValue());
|
|
|
- controlResponse.setRemarks(TopicInfo.CONTROL_RESPONSE_REMARKS.getValue());
|
|
|
- responseVOList.add(controlResponse);*/
|
|
|
-
|
|
|
- }
|
|
|
-/* else if ("add".equals(topicType)) {
|
|
|
-
|
|
|
- if (StringUtils.isBlank(productCode)) {
|
|
|
- throw new BusinessException("产品编码“productCode”不能为空!");
|
|
|
- } else if (StringUtils.isBlank(deviceId)) {
|
|
|
- throw new BusinessException("设备编号“deviceId”不能为空!");
|
|
|
- } else if (StringUtils.isBlank(deviceName)) {
|
|
|
- throw new BusinessException("设备名“deviceName“不能为空!");
|
|
|
- }
|
|
|
-
|
|
|
- DmpTopicResponseVO add = new DmpTopicResponseVO();
|
|
|
- add.setTopic("/" + productCode + "/" + deviceId + "/" + TopicInfo.ADD_REMARKS.getLetter());
|
|
|
- add.setPublisher(TopicInfo.GATEWAY_DEVICE.getValue());
|
|
|
- add.setSubscriber(TopicInfo.IOT_PLATFORM.getValue());
|
|
|
- add.setRemarks(TopicInfo.ADD_REMARKS.getValue());
|
|
|
-
|
|
|
- // 组装topicPayload
|
|
|
- JSONObject topicPayloadJson = new JSONObject();
|
|
|
- topicPayloadJson.put("productCode", productCode);
|
|
|
- topicPayloadJson.put("deviceId", deviceId);
|
|
|
- topicPayloadJson.put("deviceName", deviceName);
|
|
|
- if (!StringUtils.isBlank(simCode)) {
|
|
|
- topicPayloadJson.put("simCode", simCode);
|
|
|
- }
|
|
|
- if (!StringUtils.isBlank(installAddress)) {
|
|
|
- topicPayloadJson.put("installAddress", installAddress);
|
|
|
- }
|
|
|
- String topicPayload = topicPayloadJson.toString();
|
|
|
- add.setTopicPayload(topicPayload);
|
|
|
-
|
|
|
- }*/
|
|
|
+ DmpTopicResponseVO control = new DmpTopicResponseVO();
|
|
|
+ control.setTopic("/" + deviceUuid + "/" + TopicInfo.CONTROL_REMARKS.getLetter());
|
|
|
+ control.setSubscriber(TopicInfo.GATEWAY_DEVICE.getValue());
|
|
|
+ control.setPublisher(TopicInfo.IOT_PLATFORM.getValue());
|
|
|
+ control.setRemarks(TopicInfo.CONTROL_REMARKS.getValue());
|
|
|
+ responseVOList.add(control);
|
|
|
|
|
|
- else if ("info".equals(topicType)) {
|
|
|
+ DmpTopicResponseVO controlResponse = new DmpTopicResponseVO();
|
|
|
+ controlResponse.setTopic("/" + deviceUuid + "/" + TopicInfo.CONTROL_RESPONSE_REMARKS.getLetter());
|
|
|
+ controlResponse.setPublisher(TopicInfo.GATEWAY_DEVICE.getValue());
|
|
|
+ controlResponse.setSubscriber(TopicInfo.IOT_PLATFORM.getValue());
|
|
|
+ controlResponse.setRemarks(TopicInfo.CONTROL_RESPONSE_REMARKS.getValue());
|
|
|
+ responseVOList.add(controlResponse);
|
|
|
|
|
|
- if (StringUtils.isBlank(productCode)) {
|
|
|
- throw new BusinessException("产品编码“productCode”不能为空!");
|
|
|
- } else if (productId == null) {
|
|
|
- throw new BusinessException("产品ID“productId“不能为空!");
|
|
|
- } else if (StringUtils.isBlank(deviceId)) {
|
|
|
- throw new BusinessException("设备编号“deviceId”不能为空!");
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ switch (topicType) {
|
|
|
+ case "add":
|
|
|
+ /*if (StringUtils.isBlank(productCode)) {
|
|
|
+ throw new BusinessException("产品编码“productCode”不能为空!");
|
|
|
+ } else if (StringUtils.isBlank(deviceId)) {
|
|
|
+ throw new BusinessException("设备编号“deviceId”不能为空!");
|
|
|
+ } else if (StringUtils.isBlank(deviceName)) {
|
|
|
+ throw new BusinessException("设备名“deviceName“不能为空!");
|
|
|
+ }
|
|
|
|
|
|
- DmpTopicResponseVO info = new DmpTopicResponseVO();
|
|
|
- info.setTopic("/" + productCode + "/" + deviceId + "/" + TopicInfo.INFO_REMARKS.getLetter());
|
|
|
- info.setPublisher(TopicInfo.GATEWAY_DEVICE.getValue());
|
|
|
- info.setSubscriber(TopicInfo.IOT_PLATFORM.getValue());
|
|
|
- info.setRemarks(TopicInfo.INFO_REMARKS.getValue());
|
|
|
+ DmpTopicResponseVO add = new DmpTopicResponseVO();
|
|
|
+ add.setTopic("/" + productCode + "/" + deviceId + "/" + TopicInfo.ADD_REMARKS.getLetter());
|
|
|
+ add.setPublisher(TopicInfo.GATEWAY_DEVICE.getValue());
|
|
|
+ add.setSubscriber(TopicInfo.IOT_PLATFORM.getValue());
|
|
|
+ add.setRemarks(TopicInfo.ADD_REMARKS.getValue());
|
|
|
+
|
|
|
+ // 组装topicPayload
|
|
|
+ JSONObject topicPayloadJson = new JSONObject();
|
|
|
+ topicPayloadJson.put("productCode", productCode);
|
|
|
+ topicPayloadJson.put("deviceId", deviceId);
|
|
|
+ topicPayloadJson.put("deviceName", deviceName);
|
|
|
+ if (!StringUtils.isBlank(simCode)) {
|
|
|
+ topicPayloadJson.put("simCode", simCode);
|
|
|
+ }
|
|
|
+ if (!StringUtils.isBlank(installAddress)) {
|
|
|
+ topicPayloadJson.put("installAddress", installAddress);
|
|
|
+ }
|
|
|
+ String topicPayload = topicPayloadJson.toString();
|
|
|
+ add.setTopicPayload(topicPayload);
|
|
|
+ responseVOList.add(add);*/
|
|
|
+ break;
|
|
|
+ case "info":
|
|
|
+ if (StringUtils.isBlank(productCode)) {
|
|
|
+ throw new BusinessException("产品编码“productCode”不能为空!");
|
|
|
+ } else if (productId == null) {
|
|
|
+ throw new BusinessException("产品ID“productId“不能为空!");
|
|
|
+ } else if (StringUtils.isBlank(deviceId)) {
|
|
|
+ throw new BusinessException("设备编号“deviceId”不能为空!");
|
|
|
+ }
|
|
|
|
|
|
- // 组装topicPayload
|
|
|
- JSONObject infoPayloadJson = new JSONObject();
|
|
|
- infoPayloadJson.put("productCode", productCode);
|
|
|
- Long timestamp = System.currentTimeMillis();
|
|
|
- infoPayloadJson.put("timestamp", timestamp);
|
|
|
+ DmpTopicResponseVO info = new DmpTopicResponseVO();
|
|
|
+ info.setTopic("/" + productCode + "/" + deviceId + "/" + TopicInfo.INFO_REMARKS.getLetter());
|
|
|
+ info.setPublisher(TopicInfo.GATEWAY_DEVICE.getValue());
|
|
|
+ info.setSubscriber(TopicInfo.IOT_PLATFORM.getValue());
|
|
|
+ info.setRemarks(TopicInfo.INFO_REMARKS.getValue());
|
|
|
+
|
|
|
+ // 组装topicPayload
|
|
|
+ JSONObject infoPayloadJson = new JSONObject();
|
|
|
+ infoPayloadJson.put("productCode", productCode);
|
|
|
+ Long timestamp = System.currentTimeMillis();
|
|
|
+ infoPayloadJson.put("timestamp", timestamp);
|
|
|
+
|
|
|
+ JSONObject metricsJson = new JSONObject();
|
|
|
+ List<DmpProductAttribute> productAttributeList = getProductAttributeList(productId);
|
|
|
+ for (DmpProductAttribute productAttribute : productAttributeList) {
|
|
|
+ metricsJson.put(productAttribute.getAttributeCode(), productAttribute.getMaximum());
|
|
|
+ }
|
|
|
+ infoPayloadJson.put("metrics", metricsJson);
|
|
|
+
|
|
|
+ JSONObject tagsJson = new JSONObject();
|
|
|
+ tagsJson.put("device_id", deviceId);
|
|
|
+ infoPayloadJson.put("tags", tagsJson);
|
|
|
+ String infoPayload = infoPayloadJson.toString();
|
|
|
+ info.setTopicPayload(infoPayload);
|
|
|
+ info.setProductAttributeList(productAttributeList);
|
|
|
+ responseVOList.add(info);
|
|
|
+ break;
|
|
|
+ case "control":
|
|
|
+ /*if (StringUtils.isBlank(deviceUuid)) {
|
|
|
+ throw new BusinessException("设备uuid“deviceUuid“不能为空!");
|
|
|
+ }else if (StringUtils.isBlank(productCode)){
|
|
|
+ throw new BusinessException("产品编码“productCode”不能为空!");
|
|
|
+ }
|
|
|
|
|
|
- JSONObject metricsJson = new JSONObject();
|
|
|
- List<DmpProductAttribute> productAttributeList = getProductAttributeList(productId);
|
|
|
- for (DmpProductAttribute productAttribute : productAttributeList) {
|
|
|
- metricsJson.put(productAttribute.getAttributeCode(), productAttribute.getMaximum());
|
|
|
+ DmpTopicResponseVO control = new DmpTopicResponseVO();
|
|
|
+ control.setTopic("/" + deviceUuid + "/" + TopicInfo.CONTROL_REMARKS.getLetter());
|
|
|
+ control.setPublisher(TopicInfo.IOT_PLATFORM.getValue());
|
|
|
+ control.setSubscriber(TopicInfo.GATEWAY_DEVICE.getValue());
|
|
|
+ control.setRemarks(TopicInfo.CONTROL_REMARKS.getValue());
|
|
|
+
|
|
|
+ // 组装topicPayload
|
|
|
+ JSONObject controlPayloadJson = new JSONObject();
|
|
|
+
|
|
|
+ responseVOList.add(control);*/
|
|
|
+ break;
|
|
|
+ case "controlResponse":
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new BusinessException("topicType参数错误!");
|
|
|
}
|
|
|
- infoPayloadJson.put("metrics", metricsJson);
|
|
|
-
|
|
|
- JSONObject tagsJson = new JSONObject();
|
|
|
- tagsJson.put("device_id", deviceId);
|
|
|
- infoPayloadJson.put("tags", tagsJson);
|
|
|
- String infoPayload = infoPayloadJson.toString();
|
|
|
- info.setTopicPayload(infoPayload);
|
|
|
- responseVOList.add(info);
|
|
|
}
|
|
|
|
|
|
int fromIndex = (pageNum - 1) * pageSize;
|
|
@@ -276,13 +297,25 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
|
|
|
return ToCommonPage(page);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取产品属性列表
|
|
|
+ *
|
|
|
+ * @param productId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
private List<DmpProductAttribute> getProductAttributeList(Integer productId) {
|
|
|
LambdaQueryWrapper<DmpProductAttribute> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.select(DmpProductAttribute::getAttributeCode, DmpProductAttribute::getMaximum)
|
|
|
- .eq(DmpProductAttribute::getProductId, productId);
|
|
|
+ queryWrapper.eq(DmpProductAttribute::getProductId, productId);
|
|
|
return dmpProductAttributeMapper.selectList(queryWrapper);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取设备告警信息
|
|
|
+ *
|
|
|
+ * @param deviceId
|
|
|
+ * @param productCode
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public DmpHttpAlarmResponseVO alarmResponse(String deviceId, String productCode) {
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|