优化考试与学习记录绑定关系

master
xiaochanghai 11 months ago
parent 9027af834e
commit 024e2bd51f
  1. 13
      Tiobon.Core.Api/Tiobon.Core.Model.xml
  2. 36
      Tiobon.Core.Common/Helper/UtilHelper.cs
  3. 15
      Tiobon.Core.Model/Consts.cs
  4. 58
      Tiobon.Core.Services/Ghre/Ghre_ExamRecordServices.cs
  5. 8
      Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs

@ -12612,14 +12612,19 @@
已归档
</summary>
</member>
<member name="F:Tiobon.Core.Model.Consts.DIC_EXAM_DATE_TYPE_EXAM_DATE">
<member name="T:Tiobon.Core.Model.Consts.DicExamDateType">
<summary>
考试管理-日期类型-考试区间
考试管理-日期类型
</summary>
</member>
<member name="F:Tiobon.Core.Model.Consts.DIC_EXAM_DATE_TYPE_AFTERHOWLONG">
<member name="F:Tiobon.Core.Model.Consts.DicExamDateType.EXAM_DATE">
<summary>
考试管理-日期类型-学完多久
时间区间
</summary>
</member>
<member name="F:Tiobon.Core.Model.Consts.DicExamDateType.AFTER_HOW_LONG">
<summary>
学完多久
</summary>
</member>
<member name="F:Tiobon.Core.Model.Consts.DIC_EXAM_LINK_TYPE_COURSE">

@ -1,14 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json;
namespace Tiobon.Core
{
/// <summary>
///
/// </summary>
public static class UtilConvert
public static class UtilHelper
{
/// <summary>
///
@ -247,7 +244,7 @@ namespace Tiobon.Core
{
Type innerType = type.GetGenericArguments()[0];
object innerValue = ChangeType(value, innerType);
return Activator.CreateInstance(type, new object[] {innerValue});
return Activator.CreateInstance(type, new object[] { innerValue });
}
if (value is string && type == typeof(Guid)) return new Guid(value as string);
@ -290,7 +287,7 @@ namespace Tiobon.Core
.Remove(split.Length - 2, 1);
}
addMethod.Invoke(lis, new object[] {ChangeType(str, type)});
addMethod.Invoke(lis, new object[] { ChangeType(str, type) });
}
}
@ -308,5 +305,30 @@ namespace Tiobon.Core
return source.Any() && source.All(s => s != null);
}
public static bool IsNull(this long? thisValue)
{
return thisValue is null;
}
public static bool IsNull(this int? thisValue)
{
return thisValue is null;
}
public static bool IsNull(this decimal? thisValue)
{
return thisValue is null;
}
public static bool IsNull(this string thisValue)
{
return string.IsNullOrWhiteSpace(thisValue);
}
public static bool IsNull(this DateTime? thisValue)
{
return thisValue is null;
}
public static bool IsNull<T>(this T entity) where T : class
{
return entity == null;
}
}
}

@ -30,13 +30,19 @@ public class Consts
#region 考试管理-日期类型
/// <summary>
/// 考试管理-日期类型-考试区间
/// 考试管理-日期类型
/// </summary>
public const string DIC_EXAM_DATE_TYPE_EXAM_DATE = "ExamDate";
public static class DicExamDateType
{
/// <summary>
/// 时间区间
/// </summary>
public const string EXAM_DATE = "ExamDate";
/// <summary>
/// 考试管理-日期类型-学完多久
/// 学完多久
/// </summary>
public const string DIC_EXAM_DATE_TYPE_AFTERHOWLONG = "AfterHowLong";
public const string AFTER_HOW_LONG = "AfterHowLong";
}
#endregion
#region 考试管理-关联类型
@ -82,4 +88,5 @@ public class Consts
public const string DIC_STUDY_RECORD_STUDY_STATUS_HAS_FINISH = "HasFinish";
#endregion
}

