Пример #1
0
        private double GetOverWork(AttendanceToday attendanceToday)
        {
            double result     = 0.0;
            int    i          = 0;
            var    attendance = attendanceToday.AttendancesForDay.ConvertAll(a => a.RecordTimeToDateTime);

            attendance.Sort();
            while (i < attendanceToday.AttendancesForDay.Count)
            {
                try
                {
                    result += Math.Abs(attendance[i + 1].Subtract(attendance[i]).TotalMinutes);
                    i       = i + 2;
                }
                catch { i = i + 2; }
            }
            i = 0;
            //while(i < attendanceToday.OverWorksToday.Count)
            //{
            //    result += attendanceToday.OverWorksToday[i].EndDateTimeToDateTime.Subtract(attendanceToday.OverWorksToday[i].BeginDateTimeToDateTime).TotalMinutes;
            //    i++;
            //}
            while (i < attendanceToday.BusinessTripsToDay.Count)
            {
                result += attendanceToday.BusinessTripsToDay[i].EndDateToDateTime.Subtract(attendanceToday.BusinessTripsToDay[i].BeginDateToDateTime).TotalMinutes;
                i++;
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        ///     获取一天的值,传入一个月的值
        /// </summary>
        /// <param name="attendances"></param>
        /// <param name="overWorks"></param>
        /// <param name="businessTrips"></param>
        /// <param name="reSignIns"></param>
        /// <param name="askLeaves"></param>
        /// <param name="day"></param>
        /// <returns></returns>
        public AttendanceToday GetAttendanceToday(List <Attendance> attendances,
                                                  List <OverWork> overWorks,
                                                  List <BusinessTrip> businessTrips, List <ReSignIn> reSignIns, List <AskLeave> askLeaves, int day)
        {
            var attendanceForDay = attendances.Where(a => DateTime.Parse(a.RecordTime).Day == day).ToList();


            var overWorkForDay = overWorks.Where(o => DateTime.Parse(o.BeginDateTime).Day == day).ToList();


            var businessTripsForDay = businessTrips.Where(b => DateTime.Parse(b.BeginDate).Day == day).ToList();


            var reSignInForDay = reSignIns.Where(r => DateTime.Parse(r.ReSignInDate).Day == day).ToList();


            var askLeaveForDay = askLeaves.Where(a => DateTime.Parse(a.BeginDate).Day == day).ToList();

            var attendanceToDay = new AttendanceToday
            {
                Day                = day,
                AskleavesToDay     = askLeaveForDay,
                BusinessTripsToDay = businessTripsForDay,
                OverWorksToday     = overWorkForDay,
                ReSiginToday       = reSignInForDay.ConvertAll(r => r.ReSignInDateToDateTime),
                AttendancesForDay  = attendanceForDay
            };

            return(attendanceToDay);
        }
Пример #3
0
        /// <summary>
        /// 处理出差时间 请假时间
        /// </summary>
        /// <param name="attendanceToday"></param>
        /// <param name="aResult"></param>
        private void processUnnormal(AttendanceToday attendanceToday, AttendanceResult aResult)
        {
            var groups = attendanceToday.AskleavesToDay.GroupBy(a => a.AskLeaveType.AskLeaveTypeId);

            foreach (var group in groups)
            {
                AskLeaveTypeForAttendance atfa = new AskLeaveTypeForAttendance();

                var askLeaveType = HrManagerContext.GetInstance().AskLeaveTypes.Find(group.Key);
                atfa.AskLeaveType = askLeaveType;
                foreach (var item in group)
                {
                    atfa.TimeCount += item.EndDateToDateTime.Subtract(item.BeginDateToDateTime).TotalHours;
                }
                aResult.AskLeaveTypeForAttendances.Add(atfa);
            }

            foreach (BusinessTrip tmp_bust in attendanceToday.BusinessTripsToDay)
            {
                aResult.BusTrip += tmp_bust.EndDateToDateTime.Subtract(tmp_bust.BeginDateToDateTime).TotalHours;
            }

            var tiaoxius =
                HrManagerContext.GetInstance()
                .TiaoXius.Where(t => t.EmployeeId == attendanceToday.Employee.EmployeeId)
                .ToList()
                .Where(t => t.CurDateTime.Day == attendanceToday.Day)
                .ToList();

            if (tiaoxius.Count != 0)
            {
                if (tiaoxius[0].IsHalfDay)
                {
                    aResult.TiaoXiu = "0.5";
                }
                else
                {
                    aResult.TiaoXiu = "1";
                }
            }
            else
            {
                aResult.TiaoXiu = "0";
            }


            //foreach (OverWork tmp_over in attendanceToday.OverWorksToday)
            //{
            //    aResult.OverWork_normal += double.Parse(tmp_over.ApplyTime);
            //}

            aResult.ReSignIn = attendanceToday.ReSiginToday.Count;
        }
Пример #4
0
        public AttendanceToday   AnalysisForPresonByDay(AttendanceToday aToday, List <ArrangeWork> arrangeWorks)
        {
            //这一天的数据

            var attendanceForDay = aToday.AttendancesForDay;

            var overWorkForDay = aToday.OverWorksToday;

            var businessTripsForDay = aToday.BusinessTripsToDay;

            var reSignInForDay = aToday.ReSiginToday;
            var askLeaveForDay = aToday.AskleavesToDay;


            var toDayAttendanceList = attendanceForDay.ConvertAll(a => a.RecordTimeToDateTime);


            //排除请假 出差 加班等影响的打卡记录
            aToday.VirAttendanceDateTimes = toDayAttendanceList.ToList();

            #region 这一天的打卡记录模拟

            //这一天的打开记录


            if (toDayAttendanceList.Count != 0)
            {
                //请假单 和 出差单 都会影响正常打卡 且推导不出正常的打卡 从打卡记录里面删除

                foreach (var askLeave in askLeaveForDay)
                {
                    toDayAttendanceList.RemoveAll(t => IsInSpanTime(t, askLeave.BeginDateToDateTime, 10));
                    toDayAttendanceList.RemoveAll(t => IsInSpanTime(t, askLeave.EndDateToDateTime, 10));
                }

                foreach (var businessTrip in businessTripsForDay)
                {
                    toDayAttendanceList.RemoveAll(t => IsInSpanTime(t, businessTrip.BeginDateToDateTime, 10));
                    toDayAttendanceList.RemoveAll(t => IsInSpanTime(t, businessTrip.EndDateToDateTime, 10));
                }



                foreach (var overworke in overWorkForDay)
                {
                    if (overworke.IsOffDuty)
                    {
                        toDayAttendanceList.Add(overworke.BeginDateTimeToDateTime);
                    }
                    else if (overworke.IsOnDuty)
                    {
                        toDayAttendanceList.Add(overworke.EndDateTimeToDateTime);
                    }
                    else
                    {
                        toDayAttendanceList.RemoveAll(t => IsInSpanTime(t, overworke.BeginDateTimeToDateTime, 20));
                        toDayAttendanceList.RemoveAll(t => IsInSpanTime(t, overworke.EndDateTimeToDateTime, 20));
                    }
                }
                toDayAttendanceList.AddRange(reSignInForDay);
            }
            else
            {
                return(aToday);
            }

            #endregion


            if (toDayAttendanceList.Count() == 0)
            {
                return(aToday);
            }

            var workTimeSpans = new List <WorkTimeSpan>();



            foreach (var dateTime in toDayAttendanceList)
            {
                //求每一个打卡时间与所有班次的时间差
                foreach (var arrangeWork in  arrangeWorks)
                {
                    workTimeSpans.Add(new WorkTimeSpan
                    {
                        OnDutyTimeSpan  = GetTimeSpan(dateTime, arrangeWork.OnDutyTimeToDateTime),
                        OffDutyTimeSpan = GetTimeSpan(dateTime, arrangeWork.OffDutyTimeToDateTime),
                        ArrangeWorkNo   = arrangeWork.ArrangeWorkNo
                    });
                }
            }



            //时间少的在前面
            workTimeSpans.Sort();
            var top10WorkTimeSpans = workTimeSpans.Take(20).ToList();
            var groups             = top10WorkTimeSpans.GroupBy(t => t.ArrangeWorkNo);
            var countMax           = groups.Max(g => g.Count());
            var MaxGroups          = groups.Where(g => g.Count() == countMax).ToList();

            Dictionary <string, TimeSpan> gTimeSpans = new Dictionary <string, TimeSpan>();

            foreach (var maxGroup in MaxGroups)
            {
                var timeSpan = new TimeSpan();
                timeSpan = maxGroup.Aggregate(timeSpan, (current, span) => current + span.ComperTimeSpan);
                gTimeSpans.Add(maxGroup.Key, timeSpan);
            }
            var newdic = gTimeSpans.OrderBy(g => g.Value);
            aToday.ArrangeWorkNo = newdic.First().Key;
            return(aToday);
        }