using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using Bowin.Common.Utility; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.StudentManage.StudentProfile; using EMIS.DataLogic.StudentManage.StudentProfile; using EMIS.CommonLogic.StudentManage.StudentStatistics; using EMIS.CommonLogic.SystemServices; namespace EMIS.CommonLogic.StudentManage.StudentProfile { public class StudentEncourageServices : BaseWorkflowServices, IStudentEncourageServices { public Lazy StudentEncourageDAL { get; set; } public Lazy InSchoolSettingServices { get; set; } /// /// 数据范围 /// public StudentEncourageServices() { DataRangeUserFunc = ((x, y) => this.IsUserInDataRangeByCollege(x, y, (w => w.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID))); } /// /// 查询对应的学生奖励信息StudentEncourageView /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetStudentEncourageViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? encourageNameID, int? encourageTypeID, int? encourageLevelID, int? inSchoolStatus, int? approvalStatus, int pageIndex, int pageSize) { var approveStatusList = this.GetStatusViewList(); Expression> expStudentEncourage = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (schoolyearID.HasValue) { expStudentEncourage = expStudentEncourage.And(x => x.SchoolyearID == schoolyearID); } if (encourageNameID.HasValue) { expStudentEncourage = expStudentEncourage.And(x => x.EncourageNameID == encourageNameID); } if (encourageTypeID.HasValue) { expStudentEncourage = expStudentEncourage.And(x => x.EncourageTypeID == encourageTypeID); } if (encourageLevelID.HasValue) { expStudentEncourage = expStudentEncourage.And(x => x.EncourageLevelID == encourageLevelID); } if (approvalStatus.HasValue) { expStudentEncourage = expStudentEncourage.And(x => x.ApprovalStatus == approvalStatus); } Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (inSchoolStatus != null && inSchoolStatus > -1) { var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true); if (inSchoolStatus == 1) { expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID)); } if (inSchoolStatus == 0) { expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID)); } } var query = StudentEncourageDAL.Value.GetStudentEncourageViewQueryable(expStudentEncourage, expStudent); 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.StudentNo.Length).ThenBy(x => x.StudentNo).ThenByDescending(x => x.SchoolyearValue).ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name); return result; } /// /// 查询对应的学生奖励信息List /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IList GetStudentEncourageViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, int? gradeID, int? standardID, int? educationID, int? learningformID, string learnSystem, int? encourageNameID, int? encourageTypeID, int? encourageLevelID, int? inSchoolStatus, int? approvalStatus, List userIDList = null) { var approveStatusList = this.GetStatusViewList(); Expression> expStudentEncourage = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (schoolyearID.HasValue) { expStudentEncourage = expStudentEncourage.And(x => x.SchoolyearID == schoolyearID); } if (encourageNameID.HasValue) { expStudentEncourage = expStudentEncourage.And(x => x.EncourageNameID == encourageNameID); } if (encourageTypeID.HasValue) { expStudentEncourage = expStudentEncourage.And(x => x.EncourageTypeID == encourageTypeID); } if (encourageLevelID.HasValue) { expStudentEncourage = expStudentEncourage.And(x => x.EncourageLevelID == encourageLevelID); } if (approvalStatus.HasValue) { expStudentEncourage = expStudentEncourage.And(x => x.ApprovalStatus == approvalStatus); } Expression> expStudent = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (inSchoolStatus != null && inSchoolStatus > -1) { var inschoolStatusList = InSchoolSettingServices.Value.GetInschoolStatusList(true); if (inSchoolStatus == 1) { expStudent = expStudent.And(x => inschoolStatusList.Contains(x.InSchoolStatusID)); } if (inSchoolStatus == 0) { expStudent = expStudent.And(x => !inschoolStatusList.Contains(x.InSchoolStatusID)); } } if (userIDList != null && userIDList.Count() > 0) { expStudentEncourage = expStudentEncourage.And(x => userIDList.Contains(x.UserID)); } var query = StudentEncourageDAL.Value.GetStudentEncourageViewQueryable(expStudentEncourage, expStudent); 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.StudentNo.Length).ThenBy(x => x.StudentNo).ThenByDescending(x => x.SchoolyearValue).ToList(); result.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name); return result; } /// /// 查询对应的学生奖励信息View /// /// /// public StudentEncourageView GetStudentEncourageView(Guid? studentEncourageID) { try { var query = StudentEncourageDAL.Value.GetStudentEncourageViewQueryable(x => x.StudentEncourageID == studentEncourageID).SingleOrDefault(); return query; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 编辑 /// /// public void StudentEncourageEdit(StudentEncourageView studentEncourageView) { try { var approveStatusList = this.GetStatusViewList(); if (approveStatusList == null || approveStatusList.Count() <= 0) { throw new Exception("工作流平台中,学生奖励流程未配置,请核查。"); } var startStatusID = this.GetStartStatus(); if (startStatusID == null) { throw new Exception("工作流平台中,学生奖励流程开始环节未配置,请核查。"); } var studentEncourageVerify = StudentEncourageDAL.Value.StudentEncourageRepository.GetList(x => x.StudentEncourageID != studentEncourageView.StudentEncourageID && x.SchoolyearID == studentEncourageView.SchoolyearID && x.UserID == studentEncourageView.UserID && x.EncourageNameID == studentEncourageView.EncourageNameID).SingleOrDefault(); if (studentEncourageVerify == null) { if (studentEncourageView.StudentEncourageID != Guid.Empty) { var studentEncourage = StudentEncourageDAL.Value.StudentEncourageRepository.GetList(x => x.StudentEncourageID == studentEncourageView.StudentEncourageID).SingleOrDefault(); if (studentEncourage == null) { throw new Exception("数据有误,请核查。"); } else { //表示修改 studentEncourage.EncourageTypeID = studentEncourageView.EncourageTypeID; studentEncourage.EncourageLevelID = studentEncourageView.EncourageLevelID; studentEncourage.DocNo = studentEncourageView.DocNo; studentEncourage.Unit = studentEncourageView.Unit; studentEncourage.EncourageDate = studentEncourageView.EncourageDate; studentEncourage.Amount = studentEncourageView.Amount; studentEncourage.Reason = studentEncourageView.Reason; SetModifyStatus(studentEncourage); } } else { //表示新增 var newStudentEncourage = new EM_StudentEncourage(); newStudentEncourage.StudentEncourageID = Guid.NewGuid(); newStudentEncourage.SchoolyearID = studentEncourageView.SchoolyearID; newStudentEncourage.UserID = studentEncourageView.UserID; newStudentEncourage.EncourageNameID = studentEncourageView.EncourageNameID; newStudentEncourage.EncourageTypeID = studentEncourageView.EncourageTypeID; newStudentEncourage.EncourageLevelID = studentEncourageView.EncourageLevelID; newStudentEncourage.DocNo = studentEncourageView.DocNo; newStudentEncourage.Unit = studentEncourageView.Unit; newStudentEncourage.EncourageDate = studentEncourageView.EncourageDate; newStudentEncourage.Amount = studentEncourageView.Amount; newStudentEncourage.Reason = studentEncourageView.Reason; newStudentEncourage.ApprovalStatus = startStatusID; SetNewStatus(newStudentEncourage); UnitOfWork.Add(newStudentEncourage); } } else { throw new Exception("已存在相同的学生奖励信息,请核查。"); } UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除 /// /// /// public bool StudentEncourageDelete(List studentEncourageIDs) { try { //var startStatusID = this.GetStartStatus(); //if (startStatusID == null) //{ // throw new Exception("工作流平台中,学生奖励流程开始环节流程未配置,请核查"); //} //var approvalStatusList = StudentEncourageDAL.Value.StudentEncourageRepository.GetList(x => studentEncourageIDs.Contains(x.StudentEncourageID)).Select(x => x.ApprovalStatus).ToList(); //foreach (var approvalStatus in approvalStatusList) //{ // if (approvalStatus != startStatusID) // { // throw new Exception("只能对未提交状态的信息进行删除"); // } //} UnitOfWork.Delete(x => studentEncourageIDs.Contains(x.StudentEncourageID)); return true; } catch (Exception) { throw; } } /// /// 提交 /// /// /// /// /// public string StudentEncourageSubmit(List studentEncourageIDs, Guid userID, string comment = "") { try { var startStatusID = this.GetStartStatus(); if (startStatusID == null) { throw new Exception("工作流平台中,学生奖励流程开始环节流程未配置,请核查。"); } var studentEncourageList = StudentEncourageDAL.Value.StudentEncourageRepository.GetList(x => studentEncourageIDs.Contains(x.StudentEncourageID)).ToList(); int success = 0; string tipMessage = null; var submitIDList = new List(); var approveIDList = new List(); foreach (var studentEncourage in studentEncourageList) { if (studentEncourage.ApprovalStatus == startStatusID) { submitIDList.Add(studentEncourage.StudentEncourageID); } else { approveIDList.Add(studentEncourage.StudentEncourageID); } success++; } if (submitIDList.Count > 0) { this.StartUp(submitIDList, userID, comment); } if (approveIDList.Count > 0) { this.Approve(approveIDList, userID, Guid.Empty, comment); } tipMessage = success + "条"; return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 审核确定(批量) /// /// /// /// /// public void StudentEncourageApproveConfirm(List studentEncourageIDs, Guid userID, Guid actionID, string comment) { try { var studentEncourageList = StudentEncourageDAL.Value.StudentEncourageRepository.GetList(x => studentEncourageIDs.Contains(x.StudentEncourageID)).ToList(); foreach (var studentEncourageID in studentEncourageIDs) { var studentEncourage = studentEncourageList.Where(x => x.StudentEncourageID == studentEncourageID).SingleOrDefault(); if (studentEncourage == null) { throw new Exception("数据有误,请核查。"); } } this.Approve(studentEncourageIDs.Select(x => x.Value).ToList(), userID, actionID, comment); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 撤销确定(批量) /// /// /// /// public void StudentEncourageCancelConfirm(List studentEncourageIDs, Guid userID, string comment) { try { var studentEncourageList = StudentEncourageDAL.Value.StudentEncourageRepository.GetList(x => studentEncourageIDs.Contains(x.StudentEncourageID)).ToList(); foreach (var studentEncourageID in studentEncourageIDs) { var studentEncourage = studentEncourageList.Where(x => x.StudentEncourageID == studentEncourageID).SingleOrDefault(); if (studentEncourage == null) { throw new Exception("数据有误,请核查。"); } } var actionID = this.GetActionView(studentEncourageIDs[0].Value, userID).Where(x => (x.Description ?? "").Contains("[CANCEL]")).Select(x => x.ActionID).SingleOrDefault(); this.Approve(studentEncourageIDs.Select(x => x.Value).ToList(), userID, actionID, comment); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 流程结束跳转函数(工作流平台中配置) /// /// /// public void OnApproveEnd(List studentEncourageIDList, Guid? userID) { throw new NotImplementedException(); } } }