From 19c90b219bd80f82bfcf799a7adfd03fd469c0b7 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期三, 28 五月 2025 17:24:13 +0800 Subject: [PATCH] 1. 新增动态污染溯源新的判定逻辑(待完成) --- src/main/kotlin/com/flightfeather/uav/socket/handler/UnderwayWebSocketServerHandler.kt | 57 ++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/uav/socket/handler/UnderwayWebSocketServerHandler.kt b/src/main/kotlin/com/flightfeather/uav/socket/handler/UnderwayWebSocketServerHandler.kt index 0e912d3..fef4d1a 100644 --- a/src/main/kotlin/com/flightfeather/uav/socket/handler/UnderwayWebSocketServerHandler.kt +++ b/src/main/kotlin/com/flightfeather/uav/socket/handler/UnderwayWebSocketServerHandler.kt @@ -1,5 +1,13 @@ package com.flightfeather.uav.socket.handler +import com.flightfeather.uav.biz.sourcetrace.RealTimeExceptionAnalysisController +import com.flightfeather.uav.common.api2word.utils.JsonUtils +import com.flightfeather.uav.common.utils.GsonUtils +import com.flightfeather.uav.domain.entity.BaseRealTimeData +import com.flightfeather.uav.domain.repository.SceneInfoRep +import com.flightfeather.uav.lightshare.bean.DataVo +import com.flightfeather.uav.socket.sender.UnderwayWebSocketSender +import com.google.gson.JsonSyntaxException import io.netty.channel.ChannelHandlerContext import io.netty.handler.codec.http.websocketx.TextWebSocketFrame import org.springframework.stereotype.Component @@ -9,28 +17,43 @@ * @date 2025/5/13 * @author feiyu02 */ -@Component -class UnderwayWebSocketServerHandler : BaseHandler() { +class UnderwayWebSocketServerHandler(sceneInfoRep: SceneInfoRep) : BaseHandler() { - private val sessionPool = mutableMapOf<String?, ChannelHandlerContext?>() + private val realTimeExceptionAnalysisController = RealTimeExceptionAnalysisController(sceneInfoRep) override var tag: String = "UAV-WS" override fun channelRegistered(ctx: ChannelHandlerContext?) { super.channelRegistered(ctx) // 灏嗚繛鎺ュ瓨鍌� - if (!sessionPool.containsKey(ctx?.name())) { - sessionPool[ctx?.name()] = ctx - } + UnderwayWebSocketSender.saveSession(ctx) } override fun channelRead(ctx: ChannelHandlerContext?, msg: Any?) { super.channelRead(ctx, msg) - when (msg) { - is TextWebSocketFrame->{ - println(msg.text()) - ctx?.channel()?.writeAndFlush(msg) + is TextWebSocketFrame -> { + val msgTxt = msg.text() + + println(msgTxt) +// ctx?.channel()?.writeAndFlush(msg) + + // Test + try { + if (msgTxt == "start") { + realTimeExceptionAnalysisController.initTask() + } else { + val data = GsonUtils.parserJsonToArrayBeans(msgTxt, DataVo::class.java) + data.forEach { + realTimeExceptionAnalysisController.addOneData( + it.toBaseRealTimeData(BaseRealTimeData::class.java) + ) + } + } + } catch (e: Exception) { +// ctx?.channel()?.writeAndFlush(TextWebSocketFrame("褰撳墠涓烘祴璇曠姸鎬侊紝浼犺緭鐨勬暟鎹笉鏄蛋鑸暟鎹牸寮�")) + println("褰撳墠涓烘祴璇曠姸鎬侊紝浼犺緭鐨勬暟鎹笉鏄蛋鑸暟鎹牸寮�") + } } } } @@ -38,18 +61,6 @@ override fun channelInactive(ctx: ChannelHandlerContext?) { super.channelInactive(ctx) // 灏嗚繛鎺ョЩ闄� - if (sessionPool.containsKey(ctx?.name())) { - sessionPool.remove(ctx?.name()) - } - } - - fun send() { - - } - - fun broadcast(msg: String) { - sessionPool.forEach { t, u -> - u?.channel()?.writeAndFlush(TextWebSocketFrame(msg)) - } + UnderwayWebSocketSender.removeSession(ctx) } } \ No newline at end of file -- Gitblit v1.9.3