黄学彪
2020-02-21 bd46c57c77c276014db3192a4e2cc96e23c93202
ZigbeeApp/Shared/Phone/UserCenter/Device/DoorLock/DoorLockHistoryLogForm.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.DeviceDoorLock
{
@@ -15,7 +16,7 @@
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listView = null;
        private VerticalFrameRefreshControl listView = null;
        /// <summary>
        /// 日期From控件
        /// </summary>
@@ -29,9 +30,9 @@
        /// </summary>
        private List<MemberInfoRes> listMenberInfo = null;
        /// <summary>
        /// 设备的Mac地址
        /// 设备对象
        /// </summary>
        private string DeviceMac = string.Empty;
        private CommonDevice DeviceDoor = null;
        /// <summary>
        /// 检索对象的ID(-1:所有 空字符串:其他)
        /// </summary>
@@ -40,6 +41,10 @@
        /// 检索开锁方式的ID(-1:所有 0:密码 15:指纹 3:IC卡)
        /// </summary>
        private List<int> listSearchLockId = new List<int>() { -1 };
        /// <summary>
        /// 其他消息的主键
        /// </summary>
        private List<string> listOtherId = new List<string>();
        #endregion
@@ -50,8 +55,8 @@
        /// </summary>
        /// <param name="i_DeviceMac">门锁的Mac地址</param>
        public void ShowForm(string i_DeviceMac)
        {
            this.DeviceMac = i_DeviceMac;
        {
            this.DeviceDoor = Common.LocalDevice.Current.GetDevicesByMac(i_DeviceMac, false)[0];
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uHistoryLog));
@@ -63,11 +68,11 @@
            btnDelete.InitControl();
            btnDelete.ButtonClickEvent += (sender, e) =>
            {
                var form = new TopRightMenuControl(this, 1, 449);
                var form = new TopRightMenuControl(1, 2);
                //清空记录
                form.AddRowMenu(Language.StringByID(R.MyInternationalizationString.uClearLog), "Item/DeleteIcon2.png", "Item/DeleteIcon2Selected.png", () =>
                {
                    if (this.listView.ChildrenCount == 0)
                    if (this.listView.frameTable.ChildrenCount == 0)
                    {
                        //无数据可删
                        return;
@@ -94,19 +99,10 @@
            this.ClearBodyFrame();
            //初始化头部检索控件
            this.InitTitleSearchControl();
            //主线程的异步会阻塞主线程,导致界面有段时间会白屏,所以这样子让界面先出来
            //然后再刷新数据
            new System.Threading.Thread(() =>
            {
                Application.RunOnMainThread(() =>
                {
                    //初始化记录列表
                    this.InitLogListInfo();
                });
            })
            { IsBackground = true }.Start();
            this.InitTitleSearchControl();
            //初始化记录列表
            this.InitLogListInfo();
        }
        /// <summary>
@@ -168,15 +164,25 @@
            btnScreeningIcon.Gravity = Gravity.CenterVertical;
            btnScreeningIcon.UnSelectedImagePath = "Item/ScreeningType.png";
            frameTitle.AddChidren(btnScreeningIcon, ChidrenBindMode.NotBind);
            btnScreeningIcon.ButtonClickEvent += (sender, e) =>
            {
                //显示类型筛选界面
                this.ShowDoorLockScreeningTypeForm();
            };
            //底线
            frameTitle.AddBottomLine();
            this.listView = new VerticalListControl(29);
            this.listView = new VerticalFrameRefreshControl(29);
            listView.Y = frameTitle.Bottom - Application.GetRealHeight(3);
            listView.BackgroundColor = UserCenterColor.Current.White;
            listView.Height = bodyFrameLayout.Height - frameTitle.Bottom + Application.GetRealHeight(3);
            bodyFrameLayout.AddChidren(listView);
            listView.frameTable.BackgroundColor = UserCenterColor.Current.White;
            listView.BeginHeaderRefreshingAction += () =>
            {
                //下拉刷新
                this.InitLogListInfo();
            };
        }
        #endregion
@@ -186,56 +192,64 @@
        /// <summary>
        /// 初始化记录列表
        /// </summary>
        private async void InitLogListInfo()
        private void InitLogListInfo()
        {
            this.listView.frameTable.RemoveAll();
            listView.frameTable.Height = bodyFrameLayout.Height - Application.GetRealHeight(115 - 3);
            //如果From>To的时候,不鸟它
            if (Convert.ToInt32(dateFromControl.dateValue) > Convert.ToInt32(dateToControl.dateValue))
            {
                //开始时间大于结束时间
                this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uFromTimeIsOverToTime));
                return;
            }
            //打开进度条
            this.ShowProgressBar();
            //成员列表
            var result = await this.GetMemberListInfo();
            if (result == false)
            HdlThreadLogic.Current.RunThread(async () =>
            {
                //打开进度条
                this.ShowProgressBar();
                //成员列表
                var result = await this.GetMemberListInfo();
                if (result == false)
                {
                    //关闭进度条
                    this.CloseProgressBar(ShowReLoadMode.YES);
                    return;
                }
                //历史记录
                var historyLog = await this.GetHistoryLogInfo();
                if (historyLog == null)
                {
                    //关闭进度条
                    this.CloseProgressBar(ShowReLoadMode.YES);
                    return;
                }
                //关闭进度条
                this.CloseProgressBar(ShowReLoadMode.YES);
                return;
            }
            //历史记录
            var historyLog = await this.GetHistoryLogInf();
            if (historyLog == null)
            {
                //关闭进度条
                this.CloseProgressBar(ShowReLoadMode.YES);
                return;
            }
            //关闭进度条
            this.CloseProgressBar();
                this.CloseProgressBar();
            this.listView.RemoveAll();
            listView.Height = bodyFrameLayout.Height - Application.GetRealHeight(115 - 3);
                var dic = new Dictionary<string, string>();
                for (int i = 0; i < listMenberInfo.Count; i++)
                {
                    dic.Add(listMenberInfo[i].SubAccountDistributedMark, string.IsNullOrEmpty(listMenberInfo[i].UserName) == false ? listMenberInfo[i].UserName : listMenberInfo[i].Account);
                }
                HdlThreadLogic.Current.RunMain(() =>
                {
                    for (int i = 0; i < historyLog.Count; i++)
                    {
                        //添加记录行
                        this.AddLogInfoRow(historyLog[i], dic, i != historyLog.Count - 1);
                    }
                    //隐藏下拉刷新特效
                    listView.EndHeaderRefreshing();
            for (int i = 0; i < historyLog.Count; i++)
            {
                //添加记录行
                this.AddLogInfoRow(historyLog[i], i != historyLog.Count - 1);
            }
            if (listView.ChildrenCount == 0)
            {
                return;
            }
            //调整列表控件的高度
            var realHeight = listView.ChildrenCount * listView.GetChildren(0).Height;
            realHeight += Application.GetRealHeight(23 + 3);
            if (realHeight < listView.Height)
            {
                //缩小控件高度
                listView.Height = realHeight;
            }
                    if (listView.frameTable.ChildrenCount == 0)
                    {
                        return;
                    }
                    //调整列表控件的高度
                    listView.AdjustTableHeight(Application.GetRealHeight(23));
                });
            });
        }
        /// <summary>
