using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.CommonLogic.SystemServices; using EMIS.Entities; using EMIS.DataLogic.Common.TeachingMaterial; using System.Configuration; using EMIS.ViewModel.TeachingMaterial; using EMIS.ViewModel; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.WorkflowManage; using EMIS.CommonLogic.PlugworkflowServices; using EMIS.ViewModel.SystemView; using Bowin.Common.Utility; using EMIS.DataLogic.Repositories; using System.Linq.Expressions; using Bowin.Common.Linq; namespace EMIS.CommonLogic.TeachingMaterial { public class TeachersOrderServices : BaseWorkflowServices, ITeachersOrderServices { #region --定义-- public TeachersOrderDAL TeachersOrderDAL { get; set; } public TeachersOrderRepository TeachersOrderRepository { get; set; } public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; } public TeachersConfirmOrderRepository TeachersConfirmOrderRepository { get; set; } public TeachersPreOrderRepository TeachersPreOrderRepository { get; set; } public UserRepository UserRepository { get; set; } public CoursematerialRepository CoursematerialRepository { get; set; } public PublishRepository PublishRepository { get; set; } public SchoolyearRepository SchoolyearRepository { get; set; } public CollegeRepository CollegeRepository { get; set; } public DictionaryItemRepository DictionaryItemRepository { get; set; } #endregion public TeachersOrderServices() { DataRangeUserFunc = ((x, y) => this.IsUserInDataRangeByCollege(x, y, (w => w.CollegeID))); } /// /// 查询教师征订记录 /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetTeachersOrderViewGrid(ViewModel.ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, Guid? coursematerialID, Guid? publishID, int? ApprovalStatus, int pageIndex, int pageSize) { //.Where(x => x.ApproveStatus == (int)CF_TeachersOrderStatus.Canceled // || x.ApproveStatus == (int)CF_TeachersOrderStatus.UnSubmit || x.ApproveStatus == (int)CF_TeachersOrderStatus.Completed); var statusList = this.GetStatusViewList(); Expression> exp = (x => true); if (schoolyearID.HasValue) exp = exp.And(x => x.SchoolyearID == schoolyearID); if (collegeID.HasValue) exp = exp.And(x => x.CollegeID == collegeID); if (coursematerialID.HasValue) exp = exp.And(x => x.CF_TeachingMaterialPool.EM_Coursematerial.Any(w => w.CoursematerialID == coursematerialID)); if (publishID.HasValue) exp = exp.And(x => x.CF_TeachingMaterialPool.PublishID == publishID); if (ApprovalStatus.HasValue) exp = exp.And(x => x.ApprovalStatus == ApprovalStatus); var query = TeachersOrderDAL.GetTeachingOrderGridView(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) //return this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize); query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.CreateTime); var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => x.ApproveStatusName = statusList.Where(w => w.ID == x.ApproveStatus).Select(w => w.Name).FirstOrDefault()); return result; } /// /// 导出教师征订记录 /// /// /// /// /// /// /// /// /// /// /// public List GetTeachersOrderViewList(ViewModel.ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, Guid? coursematerialID, Guid? publishID, int? ApprovalStatus) { var statusList = this.GetStatusViewList(); Expression> exp = (x => true); if (schoolyearID.HasValue) exp = exp.And(x => x.SchoolyearID == schoolyearID); if (collegeID.HasValue) exp = exp.And(x => x.CollegeID == collegeID); if (coursematerialID.HasValue) exp = exp.And(x => x.CF_TeachingMaterialPool.EM_Coursematerial.Any(w => w.CoursematerialID == coursematerialID)); if (publishID.HasValue) exp = exp.And(x => x.CF_TeachingMaterialPool.PublishID == publishID); if (ApprovalStatus.HasValue && ApprovalStatus != -1) exp = exp.And(x => x.ApprovalStatus == ApprovalStatus); var query = TeachersOrderDAL.GetTeachingOrderGridView(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) //return this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.CreateTime).ToList(); query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.CreateTime); var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CreateTime).ToList(); result.ForEach(x => x.ApproveStatusName = statusList.Where(w => w.ID == x.ApproveStatus).Select(w => w.Name).FirstOrDefault()); return result; } /// /// 提交教师征订记录 /// /// /// /// public void SubmitTeachersOrder(List teachersOrderIDs, Guid userID, string comment = "") { try { bool IsSubmit = true; var startStatus = this.GetStartStatus(); var backPointStatusList = this.GetBackpointStatus(); var statusList = this.GetStatusViewList(); var teachersOrderList = TeachersOrderRepository.GetList(x => teachersOrderIDs.Contains(x.TeachersOrderID)).ToList(); foreach (var teachersOrder in teachersOrderList) { if (teachersOrder.ApprovalStatus != startStatus && !backPointStatusList.Contains(teachersOrder.ApprovalStatus)) { IsSubmit = false; } } if (!IsSubmit) { throw new Exception( string.Format("勾选信息状态不正确,不能提交。只能提交处于{0}状态的信息", string.Join("、", statusList.Where(x => x.ID == startStatus || backPointStatusList.Contains(x.ID)).OrderBy(x => x.ID).ToList()) ) ); } var submitTeacherOrderIDList = teachersOrderList.Where(x => x.ApprovalStatus == startStatus).Select(x => x.TeachersOrderID).ToList(); var reSubmitTeacherOrderIDList = teachersOrderList.Where(x => backPointStatusList.Contains(x.ApprovalStatus) && !submitTeacherOrderIDList.Contains(x.TeachersOrderID)) .Select(x => x.TeachersOrderID).ToList(); if (submitTeacherOrderIDList.Count > 0) { StartUp(submitTeacherOrderIDList, userID, comment); } if (reSubmitTeacherOrderIDList.Count > 0) { Approve(reSubmitTeacherOrderIDList, userID, Guid.Empty, comment); } } catch (Exception ex) { throw ex; } } /// /// 审核教师征订记录 /// /// 专业申请ID /// 当前操作用户ID /// 动作ID /// 处理意见 public void ApproveTeachersOrder(List teachersOrderIDs, Guid userID, ActionView actionView, string comment = "") { try { Approve(teachersOrderIDs, userID, actionView.ActionID, comment); } catch (Exception ex) { throw ex; } } /// /// 添加教师征订信息 /// /// 申请专业实体 /// public void AddTeachersOrder(List teachersOrderViews, Guid createUserID) { try { var startStatus = this.GetStartStatus(); foreach (var teachersOrderView in teachersOrderViews) { ET_TeachersOrder teachingMaterialPool = new ET_TeachersOrder() { TeachersOrderID = Guid.NewGuid(), SchoolyearID = teachersOrderView.SchoolyearID.GetValueOrDefault(), TeachingMaterialPoolID = teachersOrderView.TeachingMaterialPoolID, CollegeID = teachersOrderView.CollegeID.GetValueOrDefault(), OrderUserID = createUserID, OrderDate = DateTime.Now, OrderDesc = teachersOrderView.OrderDesc, OrderQty = teachersOrderView.OrderQty.GetValueOrDefault(), ApprovalStatus = startStatus, CreateTime = DateTime.Now, CreateUserID = createUserID, ModifyTime = DateTime.Now, ModifyUserID = createUserID }; UnitOfWork.Add(teachingMaterialPool); } UnitOfWork.Commit(); } catch (Exception ex) { throw ex; } } /// /// 获取流程审批步骤详细信息 /// /// /// public IGridResultSet GetWorkflowApproveHistoryView(Guid? teachersOrderID) { try { var query = GetApproveHistoryViewList((Guid)teachersOrderID).ToList().OrderByDescending(x => x.ApproveTime); return query.AsQueryable().ToGridResultSet(0, 100); } catch (Exception) { throw; } } /// /// 删除书库信息 /// /// public void DeleteTeachersOrder(List teachersOrderIDs) { try { var statusList = this.GetBackpointStatus(); statusList.Add(this.GetStartStatus()); bool? IsOrdered = false;//是否包含审核完成数据! var teachersOrderList = TeachersOrderRepository.GetList(x => teachersOrderIDs.Contains(x.TeachersOrderID)).ToList(); foreach (var teachersOrder in teachersOrderList) { //teachersOrder.ApprovalStatus != (int)CF_TeachersOrderStatus.Canceled || if (!statusList.Contains(teachersOrder.ApprovalStatus)) { IsOrdered = true; } } if ((bool)IsOrdered) { throw new Exception("只能删除未提交,已退回数据!"); } TeachersOrderRepository.UnitOfWork.Delete(x => teachersOrderIDs.Contains(x.TeachersOrderID)); } catch (Exception ex) { throw ex; } } /// /// 编辑征订信息 /// /// /// public void EditTeachersOrder(TeachersOrderView teachersOrderView, Guid createUserID) { var startStatus = this.GetStartStatus(); List teachersOrderList = new List(); try { if (teachersOrderView.TeachersOrderID != null && teachersOrderView.TeachersOrderID != Guid.Empty) { ET_TeachersOrder teachersOrder = TeachersOrderRepository.GetSingle(x => x.TeachersOrderID == teachersOrderView.TeachersOrderID); teachersOrder.OrderQty = teachersOrderView.OrderQty.GetValueOrDefault(); teachersOrder.OrderDesc = teachersOrderView.OrderDesc; teachersOrder.SchoolyearID = (Guid)teachersOrderView.SchoolyearID; TeachingMaterialPoolRepository.UnitOfWork.Update(teachersOrder); TeachingMaterialPoolRepository.UnitOfWork.Commit(); } else { teachersOrderList.Add(teachersOrderView); foreach (var teachersOrderViewS in teachersOrderList) { ET_TeachersOrder teachingMaterialPool = new ET_TeachersOrder() { TeachersOrderID = Guid.NewGuid(), SchoolyearID = teachersOrderViewS.SchoolyearID.GetValueOrDefault(), TeachingMaterialPoolID = teachersOrderViewS.TeachingMaterialPoolID, CollegeID = teachersOrderViewS.CollegeID.GetValueOrDefault(), OrderUserID = createUserID, OrderDate = DateTime.Now, OrderDesc = teachersOrderViewS.OrderDesc, OrderQty = teachersOrderViewS.OrderQty.GetValueOrDefault(), ApprovalStatus = startStatus, CreateTime = DateTime.Now, CreateUserID = createUserID }; TeachersOrderRepository.UnitOfWork.Add(teachingMaterialPool); } TeachersOrderRepository.UnitOfWork.Commit(); } } catch (Exception ex) { throw ex; } } /// /// 获取征订信息列表导出 /// /// /// public IList GetTeachersOrderViewExcel(ConfiguretView configuretView, Guid? publishID, Guid? coursematerialID, bool? isLate) { var statusList = this.GetStatusViewList(); var queryStatusList = this.GetBackpointStatus(); queryStatusList.Add(this.GetStartStatus()); List list = new List(); var query = TeachersOrderDAL.GetTeachingOrderGridView(x => true).Where(x => queryStatusList.Contains(x.ApproveStatus)); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) list = this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).ToList(); else list = this.GetQueryByDataRangeByCollege(query).ToList(); var result = list.OrderBy(x => x.CoursematerialCode).ToList(); result.ForEach(x => x.ApproveStatusName = statusList.Where(w => w.ID == x.ApproveStatus).Select(w => w.Name).FirstOrDefault()); return result; } public TeachersOrderView GetSingleTeachersOrder(Guid teachersOrderID) { return TeachersOrderDAL.GetSingleTeachersOrderView(teachersOrderID); } /// /// 获取书库信息列表 /// /// /// public IGridResultSet GetTeachingOrderByTeachingMaterialPoolViewGrid(ConfiguretView configuretView, Guid? publishID, Guid? coursematerialID, Guid? teachingMaterialPoolID, Guid? teachersOrderID, bool? isLate, int pageIndex, int pageSize) { List teachingMaterialPoolViewList = new List(); Expression> teachingMaterialPoolExp = (x => true); if (publishID != null && publishID != Guid.Empty) { teachingMaterialPoolExp = teachingMaterialPoolExp.And(x => x.PublishID == publishID); } if (coursematerialID != null && coursematerialID != Guid.Empty) { teachingMaterialPoolExp = teachingMaterialPoolExp.And(x => x.EM_Coursematerial.Any(w => w.CoursematerialID == coursematerialID)); } if (isLate != null) { teachingMaterialPoolExp = teachingMaterialPoolExp.And(x => x.IsLate == isLate); } var query = TeachersOrderDAL.GetTeachingOrderByTeachingMaterialPoolGridView(teachersOrderID, teachingMaterialPoolExp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.TeachingMaterialTypeID).OrderByDescending(x => x.TeachingMaterialName).ToGridResultSet(pageIndex, pageSize); return query.OrderBy(x => x.TeachingMaterialTypeID).OrderByDescending(x => x.TeachingMaterialName).ToGridResultSet(pageIndex, pageSize); } /// /// 查询征订申请提交数据 /// /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetTeachersOrderExamineViewGrid(ViewModel.ConfiguretView configuretView, Guid? schoolyearID, Guid? collegeID, Guid? coursematerialID, Guid? publishID, int? ApprovalStatus, int pageIndex, int pageSize) { var statusList = this.GetStatusViewList(); var approveStatusList = this.GetApproveStatusViewList().Select(x => x.ID).ToList(); Expression> exp = (x => approveStatusList.Contains(x.ApprovalStatus)); if (schoolyearID.HasValue) exp = exp.And(x => x.SchoolyearID == schoolyearID); if (collegeID.HasValue) exp = exp.And(x => x.CollegeID == collegeID); if (coursematerialID.HasValue) exp = exp.And(x => x.CF_TeachingMaterialPool.EM_Coursematerial.Any(w => w.CoursematerialID == coursematerialID)); if (publishID.HasValue) exp = exp.And(x => x.CF_TeachingMaterialPool.PublishID == publishID); if (ApprovalStatus.HasValue) exp = exp.And(x => x.ApprovalStatus == ApprovalStatus); var query = TeachersOrderDAL.GetTeachingOrderGridView(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) //return this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize); query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.CreateTime); var result = this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize); result.rows.ForEach(x => x.ApproveStatusName = statusList.Where(w => w.ID == x.ApproveStatus).Select(w => w.Name).FirstOrDefault()); return result; } public TeachersOrderView GetSingleTeachersOrderById(Guid teachersOrderID) { return TeachersOrderDAL.GetSingleTeachersOrderById(teachersOrderID); } public IGridResultSet GetTeachersOrderOrTeachingMaterialPoolViewGrid(ConfiguretView configuretView, Guid? teachingMaterialID, Guid? coursematerialID, bool? isLate, Guid? college, Guid? schoolyearID, int pageIndex, int pageSize) { Expression> exp = (x => true); if (teachingMaterialID != null && teachingMaterialID != Guid.Empty) { exp = exp.And(x => x.TeachingMaterialPoolID == teachingMaterialID); } if (coursematerialID != null && coursematerialID != Guid.Empty) { exp = exp.And(x => x.EM_Coursematerial.Any(w => w.CoursematerialID == coursematerialID)); } if (isLate != null) { exp = exp.And(x => x.IsLate == isLate); } var query = TeachersOrderDAL.GetTeachersOrderByTeachingMaterial(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.TeachingMaterialCode.Length).ThenBy(x => x.TeachingMaterialCode).ToGridResultSet(pageIndex, pageSize); return query.OrderBy(x => x.TeachingMaterialCode.Length).ThenBy(x => x.TeachingMaterialCode).ToGridResultSet(pageIndex, pageSize); } /******************加载征订明细****************************/ public IGridResultSet GetTeachersOrderDetailViewList(Guid? teachersOrderID, int pageIndex, int pageSize) { var statusList = this.GetStatusViewList(); var query = TeachersOrderDAL.GetTeachingOrderGridView(x => x.TeachersOrderID == teachersOrderID); var result = query.OrderBy(x => x.TeachingMaterialCode.Length).ThenBy(x => x.TeachingMaterialCode).ToGridResultSet(0, 10); result.rows.ForEach(x => x.ApproveStatusName = statusList.Where(w => w.ID == x.ApproveStatus).Select(w => w.Name).FirstOrDefault()); return result; } public void OnApproveEnd(List teacherOrderIDList, Guid? userID) { //var teacherOrderList = TeachersOrderDAL.TeachersOrderRepository.GetList(x => teacherOrderIDList.Contains(x.TeachersOrderID)).ToList(); //var preOrderList = TeachersOrderDAL.GetPreOrderByTeachersOrderIDList(teacherOrderIDList); //foreach (var teacherOrder in teacherOrderList) //{ // var preOrder = preOrderList.FirstOrDefault(x => x.SchoolyearID == teacherOrder.SchoolyearID // && x.TeachingMaterialPoolID == teacherOrder.TeachingMaterialPoolID); // if (preOrder == null) // { // ET_TeachersPreOrder teacherPreOrder = new ET_TeachersPreOrder() // { // TeachersPreOrderID = Guid.NewGuid(), // SchoolyearID = teacherOrder.SchoolyearID, // TeachingMaterialPoolID = teacherOrder.TeachingMaterialPoolID, // PreQty = 5, // Desc = "预加值", // CreateTime = DateTime.Now, // CreateUserID = userID, // ModifyTime = DateTime.Now, // ModifyUserID = userID // }; // UnitOfWork.Add(teacherPreOrder); // } //} } } }