优化开班查询接口

master
xiaochanghai 1 month ago
parent 55e525c4ac
commit bac0086716
  1. 8
      Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs
  2. 183
      Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs

@ -1506,7 +1506,9 @@ public class Ghre_CourseServices : BaseServices<Ghre_Course, Ghre_CourseDto, Ins
//完成人数 //完成人数
data.CompleteCount = CompleteCount; data.CompleteCount = CompleteCount;
//开班人数 //开班人数
var OpenClassCount = await Db.Queryable<Ghre_StudyRecord>().Where(x => x.CourseId == id && x.OpenClassId != null).CountAsync(); var OpenClassCount = await Db.Queryable<Ghre_StudyRecord>()
.Where(x => x.CourseId == id && x.OpenClassId != null)
.CountAsync();
data.OpenClassCount = OpenClassCount; data.OpenClassCount = OpenClassCount;
var studyRecordIds = await Db.Queryable<Ghre_StudyRecord>().Where(x => x.CourseId == id).Select(x => x.Id).ToListAsync(); var studyRecordIds = await Db.Queryable<Ghre_StudyRecord>().Where(x => x.CourseId == id).Select(x => x.Id).ToListAsync();
@ -1742,7 +1744,9 @@ public class Ghre_CourseServices : BaseServices<Ghre_Course, Ghre_CourseDto, Ins
//完成人数 //完成人数
data.CompleteCount = CompleteCount; data.CompleteCount = CompleteCount;
//开班人数 //开班人数
var OpenClassCount = await Db.Queryable<Ghre_StudyRecord>().Where(x => x.CourseSceneId == id && x.OpenClassId != null).CountAsync(); var OpenClassCount = await Db.Queryable<Ghre_StudyRecord>()
.Where(x => x.CourseSceneId == id && x.OpenClassId != null)
.CountAsync();
data.OpenClassCount = OpenClassCount; data.OpenClassCount = OpenClassCount;
var studyRecordIds = await Db.Queryable<Ghre_StudyRecord>().Where(x => x.CourseSceneId == id).Select(x => x.Id).ToListAsync(); var studyRecordIds = await Db.Queryable<Ghre_StudyRecord>().Where(x => x.CourseSceneId == id).Select(x => x.Id).ToListAsync();

