|
|
|
@ -1,4 +1,5 @@ |
|
|
|
|
using NPOI.SS.UserModel; |
|
|
|
|
using Tiobon.Core.IServices; |
|
|
|
|
using static Tiobon.Core.Model.Consts; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
@ -291,6 +292,9 @@ public class Ghre_CourseServices : BaseServices<Ghre_Course, Ghre_CourseDto, Ins |
|
|
|
|
public override async Task<Ghre_CourseDto> QueryById(object objId) |
|
|
|
|
{ |
|
|
|
|
var data = await base.QueryById(objId); |
|
|
|
|
|
|
|
|
|
if (data == null) |
|
|
|
|
throw new Exception("无效的Id"); |
|
|
|
|
var DT_TableDataT1 = Mapper.Map(data).ToANew<Ghre_CourseDto>(); |
|
|
|
|
string examPaperId = DT_TableDataT1.ExamPaperId; |
|
|
|
|
|
|
|
|
@ -1309,4 +1313,193 @@ public class Ghre_CourseServices : BaseServices<Ghre_Course, Ghre_CourseDto, Ins |
|
|
|
|
return ServiceResult.OprateSuccess("执行成功!"); |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region 课程统计 |
|
|
|
|
/// <summary> |
|
|
|
|
/// 课程统计 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="id"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public async Task<dynamic> QueryStatistic(long id) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
dynamic obj = new ExpandoObject(); |
|
|
|
|
dynamic data = new ExpandoObject(); |
|
|
|
|
var entity = await QueryById(id); |
|
|
|
|
|
|
|
|
|
data.CourseClassName = entity.CourseClassName; |
|
|
|
|
data.StandardHour = entity.StandardHour; |
|
|
|
|
data.CreditPoints = entity.CreditPoints; |
|
|
|
|
data.ManagerStaffName = entity.ManagerStaffName; |
|
|
|
|
data.InOrOut = entity.InOrOutLabel; |
|
|
|
|
data.IsOpen = entity.IsOPenLabel; |
|
|
|
|
data.ValidityPeriod = entity.ValidityPeriod; |
|
|
|
|
data.CourseSceneName = entity.CourseSceneName; |
|
|
|
|
|
|
|
|
|
//必修人数 |
|
|
|
|
var RequiredCount = await Db.Queryable<Ghre_StudyRecord>().Where(x => x.CourseId == id && (x.CourseType == "ManualRequired" || x.CourseType == "Required")).CountAsync(); |
|
|
|
|
data.RequiredCount = RequiredCount; |
|
|
|
|
|
|
|
|
|
//选修人次 |
|
|
|
|
var ElectiveCount = await Db.Queryable<Ghre_StudyRecord>().Where(x => x.CourseId == id && (x.CourseType == "ManualElective" || x.CourseType == "Elective")).CountAsync(); |
|
|
|
|
data.ElectiveCount = ElectiveCount; |
|
|
|
|
|
|
|
|
|
var CompleteCount = await Db.Queryable<Ghre_StudyRecord>().Where(x => x.CourseId == id && x.CompleteStatus == DIC_STUDY_RECORD_STUDY_COMPLETE_STATUS.FINISHED && (x.CourseType == "ManualElective" || x.CourseType == "Elective" || x.CourseType == "ManualElective" || x.CourseType == "Elective")).CountAsync(); |
|
|
|
|
//完成人数 |
|
|
|
|
data.CompleteCount = CompleteCount; |
|
|
|
|
//开班人数 |
|
|
|
|
var OpenClassCount = await Db.Queryable<Ghre_StudyRecord>().Where(x => x.CourseId == id && x.OpenClassId != null).CountAsync(); |
|
|
|
|
data.OpenClassCount = OpenClassCount; |
|
|
|
|
|
|
|
|
|
var studyRecordIds = await Db.Queryable<Ghre_StudyRecord>().Where(x => x.CourseId == id).Select(x => x.Id).ToListAsync(); |
|
|
|
|
//总学习时长 |
|
|
|
|
data.TotalStudyDuration = await Db.Queryable<Ghre_StudyRecordDetail>().Where(x => x.StudyRecordId != null && studyRecordIds.Contains(x.StudyRecordId.Value)).SumAsync(x => x.StudyDuration); |
|
|
|
|
|
|
|
|
|
var AvgStudyDuration = await Db.Queryable<Ghre_StudyRecordDetail>().Where(x => x.StudyRecordId != null && studyRecordIds.Contains(x.StudyRecordId.Value)).GroupBy(x => x.StaffId) |
|
|
|
|
.Select(m => new { m.StaffId, StudyDuration = SqlFunc.AggregateSum(m.StudyDuration) }).ToListAsync(); |
|
|
|
|
//平均学习时长 |
|
|
|
|
data.AvgStudyDuration = AvgStudyDuration.Average(x => x.StudyDuration); |
|
|
|
|
//平均分 |
|
|
|
|
var AvgScore = await Db.Queryable<Ghre_ExamRecord>().Where(x => x.StudyRecordId != null && studyRecordIds.Contains(x.StudyRecordId.Value)).AvgAsync(x => x.FinallyScore ?? (x.Score + x.AdjustScore)); |
|
|
|
|
data.AvgScore = AvgScore ?? 0; |
|
|
|
|
|
|
|
|
|
//通过率 |
|
|
|
|
var passPercent = 0; |
|
|
|
|
|
|
|
|
|
if (CompleteCount > 0 && (RequiredCount + ElectiveCount + OpenClassCount) > 0) |
|
|
|
|
passPercent = CompleteCount / (RequiredCount + ElectiveCount + OpenClassCount); |
|
|
|
|
data.PassPercent = passPercent; |
|
|
|
|
|
|
|
|
|
//考试安排次数 |
|
|
|
|
data.ExamScheduleCount = await Db.Queryable<Ghre_Exam>().Where(x => x.CourseId == id).CountAsync(); |
|
|
|
|
|
|
|
|
|
//考试人数 |
|
|
|
|
data.ExamCount = await Db.Queryable<Ghre_ExamRecord>().Where(x => x.CourseId == id).CountAsync(); |
|
|
|
|
|
|
|
|
|
//考试人次 |
|
|
|
|
data.ExamGroupCount = await Db.Queryable<Ghre_ExamRecordGroup>() |
|
|
|
|
.Where(x => x.StudyRecordId != null && studyRecordIds.Contains(x.StudyRecordId.Value)) |
|
|
|
|
.CountAsync(); |
|
|
|
|
|
|
|
|
|
//反馈人数 |
|
|
|
|
data.FeedbackCount = 0; |
|
|
|
|
|
|
|
|
|
#region 课件学习时长 |
|
|
|
|
var courseWareStudyDuration = await Db.Queryable<Ghre_StudyRecordDetail>() |
|
|
|
|
.Where(a => a.StudyRecordId != null && studyRecordIds.Contains(a.StudyRecordId.Value)) |
|
|
|
|
|
|
|
|
|
.GroupBy(a => new { a.CourseWareId, a.CourseWareAttachmentId }) |
|
|
|
|
.Select(a => new |
|
|
|
|
{ |
|
|
|
|
a.CourseWareId, |
|
|
|
|
a.CourseWareAttachmentId, |
|
|
|
|
StudyDuration = SqlFunc.AggregateSum(a.StudyDuration) |
|
|
|
|
}) |
|
|
|
|
.ToListAsync(); |
|
|
|
|
|
|
|
|
|
var courseWareStudyDurations = new JArray(); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < courseWareStudyDuration.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var courseWare = await Db.Queryable<Ghre_CourseWare>().Where(x => x.Id == courseWareStudyDuration[i].CourseWareId).FirstAsync(); |
|
|
|
|
var courseWareAttachment = await Db.Queryable<Ghre_CourseWareAttachment>().Where(x => x.Id == courseWareStudyDuration[i].CourseWareAttachmentId).FirstAsync(); |
|
|
|
|
var item = new JObject |
|
|
|
|
{ |
|
|
|
|
new JProperty("CourseWareId", courseWareStudyDuration[i].CourseWareAttachmentId), |
|
|
|
|
new JProperty("CourseWareAttachmentId", courseWareStudyDuration[i].CourseWareAttachmentId), |
|
|
|
|
new JProperty("StudyDuration", courseWareStudyDuration[i].StudyDuration), |
|
|
|
|
new JProperty("CourseWareName", courseWare?.CourseWareNo+courseWare?.CourseWareName+courseWare?.VersionNo+courseWareAttachment.AttachmentName), |
|
|
|
|
}; |
|
|
|
|
courseWareStudyDurations.Add(item); |
|
|
|
|
} |
|
|
|
|
data.CourseWareStudyDurations = courseWareStudyDurations; |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region 课件学习人数占比 |
|
|
|
|
var courseWareStudyCount1 = await Db.Queryable<Ghre_StudyRecordDetail>() |
|
|
|
|
.Where(a => a.StudyRecordId != null && studyRecordIds.Contains(a.StudyRecordId.Value)) |
|
|
|
|
.Select(a => new { a.CourseWareAttachmentId, a.StaffId }) |
|
|
|
|
.Distinct().ToListAsync(); |
|
|
|
|
var courseWareStudyCount = courseWareStudyCount1 |
|
|
|
|
.GroupBy(a => a.CourseWareAttachmentId) |
|
|
|
|
.Select(a => new |
|
|
|
|
{ |
|
|
|
|
CourseWareAttachmentId = a.Key, |
|
|
|
|
Count = a.Count() |
|
|
|
|
}) |
|
|
|
|
.ToList(); |
|
|
|
|
|
|
|
|
|
var courseWareStudyCounts = new JArray(); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < courseWareStudyCount.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var courseWareAttachment = await Db.Queryable<Ghre_CourseWareAttachment>().Where(x => x.Id == courseWareStudyCount[i].CourseWareAttachmentId).FirstAsync(); |
|
|
|
|
var item = new JObject |
|
|
|
|
{ |
|
|
|
|
new JProperty("CourseWareAttachmentId", courseWareStudyCount[i].CourseWareAttachmentId), |
|
|
|
|
new JProperty("CourseWareName", courseWareAttachment.AttachmentName), |
|
|
|
|
new JProperty("Count", courseWareStudyCount[i].Count), |
|
|
|
|
}; |
|
|
|
|
courseWareStudyCounts.Add(item); |
|
|
|
|
} |
|
|
|
|
data.CourseWareStudyCounts = courseWareStudyCounts; |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
#region 关联的考试排行 |
|
|
|
|
var exams = await Db.Queryable<Ghre_Exam>() |
|
|
|
|
.LeftJoin<Ghre_ExamPaper>((a, b) => a.ExamPaperId == b.Id)//多个条件用&& |
|
|
|
|
.Where(a => a.CourseId == id && a.Status != "Draft") |
|
|
|
|
.Select((a, b) => new |
|
|
|
|
{ |
|
|
|
|
a.Id, |
|
|
|
|
a.ExamNo, |
|
|
|
|
a.ExamName, |
|
|
|
|
b.PaperName |
|
|
|
|
}) |
|
|
|
|
.ToListAsync(); |
|
|
|
|
var examRanking = new JArray(); |
|
|
|
|
var examRankings = new JArray(); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < exams.Count; i++) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
var groups = await Db.Queryable<Ghre_ExamRecordGroup>().Where(x => x.ExamId == exams[i].Id).CountAsync(); |
|
|
|
|
var examRecordCount = await Db.Queryable<Ghre_ExamRecord>().Where(x => x.ExamId == exams[i].Id).CountAsync(); |
|
|
|
|
var examRecordPassCount = await Db.Queryable<Ghre_ExamRecord>() |
|
|
|
|
.Where(x => x.ExamId == exams[i].Id && x.IsPass == true && x.IsPass != null) |
|
|
|
|
.CountAsync(); |
|
|
|
|
var examRecordRetakeCount = await Db.Queryable<Ghre_ExamRecord>() |
|
|
|
|
.Where(x => x.ExamId == exams[i].Id && x.RetakeTimes > 0 && x.RetakeTimes != null) |
|
|
|
|
.CountAsync(); |
|
|
|
|
|
|
|
|
|
passPercent = 0; |
|
|
|
|
var retakePercent = 0; |
|
|
|
|
|
|
|
|
|
if (examRecordCount > 0) |
|
|
|
|
{ |
|
|
|
|
if (examRecordPassCount > 0) passPercent = (examRecordPassCount / examRecordCount) * 100; |
|
|
|
|
if (examRecordRetakeCount > 0) retakePercent = (examRecordRetakeCount / examRecordCount) * 100; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var item = new JObject |
|
|
|
|
{ |
|
|
|
|
new JProperty("ExamName", $"{exams[i].ExamName}({exams[i].ExamNo})" ), |
|
|
|
|
new JProperty("PaperName", exams[i].PaperName), |
|
|
|
|
new JProperty("Attempts", groups), |
|
|
|
|
new JProperty("PassPercent", passPercent), |
|
|
|
|
new JProperty("RetakePercent", retakePercent), |
|
|
|
|
//new JProperty("CourseWareName", courseWareAttachment.AttachmentName), |
|
|
|
|
}; |
|
|
|
|
examRankings.Add(item); |
|
|
|
|
} |
|
|
|
|
data.ExamRankings = examRankings; |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
obj.Data = data; |
|
|
|
|
obj.Success = true; |
|
|
|
|
obj.Status = 200; |
|
|
|
|
obj.Message = "查询成功!"; |
|
|
|
|
return obj; |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
} |