From 85446b5b526ac53af9add7c83cfd72f39ec39611 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: Fri, 07 Jul 2023 10:51:13 +0800
Subject: [PATCH] 优化外联设备报警解析并上传mqtt
---
src/main/java/com/ard/utils/SpringTool.java | 33 +++++++++++++++++++--------------
1 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/src/main/java/com/ard/utils/SpringTool.java b/src/main/java/com/ard/utils/SpringTool.java
index e152dde..123317b 100644
--- a/src/main/java/com/ard/utils/SpringTool.java
+++ b/src/main/java/com/ard/utils/SpringTool.java
@@ -1,9 +1,16 @@
package com.ard.utils;
import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
+
+import java.nio.ByteBuffer;
+import java.util.Properties;
+
/**
* @Description:
* @ClassName: SpringTool
@@ -33,20 +40,18 @@
return getApplicationContext().getBean(name);
}
- /**
- * Byte字节转Hex
- * @param b 字节
- * @return Hex
- */
- public static String byteToHex(byte b)
- {
- String hexString = Integer.toHexString(b & 0xFF);
- //由于十六进制是由0~9、A~F来表示1~16,所以如果Byte转换成Hex后如果是<16,就会是一个字符(比如A=10),通常是使用两个字符来表示16进制位的,
- //假如一个字符的话,遇到字符串11,这到底是1个字节,还是1和1两个字节,容易混淆,如果是补0,那么1和1补充后就是0101,11就表示纯粹的11
- if (hexString.length() < 2)
- {
- hexString = new StringBuilder(String.valueOf(0)).append(hexString).toString();
+ /*yml配置信息获取*/
+ public static String getYmlInfo(String key) {
+ Resource resource = new ClassPathResource("application.yml");
+ Properties properties = null;
+ try {
+ YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
+ yamlFactory.setResources(resource);
+ properties = yamlFactory.getObject();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
}
- return hexString.toUpperCase();
+ return properties.get(key).toString();
}
}
\ No newline at end of file
--
Gitblit v1.9.3