|
|
@@ -2471,6 +2471,282 @@ group by AcademicYearNo,Semester,DeptNo,MajorNo,LessonNo,TeachClassNo,EmpNo,Les |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public string ArrangeLessonTermImportPk(DataTable dt, string fileId) |
|
|
|
{ |
|
|
|
var db = this.BaseRepository("CollegeMIS").BeginTrans(); |
|
|
|
try |
|
|
|
{ |
|
|
|
int snum = 0; |
|
|
|
int fnum = 0; |
|
|
|
//插入时间 |
|
|
|
var Insertdate = DateTime.Now; |
|
|
|
if (dt.Rows.Count > 0) |
|
|
|
{ |
|
|
|
DataTable failDt = new DataTable(); |
|
|
|
dt.Columns.Add("导入错误", typeof(string)); |
|
|
|
foreach (DataColumn dc in dt.Columns) |
|
|
|
{ |
|
|
|
failDt.Columns.Add(dc.ColumnName, dc.DataType); |
|
|
|
} |
|
|
|
|
|
|
|
IEnumerable<ArrangeLessonTermEntity> ArrangeLessonTermHistory = db.FindList<ArrangeLessonTermEntity>("select * from ArrangeLessonTerm"); |
|
|
|
var ArrangeLessonTerminsert = new List<ArrangeLessonTermEntity>(); |
|
|
|
|
|
|
|
#region 上课时间 |
|
|
|
var lessonTimes = new Dictionary<int, Tuple<string, string>>(); |
|
|
|
lessonTimes.Add(1, new Tuple<string, string>("8:30", "9:15")); |
|
|
|
lessonTimes.Add(2, new Tuple<string, string>("9:25", "10:10")); |
|
|
|
lessonTimes.Add(3, new Tuple<string, string>("10:20", "11:00")); |
|
|
|
lessonTimes.Add(4, new Tuple<string, string>("11:10", "11:50")); |
|
|
|
lessonTimes.Add(5, new Tuple<string, string>("13:30", "14:15")); |
|
|
|
lessonTimes.Add(6, new Tuple<string, string>("14:25", "15:10")); |
|
|
|
lessonTimes.Add(7, new Tuple<string, string>("15:20", "16:00")); |
|
|
|
lessonTimes.Add(8, new Tuple<string, string>("16:10", "16:50")); |
|
|
|
lessonTimes.Add(9, new Tuple<string, string>("17:00", "17:40")); |
|
|
|
lessonTimes.Add(10, new Tuple<string, string>("17:50", "18:30")); |
|
|
|
#endregion |
|
|
|
|
|
|
|
var startDate = DateTime.Today; |
|
|
|
var endDate = DateTime.Today; |
|
|
|
|
|
|
|
// 循环遍历导入 |
|
|
|
foreach (DataRow dr in dt.Rows) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
#region 必填项空验证 |
|
|
|
if (dr["开始日期"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("开始日期不能为空")); |
|
|
|
} |
|
|
|
if (dr["结束日期"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("结束日期不能为空")); |
|
|
|
} |
|
|
|
if (dr["学年"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("学年不能为空")); |
|
|
|
} |
|
|
|
if (dr["学期"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("学期不能为空")); |
|
|
|
} |
|
|
|
if (dr["班级编号"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("班级编号不能为空")); |
|
|
|
} |
|
|
|
if (dr["班级名称"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("班级名称不能为空")); |
|
|
|
} |
|
|
|
if (dr["课程编号"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("课程编号不能为空")); |
|
|
|
} |
|
|
|
if (dr["课程名称"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("课程名称不能为空")); |
|
|
|
} |
|
|
|
if (dr["教师编号"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("教师编号不能为空")); |
|
|
|
} |
|
|
|
if (dr["教师名称"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("教师名称不能为空")); |
|
|
|
} |
|
|
|
if (dr["教室编号"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("教室编号不能为空")); |
|
|
|
} |
|
|
|
if (dr["教室名称"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("教室名称不能为空")); |
|
|
|
} |
|
|
|
if (dr["上课节次"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("上课节次不能为空")); |
|
|
|
} |
|
|
|
if (dr["课程类型"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("课程类型不能为空")); |
|
|
|
} |
|
|
|
if (dr["起始周"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("起始周不能为空")); |
|
|
|
} |
|
|
|
if (dr["结束周"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("结束周不能为空")); |
|
|
|
} |
|
|
|
if (dr["上课周几"].ToString().IsEmpty()) |
|
|
|
{ |
|
|
|
throw (new Exception("上课周几不能为空")); |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region 开始时间、结束时间格式判断 |
|
|
|
//var st = new TimeSpan(); |
|
|
|
//var stFlag = TimeSpan.TryParse(dr["开始时间"].ToString(), out st); |
|
|
|
//if (!stFlag) |
|
|
|
//{ |
|
|
|
// throw (new Exception("开始时间格式有误")); |
|
|
|
//} |
|
|
|
//var et = new TimeSpan(); |
|
|
|
//var etFlag = TimeSpan.TryParse(dr["结束时间"].ToString(), out et); |
|
|
|
//if (!etFlag) |
|
|
|
//{ |
|
|
|
// throw (new Exception("结束时间格式有误")); |
|
|
|
//} |
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
#region 基础数据 |
|
|
|
var lessonEntity = db.FindList<LessonInfoEntity>($"select * from Lessoninfo where LessonName='" + dr["课程名称"].ToString().Trim() + "' and LessonNo='" + dr["课程编号"].ToString().Trim() + "' and CheckMark=1 "); |
|
|
|
var classEntity = db.FindList<ClassInfoEntity>($"select * from ClassInfo where ClassName='" + dr["班级名称"].ToString().Trim() + "' and ClassNo='" + dr["班级编号"].ToString().Trim() + "' and CheckMark=1 "); |
|
|
|
var classroomEntity = db.FindList<ClassroomInfoEntity>($"select * from ClassroomInfo where ClassroomName='" + dr["教室名称"].ToString().Trim() + "' and ClassroomNo='" + dr["教室编号"].ToString().Trim() + "' and CheckMark=1 "); |
|
|
|
var empinfoEntity = db.FindList<EmpInfoEntity>($"select * from EmpInfo where EmpName='" + dr["教师名称"].ToString().Trim() + "' and EmpNo='" + dr["教师编号"].ToString().Trim() + "' and CheckMark=1 "); |
|
|
|
var CompanyEntity = BaseRepository().FindList<CompanyEntity>(x => x.F_EnabledMark == 1).ToList().FirstOrDefault(); |
|
|
|
if (lessonEntity.Count() <= 0) |
|
|
|
throw (new Exception("查无此课程")); |
|
|
|
if (classEntity.Count() <= 0) |
|
|
|
throw (new Exception("查无此班级")); |
|
|
|
if (empinfoEntity.Count() <= 0) |
|
|
|
throw (new Exception("查无此教师")); |
|
|
|
if (classroomEntity.Count() <= 0) |
|
|
|
throw (new Exception("查无此教室")); |
|
|
|
#endregion |
|
|
|
#region 初始化学期时间 |
|
|
|
startDate = dr["开始日期"].ToDate(); |
|
|
|
endDate = dr["结束日期"].ToDate(); |
|
|
|
#endregion |
|
|
|
#region 计算课程开始结束 时间 |
|
|
|
var startWeek = dr["起始周"].ToInt(); |
|
|
|
var lessonStartDate = startDate.AddDays((startWeek - 1) * 7); |
|
|
|
if (lessonStartDate < startDate) lessonStartDate = startDate; |
|
|
|
var endWeek = dr["结束周"].ToInt(); |
|
|
|
var lessonEndDate = startDate.AddDays(endWeek * 7 - 1); |
|
|
|
if (lessonEndDate > endDate) lessonEndDate = endDate; |
|
|
|
#endregion |
|
|
|
#region 计算真正的上课时间 |
|
|
|
var lessonWeekData = dr["上课周几"].ToInt(); |
|
|
|
var lessonStartDateWeek = (int)lessonStartDate.DayOfWeek; |
|
|
|
if (lessonStartDateWeek == 0) lessonStartDateWeek = 7; |
|
|
|
var trueStartDate = lessonStartDate; |
|
|
|
if (lessonStartDateWeek <= lessonWeekData) |
|
|
|
{ |
|
|
|
trueStartDate = lessonStartDate.AddDays(lessonWeekData - lessonStartDateWeek); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
trueStartDate = lessonStartDate.AddDays(7 - (lessonStartDateWeek - lessonWeekData)); |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
var intLesson = dr["上课节次"].ToInt(); |
|
|
|
var lessonTime = lessonTimes[intLesson]; |
|
|
|
var weekType = dr["课程类型"].ToString(); |
|
|
|
while (true) |
|
|
|
{ |
|
|
|
//写入要导入替换的数据 |
|
|
|
ArrangeLessonTermEntity arrangeLessonTermEntity = new ArrangeLessonTermEntity |
|
|
|
{ |
|
|
|
ALTId = Guid.NewGuid().ToString(), |
|
|
|
LessonDate = trueStartDate, |
|
|
|
StartTime = TimeSpan.Parse(lessonTime.Item1).ToString(@"hh\:mm"), |
|
|
|
EndTime = TimeSpan.Parse(lessonTime.Item2).ToString(@"hh\:mm"), |
|
|
|
AcademicYearNo = dr["学年"].ToString(), |
|
|
|
Semester = dr["学期"].ToString(), |
|
|
|
DeptNo = classEntity.FirstOrDefault().DeptNo, |
|
|
|
MajorNo = classEntity.FirstOrDefault().MajorNo, |
|
|
|
LessonNo = lessonEntity.FirstOrDefault().LessonNo, |
|
|
|
LessonName = lessonEntity.FirstOrDefault().LessonName, |
|
|
|
TeachClassNo = lessonEntity.FirstOrDefault().LessonName + classEntity.FirstOrDefault().ClassNo, |
|
|
|
EmpNo = empinfoEntity.FirstOrDefault().EmpNo, |
|
|
|
EmpName = empinfoEntity.FirstOrDefault().EmpName, |
|
|
|
ClassroomNo = classroomEntity.FirstOrDefault().ClassroomNo, |
|
|
|
LessonTime = $"{dr["上课周几"].ToString()}{dr["上课节次"].ToString()}", |
|
|
|
LessonSortNo = lessonEntity.FirstOrDefault().LessonSortNo, |
|
|
|
//默认数; |
|
|
|
CheckMark = "1", |
|
|
|
InsertDate = Insertdate, |
|
|
|
IsImport = true, |
|
|
|
F_SchoolId = CompanyEntity.F_CompanyId |
|
|
|
}; |
|
|
|
|
|
|
|
#region 判断是否重复 |
|
|
|
if (ArrangeLessonTermHistory.Count(m => m.AcademicYearNo == arrangeLessonTermEntity.AcademicYearNo && m.Semester == arrangeLessonTermEntity.Semester |
|
|
|
&& m.LessonNo == arrangeLessonTermEntity.LessonNo && m.LessonDate.Value.Date == arrangeLessonTermEntity.LessonDate.Value.Date |
|
|
|
&& m.DeptNo == arrangeLessonTermEntity.DeptNo && m.MajorNo == arrangeLessonTermEntity.MajorNo |
|
|
|
&& m.TeachClassNo == arrangeLessonTermEntity.TeachClassNo && m.EmpNo == arrangeLessonTermEntity.EmpNo |
|
|
|
&& m.ClassroomNo == arrangeLessonTermEntity.ClassroomNo && m.LessonTime == arrangeLessonTermEntity.LessonTime |
|
|
|
&& m.F_SchoolId == arrangeLessonTermEntity.F_SchoolId) == 0 |
|
|
|
&& ArrangeLessonTerminsert.Count(m => m.AcademicYearNo == arrangeLessonTermEntity.AcademicYearNo && m.Semester == arrangeLessonTermEntity.Semester |
|
|
|
&& m.LessonNo == arrangeLessonTermEntity.LessonNo && m.LessonDate.Value.Date == arrangeLessonTermEntity.LessonDate.Value.Date |
|
|
|
&& m.DeptNo == arrangeLessonTermEntity.DeptNo && m.MajorNo == arrangeLessonTermEntity.MajorNo |
|
|
|
&& m.TeachClassNo == arrangeLessonTermEntity.TeachClassNo && m.EmpNo == arrangeLessonTermEntity.EmpNo |
|
|
|
&& m.ClassroomNo == arrangeLessonTermEntity.ClassroomNo && m.LessonTime == arrangeLessonTermEntity.LessonTime |
|
|
|
&& m.F_SchoolId == arrangeLessonTermEntity.F_SchoolId) == 0) |
|
|
|
{ |
|
|
|
ArrangeLessonTerminsert.Add(arrangeLessonTermEntity); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
//throw (new Exception("当前数据重复")); |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
if (weekType == "全周") |
|
|
|
{ |
|
|
|
trueStartDate = trueStartDate.AddDays(7); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
trueStartDate = trueStartDate.AddDays(14); |
|
|
|
} |
|
|
|
|
|
|
|
if (trueStartDate > lessonEndDate) break; |
|
|
|
} |
|
|
|
snum++; |
|
|
|
|
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
fnum++; |
|
|
|
dr["导入错误"] = ex.Message; |
|
|
|
failDt.Rows.Add(dr.ItemArray); |
|
|
|
} |
|
|
|
} |
|
|
|
//执行导入 |
|
|
|
db.Insert(ArrangeLessonTerminsert); |
|
|
|
db.Commit(); |
|
|
|
if (failDt.Rows.Count > 0) |
|
|
|
{ |
|
|
|
string errordt = failDt.ToJson(); |
|
|
|
cache.Write<string>(cacheKey + fileId, errordt, CacheId.excel); |
|
|
|
} |
|
|
|
if (snum > 0) |
|
|
|
{ |
|
|
|
//写入开课计划数据 |
|
|
|
InsertTeachClassDataInImport(Insertdate); |
|
|
|
} |
|
|
|
} |
|
|
|
return snum + "|" + fnum; |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
db.Rollback(); |
|
|
|
if (ex is ExceptionEx) |
|
|
|
{ |
|
|
|
throw; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
throw ExceptionEx.ThrowServiceException(ex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 课表导入时,写入开课计划数据 |
|
|
|
/// </summary> |
|
|
|