@@ -249,12 +263,6 @@
                //只初始化一次
                return true;
            }
            var pra = new MemberListInfoPra();
            string result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetSubAccountByDistributedMark", false, pra);
            if (result == null)
            {
                return false;
            }
            listMenberInfo = new List<MemberInfoRes>();
            //把自己也加进去
            var myInfo = new MemberInfoRes()
@@ -264,7 +272,18 @@
                SubAccountDistributedMark = Common.Config.Instance.Guid
            };
            listMenberInfo.Add(myInfo);
            if (UserCenterResourse.UserInfo.AuthorityNo == 3)
            {
                //成员只能看自己的
                return true;
            }
            var pra = new MemberListInfoPra();
            string result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetSubAccountByDistributedMark", false, pra);
            if (result == null)
            {
                return false;
            }
            List<MemberInfoRes> listInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<MemberInfoRes>>(result);
            var checkList = new List<string>();
            foreach (MemberInfoRes infoRes in listInfo)
@@ -279,37 +298,6 @@
            return true;
        }
        /// <summary>
        /// 获取历史记录
        /// </summary>
        /// <returns></returns>
        private async Task<List<HistoryInfo>> GetHistoryLogInf()
        {
            //获取访问云端接口的启动参数
            var pra = this.GetDbInterfacePra();
            int nowPage = 0;
            var listLog = new List<HistoryInfo>();
            while (true)
            {
                //访问云端
                var result = await UserCenterLogic.GetResponseDataByRequestHttps("App/GetDoorLockHistoryPager", false, pra);
                if (result == null)
                {
                    return null;
                }
                var dataInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetHistoryDataResult>(result);
                if (dataInfo.HasNextPage == false)
                {
                    break;
                }
                //获取下一页
                nowPage++;
                pra.PageSetting.Page = nowPage;
            }
            return listLog;
        }
        #endregion
        #region ■ 添加记录行_________________________
