123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Bowin.Common.Linq;
- using Bowin.Common.Linq.Entity;
- using EMIS.ViewModel.PaymentManage;
- using EMIS.ViewModel;
- using EMIS.Entities;
- using EMIS.DataLogic.PaymentManage;
- using System.Linq.Expressions;
- using EMIS.ViewModel.EducationManage;
- using EMIS.DataLogic.Common.CalendarManage;
- using EMIS.DataLogic.EducationSchedule;
- using EMIS.CommonLogic.EducationSchedule;
- namespace EMIS.CommonLogic.PaymentManage
- {
- public class WorktimeAdjustmentServices : BaseServices, IWorktimeAdjustmentServices
- {
- public WorktimeAdjustmentDAL WorktimeAdjustmentDAL { get; set; }
- public SchoolYearDAL SchoolYearDAL { get; set; }
- public ActivitieDAL ActivitieDAL { get; set; }
- public Lazy<IEducationSchedulingStopServices> EducationSchedulingStopServices { get; set; }
- public IEducationSchedulingAdjustmentServices EducationSchedulingAdjustmentServices { get; set; }
- public IGridResultSet<WorktimeAdjustmentView> GetWorktimeAdjustmentViewList(ConfiguretView worktimeAdjustmentConditionView,
- Guid? schoolyearID, Guid? coursematerialID, Guid? teacherUserID, int? worktimeAdjustmentTypeID, int? pageIndex, int? pageSize)
- {
- Expression<Func<TP_WorktimeAdjustment, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- Expression<Func<EM_Coursematerial, bool>> courseExp = (x => true);
- Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp = (x => true);
- if (schoolyearID.HasValue)
- {
- schoolyearExp = schoolyearExp.And(x => x.SchoolyearID == schoolyearID);
- }
- if (coursematerialID.HasValue)
- {
- courseExp = courseExp.And(x => x.CoursematerialID == coursematerialID);
- }
- if (teacherUserID.HasValue)
- {
- exp = exp.And(x => x.UserID == teacherUserID);
- }
- if (worktimeAdjustmentTypeID.HasValue)
- {
- exp = exp.And(x => x.WorktimeAdjustmentTypeID == worktimeAdjustmentTypeID);
- }
- var query = WorktimeAdjustmentDAL.GetWorktimeAdjustmentViewQueryable(exp, courseExp, schoolyearExp);
- if (!string.IsNullOrEmpty(worktimeAdjustmentConditionView.ConditionValue) && !string.IsNullOrEmpty(worktimeAdjustmentConditionView.Attribute))
- query = query.DynamicWhere(worktimeAdjustmentConditionView.Attribute, worktimeAdjustmentConditionView.Condition, worktimeAdjustmentConditionView.ConditionValue);
- query = query.OrderByDescending(x => x.SchoolyearCode)
- .ThenBy(x => x.WorktimeAdjustmentID)
- .ThenBy(x => x.TeacherName)
- .ThenBy(x => x.CourseCode);
- return query.ToGridResultSet(pageIndex, pageSize);
- }
- public List<WorktimeAdjustmentView> GetWorktimeAdjustmentViewList(ConfiguretView worktimeAdjustmentConditionView,
- Guid? schoolyearID, Guid? coursematerialID, Guid? teacherUserID, int? worktimeAdjustmentTypeID)
- {
- Expression<Func<TP_WorktimeAdjustment, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- Expression<Func<EM_Coursematerial, bool>> courseExp = (x => true);
- Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp = (x => true);
- if (schoolyearID.HasValue)
- {
- schoolyearExp = schoolyearExp.And(x => x.SchoolyearID == schoolyearID);
- }
- if (coursematerialID.HasValue)
- {
- courseExp = courseExp.And(x => x.CoursematerialID == coursematerialID);
- }
- if (teacherUserID.HasValue)
- {
- exp = exp.And(x => x.UserID == teacherUserID);
- }
- if (worktimeAdjustmentTypeID.HasValue)
- {
- exp = exp.And(x => x.WorktimeAdjustmentTypeID == worktimeAdjustmentTypeID);
- }
- var query = WorktimeAdjustmentDAL.GetWorktimeAdjustmentViewQueryable(exp, courseExp, schoolyearExp);
- if (!string.IsNullOrEmpty(worktimeAdjustmentConditionView.ConditionValue) && !string.IsNullOrEmpty(worktimeAdjustmentConditionView.Attribute))
- query = query.DynamicWhere(worktimeAdjustmentConditionView.Attribute, worktimeAdjustmentConditionView.Condition, worktimeAdjustmentConditionView.ConditionValue);
- query = query.OrderByDescending(x => x.SchoolyearCode)
- .ThenBy(x => x.WorktimeAdjustmentID)
- .ThenBy(x => x.TeacherName)
- .ThenBy(x => x.CourseCode);
- return query.ToList();
- }
- public WorktimeAdjustmentView GetWorktimeAdjustmentView(Guid? worktimeAdjustmentID)
- {
- var query = WorktimeAdjustmentDAL.GetWorktimeAdjustmentViewQueryable(x => x.WorktimeAdjustmentID == worktimeAdjustmentID,
- (x => true), (x => true));
- return query.FirstOrDefault();
- }
- public void Save(WorktimeAdjustmentView worktimeAdjustmentView)
- {
- TP_WorktimeAdjustment worktimeAdjustment = new TP_WorktimeAdjustment();
- if (worktimeAdjustmentView.WorktimeAdjustmentID == null || worktimeAdjustmentView.WorktimeAdjustmentID == Guid.Empty)
- {
- worktimeAdjustment = new TP_WorktimeAdjustment();
- worktimeAdjustment.WorktimeAdjustmentID = Guid.NewGuid();
- SetNewStatus(worktimeAdjustment);
- UnitOfWork.Add(worktimeAdjustment);
- }
- else
- {
- worktimeAdjustment = WorktimeAdjustmentDAL.WorktimeAdjustmentRepository.GetSingle(x =>
- x.WorktimeAdjustmentID == worktimeAdjustmentView.WorktimeAdjustmentID);
- if (worktimeAdjustment == null)
- {
- throw new Exception("未能找到需要修改的数据,数据可能已被其他用户更改。");
- }
- SetModifyStatus(worktimeAdjustment);
- }
- worktimeAdjustment.EducationMissionClassID = worktimeAdjustmentView.EducationMissionClassID;
- worktimeAdjustment.AdjustDate = worktimeAdjustmentView.AdjustDate;
- worktimeAdjustment.UserID = worktimeAdjustmentView.UserID;
- worktimeAdjustment.WorktimeAdjustmentTypeID = worktimeAdjustmentView.WorktimeAdjustmentTypeID;
- worktimeAdjustment.Worktime = worktimeAdjustmentView.Worktime;
- UnitOfWork.Commit();
- }
- public void Delete(IList<Guid?> worktimeAdjustmentIDList)
- {
- if (worktimeAdjustmentIDList.Count > 0)
- {
- UnitOfWork.Delete<TP_WorktimeAdjustment>(x => worktimeAdjustmentIDList.Contains(x.WorktimeAdjustmentID));
- }
- }
- public IGridResultSet<EducationMissionClassComboView> GetEducationMissionClassList(ConfiguretView missionClassConditionView,
- Guid? schoolyearID, Guid? userID, DateTime? adjustDate, Guid? collegeID, int? gradeYearID, int? standardID, Guid? coursematerialID,
- int? pageIndex, int? pageSize)
- {
- Expression<Func<EM_EducationMissionClass, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- Expression<Func<ES_EducationSchedulingTeacher, bool>> teacherExp = (x => true);
- Expression<Func<ES_EducationScheduling, bool>> scheduleExp = (x => true);
- if (schoolyearID.HasValue)
- {
- scheduleExp = scheduleExp.And(x => x.SchoolyearID == schoolyearID);
- }
- if (userID.HasValue)
- {
- teacherExp = teacherExp.And(x => x.UserID == userID);
- }
- if (adjustDate.HasValue)
- {
- if (schoolyearID.HasValue)
- {
- var schoolyear = SchoolYearDAL.GetSchoolYearQueryable(x => x.SchoolyearID == schoolyearID).First();
- var adjustWeekNum = Convert.ToInt32(Math.Ceiling(adjustDate.Value.Subtract(schoolyear.FirstWeek.Value).TotalDays / 7));
- var adjustWeekday = (int)adjustDate.Value.DayOfWeek;
- scheduleExp = scheduleExp.And(x => x.Weekday == adjustWeekday && x.ES_EducationSchedulingWeekNum.Any(w => w.WeekNum == adjustWeekNum));
- }
- else
- {
- scheduleExp = scheduleExp.And(x => false);
- }
- }
- if (collegeID.HasValue)
- {
- exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.CollegeID == collegeID));
- }
- if (gradeYearID.HasValue)
- {
- exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.GradeID == gradeYearID));
- }
- if (standardID.HasValue)
- {
- exp = exp.And(x => x.CF_Classmajor.Any(w => w.CF_Grademajor.CF_Facultymajor.StandardID == standardID));
- }
- if (coursematerialID.HasValue)
- {
- exp = exp.And(x => x.CoursematerialID == coursematerialID);
- }
- var query = WorktimeAdjustmentDAL.GetEducationMissionClassViewQueryable(exp, teacherExp, scheduleExp);
- if (!string.IsNullOrEmpty(missionClassConditionView.ConditionValue) && !string.IsNullOrEmpty(missionClassConditionView.Attribute))
- query = query.DynamicWhere(missionClassConditionView.Attribute, missionClassConditionView.Condition, missionClassConditionView.ConditionValue);
- query = query.OrderBy(x => x.Name);
- return query.ToGridResultSet(pageIndex, pageSize);
- }
- public void GenerateChargeAgainst(Guid schoolyearID)
- {
- var activitieList = ActivitieDAL.GetActivitiesQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
- var schoolyear = SchoolYearDAL.GetSchoolYearQueryable(x => x.SchoolyearID == schoolyearID).First();
- var schoolyearEndDate = schoolyear.FirstWeek.Value.AddDays(4 + (((schoolyear.WeeksNum ?? 0) - 1) * 7));
- #region 校历节假日
- var activitieDateList = activitieList.Where(x =>
- (new DateTime(schoolyear.FirstWeek.Value.Year, x.ActivitiesTimeMonth.Value, x.ActivitiesTimeDay.Value) >= schoolyear.FirstWeek.Value
- && new DateTime(schoolyear.FirstWeek.Value.Year, x.ActivitiesTimeMonth.Value, x.ActivitiesTimeDay.Value) <= schoolyearEndDate))
- .Select(x => new DateTime(schoolyear.FirstWeek.Value.Year, x.ActivitiesTimeMonth.Value, x.ActivitiesTimeDay.Value))
- .Concat(activitieList.Where(x =>
- (new DateTime(schoolyearEndDate.Year, x.ActivitiesTimeMonth.Value, x.ActivitiesTimeDay.Value) >= schoolyear.FirstWeek.Value
- && new DateTime(schoolyearEndDate.Year, x.ActivitiesTimeMonth.Value, x.ActivitiesTimeDay.Value) <= schoolyearEndDate))
- .Select(x => new DateTime(schoolyearEndDate.Year, x.ActivitiesTimeMonth.Value, x.ActivitiesTimeDay.Value))).Distinct().ToList();
- var weekdayList = activitieDateList.Select(x =>
- new
- {
- AdjustDate = x,
- Weekday = (int)x.DayOfWeek,
- WeekNum = Convert.ToInt32(Math.Ceiling(x.Subtract(schoolyear.FirstWeek.Value).TotalDays / 7))
- }).ToList();
- var scheduleQuery = WorktimeAdjustmentDAL.GetWorktimeSchedulingViewQueryable(x => x.SchoolyearID == schoolyearID);
- var weekdayAndNumList = weekdayList.Select(x => new { x.Weekday, x.WeekNum }).ToList();
- var weekdayAndNumScheduleList = scheduleQuery.SelectByKeys(weekdayAndNumList);
- #endregion
- #region 停课记录
- var schedulingStopEndStatus = EducationSchedulingStopServices.Value.GetCorrectEndStatus();
- var schedulingStop = WorktimeAdjustmentDAL.GetWorktimeSchedulingViewByStopQueryable(
- x => x.RecordStatus == schedulingStopEndStatus,
- x => x.SchoolyearID == schoolyearID).ToList();
- #endregion
- #region 调课补课记录
- var schedulingAdjustmentEndStatus = EducationSchedulingAdjustmentServices.GetCorrectEndStatus();
- var schedulingAdjustment = WorktimeAdjustmentDAL.GetWorktimeSchedulingViewByAdjustmentQueryable(
- x => x.RecordStatus == schedulingStopEndStatus,
- x => x.SchoolyearID == schoolyearID).ToList();
- #endregion
- var scheduleList = weekdayAndNumScheduleList
- .Join(weekdayList, (x => new { Weekday = x.Weekday ?? 0, WeekNum = x.WeekNum ?? 0 }), (x => new { x.Weekday, x.WeekNum }),
- ((x, y) => new
- {
- x.EducationMissionClassID,
- y.AdjustDate,
- x.UserID,
- x.Worktime
- })).Concat(
- schedulingStop.Select(x => new
- {
- x.EducationMissionClassID,
- AdjustDate = schoolyear.FirstWeek.Value.AddDays((double)((x.WeekNum - 1) * 7 + (x.Weekday == 0 ? 7 : x.Weekday) - 1)),
- x.UserID,
- x.Worktime
- })
- );
- var achedulingAdjustmentList = schedulingAdjustment.Select(x => new
- {
- x.EducationMissionClassID,
- AdjustDate = schoolyear.FirstWeek.Value.AddDays((double)((x.WeekNum - 1) * 7 + (x.Weekday == 0 ? 7 : x.Weekday) - 1)),
- x.UserID,
- x.Worktime
- });
- var existsAdjustmentList = WorktimeAdjustmentDAL.WorktimeAdjustmentRepository.Entities.SelectByKeys(
- scheduleList.Select(x => new { x.EducationMissionClassID, x.AdjustDate, x.UserID }).ToList()
- );
- var deleteAdjustmentList = WorktimeAdjustmentDAL.WorktimeAdjustmentRepository.Entities.SelectByKeys(
- achedulingAdjustmentList.Select(x => new { x.EducationMissionClassID, x.AdjustDate, x.UserID }).ToList()
- );
- var delID = deleteAdjustmentList.Select(x => x.WorktimeAdjustmentID).ToList();
- var adjustmenntList = WorktimeAdjustmentDAL.WorktimeAdjustmentRepository.Entities.ToList();
- var insertList = new List<TP_WorktimeAdjustment>();
- var updateList = new List<TP_WorktimeAdjustment>();
- foreach (var schedule in scheduleList)
- {
- if (!existsAdjustmentList.Any(x => x.EducationMissionClassID == schedule.EducationMissionClassID
- && x.UserID == schedule.UserID && x.AdjustDate == schedule.AdjustDate
- && x.WorktimeAdjustmentTypeID == (int)TP_WorktimeAdjustmentType.ChargeAgainst))
- {
- var adjustment = new TP_WorktimeAdjustment
- {
- WorktimeAdjustmentID = Guid.NewGuid(),
- EducationMissionClassID = schedule.EducationMissionClassID,
- AdjustDate = schedule.AdjustDate,
- UserID = schedule.UserID,
- WorktimeAdjustmentTypeID = (int)TP_WorktimeAdjustmentType.ChargeAgainst,
- Worktime = schedule.Worktime
- };
- this.SetNewStatus(adjustment);
- insertList.Add(adjustment);
- }
- //else if (existsAdjustmentList.Any(x => x.EducationMissionClassID == schedule.EducationMissionClassID
- // && x.UserID == schedule.UserID && x.AdjustDate == schedule.AdjustDate
- // && x.WorktimeAdjustmentTypeID == (int)TP_WorktimeAdjustmentType.ChargeAgainst))
- //{
- // var adjustment = adjustmenntList.Where(x => x.EducationMissionClassID == schedule.EducationMissionClassID && x.UserID == schedule.UserID
- // && x.AdjustDate == schedule.AdjustDate && x.WorktimeAdjustmentTypeID == (int)TP_WorktimeAdjustmentType.ChargeAgainst).FirstOrDefault();
- //}
- }
- UnitOfWork.Delete<TP_WorktimeAdjustment>(x => delID.Contains(x.WorktimeAdjustmentID));
- UnitOfWork.BulkInsert(insertList);
- }
- }
- }
|