|
|
|
@ -17,6 +17,7 @@ using MongoDB.Driver.Linq; |
|
|
|
|
using Tiobon.Core.Common.DB.Dapper; |
|
|
|
|
using Tiobon.Core.Common.Helper; |
|
|
|
|
using System.Data; |
|
|
|
|
using Snappier; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
|
|
|
|
|
@ -717,19 +718,19 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
{ |
|
|
|
|
x.ExamName = x.ExamName + "(" + x.ExamNo + ")"; |
|
|
|
|
|
|
|
|
|
if (x.Status == Consts.DicExamStatus.RELEASED || x.Status == Consts.DicExamStatus.DISABLED) |
|
|
|
|
if (x.Status == Consts.DIC_EXAM_STATUS.RELEASED || x.Status == Consts.DIC_EXAM_STATUS.DISABLED) |
|
|
|
|
{ |
|
|
|
|
x.canEdit = 0; |
|
|
|
|
x.canDelete = 0; |
|
|
|
|
} |
|
|
|
|
if (x.Status == Consts.DicExamStatus.DRAFT) |
|
|
|
|
if (x.Status == Consts.DIC_EXAM_STATUS.DRAFT) |
|
|
|
|
{ |
|
|
|
|
x.showLink = 0; |
|
|
|
|
x.showResult = 0; |
|
|
|
|
x.canClose = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (x.Status == Consts.DicExamStatus.DISABLED) |
|
|
|
|
if (x.Status == Consts.DIC_EXAM_STATUS.DISABLED) |
|
|
|
|
{ |
|
|
|
|
x.canClose = 0; |
|
|
|
|
x.canPreview = 0; |
|
|
|
@ -1042,17 +1043,17 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
//var list = await _ghra_StaffSceneServices.Query(x => Ids.Contains(x.StaffID)); |
|
|
|
|
|
|
|
|
|
var data = await Db.Ado.SqlQueryAsync<StaffTableData>(sql); |
|
|
|
|
//var data = list.Select(x => new StaffTableData() |
|
|
|
|
//{ |
|
|
|
|
// StaffID = x.StaffID, |
|
|
|
|
// StaffNo = x.StaffNo, |
|
|
|
|
// StaffName = x.StaffName, |
|
|
|
|
// Mail = x.Email |
|
|
|
|
//}).ToList(); |
|
|
|
|
return ServiceResult<List<StaffTableData>>.OprateSuccess("查询成功!", data); |
|
|
|
|
data.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
if (x.DataSource.IsNull()) |
|
|
|
|
{ |
|
|
|
|
x.DataSource = Consts.DIC_EXAM_STAFF_SOURCE.MANUAL_REQUIRED; |
|
|
|
|
x.DataSourceLabel = "手动必修"; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ServiceResult<List<StaffTableData>>.OprateSuccess("查询成功!", data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<ServiceResult<List<StaffTableData>>> QueryStaff1(long examId) |
|
|
|
|
{ |
|
|
|
@ -1076,9 +1077,12 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
var data = await Db.Ado.SqlQueryAsync<StaffTableData>(sql); |
|
|
|
|
data.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
if (x.DataSource == "ManualRequired") |
|
|
|
|
if (x.DataSource.IsNull()) |
|
|
|
|
x.DataSource = Consts.DIC_EXAM_STAFF_SOURCE.MANUAL_REQUIRED; |
|
|
|
|
|
|
|
|
|
if (x.DataSource == Consts.DIC_EXAM_STAFF_SOURCE.MANUAL_REQUIRED) |
|
|
|
|
x.DataSourceLabel = "手动必修"; |
|
|
|
|
else if (x.DataSource == "StudyRuleRequired") |
|
|
|
|
else if (x.DataSource == Consts.DIC_EXAM_STAFF_SOURCE.STUDY_RULE_REQUIRED) |
|
|
|
|
x.DataSourceLabel = "必修规则"; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -1104,17 +1108,17 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
if (id == 0) |
|
|
|
|
{ |
|
|
|
|
if (string.IsNullOrEmpty(pageData.Status)) |
|
|
|
|
pageData.Status = Consts.DicExamStatus.DRAFT; |
|
|
|
|
pageData.Status = Consts.DIC_EXAM_STATUS.DRAFT; |
|
|
|
|
var insert = Mapper.Map(pageData).ToANew<InsertGhre_ExamInput>(); |
|
|
|
|
id = await base.Add(insert); |
|
|
|
|
|
|
|
|
|
var insertStaffs = pageData.staffTableData |
|
|
|
|
.Where(x => x.DataSource == "Manual") |
|
|
|
|
.Where(x => x.DataSource == Consts.DIC_EXAM_STAFF_SOURCE.MANUAL_REQUIRED) |
|
|
|
|
.Select(x => new InsertGhre_ExamStaffInput() |
|
|
|
|
{ |
|
|
|
|
ExamId = id, |
|
|
|
|
StaffId = x.StaffID, |
|
|
|
|
Source = "Manual" |
|
|
|
|
Source = x.DataSource ?? Consts.DIC_EXAM_STAFF_SOURCE.MANUAL_REQUIRED |
|
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
|
|
await _ghre_ExamStaffServices.Add(insertStaffs); |
|
|
|
@ -1133,12 +1137,12 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
} |
|
|
|
|
var insert = Mapper.Map(pageData).ToANew<EditGhre_ExamInput>(); |
|
|
|
|
await base.Update(id, insert); |
|
|
|
|
await _ghre_ExamStaffServices.Delete(x => x.ExamId == id && x.Source == "Manual"); |
|
|
|
|
var insertStaffs = pageData.staffTableData.Where(x => x.DataSource == "Manual").Select(x => new InsertGhre_ExamStaffInput() |
|
|
|
|
await _ghre_ExamStaffServices.Delete(x => x.ExamId == id && (x.Source == Consts.DIC_EXAM_STAFF_SOURCE.MANUAL_REQUIRED || x.Source == null)); |
|
|
|
|
var insertStaffs = pageData.staffTableData.Where(x => x.DataSource == Consts.DIC_EXAM_STAFF_SOURCE.MANUAL_REQUIRED).Select(x => new InsertGhre_ExamStaffInput() |
|
|
|
|
{ |
|
|
|
|
ExamId = id, |
|
|
|
|
StaffId = x.StaffID, |
|
|
|
|
Source = "Manual" |
|
|
|
|
Source = x.DataSource ?? Consts.DIC_EXAM_STAFF_SOURCE.MANUAL_REQUIRED |
|
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
|
|
await _ghre_ExamStaffServices.Add(insertStaffs); |
|
|
|
@ -1150,7 +1154,7 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
public async Task<ServiceResult> UpdateStatus(long[] ids, string status) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
if (status == Consts.DicExamStatus.DRAFT) |
|
|
|
|
if (status == Consts.DIC_EXAM_STATUS.DRAFT) |
|
|
|
|
{ |
|
|
|
|
string sql = $@"SELECT A.RoleId, B.RoleNo, B.RoleName
|
|
|
|
|
FROM Ghrs_UserRole A LEFT JOIN Ghrs_Role B ON A.RoleId = B.RoleId |
|
|
|
@ -1163,7 +1167,7 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
return ServiceResult.OprateFailed("暂无取消发布权限!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (status != Consts.DicExamStatus.RELEASED && status != Consts.DicExamStatus.DISABLED && status != Consts.DicExamStatus.DRAFT) |
|
|
|
|
if (status != Consts.DIC_EXAM_STATUS.RELEASED && status != Consts.DIC_EXAM_STATUS.DISABLED && status != Consts.DIC_EXAM_STATUS.DRAFT) |
|
|
|
|
throw new Exception("无效的状态"); |
|
|
|
|
|
|
|
|
|
HttpRequest request = UserContext.Context.Request; |
|
|
|
@ -1182,10 +1186,10 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
ent.UpdateIP = ip; |
|
|
|
|
ent.UpdateProg = api; |
|
|
|
|
|
|
|
|
|
if (entity.Status == Consts.DicExamStatus.RELEASED && status == Consts.DicExamStatus.DRAFT && await _ghre_ExamRecordServices.AnyAsync(x => x.ExamId == id && x.Status == "UnderWay")) |
|
|
|
|
if (entity.Status == Consts.DIC_EXAM_STATUS.RELEASED && status == Consts.DIC_EXAM_STATUS.DRAFT && await _ghre_ExamRecordServices.AnyAsync(x => x.ExamId == id && x.Status == "UnderWay")) |
|
|
|
|
return ServiceResult.OprateFailed("已有学员参与考试,不可取消发布!"); |
|
|
|
|
|
|
|
|
|
if (entity.Status == Consts.DicExamStatus.DISABLED && status == Consts.DicExamStatus.RELEASED) |
|
|
|
|
if (entity.Status == Consts.DIC_EXAM_STATUS.DISABLED && status == Consts.DIC_EXAM_STATUS.RELEASED) |
|
|
|
|
{ |
|
|
|
|
if (entity.LinkType == "CourseId") |
|
|
|
|
{ |
|
|
|
@ -1193,30 +1197,29 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
if (course is null) |
|
|
|
|
return ServiceResult.OprateFailed("该考试关联的课程已被删除,暂不可取消归档!"); |
|
|
|
|
|
|
|
|
|
if (course.Status != Consts.DicExamStatus.RELEASED) |
|
|
|
|
return ServiceResult.OprateFailed($"该考试关联的课程【{course.CourseName}({course.CourseNo})】状态为【{(course.Status == Consts.DicExamStatus.DISABLED ? "已停用" : "草稿箱")}】,暂不可取消归档!"); |
|
|
|
|
if (course.Status != Consts.DIC_EXAM_STATUS.RELEASED) |
|
|
|
|
return ServiceResult.OprateFailed($"该考试关联的课程【{course.CourseName}({course.CourseNo})】状态为【{(course.Status == Consts.DIC_EXAM_STATUS.DISABLED ? "已停用" : "草稿箱")}】,暂不可取消归档!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var examPaper = await _ghre_ExamPaperServices.QueryById(entity.ExamPaperId); |
|
|
|
|
if (examPaper is null) |
|
|
|
|
return ServiceResult.OprateFailed("该考试关联的试卷已被删除,暂不可取消归档!"); |
|
|
|
|
if (examPaper.Status != Consts.DicExamStatus.RELEASED) |
|
|
|
|
return ServiceResult.OprateFailed($"该考试关联的试卷【{examPaper.PaperName}({examPaper.PaperNo})】状态为【{(examPaper.Status == Consts.DicExamStatus.DISABLED ? "已停用" : "草稿箱")}】,暂不可取消归档!"); |
|
|
|
|
if (examPaper.Status != Consts.DIC_EXAM_STATUS.RELEASED) |
|
|
|
|
return ServiceResult.OprateFailed($"该考试关联的试卷【{examPaper.PaperName}({examPaper.PaperNo})】状态为【{(examPaper.Status == Consts.DIC_EXAM_STATUS.DISABLED ? "已停用" : "草稿箱")}】,暂不可取消归档!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (entity.LinkType == Consts.DIC_EXAM_LINK_TYPE_COURSE) |
|
|
|
|
{ |
|
|
|
|
#region 校验同一个课程下 考试时间不允许重叠 |
|
|
|
|
var exams = await base.Query(x => x.Status == Consts.DicExamStatus.RELEASED && x.CourseId == entity.CourseId && x.Id != id); |
|
|
|
|
var exams = await base.Query(x => x.Status == Consts.DIC_EXAM_STATUS.RELEASED && x.CourseId == entity.CourseId && x.Id != id); |
|
|
|
|
if (exams.Any()) |
|
|
|
|
for (int i = 0; i < exams.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var exam = exams[i]; |
|
|
|
|
var course = await _ghre_CourseServices.QuerySingle(entity.CourseId); |
|
|
|
|
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.DicExamDateType.EXAM_DATE) |
|
|
|
|
{ |
|
|
|
|
if ((entity.BeginTime >= exam.BeginTime && entity.BeginTime <= exam.EndTime) |
|
|
|
@ -1231,19 +1234,21 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
#region 校验同一个课程场景下 考试时间不允许重叠 |
|
|
|
|
var exams = await base.Query(x => x.Status == Consts.DicExamStatus.RELEASED && x.CourseSceneId == entity.CourseSceneId && x.Id != id); |
|
|
|
|
var exams = await base.Query(x => x.Status == Consts.DIC_EXAM_STATUS.RELEASED && x.CourseSceneId == entity.CourseSceneId && x.Id != id); |
|
|
|
|
if (exams.Any()) |
|
|
|
|
for (int i = 0; i < exams.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var exam = exams[i]; |
|
|
|
|
var course = await _ghre_CourseSceneServices.QuerySingle(entity.CourseSceneId); |
|
|
|
|
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.DicExamDateType.EXAM_DATE) |
|
|
|
|
{ |
|
|
|
|
if ((entity.BeginTime >= exam.BeginTime && entity.BeginTime <= exam.EndTime) || (entity.EndTime >= exam.BeginTime && entity.EndTime <= exam.EndTime)) |
|
|
|
|
if ((entity.BeginTime >= exam.BeginTime && entity.BeginTime <= exam.EndTime) |
|
|
|
|
|| (entity.EndTime >= exam.BeginTime && entity.EndTime <= exam.EndTime) |
|
|
|
|
|| (exam.EndTime >= entity.BeginTime && exam.EndTime <= entity.EndTime) |
|
|
|
|
|| (exam.EndTime >= entity.BeginTime && exam.EndTime <= entity.EndTime)) |
|
|
|
|
return ServiceResult.OprateFailed($"课程场景【{course.CourseName}】已存在有效的考试管理数据【{exam.ExamName}({exam.ExamNo})】时间重叠!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -1251,10 +1256,11 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region 生成学习记录 |
|
|
|
|
if (status == Consts.DicExamStatus.RELEASED && entity.Status == Consts.DicExamStatus.DRAFT) |
|
|
|
|
if (status == Consts.DIC_EXAM_STATUS.RELEASED && entity.Status == Consts.DIC_EXAM_STATUS.DRAFT) |
|
|
|
|
{ |
|
|
|
|
var staffs = await _ghre_ExamStaffServices.Query(x => x.ExamId == id && x.Source == "Manual"); |
|
|
|
|
var staffs = await _ghre_ExamStaffServices.Query(x => x.ExamId == id && x.Source == Consts.DIC_EXAM_STAFF_SOURCE.MANUAL_REQUIRED); |
|
|
|
|
var inserts = new List<Ghre_StudyRecord>(); |
|
|
|
|
; |
|
|
|
|
var snap = await Db.Queryable<Ghre_CourseSnap>().FirstAsync(x => x.CourseId == entity.CourseId); |
|
|
|
|
DateTime courseTime = Db.GetDate(); |
|
|
|
|
for (int i = 0; i < staffs.Count; i++) |
|
|
|
@ -1269,20 +1275,28 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
CourseId = entity.CourseId, |
|
|
|
|
CourseSceneId = entity.CourseSceneId, |
|
|
|
|
JoinTime = courseTime, |
|
|
|
|
CourseBeginTime = courseTime, |
|
|
|
|
CourseEndTime = courseTime.AddMonths(3), |
|
|
|
|
CourseType = "ManualRequired", |
|
|
|
|
CourseBeginTime = courseTime.Date, |
|
|
|
|
CourseEndTime = courseTime.Date.AddMonths(snap?.ValidityPeriod ?? 1), |
|
|
|
|
CourseType = Consts.DIC_EXAM_STAFF_SOURCE.MANUAL_REQUIRED, |
|
|
|
|
CourseStatus = Consts.DIC_STUDY_RECORD_COURSE_STATUS_IN, |
|
|
|
|
StudyStatus = Consts.DIC_STUDY_RECORD_STUDY_STATUS_NO_JOIN |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
if (inserts.Any()) |
|
|
|
|
await Db.Insertable(inserts).ExecuteReturnSnowflakeIdListAsync(); |
|
|
|
|
|
|
|
|
|
#region 自动给学习记录匹配考试ID |
|
|
|
|
var studyRecords = await Db.Queryable<Ghre_StudyRecord>() |
|
|
|
|
.WhereIF(!entity.CourseId.IsNull(), x => x.CourseId == entity.CourseId) |
|
|
|
|
.WhereIF(!entity.CourseSceneId.IsNull(), x => x.CourseSceneId == entity.CourseSceneId) |
|
|
|
|
.Where(x => x.ExamId == null).ToListAsync(); |
|
|
|
|
studyRecords.ForEach(x => x.ExamId = entity.Id); |
|
|
|
|
await Db.Updateable(studyRecords).UpdateColumns(it => new { it.ExamId }).ExecuteCommandAsync(); |
|
|
|
|
#endregion |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (status == Consts.DicExamStatus.RELEASED || status == Consts.DicExamStatus.DISABLED || status == Consts.DicExamStatus.DRAFT) |
|
|
|
|
if (status == Consts.DIC_EXAM_STATUS.RELEASED || status == Consts.DIC_EXAM_STATUS.DISABLED || status == Consts.DIC_EXAM_STATUS.DRAFT) |
|
|
|
|
{ |
|
|
|
|
entity.Status = status; |
|
|
|
|
entities.Add(entity); |
|
|
|
@ -1290,9 +1304,9 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var result = await BaseDal.Update(entities); |
|
|
|
|
if (status == Consts.DicExamStatus.RELEASED) |
|
|
|
|
if (status == Consts.DIC_EXAM_STATUS.RELEASED) |
|
|
|
|
return ServiceResult.OprateSuccess("发布成功!"); |
|
|
|
|
else if (status == Consts.DicExamStatus.DRAFT) |
|
|
|
|
else if (status == Consts.DIC_EXAM_STATUS.DRAFT) |
|
|
|
|
return ServiceResult.OprateSuccess("取消发布成功!"); |
|
|
|
|
else |
|
|
|
|
return ServiceResult.OprateSuccess("停用成功!"); |
|
|
|
@ -1418,7 +1432,7 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
{ |
|
|
|
|
var exam = await base.QueryById(id); |
|
|
|
|
var staffs = await _ghre_ExamStaffServices.Query(x => x.ExamId == id); |
|
|
|
|
exam.Status = Consts.DicExamStatus.DRAFT; |
|
|
|
|
exam.Status = Consts.DIC_EXAM_STATUS.DRAFT; |
|
|
|
|
|
|
|
|
|
var insert = Mapper.Map(exam).ToANew<InsertGhre_ExamInput>(); |
|
|
|
|
|
|
|
|
|