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