using System;
|
using System.Collections.Generic;
|
using System.Threading;
|
using HDL_ON.DAL.Server;
|
using HDL_ON.Entity;
|
using Shared;
|
using static HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock.CommonMethod;
|
|
|
namespace HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock
|
{
|
/// <summary>
|
/// 萤石视频门锁数据发送
|
/// </summary>
|
public class VideDoorLockSend
|
{
|
|
private static VideDoorLockSend send = null;
|
/// <summary>
|
/// 获取当前的对象
|
/// </summary>
|
public static VideDoorLockSend Current
|
{
|
get
|
{
|
if (send == null)
|
{
|
send = new VideDoorLockSend();
|
}
|
|
return send;
|
}
|
}
|
/// <summary>
|
/// 解绑设备(萤石视频门锁)
|
/// </summary>
|
/// <param name="function">当前的设备</param>
|
/// <param name="action">回调结果</param>
|
/// <param name="tipType">是否需要提示,默认提示</param>
|
public void DelDevice(Function function, Action<bool> action, TipType tipType = TipType.flicker)
|
{
|
new Thread(() =>
|
{
|
try
|
{
|
Dictionary<string, object> d = new Dictionary<string, object>();
|
d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
|
d.Add("deviceSerial", function.sid);//等同门锁序列号
|
d.Add("platform", 1);//平台
|
var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_DeleteDevice, "删除萤石门锁设备");
|
if (!this.DataChecking(responsePackNew, tipType))
|
{
|
return;
|
}
|
|
if (function != null)
|
{
|
action?.Invoke(true);
|
}
|
}
|
catch (Exception s)
|
{
|
}
|
})
|
{ IsBackground = true }.Start();
|
|
}
|
/// <summary>
|
/// 获取门锁状态(萤石视频门锁)
|
/// </summary>
|
/// <param name="function">当前的设备</param>
|
/// <param name="tipType">是否需要提示,默认提示</param>
|
/// <param name="return">返回结果不会为null</param>
|
public VideoDoorLockInfo GetVideoDoorLockState(Function function, TipType tipType = TipType.flicker)
|
{
|
|
Dictionary<string, object> d = new Dictionary<string, object>();
|
d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
|
d.Add("deviceId", function.deviceId);
|
var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_Lockstatus, "获取萤石视频门锁状态");
|
if (!this.DataChecking(responsePackNew,tipType))
|
{
|
return new VideoDoorLockInfo();
|
}
|
|
var videoDoorLockInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<VideoDoorLockInfo>(responsePackNew.Data.ToString());
|
if (videoDoorLockInfo == null)
|
{
|
return new VideoDoorLockInfo();
|
}
|
return videoDoorLockInfo;
|
|
|
|
}
|
/// <summary>
|
/// 获取电池电量(萤石视频门锁)
|
/// </summary>
|
/// <param name="function">当前的设备</param>
|
/// <param name="tipType">是否需要提示,默认提示</param>
|
/// <param name="return">返回结果不会为null</param>
|
public CellInfo GetCellValue(Function function, TipType tipType = TipType.flicker)
|
{
|
Dictionary<string, object> d = new Dictionary<string, object>();
|
d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
|
d.Add("deviceId", function.deviceId);
|
var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_Details, "获取萤石门锁设备电量");
|
if (!this.DataChecking(responsePackNew,tipType))
|
{
|
return new CellInfo();
|
}
|
var cellInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<CellInfo>(responsePackNew.Data.ToString());
|
if (cellInfo == null)
|
{
|
return new CellInfo();
|
}
|
|
return cellInfo;
|
|
}
|
/// <summary>
|
/// 获取门锁用户列表(萤石视频门锁)
|
/// </summary>
|
/// <param name="function">当前的设备</param>
|
/// <param name="tipType">是否需要提示,默认提示</param>
|
/// <param name="return">返回结果不会为null</param>
|
public List<UserVideoDoorLockInfo> GetVideoDoorLockUserListInfo(Function function, TipType tipType = TipType.flicker)
|
{
|
Dictionary<string, object> d = new Dictionary<string, object>();
|
d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
|
d.Add("deviceId", function.deviceId);
|
var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_UserList, "获取萤石门锁用户列表");
|
if (!this.DataChecking(responsePackNew, tipType))
|
{
|
return new List<UserVideoDoorLockInfo>();
|
}
|
var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<UserVideoDoorLockInfo>>(responsePackNew.Data.ToString());
|
if (list == null)
|
{
|
return new List<UserVideoDoorLockInfo>();
|
}
|
return list;
|
}
|
/// <summary>
|
/// 获取门锁设备列表(萤石视频门锁)
|
/// </summary>
|
/// <param name="spk">指定spk获取</param>
|
/// <param name="tipType">是否需要提示,默认提示</param>
|
/// <returns>返回结果不会为null</returns>
|
public List<Function> GetVideoDoorLockDeviceList(string spk, TipType tipType = TipType.flicker)
|
{
|
|
Dictionary<string, object> d = new Dictionary<string, object>();
|
d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
|
d.Add("spk", spk);
|
var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_GetDevcieList, "获取萤石门锁设备列表");
|
if (!this.DataChecking(responsePackNew, tipType))
|
{
|
return new List<Function>();
|
}
|
var doorLockList = Newtonsoft.Json.JsonConvert.DeserializeObject<DoorLockList>(responsePackNew.Data.ToString());
|
if (doorLockList == null)
|
{
|
return new DoorLockList().list;
|
}
|
return doorLockList.list;
|
}
|
|
/// <summary>
|
/// 获取门锁型号列表(萤石视频门锁)
|
/// </summary>
|
/// <param name="tipType">是否需要提示,默认提示</param>
|
/// <returns>返回结果不会为null</returns>
|
public List<string> GetVideoDoorLockLockModelsList(TipType tipType = TipType.flicker)
|
{
|
var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(new object { }, NewAPI.Api_Post_Lock_Models, "获取萤石门锁型号列表");
|
if (!this.DataChecking(responsePackNew, tipType))
|
{
|
return new List<string>();
|
}
|
var lockModels = Newtonsoft.Json.JsonConvert.DeserializeObject<LockModels>(responsePackNew.Data.ToString());
|
if (lockModels == null)
|
{
|
return new LockModels().lockModels;
|
}
|
return lockModels.lockModels;
|
}
|
|
/// <summary>
|
/// 先获取萤石云子账号token
|
/// </summary>
|
/// <param name="tipType">是否需要提示,默认提示</param>
|
public string GetEZGetChildToken(TipType tipType = TipType.flicker)
|
{
|
//先获取萤石云子账号token
|
var responsePackNew = new HttpServerRequest().EZGetChildToken();
|
if (!this.DataChecking(responsePackNew, tipType))
|
{
|
return "";
|
}
|
return responsePackNew.Data.ToString();
|
}
|
/// <summary>
|
/// 检验数据回复成功或者失败
|
/// </summary>
|
/// <param name="responsePackNew">回复数据对象</param>
|
/// <param name="tipType">是否需要提示</param>
|
/// <returns></returns>
|
private bool DataChecking(ResponsePackNew responsePackNew, TipType tipType)
|
{
|
if (responsePackNew.Data == null || responsePackNew.Code != "0" || responsePackNew.Data.ToString() == "")
|
{
|
if (TipType.flicker == tipType)
|
{
|
if (responsePackNew == null)
|
{
|
responsePackNew = new ResponsePackNew { message = "没回复,请确认网络是否正常.", Code = "-1", };
|
}
|
Application.RunOnMainThread(() =>
|
{
|
//new Tip()
|
//{
|
// CloseTime = 1,
|
// Text = responsePackNew.message + "(" + responsePackNew.Code + ")",
|
// Direction = AMPopTipDirection.None,
|
//}.Show(MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1));
|
CommonMethod.Current.ShowTip(responsePackNew.message + "(" + responsePackNew.Code + ")");
|
});
|
}
|
return false;
|
}
|
return true;
|
}
|
|
|
}
|
}
|