From 91c2a5373474be2ced4fe47bda83257617a0bc9e Mon Sep 17 00:00:00 2001 From: zch Date: Mon, 9 Dec 2024 17:37:39 +0800 Subject: [PATCH 1/3] =?UTF-8?q?change(ems):=20=E8=B0=83=E6=95=B4=E6=B8=A9?= =?UTF-8?q?=E5=BA=A6=E6=B9=BF=E5=BA=A6=E7=9B=91=E6=B5=8B=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E7=9A=84=E8=AE=BE=E5=A4=87=E7=B1=BB=E5=9E=8B=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 TemperatureHumidityMonitoring2 组件中增加了 collectType、energyTypeId、energyType 和 monitorTypeId 字段 - 在 TemperatureHumidityMonitoring3 组件中修改了 getTreeselect 方法,只查询类型为 3 的设备 - 移除了 TemperatureHumidityMonitoring3 组件中的 objId 验证规则 --- .../TemperatureHumidityMonitoring2/index.vue | 15 +++++++++------ .../TemperatureHumidityMonitoring3/index.vue | 6 +++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ruoyi-ui/src/views/ems/report/TemperatureHumidityMonitoring2/index.vue b/ruoyi-ui/src/views/ems/report/TemperatureHumidityMonitoring2/index.vue index 97d3d60..ba864bf 100644 --- a/ruoyi-ui/src/views/ems/report/TemperatureHumidityMonitoring2/index.vue +++ b/ruoyi-ui/src/views/ems/report/TemperatureHumidityMonitoring2/index.vue @@ -135,8 +135,11 @@ export default { zxyg: null, activePower: null, reactivePower: null, - collectType: null, - monitorType: 3 + collectType: 3, + monitorType: 3, + energyTypeId: 3, + energyType: 3, + monitorTypeId: 3 }, // 表单参数 form: {}, @@ -146,9 +149,7 @@ export default { }, // 表单校验 rules: { - objId: [ - { required: true, message: '编号不能为空', trigger: 'blur' } - ] + }, columns: [ { key: 0, label: `主键标识`, visible: false }, @@ -245,7 +246,9 @@ export default { /** 查询计量设备信息下拉树结构 */ getTreeselect() { - getMonitorInfoTree({ monitorTypeList: [3]}).then(response => { + debugger + console.log(123213) + getMonitorInfoTree({monitorTypeList: [3]}).then(response => { this.monitorInfoOptions = response.data }) }, diff --git a/ruoyi-ui/src/views/ems/report/TemperatureHumidityMonitoring3/index.vue b/ruoyi-ui/src/views/ems/report/TemperatureHumidityMonitoring3/index.vue index 5dab568..68daeee 100644 --- a/ruoyi-ui/src/views/ems/report/TemperatureHumidityMonitoring3/index.vue +++ b/ruoyi-ui/src/views/ems/report/TemperatureHumidityMonitoring3/index.vue @@ -145,9 +145,9 @@ export default { }, // 表单校验 rules: { - objId: [ +/* objId: [ {required: true, message: '编号不能为空', trigger: 'blur'} - ] + ]*/ }, columns: [ {key: 0, label: `主键标识`, visible: false}, @@ -245,7 +245,7 @@ export default { /** 查询计量设备信息下拉树结构 */ getTreeselect() { getMonitorInfoTree({ - monitorTypeList: [5, 6, 7, 8, 9], + monitorTypeList: [3], monitorType: this.$route.query.monitorType }).then(response => { this.monitorInfoOptions = response.data From a6baa9f8aed43997084f6fbac88a3a0d86103feb Mon Sep 17 00:00:00 2001 From: zch Date: Mon, 9 Dec 2024 17:37:56 +0800 Subject: [PATCH 2/3] =?UTF-8?q?add(framework):=20=E6=B7=BB=E5=8A=A0=20WebS?= =?UTF-8?q?ocket=20=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 pom.xml 中添加 Spring Boot WebSocket 依赖 - 新增 SemaphoreUtils 类用于信号量处理 - 添加 WebSocketConfig 配置类 - 实现 WebSocketServer 类处理 WebSocket 消息 - 创建 WebSocketUsers 类管理客户端用户 --- ruoyi-framework/pom.xml | 9 +- .../framework/websocket/SemaphoreUtils.java | 58 ++++++++ .../framework/websocket/WebSocketConfig.java | 20 +++ .../framework/websocket/WebSocketServer.java | 106 +++++++++++++ .../framework/websocket/WebSocketUsers.java | 140 ++++++++++++++++++ 5 files changed, 332 insertions(+), 1 deletion(-) create mode 100644 ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/SemaphoreUtils.java create mode 100644 ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/WebSocketConfig.java create mode 100644 ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/WebSocketServer.java create mode 100644 ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/WebSocketUsers.java diff --git a/ruoyi-framework/pom.xml b/ruoyi-framework/pom.xml index c4ba93b..848b053 100644 --- a/ruoyi-framework/pom.xml +++ b/ruoyi-framework/pom.xml @@ -59,6 +59,13 @@ ruoyi-system + + + org.springframework.boot + spring-boot-starter-websocket + + + - \ No newline at end of file + diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/SemaphoreUtils.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/SemaphoreUtils.java new file mode 100644 index 0000000..57567f3 --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/SemaphoreUtils.java @@ -0,0 +1,58 @@ +package com.ruoyi.framework.websocket; + +import java.util.concurrent.Semaphore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * 信号量相关处理 + * + * @author ruoyi + */ +public class SemaphoreUtils +{ + /** + * SemaphoreUtils 日志控制器 + */ + private static final Logger LOGGER = LoggerFactory.getLogger(SemaphoreUtils.class); + + /** + * 获取信号量 + * + * @param semaphore + * @return + */ + public static boolean tryAcquire(Semaphore semaphore) + { + boolean flag = false; + + try + { + flag = semaphore.tryAcquire(); + } + catch (Exception e) + { + LOGGER.error("获取信号量异常", e); + } + + return flag; + } + + /** + * 释放信号量 + * + * @param semaphore + */ + public static void release(Semaphore semaphore) + { + + try + { + semaphore.release(); + } + catch (Exception e) + { + LOGGER.error("释放信号量异常", e); + } + } +} diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/WebSocketConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/WebSocketConfig.java new file mode 100644 index 0000000..be63f35 --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/WebSocketConfig.java @@ -0,0 +1,20 @@ +package com.ruoyi.framework.websocket; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.server.standard.ServerEndpointExporter; + +/** + * websocket 配置 + * + * @author ruoyi + */ +@Configuration +public class WebSocketConfig +{ + @Bean + public ServerEndpointExporter serverEndpointExporter() + { + return new ServerEndpointExporter(); + } +} diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/WebSocketServer.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/WebSocketServer.java new file mode 100644 index 0000000..4ce319c --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/WebSocketServer.java @@ -0,0 +1,106 @@ +package com.ruoyi.framework.websocket; + +import java.util.concurrent.Semaphore; +import javax.websocket.OnClose; +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +/** + * websocket 消息处理 + * + * @author ruoyi + */ +@Component +@ServerEndpoint("/websocket/message") +public class WebSocketServer +{ + /** + * WebSocketServer 日志控制器 + */ + private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketServer.class); + + /** + * 默认最多允许同时在线人数100 + */ + public static int socketMaxOnlineCount = 100; + + private static Semaphore socketSemaphore = new Semaphore(socketMaxOnlineCount); + + /** + * 连接建立成功调用的方法 + */ + @OnOpen + public void onOpen(Session session) throws Exception + { + boolean semaphoreFlag = false; + // 尝试获取信号量 + semaphoreFlag = SemaphoreUtils.tryAcquire(socketSemaphore); + if (!semaphoreFlag) + { + // 未获取到信号量 + LOGGER.error("\n 当前在线人数超过限制数- {}", socketMaxOnlineCount); + WebSocketUsers.sendMessageToUserByText(session, "当前在线人数超过限制数:" + socketMaxOnlineCount); + session.close(); + } + else + { + // 添加用户 + WebSocketUsers.put(session.getId(), session); + LOGGER.info("\n 建立连接 - {}", session); + LOGGER.info("\n 当前人数 - {}", WebSocketUsers.getUsers().size()); + WebSocketUsers.sendMessageToUserByText(session, "连接成功"); + } + } + + /** + * 连接关闭时处理 + */ + @OnClose + public void onClose(Session session) + { + LOGGER.info("\n 关闭连接 - {}", session); + // 移除用户 + boolean removeFlag = WebSocketUsers.remove(session.getId()); + if (!removeFlag) + { + // 获取到信号量则需释放 + SemaphoreUtils.release(socketSemaphore); + } + } + + /** + * 抛出异常时处理 + */ + @OnError + public void onError(Session session, Throwable exception) throws Exception + { + if (session.isOpen()) + { + // 关闭连接 + session.close(); + } + String sessionId = session.getId(); + LOGGER.info("\n 连接异常 - {}", sessionId); + LOGGER.info("\n 异常信息 - {}", exception); + // 移出用户 + WebSocketUsers.remove(sessionId); + // 获取到信号量则需释放 + SemaphoreUtils.release(socketSemaphore); + } + + /** + * 服务器接收到客户端消息时调用的方法 + */ + @OnMessage + public void onMessage(String message, Session session) + { + String msg = message.replace("你", "我").replace("吗", ""); + WebSocketUsers.sendMessageToUserByText(session, msg); + } +} diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/WebSocketUsers.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/WebSocketUsers.java new file mode 100644 index 0000000..81e549e --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/WebSocketUsers.java @@ -0,0 +1,140 @@ +package com.ruoyi.framework.websocket; + +import java.io.IOException; +import java.util.Collection; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import javax.websocket.Session; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * websocket 客户端用户集 + * + * @author ruoyi + */ +public class WebSocketUsers +{ + /** + * WebSocketUsers 日志控制器 + */ + private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketUsers.class); + + /** + * 用户集 + */ + private static Map USERS = new ConcurrentHashMap(); + + /** + * 存储用户 + * + * @param key 唯一键 + * @param session 用户信息 + */ + public static void put(String key, Session session) + { + USERS.put(key, session); + } + + /** + * 移除用户 + * + * @param session 用户信息 + * + * @return 移除结果 + */ + public static boolean remove(Session session) + { + String key = null; + boolean flag = USERS.containsValue(session); + if (flag) + { + Set> entries = USERS.entrySet(); + for (Map.Entry entry : entries) + { + Session value = entry.getValue(); + if (value.equals(session)) + { + key = entry.getKey(); + break; + } + } + } + else + { + return true; + } + return remove(key); + } + + /** + * 移出用户 + * + * @param key 键 + */ + public static boolean remove(String key) + { + LOGGER.info("\n 正在移出用户 - {}", key); + Session remove = USERS.remove(key); + if (remove != null) + { + boolean containsValue = USERS.containsValue(remove); + LOGGER.info("\n 移出结果 - {}", containsValue ? "失败" : "成功"); + return containsValue; + } + else + { + return true; + } + } + + /** + * 获取在线用户列表 + * + * @return 返回用户集合 + */ + public static Map getUsers() + { + return USERS; + } + + /** + * 群发消息文本消息 + * + * @param message 消息内容 + */ + public static void sendMessageToUsersByText(String message) + { + Collection values = USERS.values(); + for (Session value : values) + { + sendMessageToUserByText(value, message); + } + } + + /** + * 发送文本消息 + * + * @param userName 自己的用户名 + * @param message 消息内容 + */ + public static void sendMessageToUserByText(Session session, String message) + { + if (session != null) + { + try + { + session.getBasicRemote().sendText(message); + } + catch (IOException e) + { + LOGGER.error("\n[发送消息异常]", e); + } + } + else + { + LOGGER.info("\n[你已离线]"); + } + } +} From 775fb8ae05178ce6d9cca2986bb06f6473327420 Mon Sep 17 00:00:00 2001 From: zch Date: Mon, 9 Dec 2024 17:58:53 +0800 Subject: [PATCH 3/3] =?UTF-8?q?add(ems):=20=E6=B7=BB=E5=8A=A0=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E7=9B=91=E6=B5=8B=E6=95=B0=E6=8D=AE=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 TWTempertureData 类中添加 pm1、pm2、pm10 和 standby 字段 - 更新 TWTempertureDataMapper.xml 以支持新字段的映射和查询 - 优化部分 SQL 语句,明确表别名 --- .../ems/record/domain/TWTempertureData.java | 58 +++++++++++++++++++ .../ems/record/TWTempertureDataMapper.xml | 36 ++++++++++-- 2 files changed, 90 insertions(+), 4 deletions(-) diff --git a/ruoyi-ems/src/main/java/com/ruoyi/ems/record/domain/TWTempertureData.java b/ruoyi-ems/src/main/java/com/ruoyi/ems/record/domain/TWTempertureData.java index b58f0db..4784d6d 100644 --- a/ruoyi-ems/src/main/java/com/ruoyi/ems/record/domain/TWTempertureData.java +++ b/ruoyi-ems/src/main/java/com/ruoyi/ems/record/domain/TWTempertureData.java @@ -81,6 +81,22 @@ public class TWTempertureData extends BaseEntity @Excel(name = "能源类型") private Long monitorType; + /** pm1.0 */ + @Excel(name = "pm1.0") + private BigDecimal pm1; + + /** pm2.5 */ + @Excel(name = "pm2.5") + private BigDecimal pm2; + + /** pm10.0 */ + @Excel(name = "pm10.0") + private BigDecimal pm10; + + /** 粉尘 */ + @Excel(name = "粉尘") + private BigDecimal standby; + public void setObjid(Long objid) { this.objid = objid; @@ -216,6 +232,44 @@ public class TWTempertureData extends BaseEntity this.monitorType = monitorType; } + public void setPm1(BigDecimal pm1) + { + this.pm1 = pm1; + } + + public BigDecimal getPm1() + { + return pm1; + } + public void setPm2(BigDecimal pm2) + { + this.pm2 = pm2; + } + + public BigDecimal getPm2() + { + return pm2; + } + public void setPm10(BigDecimal pm10) + { + this.pm10 = pm10; + } + + public BigDecimal getPm10() + { + return pm10; + } + public void setStandby(BigDecimal standby) + { + this.standby = standby; + } + + public BigDecimal getStandby() + { + return standby; + } + + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) @@ -233,6 +287,10 @@ public class TWTempertureData extends BaseEntity .append("confirmTime", getConfirmTime()) .append("confirmFlag", getConfirmFlag()) .append("monitorType", getMonitorType()) + .append("pm1", getPm1()) + .append("pm2", getPm2()) + .append("pm10", getPm10()) + .append("standby", getStandby()) .toString(); } } diff --git a/ruoyi-ems/src/main/resources/mapper/ems/record/TWTempertureDataMapper.xml b/ruoyi-ems/src/main/resources/mapper/ems/record/TWTempertureDataMapper.xml index ac6e5fb..70cc8cd 100644 --- a/ruoyi-ems/src/main/resources/mapper/ems/record/TWTempertureDataMapper.xml +++ b/ruoyi-ems/src/main/resources/mapper/ems/record/TWTempertureDataMapper.xml @@ -20,6 +20,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + @@ -38,8 +44,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" twtd.confirmFlag, ebmi.monitor_name, - ebmi.monitor_type + ebmi.monitor_type, + twtd.pm1, + twtd.pm2, + twtd.pm10, + twtd.standby from T_W_TempertureData twtd left join ems_base_monitor_info ebmi on twtd.monitorId = ebmi.monitor_code @@ -64,22 +74,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and twtd.confirmFlag = #{confirmFlag} and ebmi.monitor_type = #{monitorType} + and twtd.pm1 = #{pm1} + and twtd.pm2 = #{pm2} + and twtd.pm10 = #{pm10} + and twtd.standby = #{standby} order by twtd.recodeTime desc @@ -107,6 +121,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" confirmPersonID, confirmTime, confirmFlag, + pm1, + pm2, + pm10, + standby, #{monitorId}, @@ -121,6 +139,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{confirmPersonID}, #{confirmTime}, #{confirmFlag}, + + #{pm1}, + #{pm2}, + #{pm10}, + #{standby}, @@ -139,6 +162,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" confirmPersonID = #{confirmPersonID}, confirmTime = #{confirmTime}, confirmFlag = #{confirmFlag}, + + pm1 = #{pm1}, + pm2 = #{pm2}, + pm10 = #{pm10}, + standby = #{standby}, where objid = #{objid}