@@ -318,33 +306,97 @@
        ///  添加记录行
        /// </summary>
        /// <param name="historyInfo">历史记录</param>
        /// <param name="dicName">名字</param>
        /// <param name="addLine">添加底线</param>
        private void AddLogInfoRow(HistoryInfo historyInfo, bool addLine = true)
        private void AddLogInfoRow(HistoryInfo historyInfo, Dictionary<string, string> dicName, bool addLine = true)
        {
            var frameTable = new FrameRowControl(listView.rowSpace / 2);
            frameTable.UseClickStatu = false;
            this.listView.AddChidren(frameTable);
            this.listView.AddChidrenFrame2(frameTable);
            //图标
            var btnIcon = frameTable.AddLeftIcon();
            btnIcon.UnSelectedImagePath = "Item/PswSettionSelected.png";
            if (historyInfo.OpenLockMode == -1)
            {
                //其他消息
                var device = Common.LocalDevice.Current.GetDevice(historyInfo.DeviceMac, historyInfo.DeviceEpoint);
                if (device == null)
                {
                    btnIcon.UnSelectedImagePath = "Device/IntelligentLocks.png";
                }
                else
                {
                    Common.LocalDevice.Current.SetDeviceIconToControl(btnIcon, device);
                }
            }
            else if (historyInfo.UnlockIsSuccess == true)
            {
                btnIcon.UnSelectedImagePath = "Item/UnLockSuccess.png";
            }
            else
            {
                btnIcon.UnSelectedImagePath = "Item/UnLockFail.png";
            }
            //信息
            var btnMsg = frameTable.AddLeftCaption("信息测试", 600, 60);
            btnMsg.TextSize = 15;
            //这个坐标有点特殊
            btnMsg.Y = Application.GetRealHeight(12) + frameTable.chidrenYaxis;
            frameTable.AddChidren(btnMsg, ChidrenBindMode.NotBind);
            var btnMsg = frameTable.AddTopView("", 600);
            if (historyInfo.OpenLockMode == -1)
            {
                //其他消息
                btnMsg.Text = historyInfo.AlarmMsg;
            }
            else if (historyInfo.UnlockIsSuccess == true)
            {
                if (historyInfo.OpenLockMode == 0)
                {
                    //密码开锁成功
                    btnMsg.TextID = R.MyInternationalizationString.uUnlockByPasswordSuccess;
                }
                else if (historyInfo.OpenLockMode == 3)
                {
                    //IC卡开锁成功
                    btnMsg.TextID = R.MyInternationalizationString.uUnlockByICcardSuccess;
                }
                else if (historyInfo.OpenLockMode == 15)
                {
                    //指纹开锁成功
                    btnMsg.TextID = R.MyInternationalizationString.uUnlockByFingerPrintSuccess;
                }
            }
            else
            {
                if (historyInfo.OpenLockMode == 0)
                {
                    //密码开锁失败
                    btnMsg.TextID = R.MyInternationalizationString.uUnlockByPasswordFail;
                }
                else if (historyInfo.OpenLockMode == 3)
                {
                    //IC卡开锁失败
                    btnMsg.TextID = R.MyInternationalizationString.uUnlockByICcardFail;
                }
                else if (historyInfo.OpenLockMode == 15)
                {
                    //指纹开锁失败
                    btnMsg.TextID = R.MyInternationalizationString.uUnlockByFingerPrintFail;
                }
            }
            //人物
            var btnpersion = frameTable.AddLeftCaption("人物测试", 600, 50, true);
            //这个坐标有点特殊
            btnpersion.Y = Application.GetRealHeight(72) + frameTable.chidrenYaxis;
            btnpersion.TextSize = 12;
            btnpersion.TextColor = UserCenterColor.Current.TextGrayColor1;
            frameTable.AddChidren(btnpersion, ChidrenBindMode.NotBind);
            string perName = dicName.ContainsKey(historyInfo.CloudAccountId) == true ? dicName[historyInfo.CloudAccountId] : Language.StringByID(R.MyInternationalizationString.uOther);
            var btnpersion = frameTable.AddBottomView(perName, 600);
            //时间
            frameTable.AddMostRightView("13:00:00", 200);
            if (this.dateFromControl.dateValue == this.dateToControl.dateValue)
            {
                //如果日期范围一样,则不显示年月日
                frameTable.AddMostRightView(UserCenterLogic.ConvertUtcTimeToLocalTime(historyInfo.UnlockTime).ToString("HH:mm:ss"), 400);
            }
            else
            {
                //如果日期范围不一样,则显示年月日
                frameTable.AddMostRightView(UserCenterLogic.ConvertUtcTimeToLocalTime(historyInfo.UnlockTime).ToString("yyyy/MM/dd HH:mm:ss"), 700);
            }
            if (addLine == true)
            {
                //底线
@@ -382,6 +434,110 @@
        #endregion
        #region ■ 获取记录___________________________
        /// <summary>
        /// 获取历史记录
        /// </summary>
        /// <returns></returns>
        private async Task<List<HistoryInfo>> GetHistoryLogInfo()
        {
            //获取访问云端接口的启动参数
            var pra = this.GetDbInterfacePra();
            int nowPage = 0;
            var listLog = new List<HistoryInfo>();
            while (true)
            {
                //访问云端
                var result = await UserCenterLogic.GetResponseDataByRequestHttps("DoorLock/GetDoorLockHistoryPager", true, pra);
                if (result == null)
                {
                    return null;
                }
                var dataInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetHistoryDataResult>(result);
                listLog.AddRange(dataInfo.PageData);
                if (dataInfo.HasNextPage == false)
                {
                    break;
                }
                //获取下一页
                nowPage++;
                pra.PageSetting.Page = nowPage;
            }
            //排序一下
            var dic = new Dictionary<string, List<HistoryInfo>>();
            var listSort = new List<string>();
            //清空上一次的其他ID
            this.listOtherId = new List<string>();
            //是否包含其他
            bool flage = this.listSearchUserId.Contains("") || this.listSearchUserId.Contains("-1");
            if (flage == true)
            {
                //去获取其他信息
                var pra2 = new MessageInfoPra();
                pra2.BeginTime = pra.UnlockTimeBegin;
                pra2.EndTime = pra.UnlockTimeEnd;
                pra2.Topic = "/Alarms/SendAlarmInform";
                pra2.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
                var result = await UserCenterLogic.GetResponseDataByRequestHttps("MessageCenter/GetMessageCenterPagger", true, pra2);
                if (result == null)
                {
                    return null;
                }
                var dataInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<MessageCentetInfo>(result);
                foreach (var myInfo in dataInfo.PageData)
                {
                    var data = new HistoryInfo();
                    if (dic.ContainsKey(myInfo.CreatedOnUtc) == false)
                    {
                        dic[myInfo.CreatedOnUtc] = new List<HistoryInfo>();
                        listSort.Add(myInfo.CreatedOnUtc);
                    }
                    //设备对象
                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(myInfo.PayloadJson);
                    data.DeviceMac = jobject.Value<string>("DeviceAddr");
                    data.DeviceEpoint = jobject.Value<int>("Epoint");
                    //消息
                    var msgInfo = HdlAlarmsLogic.Current.GetDoorLockAlarmInfo(jobject);
                    data.AlarmMsg = msgInfo != null ? msgInfo.AlarmMsg : Language.StringByID(R.MyInternationalizationString.uDoorLocksAlarmHadTriggered);
                    dic[myInfo.CreatedOnUtc].Add(data);
                    //时间
                    data.UnlockTime = myInfo.CreatedOnUtc;
                    this.listOtherId.Add(myInfo.Id);
                }
            }
            foreach (var data in listLog)
            {
                if (flage == false && string.IsNullOrEmpty(data.CloudAccountId) == true)
                {
                    //没有指定显示其他
                    continue;
                }
                if (dic.ContainsKey(data.UnlockTime) == false)
                {
                    dic[data.UnlockTime] = new List<HistoryInfo>();
                    listSort.Add(data.UnlockTime);
                }
                dic[data.UnlockTime].Add(data);
            }
            //执行排序,时间大的在前面
            listSort.Sort();
            var listSortLog = new List<HistoryInfo>();
            for (int i = listSort.Count - 1; i >= 0; i--)
            {
                listSortLog.AddRange(dic[listSort[i]]);
            }
            return listSortLog;
        }
        #endregion
        #region ■ 清空记录___________________________
        /// <summary>
@@ -393,15 +549,38 @@
            var pra = this.GetDbInterfacePra();
            //打开进度条
            this.ShowProgressBar();
            var result = await UserCenterLogic.GetResultStatuByRequestHttps("App/ClearDoorLockHistory", false, pra);
            var result = await UserCenterLogic.GetResultStatuByRequestHttps("DoorLock/ClearDoorLockHistory", true, pra);
            if (result == false)
            {
                return;
            }
            //删除其他消息
            if (listOtherId.Count > 0)
            {
                var pra2 = new MessageReadStatuPra();
                pra2.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
                for (int i = 0; i < listOtherId.Count; i++)
                {
                    pra2.Id = listOtherId[i];
                    result = await UserCenterLogic.GetResultStatuByRequestHttps("MessageCenter/DelMessageCenterItem", true, pra);
                    if (result == false)
                    {
                        return;
                    }
                }
            }
            //关闭进度条
            this.CloseProgressBar();
            if (result == false)
            {
                return;
            }
            this.listView.RemoveAll();
            listView.Height = bodyFrameLayout.Height - Application.GetRealHeight(115 - 3);
            this.listView.frameTable.RemoveAll();
            listView.frameTable.Height = bodyFrameLayout.Height - Application.GetRealHeight(115 - 3);
            //清空
            this.listOtherId = new List<string>();
        }
        #endregion
@@ -417,37 +596,43 @@
            DateTime dateFrom = new DateTime(dateFromControl.Year, dateFromControl.Month, dateFromControl.Day, 0, 0, 0);
            DateTime dateTo = new DateTime(dateToControl.Year, dateToControl.Month, dateToControl.Day, 23, 59, 59);
            var listUser = new List<string>();
            if (listSearchUserId.Contains("-1") == true)
            List<string> listUser = new List<string>();
            if (listSearchUserId.Count == 1 && listSearchUserId[0] == "")
            {
                //所有用户
                foreach (MemberInfoRes infoRes in listMenberInfo)
                //如果单纯的只是选择其他,则让检索条件不成立即可
                listUser.Add("其他");
            }
            else if (listSearchUserId.Contains("-1") == true)
            {
                //全选
                for (int i = 0; i < listMenberInfo.Count; i++)
                {
                    listUser.Add(infoRes.DistributedMark);
                    listUser.Add(listMenberInfo[i].SubAccountDistributedMark);
                }
            }
            else
            {
                //指定用户
                listUser.AddRange(listSearchUserId);
                //移除其他,因为云端固定会给
                listUser.Remove("");
            }
            var listLock = new List<int>();
            if (listSearchLockId.Contains(-1) == true)
            //全选则为null
            List<int> listLock = null;
            if (listSearchLockId.Contains(-1) == false)
            {
                //所有开锁方式
                listLock = new List<int>() { 0, 15, 3 };
            }
            else
            {
                listLock = new List<int>();
                listLock.AddRange(listSearchLockId);
            }
            var pra = new GetHistoryDataPra();
            pra.DoorLockId = this.DeviceMac;
            pra.CloudAccountId = listUser[0];
            pra.OpenLockMode = listLock[0];
            pra.UnlockTimeBegin = dateFrom;
            pra.UnlockTimeEnd = dateTo;
            pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
            pra.DoorLockId = this.DeviceDoor.DeviceAddr + "_" + this.DeviceDoor.DeviceEpoint;
            pra.CloudAccountIdArr = listUser;
            pra.OpenLockModeArr = listLock;
            pra.UnlockTimeBegin = dateFrom.ToUniversalTime().ToString();
            pra.UnlockTimeEnd = dateTo.ToUniversalTime().ToString();
            return pra;
        }
