コード例 #1
0
        public DoorMonitorRecordViewModel()
        {
            DoorStates = new ObservableCollection <DoorState>();
            DoorStates.Add(new DoorState()
            {
                DoorNumber = "#1", Who = "张三", Time = DateTime.Now, Action = "进场"
            });
            DoorStates.Add(new DoorState()
            {
                DoorNumber = "#2", Who = "李四", Time = DateTime.Now, Action = "出场"
            });
            DoorStates.Add(new DoorState()
            {
                DoorNumber = "#3", Who = "王五", Time = DateTime.Now, Action = "进场"
            });

            Statistics = new AttendanceStatistics()
            {
                Jc   = 950,
                Cc   = 453,
                Zc   = 918,
                Xc   = 341,
                Ycq  = 950,
                Scq  = 934,
                Cqzc = 930,
                Cd   = 35,
                Zt   = 16,
                Qq   = 16
            };
        }
コード例 #2
0
        /// <summary>
        /// 统计考勤
        /// </summary>
        public static void Atten()
        {
            IAdministratorContract        _adminContract           = EntityContract._adminContract;
            IAttendanceContract           _attenContract           = EntityContract._attenContract;
            IAttendanceStatisticsContract _attenStatisticsContract = EntityContract._attenStatisticsContract;
            DateTime                    current        = DateTime.Now;
            List <Administrator>        listAdmin      = _adminContract.Administrators.Where(x => x.IsDeleted == false && x.IsEnabled == true).ToList();
            List <Attendance>           listAtten      = _attenContract.Attendances.Where(x => x.IsDeleted == false && x.IsEnabled == true && x.AttendanceTime.Year == current.Year && x.AttendanceTime.Month == current.Month && x.AttendanceTime.Day == current.Day).ToList();
            List <int>                  listAdminId    = listAdmin.Select(x => x.Id).ToList();
            List <AttendanceStatistics> listStatistics = _attenStatisticsContract.AttendanceStatisticses.Where(x => listAdminId.Contains(x.AdminId)).ToList();
            Dictionary <string, int>    dic            = GetHoliday();
            WorkTime                    workTime;
            List <Attendance>           listEntity           = new List <Attendance>();
            List <AttendanceStatistics> listStatisticsAdd    = new List <AttendanceStatistics>();
            List <AttendanceStatistics> listStatisticsUpdate = new List <AttendanceStatistics>();

            foreach (Administrator admin in listAdmin)
            {
                workTime = GetWorkTime(admin);
                bool res = OfficeHelper.IsWorkDay(current, workTime, dic);
                if (res == true)
                {
                    Attendance atten = GetAtten(listAtten, current, admin.Id, workTime.IsPersonalTime);
                    if (atten.Id == 0)
                    {
                        listEntity.Add(atten);
                    }
                    AttendanceStatistics statistics = GetAttenStatistics(listStatistics, workTime, atten, admin.Id);
                    if (statistics.Id == 0)
                    {
                        listStatisticsAdd.Add(statistics);
                    }
                    else
                    {
                        listStatisticsUpdate.Add(statistics);
                    }
                }
                else
                {
                    string            strDate           = current.ToString("yyyy/MM/dd 00:00:00");
                    DateTime          date              = DateTime.Parse(strDate);
                    IOvertimeContract _overTimeContract = DependencyResolver.Current.GetService <IOvertimeContract>();
                    int count = _overTimeContract.Overtimes.Where(x => x.AdminId == admin.Id && x.VerifyType == (int)VerifyFlag.Pass && date.CompareTo(x.StartTime) >= 0 && date.CompareTo(x.EndTime) <= 0).Count();
                    if (count > 0)
                    {
                        Attendance atten = GetAtten(listAtten, current, admin.Id, workTime.IsPersonalTime);
                        if (atten != null)
                        {
                            listEntity.Add(atten);
                        }
                    }
                }
            }

            _attenContract.Add(listEntity, listStatisticsAdd, listStatisticsUpdate);
        }
コード例 #3
0
        public JsonResult GetVacation(int AdminId)
        {
            int  PaidLeaveDays            = 0;
            int  AnnualLeaveDays          = 0;
            Rest rest                     = _restContract.Rests.Where(x => x.IsDeleted == false && x.IsEnabled == true && x.AdminId == AdminId).FirstOrDefault();
            AttendanceStatistics attenSta = _attStatisticsContract.AttendanceStatisticses.Where(x => x.IsDeleted == false && x.IsEnabled == true && x.AdminId == AdminId).FirstOrDefault();

            if (rest != null)
            {
                AnnualLeaveDays = AnnualLeaveDays + (int)rest.AnnualLeaveDays;
                PaidLeaveDays   = PaidLeaveDays + (int)rest.PaidLeaveDays;
            }
            if (attenSta != null)
            {
                PaidLeaveDays = PaidLeaveDays + (int)attenSta.RestDays;
            }
            var data = new
            {
                PaidLeaveDays,
                AnnualLeaveDays
            };

            return(Json(data));
        }
