@@ -196,6 +196,12 @@ namespace Learun.Application.Web.Areas.EducationalAdministration.Controllers | |||||
Exam_ExamPlanLessonData.ExamTimeEnd = etime[1]; | Exam_ExamPlanLessonData.ExamTimeEnd = etime[1]; | ||||
} | } | ||||
if ((Exam_ExamPlanLessonData.ClassNum == null || Exam_ExamPlanLessonData.ClassNum <= 0) || | |||||
(Exam_ExamPlanLessonData.SeatCount == null || Exam_ExamPlanLessonData.SeatCount <= 0)) | |||||
{ | |||||
exam_ExamPlanLessonIBLL.UpdateClassNumAndStuCount(Exam_ExamPlanLessonData.EPLId); | |||||
} | |||||
var jsonData = new | var jsonData = new | ||||
{ | { | ||||
Exam_ExamPlanLesson = Exam_ExamPlanLessonData, | Exam_ExamPlanLesson = Exam_ExamPlanLessonData, | ||||
@@ -364,9 +364,9 @@ where l.EPLId='{EPLId}' | |||||
} | } | ||||
//更新排考安排课程表实排班级数、实排人数 | |||||
//更新排考安排课程表实排班级数、实排人数和应排班级数、应排人数(如果没有点击【一键安排班级】,应排班级数、应排人数在安排考试页面切换课程时候更新) | |||||
string sql = $@"update l | string sql = $@"update l | ||||
set l.RealStuCount=t.RealStuCount,l.RealClassNum=t.RealClassNum | |||||
set l.RealStuCount=t.RealStuCount,l.RealClassNum=t.RealClassNum,ClassNum=t.RealClassNum,StuCount=t.RealStuCount | |||||
from Exam_ExamPlanLesson l | from Exam_ExamPlanLesson l | ||||
join (select '{lesson.EPLId}' as EPLId,count(1) as RealClassNum,sum(ClassStuNum) as RealStuCount from Exam_ExamPlanClass where EPLId='{lesson.EPLId}' | join (select '{lesson.EPLId}' as EPLId,count(1) as RealClassNum,sum(ClassStuNum) as RealStuCount from Exam_ExamPlanClass where EPLId='{lesson.EPLId}' | ||||
)t on l.EPLId=t.EPLId | )t on l.EPLId=t.EPLId | ||||
@@ -216,6 +216,26 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration | |||||
} | } | ||||
} | } | ||||
} | } | ||||
public void UpdateClassNumAndStuCount(string EPLId) | |||||
{ | |||||
try | |||||
{ | |||||
exam_ExamPlanLessonService.UpdateClassNumAndStuCount(EPLId); | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
if (ex is ExceptionEx) | |||||
{ | |||||
throw; | |||||
} | |||||
else | |||||
{ | |||||
throw ExceptionEx.ThrowBusinessException(ex); | |||||
} | |||||
} | |||||
} | |||||
/// <summary> | /// <summary> | ||||
/// 保存实体数据(新增、修改) | /// 保存实体数据(新增、修改) | ||||
/// </summary> | /// </summary> | ||||
@@ -45,6 +45,7 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration | |||||
void DeleteEntity(string keyValue); | void DeleteEntity(string keyValue); | ||||
void Check(string keyValue,int ELCheckMark); | void Check(string keyValue,int ELCheckMark); | ||||
void InitExamPlanLesson(string EPId); | void InitExamPlanLesson(string EPId); | ||||
void UpdateClassNumAndStuCount(string EPLId); | |||||
/// <summary> | /// <summary> | ||||
/// 保存实体数据(新增、修改) | /// 保存实体数据(新增、修改) | ||||
/// </summary> | /// </summary> | ||||
@@ -311,15 +311,7 @@ and AcademicYearNo='{exam_ExamPlan.AcademicYearNo}' and Semester='{exam_ExamPlan | |||||
group by LessonNo,lessonname"; | group by LessonNo,lessonname"; | ||||
this.BaseRepository("CollegeMIS").ExecuteBySql(sql); | this.BaseRepository("CollegeMIS").ExecuteBySql(sql); | ||||
} | } | ||||
//排考课程表 | |||||
var EPLIdlist = this.BaseRepository("CollegeMIS").FindList<Exam_ExamPlanLessonEntity>(x => x.EPId == EPId).Select(x => x.EPLId); | |||||
var EPLIds = string.Join("','", EPLIdlist); | |||||
//班级 | |||||
var classInfo = this.BaseRepository("CollegeMIS").FindList<Exam_ExamStudentEntity>($"select ClassNo,count(1) as StuNum FROM Exam_ExamStudent where ESEnabled=1 and ESType='{exam_ExamPlan.PlanType}' and AcademicYearNo='{exam_ExamPlan.AcademicYearNo}' and Semester='{exam_ExamPlan.Semester}' group by ClassNo"); | |||||
//修改应排班级数和应考人数 | |||||
var UpdSql = $"update Exam_ExamPlanLesson set ClassNum='{classInfo.Count()}',StuCount='{classInfo.Sum(x => x.StuNum)}' where EPLId in ('{EPLIds}')"; | |||||
this.BaseRepository("CollegeMIS").ExecuteBySql(UpdSql); | |||||
} | } | ||||
catch (Exception ex) | catch (Exception ex) | ||||
{ | { | ||||
@@ -334,6 +326,70 @@ and AcademicYearNo='{exam_ExamPlan.AcademicYearNo}' and Semester='{exam_ExamPlan | |||||
} | } | ||||
} | } | ||||
/// <summary> | |||||
/// 更新应考班级数和应考人数(安排考试切换课程时更新) | |||||
/// 【一键安排班级】功能也有更新 | |||||
/// </summary> | |||||
/// <param name="EPLId">主键</param> | |||||
public void UpdateClassNumAndStuCount(string EPLId) | |||||
{ | |||||
var db = this.BaseRepository("CollegeMIS"); | |||||
try | |||||
{ | |||||
db.BeginTrans(); | |||||
var lesson = db.FindEntity<Exam_ExamPlanLessonEntity>(x => x.EPLId == EPLId); | |||||
//排考记录表 | |||||
var examPlan = db.FindEntity<Exam_ExamPlanEntity>(lesson.EPId); | |||||
var lessonno = lesson.LessonNo; | |||||
if (lesson.LessonNo.Contains("(")) | |||||
{ | |||||
lessonno = lesson.LessonNo.Split('(')[0]; | |||||
} | |||||
//查询课程信息 | |||||
var lessoninfo = db.FindList<LessonInfoEntity>($@"select top 1 t.LessonTypeName,l.* from lessoninfo l | |||||
join [dbo].[CdLessonType] t on l.LessonTypeId = t.LTId where l.LessonNo='{lessonno}' ").FirstOrDefault(); | |||||
if (lessoninfo != null) | |||||
{ | |||||
var updSql = $@"update a set a.ClassNum=b.ClassNum,a.StuCount=b.StuCount | |||||
from Exam_ExamPlanLesson a join | |||||
( | |||||
select count(1) as ClassNum,SUM(StuNum) as StuCount,'{EPLId}' as EPLId from ( | |||||
SELECT t.ClassNo,count(1) as StuNum FROM Exam_ExamStudent t | |||||
left join classinfo c on t.ClassNo=c.ClassNo WHERE t.ESEnabled=1 and t.AcademicYearNo='{examPlan.AcademicYearNo}' and t.Semester='{examPlan.Semester}' and t.ESType='{examPlan.PlanType}' | |||||
"; | |||||
if (lessoninfo.LessonTypeName.Contains("专业")) | |||||
{ | |||||
updSql += $" and c.majorno='{lessoninfo.TeachMajorNo}' "; | |||||
} | |||||
//else if (lessoninfo.LessonTypeName.Contains("公共") || lessoninfo.LessonTypeName.Contains("公开")) | |||||
//{ | |||||
// //公共课添加所有班级 | |||||
//} | |||||
updSql += $@" group by t.ClassNo,t.AcademicYearNo,t.Semester,t.ESType,c.ClassName | |||||
) t) b on a.EPLId=b.EPLId | |||||
where a.EPLId='{EPLId}'"; | |||||
db.ExecuteBySql(updSql); | |||||
db.Commit(); | |||||
} | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
db.Rollback(); | |||||
if (ex is ExceptionEx) | |||||
{ | |||||
throw; | |||||
} | |||||
else | |||||
{ | |||||
throw ExceptionEx.ThrowServiceException(ex); | |||||
} | |||||
} | |||||
} | |||||
/// <summary> | /// <summary> | ||||
/// 保存实体数据(新增、修改) | /// 保存实体数据(新增、修改) | ||||
/// </summary> | /// </summary> | ||||
@@ -11,7 +11,7 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration | |||||
/// 日 期:2022-04-15 18:12 | /// 日 期:2022-04-15 18:12 | ||||
/// 描 述:排考安排考场表 | /// 描 述:排考安排考场表 | ||||
/// </summary> | /// </summary> | ||||
public class Exam_ExamPlanRoomEntity | |||||
public class Exam_ExamPlanRoomEntity | |||||
{ | { | ||||
#region 实体成员 | #region 实体成员 | ||||
/// <summary> | /// <summary> | ||||
@@ -75,6 +75,16 @@ namespace Learun.Application.TwoDevelopment.EducationalAdministration | |||||
this.EPRId = keyValue; | this.EPRId = keyValue; | ||||
} | } | ||||
#endregion | #endregion | ||||
/// <summary> | |||||
/// 考试日期 | |||||
/// </summary> | |||||
[NotMapped] | |||||
public DateTime? ExamDate { get; set; } | |||||
/// <summary> | |||||
/// 考试时间 | |||||
/// </summary> | |||||
[NotMapped] | |||||
public string ExamTime { get; set; } | |||||
} | } | ||||
} | } | ||||
@@ -300,8 +300,84 @@ where l.EPLId='{EPLId}'"; | |||||
return (false, "请先设置排考时间!"); | return (false, "请先设置排考时间!"); | ||||
} | } | ||||
//考试班级 | //考试班级 | ||||
var EPLIds = examLessonList.Select(y => y.EPLId).ToList(); | |||||
if (db.FindList<Exam_ExamPlanClassEntity>(x => EPLIds.Contains(x.EPLId)).Count() <= 0) | |||||
{ | |||||
return (false, "请先添加考试班级!"); | |||||
} | |||||
List<Exam_ExamPlanRoomEntity> list = new List<Exam_ExamPlanRoomEntity>(); | |||||
//循环考试课程 | |||||
foreach (var examLesson in examLessonList) | |||||
{ | |||||
//删除考场 | |||||
db.ExecuteBySql($"delete Exam_ExamPlanRoom where EPLId='{examLesson.EPLId}'"); | |||||
//已设置考试时间且已添加班级 | |||||
if (examLesson.ExamDate != null && examLesson.ExamTime.Contains("-") && examLesson.RealStuCount > 0) | |||||
{ | |||||
//当前考试课程考试时间 | |||||
var examtimeStart = Convert.ToDateTime(examLesson.ExamDate.Value.ToString("yyyy-MM-dd") + " " + (examLesson.ExamTime).Split('-')[0]); | |||||
var examtimeEnd = Convert.ToDateTime(examLesson.ExamDate.Value.ToString("yyyy-MM-dd") + " " + examLesson.ExamTime.Split('-')[1]); | |||||
//查询与考试课程的考试时间在同一天的考场,如果存在考试时间冲突的考场 则排除此考场 | |||||
List<string> conflictRoom = new List<string>(); | |||||
var examRoomByDateSql = $@"select a.ClassroomNo,b.ExamDate,b.ExamTime from [dbo].[Exam_ExamPlanRoom] a | |||||
join Exam_ExamPlanLesson b on a.EPLId = b.EPLId | |||||
where ExamDate = '{examLesson.ExamDate}'"; | |||||
var examRoomsByDate = db.FindList<Exam_ExamPlanRoomEntity>(examRoomByDateSql).ToList(); | |||||
//并集(和当前考试记录的考试课程在同一天的) | |||||
var examDatelist = list.Where(x => x.ExamDate == examLesson.ExamDate); | |||||
examRoomsByDate = examRoomsByDate.Union(examDatelist).ToList(); | |||||
foreach (var examRoom in examRoomsByDate) | |||||
{ | |||||
var examRoomTime1 = Convert.ToDateTime(examRoom.ExamDate.Value.ToString("yyyy-MM-dd") + " " + examRoom.ExamTime.Split('-')[0]); | |||||
var examRoomTime2 = Convert.ToDateTime(examRoom.ExamDate.Value.ToString("yyyy-MM-dd") + " " + examRoom.ExamTime.Split('-')[1]); | |||||
//此处判断当前考场时间是否在考试课程排考时间的开始前30分钟到结束后30分钟 | |||||
if ((examRoomTime1 >= examtimeStart.AddMinutes(-30) && examRoomTime1 <= examtimeEnd.AddMinutes(30)) || (examRoomTime2 >= examtimeStart.AddMinutes(-30) && examRoomTime2 <= examtimeEnd.AddMinutes(30))) | |||||
{ | |||||
conflictRoom.Add(examRoom.ClassroomNo); | |||||
} | |||||
} | |||||
//考场座位数 | |||||
int? seatCount = 0; | |||||
var roomListSql = | |||||
$"select * from Exam_ExamRoom where AcademicYearNo='{examPlan.AcademicYearNo}' and Semester='{examPlan.Semester}' and EREnabled=1 "; | |||||
if (conflictRoom.Count() > 0) | |||||
{ | |||||
var classroomNo = string.Join("','", conflictRoom.ToList()); | |||||
roomListSql += $" and ClassroomNo not in ('{classroomNo}')"; | |||||
} | |||||
var examRoomList = db.FindList<Exam_ExamRoomEntity>(roomListSql).OrderBy(x => Guid.NewGuid()); | |||||
foreach (var room in examRoomList) | |||||
{ | |||||
list.Add(new Exam_ExamPlanRoomEntity | |||||
{ | |||||
ClassroomNo = room.ClassroomNo, | |||||
ExamDate = examLesson.ExamDate, | |||||
ExamTime = examLesson.ExamTime, | |||||
}); | |||||
Exam_ExamPlanRoomEntity EPRoom = new Exam_ExamPlanRoomEntity(); | |||||
EPRoom.Create(); | |||||
EPRoom.EPLId = examLesson.EPLId; | |||||
EPRoom.ClassroomName = room.ClassroomName; | |||||
EPRoom.ClassroomNo = room.ClassroomNo; | |||||
EPRoom.SeatCount = room.SeatCount; | |||||
db.Insert(EPRoom); | |||||
seatCount += room.SeatCount; | |||||
if (seatCount >= examLesson.RealStuCount) | |||||
{ | |||||
break; | |||||
} | |||||
} | |||||
db.ExecuteBySql( | |||||
$"update Exam_ExamPlanLesson set SeatCount='{seatCount}' where EPLId='{examLesson.EPLId}'"); | |||||
} | |||||
} | |||||
db.Commit(); | db.Commit(); | ||||
return (true, ""); | return (true, ""); | ||||
} | } | ||||