123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- 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<ES_CollegeScheduleStatus>, ICollegeScheduleApprovalServices
- {
- public CollegeScheduleApprovalDAL collegeScheduleApprovalDAL { get; set; }
- public CollegePriorityDAL CollegePriorityDAL { get; set; }
- public IGridResultSet<CollegeScheduleApprovalView> GetCollegeScheduleApprovalViewGrid(Guid? SchoolyearID, Guid? collegeID, int? approvalStatus, int pageIndex, int pageSize)
- {
- var status = this.GetStatusViewList();
- Expression<Func<CF_College, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- Expression<Func<ES_CollegeScheduleStatus, bool>> 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<CollegeScheduleApprovalView>(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<CollegeScheduleApprovalView> GetCollegeScheduleApprovalViewList(IList<ViewModel.EducationSchedule.CollegeSchoolyearView> collegeAndSchoolyearList,
- bool isNeedDataRange = true)
- {
- var status = this.GetStatusViewList();
- Expression<Func<CF_College, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- Expression<Func<ES_CollegeScheduleStatus, bool>> 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<Guid?> collegeScheduleStatusIDs, List<Guid?> collegeIDs, Guid schoolYearID)
- {
- try
- {
- int i = 0;
- string allMessage = "";
- List<Guid> submitCollegeScheduleStatusIDList = new List<Guid>();
- 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<Guid> 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<Guid> 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;
- }
- }
- }
- }
|