From 7e6df3b12586df957f10f92a186855a0ff98639c Mon Sep 17 00:00:00 2001 From: nxiaoxiao <3247747442@qq.com> Date: Sun, 18 Aug 2024 15:00:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=9B=B4=E6=96=B0=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E7=BB=93=E7=82=B9=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Instructs/UpdateElementNodeInstuct.cs | 83 +++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Instructs/UpdateElementNodeInstuct.cs diff --git a/Instructs/UpdateElementNodeInstuct.cs b/Instructs/UpdateElementNodeInstuct.cs new file mode 100644 index 0000000..a020837 --- /dev/null +++ b/Instructs/UpdateElementNodeInstuct.cs @@ -0,0 +1,83 @@ +using System.Text.Json; +using OMS.NET.Common; +using OMS.NET.DbClass; + +namespace OMS.NET.Instructs +{ + public class UpdateElementNodeInstuct : Instruct + { + public UpdateElementNodeInstuct() + { + Type = "broadcast"; + Class = "updateElementNode"; + } + + public override Task Handler(string wsid) + { + return Task.Run(() => + { + if (!GlobalArea.LoginCheckByID(wsid)) return;//登录检查不通过则直接退出 + if (Data?.GetType() != typeof(JsonElement)) return;//Data 非空和JsonElement类型检查 + string conveyor = GlobalArea.GetLoginEmailByID(wsid); + try + { + long id = Data.GetProperty("id").GetInt64(); + string updateId = Data.GetProperty("updateId").GetString(); + string points = Data.GetProperty("points").GetString()!; + string point = Data.GetProperty("point").GetString()!; + MapData mapData = MapData.Get(id) ?? throw new Exception($"数据库中未能找到id为{id}的元素"); + mapData.Points = Util.JsonToBase64(points); + mapData.Point = Util.JsonToBase64(point); + + if (MapData.Update(mapData) == -1) throw new Exception("数据库修改失败"); + ResponseOrBroadcastInstructs.Add(new Instruct() + { + IsResponse = true, + Type = "send_correct", + Class = "updateNode", + Conveyor = conveyor, + Time = GlobalArea.GetCurrentTime(), + Data = new + { + vid = updateId, + rid = id + } + }); + ResponseOrBroadcastInstructs.Add(new Instruct() + { + IsBroadcast = true, + Type = "broadcast", + Class = "updateElementNode", + Conveyor = conveyor, + Time = GlobalArea.GetCurrentTime(), + Data = new + { + id = mapData.Id, + type = mapData.Type, + point = mapData.Point, + points = mapData.Points + } + }); + + } + catch (Exception ex) + { + GlobalArea.Log.Warn($"处理{Class}广播指令出错:" + ex.Message); + ResponseOrBroadcastInstructs.Add(new Instruct() + { + IsResponse = true, + Type = "send_error", + Class = "updateNode", + Conveyor = conveyor, + Time = GlobalArea.GetCurrentTime(), + Data = new + { + source = Data, + message = ex.Message + } + }); + } + }); + } + } +} \ No newline at end of file