@ -1169,9 +1169,9 @@ FROM Ghre_OpenClass A
LEFT JOIN Ghre_Course C ON A.LinkId = C.Id LEFT JOIN Ghre_Course C ON A.LinkId = C.Id
LEFT JOIN Ghre_CourseScene D ON A.LinkId = D.Id LEFT JOIN Ghre_CourseScene D ON A.LinkId = D.Id
LEFT JOIN Ghre_ExamRecord E ON A.Id = E.OpenClassId AND E.StaffId = '{staffId}' LEFT JOIN Ghre_ExamRecord E ON A.Id = E.OpenClassId AND E.StaffId = '{staffId}'
LEFT JOIN Ghre_StudyRecord F ON A.Id = F.OpenClassId And F.IsEnable=1 LEFT JOIN Ghre_StudyRecord F ON A.Id = F.OpenClassId And F.IsEnable=1 AND F.StaffId = '{staffId}'
LEFT JOIN Ghre_OpenClassFeedback G ON A.Id = G.OpenClassId AND G.Source = 'Trainee' AND G.StaffId = '9' LEFT JOIN Ghre_OpenClassFeedback G ON A.Id = G.OpenClassId AND G.Source = 'Trainee' AND G.StaffId = '{staffId}'
WHERE A.Status !='Temporary' AND A.IsEnable=1 AND ( EXISTS WHERE A.Status !='Temporary' AND A.Status !='Close' AND A.IsEnable=1 AND ( EXISTS
(SELECT 1 (SELECT 1
FROM Ghre_OpenClassStaff C FROM Ghre_OpenClassStaff C
WHERE C.OpenClassId = A.ID AND c.StaffId = '{staffId}') WHERE C.OpenClassId = A.ID AND c.StaffId = '{staffId}')
@ -1311,75 +1311,108 @@ WHERE A.Status !='Temporary' AND A.IsEnable=1 AND ( EXISTS
x.ShowStudyBtn = true; x.ShowStudyBtn = true;
x.ShowExamBtn = true; x.ShowExamBtn = true;
} }
if (openClassStaffs.Any(o => o.OpenClassId == x.Id))
{
if (dt >= x.CourseBeginDate && dt <= x.CourseEndDate && (x.OpenClassStatus == "Publish" || x.OpenClassStatus == "Opening") && openClassStaffs.Any(o => o.OpenClassId == x.Id))
x.DisableStudyBtn = false;
if (dt >= x.CourseBeginDate && dt <= x.CourseEndDate && (x.OpenClassStatus == "Publish" || x.OpenClassStatus == "Opening") && openClassStaffs.Any(o => o.OpenClassId == x.Id)) if (x.CourseBeginDate != null && x.CourseEndDate != null)
x.DisableStudyBtn = false; x.CourseDateString = DateTimeHelper.ConvertToDayString(x.CourseBeginDate) + "~" + DateTimeHelper.ConvertToDayString(x.CourseEndDate);
if (x.CourseBeginDate != null && x.CourseEndDate != null)
x.CourseDateString = DateTimeHelper.ConvertToDayString(x.CourseBeginDate) + "~" + DateTimeHelper.ConvertToDayString(x.CourseEndDate);
if (x.IsRequireStudy == false) if (x.IsRequireStudy == false)
x.ShowStudyBtn = false; x.ShowStudyBtn = false;
if (dt >= x.CourseBeginDate && dt <= x.CourseEndDate) if (dt >= x.CourseBeginDate && dt <= x.CourseEndDate)
x.DisableStudyBtn = false; x.DisableStudyBtn = false;
else else
x.DisableStudyBtn = true; x.DisableStudyBtn = true;
if (!x.ExamId.IsNull()) if (!x.ExamId.IsNull())
{ {
if (x.ExamBeginDate != null && x.ExamEndDate != null) if (x.ExamBeginDate != null && x.ExamEndDate != null)
x.ExamDateString = DateTimeHelper.ConvertToDayString(x.ExamBeginDate) + "~" + DateTimeHelper.ConvertToDayString(x.ExamEndDate); x.ExamDateString = DateTimeHelper.ConvertToDayString(x.ExamBeginDate) + "~" + DateTimeHelper.ConvertToDayString(x.ExamEndDate);
else x.ExamDateString = $"学完{x.AfterHowLong}天"; else x.ExamDateString = $"学完{x.AfterHowLong}天";
} }
//if (x.CourseBeginDate != null && x.CourseEndDate != null) //if (x.CourseBeginDate != null && x.CourseEndDate != null)
// if (x.StudyProgress >= 100 || !(x.CourseBeginDate.Value.Date <= DateTime.Now.Date && x.CourseEndDate.Value.Date >= DateTime.Now.Date)) // if (x.StudyProgress >= 100 || !(x.CourseBeginDate.Value.Date <= DateTime.Now.Date && x.CourseEndDate.Value.Date >= DateTime.Now.Date))
// x.DisableStudyBtn = true; // x.DisableStudyBtn = true;
if (!x.ExamId.IsNull() && x.ExamBeginDate != null && x.ExamEndDate != null && x.ExamBeginDate <= dt && x.ExamEndDate >= dt) if (!x.ExamId.IsNull() && x.ExamBeginDate != null && x.ExamEndDate != null && x.ExamBeginDate <= dt && x.ExamEndDate >= dt)
x.DisableExamBtn = false; x.DisableExamBtn = false;
if (x.StudyProgress >= 100 && x.ExamId.IsNotEmptyOrNull() && x.IsRequireStudy != false) if (x.StudyProgress >= 100 && x.ExamId.IsNotEmptyOrNull() && x.IsRequireStudy != false)
x.DisableExamBtn = false; x.DisableExamBtn = false;
if (x.FeedbackOrderId.IsNotEmptyOrNull()) if (x.FeedbackOrderId.IsNotEmptyOrNull() && x.OpenClassStatus == "Opening")
x.DisableFeedbackBtn = false; {
if (x.ShowFeedbackBtn == true && x.StudyProgress < 100) if (x.ShowFeedbackBtn == true && x.StudyProgress >= 100)
{ x.DisableFeedbackBtn = false;
x.DisableFeedbackBtn = true; }
} else
x.ShowFeedbackBtn = false;
#region 处理学习进度 #region 处理学习进度
if (x.ExamId.IsNull()) if (x.ExamId.IsNull())
x.ShowExamBtn = false; x.ShowExamBtn = false;
if (!x.ExamId.IsNull() && x.FeedbackOrderId.IsNull()) //if (!x.ExamId.IsNull() && x.FeedbackOrderId.IsNull())
{ //{
if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.WAIT || x.ExamStatus.IsNull()) // if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.WAIT || x.ExamStatus.IsNull())
x.StudyProgress = x.StudyProgress / 2; // x.StudyProgress = x.StudyProgress / 2;
else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAMING) // else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAMING)
x.StudyProgress = 75; // x.StudyProgress = 75;
else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAM_END) // else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAM_END)
x.StudyProgress = 100; // x.StudyProgress = 100;
//}
//if (!x.ExamId.IsNull() && !x.FeedbackOrderId.IsNull())
//{
// if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.WAIT)
// x.StudyProgress = x.StudyProgress / 3;
// else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAMING)
// x.StudyProgress = 45;
// else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAM_END)
// x.StudyProgress = 60;
//}
//if (x.OpenClassFeedbackStatus.IsNotEmptyOrNull())
// if (x.OpenClassFeedbackStatus == "N")
// x.StudyProgress = 83;
// else x.StudyProgress = 100;
if (x.IsRequireStudy == true)
{
if (x.ShowStudyBtn == true && x.ShowExamBtn == true && x.ShowFeedbackBtn == false)
{
if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.WAIT || x.ExamStatus.IsNull())
x.StudyProgress = x.StudyProgress / 2;
else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAMING)
x.StudyProgress = 75;
else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAM_END)
x.StudyProgress = 100;
}
else if (x.ShowStudyBtn == true && x.ShowExamBtn == true && x.ShowFeedbackBtn == true)
{
if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.WAIT || x.ExamStatus.IsNull())
x.StudyProgress = x.StudyProgress / 3;
else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAMING)
x.StudyProgress = 50;
else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAM_END)
x.StudyProgress = 75;
if (x.OpenClassFeedbackStatus == "Y")
x.StudyProgress = 100;
}
}
#endregion
} }
else
if (!x.ExamId.IsNull() && !x.FeedbackOrderId.IsNull())
{ {
if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.WAIT) x.ShowExamBtn = false;
x.StudyProgress = x.StudyProgress / 3; x.ShowFeedbackBtn = false;
else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAMING) x.ShowStudyBtn = false;
x.StudyProgress = 45;
else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAM_END)
x.StudyProgress = 60;
} }
if (x.OpenClassFeedbackStatus.IsNotEmptyOrNull())
if (x.OpenClassFeedbackStatus == "N")
x.StudyProgress = 83;
else x.StudyProgress = 100;
#endregion
}); });
return new ServicePageResult<Ghre_StudyRecordESS>(filter.pageNum, total, filter.pageSize, entitys); return new ServicePageResult<Ghre_StudyRecordESS>(filter.pageNum, total, filter.pageSize, entitys);
@ -1423,7 +1456,9 @@ WHERE A.Status !='Temporary' AND A.IsEnable=1 AND ( EXISTS
id = await base.Add(studyRecord); id = await base.Add(studyRecord);
} }
else else
id = await Db.Queryable<Ghre_StudyRecord>().Where(x => x.OpenClassId == id || x.Id == id).Select(x => x.Id).FirstAsync(); id = await Db.Queryable<Ghre_StudyRecord>()
.Where(x => (x.OpenClassId == id || x.Id == id) && x.StaffId == App.User.StaffId)
.Select(x => x.Id).FirstAsync();
#endregion #endregion
string sql = @$"SELECT A.Id, string sql = @$"SELECT A.Id,
@ -1770,23 +1805,23 @@ WHERE A.Id = '{id}'";
//var sql = $"UPDATE Ghre_StudyRecord SET StudyDuration = ISNULL(StudyDuration, 0)+{duration} WHERE Id='{studyRecordId}' AND StaffId='{staffId}'"; //var sql = $"UPDATE Ghre_StudyRecord SET StudyDuration = ISNULL(StudyDuration, 0)+{duration} WHERE Id='{studyRecordId}' AND StaffId='{staffId}'";
//await Db.Ado.ExecuteCommandAsync(sql); //await Db.Ado.ExecuteCommandAsync(sql);
var standDuration = await Db.Queryable<Ghre_CourseWareAttachment>() //var standDuration = await Db.Queryable<Ghre_CourseWareAttachment>()
.Where(x => x.Id == attachmentId) // .Where(x => x.Id == attachmentId)
.Select(x => x.LearnDuration) // .Select(x => x.LearnDuration)
.FirstAsync() ?? 1000000000; // .FirstAsync() ?? 1000000000;
var studyDuration = await Db.Queryable<Ghre_StudyRecordDetail>()
.Where(x => x.StudyRecordId == studyRecordId && x.CourseWareAttachmentId == attachmentId)
.SumAsync(it => it.StudyDuration);
if (standDuration < (studyDuration + duration)) //var studyDuration = await Db.Queryable<Ghre_StudyRecordDetail>()
duration = standDuration - studyDuration; // .Where(x => x.StudyRecordId == studyRecordId && x.CourseWareAttachmentId == attachmentId)
// .SumAsync(it => it.StudyDuration);
//decimal? duration1 = 0;
//if (standDuration < (studyDuration + duration))
// duration1 = standDuration - studyDuration;
if (duration > 0) //if (duration1 > 0)
await Db.Updateable<Ghre_StudyRecord>() await Db.Updateable<Ghre_StudyRecord>()
.SetColumns(it => new Ghre_StudyRecord() { StudyDuration = (it.StudyDuration ?? 0) + duration }, true) .SetColumns(it => new Ghre_StudyRecord() { StudyDuration = (it.StudyDuration ?? 0) + duration }, true)
.Where(it => it.Id == studyRecordId && it.StaffId == App.User.StaffId) .Where(it => it.Id == studyRecordId && it.StaffId == App.User.StaffId)
.ExecuteCommandAsync(); .ExecuteCommandAsync();
await GenerateStaffStudyRecord(Db, studyRecordId, duration.Value, attachmentId); await GenerateStaffStudyRecord(Db, studyRecordId, duration.Value, attachmentId);

Loading…
Cancel
Save