From 64dbbfe1d6488635e160189a704afccffc7d34d0 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期一, 07 十二月 2020 11:33:06 +0800
Subject: [PATCH] Merge branch 'WJC'

---
 HDL_ON/Entity/Function/Scene.cs |  503 ++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 290 insertions(+), 213 deletions(-)

diff --git a/HDL_ON/Entity/Function/Scene.cs b/HDL_ON/Entity/Function/Scene.cs
index 500f47e..c8d208e 100644
--- a/HDL_ON/Entity/Function/Scene.cs
+++ b/HDL_ON/Entity/Function/Scene.cs
@@ -1,28 +1,137 @@
 锘縰sing System;
 using System.Collections.Generic;
+using HDL_ON.DAL.Server;
+using Shared;
 
 namespace HDL_ON.Entity
 {
-    public class Scene : Function
+    public class SceneApiPack
     {
-        public Scene()
+        static SceneApiPack _ScenePack;
+        public static SceneApiPack ScenePack
         {
+            get
+            {
+                if(_ScenePack == null)
+                {
+                    _ScenePack = new SceneApiPack();
+                }
+                return _ScenePack;
+            }
         }
 
+    }
+
+    public class Scene 
+    {
+        /// <summary>
+        /// 浜戠鍞竴ID
+        /// </summary>
+        public string userSceneId = "";
+        /// <summary>
+        /// 鍦烘櫙sid
+        /// </summary>
+        public string sid = "";
+        /// <summary>
+        /// 鍦烘櫙鍚嶇О
+        /// </summary>
+        public string name = "";
+        /// <summary>
+        /// 缃戝叧ID
+        /// </summary>
+        public string gatewayId = "";
+        /// <summary>
+        /// 浜戠oss瀛樺偍鍥剧墖鐨勮矾寰�
+        /// </summary>
+        public string image = "";
+        /// <summary>
+        /// 鎵�灞炴埧闂村垪琛�
+        /// </summary>
+        public List<string> roomIds = new List<string>();
+        /// <summary>
+        /// 寤舵椂
+        /// </summary>
+        public int delay = 0;
+        /// <summary>
+        /// 寤舵椂鏄剧ず鐨勬枃鏈�
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public string delayText
+        {
+            get
+            {
+                string text = "";
+                switch (delay)
+                {
+                    case 0:
+                        text = Language.StringByID(StringId.NoDelay);
+                        break;
+                    case 30:
+                        text = "30s";
+                        break;
+                    case 60:
+                        text = "1min";
+                        break;
+                    case 120:
+                        text = "2min";
+                        break;
+                    case 300:
+                        text = "5min";
+                        break;
+                }
+                return text;
+            }
+        }
+
+        /// <summary>
+        /// 鍦烘櫙鍒嗙粍
+        /// </summary>
+        public string group = "1";
         /// <summary>
         /// 鍦烘櫙绫诲瀷
         /// </summary>
         public SceneType sceneType = SceneType.OrdinaryScenes;
-
         /// <summary>
-        /// 鍦烘櫙鑳屾櫙
+        /// 鏀惰棌鏍囪
         /// </summary>
-        public string ImagePath = "Intelligence/Gallery/scenebg1.png";//"FunctionIcon/Scene/s1.png";
+        public bool collect = false;
+
+        ///// <summary>
+        ///// 鍦烘櫙鑳屾櫙
+        ///// </summary>
+        //public string ImagePath = "Intelligence/Gallery/scenebg1.png";//"FunctionIcon/Scene/s1.png";
+
+        ///// <summary>
+        ///// 鍦烘櫙鑳屾櫙
+        ///// </summary>
+        public string ImagePath
+        {
+            get
+            {
+                if (string.IsNullOrEmpty(image))
+                {
+                    return "Intelligence/Gallery/scenebg1.png";
+                }
+                else
+                {
+                    return image;
+                }
+            }
+            set
+            {
+                image = value;
+            }
+        }
+        
 
         /// <summary>
         /// 鍦烘櫙鍔熻兘鍒楄〃
         /// </summary>
-        public List<Function> sceneFunctionList = new List<Function>();
+        public List<SceneFunction> functions = new List<SceneFunction>();
+        /// <summary>
+        /// 鍦烘櫙鎺ㄩ�侀厤缃垪琛�
+        /// </summary>
+        public List<ScenePushConfig> pushConfigs = new List<ScenePushConfig>();
 
         /// <summary>
         /// 鐢熸垚鍦烘櫙sid
@@ -53,7 +162,7 @@
                 {
                     sTimeSpan = sTimeSpan.Substring(0, 8);
                 }
-                else 
+                else
                 {
                     sTimeSpan = "00000000";
                 }
@@ -79,213 +188,181 @@
             }
         }
 
