From cb0103b9883896d02f1e5f5f75a7bbb2b7b7590d Mon Sep 17 00:00:00 2001 From: nxiaoxiao <3247747442@qq.com> Date: Sun, 18 Aug 2024 20:16:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E5=B1=82=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/LayerData.cs | 23 ++++++++++++ GlobalArea.cs | 22 ++++-------- Instructs/UpdateLayerOrderInstruct.cs | 50 +++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 Instructs/UpdateLayerOrderInstruct.cs diff --git a/Common/LayerData.cs b/Common/LayerData.cs index 264328d..c144190 100644 --- a/Common/LayerData.cs +++ b/Common/LayerData.cs @@ -107,6 +107,29 @@ namespace OMS.NET.Common } } + public void AdjustOrderLayer(long layerAId, long layerBId, string type) + { + if (Type == "order") + { + JsonArray array = Members!.AsArray(); + int indexA = array.FindElementIndex(layerAId); + int indexB = array.FindElementIndex(layerBId); + + if (type == "up") + { + array.RemoveAt(indexA); + array.Insert(indexB, layerAId); + } + + if (type == "down") + { + array.RemoveAt(indexA); + indexB = array.FindElementIndex(layerBId); + array.Insert(indexB + 1, layerAId); + } + UpdateToDb(); + } + } public MapLayer ConvertToMapLayer() { return new MapLayer() diff --git a/GlobalArea.cs b/GlobalArea.cs index d223391..956c898 100644 --- a/GlobalArea.cs +++ b/GlobalArea.cs @@ -380,21 +380,13 @@ namespace OMS.NET } } - // public static LayerData? GetLayerDataByLayerId(long layerId) - // { - // lock (_LayerDataListLock) - // { - // try - // { - // return _LayerDataList.Where(x => x.LayerId == layerId).First(); - // } - // catch - // { - // Log.Warn("通过图层id未获取到图层数据"); - // return null; - // } - // } - // } + public static LayerData GetOrderLayerData() + { + lock (_LayerDataListLock) + { + return _LayerDataList.Where(x => x.Type == "order").First()!; + } + } public static dynamic AdjustElementOrder(long elementAId, long elementBId, string templateA, string templateB, string method) { diff --git a/Instructs/UpdateLayerOrderInstruct.cs b/Instructs/UpdateLayerOrderInstruct.cs new file mode 100644 index 0000000..53ff4dd --- /dev/null +++ b/Instructs/UpdateLayerOrderInstruct.cs @@ -0,0 +1,50 @@ +using System.Text.Json; +using System.Text.Json.Nodes; +using OMS.NET.Common; + +namespace OMS.NET.Instructs +{ + public class UpdateLayerOrderInstruct : Instruct + { + public UpdateLayerOrderInstruct() + { + Type = "broadcast"; + Class = "updateLayerOrder"; + } + + 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 active = Data.GetProperty("active").GetInt64(); + long passive = Data.GetProperty("passive").GetInt64(); + string type = Data.GetProperty("type").GetString(); + LayerData order = GlobalArea.GetOrderLayerData(); + order.AdjustOrderLayer(active, passive, type); + ResponseOrBroadcastInstructs.Add(new Instruct() + { + IsBroadcast = true, + Type = "broadcast", + Class = "updateLayerOrder", + Conveyor = conveyor, + Time = GlobalArea.GetCurrentTime(), + Data = new + { + member = order.Members + } + }); + + } + catch (Exception ex) + { + GlobalArea.Log.Warn($"处理{Class}广播指令出错:" + ex.Message); + } + }); + } + } +} \ No newline at end of file