From 85446b5b526ac53af9add7c83cfd72f39ec39611 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期五, 07 七月 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瀛楄妭杞琀ex
-     * @param b 瀛楄妭
-     * @return Hex
-     */
-    public static String byteToHex(byte b)
-    {
-        String hexString = Integer.toHexString(b & 0xFF);
-        //鐢变簬鍗佸叚杩涘埗鏄敱0~9銆丄~F鏉ヨ〃绀�1~16锛屾墍浠ュ鏋淏yte杞崲鎴怘ex鍚庡鏋滄槸<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