12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Configuration;
- using Autofac;
- using EMIS.DataLogic.SystemDAL;
- using EMIS.Entities;
- using Bowin.Common.Utility;
- using EMIS.CommonLogic.PlugworkflowServices;
- using System.Reflection;
- using EMIS.ViewModel.SystemView;
- using Bowin.Common.Linq.Entity;
- using System.Linq.Expressions;
- using EMIS.ViewModel.WorkflowManage;
- using EMIS.Utility.FormValidate;
- using EMIS.Utility;
- using Bowin.Common.Mobile;
- using System.Transactions;
- namespace EMIS.CommonLogic.SystemServices
- {
- public class WorkflowServices : BaseServices, IWorkflowServices
- {
- public ProcessWorkfloconfigDAL ProcessWorkfloconfigDAL { get; set; }
- public RoleDAL RoleDAL { get; set; }
- public Lazy<IProcessRelationServices> ProcessRelationServices { get; set; }
- public Lazy<IUserServices> UserServices { get; set; }
- private PlugworkflowServices.entreeSoapClient client = new PlugworkflowServices.entreeSoapClient();
- private PlugworkflowServices.VerificationModel vm = new PlugworkflowServices.VerificationModel();
- public Func<Guid, MessageBody> MessageFunc = null;
-
-
-
- private static string sysID = ConfigurationSettings.AppSettings["sys_InsertingID"].ToString();
-
-
-
- private static string sysPwd = ConfigurationSettings.AppSettings["sys_InsertingPwd"].ToString();
-
-
-
-
-
- private Type GetEntityType(string tableName)
- {
- var assembly = typeof(EMISNewContext).Assembly;
- return assembly.GetType("EMIS.Entities." + tableName, false, true);
- }
-
-
-
- private void InitVerificationModel()
- {
- vm.AppUID = sysID;
- vm.time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- vm.AppUPwd = (sysPwd + vm.time).MD5();
- }
-
-
-
-
-
- private string GetAppIDByTableName(string tableName)
- {
- string AppID = string.Empty;
- Sys_Workfloconfig workfloconfig = ProcessWorkfloconfigDAL.GetWorkfloconfigQueryable()
- .Where(x => x.TableName == tableName).FirstOrDefault();
- if (workfloconfig != null)
- {
- AppID = workfloconfig.ProcessID.ToString();
- }
- return AppID;
- }
-
-
-
-
-
- private List<NextDetailModel> GetStatusList(string tableName)
- {
-
- string AppID = this.GetAppIDByTableName(tableName);
- this.InitVerificationModel();
- PlugworkflowServices.ProcessItemAndActionResultModel piarm = client.FlowProcessAndActionSetting(AppID, vm);
- if (piarm.doNum == 1)
- {
- return piarm.resultDataList.ToList();
- }
- else
- {
- return new List<NextDetailModel>();
- }
- }
-
-
-
-
-
- private List<NextDetailModel> GetStartStatusList(string tableName)
- {
-
- string AppID = this.GetAppIDByTableName(tableName);
- this.InitVerificationModel();
- PlugworkflowServices.ProcessItemAndActionResultModel piarm = client.FlowProcessAndActionSetting(AppID, vm);
- if (piarm.doNum == 1)
- {
- return piarm.resultDataList.Where(x => x.Tp == "start").ToList();
- }
- else
- {
- return new List<NextDetailModel>();
- }
- }
-
-
-
-
-
- public int? GetStartStatus(string tableName)
- {
- var statusList = this.GetStatusList(tableName);
- return statusList.Where(x => x.Tp == "start").Select(x => x.Pid).FirstOrDefault();
- }
-
-
-
-
-
- public int? GetSendBackStatus(string tableName)
- {
- var statusList = this.GetStatusList(tableName);
- return statusList.Where(x => x.Tp == "auto" && (x.Description ?? "").Contains("[BP]")).Select(x => x.Pid).FirstOrDefault();
- }
-
-
-
-
-
- public int? GetPassNoEndStatus(string tableName)
- {
- var statusList = this.GetStatusList(tableName);
- return statusList.Where(x => x.Tp == "auto" && (x.Description ?? "").Contains("[PASS]")).Select(x => x.Pid).FirstOrDefault();
- }
-
-
-
-
-
- public List<int?> GetEndStatus(string tableName)
- {
- var statusList = this.GetStatusList(tableName);
- return statusList.Where(x => x.Tp == "end").Select(x => x.Pid).ToList();
- }
-
-
-
-
-
- public int? GetCorrectEndStatus(string tableName)
- {
- var statusList = this.GetStatusList(tableName);
- return statusList.Where(x => x.Tp == "end" && !(x.Description ?? "").Contains("[BP]")).Select(x => x.Pid).FirstOrDefault();
- }
-
-
-
-
-
- public List<int?> GetRebutStatus(string tableName)
- {
- var statusList = this.GetStatusList(tableName);
- return statusList.Where(x => (x.Description ?? "").Contains("[Rebut]")).Select(x => x.Pid).ToList();
- }
-
-
-
-
-
- public List<int?> GetBackpointStatus(string tableName)
- {
- var statusList = this.GetStatusList(tableName);
- return statusList.Where(x => (x.Description ?? "").Contains("[BP]")).Select(x => x.Pid).ToList();
- }
-
-
-
-
-
- public List<int?> GetStartApproveStatusList(string tableName)
- {
- try
- {
- return this.GetStatusList(tableName).Where(x => x.Tp != "end" && !(x.Description ?? "").Contains("[BP]"))
- .Select(x => x.Pid).ToList();
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
-
-
-
-
-
- public List<WorkflowStatusView> GetStatusViewList(string tableName)
- {
- return this.GetStatusList(tableName).Select(x => new WorkflowStatusView
- {
- ID = x.Pid,
- Name = x.PName,
- Description = x.Description ?? ""
- }).OrderBy(x => x.ID).ToList();
- }
-
-
-
-
-
- public List<WorkflowStatusView> GetApproveStatusViewList(string tableName)
- {
- try
- {
- return this.GetStatusList(tableName).Where(x => x.Tp != "start" && x.Tp != "end" && !(x.Description ?? "").Contains("[BP]"))
- .Select(x => new WorkflowStatusView
- {
- ID = x.Pid,
- Name = x.PName,
- Description = x.Description ?? ""
- }).OrderBy(x => x.ID).ToList();
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
-
-
-
-
-
- public List<WorkflowStatusView> GetNoStartStatusViewList(string tableName)
- {
- try
- {
- return this.GetStatusList(tableName).Where(x => x.Tp != "start")
- .Select(x => new WorkflowStatusView
- {
- ID = x.Pid,
- Name = x.PName,
- Description = x.Description ?? ""
- })
- .OrderBy(x => x.ID).ToList();
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
-
-
-
-
-
- public List<WorkflowStatusView> GetEndStatusViewList(string tableName)
- {
- try
- {
- return this.GetStatusList(tableName).Where(x => x.Tp == "end")
- .Select(x => new WorkflowStatusView
- {
- ID = x.Pid,
- Name = x.PName,
- Description = x.Description ?? ""
- }).OrderBy(x => x.ID).ToList();
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
-
-
-
-
-
-
-
-
- private bool IsCanSubmit(string tableName, Guid userID, List<Guid> formIDs,
- Func<List<Guid>, Guid, bool> dataRangeUserFunc = null)
- {
- bool isMatched = false;
-
- var user = UserServices.Value.GetUserByID(userID);
- this.InitVerificationModel();
- List<PlugworkflowServices.NextDetailModel> listNetxtDetail = this.GetStatusList(tableName)
- .Where(x => x.Tp == "start").ToList();
- var userAndRoleList = listNetxtDetail.SelectMany(x => x.PendingUserType.Split(',')).Distinct().ToList();
- var posibleUserList = UserServices.Value.GetUserListByLoginID(userAndRoleList);
- IList<Sys_Role> listrole = UserServices.Value.GetUserRoles(user.UserID);
- foreach (var listDetail in listNetxtDetail)
- {
- var pandingUserList = listDetail.PendingUserType.Split(',');
- for (int i = 0; i < pandingUserList.Length; i++)
- {
- string userAndrole = pandingUserList[i];
- var userlist = posibleUserList.FirstOrDefault(x => x.LoginID == userAndrole);
-
- if (userlist != null)
- {
- if (userlist.UserID == userID)
- {
- isMatched = true;
- }
- }
- else
- {
-
- foreach (var role in listrole)
- {
- if (userAndrole == role.RoleName)
- {
- isMatched = true;
- }
- }
- }
- }
- }
- if (!isMatched)
- {
- return false;
- }
- if (dataRangeUserFunc != null)
- {
- return dataRangeUserFunc(formIDs, userID);
- }
- return true;
- }
-
-
-
-
-
-
-
-
-
- public bool IsCanApprove(string tableName, Guid userID, Guid actionID, List<Guid> formIDs,
- Func<List<Guid>, Guid, bool> dataRangeUserFunc = null)
- {
- string AppID = this.GetAppIDByTableName(tableName);
- List<string> instanceIDList = new List<string>();
- List<string> list = new List<string>();
-
- var user = UserServices.Value.GetUserByID(userID);
- var role = UserServices.Value.GetUserRoles(userID);
- this.InitVerificationModel();
-
- List<Sys_ProcessRelation> processRelationList = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
- .Where(x => x.TableName == tableName && formIDs.Contains((Guid)x.formID)).ToList();
- if (processRelationList.Count > 0)
- instanceIDList = processRelationList.Select(x => x.InstanceID).ToList();
- PendingWorkResultModel pwrm = client.PendingWorkBatchList(AppID, instanceIDList.ToArray(), vm);
- if (pwrm.doNum == 1)
- {
- var userPendingWorkList = pwrm.resultDataList.GroupBy(x => x.InstanceID)
- .Where(x => !x.Any(n => role.Any(w => w.RoleName == n.PendingUsers) || n.PendingUsers == user.LoginID)).ToList();
- if (userPendingWorkList.Count > 0)
- {
- return false;
- }
- }
- if (dataRangeUserFunc != null)
- {
- return dataRangeUserFunc.Invoke(formIDs, userID);
- }
- return true;
- }
-
-
-
-
-
-
-
- public List<WorkflowPermissionView> IsCanApprove(string tableName, Guid userID, List<Guid> formIDs)
- {
- string AppID = this.GetAppIDByTableName(tableName);
- List<string> instanceIDList = new List<string>();
- List<string> list = new List<string>();
-
- var user = UserServices.Value.GetUserByID(userID);
- var role = UserServices.Value.GetUserRoles(userID);
- this.InitVerificationModel();
-
- List<Sys_ProcessRelation> processRelationList = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
- .Where(x => x.TableName == tableName && formIDs.Contains((Guid)x.formID)).ToList();
- if (processRelationList.Count > 0)
- instanceIDList = processRelationList.Select(x => x.InstanceID).ToList();
- PendingWorkResultModel pwrm = client.PendingWorkBatchList(AppID, instanceIDList.ToArray(), vm);
- if (pwrm.doNum == 1)
- {
- var userPendingWorkList = pwrm.resultDataList.GroupBy(x => x.InstanceID)
- .Where(x => x.Any(n => role.Any(w => w.RoleName == n.PendingUsers) || n.PendingUsers == user.LoginID)).ToList();
- var permissionResult = (from fid in formIDs
- join pr in processRelationList on fid equals pr.formID into dpr
- from pr in dpr.DefaultIfEmpty()
- join upw in userPendingWorkList on pr.InstanceID equals upw.Key into dupw
- from upw in dupw.DefaultIfEmpty()
- select new { FormID = fid, IsCanApprove = (pr != null && upw != null) } into result
- group result by new { result.FormID, result.IsCanApprove } into g
- select new WorkflowPermissionView { FormID = g.Key.FormID, IsCanApprove = g.Key.IsCanApprove }).ToList();
- return permissionResult;
- }
- else
- {
- throw new Exception(pwrm.doMessage);
- }
- }
-
-
-
-
-
-
-
-
-
- public void StartUp(string tableName, Guid formID, Guid userID, Guid actionID, string comment,
- Func<List<Guid>, Guid, bool> dataRangeUserFunc = null)
- {
- try
- {
-
- string AppID = this.GetAppIDByTableName(tableName);
- string instanceID = string.Empty;
- bool isCanSubmit = this.IsCanSubmit(tableName, userID, new List<Guid> { formID }, dataRangeUserFunc);
- if (!isCanSubmit)
- {
- throw new Exception("对不起,您没权限进行操作。");
- }
-
- var user = UserServices.Value.GetUserByID(userID);
- this.InitVerificationModel();
- PlugworkflowServices.NextDetailModel listNetxtDetail = this.GetStatusList(tableName)
- .Where(x => x.Tp == "start").FirstOrDefault();
- var pendingUserList = listNetxtDetail.PendingUserType.Split(',');
-
- Sys_ProcessRelation processRelation = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
- .Where(x => x.TableName == tableName && x.formID == formID).FirstOrDefault();
- if (processRelation != null)
- instanceID = processRelation.InstanceID;
- if (string.IsNullOrEmpty(instanceID))
- {
- var result = client.InstanceProcessStart(AppID, "", user.LoginID, vm);
- if (result.doNum == 1)
- {
- PendingWorkItem pwi = result.resultDataList.FirstOrDefault();
- ProcessRelationServices.Value.ProcessRelationAdd(formID, pwi.InstanceID, tableName);
- }
- else
- {
- throw new Exception(result.doMessage);
- }
- }
- try
- {
-
- var result = client.PendingWorkList("", "", AppID, instanceID, "", "", "A", "1", "100", vm);
- if (result.doNum == 1)
- {
- if (result.resultDataList.Length == 0)
- {
- throw new Exception("该环节并无后续动作,无法提交。");
- }
- var instanceProcessModel = result.resultDataList.FirstOrDefault();
- if (instanceProcessModel.PID == this.GetStartStatus(tableName))
- {
- Approve(tableName, formID, userID, actionID, comment, dataRangeUserFunc);
- }
- else
- {
- throw new Exception("该流程已经提交,不能重复提交。");
- }
- }
- else
- {
- throw new Exception(result.doMessage);
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
-
-
-
-
-
-
-
-
- public void StartUp(string tableName, Guid formID, Guid userID, string comment = "",
- Func<List<Guid>, Guid, bool> dataRangeUserFunc = null)
- {
- this.StartUp(tableName, formID, userID, Guid.Empty, comment, dataRangeUserFunc);
- }
-
-
-
-
-
-
-
-
-
- public void BatchStartUp(string tableName, List<Guid> formIDList, Guid userID, string comment,
- Func<List<Guid>, Guid, bool> dataRangeUserFunc = null)
- {
- try
- {
-
- if (formIDList.Count == 0)
- {
- return;
- }
- string AppID = this.GetAppIDByTableName(tableName);
- List<string> instanceIDList = new List<string>();
- bool isCanSubmit = this.IsCanSubmit(tableName, userID, formIDList, dataRangeUserFunc);
- if (!isCanSubmit)
- {
- throw new Exception("对不起,您没权限进行操作。");
- }
- var newProcessRelationList = new List<BaseProcessRelationView>();
-
- var user = UserServices.Value.GetUserByID(userID);
- this.InitVerificationModel();
- PlugworkflowServices.NextDetailModel listNetxtDetail = this.GetStatusList(tableName)
- .Where(x => x.Tp == "start").FirstOrDefault();
- var pendingUserList = listNetxtDetail.PendingUserType.Split(',');
-
- List<Sys_ProcessRelation> processRelationList = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
- .Where(x => x.TableName == tableName && formIDList.Contains((Guid)x.formID)).ToList();
- if (processRelationList.Count > 0)
- instanceIDList = processRelationList.Select(x => x.InstanceID).ToList();
- var newProcessList = (from fid in formIDList
- join pr in processRelationList on fid equals pr.formID into dpr
- from pr in dpr.DefaultIfEmpty()
- where pr == null
- select fid).ToList();
- if (newProcessList.Count > 0)
- {
- var result = client.InstanceProcessBatchStart(newProcessList.Count, AppID, "", user.LoginID, vm);
- if (result.doNum == 1)
- {
- List<PendingWorkItem> pwi = result.resultDataList.ToList();
- for (var i = 0; i < newProcessList.Count; i ++ )
- {
- newProcessRelationList.Add(new BaseProcessRelationView { FormID = newProcessList[i], InstanceID = pwi[i].InstanceID });
- instanceIDList.Add(pwi[i].InstanceID);
- }
- ProcessRelationServices.Value.ProcessRelationAdd(newProcessRelationList, tableName);
- }
- else
- {
- throw new Exception(result.doMessage);
- }
- }
- try
- {
-
- var result = client.PendingWorkBatchList(AppID, instanceIDList.ToArray(), vm);
- if (result.doNum == 1)
- {
- var noNextList = instanceIDList.Where(x => !result.resultDataList.Select(w => w.InstanceID).Contains(x)).ToList();
- if (noNextList.Count > 0)
- {
- throw new Exception("部分数据在该环节并无后续动作,无法提交,可能由于没有配置相应权限,请联系系统管理员检查。");
- }
- var instanceProcessModel = result.resultDataList.FirstOrDefault();
- if (instanceProcessModel.PID == this.GetStartStatus(tableName))
- {
- BatchApprove(tableName, formIDList, userID, Guid.Empty, comment, dataRangeUserFunc);
- }
- else
- {
- throw new Exception("该流程已经提交,不能重复提交。");
- }
- }
- else
- {
- throw new Exception(result.doMessage);
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
-
-
-
-
-
-
-
-
-
- public void Approve(string tableName, Guid formID, Guid userID, Guid actionID, string comment = "",
- Func<List<Guid>, Guid, bool> dataRangeUserFunc = null)
- {
- try
- {
-
- string AppID = this.GetAppIDByTableName(tableName);
- string instanceID = string.Empty;
- List<string> nextWorkby = new List<string>();
- IList<Sys_User> dataRangeUserList = new List<Sys_User>();
- bool isCanApprove = this.IsCanApprove(tableName, userID, actionID, new List<Guid> { formID }, dataRangeUserFunc);
-
- if (!isCanApprove)
- {
- throw new Exception("对不起,您没权限进行操作。");
- }
-
- var user = UserServices.Value.GetUserByID(userID);
- var roleList = UserServices.Value.GetUserRoles(userID);
- this.InitVerificationModel();
- var startStepList = this.GetStatusList(tableName).Where(x => x.Tp == "start").ToList();
- var endStepList = this.GetStatusList(tableName).Where(x => x.Tp == "end").ToList();
-
- Sys_ProcessRelation processRelation = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
- .Where(x => x.TableName == tableName && x.formID == formID).FirstOrDefault();
- if (processRelation != null)
- instanceID = processRelation.InstanceID;
- PendingWorkResultModel pwrm = client.PendingWorkList("", "", AppID, instanceID, "",
- "", "A", "1", "100", vm);
- if (pwrm.doNum == 1)
- {
- var userPendingWorkList = pwrm.resultDataList.Where(x => roleList.Any(w => w.RoleName == x.PendingUsers) || x.PendingUsers == user.LoginID).ToList();
- if (userPendingWorkList.Count == 0)
- {
- throw new Exception("对不起,您没权限进行操作。");
- }
- foreach (var itempwi in userPendingWorkList)
- {
- if (itempwi.WorkTime == null)
- {
- List<NextStepModel> nextStepList = null;
- var processItemResultModel = client.ProcessLoadNextDetail(itempwi.InstanceProcessID, vm);
- if (processItemResultModel.resultDataItem.Tp == "start")
- {
- throw new Exception("当前流程并未提交,请先提交再进行审核。");
- }
- if (processItemResultModel.resultDataItem.Tp == "end")
- {
- throw new Exception("当前流程已经结束,无法审核。");
- }
-
- if (actionID != null && actionID != Guid.Empty)
- nextStepList = processItemResultModel.resultDataItem.NextSteps
- .Where(x => x.ActionID == actionID.ToString()).ToList();
- else
- nextStepList = processItemResultModel.resultDataItem.NextSteps.ToList();
-
- foreach (var itemnext in nextStepList)
- {
- string nextActionID = itemnext.ActionID.ToString();
- string methodName = itemnext.ActionFunc;
- int pid = itemnext.Pid;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (endStepList.Any(x => x.Pid == pid))
- {
- nextWorkby = new List<string>();
- }
- else
- {
-
- nextWorkby = itemnext.PendingUserType.Split(',').ToList();
- }
- if (nextWorkby.Count == 0 && !endStepList.Any(x => x.Pid == pid))
- {
- throw new Exception("后续的流程环节并没有适合的审批人,无法提交。");
- }
- if (!string.IsNullOrEmpty(methodName))
- {
- ReflectorHelper.RunMethod(methodName, new List<Guid>() { formID }, userID);
- }
-
- ResultModel rm = client.ProcessMoveNext(itempwi.InstanceProcessID, nextActionID
- , new ActionFunc[] { }, nextWorkby.Distinct().ToArray(), comment, user.LoginID, new string[] { }, vm);
- if (rm.doNum != 1)
- throw new Exception(rm.doMessage);
- else
- {
- var entity = UnitOfWork.Set(this.GetEntityType(tableName)).Find(formID);
- dynamic dyEntity = entity;
- var entityType = entity.GetType();
- if (entityType.GetProperty("ApprovalStatus") != null)
- {
- dyEntity.ApprovalStatus = pid;
- }
- else if (entityType.GetProperty("RecordStatus") != null)
- {
- dyEntity.RecordStatus = pid;
- }
- UnitOfWork.Update(dyEntity);
- UnitOfWork.Commit();
- this.SendMobileMQ(formID, nextWorkby.ToArray());
- return;
- }
- }
- }
- }
- }
- else
- {
- throw new Exception(pwrm.doMessage);
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
-
-
-
-
-
-
-
-
-
- public void BatchApprove(string tableName, List<Guid> formIDList, Guid userID, Guid actionID, string comment = "",
- Func<List<Guid>, Guid, bool> dataRangeUserFunc = null)
- {
- try
- {
- if (formIDList.Count == 0)
- {
- return;
- }
-
- string AppID = this.GetAppIDByTableName(tableName);
- List<string> instanceIDList = new List<string>();
- List<string> nextWorkby = new List<string>();
- IList<Sys_User> dataRangeUserList = new List<Sys_User>();
- string approveMethodName = null;
- string nextActionID = null;
- int? pid = null;
- bool isCanApprove = this.IsCanApprove(tableName, userID, actionID, formIDList, dataRangeUserFunc);
-
- if (!isCanApprove)
- {
- throw new Exception("对不起,您没权限进行操作。");
- }
-
- var user = UserServices.Value.GetUserByID(userID);
- var roleList = UserServices.Value.GetUserRoles(userID);
- this.InitVerificationModel();
- var startStepList = this.GetStatusList(tableName).Where(x => x.Tp == "start").ToList();
- var endStepList = this.GetStatusList(tableName).Where(x => x.Tp == "end").ToList();
-
- List<Sys_ProcessRelation> processRelationList = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
- .Where(x => x.TableName == tableName && formIDList.Contains((Guid)x.formID)).ToList();
- if (processRelationList.Count == formIDList.Count)
- instanceIDList = processRelationList.Select(x => x.InstanceID).ToList();
- else
- throw new Exception("部分记录并未提交,无法直接审核。");
- PendingWorkResultModel pwrm = client.PendingWorkBatchList(AppID, instanceIDList.ToArray(), vm);
- if (pwrm.doNum == 1)
- {
- var userPendingWorkList = pwrm.resultDataList.Where(x => roleList.Any(w => w.RoleName == x.PendingUsers) || x.PendingUsers == user.LoginID).ToList();
- if (userPendingWorkList.Select(x => x.InstanceID).Distinct().Count() != formIDList.Count)
- {
- throw new Exception("对不起,对于部分数据,您没权限进行操作,请重新选择数据提交。");
- }
- if (userPendingWorkList.GroupBy(x => new { x.AppID, x.PID }).Count() > 1)
- {
- throw new Exception("需要审批的数据状态不一致,不能批量审核,请重新选择数据提交。");
- }
- var processItemResultModelList = client.ProcessBatchLoadNextDetail(userPendingWorkList.Select(x => x.InstanceProcessID).ToArray(), vm);
- if (processItemResultModelList.doNum != 1)
- {
- throw new Exception("流程信息读取失败。", new Exception(processItemResultModelList.doMessage));
- }
- foreach (var itempwi in userPendingWorkList)
- {
- if (itempwi.WorkTime == null)
- {
- List<NextStepModel> nextStepList = null;
- var processItemResultModel = processItemResultModelList.resultDataItemList.FirstOrDefault(x => x.ID == itempwi.InstanceProcessID);
- if (processItemResultModel == null)
- {
- throw new Exception("流程信息读取失败。");
- }
- if (processItemResultModel.Tp == "start")
- {
- throw new Exception("当前流程并未提交,请先提交再进行审核。");
- }
- if (processItemResultModel.Tp == "end")
- {
- throw new Exception("当前流程已经结束,无法审核。");
- }
-
- if (actionID != null && actionID != Guid.Empty)
- nextStepList = processItemResultModel.NextSteps
- .Where(x => x.ActionID == actionID.ToString()).ToList();
- else
- nextStepList = processItemResultModel.NextSteps.ToList();
-
- foreach (var itemnext in nextStepList)
- {
- nextActionID = itemnext.ActionID.ToString();
- approveMethodName = itemnext.ActionFunc;
- pid = itemnext.Pid;
- if (endStepList.Any(x => x.Pid == pid))
- {
- nextWorkby = new List<string>();
- }
- else
- {
-
- nextWorkby = itemnext.PendingUserType.Split(',').ToList();
- }
- if (nextWorkby.Count == 0 && !endStepList.Any(x => x.Pid == pid))
- {
- throw new Exception("后续的流程环节并没有适合的审批人,无法提交。");
- }
- }
- }
- }
- using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TimeSpan(1, 0, 0)))
- {
- if (!string.IsNullOrEmpty(approveMethodName))
- {
- ReflectorHelper.RunMethod(approveMethodName, formIDList, userID);
- }
-
- ResultModel rm = client.ProcessBatchMoveNext(userPendingWorkList.Select(x => x.InstanceProcessID).ToArray(), nextActionID
- , new ActionFunc[] { }, nextWorkby.Distinct().ToArray(), comment, user.LoginID, new string[] { }, vm);
- if (rm.doNum != 1)
- throw new Exception(rm.doMessage);
- else
- {
- IDictionary<string, object> updateKeyValueList = new Dictionary<string, object>();
- var entityType = this.GetEntityType(tableName);
- if (entityType.GetProperty("ApprovalStatus") != null)
- {
- updateKeyValueList.Add("ApprovalStatus", pid.Value);
- }
- else if (entityType.GetProperty("RecordStatus") != null)
- {
- updateKeyValueList.Add("RecordStatus", pid);
- }
- foreach (var formID in formIDList)
- {
- this.SendMobileMQ(formID, nextWorkby.ToArray());
- }
- UnitOfWork.BatchUpdate(tableName, updateKeyValueList, formIDList);
- scope.Complete();
- return;
- }
- }
- }
- else
- {
- throw new Exception(pwrm.doMessage);
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
-
-
-
-
-
-
-
- public void ModifyProcessState(string tableName, Guid formID, string status, string description)
- {
- try
- {
- string AppID = this.GetAppIDByTableName(tableName);
- string instanceID = string.Empty;
- List<string> list = new List<string>();
-
- Sys_ProcessRelation processRelation = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
- .Where(x => x.TableName == tableName && x.formID == formID).FirstOrDefault();
- if (processRelation != null)
- instanceID = processRelation.InstanceID;
- this.InitVerificationModel();
- ResultModel rm = client.InstanceProcessChange(instanceID, status, description, vm);
- if (rm.doNum != 1)
- {
- throw new Exception(rm.doMessage);
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
-
-
-
-
-
-
-
- public List<ActionView> GetActionView(string tableName, Guid formID, Guid userID)
- {
- try
- {
- List<ActionView> listAction = new List<ActionView>();
- string AppID = this.GetAppIDByTableName(tableName);
- string instanceID = string.Empty;
- Sys_ProcessRelation processRelation = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
- .Where(x => x.formID == formID && x.TableName == tableName).FirstOrDefault();
- if (processRelation != null)
- instanceID = processRelation.InstanceID;
- this.InitVerificationModel();
- var user = UserServices.Value.GetUserByID(userID);
- var role = UserServices.Value.GetUserRoles(userID);
- PendingWorkResultModel pwrm = client.PendingWorkList("", "", AppID, instanceID, "", "", "A", "1", "100", vm);
- if (pwrm != null)
- {
- var userPendingWorkList = pwrm.resultDataList.Where(x => role.Any(w => w.RoleName == x.PendingUsers) || x.PendingUsers == user.LoginID).ToList();
- if (userPendingWorkList.Count == 0)
- {
- throw new Exception("对不起,您没权限进行操作。");
- }
- List<PendingWorkItem> listpwi = userPendingWorkList.Take(1).ToList();
- foreach (var itempwi in listpwi)
- {
- if (itempwi.WorkTime == null)
- {
- var processItemResultModel = client.ProcessLoadNextDetail(itempwi.InstanceProcessID, vm);
- List<NextStepModel> listnext = processItemResultModel.resultDataItem.NextSteps.OrderBy(x => x.sort).ToList();
- foreach (var item in listnext)
- {
- ActionView action = new ActionView();
- action.ActionID = new Guid(item.ActionID);
- action.ActionName = item.AName;
- action.PendingUser = item.PendingUserType;
- action.PendingUserName = item.PendingUser;
- action.StepName = item.PName;
- action.Sort = item.sort;
- action.Description = item.ADescription;
- listAction.Add(action);
- }
- }
- }
- }
- return listAction;
- }
- catch (Exception ex)
- {
- throw (new Exception(ex.Message));
- }
- }
-
-
-
-
-
- public List<ActionView> GetActionView(string tableName)
- {
- try
- {
- List<NextDetailModel> statusLists = GetStatusList(tableName);
- List<ActionView> listAction = new List<ActionView>();
- foreach (var statusList in statusLists)
- {
- foreach (var item in statusList.NextSteps)
- {
- ActionView action = new ActionView();
- action.ActionID = new Guid(item.ActionID);
- action.ActionName = item.AName;
- action.PendingUser = item.PendingUserType;
- action.PendingUserName = item.PendingUser;
- action.StepName = item.PName;
- action.Pid = statusList.Pid;
- action.ToPid = item.Pid;
- action.Sort = item.sort;
- listAction.Add(action);
- }
- }
- return listAction;
- }
- catch (Exception ex)
- {
- throw (new Exception(ex.Message));
- }
- }
-
-
-
-
-
- public List<ActionView> GetStartActionView(string tableName)
- {
- return this.GetStartStatusList(tableName).FirstOrDefault().NextSteps.Select(x => new ActionView
- {
- ActionID = new Guid(x.ActionID),
- ActionName = x.AName,
- StepName = x.AName,
- Sort = x.sort,
- Description = x.ADescription
- }).ToList();
- }
-
-
-
-
-
-
- public IList<ViewModel.SystemView.WorkflowApproveHistoryView> GetApproveHistoryViewList(string tableName, Guid formID)
- {
- try
- {
- string AppID = this.GetAppIDByTableName(tableName);
- string InstanceID = string.Empty;
- List<WorkflowApproveHistoryView> list = new List<WorkflowApproveHistoryView>();
- this.InitVerificationModel();
- Sys_ProcessRelation processRelation = ProcessWorkfloconfigDAL.GetProcessRelationQueryable()
- .Where(x => x.formID == formID && x.TableName == tableName).FirstOrDefault();
- if (processRelation != null)
- InstanceID = processRelation.InstanceID;
- if (!string.IsNullOrEmpty(InstanceID))
- {
- ProcessDetailResultModel processDetailResultModel = client.LoadProcessDetails(AppID, InstanceID, vm);
- List<InstanceProcessModel> listipm = processDetailResultModel.resultDataList
- .Where(x => !string.IsNullOrEmpty(x.WorkBy))
- .OrderBy(x => x.CreateTime).ToList();
- foreach (var lt in listipm)
- {
- string userNo = string.Empty;
- string username = string.Empty;
- if (lt.WorkBy != null)
- {
- var userlist = UserServices.Value.GetUserByLoginID(lt.WorkBy);
- if (userlist != null)
- {
- userNo = userlist.LoginID;
- username = userlist.Name;
- }
- }
- if (!list.Any(x => x.PID == lt.PID && x.ApproveUserName == username
- && x.PName == lt.PName && x.ActionName == lt.ActionName
- && x.ApproveTime == lt.WorkTime.ParseStrTo<DateTime>() && x.Comment == lt.Comment))
- {
- WorkflowApproveHistoryView wahv = new WorkflowApproveHistoryView();
- wahv.ApproveHistoryID = lt.ID.ParseStrTo<Guid>();
- wahv.PID = lt.PID;
- wahv.ApproveUserNo = userNo;
- wahv.ApproveUserName = username;
- wahv.PName = lt.PName;
- wahv.ActionName = lt.ActionName;
- wahv.ApproveTime = lt.WorkTime.ParseStrTo<DateTime>();
- wahv.Comment = lt.Comment;
- list.Add(wahv);
- }
- }
- }
- return list;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
- public IGridResultSet<T> QueryByPendingJob<T, TOrder>(string tableName, IQueryable<T> query, Guid userID,
- Expression<Func<T, Guid>> pkSelector, Expression<Func<T, TOrder>> orderby, bool isDescending = false,
- int? pageIndex = null, int? pageSize = null)
- {
- try
- {
- string AppID = this.GetAppIDByTableName(tableName);
- string InstanceID = string.Empty;
- var user = UserServices.Value.GetUserByID(userID);
- var role = UserServices.Value.GetUserRoles(userID);
- this.InitVerificationModel();
- var queryProessRelation = ProcessWorkfloconfigDAL.processRelationRepository.GetList(x => x.TableName == tableName);
- PendingWorkResultModel pwrm = client.PendingWorkList("", "", AppID, "", "", "", "A",
- ((pageIndex ?? 0) + 1).ToString(), "9999", vm);
-
- if (pwrm.doNum == 1)
- {
- var instanceIDList = pwrm.resultDataList.Where(x => role.Any(w => w.RoleName == x.PendingUsers) || x.PendingUsers == user.LoginID)
- .Select(x => x.InstanceID).ToList();
- var queryprrm = queryProessRelation.Where(x => instanceIDList.Contains(x.InstanceID));
- var result = query.Join(queryprrm, pkSelector, (x => (x.formID ?? Guid.Empty)), ((x, y) => x));
- if (isDescending)
- {
- result = result.OrderByDescending(orderby);
- }
- else
- {
- result = result.OrderBy(orderby);
- }
- return result.ToGridResultSet(pageIndex, pageSize);
- }
- else
- {
- return new GridResultSet<T> { rows = new List<T>(), total = 0 };
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
-
-
-
-
-
- private void SendMobileMQ(Guid formID, string[] nextWorkbyArray)
- {
- if (this.MessageFunc == null)
- {
- return;
- }
- var userIDList = RoleDAL.RoleRepository.GetList(x => nextWorkbyArray.Contains(x.RoleName))
- .SelectMany(x => x.Sys_User).Where(x => x.CF_Student.UserID != null).Distinct()
- .Union(
- RoleDAL.UserRepository.GetList(x => nextWorkbyArray.Contains(x.LoginID))
- .Where(x => x.CF_Student.UserID != null))
- .Select(x => x.UserID).ToList();
- var message = this.MessageFunc.Invoke(formID);
- MobileMQ.SendMessage(userIDList.Select(x => x.ToString()).ToArray(), message);
- }
- }
- }
|