+        /// <summary>
+        /// 鑾峰彇璁惧娣诲姞鍒版埧闂寸殑鎴块棿鍚嶇О
+        /// </summary>
+        /// <returns></returns>
+        public string GetRoomListName()
+        {
+            string roomNameList = "";
+            foreach (var roomId in roomIds)
+            {
+                var findRoom = DB_ResidenceData.residenceData.Rooms.Find(obj => obj.uid == roomId);
+                if (findRoom == null)
+                {
+                    continue;
+                }
+                if (roomNameList != "")
+                {
+                    roomNameList += ",";
+                }
+                roomNameList += findRoom.floorName + findRoom.roomName;
+            }
+            if (roomNameList == "" )
+            {
+                roomNameList = Shared.Language.StringByID(StringId.WholeHouseScene);
+            }
+            return roomNameList;
+        }
+
+        /// <summary>
+        /// 鏁版嵁瀛樺偍鏂囦欢鍚�
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public string savePath
+        {
+            get
+            {
+                return "SceneData_" + sid;
+            }
+        }
+
+        /// <summary>
+        /// 淇濆瓨鍔熻兘鏁版嵁
+        /// </summary>
+        public void SaveSceneData()
+        {
+            var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
+            FileUtils.WriteFileByBytes(savePath, ssd);
+            MainPage.Log($"Save Scene Data : {savePath}");
+            UploadScene();
+        }
+
+        /// <summary>
+        /// 涓婁紶鏁版嵁鍒颁簯绔�
+        /// </summary>
+        void UploadScene()
+        {
+            var pm = new HttpServerRequest();
+            ResponsePackNew revPack;
+            if (DeleteSign)
+            {
+                var resCode = pm.DeleteScene(userSceneId);
+            }
+            else
+            {
+                if (string.IsNullOrEmpty(createTime) && string.IsNullOrEmpty(modifyTime))
+                {
+                    revPack = pm.AddScene(this);
+                    if (revPack.Code == StateCode.SUCCESS)
+                    {
+                        var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
+                        FileUtils.WriteFileByBytes(savePath, ssd);
+                    }
+                }
+                else if (!string.IsNullOrEmpty(createTime) && !string.IsNullOrEmpty(modifyTime))
+                {
+                    revPack = pm.EditScene(this);
+                    if (revPack.Code == StateCode.SUCCESS)
+                    {
+                        var scenes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(revPack.Data.ToString());
+                        var tempScene = scenes.Find((obj) => obj.sid == sid);
+                        if (tempScene != null)
+                        {
+                            var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(tempScene));
+                            FileUtils.WriteFileByBytes(savePath, ssd);
+                        }
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// 鍒犻櫎鏍囪
+        /// 闇�瑕佸垹闄ゆ暟鎹椂锛屾爣璁颁负锛歵rue
+        /// 鐢变簯绔垹闄ゆ垚鍔熶箣鍚庯紝杩斿洖鏁版嵁鍐嶆竻闄ゆ湰鍦版暟鎹�
+        /// </summary>
+        public bool DeleteSign = false;
+
+        /// <summary>
+        /// 浜戠鏁版嵁鍒涘缓鐨勬椂闂�
+        /// </summary>
+        public string createTime = "";
+        /// <summary>
+        /// 浜戠鏁版嵁淇敼鐨勬渶鍚庢椂闂�
+        /// </summary>
+        public string modifyTime = "";
+    }
+    /// <summary>
+    /// 鍦烘櫙鍔熻兘瀵硅薄
+    /// </summary>
+    public class SceneFunction
+    {
+        public string sid = "";
+
+        public List<SceneFunctionStatus> status = new List<SceneFunctionStatus>();
+        /// <summary>
+        /// 鍔熻兘寤舵椂
+        /// </summary>
+        public string delay = "0";
+
+        Function _localFunction;
+        /// <summary>
+        /// 鏈湴瀵瑰簲鐨勫姛鑳�
+        /// </summary>
+        [Newtonsoft.Json.JsonIgnore]
+        public Function localFunction {
+            get
+            {
+                if(_localFunction == null)
+                {
+                    _localFunction = ConvertFunctionObject();
+                }
+                return _localFunction;
+            }
+        }
+
+        /// <summary>
+        /// 杞崲鎴愬姛鑳藉璞�
+        /// </summary>
+        /// <returns></returns>
+        Function ConvertFunctionObject()
+        {
+            var localFunction = DB_ResidenceData.functionList.GetAllDeviceFunctionList().Find((obj) => obj.sid == sid);
+            foreach (var s in status)
+            {
+                localFunction.attributes.Add(new FunctionAttributes() { key = s.key, curValue = s.value, value = new List<string>() { s.value } });
+            }
+            return localFunction;
+        }
+      
     }
 
+    /// <summary>
+    /// 鍦烘櫙鍔熻兘灞炴��
+    /// </summary>
+    public class SceneFunctionStatus
+    {
+        public string key = "";
+        public string value = "";
+    }
+    /// <summary>
+    /// 鍦烘櫙鎺ㄩ�侀厤缃�
+    /// </summary>
+    public class ScenePushConfig
+    {
+        /// <summary>
+        /// 鎺ㄩ�佹柟寮�
+        /// </summary>
+        public string pushMethod = "";
+        /// <summary>
+        /// 鎺ㄩ�佸唴瀹�
+        /// </summary>
+        public string pushContent = "";
+        /// <summary>
+        /// 鎺ㄩ�佺洰鏍囬泦鍚�
+        /// </summary>
+        public List<string> pushTarget = new List<string>();
+    }
 
 }
-//5.1.14鑾峰彇鍦烘櫙鍒楄〃
-//璇锋眰鍙傛暟
-//{
-//	"namespace": "HDL",
-//	"type": "scene",
-//	"command": "get_list"
-//}
-//杩斿洖鍊� json鏍煎紡 鎵�鏈夊満鏅痠d鍙婂満鏅噷鎵ц鐨勭洰鏍囨暟鎹�
-//杩斿洖渚嬪瓙
-//{
-//	"namespace": "HDL",
-//	"command": "get_list_respond",
-//	"type": "scene",
-//	"number": [{
-//		"scene_id": "0001",
-//		"scene_name": "dinner",
-//		"objects": [{
-//			   "sid": "00010019101209000025670100010001",
-//"data_type": "string ",
-//			"value": "on"
-//		  }]
-//	}]
-//}
-//璇存槑 鑾峰彇鍦烘櫙鍒楄〃鍜屽睘鎬э紝鍙紑锛屽彧鍏筹紝鏃㈠紑鍙堝叧
-	
-//5.1.15鍒涘缓鍦烘櫙
-//璇锋眰鍙傛暟
-//{
-//	"namespace": "HDL",
-//	"command": "create",
-//	"type": "scene",
-//	"objects": [{
-//		"scene_name": "Away ",
-//		"status": "single_off"
-//	}]
-//}
-//杩斿洖鍊� json鏍煎紡
-//杩斿洖渚嬪瓙	{
-//	"namespace": "HDL",
-//	"command": "create_respond",
-//	"type": "scene",
-//	"objects": [{
-//		"scene_id": "0004",
-//		"name": "Away",
-//		"status": "single_off"
-//	}]
-//}
-//璇存槑 鍒涘缓鍦烘櫙
-	
-//5.1.16娣诲姞鐩爣鍒板満鏅�
-//璇锋眰鍙傛暟
-//{
-//	"namespace": "HDL",
-//	"command": "add_member",
-//	"type": "scene",
-//	"number": [{
-//		"scene_id": "0001",
-//		"objects": [{
-//			"sid": "00010019101209000025670100010001",
-//			"function": [{
-//				"attri": "switch",
-//"data_type": "string ",
-//				"value": "on"
-//			}]
-
-//		}]
-//	}, {
-//		"scene_id": "0002",
-//		"objects": [{
-//			"sid": "00010019101209000025670200010001",
-//			"function": [{
-//				"attri": "brightness",
-//"data_type": "int",
-//				"value": 50
-//			}]
-//		}]
-//	}]
-//}
-//杩斿洖鍊� json鏍煎紡
-//杩斿洖渚嬪瓙	{
-//	"namespace": "HDL",
-//	"command": "add_member_respond",
-//	"type": "scene",
-//	"scene_id": "0001",
-//	"value": "success"
-//}
-//璇存槑 鎴愬姛娣诲姞鐩爣鐨勫満鏅垪琛�
-	
-//5.1.17鍒犻櫎鍦烘櫙鍛戒护
-//璇锋眰鍙傛暟
-//{
-//	"namespace": "HDL",
-//	"command": "delete",
-//	"type": "scene",
-//	"objects": [{
-//		"scene_id": "0001"
-//	}]
-//}
-//杩斿洖鍊� json鏍煎紡
-//杩斿洖渚嬪瓙	{
-//	"namespace": "HDL",
-//	"command": "delete_respond",
-//	"type": "scene",
-//	"scene_id": "0001",
-//	"value": "success"
-//}
-//璇存槑 鍒犻櫎鍦烘櫙
-	
-//5.1.18鍒犻櫎鍦烘櫙閲岀殑鐩爣
-//璇锋眰鍙傛暟
-//{
-//	"Namespace": "HDL",
-//	"Command": "delete_member",
-//	"type": "scene",
-//	"number": [{
-//		"scene_id": "0001",
-//		"objects": [{
-//			"sid": "00010019101209000025670100010001"
-//		}, {
-//			"sid": "00010019101209000025670100010002"
-//		}]
-//	}]
-//}
-//杩斿洖鍊� json鏍煎紡
-//杩斿洖渚嬪瓙	{
-//	"namespace": "HDL",
-//	"command": "delete_member_respond",
-//	"type": "scene",
-//	"scenesid": "0001",
-//	"sid": "00010019101209000025670100010001",
-//	"value": "success"
-//}
-//璇存槑 鍒犻櫎鍦烘櫙鍐呰澶�
-	
-//5.1.19閰嶇疆鍦烘櫙鍒嗙粍锛堣冻鍐呭満鏅姸鎬佽嚜鍔ㄨ褰曟渶鍚庝竴娆¤褰曪級
-//璇锋眰鍙傛暟	{
-//	"namespace": "HDL",
-//	"command": "group",
-//	"type": "scene",
-//	"objects": [{
-//		"group_id": 1,
-//		"scene_ids": [{
-//			"scene_id": "0001"
-//		}, {
-//			"scene_id": "0002"
-//		}]
-//	}]
-//}
-//杩斿洖鍊� json鏍煎紡
-//杩斿洖渚嬪瓙	{
-//	"namespace": "HDL",
-//	"command": "group_respond",
-//	"type": "scene",
-//	"group_id": "0001",
-//	"value": "success"
-//}
-//璇存槑 鎺у埗鍦烘櫙
-	
-
-//5.1.20璇诲彇鍦烘櫙鍒嗙粍
-//璇锋眰鍙傛暟
-//{
-//	"namespace": "HDL",
-//	"command": "read_group",
-//	"type": "scene",
-//	"objects": [{
-//		"group_id": 1
-//	}]
-//}
-//杩斿洖鍊� json鏍煎紡
-//杩斿洖渚嬪瓙	{
-//	"namespace": "HDL",
-//	"command": "read_group_respond",
-//	"type": "scene",
-//	"objects": [{
-//		"group_id": 1,
-//		"scene_ids": [{
-//			"scene_id": "0001"
-//		}, {
-//			"scene_id": "0002"
-//		}]
-//	}]
-//}
-//璇存槑 鎺у埗鍦烘櫙
-	
-
-//5.1.21鎺у埗鍦烘櫙
-//璇锋眰鍙傛暟
-//{
-//	"namespace": "HDL",
-//	"command": "contrl",
-//	"type": "scene",
-//	"objects": [{
-//		"scene_id": "0001",
-//		"value": 鈥渙n鈥�
-//	}]
-//}
-//杩斿洖鍊� json鏍煎紡
-//杩斿洖渚嬪瓙	{
-//	"namespace": "HDL",
-//	"command": "contrl_respond",
-//	"type": "scene",
-//		"scene_id": "0001",
-//		"value": "success"
-//}
-//璇存槑 鎺у埗鍦烘櫙
\ No newline at end of file

--
Gitblit v1.8.0