using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.SchedulingManage.ScheduleApproval; using EMIS.ViewModel.SchedulingManage.ScheduleApproval; using EMIS.Entities; using System.Linq.Expressions; using EMIS.ViewModel; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.CommonLogic.SystemServices; using EMIS.Utility.FormValidate; using EMIS.DataLogic.SchedulingManage.SchedulingSettings; namespace EMIS.CommonLogic.SchedulingManage.ScheduleApproval { public class CollegeScheduleApprovalServices : BaseWorkflowServices, ICollegeScheduleApprovalServices { public CollegeScheduleApprovalDAL collegeScheduleApprovalDAL { get; set; } public CollegePriorityDAL CollegePriorityDAL { get; set; } public IGridResultSet GetCollegeScheduleApprovalViewGrid(Guid? SchoolyearID, Guid? collegeID, int? approvalStatus, int pageIndex, int pageSize) { var status = this.GetStatusViewList(); Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> exp1 = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (SchoolyearID != null) exp1 = exp1.And(x => x.SchoolyearID == SchoolyearID); if (collegeID != null) exp = exp.And(x => x.CollegeID == collegeID); //if (approvalStatus != null) //{ // if (approvalStatus == (int)EMIS.ViewModel.ES_CollegeScheduleStatusCode.NotSubmited) // exp1 = exp1.And(x => x.RecordStatus == approvalStatus || x.RecordStatus == null); // else // exp1 = exp1.And(x => x.RecordStatus == approvalStatus); //} var query = this.GetQueryByDataRangeByCollege(collegeScheduleApprovalDAL.GetCollegeScheduleApprovalViewQueryable(exp, exp1)); if (approvalStatus != null) { if (approvalStatus == (int)EMIS.ViewModel.ES_CollegeScheduleStatusCode.NotSubmited) query = query.Where(x => x.RecordStatus == approvalStatus || x.RecordStatus == null); else query = query.Where(x => x.RecordStatus == approvalStatus); } var result = query.OrderBy(x => x.CollegeNo).ThenByDescending(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => { x.CollegeScheduleStatusID = x.CollegeScheduleStatusID ?? Guid.Empty; x.RecordStatus = x.RecordStatus ?? (int)EMIS.ViewModel.ES_CollegeScheduleStatusCode.NotSubmited; x.StatusName = status.FirstOrDefault(w => w.ID == x.RecordStatus).Name; }); return result; } public List GetCollegeScheduleApprovalViewList(IList collegeAndSchoolyearList, bool isNeedDataRange = true) { var status = this.GetStatusViewList(); Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> exp1 = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); var query = collegeScheduleApprovalDAL.GetCollegeScheduleApprovalViewQueryable(exp, exp1); if (isNeedDataRange) { query = this.GetQueryByDataRangeByCollege(query); } try { var result = query .SelectByKeys(collegeAndSchoolyearList).OrderBy(x => x.CollegeNo).ThenByDescending(x => x.CreateTime).ToList(); result.ForEach(x => x.StatusName = status.FirstOrDefault(w => w.ID == x.RecordStatus).Name); return result; } catch (Exception) { throw; } } public bool Submit(List collegeScheduleStatusIDs, List collegeIDs, Guid schoolYearID) { try { int i = 0; string allMessage = ""; List submitCollegeScheduleStatusIDList = new List(); for (i = 0; i < collegeIDs.Count; i++) { var collegeID = collegeIDs[i]; var collegeScheduleStatus = this.collegeScheduleApprovalDAL.collegeScheduleStatusRepository .GetList(x => x.SchoolyearID == schoolYearID && x.CollegeID == collegeID, (x => x.CF_College)).FirstOrDefault(); if (collegeScheduleStatus != null) { if (collegeScheduleStatus.RecordStatus != (int)ES_CollegeScheduleStatusCode.NotSubmited) { allMessage += collegeScheduleStatus.CF_College.Name + "的课表已经提交,无需重复提交。"; continue; } SetModifyStatus(collegeScheduleStatus); } else { collegeScheduleStatus = new ES_CollegeScheduleStatus(); collegeScheduleStatus.CollegeScheduleStatusID = Guid.NewGuid(); collegeScheduleStatus.CollegeID = collegeIDs[i]; collegeScheduleStatus.SchoolyearID = schoolYearID; SetNewStatus(collegeScheduleStatus); collegeScheduleStatus.RecordStatus = (int)ES_CollegeScheduleStatusCode.NotSubmited; UnitOfWork.Add(collegeScheduleStatus); } this.UnitOfWork.Commit(); submitCollegeScheduleStatusIDList.Add(collegeScheduleStatus.CollegeScheduleStatusID); } this.StartUp(submitCollegeScheduleStatusIDList, CustomPrincipal.Current.UserID); if (allMessage != "") { throw new Exception(allMessage); } return true; } catch (Exception) { throw; } } public bool Approve(List collegeScheduleStatusIDs) { try { var startStatus = this.GetStartStatus(); var endStatus = this.GetCorrectEndStatus(); var collegeScheduleStatusList = this.collegeScheduleApprovalDAL.GetCollegeScheduleApprovalViewQueryable((x => true), (x => collegeScheduleStatusIDs.Contains(x.CollegeScheduleStatusID))).ToList(); if (collegeScheduleStatusIDs.Count == 0) { return true; } var appproveList = collegeScheduleStatusIDs.Where(x => false).Select(x => new { ID = x, ActionID = Guid.Empty }).ToList(); foreach (var id in collegeScheduleStatusIDs) { var collegeScheduleStatus = collegeScheduleStatusList .Where(x => x.CollegeScheduleStatusID == id).FirstOrDefault(); if (!collegeScheduleStatus.RecordStatus.HasValue || collegeScheduleStatus.RecordStatus == startStatus) { throw new Exception(collegeScheduleStatus.CollegeName + "的课表目前并未提交,请先提交后再进行审核。"); } //if (collegeScheduleStatus.RecordStatus == endStatus) //{ // throw new Exception(collegeScheduleStatus.CollegeName + "的课表目前已形成正式课表,无需审核,教务管理员可以使用撤销功能退回给院系所重新提交。"); //} var actionList = this.GetActionView(id, CustomPrincipal.Current.UserID).Where(x => x.ActionName == "同意").ToList(); //collegeScheduleStatus.RecordStatus = (int)ES_CollegeScheduleStatusCode.NotSubmited; var action = actionList.FirstOrDefault(); if (action == null) { throw new Exception(collegeScheduleStatus.CollegeName + "的课表所在的环节并无审核流程,无法审核。"); } appproveList.Add(new { ID = id, ActionID = action.ActionID }); } appproveList.GroupBy(x => x.ActionID).ToList().ForEach(x => this.Approve(x.Select(w => w.ID).ToList(), CustomPrincipal.Current.UserID, x.Key)); //this.UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } public bool ReturnBack(List collegeScheduleStatusIDs) { try { var appproveList = collegeScheduleStatusIDs.Where(x => false).Select(x => new { ID = x, ActionID = Guid.Empty }).ToList(); foreach (var id in collegeScheduleStatusIDs) { var actionList = this.GetActionView(id, CustomPrincipal.Current.UserID).Where(x => x.ActionName == "不同意" || x.ActionName == "退回").ToList(); //var collegeScheduleStatus = this.collegeScheduleApprovalDAL.collegeScheduleStatusRepository.GetList(x => x.CollegeScheduleStatusID == id).FirstOrDefault(); //collegeScheduleStatus.RecordStatus = (int)ES_CollegeScheduleStatusCode.NotSubmited; var action = actionList.FirstOrDefault(); if (action == null) { throw new Exception("该环节不能退回。"); } appproveList.Add(new { ID = id, ActionID = action.ActionID }); } //this.UnitOfWork.Commit(); appproveList.GroupBy(x => x.ActionID).ToList().ForEach(x => this.Approve(x.Select(w => w.ID).ToList(), CustomPrincipal.Current.UserID, x.Key)); return true; } catch (Exception) { throw; } } } }