//按部门汇总
IEnumerable<WeekReportWithDepartmentInfo> report = summary
.GroupBy(x => new
{
x.DeptID,
x.DeptName
}).Select(g => new WeekReportWithDepartmentInfo
{
DeptID = g.Key.DeptID,
DeptName = g.Key.DeptName,
TotalNumber = g.Count(),
WorkOvertime = g.Sum(a => a.WorkOverHours),
WorkLeave = g.Where(a => a.IsNeedAttendance == true).Sum(a => a.WorkHours),
PersonalLeave = g.Where(a => a.IsNeedAttendance == true).Sum(a => a.PersonalLeave),
PaidLeave = g.Where(a => a.IsNeedAttendance == true).Sum(a => a.PaidLeave),
LateAndLeavingEarly = g.Where(a => a.IsNeedAttendance == true).Sum(a => a.LateAndLeavingEarly)
}).Skip(PageSize * (CurrentPage - 1)).Take(PageSize);
//总行数
int rows = summary
.GroupBy(x => new
{
x.DeptID,
x.DeptName
}).Count();
List<WeekReportWithDepartmentInfo> reportlist = new List<WeekReportWithDepartmentInfo>();
IEnumerable<string> tempEmail;
foreach (WeekReportWithDepartmentInfo item in report)
{
//找到当前部门的所有人
tempEmail = employees.Where(e => e.DeptID == item.DeptID).Select(s => s.Email);
item.TotalNumber = summary.Where(e => e.DeptID == item.DeptID).GroupBy(x => new {x.EmpID}).Count();
////汇总所有人的事假
//item.PersonalLeave = personalLeave.Where(p => tempEmail.Contains(p.Key)).Sum(s => s.Value);
////汇总所有人的带薪假总工时
//item.PaidLeave = paidLeave.Where(p => tempEmail.Contains(p.Key)).Sum(s => s.Value);
//double jialeave=JiaLeave.Where(p => tempEmail.Contains(p.Key)).Sum(s => s.Value);
////迟到早退工时
//item.LateAndLeavingEarly = item.LateAndLeavingEarly - jialeave;
//item.LateAndLeavingEarly = item.LateAndLeavingEarly < 0 ? 0 : item.LateAndLeavingEarly;
//汇总所有人的加班总工时
//item.WorkOvertime = workOvertime.Where(p => tempEmail.Contains(p.Key)).Sum(s => s.Value);
//全勤人数
item.QqingNumber = item.TotalNumber - summary.Where(s => s.IsNeedAttendance && s.DeptID == item.DeptID && s.AttendanceState != 9).Select(s => s.EmpID).Distinct().Count();//去重复
//正常考勤时 item.WorkLeave
//缺勤率
item.BsenteeismRatio = (item.LateAndLeavingEarly + item.PersonalLeave + item.PaidLeave) / item.WorkLeave * 100;
//加班率
item.OvertimeRatio = item.WorkOvertime / item.WorkLeave * 100;
reportlist.Add(item);
}
//IEnumerable<KeyValue<string, double>> JiaLeave = leaveWithWeek.Where(l => l.TypeName != LeaveType.加班
// && l.TypeName != LeaveType.补打卡)
// .GroupBy(x => new { x.Email })
// .Select(g => new KeyValue<string, double>
// {
// Key = g.Key.Email,
// Value = g.Sum(a => (a.AskLeaveHour))
// });
//签到(9:00-12:00)
tempAtdRec = attendances.Where(a => a.EmpID == emp.EmpID && a.RecDateTime > workDay.GetInTime().AddHours(-4) && a.RecDateTime < workDay.GetOutTime()).OrderBy(a => a.RecDateTime);
if (tempAtdRec.Count() > 0)
{
info.SigninTime = tempAtdRec.First().RecTime;
info.SigninDateTime = tempAtdRec.First().RecDateTime;
}
//签退(13:30-18:00)
tempAtdRec = attendances.Where(a => a.EmpID == emp.EmpID && a.RecDateTime > workDay.GetInTime() && a.RecDateTime < workDay.GetInTime().AddDays(1).AddHours(-4)).OrderByDescending(a => a.RecDateTime);
if (tempAtdRec.Count() > 0)
{
info.SignoutTime = tempAtdRec.First().RecTime;
info.SignoutDateTime = tempAtdRec.First().RecDateTime;
}