public List <WFFlowEntity> GetFlowsByServiceId(string serviceId) { if (string.IsNullOrWhiteSpace(serviceId)) { throw new ArgumentException($"{nameof(serviceId)} is not null"); } var filter = TableFilter.New().Equals("id", serviceId); var serviceEntity = DataAccess.Query(WFServiceEntity.TableCode).FixField("*").Where(filter).QueryFirst <WFServiceEntity>(); if (serviceEntity == null) { throw new Exception("没有找到流程业务"); } filter = TableFilter.New().Equals("serviceId", serviceId).Equals("istemplate", 1); var query = DataAccess.Query(WFFlowEntity.TableCode).FixField("*").Sort("version desc").Where(filter); var list = query.QueryList <WFFlowEntity>().ToList(); var currentFlow = list.Where(flow => flow.ID == serviceEntity.Currentflowid).FirstOrDefault(); if (currentFlow != null) { currentFlow.CurrentTag = 1; } return(list); }
public int ProcessWftEvent(uint batchCount) { var filter = TableFilter.New().Equals("status", 0); //.Equals("waitcallback", 0); //#if DEBUG // filter = TableFilter.New().Equals("status", 0).Equals("flowid", "00001F493WJRC0000A01"); //#endif var jobs = _DataAccess.Query(WFTEventEntity.TableCode).FixField("*").Paging(1, batchCount).Where(filter).QueryList <WFTEventEntity>(); Parallel.ForEach <WFTEventEntity>(jobs, new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }, (job) => { try { Run(job); } catch (HttpRequestException ex) { _Logger.LogError($"处理wftevent发升网络错误:{ex.Message}", ex); } catch (Exception ex) { if (ex.InnerException != null) { _Logger.LogError($"处理wftevent发升错误InnerException:{ex.InnerException.Message}", ex.InnerException); } _Logger.LogError($"处理wftevent发升错误:{ex.Message}", ex); } }); return(jobs.Count()); }
public int Callback(string mqId) { var filter = TableFilter.New().Equals("id", mqId); var eventEntity = _DataAccess.Query(WFTEventEntity.TableCode).FixField("*").Where(filter).QueryFirst <WFTEventEntity>(); if (eventEntity == null) { throw new Exception($"回调任务{mqId}不存在"); } if (eventEntity.ProcessDate == DateTime.MinValue) { throw new Exception($"回到任务会处理完毕,请稍后回调"); } var tinsEntity = _WFTask.GetTinsById(eventEntity.Tinsid); var taskEntity = _WFTask.GetTaskById(eventEntity.Taskid); var fins = _WorkFlowIns.GetFlowInstance(eventEntity.Finsid); var bisJsonData = GetBisData(taskEntity, eventEntity.Dataid, fins.ServiceId, eventEntity.Tinsid, out bool isMultipleNextTask); var nextTasks = _WFTask.GetNextTasks(taskEntity, tinsEntity, bisJsonData); if (nextTasks.Length != 1) { throw new Exception("流程配置错误,下个任务节点数量必须是1"); } taskEntity.ReplaceTemplateInfo(bisJsonData); using (var tran = TransHelper.BeginTrans()) { //1、更新任务实例状态 eventEntity.State = EDBEntityState.Modified; eventEntity.Waitcallback = 0; eventEntity.Callbackdate = DateTime.Now; _DataAccess.Update(eventEntity); tinsEntity.State = EDBEntityState.Modified; tinsEntity.Edate = DateTime.Now; _DataAccess.Update(tinsEntity); //2、找下个任务节点,并流转,回调节点不应该有多个下个节点 //如果下一个节点是聚合节点,则需要加锁,防止与回调冲突。默认等待10S if (nextTasks[0].Type == ETaskType.JuHe) { var lockKey = $"{MutexConfig.WORKFLOWLOCKPRE}{fins.Dataid}"; var success = ExeWithLock(lockKey, MutexConfig.WORKFLOWLOCKTIMEOUT, () => { ExeNextTask(fins, nextTasks); tran.Commit(); }); if (!success) { throw new Exception($"未获取独占锁,请重试,dataid:{fins.Dataid }"); } } else { ExeNextTask(fins, nextTasks); tran.Commit(); } } return(1); }
public WFFinsEntity GetFlowInstance(string finsId) { var filter = TableFilter.New().Equals("ID", finsId); return(_DataAccess.Query(WFFinsEntity.TableCode).FixField("*") .Where(filter).QueryFirst <WFFinsEntity>()); }
public WFTinsEntity GetTinsById(string tinsId) { var filter = TableFilter.New().Equals("id", tinsId); var tinsEntity = DataAccess.Query(WFTinsEntity.TableCode) .FixField("*").Where(filter).QueryFirst <WFTinsEntity>(); return(tinsEntity); }
public WFTaskEntity GetStartTask(string flowId) { var filter = TableFilter.New().Equals("flowid", flowId).Equals("type", 1); var taskEntity = DataAccess.Query(WFTaskEntity.TableCode) .FixField("*").Where(filter).QueryFirst <WFTaskEntity>(); return(taskEntity); }
public bool IsMultipleNextTask(WFTaskEntity preTask) { var filter = TableFilter.New().Equals("BEGINTASKID", preTask.ID); var links = DataAccess.Query(WFLinkEntity.TableCode) .FixField("*").Where(filter).QueryList <WFLinkEntity>().ToList(); return(links.Count > 1); }
public IEnumerable <WFTinsEntity> GetTinssById(string finsId, string[] taskIds) { var filter = TableFilter.New().Equals("FINSID", finsId).In("taskid", string.Join(',', taskIds)); var tinsEntitys = DataAccess.Query(WFTinsEntity.TableCode) .FixField("*").Where(filter).QueryList <WFTinsEntity>(); return(tinsEntitys); }
/// <summary> /// 从数据库或者缓存中获取流程服务的接入url信息 /// </summary> /// <param name="serviceId"></param> /// <returns></returns> private string GetAppAccessUrl(string serviceId) { var filter = TableFilter.New().Equals("id", serviceId); var serviceEntity = _dataAccess.Query(WFServiceEntity.TableCode).FixField("id,wfappid").Where(filter).QueryFirst <WFServiceEntity>(); filter = TableFilter.New().Equals("id", serviceEntity.WfappId); return(_dataAccess.Query("wfapp").FixField("url").Where(filter).QueryScalar().ConvertTostring()); }
public WFTaskSettingEntity GetTaskJobInfo(WFTaskEntity taskEntity) { var filter = TableFilter.New().Equals("id", taskEntity.ID); var settingEntity = DataAccess.Query(WFTaskSettingEntity.TableCode) .FixField("*").Where(filter).QueryFirst <WFTaskSettingEntity>(); return(settingEntity); }
public WFTEventEntity GetById(string id) { var col = this._DataAccess.Query(WFTEventEntity.TableCode) .FixField("*") .Where(TableFilter.New().Equals("ID", id)) .Query <WFTEventEntity>(); return(col.Data.FirstOrDefault()); }
public void TestMethod() { var col = this._da.Query(WFTinsEntity.TableCode) .FixField("*") .Where(TableFilter.New().Equals("ID", "00001Q1FJ6JYK0000A03")) .Query <WFTinsEntity>(); Console.WriteLine(this.Json.Serialize(col.Data.FirstOrDefault().Edate)); }
public DBCollection <WFFinsEntity> GetRuningData(WFMonitorSearchModel searchModel) { TableFilter filter = TableFilter.New(); BuildFilter(filter, searchModel); var coll = GetRuningData(searchModel, filter); return(coll); }
private WFServiceEntity InitData(string key) { var col = this._da.Query(WFServiceEntity.TableCode) .FixField("*") .Where(TableFilter.New().Equals("ID", key)) .Query <WFServiceEntity>(); return(col.Data.FirstOrDefault()); }
public List <WFTinsEntity> GetTinsList(string finsId) { var col = this.DataAccess.Query(WFTinsEntity.TableCode) .FixField("*") .Where(TableFilter.New().Equals("FINSID", finsId)) .Query <WFTinsEntity>(); return(col.Data.ToList()); }
public DBCollection <WFTEventEntity> GetWaitcallbackData(string finsId) { if (string.IsNullOrWhiteSpace(finsId)) { return(new DBCollection <WFTEventEntity>()); } var filter = TableFilter.New().Equals("finsid", finsId).Equals("waitcallback", 1); return(_dataAccess.Query("wftevent").FixField("id,taskid,tinsid,processdate").Where(filter).Query <WFTEventEntity>()); }
public WFTaskEntity[] GetPreTasks(WFTaskEntity nextTask) { var filter = TableFilter.New().Equals("ENDTASKID", nextTask.ID); var links = DataAccess.Query(WFLinkEntity.TableCode) .FixField("*").Where(filter).QueryList <WFLinkEntity>(); filter = TableFilter.New().In("ID", string.Join(',', links.Select(l => l.Begintaskid).ToArray())); var tasks = DataAccess.Query(WFTaskEntity.TableCode).FixField("*") .Where(filter).QueryList <WFTaskEntity>(); return(tasks.ToArray()); }
/// <summary> /// 回调任务并注册错误信息 /// </summary> /// <param name="mqId"></param> /// <param name="errorMsg"></param> /// <returns></returns> public int CallbackForTaskError(string mqId, string errorMsg) { var filter = TableFilter.New().Equals("id", mqId); var eventEntity = _DataAccess.Query(WFTEventEntity.TableCode).FixField("*").Where(filter).QueryFirst <WFTEventEntity>(); if (eventEntity == null) { throw new Exception($"回调任务{mqId}不存在"); } //判断任务节点状态是否正确 if (eventEntity.Waitcallback == 0) { throw new Exception($"回调任务{mqId}已经回调,无法继续处理"); } if (eventEntity.Status == -1) { throw new Exception($"回调任务{mqId}已标记为异常,请尝试修复"); } //插入 异常消息 var flowEntity = _DataAccess.Query(WFFinsEntity.TableCode).FixField("ID,STATUS").Where(TableFilter.New().Equals("ID", eventEntity.Finsid)).QueryFirst <WFFinsEntity>(); using (var tran = TransHelper.BeginTrans()) { //流程实例更新为失败 flowEntity.Status = -1; _DataAccess.Update(flowEntity); //1、更新任务实例状态 eventEntity.State = EDBEntityState.Modified; eventEntity.Status = -1; //标记失败 _DataAccess.Update(eventEntity); //写入event异常日志 WFTEventMsgEntity en = _DataAccess.GetNewEntity <WFTEventMsgEntity>(); en.EventId = mqId; en.CDate = DateTime.Now; en.Remark = errorMsg; en.RepairDate = new DateTime(9999, 12, 31); en.FinsId = flowEntity.ID; _DataAccess.Update(en); tran.Commit(); } return(1); }
public WFFlowEntity GetWFTemplate(string flowId) { if (string.IsNullOrWhiteSpace(flowId)) { throw new ArgumentException($"{nameof(flowId)} is not null"); } var filter = TableFilter.New().Equals("id", flowId); var query = DataAccess.Query(WFFlowEntity.TableCode).FixField("id").Where(filter); var flowEntity = query.QueryFirst <WFFlowEntity>(); if (flowEntity != null) { filter = TableFilter.New().Equals("flowid", flowId); flowEntity.Links = DataAccess.Query(WFLinkEntity.TableCode).FixField("id,begintaskid,endtaskid,memo").Where(filter).QueryList <WFLinkEntity>().ToList(); flowEntity.Tasks = DataAccess.Query(WFTaskEntity.TableCode).FixField("id,name,type,x,y").Where(filter).QueryList <WFTaskEntity>().ToList(); } return(flowEntity); }
public WFTaskEntity[] GetNextTasks(WFTaskEntity preTask, WFTinsEntity tinsEntity, string bisJsonData) { var filter = TableFilter.New().Equals("BEGINTASKID", preTask.ID); var links = DataAccess.Query(WFLinkEntity.TableCode) .FixField("*").Where(filter).QueryList <WFLinkEntity>().ToList(); if (preTask.Type != ETaskType.BingXing && links.Count() > 1) { var dataList = new List <WFJsonDataEntity>(); dataList.Add(_JsonConverter.Deserialize <WFJsonDataEntity>(bisJsonData)); foreach (var link in links.OrderByDescending(l => l.Priority)) { bool hitRule = false; if (string.IsNullOrWhiteSpace(link.Filter)) { hitRule = true; } else { var conditionFilter = _JsonConverter.Deserialize <TableFilter>(link.Filter); hitRule = dataList.QueryDynamic(conditionFilter).Count() == 1; } if (hitRule) { links = new List <WFLinkEntity>(); links.Add(link); break; } } } if (links.Count() == 1) { filter = TableFilter.New().Equals("ID", string.Join(',', links.Select(l => l.Endtaskid).ToArray())); } else { filter = TableFilter.New().In("ID", string.Join(',', links.Select(l => l.Endtaskid).ToArray())); } var tasks = DataAccess.Query(WFTaskEntity.TableCode).FixField("*") .Where(filter).QueryList <WFTaskEntity>(); return(tasks.ToArray()); }
public int Start(string serviceId, string dataId, string name) { var filter = TableFilter.New().Equals("status", 0); //根据业务id获取当前版本的id var serviceEntity = _DataAccess.Query(WFServiceEntity.TableCode).FixField("id,currentflowid").Where(TableFilter.New().Equals("ID", serviceId)).QueryFirst <WFServiceEntity>(); if (serviceEntity == null || string.IsNullOrWhiteSpace(serviceEntity.Currentflowid)) { return(0); } var startTask = _WFTask.GetStartTask(serviceEntity.Currentflowid); if (startTask == null) { throw new Exception("没有找到开始节点"); } //判断是否 var bisJsonData = GetBisData(startTask, dataId, serviceId, string.Empty, out bool isMultipleNextTask); using (var trans = TransHelper.BeginTrans()) { //1、创建流程实例、开始节点实例,执行开始节点任务 var fins = _WorkFlowIns.CreatFlowInstance(serviceEntity.ID, serviceEntity.Currentflowid, dataId, name); var tinsStart = _WFTask.CreateTaskIns(fins, startTask); var startTaskSetting = _WFTask.GetTaskInfo(startTask); startTaskSetting.RunTask(startTask, fins, tinsStart, null); var nextTasks = _WFTask.GetNextTasks(startTask, tinsStart, bisJsonData); if (nextTasks == null || nextTasks.Length != 1) { throw new Exception("没有找到唯一的下一个任务节点"); } //如果找到多个下个任务节点,则需要获取业务数据 var nextTask = nextTasks[0]; var tinsNext = _WFTask.CreateTaskIns(fins, nextTask); _WFTask.GetTaskInfo(nextTask).CreateJob(fins, tinsNext, IsNeedCallback(nextTask.Type)); trans.Commit(); } return(1); }
/// <summary> /// 流程废弃 /// </summary> /// <param name="mqId"></param> /// <returns></returns> public CommonResult <int> GiveUp(string mqId, string reason) { //根据MQID var en = this._WfTEventDal.Get(mqId); if (en == null) { return(new WarnResult($"回调任务{mqId}不存在")); } //判断任务节点状态是否正确 if (en.Waitcallback == 0) { return(new WarnResult($"回调任务{mqId}已经回调,无法继续处理")); } var enFins = this._WfFinsDal.Get(en.Finsid); if (enFins == null) { return(new WarnResult("未找到此流程")); } if (!(enFins.Status == (int)EFlowStatus.Starting || enFins.Status == (int)EFlowStatus.Error)) { return(new WarnResult("非审批中的流程不能废弃!")); } using (var tran = TransHelper.BeginTrans()) { var num = this._DataAccess.Update(WFFinsEntity.TableCode).Set("Status", (int)EFlowStatus.GiveUp).Where(TableFilter.New().Equals("ID", enFins.ID)).ExecuteNonQuery(); if (num > 0) { this._DataAccess.Update(WFTinsEntity.TableCode) .Set("EDATE", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")) .Set("Memo", $"因为[{reason}]废弃流程") .Where(TableFilter.New().Equals("FinsId", enFins.ID).IsNull("EDATE")) .ExecuteNonQuery(); } tran.Commit(); } return(1); }
public string GetIdByDataIdAndFlowId(string dataid, string flowId) { string rtn = ""; if (string.IsNullOrEmpty(dataid)) { dataid = "none";//如果没有值则给个默认值,防止全表查询 } var col = this._da.Query(WFFinsEntity.TableCode) .FixField("ID") .Where(TableFilter.New().Equals("DATAID", dataid).Equals("FlOWID", flowId)) .Query <WFFinsEntity>(); if (col.Data.Any()) { rtn = col.Data.First().ID; } return(rtn); }
public WFFinsEntity GetWFFinsExecInfo(string finsId) { var col = this._dataAccess.Query(WFFinsEntity.TableCode) .FixField("*") .Where(TableFilter.New().Equals("ID", finsId)) .Query <WFFinsEntity>(); if (!col.Data.Any()) { throw new Exception($"{finsId}数据不存在"); } var en = col.Data.FirstOrDefault(); en.WfFlow = this._workFlowTemplate.GetWFTemplate(en.Flowid); en.TaskIns = _WorkFlowInstance.GetTinsList(finsId); TableFilter tf = TableFilter.New().Equals("FINSID", en.ID); var eventArr = this._wftEventRepository.GetList(tf);//查询异步回调信息 en.LinkIns = new List <WFLinkEntity>(); for (int i = 0; i < en.TaskIns.Count; i++) { WFTinsEntity startTIns = en.TaskIns[i]; if (startTIns.Edate.ToString("yyyy-MM-dd") == "0001-01-01")//#如果没有结束时间 { //TODOWHP 待完善 on 2020-03-28 09:41:14 //eventArr.Data.All(o=>o.Tinsid=en.ID) } } foreach (WFLinkEntity link in en.WfFlow.Links) { if (en.TaskIns.Any(o => o.Taskid == link.Begintaskid) && en.TaskIns.Any(o => o.Taskid == link.Endtaskid)) { en.LinkIns.Add(link); } } return(en); }
public string GetIdByFinsIdAndTaskId(string finsId, string taskId) { string rtn = ""; if (string.IsNullOrEmpty(finsId)) { finsId = "none";//防全表查询用 } var col = this._da.Query(WFTDataEntity.TableCode) .FixField("ID") .Where(TableFilter.New().Equals("FinsId", finsId).Equals("TaskId", taskId)) .Sort("SDATE DESC") .Query <WFTDataEntity>(); if (col.Data.Any()) { rtn = col.Data.First().ID; } return(rtn); }
public void Add(string flowId, string finsid, string taskId, string tinsId, string jsonData) { TableFilter tf = TableFilter.New().Equals("FlowID", flowId).Equals("FinsId", finsid).Equals("TinsId", tinsId); //查重, var col = GetByFlowIdAndTaskId(tf); if (col.Data.Any(o => o.JsonData == jsonData)) { return;//如果有记录则不再插入数据 } WFTDataEntity dataEntity = new WFTDataEntity(); dataEntity.State = EDBEntityState.Added; dataEntity.Flowid = flowId; dataEntity.Finsid = finsid; dataEntity.Taskid = taskId; dataEntity.Tinsid = tinsId; dataEntity.Cdate = System.DateTime.Now; dataEntity.JsonData = jsonData; this._da.Update(dataEntity); }
public CommonResult <int> SetCurrentFow(string serviceId, string flowId) { if (string.IsNullOrWhiteSpace(flowId)) { return(new WarnResult($"{nameof(flowId)} is not null")); } var flowEntity = DataAccess.Query(WFFlowEntity.TableCode).FixField("*").Where(TableFilter.New().Equals("Id", flowId)).QueryFirst <WFFlowEntity>(); if (flowEntity == null || flowEntity.Released == 0) { return(new WarnResult("必须发布后的流程才能设置为当前")); } var serviceEntity = DataAccess.Query(WFServiceEntity.TableCode).FixField("*").Where(TableFilter.New().Equals("Id", serviceId)).QueryFirst <WFServiceEntity>(); if (serviceEntity == null) { return(new WarnResult("没有找到业务流程")); } if (serviceEntity.Currentflowid != flowId) { serviceEntity.Currentflowid = flowId; DataAccess.Update(serviceEntity); } return(1); }
public CommonResult <int> ReleaseFlow(string flowId) { if (string.IsNullOrWhiteSpace(flowId)) { return(new WarnResult($"{nameof(flowId)} is not null")); } var flowEntity = DataAccess.Query(WFFlowEntity.TableCode).FixField("*").Where(TableFilter.New().Equals("Id", flowId)).QueryFirst <WFFlowEntity>(); if (flowEntity != null && flowEntity.Released == 0) { flowEntity.Released = 1; flowEntity.ReleaseDate = DateTime.Now; DataAccess.Update(flowEntity); } return(1); }