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.WorkflowManage; using EMIS.ViewModel.CultureplanManage.PlanManagement; using EMIS.DataLogic.CultureplanManage.PlanManagement; using EMIS.CommonLogic.SystemServices; namespace EMIS.CommonLogic.CultureplanManage.PlanManagement { public class PlanApplicationApproveServices : BaseWorkflowServices, IPlanApplicationApproveServices { public PlanApplicationDAL PlanApplicationDAL { get; set; } /// /// 查询对应的计划审核信息PlanApplicationView /// 注:普教版本(年级专业) /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetPlanApplicationApproveViewGrid(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem, Guid? grademajorID, Guid? coursematerialID, int? handleModeID, int? approvalStatus, int pageIndex, int pageSize) { var approveStatusList = this.GetApproveStatusViewList(); var approveStatusIDList = approveStatusList.Select(x => x.ID).ToList(); //计划申请 Expression> expPlanApplication = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expPlanApplication = expPlanApplication.And(x => approveStatusIDList.Contains(x.RecordStatus)); if (schoolyearID.HasValue) { expPlanApplication = expPlanApplication.And(x => x.SchoolyearID == schoolyearID); } if (grademajorID.HasValue) { expPlanApplication = expPlanApplication.And(x => x.GrademajorID == grademajorID); } if (coursematerialID.HasValue) { expPlanApplication = expPlanApplication.And(x => x.CoursematerialID == coursematerialID); } if (handleModeID.HasValue) { expPlanApplication = expPlanApplication.And(x => x.HandleModeID == handleModeID); } if (approvalStatus.HasValue) { expPlanApplication = expPlanApplication.And(x => x.RecordStatus == approvalStatus); } var query = PlanApplicationDAL.GetPlanApplicationViewQueryable(expPlanApplication); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } if (collegeID.HasValue) { query = query.Where(x => x.CollegeID == collegeID); } if (yearID.HasValue) { query = query.Where(x => x.GradeID == yearID); } 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.GetQueryByDataRangeByCollege(query) .OrderBy(x => x.GrademajorCode.Length).ThenBy(x => x.GrademajorCode) .ThenBy(x => x.Value).ThenBy(x => x.CourseTypeID) .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode) .ThenByDescending(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name); return result; } /// /// 查询对应的计划审核信息List /// 注:普教版本(年级专业) /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// public IList GetPlanApplicationApproveViewList(ConfiguretView configuretView, Guid? schoolyearID, Guid? campusID, Guid? collegeID, int? yearID, int? standardID, int? educationID, int? learningformID, string learnSystem, Guid? grademajorID, Guid? coursematerialID, int? handleModeID, int? approvalStatus) { var approveStatusList = this.GetApproveStatusViewList(); var approveStatusIDList = approveStatusList.Select(x => x.ID).ToList(); //计划申请 Expression> expPlanApplication = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expPlanApplication = expPlanApplication.And(x => approveStatusIDList.Contains(x.RecordStatus)); if (schoolyearID.HasValue) { expPlanApplication = expPlanApplication.And(x => x.SchoolyearID == schoolyearID); } if (grademajorID.HasValue) { expPlanApplication = expPlanApplication.And(x => x.GrademajorID == grademajorID); } if (coursematerialID.HasValue) { expPlanApplication = expPlanApplication.And(x => x.CoursematerialID == coursematerialID); } if (handleModeID.HasValue) { expPlanApplication = expPlanApplication.And(x => x.HandleModeID == handleModeID); } if (approvalStatus.HasValue) { expPlanApplication = expPlanApplication.And(x => x.RecordStatus == approvalStatus); } var query = PlanApplicationDAL.GetPlanApplicationViewQueryable(expPlanApplication); if (campusID.HasValue) { query = query.Where(x => x.CampusID == campusID); } if (collegeID.HasValue) { query = query.Where(x => x.CollegeID == collegeID); } if (yearID.HasValue) { query = query.Where(x => x.GradeID == yearID); } 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.GetQueryByDataRangeByCollege(query) .OrderBy(x => x.GrademajorCode.Length).ThenBy(x => x.GrademajorCode) .ThenBy(x => x.Value).ThenBy(x => x.CourseTypeID) .ThenBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode) .ThenByDescending(x => x.CreateTime).ToList(); result.ForEach(x => x.ApprovalStatusName = approveStatusList.FirstOrDefault(w => w.ID == x.ApprovalStatus).Name); return result; } /// /// 查询对应的计划审核信息PlanApplicationView(根据计划申请ID) /// /// /// public PlanApplicationView GetPlanApplicationApproveView(Guid? planApplicationID) { try { var planApplicationView = PlanApplicationDAL.GetPlanApplicationViewQueryable(x => x.PlanApplicationID == planApplicationID).SingleOrDefault(); return planApplicationView; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 编辑(新增、修改) /// /// public void PlanApplicationApproveEdit(PlanApplicationView planApplicationView) { throw new NotImplementedException(); } /// /// 查询对应的流程环节动作List(ActionView) /// /// /// /// public List GetApproveActionView(Guid formID, Guid userID) { try { List listAction = this.GetActionView(formID, userID); return listAction; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除 /// /// /// public bool PlanApplicationApproveDelete(List planApplicationIDs) { try { using (TransactionScope ts = new TransactionScope()) { UnitOfWork.Delete(x => planApplicationIDs.Contains(x.PlanApplicationID)); UnitOfWork.Delete(x => planApplicationIDs.Contains(x.PlanApplicationID)); UnitOfWork.Delete(x => planApplicationIDs.Contains(x.PlanApplicationID)); UnitOfWork.Delete(x => planApplicationIDs.Contains(x.PlanApplicationID)); ts.Complete(); return true; } } catch (Exception) { throw; } } /// /// 审核确定(批量) /// /// /// /// /// /// public string PlanApplicationApproveConfirm(List planApplicationIDs, Guid userID, Guid actionID, string comment) { try { //查询对应的工作流程环节状态信息View var approveStatusList = this.GetStatusViewList(); if (approveStatusList == null || approveStatusList.Count() <= 0) { throw new Exception("工作流平台中,专业计划流程未配置,请核查。"); } //查询工作流程结束环节状态 var endStatusID = this.GetCorrectEndStatus(); if (endStatusID == null) { throw new Exception("工作流平台中,专业计划流程结束环节未配置,请核查。"); } //查询对应的计划申请信息List var planApplicationList = PlanApplicationDAL.PlanApplicationRepository .GetList(x => planApplicationIDs.Contains(x.PlanApplicationID), (x => x.EM_PlanApplicationTeachingSetting)).ToList(); //计划申请信息对应的grademajorIDList var grademajorIDList = planApplicationList.Where(x => !string.IsNullOrEmpty(x.GrademajorID.ToString())) .Select(x => x.GrademajorID).ToList(); //查询对应的专业计划信息 var specialtyPlanList = PlanApplicationDAL.SpecialtyPlanRepository .GetList(x => grademajorIDList.Contains(x.GrademajorID), (x => x.EM_SpecialtyPlanTeachingSetting)).ToList(); int success = 0; //成功 int fail = 0; //失败 string tipMessage = null; //提示消息 var approveIDList = new List(); foreach (var planApplication in planApplicationList) { //查询对应的计划审核信息(业务主键:学年学期ID、年级专业ID、课程信息ID) var specialtyPlan = specialtyPlanList.Where(x => x.SchoolyearID == planApplication.SchoolyearID && x.GrademajorID == planApplication.GrademajorID && x.CoursematerialID == planApplication.CoursematerialID).SingleOrDefault(); if (specialtyPlan == null) { approveIDList.Add(planApplication.PlanApplicationID); success++; } else { fail++; } } if (approveIDList.Count > 0) { //审核 this.Approve(approveIDList, userID, actionID, comment); } if (success > 0 && fail <= 0) { tipMessage = success + "条"; } else { tipMessage = success + "条," + fail + "条失败,原因:已存在相同的专业计划信息,请检查。"; } return tipMessage; } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 查询计划审核对应的授课方式List /// /// /// public List GetTeachingModeTypeList(Guid? planApplicationID) { //计划申请 Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); exp = exp.And(x => x.PlanApplicationID == planApplicationID); var query = PlanApplicationDAL.GetTeachingModeTypeQueryble(exp); return query.OrderBy(x => x.Value).Select(x => x.ToString()).ToList(); } /// /// 查询计划审核对应的授课地点List /// /// /// public List GetTeachingPlaceList(Guid? planApplicationID) { //计划申请 Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); exp = exp.And(x => x.PlanApplicationID == planApplicationID); var query = PlanApplicationDAL.GetTeachingPlaceQueryble(exp); return query.OrderBy(x => x.Value).Select(x => x.ToString()).ToList(); } } }