コード例 #4
0
        /// <summary>
        /// 根据时期获取考勤数据
        /// </summary>
        /// <returns></returns>
        public JsonResult GetAttenByDate(int AdminId, DateTime Date)
        {
            OperationResult oper = new OperationResult(OperationResultType.Error, "服务器忙,请稍候访问");

            try
            {
                Administrator admin = _administratorContract.View(AdminId);
                //获取工作时间
                var      WToper   = GetWorkTime(admin);
                WorkTime workTime = new WorkTime();
                if (WToper.ResultType != OperationResultType.Success)
                {
                    WToper.Data = null;
                    return(Json(WToper, JsonRequestBehavior.AllowGet));
                }
                workTime = WToper.Data as WorkTime;

                List <Attendance>  listAtten = _attendanceContract.Attendances.Where(x => x.IsDeleted == false && x.IsEnabled == true && x.AdminId == AdminId && x.AttendanceTime.Year == Date.Year && x.AttendanceTime.Month == Date.Month).ToList();
                AppAttenStatistics appAtten  = new AppAttenStatistics();
                double             num       = 0;
                appAtten.NormalCount = listAtten.Count();
                var leaveinfos = _leaveInfoContract.LeaveInfos.Where(x => x.IsDeleted == false && x.IsEnabled == true && x.AdminId == AdminId && x.StartTime.Year == Date.Year && x.StartTime.Month == Date.Month);
                appAtten.LeaveTimes = leaveinfos == null || leaveinfos.Count() == 0 ? num : leaveinfos.ToList().Sum(x => x.LeaveDays);
                var overtimes = _overtimeContract.Overtimes.Where(x => x.IsDeleted == false && x.IsEnabled == true && x.AdminId == AdminId && x.StartTime.Year == Date.Year && x.StartTime.Month == Date.Month);
                appAtten.OvertimeTimes = overtimes == null || overtimes.Count() == 0 ? num : overtimes.ToList().Sum(x => x.OvertimeDays);
                var fields = _fieldContract.Fields.Where(x => x.IsDeleted == false && x.IsEnabled == true && x.AdminId == AdminId && x.StartTime.Year == Date.Year && x.StartTime.Month == Date.Month);
                appAtten.FieldTimes  = fields == null || fields.Count() == 0 ? num : fields.ToList().Sum(x => x.FieldDays);
                appAtten.RepairCount = listAtten.Where(w => w.AttendanceRepairs != null).SelectMany(s => s.AttendanceRepairs).Where(w => w.VerifyType == (int)VerifyFlag.Pass).Count();

                if (listAtten != null)
                {
                    appAtten.ArrivalEarlyCount         = listAtten.Where(x => x.ArrivalEarlyMinutes > 0).Count();
                    appAtten.LateCount                 = listAtten.Where(x => x.IsLate == -1).Count();
                    appAtten.IsLateConfirmRepair       = listAtten.Count(x => x.IsLate == -1 && x.AttendanceRepairs != null && x.AttendanceRepairs.Count(r => r.VerifyType == 3 && r.ApiAttenFlag == (int)ApiAttenFlag.Late && !r.IsDeleted && r.IsEnabled) > 0) > 0;
                    appAtten.LeaveEarlyCount           = listAtten.Where(x => x.IsLeaveEarly == -1).Count();
                    appAtten.IsLeaveEarlyConfirmRepair = listAtten.Count(x => x.IsLeaveEarly == -1 && x.AttendanceRepairs != null && x.AttendanceRepairs.Count(r => r.VerifyType == 3 && r.ApiAttenFlag == (int)ApiAttenFlag.LeaveEarly && !r.IsDeleted && r.IsEnabled) > 0) > 0;
                    appAtten.NoSignOutCount            = listAtten.Where(x => x.IsNoSignOut == -1 && (!x.AttendanceTime.ToShortDateString().Equals(DateTime.Now.ToShortDateString()) || (x.AttendanceTime.ToShortDateString().Equals(DateTime.Now.ToShortDateString()) && DateTime.Now > Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + workTime.PmEndTime)))).Count();
                    appAtten.IsNoSignOutConfirmRepair  = listAtten.Count(x => x.IsNoSignOut == -1 && (!x.AttendanceTime.ToShortDateString().Equals(DateTime.Now.ToShortDateString()) || (x.AttendanceTime.ToShortDateString().Equals(DateTime.Now.ToShortDateString()) && DateTime.Now > Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + workTime.PmEndTime))) && x.AttendanceRepairs != null && x.AttendanceRepairs.Count(r => r.VerifyType == 3 && r.ApiAttenFlag == (int)ApiAttenFlag.NoSignOut && !r.IsDeleted && r.IsEnabled) > 0) > 0;
                    appAtten.LeaveLateCount            = listAtten.Where(x => x.LeaveLateMinutes > 0).Count();
                }
                int absenceCount = 0;// listAtten.Where(x => x.IsAbsence == true && x.AbsenceType == (int)AttendanceFlag.DayOfAbsence).Count();
                var _oper        = _attendanceContract.GetNoLoginCount(admin.Id);
                if (_oper.ResultType == OperationResultType.Success)
                {
                    absenceCount = (_oper.Data as List <AttendanceInfo>).Count();
                }
                appAtten.AbsenceCount = absenceCount;
                DateTime endtime = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " 18:00");
                if (admin.WorkTime != null && !string.IsNullOrEmpty(admin.WorkTime.PmEndTime))
                {
                    endtime = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + admin.WorkTime.PmEndTime);
                }
                //appAtten.NoSignOutCount = listAtten.Where(x => string.IsNullOrEmpty(x.PmEndTime) && endtime < DateTime.Now).Count();
                AttendanceStatistics attSta = _attStatisticsContract.AttendanceStatisticses.FirstOrDefault(x => x.AdminId == AdminId && x.CreatedTime.Year == Date.Year);
                Rest rest = _restContract.Rests.FirstOrDefault(x => x.AdminId == AdminId);
                if (rest != null)
                {
                    appAtten.AnnualLeave  = rest.AnnualLeaveDays;
                    appAtten.PaidVacation = rest.PaidLeaveDays;
                }
                if (attSta != null)
                {
                    appAtten.WorkDays = attSta.AbsenceDays;
                    //appAtten.RestDays = attSta.RestDays;
                }
                oper.Message    = string.Empty;
                oper.Data       = appAtten;
                oper.ResultType = OperationResultType.Success;
                return(Json(oper, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                _Logger.Error <string>(ex.ToString());
                return(Json(oper, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #5
0
        private static AttendanceStatistics GetAttenStatistics(List <AttendanceStatistics> listStatistics, WorkTime workTime, Attendance atten, int adminId)
        {
            AttendanceStatistics statistics = listStatistics.FirstOrDefault(x => x.AdminId == adminId && x.CreatedTime.Year == atten.CreatedTime.Year);
            int hour            = workTime.WorkHour;
            int negativeMinutes = 0;
            int positiveMinutes = 0;

            if (workTime.IsPersonalTime)
            {
                var deatile = EntityContract._workTimeDetaileContract.WorkTimeDetailes.Where(x => x.WorkTimeId == workTime.Id && x.WorkDay == DateTime.Now.Day)
                              .FirstOrDefault();
                if (deatile != null)
                {
                    hour = deatile.WorkHour;
                }
            }
            if (statistics == null)
            {
                statistics = new AttendanceStatistics()
                {
                    AdminId = adminId,
                };
            }
            else
            {
                //negativeMinutes = statistics.NegativeMinutes;
                //positiveMinutes = statistics.PositiveMinutes;
            }
            negativeMinutes = (int)(atten.LateMinutes + negativeMinutes + atten.LeaveEarlyMinutes);
            positiveMinutes = (int)(atten.ArrivalEarlyMinutes + positiveMinutes + atten.LeaveLateMinutes);
            if (atten.IsAbsence == -1)
            {
                if (atten.AbsenceType == (int)AttendanceFlag.AmAbsence || atten.AbsenceType == (int)AttendanceFlag.PmAbsence)
                {
                    int mimutes = 0;
                    if (workTime.IsFlexibleWork == true)
                    {
                        mimutes = 4 * 60;
                    }
                    else
                    {
                        mimutes = hour / 2 * 60;
                    }
                    negativeMinutes = negativeMinutes + mimutes;
                }
                else
                {
                    statistics.AbsenceDays = statistics.AbsenceDays + 1;
                }
            }
            statistics.NegativeMinutes = negativeMinutes + statistics.NegativeMinutes;
            statistics.PositiveMinutes = positiveMinutes + statistics.PositiveMinutes;
            if (workTime.IsFlexibleWork == false && statistics.NegativeMinutes > 60 * hour)
            {
                int workMin = 60 * hour;
                int neDays  = statistics.NegativeMinutes / workMin;
                int neMins  = statistics.NegativeMinutes % workMin;
                statistics.AbsenceDays     = statistics.AbsenceDays + neDays;
                statistics.NegativeMinutes = neMins;
            }
            if (workTime.IsFlexibleWork == false && statistics.PositiveMinutes > 60 * hour)
            {
                int workMin = 60 * hour;
                int poDays  = statistics.PositiveMinutes / workMin;
                int poMins  = statistics.PositiveMinutes % workMin;
                statistics.RestDays        = statistics.RestDays + poDays;
                statistics.PositiveMinutes = poMins;
            }
            return(statistics);
        }