Пример #1
0
        private void EnsureCheckInOrCheckOut(AttendanceLog log, string workerId)
        {
            var attendance          = _db.GetLastAttendanceLogByEnrollNumber(log.UserId);
            AttendanceStatus status = AttendanceStatus.Unknown;

            try
            {
                status = log.CalculateStatus(attendance);
            }
            catch (NotSupportedException ex)
            {
                _logger.ErrorFormat("EnsureCheckInOrCheckOut error:{exception}, attendance:{@log}, worker:{id}",
                                    ex.Message, attendance, workerId);
                return;
            }

            if (status == AttendanceStatus.CheckIn)
            {
                EnsureCheckIn(log, workerId);
                return;
            }

            if (status == AttendanceStatus.CheckOut)
            {
                EnsureCheckOut(log, workerId);
                return;
            }

            _logger.ErrorFormat("EnsureCheckInOrCheckOut: Unknown status, attendance:{@log}, worker:{id}", attendance, workerId);
        }
Пример #2
0
        private void CheckInOrCheckOut(AttendanceLog attendance, string workerId)
        {
            var lastAttendance = GetLastAttendanceLog(attendance.UserId, attendance.LogDate);

            Logger.DebugFormat("Last attendance({@attendance}).", lastAttendance);

            AttendanceStatus status = AttendanceStatus.Unknown;

            try
            {
                status = attendance.CalculateStatus(lastAttendance);
                Logger.DebugFormat("Attendance({id}) status: {status}.", attendance.Id, status);
            }
            catch (NotSupportedException ex)
            {
                Logger.ErrorFormat("CheckInOrCheckOut error:{exception}, attendance:{@log}, worker:{id}",
                                   ex.Message, attendance, workerId);
                return;
            }

            if (status == AttendanceStatus.CheckIn)
            {
                CheckIn(attendance, workerId);
                return;
            }

            if (status == AttendanceStatus.CheckOut)
            {
                CheckOut(attendance, workerId);
                return;
            }

            Logger.ErrorFormat("CheckInOrCheckOut: Unknown status, attendance:{@log}, worker:{id}", attendance, workerId);
        }
        public void TestCheckInAndOut()
        {
            var prev   = new AttendanceLog("6365298588900000001", "1", 15, 15, new DateTime(2018, 1, 31, 8, 58, 9), 1, 1, "592e2531b2ddc226f0df2b24", "gate02", DeviceType.InOut, AttendanceStatus.CheckIn);
            var next   = new AttendanceLog("1", 15, 15, 2018, 1, 31, 18, 15, 16, 1, 1, "gate02", DeviceType.InOut);
            var status = next.CalculateStatus(prev);

            Assert.AreEqual(AttendanceStatus.CheckOut, status);
        }
Пример #4
0
        public void TestCheckInOut05()
        {
            var lastLog = new AttendanceLog("1", 15, 15, 2017, 12, 27, 18, 0, 0, 0, 1, "gate-01", DeviceType.InOut);

            lastLog.CheckOut();
            var currLog = new AttendanceLog("1", 15, 15, 2017, 12, 28, 7, 0, 0, 0, 1, "gate-01", DeviceType.InOut);
            var status  = currLog.CalculateStatus(lastLog);

            Assert.AreEqual(AttendanceStatus.CheckIn, status);
        }