调整Instruct的命名和继承逻辑,减少非服务器接收Instruct的实现,并且减少代码的if嵌套。
parent
e2c85517cc
commit
670856fb58
@ -0,0 +1,132 @@
|
|||||||
|
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using OMS.NET.Common;
|
||||||
|
using OMS.NET.DbClass;
|
||||||
|
|
||||||
|
namespace OMS.NET.Instructs
|
||||||
|
{
|
||||||
|
public class AddElementInstruct : Instruct
|
||||||
|
{
|
||||||
|
public AddElementInstruct()
|
||||||
|
{
|
||||||
|
Type = "broadcast";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task Handler(string wsid)
|
||||||
|
{
|
||||||
|
return Task.Run(() =>
|
||||||
|
{
|
||||||
|
if (!GlobalArea.LoginCheckByID(wsid)) return;//登录检查,不通过则直接退出
|
||||||
|
if (Data?.GetType() != typeof(JsonElement)) return;//Data 非空和JsonElement类型检查
|
||||||
|
try
|
||||||
|
{
|
||||||
|
long id = Data.GetProperty("id").GetInt64();
|
||||||
|
string type = Data.GetProperty("type").GetString();
|
||||||
|
string points = Data.GetProperty("points").GetString();
|
||||||
|
string point = Data.GetProperty("point").GetString();
|
||||||
|
string? color = Data.GetProperty("color").GetString();
|
||||||
|
int? width = Data.GetProperty("width").GetInt32();
|
||||||
|
string? childRelations = Data.GetProperty("childRelations").GetString();
|
||||||
|
string? fatherRelations = Data.GetProperty("fatherRelations").GetString();
|
||||||
|
string? childNodes = Data.GetProperty("childNodes").GetString();
|
||||||
|
string? fatherNode = Data.GetProperty("fatherNode").GetString();
|
||||||
|
string? details = Data.GetProperty("details").GetString();
|
||||||
|
string? custom = Data.GetProperty("custom").GetString();
|
||||||
|
//validations todo
|
||||||
|
//假设所有数据均合法
|
||||||
|
MapData mapData = new()
|
||||||
|
{
|
||||||
|
Type = type,
|
||||||
|
Points = Util.JsonToBase64(points),
|
||||||
|
Point = Util.JsonToBase64(point),
|
||||||
|
Color = color,
|
||||||
|
Width = width,
|
||||||
|
ChildRelations = childRelations,
|
||||||
|
FatherRelations = fatherRelations,
|
||||||
|
ChildNodes = childNodes,
|
||||||
|
FatherNode = fatherNode,
|
||||||
|
Details = Util.JsonToBase64(details),
|
||||||
|
Custom = Util.JsonToBase64(custom)
|
||||||
|
};
|
||||||
|
//保存点到数据库
|
||||||
|
MapData.Add(mapData);
|
||||||
|
//获取图层id
|
||||||
|
if (Data.GetProperty("custom").TryGetProperty("tmpId", out JsonElement tmpIdNode))
|
||||||
|
{
|
||||||
|
string tmpId = tmpIdNode.GetString() ?? throw new Exception("tmpId不能为空");
|
||||||
|
LayerData? layer = GlobalArea.GetLayerDataByTemplateId(tmpId);
|
||||||
|
if (layer != null && mapData.Id != -1)
|
||||||
|
{
|
||||||
|
layer.AppendElement(mapData.Id, mapData.Type);//包括数据库操作
|
||||||
|
//准备回复广播
|
||||||
|
string conveyor = GlobalArea.GetLoginEmailByID(wsid);
|
||||||
|
string time = GlobalArea.GetCurrentTime();
|
||||||
|
ResponseOrBroadcastInstructs.Add(new Instruct()
|
||||||
|
{
|
||||||
|
IsBroadcast = true,
|
||||||
|
Type = "broadcast",
|
||||||
|
Class = this.Class,
|
||||||
|
Conveyor = conveyor,
|
||||||
|
Time = time,
|
||||||
|
Data = mapData,
|
||||||
|
});
|
||||||
|
ResponseOrBroadcastInstructs.Add(new Instruct()
|
||||||
|
{
|
||||||
|
IsBroadcast = true,
|
||||||
|
Type = "broadcast",
|
||||||
|
Class = "updateLayerData",
|
||||||
|
Conveyor = conveyor,
|
||||||
|
Time = time,
|
||||||
|
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 = time,
|
||||||
|
Data = new Dictionary<string, object>()
|
||||||
|
{
|
||||||
|
{"vid",id},
|
||||||
|
{"rid",mapData.Id}
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("未找到 tmpId");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
ResponseOrBroadcastInstructs.Add(new Instruct()
|
||||||
|
{
|
||||||
|
IsResponse = true,
|
||||||
|
Type = "send_error",
|
||||||
|
Class = "upload",
|
||||||
|
Conveyor = GlobalArea.GetLoginEmailByID(wsid),
|
||||||
|
Time = GlobalArea.GetCurrentTime(),
|
||||||
|
Data = new
|
||||||
|
{
|
||||||
|
source = Data,
|
||||||
|
message = ex.Message
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,31 +0,0 @@
|
|||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
namespace OMS.NET.Instructs
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 广播指令的基类
|
|
||||||
/// </summary>
|
|
||||||
public class BroadcastInstuct : Instruct
|
|
||||||
{
|
|
||||||
public BroadcastInstuct()
|
|
||||||
{
|
|
||||||
this.Type = "broadcast";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SendCorrectInstuct : Instruct
|
|
||||||
{
|
|
||||||
public SendCorrectInstuct()
|
|
||||||
{
|
|
||||||
this.Type = "send_error";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SendErrorInstuct : Instruct
|
|
||||||
{
|
|
||||||
public SendErrorInstuct()
|
|
||||||
{
|
|
||||||
this.Type = "send_correct";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue