You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
4.3 KiB
C#
110 lines
4.3 KiB
C#
using System.Text.Json;
|
|
using OMS.NET.Common;
|
|
using OMS.NET.DbClass;
|
|
|
|
namespace OMS.NET.Instructs
|
|
{
|
|
public class DeleteElementInstruct : Instruct
|
|
{
|
|
public DeleteElementInstruct()
|
|
{
|
|
Type = "broadcast";
|
|
Class = "deleteElement";
|
|
}
|
|
|
|
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
|
|
{
|
|
//解析id和tmpId
|
|
long id = Data.GetProperty("id").GetInt64();
|
|
string tmpId = Data.GetProperty("tmpId").GetString();
|
|
//需要先实现activeData相关
|
|
MapData mapData = MapData.Get(id) ?? throw new Exception($"Element{id}不存在");
|
|
mapData.Phase = 2;
|
|
int row = MapData.Update(mapData);
|
|
if (row == -1) throw new Exception("数据库修改失败");
|
|
if (GlobalArea.IsElementExit(id))
|
|
{
|
|
GlobalArea.RemoveActiveDataElement(id);
|
|
ResponseOrBroadcastInstructs.Add(new Instruct()
|
|
{
|
|
IsBroadcast = true,
|
|
Type = "broadcast",
|
|
Class = "pickSelectEndElements",
|
|
Conveyor = conveyor,
|
|
Time = GlobalArea.GetCurrentTime(),
|
|
Data = new
|
|
{
|
|
id = id
|
|
}
|
|
});
|
|
}
|
|
ResponseOrBroadcastInstructs.Add(new Instruct()
|
|
{
|
|
IsResponse = true,
|
|
Type = "send_correct",
|
|
Class = "delete",
|
|
Conveyor = conveyor,
|
|
Time = GlobalArea.GetCurrentTime(),
|
|
Data = new
|
|
{
|
|
rid = id
|
|
}
|
|
});
|
|
ResponseOrBroadcastInstructs.Add(new Instruct()
|
|
{
|
|
IsBroadcast = true,
|
|
Type = "broadcast",
|
|
Class = "deleteElement",
|
|
Conveyor = conveyor,
|
|
Time = GlobalArea.GetCurrentTime(),
|
|
Data = new
|
|
{
|
|
id = id
|
|
}
|
|
});
|
|
LayerData layer = GlobalArea.GetLayerDataByTemplateId(tmpId)!;
|
|
layer.DeleteElement(id);
|
|
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(),
|
|
}
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
GlobalArea.Log.Warn($"处理{Class}广播指令出错:" + ex.Message);
|
|
//ResponseOrBroadcastInstructs.Clear();
|
|
ResponseOrBroadcastInstructs.Add(new Instruct()
|
|
{
|
|
IsResponse = true,
|
|
Type = "send_error",
|
|
Class = "delete",
|
|
Conveyor = conveyor,
|
|
Time = GlobalArea.GetCurrentTime(),
|
|
Data = new
|
|
{
|
|
source = Data,
|
|
message = ex.Message
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
} |