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