using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using System.Transactions; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.StudentManage.OnlineChecking; using EMIS.DataLogic.StudentManage.OnlineChecking; using EMIS.CommonLogic.SystemServices; namespace EMIS.CommonLogic.StudentManage.OnlineChecking { public class CheckingApproveServices : BaseWorkflowServices, ICheckingApproveServices { public Lazy CheckingApproveDAL { get; set; } /// /// 数据范围 /// public CheckingApproveServices() { DataRangeUserFunc = ((x, y) => this.IsUserInDataRangeByCollege(x, y, (w => w.Sys_User.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID))); } /// /// 查询对应的校对审核信息CheckingApproveView /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetCheckingApproveViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? approvalStatus, int pageIndex, int pageSize) { var approveStatusList = this.GetApproveStatusViewList(); var approveStatusIDList = approveStatusList.Select(x => x.ID).ToList(); Expression> expStudentContrast = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expStudentContrast = expStudentContrast.And(x => approveStatusIDList.Contains(x.ApprovalStatus)); if (approvalStatus.HasValue) { expStudentContrast = expStudentContrast.And(x => x.ApprovalStatus == approvalStatus); } Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> expStudentRecordChangeHistory = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); //expStudentRecordChangeHistory = expStudentRecordChangeHistory.And(x => x.CheckingTypeID == (int)CF_CheckingType.OpenApprove); var query = CheckingApproveDAL.Value.GetCheckingApproveViewQueryable(expStudentContrast, expStudent, expStudentRecordChangeHistory); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } if (collegeID.HasValue) { query = query.Where(x => x.CollegeID == collegeID); } if (gradeID.HasValue) { query = query.Where(x => x.GradeID == gradeID); } if (standardID.HasValue) { query = query.Where(x => x.StandardID == standardID); } if (educationID.HasValue) { query = query.Where(x => x.EducationID == educationID); } if (learningformID.HasValue) { query = query.Where(x => x.LearningformID == learningformID); } if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1") { var LearnSystems = Convert.ToDecimal(learnSystem); query = query.Where(x => x.LearnSystem == LearnSystems); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query)) .OrderBy(x => x.ClassmajorNo.Length).ThenBy(x => x.ClassmajorNo).ThenBy(x => x.GradeID) .ThenBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).OrderByDescending(x => x.ModifyTime) .ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name); return result; } /// /// 查询对应的校对审核信息List /// /// /// /// /// /// /// /// /// /// /// public IList GetCheckingApproveViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? approvalStatus) { var approveStatusList = this.GetApproveStatusViewList(); var approveStatusIDList = approveStatusList.Select(x => x.ID).ToList(); Expression> expStudentContrast = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expStudentContrast = expStudentContrast.And(x => approveStatusIDList.Contains(x.ApprovalStatus)); if (approvalStatus.HasValue) { expStudentContrast = expStudentContrast.And(x => x.ApprovalStatus == approvalStatus); } Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); Expression> expStudentRecordChangeHistory = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); //expStudentRecordChangeHistory = expStudentRecordChangeHistory.And(x => x.CheckingTypeID == (int)CF_CheckingType.OpenApprove); var query = CheckingApproveDAL.Value.GetCheckingApproveViewQueryable(expStudentContrast, expStudent, expStudentRecordChangeHistory); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } if (collegeID.HasValue) { query = query.Where(x => x.CollegeID == collegeID); } if (gradeID.HasValue) { query = query.Where(x => x.GradeID == gradeID); } if (standardID.HasValue) { query = query.Where(x => x.StandardID == standardID); } if (educationID.HasValue) { query = query.Where(x => x.EducationID == educationID); } if (learningformID.HasValue) { query = query.Where(x => x.LearningformID == learningformID); } if (!string.IsNullOrEmpty(learnSystem) && learnSystem != "-1") { var LearnSystems = Convert.ToDecimal(learnSystem); query = query.Where(x => x.LearnSystem == LearnSystems); } //查询条件 if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } var result = this.GetQueryByAssistant(query, (x => x.ClassmajorID), this.GetQueryByDataRangeByCollege(query)) .OrderBy(x => x.ClassmajorNo.Length).ThenBy(x => x.ClassmajorNo).ThenBy(x => x.GradeID) .ThenBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).OrderByDescending(x => x.ModifyTime).ToList(); result.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name); return result; } /// /// 查询对应的校对审核信息CheckingContrastView /// /// /// public CheckingContrastView GetStudentContrastView(Guid? studentContrastID) { try { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); exp = exp.And(x => x.StudentContrastID == studentContrastID); var query = CheckingApproveDAL.Value.GetCheckingApproveViewQueryable(exp).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除 /// /// /// public bool StudentContrastDelete(List studentContrastIDs) { try { using (TransactionScope ts = new TransactionScope()) { UnitOfWork.Delete(x => studentContrastIDs.Contains(x.StudentContrastID)); UnitOfWork.Delete(x => studentContrastIDs.Contains(x.StudentContrastID)); UnitOfWork.Delete(x => studentContrastIDs.Contains(x.StudentContrastID)); UnitOfWork.Delete(x => studentContrastIDs.Contains(x.StudentContrastID)); UnitOfWork.Delete(x => studentContrastIDs.Contains(x.StudentContrastID)); UnitOfWork.Delete(x => studentContrastIDs.Contains(x.StudentContrastID)); UnitOfWork.Delete(x => studentContrastIDs.Contains(x.StudentContrastID)); UnitOfWork.Delete(x => studentContrastIDs.Contains(x.StudentContrastID)); UnitOfWork.Delete(x => studentContrastIDs.Contains(x.StudentContrastID)); UnitOfWork.Delete(x => studentContrastIDs.Contains(x.StudentContrastID)); UnitOfWork.Delete(x => studentContrastIDs.Contains(x.StudentContrastID)); UnitOfWork.Delete(x => studentContrastIDs.Contains(x.StudentContrastID)); UnitOfWork.Delete(x => studentContrastIDs.Contains(x.StudentContrastID)); ts.Complete(); return true; } } catch (Exception) { throw; } } /// /// 查询对应的校对数明细CheckingHistoryView /// /// /// /// /// /// public IGridResultSet GetCheckingDetailViewGrid(ConfiguretView configuretView, Guid? studentContrastID, int pageIndex, int pageSize) { Expression> expStudentContrast = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expStudentContrast = expStudentContrast.And(x => x.StudentContrastID == studentContrastID); var query = CheckingApproveDAL.Value.GetCheckingHistoryViewQueryable(expStudentContrast); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).ThenBy(x => x.ColumnName.Length) .ThenBy(x => x.ColumnName).ToGridResultSet(pageIndex, pageSize); } /// /// 查询对应的校对数明细List /// /// /// /// public IList GetCheckingDetailViewList(ConfiguretView configuretView, Guid? studentContrastID) { Expression> expStudentContrast = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expStudentContrast = expStudentContrast.And(x => x.StudentContrastID == studentContrastID); var query = CheckingApproveDAL.Value.GetCheckingHistoryViewQueryable(expStudentContrast); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); } return query.OrderBy(x => x.StudentNo.Length).ThenBy(x => x.StudentNo).ThenBy(x => x.ColumnName.Length) .ThenBy(x => x.ColumnName).ToList(); } /// /// 审核确定(批量) /// /// /// /// /// public void CheckingApproveConfirm(List studentContrastIDs, Guid userID, Guid actionID, string comment) { try { var studentContrastList = CheckingApproveDAL.Value.StudentContrastRepository.GetList(x => studentContrastIDs.Contains(x.StudentContrastID)).ToList(); foreach (var studentContrastID in studentContrastIDs) { var studentContrast = studentContrastList.Where(x => x.StudentContrastID == studentContrastID).SingleOrDefault(); if (studentContrast == null) { throw new Exception("数据有误,请核查"); } } this.Approve(studentContrastIDs.Select(x => x.Value).ToList(), userID, actionID, comment); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询对应列名称及值ColumnNameValue /// /// /// /// public Dictionary GetColumnNameValue(T t) { try { var columnNameValueList = new Dictionary(); System.Reflection.PropertyInfo[] properties = t.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); foreach (System.Reflection.PropertyInfo item in properties) { if (item.PropertyType.IsValueType || item.PropertyType.Name.StartsWith("String")) { columnNameValueList.Add(item.Name, item.GetValue(t, null)); } } return columnNameValueList; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 流程结束跳转函数(工作流平台中配置) /// 注:需对网上校对信息进行处理 /// /// /// public void OnApproveEnd(List studentContrastIDList, Guid? userID) { try { var studentContrastList = CheckingApproveDAL.Value.StudentContrastRepository.GetList(x => studentContrastIDList.Contains(x.StudentContrastID)).ToList(); var userIDList = studentContrastList.Select(x => x.UserID).ToList(); var studentList = CheckingApproveDAL.Value.StudentRepository.GetList(x => userIDList.Contains(x.UserID), (x => x.CF_StudentProfile), (x => x.CF_StudentContact), (x => x.CF_StudentAccount), (x => x.CF_Recruitstudents), (x => x.Sys_User)).ToList(); var checkingHistoryViewList = CheckingApproveDAL.Value.GetCheckingHistoryViewQueryable(x => studentContrastIDList.Contains(x.StudentContrastID)).ToList(); bool isUserCheck = false; bool isStudentCheck = false; bool isStuProfileCheck = false; bool isStuContactCheck = false; bool isStuAccountCheck = false; bool isStuRecruitCheck = false; List userUpList = new List(); List studentUpList = new List(); List studentProfileUpList = new List(); List studentContactUpList = new List(); List studentAccountUpList = new List(); List recruitstudentsUpList = new List(); foreach (var studentContrast in studentContrastList) { isUserCheck = false; isStudentCheck = false; isStuProfileCheck = false; isStuContactCheck = false; isStuAccountCheck = false; isStuRecruitCheck = false; var keyValuePairList = checkingHistoryViewList.Where(x => x.StudentContrastID == studentContrast.StudentContrastID).ToDictionary(x => x.ColumnName, x => x.CheckingAfterValue); var student = studentList.Where(x => x.UserID == studentContrast.UserID).SingleOrDefault(); foreach (var keyValuePair in keyValuePairList) { var userProperty = typeof(Sys_User).GetProperties().Where(x => x.Name.ToLower() == keyValuePair.Key.ToLower()).SingleOrDefault(); if (userProperty != null) { if (!(userProperty.GetValue(student.Sys_User, null) ?? "").Equals((keyValuePairList[keyValuePair.Key] ?? ""))) { userProperty.SetValue(student.Sys_User, keyValuePairList[keyValuePair.Key], null); isUserCheck = true; } } var studentProperty = typeof(CF_Student).GetProperties().Where(x => x.Name.ToLower() == keyValuePair.Key.ToLower()).SingleOrDefault(); if (studentProperty != null) { if (!(studentProperty.GetValue(student, null) ?? "").Equals((keyValuePairList[keyValuePair.Key] ?? ""))) { studentProperty.SetValue(student, keyValuePairList[keyValuePair.Key], null); isStudentCheck = true; } } var studentProfileProperty = typeof(CF_StudentProfile).GetProperties().Where(x => x.Name.ToLower() == keyValuePair.Key.ToLower()).SingleOrDefault(); if (studentProfileProperty != null) { if (!(studentProfileProperty.GetValue(student.CF_StudentProfile, null) ?? "").Equals((keyValuePairList[keyValuePair.Key] ?? ""))) { studentProfileProperty.SetValue(student.CF_StudentProfile, keyValuePairList[keyValuePair.Key], null); isStuProfileCheck = true; } } var studentContactProperty = typeof(CF_StudentContact).GetProperties().Where(x => x.Name.ToLower() == keyValuePair.Key.ToLower()).SingleOrDefault(); if (studentContactProperty != null) { if (!(studentContactProperty.GetValue(student.CF_StudentContact, null) ?? "").Equals((keyValuePairList[keyValuePair.Key] ?? ""))) { studentContactProperty.SetValue(student.CF_StudentContact, keyValuePairList[keyValuePair.Key], null); isStuContactCheck = true; } } var studentAccountProperty = typeof(CF_StudentAccount).GetProperties().Where(x => x.Name.ToLower() == keyValuePair.Key.ToLower()).SingleOrDefault(); if (studentAccountProperty != null) { if (!(studentAccountProperty.GetValue(student.CF_StudentAccount, null) ?? "").Equals((keyValuePairList[keyValuePair.Key] ?? ""))) { studentAccountProperty.SetValue(student.CF_StudentAccount, keyValuePairList[keyValuePair.Key], null); isStuAccountCheck = true; } } var recruitstudentsProperty = typeof(CF_Recruitstudents).GetProperties().Where(x => x.Name.ToLower() == keyValuePair.Key.ToLower()).SingleOrDefault(); if (recruitstudentsProperty != null) { if (!(recruitstudentsProperty.GetValue(student.CF_Recruitstudents, null) ?? "").Equals((keyValuePairList[keyValuePair.Key] ?? ""))) { recruitstudentsProperty.SetValue(student.CF_Recruitstudents, keyValuePairList[keyValuePair.Key], null); isStuRecruitCheck = true; } } } if (isUserCheck) { student.Sys_User.ModifyUserID = userID; student.Sys_User.ModifyTime = DateTime.Now; userUpList.Add(student.Sys_User); } if (isStudentCheck) { student.ModifyUserID = userID; student.ModifyTime = DateTime.Now; studentUpList.Add(student); } if (isStuProfileCheck) { student.CF_StudentProfile.ModifyUserID = userID; student.CF_StudentProfile.ModifyTime = DateTime.Now; studentProfileUpList.Add(student.CF_StudentProfile); } if (isStuContactCheck) { student.CF_StudentContact.ModifyUserID = userID; student.CF_StudentContact.ModifyTime = DateTime.Now; studentContactUpList.Add(student.CF_StudentContact); } if (isStuAccountCheck) { student.CF_StudentAccount.ModifyUserID = userID; student.CF_StudentAccount.ModifyTime = DateTime.Now; studentAccountUpList.Add(student.CF_StudentAccount); } if (isStuRecruitCheck) { student.CF_Recruitstudents.ModifyUserID = userID; student.CF_Recruitstudents.ModifyTime = DateTime.Now; recruitstudentsUpList.Add(student.CF_Recruitstudents); } } TransactionOptions transactionOption = new TransactionOptions(); transactionOption.IsolationLevel = System.Transactions.IsolationLevel.Serializable; transactionOption.Timeout = new TimeSpan(0, 3, 0); using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, transactionOption)) { if (userUpList != null && userUpList.Count() > 0) { UnitOfWork.BatchUpdate(userUpList); } if (studentUpList != null && studentUpList.Count() > 0) { UnitOfWork.BatchUpdate(studentUpList); } if (studentProfileUpList != null && studentProfileUpList.Count() > 0) { UnitOfWork.BatchUpdate(studentProfileUpList); } if (studentContactUpList != null && studentContactUpList.Count() > 0) { UnitOfWork.BatchUpdate(studentContactUpList); } if (studentAccountUpList != null && studentAccountUpList.Count() > 0) { UnitOfWork.BatchUpdate(studentAccountUpList); } if (recruitstudentsUpList != null && recruitstudentsUpList.Count() > 0) { UnitOfWork.BatchUpdate(recruitstudentsUpList); } ts.Complete(); } } catch (Exception ex) { throw new Exception(ex.Message); } } } }