@ -375,50 +375,27 @@ public class Ghre_ExamRecordServices : BaseServices<Ghre_ExamRecord, Ghre_ExamRe
{
var examRecord = await Db.Queryable<Ghre_ExamRecord>().FirstAsync(x => x.StudyRecordId == id);
if (examRecord != null)
if (!examRecord.IsNull())
examRecordId = examRecord.Id;
else
{
var studyRecord = await Db.Queryable<Ghre_StudyRecord>().FirstAsync(x => x.Id == id);
//string sql = @$"SELECT A.StaffId,
// A.Source,
// A.ExamId,
// B.Id,
// B.LinkType,
// B.CourseId,
// B.CourseSceneId,
// B.ExamPaperId,
// B.CoverUrl,
// B.ExamNo,
// B.ExamName,
// B.DateType,
// B.BeginTime,
// B.EndTime,
// B.AfterHowLong,
// B.ExamMode,
// B.ExamPlace,
// B.IsLinkOpenClass,
// B.OpenClassId,
// B.Status
// FROM Ghre_ExamStaff A
// JOIN Ghre_Exam B
// ON A.ExamId = B.Id
// AND B.Status = 'Released'
// AND A.IsEnable = B.IsEnable
// AND B.CourseId = '{studyRecord.CourseId}'
// WHERE A.IsEnable = 1
// AND ( B.DateType = 'AfterHowLong'
// OR ( B.DateType = 'ExamDate'
// AND B.BeginTime >= GETDATE ()
// AND B.EndTime <= GETDATE ()))
// AND A.StaffId = {studyRecord.StaffId}";
var exam = await Db.Queryable<Ghre_Exam>()
.Where(x => x.Id == studyRecord.ExamId)
.FirstAsync(x => x.Status == Consts.DicExamStatus.RELEASED);
if (exam is null)
return ServiceResult<QueryExam>.OprateFailed("该门课程无需考试!");
if (exam.IsNull())
exam = await Db.Queryable<Ghre_Exam>()
.Where(x => x.Status == Consts.DicExamStatus.RELEASED
&& ((x.DateType == Consts.DicExamDateType.EXAM_DATE
&& x.BeginTime.Value.Date <= DateTime.Now.Date && x.EndTime.Value.Date >= DateTime.Now.Date) || x.DateType == Consts.DicExamDateType.AFTER_HOW_LONG))
.WhereIF(!studyRecord.CourseId.IsNull(), x => x.CourseId == studyRecord.CourseId)
.WhereIF(!studyRecord.CourseSceneId.IsNull(), x => x.CourseSceneId == studyRecord.CourseSceneId)
.FirstAsync();
if (exam.IsNull())
return ServiceResult<QueryExam>.OprateFailed("该门课程尚未开启考试,清联系HR !");
var insrt = new InsertGhre_ExamRecordInput()
{
@ -435,12 +412,17 @@ public class Ghre_ExamRecordServices : BaseServices<Ghre_ExamRecord, Ghre_ExamRe
EndTime = exam.EndTime
};
examRecordId = await base.Add(insrt);
if (studyRecord.ExamId.IsNull())
{
string sql = $@"UPDATE Ghre_StudyRecord SET ExamId={exam.Id} WHERE Id='{studyRecord.Id}'; ";
await Db.Ado.ExecuteCommandAsync(sql);
}
}
}
if (examRecordId == 0) examRecordId = id;
var records = await QueryFilterPage(body, $"Id='{examRecordId}'");
if (!records.result.DT_TableDataT1.Any())
@ -569,10 +551,10 @@ public class Ghre_ExamRecordServices : BaseServices<Ghre_ExamRecord, Ghre_ExamRe
//extend.RemainingSecond = Convert.ToInt32(timeDifference.TotalSeconds);
//if (extend.RemainingSecond < 0) extend.RemainingSecond = 0;
extend.RemainingSecond = 3600;
if (exampaper.AnswerTime != null)
if (!exampaper.AnswerTime.IsNull())
extend.RemainingSecond = exampaper.AnswerTime.Value * 60;
if (record.ActualEndTime != null)
if (!record.ActualEndTime.IsNull())
{
TimeSpan timeDifference = record.ActualEndTime.Value - record.ActualBeginTime.Value;

@ -1213,11 +1213,11 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
{
var exam = exams[i];
var course = await _ghre_CourseServices.QuerySingle(entity.CourseId);
if (exam.DateType != entity.DateType || exam.DateType == Consts.DIC_EXAM_DATE_TYPE_AFTERHOWLONG)
if (exam.DateType != entity.DateType || exam.DateType == Consts.DicExamDateType.AFTER_HOW_LONG)
{
return ServiceResult.OprateFailed($"课程【{course.CourseName}】已存在有效的考试管理数据【{exam.ExamName}({exam.ExamNo})】!");
}
else if (exam.DateType == Consts.DIC_EXAM_DATE_TYPE_EXAM_DATE)
else if (exam.DateType == Consts.DicExamDateType.EXAM_DATE)
{
if ((entity.BeginTime >= exam.BeginTime && entity.BeginTime <= exam.EndTime)
|| (entity.EndTime >= exam.BeginTime && entity.EndTime <= exam.EndTime)
@ -1237,11 +1237,11 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr
{
var exam = exams[i];
var course = await _ghre_CourseSceneServices.QuerySingle(entity.CourseSceneId);
if (exam.DateType != entity.DateType || exam.DateType == Consts.DIC_EXAM_DATE_TYPE_AFTERHOWLONG)
if (exam.DateType != entity.DateType || exam.DateType == Consts.DicExamDateType.AFTER_HOW_LONG)
{
return ServiceResult.OprateFailed($"课程场景【{course.CourseName}】已存在有效的考试管理数据【{exam.ExamName}({exam.ExamNo})】!");
}
else if (exam.DateType == Consts.DIC_EXAM_DATE_TYPE_EXAM_DATE)
else if (exam.DateType == Consts.DicExamDateType.EXAM_DATE)
{
if ((entity.BeginTime >= exam.BeginTime && entity.BeginTime <= exam.EndTime) || (entity.EndTime >= exam.BeginTime && entity.EndTime <= exam.EndTime))
return ServiceResult.OprateFailed($"课程场景【{course.CourseName}】已存在有效的考试管理数据【{exam.ExamName}({exam.ExamNo})】时间重叠!");

Loading…
Cancel
Save