12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046 |
- using LeaRun.Application.Code;
- using LeaRun.Application.Entity.BaseManage;
- using LeaRun.Application.Entity.FlowManage;
- using LeaRun.Application.Entity.SystemManage;
- using LeaRun.Application.IService.BaseManage;
- using LeaRun.Application.IService.FlowManage;
- using LeaRun.Application.IService.SystemManage;
- using LeaRun.Application.Service.BaseManage;
- using LeaRun.Application.Service.SystemManage;
- using LeaRun.Data.Repository;
- using LeaRun.Util;
- using LeaRun.Util.FlowWork;
- using System;
- using System.Collections.Generic;
- using System.Data;
- namespace LeaRun.Application.Service.FlowManage
- {
- /// <summary>
- /// 版 本 6.1
- /// Copyright (c) 2013-2016 上海力软信息技术有限公司
- /// 创建人:陈彬彬
- /// 日 期:2016.04.12 15:54
- /// 描 述:工作流运行实例处理方法类
- /// </summary>
- public class WFRuntimeService :RepositoryFactory, WFRuntimeIService
- {
- private WFSchemeInfoIService wfSchemeInfoService = new WFSchemeInfoService();
- private WFSchemeContentIService wfSchemeContentService = new WFSchemeContentService();
- private WFProcessInstanceIService wfProcessInstanceService = new WFProcessInstanceService();
- private WFProcessSchemeIService wfProcessSchemeService = new WFProcessSchemeService();
- private WFProcessOperationHistoryIService wfProcessOperationHistoryService = new WFProcessOperationHistoryService();
- private WFProcessTransitionHistoryIService wfProcessTransitionHistoryService = new WFProcessTransitionHistoryService();
- private WFDelegateRuleIService wfDelegateRuleService = new WFDelegateRuleService();
- private IUserService userService = new UserService();//用户数据库操作类
- private IDepartmentService departmentService = new DepartmentService();
- private IOrganizeService organizeService = new OrganizeService();
- private IDataBaseLinkService dataBaseLinkService = new DataBaseLinkService();
- private string delegateUserList = "";
- #region 流程处理API
- /// <summary>
- /// 创建一个实例
- /// </summary>
- /// <param name="processId">进程GUID</param>
- /// <param name="schemeInfoId">模板信息ID</param>
- /// <param name="wfLevel"></param>
- /// <param name="code">进程编号</param>
- /// <param name="customName">自定义名称</param>
- /// <param name="description">备注</param>
- /// <param name="frmData">表单数据信息</param>
- /// <returns></returns>
- public bool CreateInstance(Guid processId, string schemeInfoId, WFProcessInstanceEntity wfProcessInstanceEntity, string frmData = null)
- {
-
- try
- {
- WFSchemeInfoEntity wfSchemeInfoEntity = wfSchemeInfoService.GetEntity(schemeInfoId);
- WFSchemeContentEntity wfSchemeContentEntity = wfSchemeContentService.GetEntity(schemeInfoId, wfSchemeInfoEntity.SchemeVersion);
- WF_RuntimeInitModel wfRuntimeInitModel = new WF_RuntimeInitModel()
- {
- schemeContent = wfSchemeContentEntity.SchemeContent,
- currentNodeId = "",
- frmData = frmData,
- processId = processId.ToString()
- };
- IWF_Runtime wfruntime = null;
- if (wfSchemeInfoEntity.FrmType == 0)
- {
- if(frmData == null)
- {
- throw new Exception("自定义表单需要提交表单数据");
- }
- else
- {
- wfruntime = new WF_Runtime(wfRuntimeInitModel);
- }
- }
- else
- {
- wfruntime = new WF_Runtime(wfRuntimeInitModel, GetFrmData);
- }
-
- #region 实例信息
- wfProcessInstanceEntity.ActivityId = wfruntime.runtimeModel.nextNodeId;
- wfProcessInstanceEntity.ActivityType = wfruntime.GetStatus();//-1无法运行,0会签开始,1会签结束,2一般节点,4流程运行结束
- wfProcessInstanceEntity.ActivityName = wfruntime.runtimeModel.nextNode.name;
- wfProcessInstanceEntity.PreviousId = wfruntime.runtimeModel.currentNodeId;
- wfProcessInstanceEntity.SchemeType = wfSchemeInfoEntity.SchemeType;
- wfProcessInstanceEntity.FrmType = wfSchemeInfoEntity.FrmType;
- wfProcessInstanceEntity.EnabledMark = 1;//正式运行
- wfProcessInstanceEntity.MakerList =(wfruntime.GetStatus() != 4 ? GetMakerList(wfruntime) : "");//当前节点可执行的人信息
- wfProcessInstanceEntity.isFinish = (wfruntime.GetStatus() == 4 ? 1 : 0);
- #endregion
- #region 实例模板
- var data = new
- {
- SchemeContent = wfSchemeContentEntity.SchemeContent,
- frmData = frmData
- };
- WFProcessSchemeEntity wfProcessSchemeEntity = new WFProcessSchemeEntity {
- WFSchemeInfoId = schemeInfoId,
- SchemeVersion = wfSchemeInfoEntity.SchemeVersion,
- ProcessType = 1,//1正式,0草稿
- SchemeContent = data.ToJson().ToString()
- };
- #endregion
- #region 流程操作记录
- WFProcessOperationHistoryEntity processOperationHistoryEntity = new WFProcessOperationHistoryEntity();
- processOperationHistoryEntity.Content = "【创建】" + OperatorProvider.Provider.Current().UserName + "创建了一个流程进程【" + wfProcessInstanceEntity.Code + "/" + wfProcessInstanceEntity.CustomName + "】";
- #endregion
- #region 流转记录
- WFProcessTransitionHistoryEntity processTransitionHistoryEntity = new WFProcessTransitionHistoryEntity();
- processTransitionHistoryEntity.fromNodeId = wfruntime.runtimeModel.currentNodeId;
- processTransitionHistoryEntity.fromNodeName = wfruntime.runtimeModel.currentNode.name.Value;
- processTransitionHistoryEntity.fromNodeType = wfruntime.runtimeModel.currentNodeType;
- processTransitionHistoryEntity.toNodeId = wfruntime.runtimeModel.nextNodeId;
- processTransitionHistoryEntity.toNodeName = wfruntime.runtimeModel.nextNode.name.Value;
- processTransitionHistoryEntity.toNodeType = wfruntime.runtimeModel.nextNodeType;
- processTransitionHistoryEntity.TransitionSate =0;
- processTransitionHistoryEntity.isFinish = (processTransitionHistoryEntity.toNodeType == 4 ? 1 : 0);
- #endregion
- #region 委托记录
- List<WFDelegateRecordEntity> delegateRecordEntitylist = GetDelegateRecordList(schemeInfoId, wfProcessInstanceEntity.Code, wfProcessInstanceEntity.CustomName, wfProcessInstanceEntity.MakerList);
- wfProcessInstanceEntity.MakerList += delegateUserList;
- #endregion
- wfProcessInstanceService.SaveProcess(wfruntime.runtimeModel, wfProcessInstanceEntity, wfProcessSchemeEntity, processOperationHistoryEntity, processTransitionHistoryEntity, delegateRecordEntitylist);
- return true;
- }
- catch
- {
- throw;
- }
-
- }
- /// <summary>
- /// 创建一个实例(草稿创建)
- /// </summary>
- /// <param name="processId"></param>
- /// <param name="code"></param>
- /// <param name="customName"></param>
- /// <param name="description"></param>
- /// <param name="frmData"></param>
- /// <returns></returns>
- public bool CreateInstance(WFProcessInstanceEntity wfProcessInstanceEntity, string frmData = null)
- {
- try
- {
- WFProcessInstanceEntity _wfProcessInstanceEntity = wfProcessInstanceService.GetEntity(wfProcessInstanceEntity.Id);
- WFProcessSchemeEntity wfProcessSchemeEntity = wfProcessSchemeService.GetEntity(wfProcessInstanceEntity.ProcessSchemeId);
- dynamic schemeContentJson = wfProcessSchemeEntity.SchemeContent.ToJson();//获取工作流模板内容的json对象;
- WF_RuntimeInitModel wfRuntimeInitModel = new WF_RuntimeInitModel()
- {
- schemeContent = schemeContentJson.SchemeContent.Value,
- currentNodeId = "",
- frmData = frmData,
- processId = wfProcessSchemeEntity.Id
- };
- IWF_Runtime wfruntime = null;
- if (_wfProcessInstanceEntity.FrmType == 0)
- {
- if (frmData == null)
- {
- throw new Exception("自定义表单需要提交表单数据");
- }
- else
- {
- wfruntime = new WF_Runtime(wfRuntimeInitModel);
- }
-
- }
- else
- {
- wfruntime = new WF_Runtime(wfRuntimeInitModel, GetFrmData);
- }
- #region 实例信息
- wfProcessInstanceEntity.ActivityId = wfruntime.runtimeModel.nextNodeId;
- wfProcessInstanceEntity.ActivityType = wfruntime.GetStatus();//-1无法运行,0会签开始,1会签结束,2一般节点,4流程运行结束
- wfProcessInstanceEntity.ActivityName = wfruntime.runtimeModel.nextNode.name;
- wfProcessInstanceEntity.PreviousId = wfruntime.runtimeModel.currentNodeId;
- wfProcessInstanceEntity.EnabledMark = 1;//正式运行
- wfProcessInstanceEntity.MakerList = (wfruntime.GetStatus() != 4 ? GetMakerList(wfruntime) : "");//当前节点可执行的人信息
- wfProcessInstanceEntity.isFinish = (wfruntime.GetStatus() == 4 ? 1 : 0);
- #endregion
- #region 实例模板
- var data = new
- {
- SchemeContent = schemeContentJson.SchemeContent.Value,
- frmData = frmData
- };
- wfProcessSchemeEntity.ProcessType = 1;//1正式,0草稿
- wfProcessSchemeEntity.SchemeContent = data.ToJson().ToString();
- #endregion
- #region 流程操作记录
- WFProcessOperationHistoryEntity processOperationHistoryEntity = new WFProcessOperationHistoryEntity();
- processOperationHistoryEntity.Content = "【创建】" + OperatorProvider.Provider.Current().UserName + "创建了一个流程进程【" + wfProcessInstanceEntity.Code + "/" + wfProcessInstanceEntity.CustomName + "】";
- #endregion
- #region 流转记录
- WFProcessTransitionHistoryEntity processTransitionHistoryEntity = new WFProcessTransitionHistoryEntity();
- processTransitionHistoryEntity.fromNodeId = wfruntime.runtimeModel.currentNodeId;
- processTransitionHistoryEntity.fromNodeName = wfruntime.runtimeModel.currentNode.name.Value;
- processTransitionHistoryEntity.fromNodeType = wfruntime.runtimeModel.currentNodeType;
- processTransitionHistoryEntity.toNodeId = wfruntime.runtimeModel.nextNodeId;
- processTransitionHistoryEntity.toNodeName = wfruntime.runtimeModel.nextNode.name.Value;
- processTransitionHistoryEntity.toNodeType = wfruntime.runtimeModel.nextNodeType;
- processTransitionHistoryEntity.TransitionSate = 0;
- processTransitionHistoryEntity.isFinish = (processTransitionHistoryEntity.toNodeType == 4 ? 1 : 0);
- #endregion
- #region 委托记录
- List<WFDelegateRecordEntity> delegateRecordEntitylist = GetDelegateRecordList(wfProcessSchemeEntity.WFSchemeInfoId, wfProcessInstanceEntity.Code, wfProcessInstanceEntity.CustomName, wfProcessInstanceEntity.MakerList);
- wfProcessInstanceEntity.MakerList += delegateUserList;
- #endregion
- wfProcessInstanceService.SaveProcess(wfruntime.runtimeModel, wfProcessInstanceEntity, wfProcessSchemeEntity, processOperationHistoryEntity, processTransitionHistoryEntity, delegateRecordEntitylist);
- return true;
- }
- catch
- {
- throw;
- }
- }
- /// <summary>
- /// 编辑表单再次提交(驳回后处理)
- /// </summary>
- /// <param name="processId"></param>
- /// <param name="description"></param>
- /// <param name="frmData"></param>
- /// <returns></returns>
- public bool EditionInstance(string processId, string description, string frmData = null)
- {
- try
- {
- WFProcessInstanceEntity wfProcessInstanceEntity = wfProcessInstanceService.GetEntity(processId);
- WFProcessSchemeEntity wfProcessSchemeEntity = wfProcessSchemeService.GetEntity(wfProcessInstanceEntity.ProcessSchemeId);
- dynamic schemeContentJson = wfProcessSchemeEntity.SchemeContent.ToJson();//获取工作流模板内容的json对象;
- var data = new
- {
- SchemeContent = schemeContentJson.SchemeContent.Value,
- frmData = frmData
- };
- wfProcessSchemeEntity.SchemeContent = data.ToJson().ToString();
- wfProcessInstanceEntity.isFinish = 0;
- if (string.IsNullOrEmpty(description))
- {
- wfProcessInstanceEntity.Description = description;
- }
- wfProcessInstanceEntity.CreateDate = DateTime.Now;
- #region 流程操作记录
- WFProcessOperationHistoryEntity processOperationHistoryEntity = new WFProcessOperationHistoryEntity();
- processOperationHistoryEntity.Content = "【创建】" + OperatorProvider.Provider.Current().UserName + "创建了一个流程进程【" + wfProcessInstanceEntity.Code + "/" + wfProcessInstanceEntity.CustomName + "】";
- #endregion
- #region 委托记录
- List<WFDelegateRecordEntity> delegateRecordEntitylist = GetDelegateRecordList(wfProcessSchemeEntity.WFSchemeInfoId, wfProcessInstanceEntity.Code, wfProcessInstanceEntity.CustomName, wfProcessInstanceEntity.MakerList);
- wfProcessInstanceEntity.MakerList += delegateUserList;
- #endregion
- wfProcessInstanceService.SaveProcess(wfProcessInstanceEntity, wfProcessSchemeEntity, processOperationHistoryEntity, delegateRecordEntitylist);
- return true;
- }
- catch
- {
- throw;
- }
- }
- /// <summary>
- /// 创建一个草稿
- /// </summary>
- /// <param name="processId"></param>
- /// <param name="schemeInfoId"></param>
- /// <param name="wfLevel"></param>
- /// <param name="code"></param>
- /// <param name="customName"></param>
- /// <param name="description"></param>
- /// <param name="frmData"></param>
- /// <returns></returns>
- public bool CreateRoughdraft(Guid processId, string schemeInfoId, WFProcessInstanceEntity wfProcessInstanceEntity, string frmData = null)
- {
- try
- {
- WFSchemeInfoEntity wfSchemeInfoEntity = wfSchemeInfoService.GetEntity(schemeInfoId);
- WFSchemeContentEntity wfSchemeContentEntity = wfSchemeContentService.GetEntity(schemeInfoId, wfSchemeInfoEntity.SchemeVersion);
-
- wfProcessInstanceEntity.ActivityId = "";
- wfProcessInstanceEntity.ActivityName = "";
- wfProcessInstanceEntity.ActivityType = 0;//开始节点
- wfProcessInstanceEntity.isFinish = 0;
- wfProcessInstanceEntity.SchemeType = wfSchemeInfoEntity.SchemeType;
- wfProcessInstanceEntity.EnabledMark = 3;//草稿
- wfProcessInstanceEntity.CreateDate = DateTime.Now;
- wfProcessInstanceEntity.FrmType = wfSchemeInfoEntity.FrmType;
- WFProcessSchemeEntity wfProcessSchemeEntity = new WFProcessSchemeEntity();
- wfProcessSchemeEntity.WFSchemeInfoId = schemeInfoId;
- wfProcessSchemeEntity.SchemeVersion = wfSchemeInfoEntity.SchemeVersion;
- wfProcessSchemeEntity.ProcessType = wfProcessInstanceEntity.EnabledMark;
- var data = new
- {
- SchemeContent = wfSchemeContentEntity.SchemeContent,
- frmData = frmData
- };
- wfProcessSchemeEntity.SchemeContent = data.ToJson().ToString();
- wfProcessInstanceService.SaveProcess(processId.ToString(),wfProcessInstanceEntity, wfProcessSchemeEntity);
- return true;
- }
- catch
- {
- throw;
- }
- }
- /// <summary>
- /// 创建一个草稿
- /// </summary>
- /// <param name="wfProcessInstanceEntity"></param>
- /// <param name="frmData"></param>
- /// <returns></returns>
- public bool EditionRoughdraft(WFProcessInstanceEntity wfProcessInstanceEntity, string frmData = null)
- {
- try
- {
- WFProcessSchemeEntity wfProcessSchemeEntity = wfProcessSchemeService.GetEntity(wfProcessInstanceEntity.ProcessSchemeId);
- dynamic schemeContentJson = wfProcessSchemeEntity.SchemeContent.ToJson();//获取工作流模板内容的json对象;
- var data = new
- {
- SchemeContent = schemeContentJson.SchemeContent.Value,
- frmData = frmData
- };
- wfProcessSchemeEntity.SchemeContent = data.ToJson().ToString();
- wfProcessInstanceEntity.isFinish = 0;
- wfProcessInstanceEntity.CreateDate = DateTime.Now;
- wfProcessInstanceService.SaveProcess(wfProcessInstanceEntity.Id,wfProcessInstanceEntity, wfProcessSchemeEntity);
- return true;
- }
- catch
- {
- throw;
- }
- }
- /// <summary>
- /// 节点审核
- /// </summary>
- /// <param name="processId"></param>
- /// <returns></returns>
- public bool NodeVerification(string processId, bool flag, string description = "")
- {
- bool _res = false;
- try
- {
- string _sqlstr="", _dbbaseId="";
- WFProcessInstanceEntity wfProcessInstanceEntity = wfProcessInstanceService.GetEntity(processId);
- WFProcessSchemeEntity wfProcessSchemeEntity = wfProcessSchemeService.GetEntity(wfProcessInstanceEntity.ProcessSchemeId);
- WFProcessOperationHistoryEntity wfProcessOperationHistoryEntity = new WFProcessOperationHistoryEntity();//操作记录
- WFProcessTransitionHistoryEntity processTransitionHistoryEntity = null;//流转记录
- List<WFDelegateRecordEntity> delegateRecordEntitylist = new List<WFDelegateRecordEntity>();//委托记录
- dynamic schemeContentJson = wfProcessSchemeEntity.SchemeContent.ToJson();//获取工作流模板内容的json对象;
- WF_RuntimeInitModel wfRuntimeInitModel = new WF_RuntimeInitModel()
- {
- schemeContent = schemeContentJson.SchemeContent.Value,
- currentNodeId = wfProcessInstanceEntity.ActivityId,
- frmData = schemeContentJson.frmData.Value,
- previousId = wfProcessInstanceEntity.PreviousId,
- processId = processId
- };
- IWF_Runtime wfruntime = null;
- if (wfProcessInstanceEntity.FrmType == 0)//自定义表单
- {
- wfruntime = new WF_Runtime(wfRuntimeInitModel);
- }
- else
- {
- wfruntime = new WF_Runtime(wfRuntimeInitModel, GetFrmData);
- }
- #region 会签
- if (wfProcessInstanceEntity.ActivityType == 0)//会签
- {
- wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, 1,"");//标记当前节点通过
- ///寻找需要审核的节点Id
- string _VerificationNodeId = "";
- List<string> _nodelist = wfruntime.GetCountersigningNodeIdList(wfruntime.runtimeModel.currentNodeId);
- string _makerList = "";
- foreach (string item in _nodelist)
- {
- _makerList = GetMakerList(wfruntime.runtimeModel.nodeDictionary[item], wfruntime.runtimeModel.processId);
- if (_makerList != "-1")
- {
- foreach (string one in _makerList.Split(','))
- {
- if (OperatorProvider.Provider.Current().UserId == one || OperatorProvider.Provider.Current().ObjectId.IndexOf(one) != -1)
- {
- _VerificationNodeId = item;
- break;
- }
- }
- }
- }
- if (_VerificationNodeId != "")
- {
- if (flag)
- {
- wfProcessOperationHistoryEntity.Content = "【" + OperatorProvider.Provider.Current().UserName + "】【" + wfruntime.runtimeModel.nodeDictionary[_VerificationNodeId].name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】同意,备注:" + description;
- }
- else
- {
- wfProcessOperationHistoryEntity.Content = "【" + OperatorProvider.Provider.Current().UserName + "】【" + wfruntime.runtimeModel.nodeDictionary[_VerificationNodeId].name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】不同意,备注:" + description;
- }
- string _Confluenceres = wfruntime.NodeConfluence(_VerificationNodeId, flag, OperatorProvider.Provider.Current().UserId, description);
- var _data = new {
- SchemeContent = wfruntime.runtimeModel.schemeContentJson.ToString(),
- frmData = (wfProcessInstanceEntity.FrmType == 0?wfruntime.runtimeModel.frmData:null)
- };
- wfProcessSchemeEntity.SchemeContent = _data.ToJson().ToString();
- switch (_Confluenceres)
- {
- case "-1"://不通过
- wfProcessInstanceEntity.isFinish = 3;
- break;
- case "1"://等待
- break;
- default://通过
- wfProcessInstanceEntity.PreviousId = wfProcessInstanceEntity.ActivityId;
- wfProcessInstanceEntity.ActivityId = wfruntime.runtimeModel.nextNodeId;
- wfProcessInstanceEntity.ActivityType = wfruntime.runtimeModel.nextNodeType;//-1无法运行,0会签开始,1会签结束,2一般节点,4流程运行结束
- wfProcessInstanceEntity.ActivityName = wfruntime.runtimeModel.nextNode.name;
- wfProcessInstanceEntity.isFinish = (wfruntime.runtimeModel.nextNodeType == 4 ? 1 : 0);
- wfProcessInstanceEntity.MakerList = (wfruntime.runtimeModel.nextNodeType == 4 ? GetMakerList(wfruntime) : "");//当前节点可执行的人信息
-
- #region 流转记录
- processTransitionHistoryEntity = new WFProcessTransitionHistoryEntity();
- processTransitionHistoryEntity.fromNodeId = wfruntime.runtimeModel.currentNodeId;
- processTransitionHistoryEntity.fromNodeName = wfruntime.runtimeModel.currentNode.name.Value;
- processTransitionHistoryEntity.fromNodeType = wfruntime.runtimeModel.currentNodeType;
- processTransitionHistoryEntity.toNodeId = wfruntime.runtimeModel.nextNodeId;
- processTransitionHistoryEntity.toNodeName = wfruntime.runtimeModel.nextNode.name.Value;
- processTransitionHistoryEntity.toNodeType = wfruntime.runtimeModel.nextNodeType;
- processTransitionHistoryEntity.TransitionSate = 0;
- processTransitionHistoryEntity.isFinish = (processTransitionHistoryEntity.toNodeType == 4 ? 1 : 0);
- #endregion
- #region 委托记录
- WFDelegateRecordEntity delegateRecordEntity = null;
- DataTable dt = wfDelegateRuleService.GetEntityBySchemeInfoId(wfProcessSchemeEntity.WFSchemeInfoId, wfProcessInstanceEntity.MakerList.Split(','));
- foreach (DataRow dr in dt.Rows)
- {
- if (!string.IsNullOrEmpty(dr["Id"].ToString()))
- {
- delegateRecordEntity = new WFDelegateRecordEntity();
- delegateRecordEntity.WFDelegateRuleId = dr["Id"].ToString();
- delegateRecordEntity.FromUserId = dr["CreateUserId"].ToString();
- delegateRecordEntity.FromUserName = dr["CreateUserName"].ToString();
- delegateRecordEntity.ToUserId = dr["ToUserId"].ToString();
- delegateRecordEntity.ToUserName = dr["ToUserName"].ToString();
- delegateRecordEntity.ProcessCode = wfProcessInstanceEntity.Code;
- delegateRecordEntity.ProcessName = wfProcessInstanceEntity.CustomName;
- delegateRecordEntitylist.Add(delegateRecordEntity);
- wfProcessInstanceEntity.MakerList += "," + dr["ToUserId"].ToString();
- }
- }
- #endregion
- if (wfruntime.runtimeModel.currentNode.setInfo != null && wfruntime.runtimeModel.currentNode.setInfo.NodeSQL != null)
- {
- _sqlstr = wfruntime.runtimeModel.currentNode.setInfo.NodeSQL.Value;
- _dbbaseId = wfruntime.runtimeModel.currentNode.setInfo.NodeDataBaseToSQL.Value;
- }
- break;
- }
- }
- else
- {
- throw(new Exception("审核异常,找不到审核节点"));
- }
- }
- #endregion
- #region 一般审核
- else//一般审核
- {
- if (flag)
- {
- wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, 1, OperatorProvider.Provider.Current().UserId, description);
- wfProcessInstanceEntity.PreviousId = wfProcessInstanceEntity.ActivityId;
- wfProcessInstanceEntity.ActivityId = wfruntime.runtimeModel.nextNodeId;
- wfProcessInstanceEntity.ActivityType = wfruntime.runtimeModel.nextNodeType;//-1无法运行,0会签开始,1会签结束,2一般节点,4流程运行结束
- wfProcessInstanceEntity.ActivityName = wfruntime.runtimeModel.nextNode.name;
- wfProcessInstanceEntity.MakerList = (wfruntime.runtimeModel.nextNodeType == 4 ? GetMakerList(wfruntime) : "");//当前节点可执行的人信息
- wfProcessInstanceEntity.isFinish = (wfruntime.runtimeModel.nextNodeType == 4 ? 1 : 0);
- #region 流转记录
- processTransitionHistoryEntity = new WFProcessTransitionHistoryEntity();
- processTransitionHistoryEntity.fromNodeId = wfruntime.runtimeModel.currentNodeId;
- processTransitionHistoryEntity.fromNodeName = wfruntime.runtimeModel.currentNode.name.Value;
- processTransitionHistoryEntity.fromNodeType = wfruntime.runtimeModel.currentNodeType;
- processTransitionHistoryEntity.toNodeId = wfruntime.runtimeModel.nextNodeId;
- processTransitionHistoryEntity.toNodeName = wfruntime.runtimeModel.nextNode.name.Value;
- processTransitionHistoryEntity.toNodeType = wfruntime.runtimeModel.nextNodeType;
- processTransitionHistoryEntity.TransitionSate = 0;
- processTransitionHistoryEntity.isFinish = (processTransitionHistoryEntity.toNodeType == 4 ? 1 : 0);
- #endregion
- #region 委托记录
- WFDelegateRecordEntity delegateRecordEntity = null;
-
- DataTable dt = wfDelegateRuleService.GetEntityBySchemeInfoId(wfProcessSchemeEntity.WFSchemeInfoId, wfProcessInstanceEntity.MakerList.Split(','));
- foreach (DataRow dr in dt.Rows)
- {
- if (!string.IsNullOrEmpty(dr["Id"].ToString()))
- {
- delegateRecordEntity = new WFDelegateRecordEntity();
- delegateRecordEntity.WFDelegateRuleId = dr["Id"].ToString();
- delegateRecordEntity.FromUserId = dr["CreateUserId"].ToString();
- delegateRecordEntity.FromUserName = dr["CreateUserName"].ToString();
- delegateRecordEntity.ToUserId = dr["ToUserId"].ToString();
- delegateRecordEntity.ToUserName = dr["ToUserName"].ToString();
- delegateRecordEntity.ProcessCode = wfProcessInstanceEntity.Code;
- delegateRecordEntity.ProcessName = wfProcessInstanceEntity.CustomName;
- delegateRecordEntitylist.Add(delegateRecordEntity);
- wfProcessInstanceEntity.MakerList += "," + dr["ToUserId"].ToString();
- }
- }
- #endregion
- if (wfruntime.runtimeModel.currentNode.setInfo != null && wfruntime.runtimeModel.currentNode.setInfo.NodeSQL != null)
- {
- _sqlstr = wfruntime.runtimeModel.currentNode.setInfo.NodeSQL.Value;
- _dbbaseId = wfruntime.runtimeModel.currentNode.setInfo.NodeDataBaseToSQL.Value;
- }
-
- wfProcessOperationHistoryEntity.Content = "【" + OperatorProvider.Provider.Current().UserName + "】【" + wfruntime.runtimeModel.currentNode.name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】同意,备注:" + description;
- }
- else
- {
- wfProcessInstanceEntity.isFinish = 3; //表示该节点不同意
- wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, -1, OperatorProvider.Provider.Current().UserId, description);
- wfProcessOperationHistoryEntity.Content = "【" + OperatorProvider.Provider.Current().UserName + "】【" + wfruntime.runtimeModel.currentNode.name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】不同意,备注:" + description;
- }
- var data = new
- {
- SchemeContent = wfruntime.runtimeModel.schemeContentJson.ToString(),
- frmData = (wfProcessInstanceEntity.FrmType == 0 ? wfruntime.runtimeModel.frmData : null)
- };
- wfProcessSchemeEntity.SchemeContent = data.ToJson().ToString();
- }
- #endregion
- _res = true;
- wfProcessInstanceService.SaveProcess(_sqlstr, _dbbaseId,wfProcessInstanceEntity, wfProcessSchemeEntity, wfProcessOperationHistoryEntity, delegateRecordEntitylist, processTransitionHistoryEntity);
- return _res;
- }
- catch {
- throw;
- }
- }
- /// <summary>
- /// 驳回
- /// </summary>
- /// <param name="processId"></param>
- /// <param name="nodeId"></param>
- /// <param name="description"></param>
- /// <returns></returns>
- public bool NodeReject(string processId,string nodeId, string description = "")
- {
- try
- {
- WFProcessInstanceEntity wfProcessInstanceEntity = wfProcessInstanceService.GetEntity(processId);
- WFProcessSchemeEntity wfProcessSchemeEntity = wfProcessSchemeService.GetEntity(wfProcessInstanceEntity.ProcessSchemeId);
- WFProcessOperationHistoryEntity wfProcessOperationHistoryEntity = new WFProcessOperationHistoryEntity();
- WFProcessTransitionHistoryEntity processTransitionHistoryEntity = null;
- dynamic schemeContentJson = wfProcessSchemeEntity.SchemeContent.ToJson();//获取工作流模板内容的json对象;
- WF_RuntimeInitModel wfRuntimeInitModel = new WF_RuntimeInitModel()
- {
- schemeContent = schemeContentJson.SchemeContent.Value,
- currentNodeId = wfProcessInstanceEntity.ActivityId,
- frmData = schemeContentJson.frmData.Value,
- previousId = wfProcessInstanceEntity.PreviousId,
- processId = processId
- };
- IWF_Runtime wfruntime = null;
- if (wfProcessInstanceEntity.FrmType == 0)//自定义表单
- {
- wfruntime = new WF_Runtime(wfRuntimeInitModel);
- }
- else
- {
- wfruntime = new WF_Runtime(wfRuntimeInitModel, GetFrmData);
- }
- string resnode = "";
- if (nodeId == "")
- {
- resnode = wfruntime.RejectNode();
- }
- else
- {
- resnode = nodeId;
- }
- wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, 0, OperatorProvider.Provider.Current().UserId, description);
- wfProcessInstanceEntity.isFinish = 4;//4表示驳回(需要申请者重新提交表单)
- if (resnode != "")
- {
- wfProcessInstanceEntity.PreviousId = wfProcessInstanceEntity.ActivityId;
- wfProcessInstanceEntity.ActivityId = resnode;
- wfProcessInstanceEntity.ActivityType = wfruntime.GetNodeStatus(resnode);//-1无法运行,0会签开始,1会签结束,2一般节点,4流程运行结束
- wfProcessInstanceEntity.ActivityName = wfruntime.runtimeModel.nodeDictionary[resnode].name;
- wfProcessInstanceEntity.MakerList = GetMakerList(wfruntime.runtimeModel.nodeDictionary[resnode], wfProcessInstanceEntity.PreviousId);//当前节点可执行的人信息
- #region 流转记录
- processTransitionHistoryEntity = new WFProcessTransitionHistoryEntity();
- processTransitionHistoryEntity.fromNodeId = wfruntime.runtimeModel.currentNodeId;
- processTransitionHistoryEntity.fromNodeName = wfruntime.runtimeModel.currentNode.name.Value;
- processTransitionHistoryEntity.fromNodeType = wfruntime.runtimeModel.currentNodeType;
- processTransitionHistoryEntity.toNodeId = wfruntime.runtimeModel.nextNodeId;
- processTransitionHistoryEntity.toNodeName = wfruntime.runtimeModel.nextNode.name.Value;
- processTransitionHistoryEntity.toNodeType = wfruntime.runtimeModel.nextNodeType;
- processTransitionHistoryEntity.TransitionSate = 1;//
- processTransitionHistoryEntity.isFinish = (processTransitionHistoryEntity.toNodeType == 4 ? 1 : 0);
- #endregion
- }
- var data = new
- {
- SchemeContent = wfruntime.runtimeModel.schemeContentJson.ToString(),
- frmData = (wfProcessInstanceEntity.FrmType == 0 ? wfruntime.runtimeModel.frmData : null)
- };
- wfProcessSchemeEntity.SchemeContent = data.ToJson().ToString();
- wfProcessOperationHistoryEntity.Content = "【" + OperatorProvider.Provider.Current().UserName + "】【" + wfruntime.runtimeModel.currentNode.name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】驳回,备注:" + description;
- wfProcessInstanceService.SaveProcess(wfProcessInstanceEntity, wfProcessSchemeEntity, wfProcessOperationHistoryEntity,null, processTransitionHistoryEntity);
- return true;
- }
- catch
- {
- throw;
- }
- }
- /// <summary>
- /// 召回流程进程
- /// </summary>
- /// <param name="processId"></param>
- public void CallingBackProcess(string processId)
- {
- try
- {
- wfProcessInstanceService.OperateVirtualProcess(processId,2);
- }
- catch
- {
- throw;
- }
- }
- /// <summary>
- /// 终止一个实例(彻底删除)
- /// </summary>
- /// <param name="processId"></param>
- /// <returns></returns>
- public void KillProcess(string processId)
- {
- try
- {
- wfProcessInstanceService.DeleteProcess(processId);
- }
- catch
- {
- throw;
- }
- }
- /// <summary>
- /// 获取某个节点(审核人所能看到的提交表单的权限)
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public string GetProcessSchemeContentByNodeId(string data, string nodeId)
- {
- try
- {
- List<dynamic> list = new List<dynamic>();
- dynamic schemeContentJson = data.ToJson();//获取工作流模板内容的json对象;
- string schemeContent1 = schemeContentJson.SchemeContent.Value;
- dynamic schemeContentJson1 = schemeContent1.ToJson();
- string FrmContent = schemeContentJson1.Frm.FrmContent.Value;
- dynamic FrmContentJson = FrmContent.ToJson();
- foreach (var item in schemeContentJson1.Flow.nodes)
- {
- if (item.id.Value == nodeId)
- {
- foreach (var item1 in item.setInfo.frmPermissionInfo)
- {
- foreach (var item2 in FrmContentJson)
- {
- if (item2.control_field.Value == item1.fieldid.Value)
- {
- if (item1.look.Value == true)
- {
- if (item1.down != null)
- {
- item2.down = item1.down.Value;
- }
- list.Add(item2);
- }
- break;
- }
- }
- }
- break;
- }
- }
- schemeContentJson1.Frm.FrmContent = list.ToJson().ToString();
- schemeContentJson.SchemeContent = schemeContentJson1.ToString();
- return schemeContentJson.ToString();
- }
- catch
- {
- throw;
- }
- }
- /// <summary>
- /// 获取某个节点(审核人所能看到的提交表单的权限)
- /// </summary>
- /// <param name="data"></param>
- /// <param name="userId"></param>
- /// <returns></returns>
- public string GetProcessSchemeContentByUserId(string data, string userId)
- {
- try
- {
- List<dynamic> list = new List<dynamic>();
- dynamic schemeContentJson = data.ToJson();//获取工作流模板内容的json对象;
- string schemeContent1 = schemeContentJson.SchemeContent.Value;
- dynamic schemeContentJson1 = schemeContent1.ToJson();
- string FrmContent = schemeContentJson1.Frm.FrmContent.Value;
- dynamic FrmContentJson = FrmContent.ToJson();
- foreach (var item in schemeContentJson1.Flow.nodes)
- {
- if (item.setInfo != null && item.setInfo.UserId != null && item.setInfo.UserId.Value == userId)
- {
- foreach (var item1 in item.setInfo.frmPermissionInfo)
- {
- foreach (var item2 in FrmContentJson)
- {
- if (item2.control_field.Value == item1.fieldid.Value)
- {
- if (item1.look.Value == true)
- {
- if (item1.down != null)
- {
- item2.down = item1.down.Value;
- }
- list.Add(item2);
- }
- break;
- }
- }
- }
- break;
- }
- }
- schemeContentJson1.Frm.FrmContent = list.ToJson().ToString();
- schemeContentJson.SchemeContent = schemeContentJson1.ToString();
- return schemeContentJson.ToString();
- }
- catch
- {
- throw;
- }
- }
- #endregion
- #region 工作流流程处理方法(公用)
- /// <summary>
- /// 寻找该节点执行人
- /// </summary>
- /// <param name="wfruntime"></param>
- /// <returns></returns>
- private string GetMakerList(IWF_Runtime wfruntime)
- {
- try
- {
- string makerList = "";
- if (wfruntime.runtimeModel.nextNodeId == "-1")
- {
- throw (new Exception("无法寻找到下一个节点"));
- }
- if (wfruntime.runtimeModel.nextNodeType == 0)//如果是会签节点
- {
- List<string> _nodelist = wfruntime.GetCountersigningNodeIdList(wfruntime.runtimeModel.nextNodeId);
- string _makerList = "";
- foreach (string item in _nodelist)
- {
- _makerList = GetMakerList(wfruntime.runtimeModel.nodeDictionary[item], wfruntime.runtimeModel.processId);
- if (_makerList == "-1")
- {
- throw (new Exception("无法寻找到会签节点的审核者,请查看流程设计是否有问题!"));
- }
- else if (_makerList == "1")
- {
- throw (new Exception("会签节点的审核者不能为所有人,请查看流程设计是否有问题!"));
- }
- else
- {
- if (makerList != "")
- {
- makerList += ",";
- }
- makerList += _makerList;
- }
- }
- }
- else
- {
- makerList = GetMakerList(wfruntime.runtimeModel.nextNode, wfruntime.runtimeModel.processId);
- if (makerList == "-1")
- {
- throw (new Exception("无法寻找到节点的审核者,请查看流程设计是否有问题!"));
- }
- }
- return makerList;
- }
- catch
- {
- throw;
- }
- }
- /// <summary>
- /// 寻找该节点执行人
- /// </summary>
- /// <param name="node"></param>
- /// <returns></returns>
- private string GetMakerList(dynamic node, string processId)
- {
- try
- {
- string makerlsit = "";
- if (node.setInfo == null)
- {
- makerlsit = "-1";
- }
- else
- {
- if (node.setInfo.NodeDesignate.Value == "NodeDesignateType1")//所有成员
- {
- makerlsit = "1";
- }
- else if (node.setInfo.NodeDesignate.Value == "NodeDesignateType2")//指定成员
- {
- makerlsit = ArrwyToString(node.setInfo.NodeDesignateData.role, makerlsit);
- makerlsit = ArrwyToString(node.setInfo.NodeDesignateData.post, makerlsit);
- makerlsit = ArrwyToString(node.setInfo.NodeDesignateData.usergroup, makerlsit);
- makerlsit = ArrwyToString(node.setInfo.NodeDesignateData.user, makerlsit);
- if (makerlsit == "")
- {
- makerlsit = "-1";
- }
- }
- else if (node.setInfo.NodeDesignate.Value == "NodeDesignateType3")//发起者领导
- {
- UserEntity userEntity = userService.GetEntity(OperatorProvider.Provider.Current().UserId);
- if (string.IsNullOrEmpty(userEntity.ManagerId))
- {
- makerlsit = "-1";
- }
- else
- {
- makerlsit = userEntity.ManagerId;
- }
- }
- else if (node.setInfo.NodeDesignate.Value == "NodeDesignateType4")//前一步骤领导
- {
- WFProcessTransitionHistoryEntity transitionHistoryEntity = wfProcessTransitionHistoryService.GetEntity(processId, node.id.Value);
- UserEntity userEntity = userService.GetEntity(transitionHistoryEntity.CreateUserId);
- if (string.IsNullOrEmpty(userEntity.ManagerId))
- {
- makerlsit = "-1";
- }
- else
- {
- makerlsit = userEntity.ManagerId;
- }
- }
- else if (node.setInfo.NodeDesignate.Value == "NodeDesignateType5")//发起者部门领导
- {
- UserEntity userEntity = userService.GetEntity(OperatorProvider.Provider.Current().UserId);
- DepartmentEntity departmentEntity = departmentService.GetEntity(userEntity.DepartmentId);
- if (string.IsNullOrEmpty(departmentEntity.ManagerId))
- {
- makerlsit = "-1";
- }
- else
- {
- makerlsit = departmentEntity.ManagerId;
- }
- }
- else if (node.setInfo.NodeDesignate.Value == "NodeDesignateType6")//发起者公司领导
- {
- UserEntity userEntity = userService.GetEntity(OperatorProvider.Provider.Current().UserId);
- OrganizeEntity organizeEntity = organizeService.GetEntity(userEntity.OrganizeId);
- if (string.IsNullOrEmpty(organizeEntity.ManagerId))
- {
- makerlsit = "-1";
- }
- else
- {
- makerlsit = organizeEntity.ManagerId;
- }
- }
- }
- return makerlsit;
- }
- catch
- {
- throw;
- }
- }
- /// <summary>
- /// 将数组转化成逗号相隔的字串
- /// </summary>
- /// <param name="data"></param>
- /// <param name="Str"></param>
- /// <returns></returns>
- private string ArrwyToString(dynamic data, string Str)
- {
- string resStr = Str;
- foreach (var item in data)
- {
- if (resStr != "")
- {
- resStr += ",";
- }
- resStr += item.Value;
- }
- return resStr;
- }
- /// <summary>
- /// 获取系统表单信息
- /// </summary>
- /// <param name="DataBaseId"></param>
- /// <param name="tableName"></param>
- /// <param name="tableFiled"></param>
- /// <param name="processId"></param>
- /// <returns></returns>
- private string GetFrmData(string DataBaseId, string tableName, string tableFiled, string processId)
- {
-
- string res = "";
- try
- {
- if (DataBaseId == "" || DataBaseId == "" || DataBaseId == "")
- {
- return "";
- }
- DataBaseLinkEntity dataBaseLinkEntity = dataBaseLinkService.GetEntity(DataBaseId);//获取
- string sqlstr = string.Format("Select * from {0} where {1} = '{2}' ", tableName, tableFiled, processId);
- DataTable dt = this.BaseRepository(dataBaseLinkEntity.DbConnection).FindTable(sqlstr);
- res = dt.ToJson();
- return res;
- }
- catch
- {
- throw;
- }
- }
- /// <summary>
- /// 获取委托记录列表
- /// </summary>
- /// <param name="wfSchemeInfoId"></param>
- /// <param name="code"></param>
- /// <param name="customName"></param>
- /// <param name="makerList"></param>
- /// <returns></returns>
- private List<WFDelegateRecordEntity> GetDelegateRecordList(string wfSchemeInfoId, string code, string customName, string makerList)
- {
- try
- {
- delegateUserList = "";
- WFDelegateRecordEntity delegateRecordEntity = null;
- List<WFDelegateRecordEntity> delegateRecordEntitylist = new List<WFDelegateRecordEntity>();
- DataTable dt = wfDelegateRuleService.GetEntityBySchemeInfoId(wfSchemeInfoId, makerList.Split(','));
- foreach (DataRow dr in dt.Rows)
- {
- if (!string.IsNullOrEmpty(dr["Id"].ToString()))
- {
- delegateRecordEntity = new WFDelegateRecordEntity();
- delegateRecordEntity.WFDelegateRuleId = dr["Id"].ToString();
- delegateRecordEntity.FromUserId = dr["CreateUserId"].ToString();
- delegateRecordEntity.FromUserName = dr["CreateUserName"].ToString();
- delegateRecordEntity.ToUserId = dr["ToUserId"].ToString();
- delegateRecordEntity.ToUserName = dr["ToUserName"].ToString();
- delegateRecordEntity.ProcessCode = code;
- delegateRecordEntity.ProcessName = customName;
- delegateRecordEntitylist.Add(delegateRecordEntity);
- delegateUserList += "," + dr["ToUserId"].ToString();
- }
- }
- return delegateRecordEntitylist;
- }
- catch {
- throw;
- }
- }
- #endregion
- }
- }
|