using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; using System.Data.Entity; using Autofac; using EMIS.DataLogic.SystemDAL; using EMIS.Entities; using EMIS.ViewModel.SystemView; using Bowin.Common.JSON; using EMIS.CommonLogic.PlugworkflowServices; using Bowin.Common.Linq.Entity; using Bowin.Common.Utility; using System.Linq.Expressions; using EMIS.Utility.FormValidate; using EMIS.DataLogic.Repositories; using EMIS.ViewModel.WorkflowManage; using EMIS.Utility; using EMIS.DataLogic.StudentManage.StudentProfile; namespace EMIS.CommonLogic.SystemServices { public class BaseWorkflowServices : BaseServices, IBaseWorkflowServices where TEntity : class { protected Func, Guid, bool> DataRangeUserFunc { get; set; } public Lazy WorkflowServices { get; set; } public StudentDAL StudentDAL { get; set; } private string tableName { get; set; } /// /// /// public BaseWorkflowServices() { tableName = typeof(TEntity).Name; var scope = AutofacHelper.RequestLifetimeScope; StudentDAL = scope.Resolve(); } /// /// 查询对应的接入流程表开始流程环节的Pid(对应的流程环节Pid) /// /// public int? GetStartStatus() { return WorkflowServices.Value.GetStartStatus(tableName); } /// /// 查询对应的接入流程表已退回流程环节Pid(注:不包含开始环节、结束环节且为[BP]标识) /// /// public int? GetSendBackStatus() { return WorkflowServices.Value.GetSendBackStatus(tableName); } /// /// 查询对应的接入流程表已通过流程环节Pid(注:不包含开始环节、结束环节且为[PASS]标识) /// /// public int? GetPassNoEndStatus() { return WorkflowServices.Value.GetPassNoEndStatus(tableName); } /// /// 查询对应的结束流程环节Pid /// /// public List GetEndStatus() { return WorkflowServices.Value.GetEndStatus(tableName); } /// /// 查询对应的结束流程环节且正常结束的流程环节Pid(注:结束环节且不为[BP]标识的) /// /// public int? GetCorrectEndStatus() { return WorkflowServices.Value.GetCorrectEndStatus(tableName); } /// /// 查询对应的接入流程表非正常结束的流程环节Pid(注:通常为结束环节且为[BP]标识的) /// /// public List GetBackpointStatus() { return WorkflowServices.Value.GetBackpointStatus(tableName); } /// /// 查询对应的接入流程表中开始环节、审核流程环节Pid(注:不包含结束、非正常[BP]结束环节) /// /// public List GetStartApproveStatusList() { return WorkflowServices.Value.GetStartApproveStatusList(tableName); } /// /// 查询重录待审,重新录入环节Pid(用于期末设定学生名单背景颜色) /// /// public List GetRebutStatus() { return WorkflowServices.Value.GetRebutStatus(tableName); } /// /// 查询对应的接入流程表中全部流程环节信息(WorkflowStatusView) /// /// public List GetStatusViewList() { return WorkflowServices.Value.GetStatusViewList(tableName); } /// /// 查询对应的接入流程表中审核流程环节信息(WorkflowStatusView,不包含开始、结束、非正常[BP]结束环节) /// /// public List GetApproveStatusViewList() { return WorkflowServices.Value.GetApproveStatusViewList(tableName); } /// /// 重载方法,根据当前流程环节ID获取全部审批动作 /// /// public List GetActionView() { return WorkflowServices.Value.GetActionView(tableName); } /// /// 查询开始流程环节的动作列表List /// /// public List GetStartActionView() { return WorkflowServices.Value.GetStartActionView(tableName); } /// /// 根据当前环节ID、用户ID查询下一步审批动作信息List(ActionView) /// /// 表单ID /// 当前用户ID /// public List GetActionView(Guid formID, Guid userID) { try { return WorkflowServices.Value.GetActionView(tableName, formID, userID); } catch (Exception) { throw; } } /// /// 查询对应的工作流程中是否有对应的操作权限 /// /// /// /// public bool IsCanApprove(Guid formID, Guid userID) { try { var action = this.WorkflowServices.Value.GetActionView(tableName, formID, userID).FirstOrDefault(); if (StudentDAL.StudentRepository.GetSingle(x => x.UserID == userID) == null) { return WorkflowServices.Value.IsCanApprove(tableName, userID, action.ActionID, new List { formID }, DataRangeUserFunc); } else { return WorkflowServices.Value.IsCanApprove(tableName, userID, action.ActionID, new List { formID }); } } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// /// /// /// /// public List IsCanApprove(Guid userID, List formIDs) { return WorkflowServices.Value.IsCanApprove(tableName, userID, formIDs); } /// /// 根据当前用户ID、actionID、formIDs判断是否有权限 /// /// /// public bool GetRangeUserList(Guid userID, Guid actionID, List formIDs) { return WorkflowServices.Value.IsCanApprove(tableName, userID, actionID, formIDs, DataRangeUserFunc); } /// /// 启动对应的流程并执行指定的动作至下一环节(提交) /// /// 需要提交的记录主键ID /// 提交人ID /// 提交意见 public void StartUp(List formIDList, Guid userID, string comment = "") { try { if (StudentDAL.StudentRepository.GetSingle(x => x.UserID == userID) == null) { WorkflowServices.Value.BatchStartUp(tableName, formIDList, userID, comment, DataRangeUserFunc); } else { WorkflowServices.Value.BatchStartUp(tableName, formIDList, userID, comment, null); } } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 重载方法,启动对应的流程并执行指定的动作至下一环节(提交),适用于开始节点有两个以上动作时 /// /// 需要提交的记录主键ID /// 提交人ID /// 动作ID /// 提交意见 public void StartUp(Guid formID, Guid userID, Guid actionID, string comment) { try { if (StudentDAL.StudentRepository.GetSingle(x => x.UserID == userID) == null) { WorkflowServices.Value.StartUp(tableName, formID, userID, actionID, comment, DataRangeUserFunc); } else { WorkflowServices.Value.StartUp(tableName, formID, userID, actionID, comment, null); } } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 审核流程(不包括提交——不包含流程启动) /// /// 需要审核的记录主键ID /// 审核人ID /// 审核动作ID /// 提交意见 public void Approve(List formIDList, Guid userID, Guid actionID, string comment = "") { try { if (StudentDAL.StudentRepository.GetSingle(x => x.UserID == userID) == null) { WorkflowServices.Value.BatchApprove(tableName, formIDList, userID, actionID, comment, DataRangeUserFunc); } else { WorkflowServices.Value.BatchApprove(tableName, formIDList, userID, actionID, comment, null); } } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 工作流流程状态修改(通常用于取消申请、撤销等环节) /// /// 表单ID /// 状态:A为活动,D为结束、其他的自己定义 /// 描述改变内容 public void ModifyProcessState(Guid formID, string status, string description) { try { WorkflowServices.Value.ModifyProcessState(tableName, formID, status, description); } catch (Exception) { throw; } } /// /// 查询对应的审核历史信息列表List(WorkflowApproveHistoryView) /// /// 需要获取的记录主键ID /// public IList GetApproveHistoryViewList(Guid formID) { try { return WorkflowServices.Value.GetApproveHistoryViewList(tableName, formID); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 根据相应的信息查询待办信息View /// /// 视图类型 /// 查询视图,指定一个IQueryable决定如何获取表单记录 /// 待办用户ID /// 指定主键列 /// 页码 /// 每页行数 /// public IGridResultSet QueryByPendingJob(IQueryable query, Guid userID, Expression> pkSelector, Expression> orderby, bool isDescending = false, int? pageIndex = null, int? pageSize = null) { try { return WorkflowServices.Value.QueryByPendingJob(tableName, query, userID, pkSelector, orderby, isDescending, pageIndex, pageSize); } catch (Exception) { throw; } } } }