Exemplo n.º 1
0
        /// <summary>
        /// 获取服务器考勤记录
        /// </summary>
        public void GetServicePunchClocksData(bool isNewRecord = false)
        {
            if (isNewRecord)
            {
                _isLast = false;
            }
            if (_isLast)
            {
                return;
            }
            AsyncHandler.CallFuncWithUI(System.Windows.Application.Current.Dispatcher,
                                        () =>
            {
                if (isNewRecord)
                {
                    timer?.Stop();
                    timer = null;
                    _page = 0;
                    todayAttendanceRecords = null;
                }
                _page++;
                var errorCode         = 0;
                var errorMsg          = string.Empty;
                var punchClocksOutput = AntSdkService.GetPunchClocks(AntSdkService.AntSdkLoginOutput.userId, _page, _size, ref errorCode, ref errorMsg);
                return(punchClocksOutput);
            },
                                        (ex, datas) =>
            {
                if (isNewRecord)
                {
                    AttendanceRecords.Clear();
                }
                if (datas != null && datas.list.Count > 0)
                {
                    var serverDateTime        = PublicTalkMothed.ConvertStringToDateTime(datas.systemTime);
                    var punchClocksOutputList = datas.list.OrderByDescending(m => m.attendId);
                    foreach (var punchClocks in datas.list)
                    {
                        var exitAttendanceRecord = AttendanceRecords.FirstOrDefault(m => m.AttendId == punchClocks.attendId);
                        if (exitAttendanceRecord != null)
                        {
                            continue;
                        }
                        var attendanceRecord              = new AttendanceRecord();
                        attendanceRecord.AttendId         = punchClocks.attendId;
                        attendanceRecord.VerifyState      = punchClocks.status;
                        attendanceRecord.PuncherTimeStamp = punchClocks.attendTime;

                        if (attendanceRecord.VerifyState == 0)
                        {
                            attendanceRecord.IsbtnVerify    = true;
                            attendanceRecord.VerifyDescribe = "待验证";
                        }
                        else if (attendanceRecord.VerifyState == 1)
                        {
                            attendanceRecord.VerifyDescribe = "验证过期";
                        }
                        else if (attendanceRecord.VerifyState == 2)
                        {
                            attendanceRecord.VerifyDescribe = "打卡成功";
                        }
                        var diffMinute = serverDateTime - PublicTalkMothed.ConvertStringToDateTime(punchClocks.attendTime);
                        if ((diffMinute.Days > 0 || diffMinute.TotalMinutes > 20) && attendanceRecord.VerifyState == 0)
                        {
                            attendanceRecord.IsbtnVerify    = false;
                            attendanceRecord.VerifyDescribe = "验证过期";
                            attendanceRecord.VerifyState    = 1;
                        }
                        if (!string.IsNullOrEmpty(punchClocks.attendTime))
                        {
                            attendanceRecord.PuncherDateTime = PublicTalkMothed.ConvertStringToDateTime(punchClocks.attendTime);
                        }
                        else
                        {
                            attendanceRecord.PuncherDateTime = DateTime.Now;
                        }
                        attendanceRecord.PuncherAddress = punchClocks.address;
                        if (attendanceRecord.PuncherDateTime.Year - DateTime.Now.Year > 0)
                        {
                            attendanceRecord.PuncherDate = attendanceRecord.PuncherDateTime.ToString("yyyy年MM月dd日");
                        }
                        else
                        {
                            attendanceRecord.PuncherDate = attendanceRecord.PuncherDateTime.ToString("MM月dd日");
                        }
                        attendanceRecord.PuncherTime = attendanceRecord.PuncherDateTime.ToString("HH:mm");
                        AttendanceRecords.Insert(0, attendanceRecord);
                    }

                    _isFirst = datas.isFirstPage;
                    _isLast  = datas.isLastPage;
                    var tempAttendanceRecord = AttendanceRecords.FirstOrDefault(m => m.IsbtnVerify);
                    if (tempAttendanceRecord != null)
                    {
                        LoadData(tempAttendanceRecord);
                    }
                }
                else
                {
                }
            });
        }