@@ -458,7 +643,7 @@
        /// <summary>
        /// 获取历史记录数据
        /// </summary>
        private class GetHistoryDataPra
        private class GetHistoryDataPra : IfacePraCommon
        {
            /// <summary>
            /// RequestVersion
@@ -467,7 +652,7 @@
            /// <summary>
            /// Token
            /// </summary>
            public string LoginAccessToken = Shared.Common.Config.Instance.Token;
            public string LoginAccessToken = string.Empty;
            /// <summary>
            /// 住宅ID
            /// </summary>
@@ -479,11 +664,11 @@
            /// <summary>
            ///  Config.Instance.Guid 或者 MemberInfoRes.SubAccountDistributedMark
            /// </summary>
            public string CloudAccountId = string.Empty;
            public List<string> CloudAccountIdArr = new List<string>();
            /// <summary>
            ///  开锁方式(0:密码、15:指纹、3:IC卡)
            /// </summary>
            public int OpenLockMode = -1;
            public List<int> OpenLockModeArr = null;
            /// <summary>
            /// 开锁是否成功
            /// </summary>
@@ -491,11 +676,11 @@
            /// <summary>
            /// 搜索开锁开始时间
            /// </summary>
            public DateTime UnlockTimeBegin;
            public string UnlockTimeBegin;
            /// <summary>
            /// 搜索开锁结束时间
            /// </summary>
            public DateTime UnlockTimeEnd;
            public string UnlockTimeEnd;
            /// <summary>
            /// 页数
            /// </summary>
@@ -523,7 +708,7 @@
        private class HistoryInfo
        {
            /// <summary>
            /// 开锁方式
            /// 开锁方式 0:密码  15:指纹  3:IC卡
            /// </summary>
            public int OpenLockMode = -1;
            /// <summary>
@@ -534,6 +719,22 @@
            /// 开锁是否成功
            /// </summary>
            public bool UnlockIsSuccess = false;
            /// <summary>
            /// 账号的ID
            /// </summary>
            public string CloudAccountId = string.Empty;
            /// <summary>
            /// 当开锁方式为-1时使用,它属于其他类
            /// </summary>
            public string AlarmMsg = string.Empty;
            /// <summary>
            /// 当开锁方式为-1时使用,设备Mac
            /// </summary>
            public string DeviceMac = string.Empty;
            /// <summary>
            /// 当开锁方式为-1时使用,设备端点
            /// </summary>
            public int DeviceEpoint = 0;
        }
        #endregion