using System;
|
using System.Collections.Generic;
|
|
namespace HDL_ON.Entity
|
{
|
/// <summary>
|
/// 读取服务器空间信息返回到数据包
|
/// </summary>
|
public class RoomApiPack
|
{
|
public List<SpatialInfo> list = new List<SpatialInfo>();
|
|
public string totalCount = "0";
|
|
public string totalPage = "0";
|
|
public string pageNo = "0";
|
|
public string pageSize = "0";
|
|
}
|
/// <summary>
|
/// 空间信息基础类
|
/// 包含楼层/房间
|
/// </summary>
|
public class SpatialInfo
|
{
|
public string roomId = "";
|
public string roomName = "";
|
public string roomImage = "";
|
public string roomType = "";
|
public string parentId = "";
|
public string uid = Guid.NewGuid().ToString();
|
|
public string createTime = "";
|
public string modifyTime = "";
|
|
protected void SaveSpatialInfo()
|
{
|
var pm = new DAL.Server.HttpServerRequest();
|
if (string.IsNullOrEmpty(createTime) && string.IsNullOrEmpty(modifyTime))
|
{
|
pm.AddRoom(new List<SpatialInfo>() { this });
|
}
|
else if (string.IsNullOrEmpty(createTime) && !string.IsNullOrEmpty(modifyTime))
|
{
|
pm.DeleteRoom(new List<string>() { roomId });
|
}
|
else if (!string.IsNullOrEmpty(createTime) && !string.IsNullOrEmpty(modifyTime))
|
{
|
pm.UpdateRoom(new List<SpatialInfo>() { this });
|
}
|
}
|
|
/// <summary>
|
/// 更新楼层信息
|
/// </summary>
|
public void UpdateSpatialInfoData()
|
{
|
if (roomType == "ROOM")
|
{
|
|
}
|
else if (roomType == "FLOOR")
|
{
|
var tempFloor = Floor.InsFloor.Floors.Find((obj) => obj.roomId == roomId);
|
if (tempFloor == null)
|
{
|
Floor.InsFloor.Floors.Add(this as Floor);
|
}
|
else
|
{
|
tempFloor = this as Floor;
|
}
|
var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(Floor.InsFloor.Floors));
|
FileUtils.WriteFileByBytes(Floor.InsFloor.FloorDataSavePath, ssd);
|
MainPage.Log("更新楼层信息");
|
}
|
}
|
}
|
|
/// <summary>
|
/// 房间对象
|
/// </summary>
|
[Serializable]
|
public class Floor : SpatialInfo
|
{
|
#region 楼层数据相关
|
static Floor ins_Floor ;
|
public static Floor InsFloor {
|
get {
|
if(ins_Floor== null)
|
{
|
ins_Floor = new Floor();
|
}
|
return ins_Floor;
|
}
|
}
|
public string FloorDataSavePath = "FloorsData";
|
/// <summary>
|
/// 楼层列表
|
/// </summary>
|
List<Floor> floors;
|
public List<Floor> Floors
|
{
|
get
|
{
|
if (floors == null)
|
{
|
try
|
{
|
var floorsDataBytes = FileUtils.ReadFile(FloorDataSavePath);
|
if (floorsDataBytes != null)
|
{
|
var floorsDataString = System.Text.Encoding.UTF8.GetString(floorsDataBytes);
|
MainPage.Log(floorsDataString);
|
floors = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Floor>>(floorsDataString);
|
if (floors == null)
|
{
|
floors = new List<Floor>();
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log($"楼层数据初始化失败:{ex.Message}");
|
}
|
}
|
return floors;
|
}
|
}
|
|
/// <summary>
|
/// 增加楼层
|
/// </summary>
|
/// <param name="floor"></param>
|
public void AddFloor(Floor floor)
|
{
|
ins_Floor.floors.Add(floor);
|
floor.SaveFloorData();
|
}
|
/// <summary>
|
/// 删除楼层
|
/// </summary>
|
/// <param name="floor"></param>
|
public void DelFloor(Floor floor)
|
{
|
var tRoom = ins_Floor.floors.Find((obj) => obj.uid == floor.uid);
|
if (tRoom != null)
|
{
|
ins_Floor.floors.Remove(floor);
|
floor.modifyTime = "";
|
}
|
SaveFloorData();
|
}
|
|
#endregion
|
|
public Floor()
|
{
|
roomType = "FLOOR";
|
parentId = DB_ResidenceData.residenceData.CurReginID;
|
}
|
/// <summary>
|
/// 保存楼层数据
|
/// </summary>
|
public void SaveFloorData()
|
{
|
var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(ins_Floor.floors));
|
FileUtils.WriteFileByBytes(FloorDataSavePath, ssd);
|
MainPage.Log($"Save floor Data");
|
base.SaveSpatialInfo();
|
}
|
|
}
|
|
[Serializable]
|
public class Room : SpatialInfo
|
{
|
public Room()
|
{
|
roomType = "ROOM";
|
roomName = "Room";
|
}
|
public string backgroundImage = "Classification/Room/Roombg.png";
|
public string roomSavePath
|
{
|
get
|
{
|
return "RoomPath_" + uid;
|
}
|
}
|
/// <summary>
|
/// 楼层
|
/// </summary>
|
[Newtonsoft.Json.JsonIgnore]
|
public string floorName
|
{
|
get
|
{
|
if (Floor.InsFloor.Floors.Count > 0)
|
{
|
var f = Floor.InsFloor.Floors.Find((obj) => obj.uid == parentId);
|
if (f != null)
|
{
|
return f.roomName + " ";
|
}
|
}
|
return "";
|
}
|
}
|
|
/// <summary>
|
/// 房间功能列表
|
/// </summary>
|
List<Function> functions = new List<Function>();
|
/// <summary>
|
/// 获取房间功能列表
|
/// </summary>
|
public List<Function> GetRoomFunctions(bool needRefresh)
|
{
|
if (needRefresh)
|
{
|
functions = new List<Function>();
|
}
|
if (functions.Count == 0)
|
{
|
foreach (var f in DB_ResidenceData.functionList.GetAllFunction())
|
{
|
if (f.roomIds.Contains(uid) && uid != null)
|
{
|
functions.Add(f);
|
}
|
}
|
}
|
return functions;
|
}
|
/// <summary>
|
/// 增加房间功能
|
/// 操作的是缓存数据,不用保存
|
/// </summary>
|
public void AddRoomFunction(Function function)
|
{
|
functions.Add(function);
|
}
|
/// <summary>
|
/// 删除房间功能
|
/// 操作的是缓存数据,不用保存
|
/// </summary>
|
public void RemoveRoomFunction(Function function)
|
{
|
functions.Remove(functions.Find((obj) => obj.sid == function.sid));
|
}
|
/// <summary>
|
/// 房间场景列表
|
/// </summary>
|
List<Scene> scenes = new List<Scene>();
|
/// <summary>
|
/// 获取场景列表
|
/// </summary>
|
/// <returns></returns>
|
public List<Scene> GetRoomScenes(bool needRefresh)
|
{
|
if (needRefresh)
|
{
|
scenes = new List<Scene>();
|
}
|
if (scenes.Count == 0)
|
{
|
foreach (var s in DB_ResidenceData.functionList.scenes)
|
{
|
if (s.roomIds.Contains(uid) && uid != null)
|
{
|
scenes.Add(s);
|
}
|
}
|
}
|
return scenes;
|
}
|
/// <summary>
|
/// 增加房间场景
|
/// 操作的是缓存数据,不用保存
|
/// </summary>
|
/// <param name="scene"></param>
|
public void AddRoomScene(Scene scene)
|
{
|
scenes.Add(scene);
|
}
|
/// <summary>
|
/// 移除房间场景
|
/// 操作的是缓存数据,不用保存
|
/// </summary>
|
/// <param name="scene"></param>
|
public void RemoveRoomScene(Scene scene)
|
{
|
scenes.Remove(scenes.Find((obj) => obj.sid == scene.sid));
|
}
|
/// <summary>
|
/// 保存房间数据
|
/// </summary>
|
public void SaveRoomData()
|
{
|
var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
|
FileUtils.WriteFileByBytes(roomSavePath, ssd);
|
MainPage.Log($"Save Room Data {roomName} : {this.uid}");
|
base.SaveSpatialInfo();
|
}
|
}
|
|
}
|