From 39cf2411b59772d56ee731f229f09ff472889bad Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期四, 22 九月 2022 15:12:04 +0800 Subject: [PATCH] Merge branch 'Dev-Branch' into hxb --- HDL_ON/UI/UI2/3-Intelligence/Automation/Send.cs | 907 ++++++++++++++++++++++++++++++++------------------------ 1 files changed, 520 insertions(+), 387 deletions(-) diff --git a/HDL_ON/UI/UI2/3-Intelligence/Automation/Send.cs b/HDL_ON/UI/UI2/3-Intelligence/Automation/Send.cs index d955285..5a95e83 100644 --- a/HDL_ON/UI/UI2/3-Intelligence/Automation/Send.cs +++ b/HDL_ON/UI/UI2/3-Intelligence/Automation/Send.cs @@ -8,410 +8,543 @@ namespace HDL_ON.UI.UI2.Intelligence.Automation { - public class Send - { - - /// <summary> - /// 璋冪敤鑾峰彇浣忓畢瀛愯处鍙峰垪琛� - /// </summary> - public static List<ResidenceMemberInfo> GetResidenceMemberAccount() + public class Send { - - var responePack = new HttpServerRequest().GetResidenceMemberAccount(); - if (responePack.Code == StateCode.SUCCESS) - { - return Newtonsoft.Json.JsonConvert.DeserializeObject<List<ResidenceMemberInfo>>(responePack.Data.ToString()); - } - //澶辫触 - else - { - //鎻愮ず - IMessageCommon.Current.ShowErrorInfoAlter(responePack.Code); - } - return new List<ResidenceMemberInfo>(); - } - /// <summary> - /// 鑾峰彇閫昏緫ID鍒楄〃 - /// </summary> - /// <returns></returns> - public static ResponsePackNew GetLogicIdList() - { - var jObject = new JObject { { "homeId", LogicMethod.CurrLogicMethod.HomeId } }; - var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_List); - //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken - if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) - { - RefreshToken(); - GetLogicIdList(); - } - return responsePackNew; - } - /// <summary> - /// 鑾峰彇閫昏緫 - /// </summary> - /// <param name="listIdList">閫昏緫ID鍒楄〃</param> - /// <returns></returns> - public static ResponsePackNew GetLogic(List<string> listIdList) - { - var jArray = new JArray { }; - for (int i = 0; i < listIdList.Count; i++) - { - jArray.Add(listIdList[i]); - } - var jObject = new JObject { { "userLogicIds", jArray } }; - var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Info); - //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken - if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) - { - RefreshToken(); - GetLogic(listIdList); - } - return responsePackNew; - } - /// <summary> - /// 娣诲姞鑷姩鍖栧懡浠� - /// </summary> - /// <param name="logic"></param> - /// <returns></returns> - public static ResponsePackNew AddLogic(Logic logic) - { - ResponsePackNew responsePackNew = null; - try - { - - var cycleJObject = new JObject { }; - var cyclevaluejArray = new JArray { }; - cycleJObject.Add("type", logic.cycle.type); - foreach (var dictionary in logic.cycle.value) + private static Send s_Current = null; + public static Send Current { - cyclevaluejArray.Add(dictionary); - } - cycleJObject.Add("value", cyclevaluejArray); - - var inputArray = new JArray { }; - foreach (var dictionary in logic.input) - { - var inputTypeJOb = new JObject { }; - inputTypeJOb.Add("sid", dictionary.sid); - inputTypeJOb.Add("condition_type", dictionary.condition_type); - - var conditionArray = new JArray { }; - foreach (var dic in dictionary.condition) - { - var conditionJOb = new JObject { }; - conditionJOb.Add("key", dic["key"]); - conditionJOb.Add("comparator", dic["comparator"]); - conditionJOb.Add("data_type", dic["data_type"]); - conditionJOb.Add("value", dic["value"]); - conditionArray.Add(conditionJOb); - } - inputTypeJOb.Add("condition", conditionArray); - if (dictionary.condition_type == "8") - { - ///鍦扮悊鍥存爮 - var geo_fencejob = new JObject(); - geo_fencejob.Add("longitude", dictionary.geo_fence.longitude); - geo_fencejob.Add("latitude", dictionary.geo_fence.latitude); - geo_fencejob.Add("radius", dictionary.geo_fence.radius); - inputTypeJOb.Add("geo_fence", geo_fencejob); - } - inputArray.Add(inputTypeJOb); - } - - var outputArray = new JArray { }; - foreach (var dictionary in logic.output) - { - var outputTypeJOb = new JObject { }; - outputTypeJOb.Add("sid", dictionary.sid); - outputTypeJOb.Add("delay", dictionary.delay); - outputTypeJOb.Add("target_type", dictionary.target_type); - var statusArray = new JArray { }; - foreach (var dic in dictionary.status) - { - var statusJOb = new JObject { }; - statusJOb.Add("key", dic["key"]); - statusJOb.Add("value", dic["value"]); - statusArray.Add(statusJOb); - } - outputTypeJOb.Add("status", statusArray); - outputArray.Add(outputTypeJOb); - } - - - var noticeConfigJObject = new JObject(); - noticeConfigJObject.Add("enable", logic.noticeConfig.enable); - noticeConfigJObject.Add("noticeContent", logic.noticeConfig.noticeContent); - - var pushConfigsArray = new JArray { }; - if (logic.pushConfigs.Count > 0) - { //聽鎺ㄩ�佹枃鏈� - foreach (var pushConfig in logic.pushConfigs) - { - - var pushConfigJob = new JObject { }; - pushConfigJob.Add("pushMethod", pushConfig.pushMethod); - var accountArray = new JArray { }; - foreach (var account in pushConfig.pushTarget) + get { - accountArray.Add(account); + if (s_Current == null) + { + s_Current = new Send(); + } + return s_Current; } - pushConfigJob.Add("pushTarget", accountArray); - pushConfigsArray.Add(pushConfigJob); - } } - - var logicjArray = new JArray { }; - var logicIfon = new JObject { }; - logicIfon.Add("sid", logic.sid); - logicIfon.Add("gatewayId", LogicMethod.CurrLogicMethod.GatewayId); - logicIfon.Add("tag", logic.tag); - logicIfon.Add("name", logic.name); - logicIfon.Add("relation", logic.relation); - logicIfon.Add("enable", logic.enable); - logicIfon.Add("cycle", cycleJObject); - logicIfon.Add("input", inputArray); - logicIfon.Add("output", outputArray); - logicIfon.Add("noticeConfig", noticeConfigJObject); - logicIfon.Add("pushConfigs", pushConfigsArray); - logicjArray.Add(logicIfon); - //string str = logicIfon.ToString(); - var jObject = new JObject { { "homeId", LogicMethod.CurrLogicMethod.HomeId }, { "logics", logicjArray } }; - responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Add, 5); - //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken - if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + public List<Face> faceList = new List<Face>(); + /// <summary> + /// 璋冪敤鑾峰彇浣忓畢瀛愯处鍙峰垪琛� + /// </summary> + public List<ResidenceMemberInfo> GetResidenceMemberAccount() { - RefreshToken(); - AddLogic(logic); - } - } - catch (Exception e) - { - var dd = e.Message; - } - return responsePackNew; - } - /// <summary> - /// 缂栬緫鏇存柊閫昏緫 - /// </summary> - /// <param name="logic"></param> - /// <returns></returns> - public static ResponsePackNew UpdateLogic(Logic logic) - { - ResponsePackNew responsePackNew = null; - try - { - var cycleJObject = new JObject { }; - var cyclevaluejArray = new JArray { }; - cycleJObject.Add("type", logic.cycle.type); - foreach (var dictionary in logic.cycle.value) - { - cyclevaluejArray.Add(dictionary); - } - cycleJObject.Add("value", cyclevaluejArray); - var inputArray = new JArray { }; - foreach (var dictionary in logic.input) - { - var inputTypeJOb = new JObject { }; - inputTypeJOb.Add("sid", dictionary.sid); - inputTypeJOb.Add("condition_type", dictionary.condition_type); - - var conditionArray = new JArray { }; - foreach (var dic in dictionary.condition) - { - - var conditionJOb = new JObject { }; - conditionJOb.Add("key", dic["key"]); - var c1 = ""; - dic.TryGetValue("comparator", out c1); - c1 = string.IsNullOrEmpty(c1) ? "" : c1; - conditionJOb.TryAdd("comparator", c1); - conditionJOb.Add("data_type", dic["data_type"]); - conditionJOb.Add("value", dic["value"]); - conditionArray.Add(conditionJOb); - if (dictionary.condition_type == "8") + var responePack = new HttpServerRequest().GetResidenceMemberAccount(); + if (responePack.Code == StateCode.SUCCESS) { - ///鍦扮悊鍥存爮 - var geo_fencejob = new JObject(); - geo_fencejob.Add("longitude", dictionary.geo_fence.longitude); - geo_fencejob.Add("latitude", dictionary.geo_fence.latitude); - geo_fencejob.Add("radius", dictionary.geo_fence.radius); - inputTypeJOb.Add("geo_fence", geo_fencejob); + return Newtonsoft.Json.JsonConvert.DeserializeObject<List<ResidenceMemberInfo>>(responePack.Data.ToString()); } - } - inputTypeJOb.Add("condition", conditionArray); - inputArray.Add(inputTypeJOb); - } - - var outputArray = new JArray { }; - foreach (var dictionary in logic.output) - { - var outputTypeJOb = new JObject { }; - outputTypeJOb.Add("sid", dictionary.sid); - outputTypeJOb.Add("delay", dictionary.delay); - outputTypeJOb.Add("target_type", dictionary.target_type); - var statusArray = new JArray { }; - foreach (var dic in dictionary.status) - { - var statusJOb = new JObject { }; - statusJOb.Add("key", dic["key"]); - statusJOb.Add("value", dic["value"]); - statusArray.Add(statusJOb); - } - outputTypeJOb.Add("status", statusArray); - outputArray.Add(outputTypeJOb); - } - - var noticeConfigJObject = new JObject(); - noticeConfigJObject.Add("enable", logic.noticeConfig.enable); - noticeConfigJObject.Add("noticeContent", logic.noticeConfig.noticeContent); - - var pushConfigsArray = new JArray { }; - if (logic.pushConfigs.Count > 0) - { - //聽鎺ㄩ�佹枃鏈� - foreach (var pushConfig in logic.pushConfigs) - { - - var pushConfigJob = new JObject { }; - pushConfigJob.Add("pushMethod", pushConfig.pushMethod); - var accountArray = new JArray { }; - foreach (var account in pushConfig.pushTarget) + //澶辫触 + else { - accountArray.Add(account); + //鎻愮ず + IMessageCommon.Current.ShowErrorInfoAlter(responePack.Code); } - pushConfigJob.Add("pushTarget", accountArray); - pushConfigsArray.Add(pushConfigJob); - } + return new List<ResidenceMemberInfo>(); } - - var logicjArray = new JArray { }; - var logicIfon = new JObject { }; - logicIfon.Add("userLogicId", logic.userLogicId); - logicIfon.Add("sid", logic.sid); - logicIfon.Add("gatewayId", LogicMethod.CurrLogicMethod.GatewayId); - logicIfon.Add("tag", logic.tag); - logicIfon.Add("name", logic.name); - logicIfon.Add("relation", logic.relation); - logicIfon.Add("enable", logic.enable); - logicIfon.Add("cycle", cycleJObject); - logicIfon.Add("input", inputArray); - logicIfon.Add("output", outputArray); - logicIfon.Add("noticeConfig", noticeConfigJObject); - logicIfon.Add("pushConfigs", pushConfigsArray); - - logicjArray.Add(logicIfon); - var jObject = new JObject { { "homeId", LogicMethod.CurrLogicMethod.HomeId }, { "logics", logicjArray } }; - - string str = jObject.ToString(); - responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Update, 5); - //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken - if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + /// <summary> + /// 鑾峰彇閫昏緫ID鍒楄〃 + /// </summary> + /// <returns></returns> + public ResponsePackNew GetLogicIdList(bool isTip = false) { - RefreshToken(); - UpdateLogic(logic); + var jObject = new JObject { { "homeId", LogicMethod.Current.HomeId } }; + var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_List, "鑾峰彇閫昏緫ID鍒楄〃"); + //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + { + RefreshToken(); + GetLogicIdList(isTip); + } + if (Check(responsePackNew, isTip) == false) + { + return null; + } + return responsePackNew; } - } - catch (Exception e) - { - var dd = e.Message; - } - return responsePackNew; - } - /// <summary> - /// 鍒犻櫎閫昏緫 - /// </summary> - /// <returns></returns> - public static ResponsePackNew DelLogic(Logic logic) - { - var jArray = new JArray { }; - jArray.Add(logic.userLogicId); - var jObject = new JObject { { "userLogicIds", jArray } }; - var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Delete); - //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken - if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) - { - RefreshToken(); - DelLogic(logic); - } - return responsePackNew; - } - /// <summary> - /// 閫昏緫寮�鍏� - /// </summary> - /// <returns></returns> - public static ResponsePackNew SwitchLogic(Logic logic) - { - var jArray = new JArray { }; - var job = new JObject { { "userLogicId", logic.userLogicId }, { "enable", logic.enable } }; - jArray.Add(job); - var jObject = new JObject { { "logics", jArray } }; - var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Enable); - //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken - if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) - { - RefreshToken(); - SwitchLogic(logic); - } - return responsePackNew; - } - /// <summary> - /// 鑷姩鍖栧湴鐞嗗洿鏍忕姸鎬佷笂鎶� - /// </summary> - /// <param name="userLogicId">鑷姩鍖栦簯绔痠d<澶囨敞锛歭ogicSid涓巙serLogicId 涓嶈兘鍚屾椂涓虹┖></param> - /// <param name="logicSid">鑷姩鍖杝id<澶囨敞锛歭ogicSid涓巙serLogicId 涓嶈兘鍚屾椂涓虹┖></param> - /// <param name="direction">arrive:鍒拌揪(杩涘叆) leave锛氱寮�</param> - /// <returns></returns> - public static bool GeoFenceStateReport(string userLogicId, string logicSid, string direction) - { - var jObject = new JObject(); - jObject.Add("homeId", LogicMethod.CurrLogicMethod.HomeId); - jObject.Add("userLogicId", userLogicId); - jObject.Add("sid", logicSid); - jObject.Add("direction", direction); - var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_GeoFenceStateReport); - //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken - if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) - { - RefreshToken(); - GeoFenceStateReport(userLogicId, logicSid, direction); - } - if (responsePackNew.Code == "0") - { - //鎴愬姛 - return true; - } - //澶辫触 - return false; - } + /// <summary> + /// 鑾峰彇鑷姩鍖栬鎯� + /// </summary> + /// <param name="listIdList">鑷姩鍖朓D鍒楄〃</param> + /// <returns></returns> + public ResponsePackNew GetLogic(List<string> listIdList, bool isTip = false) + { + var jArray = new JArray { }; + for (int i = 0; i < listIdList.Count; i++) + { + jArray.Add(listIdList[i]); + } + var jObject = new JObject { { "userLogicIds", jArray } }; + var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Info, "鑾峰彇鑷姩鍖栬鎯�"); + //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + { + RefreshToken(); + GetLogic(listIdList,isTip); + } + if (Check(responsePackNew, isTip) == false) + { + return null; + } + return responsePackNew; + } + /// <summary> + /// 娣诲姞鑷姩鍖栧懡浠� + /// </summary> + /// <param name="logic"></param> + /// <returns></returns> + public ResponsePackNew AddLogic(Logic logic,bool isTip) + { + ResponsePackNew responsePackNew = null; + try + { - /// <summary> - ///璇锋眰鏈嶅姟鍣紙涓庝綇瀹呮湁鍏�:渚嬪锛沨omeId锛� - /// </summary> - /// <returns></returns> - public static ResponsePackNew RequestServerhomeId(object o, string api_Url, int mTimeout = 3) - { - var requestJson = HttpUtil.GetSignRequestJson(o); - return HttpUtil.RequestHttpsPostFroHome(api_Url, requestJson, mTimeout); + var cycleJObject = new JObject { }; + var cyclevaluejArray = new JArray { }; + cycleJObject.Add("type", logic.cycle.type); + foreach (var dictionary in logic.cycle.value) + { + cyclevaluejArray.Add(dictionary); + } + cycleJObject.Add("value", cyclevaluejArray); + + var inputArray = new JArray { }; + foreach (var dictionary in logic.input) + { + var inputTypeJOb = new JObject { }; + inputTypeJOb.Add("sid", dictionary.sid); + inputTypeJOb.Add("condition_type", dictionary.condition_type); + if (dictionary.condition_type=="9") { + inputTypeJOb.Add("identifier", dictionary.identifier); + } + var conditionArray = new JArray { }; + foreach (var dic in dictionary.condition) + { + var conditionJOb = new JObject { }; + conditionJOb.Add("key", dic["key"]); + conditionJOb.Add("comparator", dic["comparator"]); + conditionJOb.Add("data_type", dic["data_type"]); + conditionJOb.Add("value", dic["value"]); + conditionArray.Add(conditionJOb); + } + inputTypeJOb.Add("condition", conditionArray); + if (dictionary.condition_type == "8") + { + ///鍦扮悊鍥存爮 + var geo_fencejob = new JObject(); + geo_fencejob.Add("longitude", dictionary.geo_fence.longitude); + geo_fencejob.Add("latitude", dictionary.geo_fence.latitude); + geo_fencejob.Add("radius", dictionary.geo_fence.radius); + inputTypeJOb.Add("geo_fence", geo_fencejob); + } + inputArray.Add(inputTypeJOb); + } + + var outputArray = new JArray { }; + foreach (var dictionary in logic.output) + { + var outputTypeJOb = new JObject { }; + outputTypeJOb.Add("sid", dictionary.sid); + outputTypeJOb.Add("delay", dictionary.delay); + outputTypeJOb.Add("target_type", dictionary.target_type); + var statusArray = new JArray { }; + foreach (var dic in dictionary.status) + { + var statusJOb = new JObject { }; + statusJOb.Add("key", dic["key"]); + statusJOb.Add("value", dic["value"]); + statusArray.Add(statusJOb); + } + outputTypeJOb.Add("status", statusArray); + outputArray.Add(outputTypeJOb); + } + + + var noticeConfigJObject = new JObject(); + noticeConfigJObject.Add("enable", logic.noticeConfig.enable); + noticeConfigJObject.Add("noticeContent", logic.noticeConfig.noticeContent); + + var pushConfigsArray = new JArray { }; + if (logic.pushConfigs.Count > 0) + { //聽鎺ㄩ�佹枃鏈� + foreach (var pushConfig in logic.pushConfigs) + { + + var pushConfigJob = new JObject { }; + pushConfigJob.Add("pushMethod", pushConfig.pushMethod); + var accountArray = new JArray { }; + foreach (var account in pushConfig.pushTarget) + { + accountArray.Add(account); + } + pushConfigJob.Add("pushTarget", accountArray); + pushConfigsArray.Add(pushConfigJob); + } + } + + var logicjArray = new JArray { }; + var logicIfon = new JObject { }; + logicIfon.Add("sid", logic.sid); + logicIfon.Add("gatewayId", LogicMethod.Current.GatewayId); + logicIfon.Add("tag", logic.tag); + logicIfon.Add("name", logic.name); + logicIfon.Add("relation", logic.relation); + logicIfon.Add("enable", logic.enable); + logicIfon.Add("cycle", cycleJObject); + logicIfon.Add("input", inputArray); + logicIfon.Add("output", outputArray); + logicIfon.Add("noticeConfig", noticeConfigJObject); + logicIfon.Add("pushConfigs", pushConfigsArray); + logicjArray.Add(logicIfon); + var jObject = new JObject { { "homeId", LogicMethod.Current.HomeId }, { "logics", logicjArray } }; + responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Add, "娣诲姞鑷姩鍖�", 5); + //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + { + RefreshToken(); + AddLogic(logic,isTip); + } + if (Check(responsePackNew, isTip) == false) + { + return null; + } + } + catch (Exception e) + { + var dd = e.Message; + } + return responsePackNew; + } + /// <summary> + /// 缂栬緫鏇存柊鑷姩鍖� + /// </summary> + /// <param name="logic"></param> + /// <returns></returns> + public ResponsePackNew UpdateLogic(Logic logic,bool isTip) + { + ResponsePackNew responsePackNew = null; + try + { + var cycleJObject = new JObject { }; + var cyclevaluejArray = new JArray { }; + cycleJObject.Add("type", logic.cycle.type); + foreach (var dictionary in logic.cycle.value) + { + cyclevaluejArray.Add(dictionary); + } + cycleJObject.Add("value", cyclevaluejArray); + + var inputArray = new JArray { }; + foreach (var dictionary in logic.input) + { + var inputTypeJOb = new JObject { }; + inputTypeJOb.Add("sid", dictionary.sid); + inputTypeJOb.Add("condition_type", dictionary.condition_type); + if (dictionary.condition_type == "9") + { + inputTypeJOb.Add("identifier", dictionary.identifier); + } + var conditionArray = new JArray { }; + foreach (var dic in dictionary.condition) + { + + var conditionJOb = new JObject { }; + conditionJOb.Add("key", dic["key"]); + var c1 = ""; + dic.TryGetValue("comparator", out c1); + c1 = string.IsNullOrEmpty(c1) ? "" : c1; + conditionJOb.TryAdd("comparator", c1); + conditionJOb.Add("data_type", dic["data_type"]); + conditionJOb.Add("value", dic["value"]); + conditionArray.Add(conditionJOb); + if (dictionary.condition_type == "8") + { + ///鍦扮悊鍥存爮 + var geo_fencejob = new JObject(); + geo_fencejob.Add("longitude", dictionary.geo_fence.longitude); + geo_fencejob.Add("latitude", dictionary.geo_fence.latitude); + geo_fencejob.Add("radius", dictionary.geo_fence.radius); + inputTypeJOb.Add("geo_fence", geo_fencejob); + } + } + inputTypeJOb.Add("condition", conditionArray); + inputArray.Add(inputTypeJOb); + } + + var outputArray = new JArray { }; + foreach (var dictionary in logic.output) + { + var outputTypeJOb = new JObject { }; + outputTypeJOb.Add("sid", dictionary.sid); + outputTypeJOb.Add("delay", dictionary.delay); + outputTypeJOb.Add("target_type", dictionary.target_type); + var statusArray = new JArray { }; + foreach (var dic in dictionary.status) + { + var statusJOb = new JObject { }; + statusJOb.Add("key", dic["key"]); + statusJOb.Add("value", dic["value"]); + statusArray.Add(statusJOb); + } + outputTypeJOb.Add("status", statusArray); + outputArray.Add(outputTypeJOb); + } + + var noticeConfigJObject = new JObject(); + noticeConfigJObject.Add("enable", logic.noticeConfig.enable); + noticeConfigJObject.Add("noticeContent", logic.noticeConfig.noticeContent); + + var pushConfigsArray = new JArray { }; + if (logic.pushConfigs.Count > 0) + { + //聽鎺ㄩ�佹枃鏈� + foreach (var pushConfig in logic.pushConfigs) + { + + var pushConfigJob = new JObject { }; + pushConfigJob.Add("pushMethod", pushConfig.pushMethod); + var accountArray = new JArray { }; + foreach (var account in pushConfig.pushTarget) + { + accountArray.Add(account); + } + pushConfigJob.Add("pushTarget", accountArray); + pushConfigsArray.Add(pushConfigJob); + } + } + + var logicjArray = new JArray { }; + var logicIfon = new JObject { }; + logicIfon.Add("userLogicId", logic.userLogicId); + logicIfon.Add("sid", logic.sid); + logicIfon.Add("gatewayId", LogicMethod.Current.GatewayId); + logicIfon.Add("tag", logic.tag); + logicIfon.Add("name", logic.name); + logicIfon.Add("relation", logic.relation); + logicIfon.Add("enable", logic.enable); + logicIfon.Add("cycle", cycleJObject); + logicIfon.Add("input", inputArray); + logicIfon.Add("output", outputArray); + logicIfon.Add("noticeConfig", noticeConfigJObject); + logicIfon.Add("pushConfigs", pushConfigsArray); + + logicjArray.Add(logicIfon); + var jObject = new JObject { { "homeId", LogicMethod.Current.HomeId }, { "logics", logicjArray } }; + + string str = jObject.ToString(); + responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Update, "缂栬緫鏇存柊鑷姩鍖�", 5); + //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + { + RefreshToken(); + UpdateLogic(logic, isTip); + } + if (Check(responsePackNew, isTip) == false) + { + return null; + } + } + catch (Exception e) + { + return null; + } + return responsePackNew; + } + + /// <summary> + /// 鍒犻櫎鑷姩鍖� + /// </summary> + /// <param name="logic">褰撳墠瀵硅薄</param> + /// <param name="isTip">鏄惁瑕佹彁绀�</param> + /// <returns></returns> + public ResponsePackNew DelLogic(Logic logic,bool isTip) + { + var jArray = new JArray { }; + jArray.Add(logic.userLogicId); + var jObject = new JObject { { "userLogicIds", jArray } }; + var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Delete, "鍒犻櫎鑷姩鍖�"); + //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + { + RefreshToken(); + DelLogic(logic, isTip); + } + if (Check(responsePackNew, isTip) == false) + { + return null; + } + return responsePackNew; + } + /// <summary> + /// 鑷姩鍖栦娇鑳� + /// </summary> + /// <param name="logic">褰撳墠瀵硅薄</param> + /// <param name="isTip">鏄惁瑕佹彁绀�</param> + /// <returns></returns> + public ResponsePackNew EnableLogic(Logic logic,bool isTip=false) + { + var jArray = new JArray { }; + var job = new JObject { { "userLogicId", logic.userLogicId }, { "enable", logic.enable } }; + jArray.Add(job); + var jObject = new JObject { { "logics", jArray } }; + var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Enable, "鑷姩鍖栧紑鍏�"); + //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + { + RefreshToken(); + EnableLogic(logic, isTip); + } + if (Check(responsePackNew, isTip) == false) + { + return null; + } + return responsePackNew; + } + /// <summary> + /// 鑷姩鍖栧湴鐞嗗洿鏍忕姸鎬佷笂鎶� + /// </summary> + /// <param name="userLogicId">鑷姩鍖栦簯绔痠d<澶囨敞锛歭ogicSid涓巙serLogicId 涓嶈兘鍚屾椂涓虹┖></param> + /// <param name="logicSid">鑷姩鍖杝id<澶囨敞锛歭ogicSid涓巙serLogicId 涓嶈兘鍚屾椂涓虹┖></param> + /// <param name="direction">arrive:鍒拌揪(杩涘叆) leave锛氱寮�</param> + /// <returns></returns> + public bool GetFenceStateReport(string userLogicId, string logicSid, string direction) + { + var jObject = new JObject(); + jObject.Add("homeId", LogicMethod.Current.HomeId); + jObject.Add("userLogicId", userLogicId); + jObject.Add("sid", logicSid); + jObject.Add("direction", direction); + var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_GeoFenceStateReport, "鑷姩鍖栧湴鐞嗗洿鏍忕姸鎬佷笂鎶�"); + //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + { + RefreshToken(); + GetFenceStateReport(userLogicId, logicSid, direction); + } + if (responsePackNew.Code == "0") + { + //鎴愬姛 + return true; + } + //澶辫触 + return false; + } + + /// <summary> + /// 鑾峰彇浣忓畢宸插綍鍏ヤ汉鑴镐俊鎭紙鍙瀵硅浜鸿劯寮�闂ㄨЕ鍙戣嚜鍔ㄥ寲閰嶇疆鐢級 + /// </summary> + /// <param name="deviceId">鍙瀵硅璁惧id</param> + /// <returns></returns> + public List<Face> GetListHomeFace(string deviceId, bool isTip) + { + var jObject = new JObject(); + jObject.Add("homeId", LogicMethod.Current.HomeId); + jObject.Add("deviceId", deviceId); + var responsePackNew = RequestServerhomeId(jObject, NewAPI.Api_Post_GetListHomeFace, "鑾峰彇浣忓畢宸插綍鍏ヤ汉鑴镐俊鎭�"); + //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + { + RefreshToken(); + GetListHomeFace(deviceId, isTip); + } + if (Check(responsePackNew, isTip) == false) + { + return new List<Face>(); + } + var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Face>>(responsePackNew.Data.ToString()); + if (list == null) + { + list = new List<Face>(); + } + faceList.Clear(); + faceList.AddRange(list); + return list; + + } + + /// <summary> + ///璇锋眰鏈嶅姟鍣紙涓庝綇瀹呮湁鍏�:渚嬪锛沨omeId锛� + /// </summary> + /// <param name="o">鍙戦�佹暟鎹�</param> + /// <param name="api_Url">璇锋眰鍦板潃(涓嶆槸缁濆鍦板潃)</param> + /// <param name="tag">鏍囪->鎻忚堪鎺ュ彛(鑷畾涔�)</param> + /// <returns></returns> + public ResponsePackNew RequestServerhomeId(object o, string api_Url, string tag,int mTimeout = 3) + { + Log($"{DateTime.Now}->鍙戦��->{tag}", api_Url,o.ToString()); + var requestJson = HttpUtil.GetSignRequestJson(o); + var r= HttpUtil.RequestHttpsPostFroHome(api_Url, requestJson, mTimeout); + Log($"{DateTime.Now}->鍥炲->{tag}", "", Newtonsoft.Json.JsonConvert.SerializeObject(r)); + return r; + + } + /// <summary> + /// 璇锋眰鏈嶅姟鍣� + /// </summary> + /// <param name="o">鍙戦�佹暟鎹�</param> + /// <param name="api_Url">璇锋眰鍦板潃(涓嶆槸缁濆鍦板潃)</param> + /// <param name="tag">鏍囪</param> + /// <returns></returns> + public ResponsePackNew RequestServer(object o, string api_Url,string tag) + { + Log($"鍙戦�佹暟鎹�->{tag}", api_Url, o.ToString()); + var requestJson = HttpUtil.GetSignRequestJson(o); + var r = HttpUtil.RequestHttpsPost(api_Url, requestJson); + Log($"鍥炲鏁版嵁->{tag}", "", Newtonsoft.Json.JsonConvert.SerializeObject(r)); + return r; + } + /// <summary> + /// 鍒锋柊Token + /// </summary> + public void RefreshToken() + { + IMessageCommon.Current.StartRefreshToken(); + } + /// <summary> + /// 妫�楠屾暟鎹槸鍚﹀悎娉曠殑 + /// </summary> + /// <param name="r"></param> + /// <param name="isTip">鏄惁瑕佸脊绐楋紙榛樿鏄痜alse涓嶉渶瑕侊級</param> + /// <returns></returns> + public bool Check(ResponsePackNew r, bool isTip) + { + if (r.Code == "0" && r.Data != null && r.Data.ToString() != "") + { + return true; + } + if (r.Code != "0") + { + //澶辫触鏃舵槸鍚﹁鎻愮ず + if (isTip) + { + new LogicView.TipPopView().FlashingBox(r.message + $"({r.Code})"); + } + } + return false; + } + /// <summary> + /// 鎵撳嵃鏃ュ織 + /// </summary> + /// <param name="tag">鎵撳嵃鏍囪</param> + /// <param name="content">鎵撳嵃鍐呭</param> + public void Log(string tag,string url, string content) + { + #if DEBUG + Console.WriteLine(tag + $"\r\n{url}\r\n{content}"); + #endif + } + } - /// <summary> - /// 璇锋眰鏈嶅姟鍣� - /// </summary> - /// <returns></returns> - public static ResponsePackNew RequestServer(object o, string api_Url) + public class Face { - var requestJson = HttpUtil.GetSignRequestJson(o); - return HttpUtil.RequestHttpsPost(api_Url, requestJson); - + /// <summary> + /// 鐢ㄦ埛鍚嶇О + /// </summary> + public string userName = string.Empty; + /// <summary> + /// 鐢ㄦ埛浜鸿劯id + /// </summary> + public string userId = string.Empty; } - /// <summary> - /// 鍒锋柊Token - /// </summary> - public static void RefreshToken() - { - IMessageCommon.Current.StartRefreshToken(); - } - - } } -- Gitblit v1.8.0