| | |
| | | using System.IO; |
| | | using System.Net; |
| | | using System.Text; |
| | | using HDL_ON.DAL.Mqtt; |
| | | using HDL_ON.Entity; |
| | | using Newtonsoft.Json.Linq; |
| | | using Shared; |
| | | |
| | | namespace HDL_ON.DAL.Server |
| | | { |
| | |
| | | /// <returns></returns> |
| | | public string UpdataUserHeadImage(string fileName) |
| | | { |
| | | FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); |
| | | byte[] bytes = new byte[fs.Length]; |
| | | fs.Read(bytes, 0, bytes.Length); |
| | | byte[] bytes = Shared.IO.FileUtils.ReadFile(fileName); |
| | | var revertObj = HttpUtil.RequestHttpsUpload(RestSharp.Method.POST, NewAPI.API_POST_Head_Upload, bytes); |
| | | return revertObj.Code; |
| | | } |
| | |
| | | } |
| | | DB_ResidenceData.residenceData.SaveResidenceData(); |
| | | UserInfo.Current.SaveUserInfo(); |
| | | |
| | | //刷新一次住宅网关 |
| | | GetHomeGatewayList(); |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取刷新当前住宅网关接口 |
| | | /// 获取刷新当前住宅的网关列表 |
| | | /// </summary> |
| | | public void GetHomeGatewayList() |
| | | { |
| | | if (string.IsNullOrEmpty(DB_ResidenceData.residenceData.residecenInfo.RegionID)) return; |
| | | var nowhomeId = DB_ResidenceData.residenceData.residecenInfo.RegionID; |
| | | var requestJson = HttpUtil.GetSignRequestJson(new HomeIdObj() { homeId = nowhomeId }); |
| | | var revertObj = HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_GetGatewayList, requestJson); |
| | | if (revertObj.Code == StateCode.SUCCESS) |
| | | try |
| | | { |
| | | var mHomeGatewayRes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<HomeGatewayInfo>>(revertObj.Data.ToString()); |
| | | if (nowhomeId == DB_ResidenceData.residenceData.residecenInfo.RegionID) |
| | | if (string.IsNullOrEmpty(DB_ResidenceData.residenceData.residecenInfo.RegionID)) return; |
| | | var nowhomeId = DB_ResidenceData.residenceData.residecenInfo.RegionID; |
| | | var requestJson = HttpUtil.GetSignRequestJson(new HomeIdObj() { homeId = nowhomeId }); |
| | | var revertObj = HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_GetGatewayList, requestJson); |
| | | if (revertObj.Code == StateCode.SUCCESS) |
| | | { |
| | | if (mHomeGatewayRes != null) |
| | | var mHomeGatewayRes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<HomeGatewayInfo>>(revertObj.Data.ToString()); |
| | | if (nowhomeId == DB_ResidenceData.residenceData.residecenInfo.RegionID) |
| | | { |
| | | if (mHomeGatewayRes.Count > 0) |
| | | if (mHomeGatewayRes != null) |
| | | { |
| | | DB_ResidenceData.residenceData.residenceGatewayMAC = mHomeGatewayRes[0].mac; |
| | | if (mHomeGatewayRes.Count > 0) |
| | | { |
| | | DB_ResidenceData.residenceData.HomeGateway = mHomeGatewayRes[0]; |
| | | DB_ResidenceData.residenceData.SaveResidenceData(); |
| | | return; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | DB_ResidenceData.residenceData.residenceGatewayMAC = ""; |
| | | |
| | | } |
| | | //其余情况清空网关信息 |
| | | DB_ResidenceData.residenceData.HomeGateway = null; |
| | | DB_ResidenceData.residenceData.SaveResidenceData(); |
| | | } |
| | | |
| | | if (mHomeGatewayRes != null) |
| | | { |
| | | //Utlis.WriteLine ("获得当前住宅网关个数:" + mHomeGatewayRes.content.Count); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //提示错误 |
| | | } |
| | | } |
| | | else |
| | | catch |
| | | { |
| | | //提示错误 |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | }); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Child_Update, requestJson); |
| | | } |
| | | |
| | | #region 新数据分享 |
| | | /// <summary> |
| | | /// 添加分享 |
| | | /// </summary> |
| | | /// <param name="addShareObj"></param> |
| | | /// <returns></returns> |
| | | public ResponsePackNew AddShare(AddShareObj addShareObj) |
| | | { |
| | | var requestJson = HttpUtil.GetSignRequestJson(addShareObj); |
| | | |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Share_Add, requestJson); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除分享 |
| | | /// </summary> |
| | | /// <param name="deleteShareObj"></param> |
| | | /// <returns></returns> |
| | | public ResponsePackNew DeleteShare(DeleteShareObj deleteShareObj) |
| | | { |
| | | var requestJson = HttpUtil.GetSignRequestJson(deleteShareObj); |
| | | |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Share_Delete, requestJson); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取分享 |
| | | /// </summary> |
| | | /// <param name="addShareObj"></param> |
| | | /// <returns></returns> |
| | | public ResponsePackNew GetShare(GetShareObj getShareObj) |
| | | { |
| | | var requestJson = HttpUtil.GetSignRequestJson(getShareObj); |
| | | |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Share_Delete, requestJson); |
| | | } |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 获取住宅下子账号的共享数据列表 |
| | |
| | | #endregion |
| | | |
| | | |
| | | #region Kaede --设备功能—————————————————————————————————— |
| | | /// <summary> |
| | | /// 获取设备列表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ResponsePackNew GetDeviceList() |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("gatewayId", DB_ResidenceData.residenceData.HomeGateway.id); |
| | | //d.Add("roomId", DB_ResidenceData.residenceData.residecenInfo.RegionID);//可控参数,当需要分页获取,怎么知道分页总数 |
| | | //d.Add("searchType", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | //d.Add("pageSize", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | //d.Add("pageNo", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetDevcieList, requestJson); |
| | | } |
| | | /// <summary> |
| | | /// 获取设备详情列表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ResponsePackNew GetDeviceInfoList(List<string> functionIds) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("deviceIds", functionIds); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetDevcieInfoList, requestJson); |
| | | } |
| | | /// <summary> |
| | | /// 控制设备 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ResponsePackNew ControlDevice(List<ApiAlinkControlActionObj> actionObjs) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("gatewayId", DriverLayer.Control.Ins.GatewayId); |
| | | d.Add("actions", actionObjs); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_ControlDevice, requestJson); |
| | | } |
| | | /// <summary> |
| | | /// 设备绑定房间 |
| | | /// </summary> |
| | | public string BindDeviceToRoom(string deviceId,string roomId) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("deviceIds", new List<string>() { deviceId}); |
| | | d.Add("roomIds", new List<string>() { roomId}); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_BindDeviceToRoom, requestJson).Code; |
| | | } |
| | | /// <summary> |
| | | /// 设备解绑房间 |
| | | /// </summary> |
| | | public string UnbindDeviceToRoom(string deviceId, string roomId) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("deviceIds", new List<string>() { deviceId }); |
| | | d.Add("roomIds", new List<string>() { roomId }); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_UnbindDeviceToRoom, requestJson).Code; |
| | | } |
| | | /// <summary> |
| | | /// 设备名称修改 |
| | | /// </summary> |
| | | public string EditDeviceName(string deviceId, string deviceName) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("deviceId", deviceId); |
| | | d.Add("name", deviceName); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_EditDeviceName, requestJson).Code; |
| | | } |
| | | /// <summary> |
| | | /// 收藏设备 |
| | | /// </summary> |
| | | public string CollectDevice(string deviceId) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("deviceId",new List<string>() { deviceId }); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_CollectDevice, requestJson).Code; |
| | | } |
| | | /// <summary> |
| | | /// 取消收藏设备 |
| | | /// </summary> |
| | | public string CancelCollectDevice(string deviceId) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("deviceId", new List<string>() { deviceId }); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_CancelCollectDevice, requestJson).Code; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region Kaede --场景功能-------------------------- |
| | | /// <summary> |
| | | /// 获取场景列表 |
| | | /// 房间ID可空,默认查询住宅下所有房间 |
| | | /// </summary> |
| | | /// <param name="roomId">房间ID</param> |
| | | /// <returns></returns> |
| | | public ResponsePackNew GetSceneList(string roomId = null) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | if (roomId != null) |
| | | { |
| | | d.Add("roomId", roomId); |
| | | } |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetSecneList, requestJson); |
| | | } |
| | | /// <summary> |
| | | /// 获取场景详情 |
| | | /// </summary> |
| | | /// <param name="seceneId">场景ID</param> |
| | | /// <returns></returns> |
| | | public ResponsePackNew GetSceneInfo(string seceneId) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("userSceneIds",new List<string>() { seceneId }); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetSecneList, requestJson); |
| | | } |
| | | /// <summary> |
| | | /// 添加场景 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ResponsePackNew AddScene(Scene scene) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("scenes", new List<Scene>() { scene }); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_EditSecne, requestJson); |
| | | } |
| | | /// <summary> |
| | | /// 编辑场景 |
| | | /// </summary> |
| | | /// <param name="scene"></param> |
| | | /// <returns></returns> |
| | | public ResponsePackNew EditScene(Scene scene) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("scenes", new List<Scene>() { scene }); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_EditSecne, requestJson); |
| | | } |
| | | /// <summary> |
| | | /// 删除场景 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public string DeleteScene(string userSceneId) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("userSceneIds", new List<string>() { userSceneId }); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_DeleteSecne, requestJson).Code; |
| | | } |
| | | /// <summary> |
| | | /// 执行场景 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public string ExecuteScene(string userSceneId) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("userSceneIds", new List<string>() { userSceneId }); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_ExecuteSecne, requestJson).Code; |
| | | } |
| | | /// <summary> |
| | | /// 收藏场景 |
| | | /// </summary> |
| | | /// <param name="userSceneId"></param> |
| | | /// <returns></returns> |
| | | public string CollectScene(string userSceneId) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("userSceneIds", new List<string>() { userSceneId }); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_CollectScene, requestJson).Code; |
| | | } |
| | | /// <summary> |
| | | /// 取消收藏场景 |
| | | /// </summary> |
| | | /// <param name="userSceneId"></param> |
| | | /// <returns></returns> |
| | | public string CancelCollectScene(string userSceneId) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("userSceneIds", new List<string>() { userSceneId }); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_CancelCollectScene, requestJson).Code; |
| | | } |
| | | #endregion |
| | | |
| | | #region Kaede --房间功能-------------------------- |
| | | /// <summary> |
| | | /// 获取房间列表 |
| | | /// </summary> |
| | | /// <param name="GetType">获取类型:ROOM\FLOOR;不输入返回全部</param> |
| | | /// <returns></returns> |
| | | public ResponsePackNew GetRoomList(string GetType = "All") |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | if (GetType != "All") |
| | | { |
| | | d.Add("roomType", GetType); |
| | | } |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | var pack = HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetRoomList, requestJson); |
| | | var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpatialInfo>>(pack.Data.ToString()); |
| | | if (revData != null) |
| | | { |
| | | foreach (var spatial in revData) |
| | | { |
| | | spatial.UpdateSpatialInfoData(); |
| | | } |
| | | } |
| | | return pack; |
| | | } |
| | | /// <summary> |
| | | /// 添加房间\楼层 |
| | | /// 楼层也属于房间 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ResponsePackNew AddRoom(List<SpatialInfo> rooms) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("rooms", rooms); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | var pack = HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_AddRoom, requestJson); |
| | | var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpatialInfo>>(pack.Data.ToString()); |
| | | if (revData != null) |
| | | { |
| | | foreach (var spatial in revData) |
| | | { |
| | | spatial.UpdateSpatialInfoData(); |
| | | } |
| | | } |
| | | return pack; |
| | | } |
| | | /// <summary> |
| | | /// 修改房间信息 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ResponsePackNew UpdateRoom(List<SpatialInfo> rooms) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("rooms", rooms); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | var pack = HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_UpdateRoom, requestJson); |
| | | var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpatialInfo>>(pack.Data.ToString()); |
| | | if (revData != null) |
| | | { |
| | | foreach (var spatial in revData) |
| | | { |
| | | spatial.UpdateSpatialInfoData(); |
| | | } |
| | | } |
| | | return pack; |
| | | } |
| | | /// <summary> |
| | | /// 删除房间 |
| | | /// </summary> |
| | | /// <param name="roomIds"></param> |
| | | /// <returns></returns> |
| | | public ResponsePackNew DeleteRoom(List<string> roomIds) |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID); |
| | | d.Add("ids", roomIds); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(d); |
| | | var pack = HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_DelRoom, requestJson); |
| | | return pack; |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |