From 43b0d5870d528f23ecd6aeceb6cfd4325188b46f Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期四, 01 七月 2021 15:50:43 +0800 Subject: [PATCH] Revert "1" --- HDL_ON/Entity/Room.cs | 579 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 542 insertions(+), 37 deletions(-) diff --git a/HDL_ON/Entity/Room.cs b/HDL_ON/Entity/Room.cs index 7884d78..609e788 100644 --- a/HDL_ON/Entity/Room.cs +++ b/HDL_ON/Entity/Room.cs @@ -1,67 +1,572 @@ 锘縰sing System; using System.Collections.Generic; +using HDL_ON.DAL.Server; +using Shared; namespace HDL_ON.Entity { - /// <summary> - /// 鎴块棿瀵硅薄 - /// 鎴块棿鍛藉悕瑙勫垯 typeof (Room).Name + "_" + etNameBox.Text.Trim (); + /// 璇诲彇鏈嶅姟鍣ㄧ┖闂翠俊鎭繑鍥炲埌鏁版嵁鍖� /// </summary> - [System.Serializable] - public class Room + public class SpatialApiPack { - /// <summary> - /// 鎴块棿鍚� - /// </summary> - public string name = "Room"; - /// <summary> - /// 鎴块棿ID - /// </summary> - public string sid; - /// <summary> - /// 妤煎眰绱㈠紩 - /// </summary> - public int floorIndex = -1; + 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 + { + static SpatialInfo _currentSpatial; + public static SpatialInfo CurrentSpatial + { + get + { + if (_currentSpatial == null) + { + _currentSpatial = new SpatialInfo(); + } + return _currentSpatial; + } + } + public SpatialInfo() + { + } + + public SpatialInfo(string spatialType) + { + roomType = "FLOOR"; + parentId = DB_ResidenceData.Instance.CurrentRegion.id; + } + + public string homeId = ""; + public string roomId = ""; + public string roomName = ""; + //public string roomImage = ""; + public string roomImage = "Classification/Room/Roombg.png"; + public string roomType = ""; + public string parentId = ""; + public string uid = Guid.NewGuid().ToString(); + public string floorRoomName = ""; + public string createTime = ""; + public string modifyTime = ""; + ///// <summary> + ///// 鍒犻櫎鏍囪 20201208锛氬彲娆�:APP鐨勫湪绾垮拰绂荤嚎闂锛屽垰鍒氱‘瀹氫簡锛岀绾挎棤娉曠紪杈戯紝鍙兘鎺у埗 + ///// 闇�瑕佸垹闄ゆ暟鎹椂锛屾爣璁颁负锛歵rue + ///// 鐢变簯绔垹闄ゆ垚鍔熶箣鍚庯紝杩斿洖鏁版嵁鍐嶆竻闄ゆ湰鍦版暟鎹� + ///// </summary> + //public bool DeleteSign = false; /// <summary> - /// 鎴块棿鑳屾櫙 + /// 鏇存柊绌洪棿淇℃伅 /// </summary> - public string backgroundImage = "Classification/Room/Roombg.png"; + /// <param name="spatials">绌洪棿淇℃伅</param> + /// <param name="optionType">鎿嶄綔绫诲瀷锛欰DD/UPDATE/DELETE</param> + public void UpdateSpatialList(List<SpatialInfo> spatials) + { + var roomUpdateList = spatials.FindAll((obj) => obj.roomType == "ROOM"); + var floorUpdateList = spatials.FindAll((obj) => obj.roomType == "FLOOR"); + CurrentSpatial.DeleteAllRoom(); + FloorList.Clear(); + //澶勭悊鎴块棿鍒楄〃 + if (roomUpdateList != null && roomUpdateList.Count > 0) + { + foreach (var newRoom in roomUpdateList) + { + newRoom.SaveRoomFile(); + RoomList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Room>( + Newtonsoft.Json.JsonConvert.SerializeObject(newRoom))); + } + } + //妤煎眰鎴块棿鍒楄〃 + if (floorUpdateList != null && floorUpdateList.Count > 0) + { + foreach (var updateTemp in floorUpdateList) + { + FloorList.Add(updateTemp); + } + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList)); + Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); + } + } + + #region 妤煎眰鍒楄〃 + /// <summary> + /// 妤煎眰鍒楄〃 + /// </summary> + List<SpatialInfo> floors; + /// <summary> + /// 妤煎眰鍒楄〃 + /// </summary> + public List<SpatialInfo> FloorList + { + get + { + if (MainPage.NoLoginMode) + { + if (floors == null) + { + floors = new List<SpatialInfo>(); + } + return floors; + } + + if (floors == null) + { + try + { + var floorsDataBytes = Common.FileUtlis.Files.ReadFile("FloorsData"); + 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) + { + floors = new List<SpatialInfo>(); + MainPage.Log($"妤煎眰鏁版嵁鍒濆鍖栧け璐ワ細{ex.Message}"); + } + } + return floors; + } + } + /// <summary> + /// 鏁版嵁淇濆瓨璺緞 + /// </summary> + 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 string AddFloor(SpatialInfo floor, out SpatialInfo newFloor) + { + var pm = new HttpServerRequest(); + var revPack = new ResponsePackNew(); + revPack = pm.AddRoom(new List<SpatialInfo>() { floor }); + if (revPack.Code == StateCode.SUCCESS) + { + var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpatialInfo>>(revPack.Data.ToString()); + if (revData.Count > 0) + { + var addFloor = revData.Find((obj) => obj.uid == floor.uid); + if (addFloor != null) + { + CurrentSpatial.FloorList.Add(addFloor); + floor = addFloor; + } + } + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(CurrentSpatial.FloorList)); + Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); + } + else + { + Utlis.ShowTip(Language.StringByID(StringId.AddFloorFail) + "\r\nCode:" + revPack.Code); + } + newFloor = floor; + return revPack.Code; + } + /// <summary> + /// 鏇存柊妤煎眰淇℃伅 + /// </summary> + /// <param name="floor"></param> + public string UpdateFloor(SpatialInfo floor) + { + var pm = new HttpServerRequest(); + var revPack = pm.UpdateRoom(new List<SpatialInfo>() { floor }); + if (revPack.Code == StateCode.SUCCESS) + { + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList)); + Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); + } + return revPack.Code; + } + /// <summary> + /// 鍒犻櫎妤煎眰 + /// </summary> + /// <param name="floor"></param> + public string DelFloor(string floorId) + { + if (string.IsNullOrEmpty( floorId)) + return ""; + var pm = new HttpServerRequest(); + var code = pm.DeleteRoom(new List<string>() { floorId }).Code; + if (code == StateCode.SUCCESS) + { + var tRoom = CurrentSpatial.FloorList.Find((obj) => obj.roomId == floorId); + if (tRoom != null) + { + CurrentSpatial.FloorList.Remove(tRoom); + } + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(FloorList)); + Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); + } + else + { + Utlis.ShowTip(Language.StringByID(StringId.DeleteFloorFail) + "\r\nCode:" + code); + } + return code; + } + + #endregion + + #region 鎴块棿鍒楄〃 + /// <summary> + /// 鎴块棿鍒楄〃 + /// </summary> + List<Room> rooms; + /// <summary> + /// 鎴块棿鍒楄〃 + /// </summary> + public List<Room> RoomList + { + get + { + if(MainPage.NoLoginMode ) + { + if (rooms == null) + { + rooms = new List<Room>(); + } + return rooms; + } + if (rooms == null) + { + try + { + rooms = new List<Room> { }; + var filePathList = Common.FileUtlis.Files.ReadFiles(); + + foreach (var filePath in filePathList) + { + if (filePath.StartsWith("RoomData_")) + { + var roomDataBytes = Common.FileUtlis.Files.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 string AddRoom(Room room,out Room newRoom) + { + var pm = new HttpServerRequest(); + var pack = pm.AddRoom(new List<SpatialInfo>() { room }); + + if (pack.Code == StateCode.SUCCESS) + { + var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpatialInfo>>(pack.Data.ToString()); + if (revData != null) + { + if (revData.Count > 0) + { + var tempRoom = revData.Find((obj) => obj.uid == room.uid); + if (tempRoom != null) + { + room.roomId = tempRoom.roomId; + CurrentSpatial.RoomList.Add(room); + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(room)); + Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); + } + } + } + } + newRoom = room; + return pack.Code; + } + /// <summary> + /// 鍒犻櫎鎴块棿 + /// </summary> + /// <param name="room"></param> + public string DelRoom(Room room) + { + var pm = new HttpServerRequest(); + var pack = pm.DeleteRoom(new List<string>() { room.roomId }); + if (pack.Code == StateCode.SUCCESS) + { + var tRoom = RoomList.Find((obj) => obj.roomId == room.roomId); + if (tRoom != null) + { + CurrentSpatial.RoomList.Remove(room); + } + Common.FileUtlis.Files.DeleteFile(room.dataSavePath); + } + return pack.Code; + } + /// <summary> + /// 鍒犻櫎鎵�鏈夋埧闂� + /// </summary> + public void DeleteAllRoom() + { + for(int i=0;i< RoomList.Count;) + { + Common.FileUtlis.Files.DeleteFile(RoomList[i].dataSavePath); + RoomList.RemoveAt(i); + } + rooms = null; + } + + public void Clear() + { + if (_currentSpatial != null) + { + if (_currentSpatial.floors != null) + { + _currentSpatial.floors.Clear(); + } + if (_currentSpatial.rooms != null) + { + _currentSpatial.rooms.Clear(); + } + _currentSpatial = null; + } + } + + /// <summary> + /// 鍒濆鍖栨瘡涓埧闂寸殑鍔熻兘鏁版嵁 + /// </summary> + public void InitRoomListFunctions() + { + new System.Threading.Thread(() => + { + try + { + //鍒濆鍖栦綇瀹呮墍鏈夋埧闂村姛鑳芥暟鎹� + foreach (var r in RoomList) + { + InitRoomFuntion(r); + } + } + catch (Exception ex) + { + MainPage.Log($"Init room function error : {ex.Message}"); + } + }) + { IsBackground = true }.Start(); + } + /// <summary> + /// 鍒濆鍖栨埧闂村姛鑳� + /// </summary> + /// <param name="tempRoom"></param> + public void InitRoomFuntion(Room tempRoom) + { + tempRoom.GetRoomFunctions(true); + tempRoom.GetRoomScenes(true); + } + + /// <summary> + /// 淇濆瓨鎴块棿鏁版嵁鏂囦欢 + /// </summary> + public void SaveRoomFile() + { + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); + Common.FileUtlis.Files.WriteFileByBytes(dataSavePath, ssd); + } + /// <summary> + /// 鏇存柊鎴块棿鏁版嵁 + /// </summary> + public void UpdataRoomInfo() + { + new System.Threading.Thread(() => + { + var pm = new HttpServerRequest(); + var pack = pm.UpdateRoom(new List<SpatialInfo>() { this }); + this.SaveRoomFile(); + if (pack.Code != StateCode.SUCCESS) + { + IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); + } + }) + { IsBackground = true }.Start(); + } + + #endregion + + } + + + + [Serializable] + public class Room : SpatialInfo + { + public Room() + { + roomType = "ROOM"; + roomName = "Room"; + } + //public string backgroundImage = "Classification/Room/Roombg.png"; + public string backgroundImage + { + get + { + if (string.IsNullOrEmpty(roomImage)) + { + return "Classification/Room/Roombg.png"; + } + else + { + return roomImage; + } + } + set + { + roomImage = value; + } + } + + /// <summary> /// 妤煎眰 /// </summary> - public string floor { + [Newtonsoft.Json.JsonIgnore] + public string floorName + { get { - string str = ""; - if (floorIndex != -1) + if (CurrentSpatial.FloorList.Count > 0) { - if (floorIndex < DB_ResidenceData.residenceData.floors.Count) - str = DB_ResidenceData.residenceData.floors[floorIndex]; + var f = CurrentSpatial.FloorList.Find((obj) => obj.uid == parentId); + if (f != null) + { + return f.roomName + " "; + } } - return str; + return ""; } } - + ///// <summary> + ///// 鎴块棿鍔熻兘鍒楄〃 + ///// </summary> + //List<Function> functions = new List<Function>(); /// <summary> - /// 鎴块棿鍔熻兘鍒楄〃 + /// 鑾峰彇鎴块棿鍔熻兘鍒楄〃 /// </summary> - [Newtonsoft.Json.JsonIgnore] - public List<Function> functions = new List<Function>(); - - public void RefreshFunctions() + public List<Function> GetRoomFunctions(bool needRefresh) { - List<Function> funcList = new List<Function>(); - foreach (var f in DB_ResidenceData.residenceData.functionList.functions) + if (needRefresh) { - if (f.roomIdList.Contains(sid) && sid != null) + } + var functions = new List<Function>(); + if (functions.Count == 0) + { + foreach (var f in FunctionList.List.GetDeviceFunctionList()) { - funcList.Add(f); + if (f.roomIds.Contains(roomId) && roomId != null) + { + functions.Add(f); + } } } - functions = funcList; + 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 FunctionList.List.scenes) + { + if (s.roomIds.Contains(roomId) && roomId != 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)); } } -} + +} \ No newline at end of file -- Gitblit v1.8.0