实现更新元素结点指令
parent
3264956cdf
commit
7e6df3b125
@ -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
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue