课程统计分析接口开发

master
xiaochanghai 2 months ago
parent 6f83038d7f
commit eb3aa46576
  1. 2313
      Model/Tiobon.Web.pdm
  2. 11
      Tiobon.Core.Api/Controllers/Ghre/Ghre_CourseController.cs
  3. 7
      Tiobon.Core.Api/Tiobon.Core.xml
  4. 2
      Tiobon.Core.Api/appsettings.json
  5. 2
      Tiobon.Core.IServices/Ghre/IGhre_CourseServices.cs
  6. 193
      Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs

File diff suppressed because it is too large Load Diff

@ -92,4 +92,15 @@ public class Ghre_CourseController : BaseController<IGhre_CourseServices, Ghre_C
{ {
return await _service.ModifyCourseSortNo(courses); return await _service.ModifyCourseSortNo(courses);
} }
/// <summary>
/// 统计
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[Route("QueryStatistic/{id}")]
public async Task<dynamic> QueryStatistic(long id)
{
return await _service.QueryStatistic(id);
}
} }

@ -796,6 +796,13 @@
<param name="KeyWords"></param> <param name="KeyWords"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Tiobon.Core.Api.Controllers.Ghre_CourseController.QueryStatistic(System.Int64)">
<summary>
统计
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="T:Tiobon.Core.Api.Controllers.Ghre_CourseSceneController"> <member name="T:Tiobon.Core.Api.Controllers.Ghre_CourseSceneController">
<summary> <summary>
课程场景(Controller) 课程场景(Controller)

@ -269,7 +269,7 @@
"Enabled": false "Enabled": false
}, },
"QuartzNetJob": { "QuartzNetJob": {
"Enabled": true "Enabled": false
}, },
"Consul": { "Consul": {
"Enabled": false "Enabled": false

@ -26,4 +26,6 @@ public interface IGhre_CourseServices : IBaseServices<Ghre_Course, Ghre_CourseDt
Task<ServiceResult<List<Ghre_CourseDto>>> QueryBySceneId(long courseSceneId); Task<ServiceResult<List<Ghre_CourseDto>>> QueryBySceneId(long courseSceneId);
Task<ServiceResult> ModifyCourseSortNo(List<Ghre_Course> courses); Task<ServiceResult> ModifyCourseSortNo(List<Ghre_Course> courses);
Task<dynamic> QueryStatistic(long id);
} }

@ -1,4 +1,5 @@
using NPOI.SS.UserModel; using NPOI.SS.UserModel;
using Tiobon.Core.IServices;
using static Tiobon.Core.Model.Consts; using static Tiobon.Core.Model.Consts;
namespace Tiobon.Core.Services; 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) public override async Task<Ghre_CourseDto> QueryById(object objId)
{ {
var data = await base.QueryById(objId); var data = await base.QueryById(objId);
if (data == null)
throw new Exception("无效的Id");
var DT_TableDataT1 = Mapper.Map(data).ToANew<Ghre_CourseDto>(); var DT_TableDataT1 = Mapper.Map(data).ToANew<Ghre_CourseDto>();
string examPaperId = DT_TableDataT1.ExamPaperId; string examPaperId = DT_TableDataT1.ExamPaperId;
@ -1309,4 +1313,193 @@ public class Ghre_CourseServices : BaseServices<Ghre_Course, Ghre_CourseDto, Ins
return ServiceResult.OprateSuccess("执行成功!"); return ServiceResult.OprateSuccess("执行成功!");
} }
#endregion #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
} }
Loading…
Cancel
Save