实现麻烦的调整元素顺序指令
parent
13b64ed549
commit
2666922c4e
@ -0,0 +1,31 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
|
namespace OMS.NET.Common
|
||||||
|
{
|
||||||
|
public static class Extensions
|
||||||
|
{
|
||||||
|
public static int FindElementIndex(this JsonArray jsonArray, long elementToFind)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < jsonArray.Count; i++)
|
||||||
|
{
|
||||||
|
JsonNode node = jsonArray.ElementAt(i)!;
|
||||||
|
if (node.GetValueKind() == JsonValueKind.Number &&
|
||||||
|
node.GetValue<long>() == elementToFind)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1; // 未找到目标元素,返回 -1
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveAll(this JsonArray jsonArray, Func<JsonNode?, bool> predicate)
|
||||||
|
{
|
||||||
|
var itemsToRemove = jsonArray.Where(predicate).ToList();
|
||||||
|
foreach (var item in itemsToRemove)
|
||||||
|
{
|
||||||
|
jsonArray.Remove(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,75 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using OMS.NET.Common;
|
||||||
|
using OMS.NET.DbClass;
|
||||||
|
|
||||||
|
namespace OMS.NET.Instructs
|
||||||
|
{
|
||||||
|
public class AdjustElementOrderInstuct : Instruct
|
||||||
|
{
|
||||||
|
public AdjustElementOrderInstuct()
|
||||||
|
{
|
||||||
|
Type = "broadcast";
|
||||||
|
Class = "adjustElementOrder";
|
||||||
|
}
|
||||||
|
|
||||||
|
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 elementA = Data.GetProperty("elementA").GetInt64();
|
||||||
|
long elementB = Data.GetProperty("elementB").GetInt64();
|
||||||
|
string templateA = Data.GetProperty("templateA").GetString();
|
||||||
|
string templateB = Data.GetProperty("templateB").GetString();
|
||||||
|
string method = Data.GetProperty("method").GetString();
|
||||||
|
dynamic result = GlobalArea.AdjustElementOrder(elementA, elementB, templateA, templateB, method);
|
||||||
|
List<dynamic> list = new();
|
||||||
|
foreach (LayerData layerData in result.layers)
|
||||||
|
{
|
||||||
|
list.Add(new
|
||||||
|
{
|
||||||
|
id = layerData.LayerId,
|
||||||
|
members = layerData.Members,
|
||||||
|
structure = layerData.Structure,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ResponseOrBroadcastInstructs.Add(new Instruct()
|
||||||
|
{
|
||||||
|
IsBroadcast = true,
|
||||||
|
Type = "broadcast",
|
||||||
|
Class = "batchUpdateLayerData",
|
||||||
|
Conveyor = conveyor,
|
||||||
|
Time = GlobalArea.GetCurrentTime(),
|
||||||
|
Data = list
|
||||||
|
});
|
||||||
|
if (result.element != null && result.element.GetType() != typeof(MapData))
|
||||||
|
{
|
||||||
|
ResponseOrBroadcastInstructs.Add(new Instruct()
|
||||||
|
{
|
||||||
|
IsBroadcast = true,
|
||||||
|
Type = "broadcast",
|
||||||
|
Class = "updateElement",
|
||||||
|
Conveyor = conveyor,
|
||||||
|
Time = GlobalArea.GetCurrentTime(),
|
||||||
|
Data = new
|
||||||
|
{
|
||||||
|
id = result.element.ID,
|
||||||
|
type = result.element.Type,
|
||||||
|
details = result.element.Details,
|
||||||
|
custom = result.element.Custom
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
GlobalArea.Log.Warn($"处理{Class}广播指令出错:" + ex.Message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue