From dcb9b9b5561b4e6d1eaf1e602e8ae054e578ec6e Mon Sep 17 00:00:00 2001 From: 陈嘉乐 <cjl@hdlchina.com.cn> Date: 星期五, 04 十二月 2020 16:06:47 +0800 Subject: [PATCH] Merge branch 'master' into WJC --- HDL_ON/Entity/Room.cs | 467 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 395 insertions(+), 72 deletions(-) diff --git a/HDL_ON/Entity/Room.cs b/HDL_ON/Entity/Room.cs index d339869..91e78cd 100644 --- a/HDL_ON/Entity/Room.cs +++ b/HDL_ON/Entity/Room.cs @@ -1,55 +1,412 @@ 锘縰sing System; using System.Collections.Generic; +using HDL_ON.DAL.Server; namespace HDL_ON.Entity { /// <summary> - /// 鎴块棿瀵硅薄 + /// 璇诲彇鏈嶅姟鍣ㄧ┖闂翠俊鎭繑鍥炲埌鏁版嵁鍖� /// </summary> - [Serializable] - public class Floor + public class SpatialApiPack { - /// <summary> - /// 妤煎眰鍚嶇О - /// </summary> - public string name = "1F"; - /// <summary> - /// 妤煎眰ID - /// </summary> - public string sid; + 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> - [Serializable] - public class Room + public class SpatialInfo { - /// <summary> - /// 鎴块棿鍚� - /// </summary> - public string name = "Room"; - - public string roomSavePath + static SpatialInfo _currentSpatial; + public static SpatialInfo CurrentSpatial { get { - return "RoomPath_" + sid; + if (_currentSpatial == null) + { + _currentSpatial = new SpatialInfo(); + } + return _currentSpatial; + } + } + public SpatialInfo() + { + } + + public SpatialInfo(string spatialType) + { + roomType = "FLOOR"; + parentId = DB_ResidenceData.residenceData.CurReginID; + } + + 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 = ""; + /// <summary> + /// 鍒犻櫎鏍囪 + /// 闇�瑕佸垹闄ゆ暟鎹椂锛屾爣璁颁负锛歵rue + /// 鐢变簯绔垹闄ゆ垚鍔熶箣鍚庯紝杩斿洖鏁版嵁鍐嶆竻闄ゆ湰鍦版暟鎹� + /// </summary> + public bool DeleteSign = false; + + + protected void SaveSpatialInfo() + { + var pm = new 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 DownloadRoomList() + { + new System.Threading.Thread(() => + { + var pm = new HttpServerRequest(); + var pack = pm.GetRoomList(); + if (pack.Code == StateCode.SUCCESS) + { + var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<SpatialApiPack>(pack.Data.ToString()); + if (revData != null) + { + CurrentSpatial.UpdateSpatialList(revData.list, OptionType.Cover); + } + } + else + { + MainPage.Log($"璇诲彇鎴块棿鏁版嵁澶辫触:\r\nCode:{pack.Code}; msg:{pack.message}"); + } + }) + { IsBackground = true }.Start(); + } + + /// <summary> + /// 鏇存柊绌洪棿淇℃伅 + /// </summary> + /// <param name="spatials">绌洪棿淇℃伅</param> + /// <param name="optionType">鎿嶄綔绫诲瀷锛欰DD/UPDATE/DELETE</param> + public void UpdateSpatialList(List<SpatialInfo> spatials,OptionType optionType) + { + var roomUpdateList = spatials.FindAll((obj) => obj.roomType == "ROOM"); + var floorUpdateList = spatials.FindAll((obj) => obj.roomType == "FLOOR"); + //澶勭悊鎴块棿鍒楄〃 + if (roomUpdateList != null && roomUpdateList.Count > 0) + { + if (optionType == OptionType.Update) + { + foreach (var updateTemp in roomUpdateList) + { + var localRoom = CurrentSpatial.RoomList.Find((obj) => obj.roomId == updateTemp.roomId); + if (localRoom != null) + { + localRoom.roomName = updateTemp.roomName; + localRoom.roomImage = updateTemp.roomImage; + localRoom.parentId = updateTemp.parentId; + localRoom.createTime = updateTemp.createTime; + localRoom.modifyTime = updateTemp.modifyTime; + localRoom.SaveRoomData(); + }else + { + updateTemp.SaveRoomData(); + } + } + } + else if (optionType == OptionType.Cover) + { + CurrentSpatial.DeleteAllRoom(); + foreach(var newRoom in roomUpdateList) + { + newRoom.SaveRoomData(); + } + } + } + //妤煎眰鎴块棿鍒楄〃 + if (floorUpdateList != null && floorUpdateList.Count > 0) + { + if (optionType == OptionType.Update) + { + foreach(var updateTemp in floorUpdateList) + { + var localFloor = FloorList.Find((obj) => obj.roomId == updateTemp.roomId); + if (localFloor == null) + { + FloorList.Add(updateTemp); + } + else + { + localFloor = updateTemp; + } + } + CurrentSpatial.SaveFloorData(); + } + if(optionType == OptionType.Cover) + { + FloorList.Clear(); + foreach (var updateTemp in floorUpdateList) + { + FloorList.Add(updateTemp); + } + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList)); + FileUtils.WriteFileByBytes(dataSavePath, ssd); + } + } + } + + #region 妤煎眰鍒楄〃 + /// <summary> + /// 妤煎眰鍒楄〃 + /// </summary> + List<SpatialInfo> floors; + /// <summary> + /// 妤煎眰鍒楄〃 + /// </summary> + public List<SpatialInfo> FloorList + { + get + { + if (floors == null) + { + try + { + var floorsDataBytes = FileUtils.ReadFile(dataSavePath); + if (floorsDataBytes != null) + { + var floorsDataString = System.Text.Encoding.UTF8.GetString(floorsDataBytes); + MainPage.Log(floorsDataString); + floors = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpatialInfo>>(floorsDataString); + if (floors == null) + { + floors = new List<SpatialInfo>(); + } + } + } + catch (Exception ex) + { + MainPage.Log($"妤煎眰鏁版嵁鍒濆鍖栧け璐ワ細{ex.Message}"); + } + } + return floors; } } /// <summary> - /// 鎴块棿ID + /// 鏁版嵁淇濆瓨璺緞 /// </summary> - public string sid; + string dataSavePath + { + get + { + if(roomType == "ROOM") + { + return "RoomPath_" + uid; + } + if(roomType == "FLOOR") + { + return "FloorsData"; + } + else + { + return "SpatialInfo_"+uid; + } + } + } /// <summary> - /// 鎴块棿鑳屾櫙 + /// 澧炲姞妤煎眰 /// </summary> + /// <param name="floor"></param> + public void AddFloor(SpatialInfo floor) + { + FloorList.Add(floor); + SaveFloorData(); + } + /// <summary> + /// 鏇存柊妤煎眰淇℃伅 + /// </summary> + /// <param name="floor"></param> + public void UpdateFloor() + { + SaveFloorData(); + } + /// <summary> + /// 鍒犻櫎妤煎眰 + /// </summary> + /// <param name="floor"></param> + public void DelFloor(SpatialInfo floor) + { + var tRoom = FloorList.Find((obj) => obj.uid == floor.uid); + if (tRoom != null) + { + FloorList.Remove(floor); + floor.modifyTime = ""; + } + SaveFloorData(); + } + + /// <summary> + /// 淇濆瓨妤煎眰鏁版嵁 + /// </summary> + void SaveFloorData() + { + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList)); + FileUtils.WriteFileByBytes(dataSavePath, ssd); + MainPage.Log($"Save floor Data"); + SaveSpatialInfo(); + } + + /// <summary> + /// 淇濆瓨鎴块棿鏁版嵁 + /// </summary> + public void SaveRoomData() + { + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); + FileUtils.WriteFileByBytes(dataSavePath, ssd); + MainPage.Log($"Save Room Data {roomName} : {uid}"); + SaveSpatialInfo(); + } + #endregion + + #region 鎴块棿鍒楄〃 + /// <summary> + /// 鎴块棿鍒楄〃 + /// </summary> + List<Room> rooms; + /// <summary> + /// 鎴块棿鍒楄〃 + /// </summary> + public List<Room> RoomList + { + get + { + if (rooms == null) + { + try + { + rooms = new List<Room> { }; + var filePathList = FileUtils.ReadFiles(); + + foreach (var filePath in filePathList) + { + if (filePath.StartsWith("RoomData_")) + { + var roomDataBytes = FileUtils.ReadFile(filePath); + var roomDataString = System.Text.Encoding.UTF8.GetString(roomDataBytes); + var room = Newtonsoft.Json.JsonConvert.DeserializeObject<Room>(roomDataString); + if (room != null) + { + rooms.Add(room); + } + } + } + } + catch (Exception ex) + { + MainPage.Log($"鍔熻兘鏁版嵁鍒濆鍖栧け璐ワ細{ex.Message}"); + } + } + return rooms; + } + } + /// <summary> + /// 澧炲姞鎴块棿 + /// </summary> + /// <param name="room"></param> + public void AddRoom(Room room) + { + RoomList.Add(room); + room.SaveRoomData(); + } + /// <summary> + /// 鍒犻櫎鎴块棿 + /// </summary> + /// <param name="room"></param> + public void DelRoom(Room room) + { + var tRoom = RoomList.Find((obj) => obj.uid == room.uid); + if (tRoom != null) + { + FileUtils.DeleteFile(room.dataSavePath); + RoomList.Remove(room); + room.DeleteSign = true; + } + room.SaveRoomData(); + } + /// <summary> + /// 鍒犻櫎鎵�鏈夋埧闂� + /// </summary> + public void DeleteAllRoom() + { + foreach(var localRoom in RoomList) + { + FileUtils.DeleteFile(localRoom.dataSavePath); + } + RoomList.Clear(); + } + /// <summary> + /// 鍒濆鍖栨瘡涓埧闂寸殑鍔熻兘鏁版嵁 + /// </summary> + public void InitRoomFunction() + { + new System.Threading.Thread(() => + { + try + { + //鍒濆鍖栦綇瀹呮墍鏈夋埧闂村姛鑳芥暟鎹� + foreach (var r in RoomList) + { + r.GetRoomFunctions(true); + r.GetRoomScenes(true); + } + } + catch (Exception ex) + { + MainPage.Log($"Init room function error : {ex.Message}"); + } + }) + { IsBackground = true }.Start(); + } + + + #endregion + + } + + + + [Serializable] + public class Room : SpatialInfo + { + public Room() + { + roomType = "ROOM"; + roomName = "Room"; + } public string backgroundImage = "Classification/Room/Roombg.png"; - /// <summary> - /// 妤煎眰绱㈠紩 - /// </summary> - public string floorId = ""; + /// <summary> /// 妤煎眰 /// </summary> @@ -58,17 +415,18 @@ { get { - if (DB_ResidenceData.residenceData.floors.Count > 0) + if (FloorList.Count > 0) { - var f = DB_ResidenceData.residenceData.floors.Find((obj) => obj.sid == floorId); + var f = FloorList.Find((obj) => obj.uid == parentId); if (f != null) { - return f.name + " "; + return f.roomName + " "; } } return ""; } } + /// <summary> /// 鎴块棿鍔熻兘鍒楄〃 /// </summary> @@ -78,7 +436,7 @@ /// </summary> public List<Function> GetRoomFunctions(bool needRefresh) { - if(needRefresh) + if (needRefresh) { functions = new List<Function>(); } @@ -86,7 +444,7 @@ { foreach (var f in DB_ResidenceData.functionList.GetAllFunction()) { - if (f.roomIds.Contains(sid) && sid != null) + if (f.roomIds.Contains(uid) && uid != null) { functions.Add(f); } @@ -128,7 +486,7 @@ { foreach (var s in DB_ResidenceData.functionList.scenes) { - if (s.roomIds.Contains(sid) && sid != null) + if (s.roomIds.Contains(uid) && uid != null) { scenes.Add(s); } @@ -154,41 +512,6 @@ { 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("RoomData_" + this.sid, ssd); - MainPage.Log($"Save FunctionData {name} : {this.sid}"); - } - - } - - /// <summary> - /// 鏈嶅姟杩斿洖鐨勬埧闂村璞� - /// </summary> - public class ServerReplyRoom - { - //浜戠鎴块棿ID - public string roomId = ""; - /// <summary> - /// 鎴块棿鍚嶇О - /// </summary> - public string roomName = ""; - /// <summary> - /// 鎴块棿鍥剧墖 - /// </summary> - public string roomImage = ""; - /// <summary> - /// 鎴块棿鍏ㄥ悕 - /// </summary> - public string roomFullName = ""; - /// <summary> - /// 璋冭瘯杞欢\app鐢熸垚鐨勫敮涓�ID - /// </summary> - public string uid = ""; - } + } \ No newline at end of file -- Gitblit v1.8.0