优化开班查询接口

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;
//开班人数
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;
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;
//开班人数
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;
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_CourseScene D ON A.LinkId = D.Id
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_OpenClassFeedback G ON A.Id = G.OpenClassId AND G.Source = 'Trainee' AND G.StaffId = '9'
WHERE A.Status !='Temporary' AND A.IsEnable=1 AND ( EXISTS
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 = '{staffId}'
WHERE A.Status !='Temporary' AND A.Status !='Close' AND A.IsEnable=1 AND ( EXISTS
(SELECT 1
FROM Ghre_OpenClassStaff C
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.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))
x.DisableStudyBtn = false;
if (x.CourseBeginDate != null && x.CourseEndDate != null)
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)
x.ShowStudyBtn = false;
if (x.IsRequireStudy == false)
x.ShowStudyBtn = false;
if (dt >= x.CourseBeginDate && dt <= x.CourseEndDate)
x.DisableStudyBtn = false;
else
x.DisableStudyBtn = true;
if (dt >= x.CourseBeginDate && dt <= x.CourseEndDate)
x.DisableStudyBtn = false;
else
x.DisableStudyBtn = true;
if (!x.ExamId.IsNull())
{
if (x.ExamBeginDate != null && x.ExamEndDate != null)
x.ExamDateString = DateTimeHelper.ConvertToDayString(x.ExamBeginDate) + "~" + DateTimeHelper.ConvertToDayString(x.ExamEndDate);
else x.ExamDateString = $"学完{x.AfterHowLong}天";
}
if (!x.ExamId.IsNull())
{
if (x.ExamBeginDate != null && x.ExamEndDate != null)
x.ExamDateString = DateTimeHelper.ConvertToDayString(x.ExamBeginDate) + "~" + DateTimeHelper.ConvertToDayString(x.ExamEndDate);
else x.ExamDateString = $"学完{x.AfterHowLong}天";
}
//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))
// x.DisableStudyBtn = true;
if (!x.ExamId.IsNull() && x.ExamBeginDate != null && x.ExamEndDate != null && x.ExamBeginDate <= dt && x.ExamEndDate >= dt)
x.DisableExamBtn = false;
//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))
// x.DisableStudyBtn = true;
if (!x.ExamId.IsNull() && x.ExamBeginDate != null && x.ExamEndDate != null && x.ExamBeginDate <= dt && x.ExamEndDate >= dt)
x.DisableExamBtn = false;
if (x.StudyProgress >= 100 && x.ExamId.IsNotEmptyOrNull() && x.IsRequireStudy != false)
x.DisableExamBtn = false;
if (x.StudyProgress >= 100 && x.ExamId.IsNotEmptyOrNull() && x.IsRequireStudy != false)
x.DisableExamBtn = false;
if (x.FeedbackOrderId.IsNotEmptyOrNull())
x.DisableFeedbackBtn = false;
if (x.FeedbackOrderId.IsNotEmptyOrNull() && x.OpenClassStatus == "Opening")
{
if (x.ShowFeedbackBtn == true && x.StudyProgress < 100)
{
x.DisableFeedbackBtn = true;
}
if (x.ShowFeedbackBtn == true && x.StudyProgress >= 100)
x.DisableFeedbackBtn = false;
}
else
x.ShowFeedbackBtn = false;
#region 处理学习进度
#region 处理学习进度
if (x.ExamId.IsNull())
x.ShowExamBtn = false;
if (x.ExamId.IsNull())
x.ShowExamBtn = false;
if (!x.ExamId.IsNull() && x.FeedbackOrderId.IsNull())
{
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;
//if (!x.ExamId.IsNull() && x.FeedbackOrderId.IsNull())
//{
// 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;
//}
//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
}
if (!x.ExamId.IsNull() && !x.FeedbackOrderId.IsNull())
else
{
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;
x.ShowExamBtn = false;
x.ShowFeedbackBtn = false;
x.ShowStudyBtn = false;
}
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);
@ -1423,7 +1456,9 @@ WHERE A.Status !='Temporary' AND A.IsEnable=1 AND ( EXISTS
id = await base.Add(studyRecord);
}
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
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}'";
//await Db.Ado.ExecuteCommandAsync(sql);
var standDuration = await Db.Queryable<Ghre_CourseWareAttachment>()
.Where(x => x.Id == attachmentId)
.Select(x => x.LearnDuration)
.FirstAsync() ?? 1000000000;
var studyDuration = await Db.Queryable<Ghre_StudyRecordDetail>()
.Where(x => x.StudyRecordId == studyRecordId && x.CourseWareAttachmentId == attachmentId)
.SumAsync(it => it.StudyDuration);
//var standDuration = await Db.Queryable<Ghre_CourseWareAttachment>()
// .Where(x => x.Id == attachmentId)
// .Select(x => x.LearnDuration)
// .FirstAsync() ?? 1000000000;
if (standDuration < (studyDuration + duration))
duration = standDuration - studyDuration;
//var studyDuration = await Db.Queryable<Ghre_StudyRecordDetail>()
// .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)
await Db.Updateable<Ghre_StudyRecord>()
.SetColumns(it => new Ghre_StudyRecord() { StudyDuration = (it.StudyDuration ?? 0) + duration }, true)
.Where(it => it.Id == studyRecordId && it.StaffId == App.User.StaffId)
.ExecuteCommandAsync();
//if (duration1 > 0)
await Db.Updateable<Ghre_StudyRecord>()
.SetColumns(it => new Ghre_StudyRecord() { StudyDuration = (it.StudyDuration ?? 0) + duration }, true)
.Where(it => it.Id == studyRecordId && it.StaffId == App.User.StaffId)
.ExecuteCommandAsync();
await GenerateStaffStudyRecord(Db, studyRecordId, duration.Value, attachmentId);

Loading…
Cancel
Save