From 13b64ed549f69d8d39bd8b5d8285403abc0f7599 Mon Sep 17 00:00:00 2001 From: nxiaoxiao <3247747442@qq.com> Date: Sun, 18 Aug 2024 15:19:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=81=A2=E5=A4=8D=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Instructs/RestoreElementInstruct.cs | 75 +++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Instructs/RestoreElementInstruct.cs diff --git a/Instructs/RestoreElementInstruct.cs b/Instructs/RestoreElementInstruct.cs new file mode 100644 index 0000000..1b21287 --- /dev/null +++ b/Instructs/RestoreElementInstruct.cs @@ -0,0 +1,75 @@ +using System.Text.Json; +using OMS.NET.Common; +using OMS.NET.DbClass; + +namespace OMS.NET.Instructs +{ + public class RestoreElementInstruct : Instruct + { + public RestoreElementInstruct() + { + Type = "broadcast"; + Class = "restoreElement"; + } + + public override Task Handler(string wsid) + { + return Task.Run(() => + { + if (!GlobalArea.LoginCheckByID(wsid)) return;//登录检查不通过则直接退出 + if (Data?.GetType() != typeof(JsonElement)) return;//Data 非空和JsonElement类型检查 + try + { + string conveyor = GlobalArea.GetLoginEmailByID(wsid); + long id = Data.GetProperty("id").GetInt64(); + string tmpId = Data.GetProperty("tmpId").GetString(); + MapData mapData = MapData.Get(id) ?? throw new Exception($"Element{id}不存在"); + mapData.Phase = 1; + if (MapData.Update(mapData) == -1) throw new Exception("数据库修改失败"); + LayerData layer = GlobalArea.GetLayerDataByTemplateId(tmpId)!; + layer.AppendElement(id, mapData.Type); + ResponseOrBroadcastInstructs.Add(new Instruct() + { + IsBroadcast = true, + Type = "broadcast", + Class = mapData.Type, + Conveyor = conveyor, + Time = GlobalArea.GetCurrentTime(), + Data = mapData + }); + ResponseOrBroadcastInstructs.Add(new Instruct() + { + IsBroadcast = true, + Type = "broadcast", + Class = "updateLayerData", + Conveyor = conveyor, + Time = GlobalArea.GetCurrentTime(), + Data = new + { + id = layer.LayerId, + members = layer.Members!.ToString(), + structure = layer.Structure!.ToString(), + } + }); + ResponseOrBroadcastInstructs.Add(new Instruct() + { + IsResponse = true, + Type = "send_correct", + Class = "upload", + Conveyor = conveyor, + Time = GlobalArea.GetCurrentTime(), + Data = new + { + rid = id, + vid = "restore" + } + }); + } + catch (Exception ex) + { + GlobalArea.Log.Warn($"处理{Class}广播指令出错:" + ex.Message); + } + }); + } + } +} \ No newline at end of file