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); } }); } } }