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.
63 lines
2.1 KiB
C#
63 lines
2.1 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Nodes;
|
|
using OMS.NET.DbClass;
|
|
|
|
namespace OMS.NET.Common
|
|
{
|
|
public class LayerData
|
|
{
|
|
public string? TemplateId { get; set; }
|
|
public long LayerId { get; set; }
|
|
public bool HasChange { get; set; } = false;
|
|
public string Type { get; set; }
|
|
public JsonNode? Members { get; set; }
|
|
public JsonNode? Structure { get; set; }
|
|
public int Phase { get; set; } = 1;
|
|
|
|
public LayerData(long layerId, string type)
|
|
{
|
|
LayerId = layerId;
|
|
Type = type;
|
|
}
|
|
|
|
public LayerData(string? templateId, MapLayer layer)
|
|
{
|
|
TemplateId = templateId;
|
|
LayerId = layer.Id;
|
|
Type = layer.Type;
|
|
Members = (layer.Type == "order") ? JsonNode.Parse(layer.Members) : JsonNode.Parse(Util.Base64ToJson(layer.Members));
|
|
Structure = string.IsNullOrEmpty(layer.Structure) ? null : JsonNode.Parse(Util.Base64ToJson(layer.Structure));
|
|
Phase = layer.Phase;
|
|
}
|
|
|
|
public void AppendElement(long itemId, string ItemType)
|
|
{
|
|
if (Type == "order")
|
|
{
|
|
GlobalArea.Log.Error($"order图层不能添加{ItemType}元素");
|
|
return;
|
|
}
|
|
if (Members![itemId.ToString()] == null)
|
|
{
|
|
Members![itemId.ToString()] = ItemType;
|
|
Structure!.AsArray().Add(itemId);
|
|
HasChange = true;
|
|
//上传图层到数据库
|
|
MapLayer mapLayer = ConvertToMapLayer();
|
|
MapLayer.Update(mapLayer);
|
|
}
|
|
}
|
|
|
|
public MapLayer ConvertToMapLayer()
|
|
{
|
|
return new MapLayer()
|
|
{
|
|
Id = LayerId,
|
|
Type = Type,
|
|
Members = (Type == "order") ? Members!.ToString() : Util.JsonToBase64(Members!.ToString()),
|
|
Structure = (Structure == null) ? "" : Util.JsonToBase64(Structure!.ToString()),
|
|
Phase = Phase
|
|
};
|
|
}
|
|
}
|
|
} |