From e8a7beb5455d0c9f50f93004b600dd2781ad6bfd Mon Sep 17 00:00:00 2001 From: baoshiwei <baoshiwei@shlanbao.cn> Date: 星期一, 30 六月 2025 09:36:56 +0800 Subject: [PATCH] feat(空调控制): 实现空调控制功能并优化 SVG 数据加载- 新增 AirCondConstants 类,定义空调控制常量 - 修改 AirConditionerServiceImpl,使用常量替代硬编码值 - 更新 MQTT 消息发送逻辑,使用常量定义主题 - 优化 SVG 数据加载和处理逻辑,改进标签值更新方式 - 调整域名地址配置,支持生产环境 API --- zhitan-airconditioner/src/main/java/com/zhitan/airconditioner/service/impl/AirConditionerServiceImpl.java | 17 +++++--- zhitan-vue/src/views/svg/components/configure.vue | 10 +++-- zhitan-vue/src/views/svg/components/configureView.vue | 46 +++++++++++++++++------ zhitan-airconditioner/src/main/java/com/zhitan/airconditioner/common/AirCondConstants.java | 10 +++++ zhitan-admin/src/main/resources/application.yml | 3 + 5 files changed, 63 insertions(+), 23 deletions(-) diff --git a/zhitan-admin/src/main/resources/application.yml b/zhitan-admin/src/main/resources/application.yml index 7ed13b1..4ac24f8 100644 --- a/zhitan-admin/src/main/resources/application.yml +++ b/zhitan-admin/src/main/resources/application.yml @@ -12,7 +12,8 @@ # 楠岃瘉鐮佺被鍨� math 鏁板瓧璁$畻 char 瀛楃楠岃瘉 captchaType: math # 鍩熷悕鍦板潃 - domainName: http://127.0.0.1:8088 + # domainName: http://127.0.0.1:8088 + domainName: http://192.168.0.24:8888/prod-api # 寮�鍙戠幆澧冮厤缃� server: diff --git a/zhitan-airconditioner/src/main/java/com/zhitan/airconditioner/common/AirCondConstants.java b/zhitan-airconditioner/src/main/java/com/zhitan/airconditioner/common/AirCondConstants.java new file mode 100644 index 0000000..12b5bfa --- /dev/null +++ b/zhitan-airconditioner/src/main/java/com/zhitan/airconditioner/common/AirCondConstants.java @@ -0,0 +1,10 @@ +package com.zhitan.airconditioner.common; + +public class AirCondConstants { + public static final String COOL_OPEN = "0"; + public static final String HOT_OPEN = "1"; + public static final String OFF = "2"; + + public static final String SEND_COMMAND_TOPIC = "lanbao/nygl/sevice/kt1/down"; + +} diff --git a/zhitan-airconditioner/src/main/java/com/zhitan/airconditioner/service/impl/AirConditionerServiceImpl.java b/zhitan-airconditioner/src/main/java/com/zhitan/airconditioner/service/impl/AirConditionerServiceImpl.java index 9852b18..628b4a6 100644 --- a/zhitan-airconditioner/src/main/java/com/zhitan/airconditioner/service/impl/AirConditionerServiceImpl.java +++ b/zhitan-airconditioner/src/main/java/com/zhitan/airconditioner/service/impl/AirConditionerServiceImpl.java @@ -4,6 +4,7 @@ import java.util.List; import com.alibaba.fastjson2.JSONObject; +import com.zhitan.airconditioner.common.AirCondConstants; import com.zhitan.airconditioner.domain.AirConditioner; import com.zhitan.airconditioner.domain.AirConditionerLog; import com.zhitan.airconditioner.mapper.AirConditionerLogMapper; @@ -12,6 +13,8 @@ import com.zhitan.common.utils.DateUtils; import com.zhitan.common.utils.SecurityUtils; import com.zhitan.framework.mqtt.MqttClientUtil; +import com.zhitan.realtimedata.domain.TagValue; +import com.zhitan.realtimedata.service.RealtimeDatabaseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -31,6 +34,9 @@ @Autowired private MqttClientUtil mqttClientUtil; + + @Autowired + private RealtimeDatabaseService realtimeDatabaseService; /** * 鏌ヨ绌鸿皟鎺у埗鍣ㄥ垪琛� @@ -176,20 +182,19 @@ JSONObject jsonObject = JSONObject.parseObject(msg); JSONObject rwProt = jsonObject.getJSONObject("rw_prot"); rwProt.put("id", airConditioner.getControllerId()); - if ("0".equals(mode)) { + if (AirCondConstants.COOL_OPEN.equals(mode)) { rwProt.getJSONArray("w_data").getJSONObject(0).put("value", "1"); - } else if ("1".equals(mode)) { + } else if (AirCondConstants.HOT_OPEN.equals(mode)) { rwProt.getJSONArray("w_data").getJSONObject(1).put("value", "1"); - } else if ("2".equals(mode)) { + } else if (AirCondConstants.OFF.equals(mode)) { rwProt.getJSONArray("w_data").getJSONObject(2).put("value", "1"); } // 鏋勫缓MQTT娑堟伅 - String topic = "lanbao/nygl/sevice/kt1/down"; String message = jsonObject.toJSONString(); // 鍙戦�丮QTT娑堟伅 - mqttClientUtil.sendMessage(topic, message, 2); - + mqttClientUtil.sendMessage(AirCondConstants.SEND_COMMAND_TOPIC, message, 2); + // 璁板綍鎿嶄綔鏃ュ織 AirConditionerLog log = new AirConditionerLog(); log.setAirConditionerId(id); diff --git a/zhitan-vue/src/views/svg/components/configure.vue b/zhitan-vue/src/views/svg/components/configure.vue index 3b4820b..a125d80 100644 --- a/zhitan-vue/src/views/svg/components/configure.vue +++ b/zhitan-vue/src/views/svg/components/configure.vue @@ -104,17 +104,19 @@ /* 鐩戝惉xhr瀵硅薄 */ xhr.addEventListener("load", () => { svgHtml.value = xhr.responseText - let values = xhr.responseXML.getElementsByTagName("text") + let values = xhr.responseXML.getElementsByTagName("g") let tagTemps = [] for (let i = 0; i < values.length; i++) { - if (values[i].getAttribute("id") != undefined) + let tag_id = values[i].getAttribute("id"); + // tag_id涓嶄负绌哄苟涓斾互EV寮�鍏� + if (tag_id != undefined && tag_id.startsWith("EV")) { tagTemps.push({ - param: values[i].textContent, + param: values[i].id.split("_")[0], tag: "", tagType: "COLLECT", }) + } } - console.log(tags.value.length, tagTemps.length) if (tags.value.length === 0 || tags.value.length != tagTemps.length) { tags.value = [] tags.value = tagTemps diff --git a/zhitan-vue/src/views/svg/components/configureView.vue b/zhitan-vue/src/views/svg/components/configureView.vue index 46eed3f..7ea5f49 100644 --- a/zhitan-vue/src/views/svg/components/configureView.vue +++ b/zhitan-vue/src/views/svg/components/configureView.vue @@ -45,10 +45,12 @@ } function refresh() { + //console.log("refresh", tagCodes.value) if (tagCodes.value.length === 0) { return } getLiveData(tagCodes.value).then((response) => { + // console.log("tagCodes:::", tagCodes.value) if (response.code === 200) { if (response.data) { response.data.forEach((tagValue) => { @@ -58,20 +60,39 @@ } else { value = "0" } - + // console.log("tagValue::",tagValue) let el = document.getElementById(tagValue.tagCode) if (el) { - el.textContent = value + // 鍒ゆ柇tagValue.tagCode鏄笉鏄互old鎴杝even鎴杘ut寮�澶� + if (tagValue.tagCode.startsWith("old") || tagValue.tagCode.startsWith("seven") || tagValue.tagCode.startsWith("out")) { + // 鑾峰彇 el涓嬬殑g鏍囩涓嬬殑text鏍囩锛岃祴鍊间负value + let svgTextElement = el.querySelector("g").querySelector("text"); + console.log("svgTextElement::",svgTextElement) + svgTextElement.textContent = value; + }else { + if (parseFloat(value) > 0) { + el.setAttribute("fill", "rgb(0,234,136)") + }else { + el.setAttribute("fill", "rgb(255,82,96)") + } + } + + // console.log("el::",el) + // 灏唀l鐨刦ill灞炴�ц缃负23 + + + + } }) //杩欏潡鏄崟鐙姞鐨� 鐢ㄦ潵澶勭悊 娌℃湁鎸囨爣鎴栬�呮寚鏍囨病鏈夌粨鏋滅殑 閮借缃�0 - let allText = document.getElementsByTagName("text") - for (let i = 0; i < allText.length; i++) { - // console.log(i + "textContent=" + allText[i].textContent); - if (allText[i].textContent == null || allText[i].textContent == "") { - allText[i].textContent = "0" - } - } + // let allText = document.getElementsByTagName("g") + // for (let i = 0; i < allText.length; i++) { + // // console.log(i + "textContent=" + allText[i].textContent); + // if (allText[i].textContent == null || allText[i].textContent == "") { + // allText[i].textContent = "0" + // } + // } } } }) @@ -101,12 +122,13 @@ xhr.addEventListener("load", () => { const resXML = xhr.responseXML let svgDom = resXML.documentElement.cloneNode(true) - let values = svgDom.getElementsByTagName("text") + let values = svgDom.getElementsByTagName("g") for (let i = 0; i < values.length; i++) { - let tag = tags.value.filter((f) => f.param === values[i].textContent) + let tag_id = values[i].getAttribute("id"); + let tag = tags.value.filter((f) => f.param === values[i].id.split("_")[0]) if (tag && tag.length > 0) { let tagCode = tag[0].tag - values[i].textContent = "" + if (tagCode) { values[i].setAttribute("id", tagCode) tagCodes.value.push(tagCode) -- Gitblit v1.9.3