diff --git a/Tiobon.Core.Services/Ghre/Ghre_PlanServices.cs b/Tiobon.Core.Services/Ghre/Ghre_PlanServices.cs index 99a9ab8a..47616247 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_PlanServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_PlanServices.cs @@ -807,17 +807,63 @@ public class Ghre_PlanServices : BaseServices() + .Where(x => x.Year == dt.Value.Year && x.DeptId == deptId && x.Month.Contains($"\"{dt.Value.Month}\"")) + .CountAsync(); + + if (courseCount > 0) + { + var planIds = await Db.Queryable() + .Where(x => x.Year == dt.Value.Year && x.DeptId == deptId && x.Month.Contains($"\"{dt.Value.Month}\"")) + .Select(x => x.Id).ToListAsync(); + + for (int i = 0; i < planIds.Count; i++) + { + var submitCount1 = await Db.Queryable() + .Where(x => x.PlanId != null && x.PlanId.Contains(planIds[i].ObjToString())).CountAsync(); + submitCount = submitCount + submitCount1; + } + } data.Add(new CompletionRateBLT { - Month = formatted + Month = formatted, + SubmitCount = submitCount, + CourseCount = courseCount }); } } else { + int submitCount = 0; + var courseCount = 0; + for (DateTime? dt = startTime; dt <= endTime; dt = dt.Value.AddMonths(1)) + { + string formatted = dt.Value.ToString("yyyy-MM"); + var courseCount1 = await Db.Queryable() + .Where(x => x.Year == dt.Value.Year && x.DeptId == deptId && x.Month.Contains($"\"{dt.Value.Month}\"")) + .CountAsync(); + courseCount = courseCount + courseCount1; + + if (courseCount > 0) + { + var planIds = await Db.Queryable() + .Where(x => x.Year == dt.Value.Year && x.DeptId == deptId && x.Month.Contains($"\"{dt.Value.Month}\"")) + .Select(x => x.Id).ToListAsync(); + + for (int i = 0; i < planIds.Count; i++) + { + var submitCount1 = await Db.Queryable() + .Where(x => x.PlanId != null && x.PlanId.Contains(planIds[i].ObjToString())).CountAsync(); + submitCount = submitCount + submitCount1; + } + } + } data.Add(new CompletionRateBLT { - Month = $"{startTime.Value.ToString("yyyy-MM")}~{endTime.Value.ToString("yyyy-MM")}" + Month = $"{startTime.Value.ToString("yyyy-MM")}~{endTime.Value.ToString("yyyy-MM")}", + SubmitCount = submitCount, + CourseCount = courseCount }); } @@ -830,6 +876,10 @@ public class Ghre_PlanServices : BaseServices 0 && data[i].SubmitCount > 0) + data[i].CompletionRate = data[i].SubmitCount / data[i].CourseCount; + + data[i].CompletionRate1 = $"{data[i].CompletionRate}%"; //var examCount = await Db.Queryable() // .Where(x => x.StudyRecordId != null && studyRecordIds.Contains(x.StudyRecordId.Value)) // .CountAsync();