using System; using System.Collections.Generic; using System.Text; namespace Shared.Phone { /// /// 门锁历史记录的逻辑 /// public class HdlDeviceDoorLockLogic { #region ■ 变量声明___________________________ /// /// 门锁历史记录的逻辑 /// private static HdlDeviceDoorLockLogic m_Current = null; /// /// 门锁历史记录的逻辑 /// public static HdlDeviceDoorLockLogic Current { get { if (m_Current == null) { m_Current = new HdlDeviceDoorLockLogic(); } return m_Current; } } #endregion #region ■ 添加历史记录_______________________ /// /// 添加历史记录 /// /// 门锁对象 /// 其他开锁方式 9001:常开打开 9002:常开取消 9003:常开持续 9004:常开自动化手动取消 /// 常开持续时间(1~72小时 OtherOpenLockMode=9003的时候有效) public void AddDoorHistoryLog(ZigBee.Device.DoorLock i_doorLock, int OtherOpenLockMode, string NormallyOpenContinuedTime) { HdlThreadLogic.Current.RunThread(() => { var pra = new { doorLockId = i_doorLock.DeviceAddr + "_" + i_doorLock.DeviceEpoint, unlockMode = OtherOpenLockMode, homeId = Common.Config.Instance.Home.Id, isUnlockSuccess = true, normallyOpenContinuedTime = NormallyOpenContinuedTime, unlockTime = DateTime.UtcNow.ToString() }; //不管返回值 var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/doorLockUnlockHistory/save", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); }); } #endregion #region ■ 获取历史记录_______________________ /// /// 获取门锁的历史记录(不会返回null) /// /// 门锁的Mac + "_" + 端点 /// 搜索时间From(不是utc时间) /// 搜索时间To(不是utc时间) /// public List GetDoorHistoryLogInfo(string i_doorKey, DateTime i_dateTimeFrom, DateTime i_dateTimeTo) { var pra = new { doorLockId = i_doorKey, homeId = Common.Config.Instance.Home.Id, unlockBeginTime = i_dateTimeFrom.ToUniversalTime().ToString(), unlockEndTime = i_dateTimeTo.ToUniversalTime().ToString() }; var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/doorLockUnlockHistory/list", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限, false, 5); if (result == null || result.Code != HttpMessageEnum.A成功) { return new List(); } var listData = Newtonsoft.Json.JsonConvert.DeserializeObject>(result.Data.ToString()); var listLog = new List(); foreach (var data in listData) { //不知道为什么会有上报了虚拟9000的那个特殊的东西(这是以前的注释,先放这里) if (data.UserId == null) { data.UserId = string.Empty; } listLog.Add(data); } return listLog; } #endregion #region ■ 清空历史记录_______________________ /// /// 清空历史记录 /// /// 门锁的Mac + "_" + 端点 /// 时间From(不是utc时间) /// 时间To(不是utc时间) /// 存在另一张表的消息记录的主键 /// public bool ClearAllDoorHistoryLog(string i_doorId, DateTime i_dateTimeFrom, DateTime i_dateTimeTo, List i_listOtherId) { var pra1 = new { doorLockId = i_doorId, homeId = Common.Config.Instance.Home.Id, unlockBeginTime = i_dateTimeFrom.ToUniversalTime().ToString(), unlockEndTime = i_dateTimeTo.ToUniversalTime().ToString() }; //清空记录 var result1 = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/app/doorLockUnlockHistory/clear", RestSharp.Method.POST, pra1, null, null, CheckMode.A账号权限); if (result1 == null || result1.Code != HttpMessageEnum.A成功) { return false; } //清空另外一张表的记录 foreach (var msgId in i_listOtherId) { var result2 = HdlMessageLogic.Current.DeleteCloundMessage(msgId); if (result2 == false) { return false; } } return true; } #endregion } }