private bool IsExecOfDay(LibBusinessTask task) { bool needExec = false; int curDate = LibDateUtils.GetCurrentDate(); if (task.ExecDate == 0) { if (task.RepeatDateMark != 0) { needExec = IsExecOfDay(task.RepeatDateMark, curDate); if (task.IsJustWorkDay) { string calendarId = task.CalendarId; if (!string.IsNullOrEmpty(calendarId)) { CalendarData calendarData = new CalendarData(calendarId); needExec = IsWorkDay(curDate, calendarData); } } } } else { needExec = task.ExecDate == curDate; } return(needExec); }
public List <LibBusinessTask> InitTempTask() { List <LibBusinessTask> list = new List <LibBusinessTask>(); LibDataAccess dataAccess = new LibDataAccess(); using (IDataReader reader = dataAccess.ExecuteDataReader("select TASKID,PROGID,BUSINESSTASKID,EXECDATE,EXECTIME,EXECCONDITION,INTERNALID from AXPBUSINESSTEMPTASK", false)) { while (reader.Read()) { LibBusinessTask task = new LibBusinessTask() { TaskType = LibTaskType.TempTask, TaskId = LibSysUtils.ToString(reader["TASKID"]), ProgId = LibSysUtils.ToString(reader["PROGID"]), BusinessTaskId = LibSysUtils.ToString(reader["BUSINESSTASKID"]), ExecDate = LibSysUtils.ToInt32(reader["EXECDATE"]), ExecCondition = LibSysUtils.ToString(reader["EXECCONDITION"]), InternalId = LibSysUtils.ToString(reader["INTERNALID"]) }; task.ExecTime.Add(LibSysUtils.ToInt32(reader["EXECTIME"])); list.Add(task); } } return(list); }
protected override void AfterUpdate() { base.AfterUpdate(); if (!this.ManagerMessage.IsThrow) { if (EnvProvider.Default.ScheduleTaskOpened) { DataRow masterRow = this.DataSet.Tables[0].Rows[0]; string taskId = LibSysUtils.ToString(masterRow["TASKID"]); LibBusinessTask task = null; PostAccountWay way = PostAccountHelper.GetPostAccountWay(PostAccountState.Release, masterRow); switch (way) { case PostAccountWay.Diff: string oldTaskId = LibSysUtils.ToString(masterRow["TASKID", DataRowVersion.Original]); LibBusinessTaskCache.Default.RemoveCacheItem(oldTaskId); LibScheduleTaskHost.Default.DeleteTask(oldTaskId); task = AddTask(); LibScheduleTaskHost.Default.AddTask(task); break; case PostAccountWay.Positive: task = AddTask(); LibScheduleTaskHost.Default.AddTask(task); break; case PostAccountWay.Reverse: LibBusinessTaskCache.Default.RemoveCacheItem(LibSysUtils.ToString(masterRow["TASKID"])); LibScheduleTaskHost.Default.DeleteTask(taskId); break; } } } }
private LibBusinessTask AddTask() { LibBusinessTask task = new LibBusinessTask(); DataRow masterRow = this.DataSet.Tables[0].Rows[0]; task.BusinessTaskId = LibSysUtils.ToString(masterRow["BUSINESSTASKID"]); task.CalendarId = LibSysUtils.ToString(masterRow["CALENDARID"]); task.ExecCondition = LibSysUtils.ToString(masterRow["ExecCondition"]); task.ExecDate = LibSysUtils.ToInt32(masterRow["EXECDATE"]); task.IntervalTime = LibSysUtils.ToInt32(masterRow["INTERVALTIME"]); task.IsJustWorkDay = LibSysUtils.ToBoolean(masterRow["ISJUSTWORKDAY"]); task.ProgId = LibSysUtils.ToString(masterRow["PROGID"]); task.Title = LibSysUtils.ToString(masterRow["TITLE"]); task.MainContent = LibSysUtils.ToString(masterRow["MAINCONTENT"]); task.RepeatDateMark = LibSysUtils.ToInt32(masterRow["REPEATDATEMARK"]); task.TaskId = LibSysUtils.ToString(masterRow["TASKID"]); foreach (DataRow curRow in this.DataSet.Tables[1].Rows) { if (curRow.RowState == DataRowState.Deleted) { continue; } task.ExecTime.Add(LibSysUtils.ToInt32(curRow["EXECTIME"])); } string sql = string.Format("select distinct A.TASKID,A.PERSONID,D.DEPTID,C.USERID from AXPSCHEDULETASKPERSON A " + "inner join AXPSCHEDULETASK B on B.TASKID=A.TASKID left join COMPERSON D on D.PERSONID=A.PERSONID inner join AXPUSER C on C.PERSONID=A.PERSONID " + "where B.TASKID={0}", LibStringBuilder.GetQuotString(task.TaskId)); using (IDataReader reader = this.DataAccess.ExecuteDataReader(sql, false)) { while (reader.Read()) { task.Liaison.Add(new LibBusinessTaskLiaison() { PersonId = LibSysUtils.ToString(reader["PERSONID"]), DeptId = LibSysUtils.ToString(reader["DEPTID"]), UserId = LibSysUtils.ToString(reader["USERID"]) }); } } LibBusinessTaskCache.Default.AddCacheItem(task); return(task); }
public void AddTask(LibBusinessTask task, bool needAddDB = false) { int curDate = LibDateUtils.GetCurrentDate(); if (string.IsNullOrEmpty(task.ProgId) || string.IsNullOrEmpty(task.BusinessTaskId)) { return; } //如果指定的日期大于当前日期,无需执行 if (task.TaskType == LibTaskType.None && task.ExecDate != 0 && task.ExecDate > curDate) { return; } //未指定有效执行日期则跳过 if (task.ExecDate == 0 && task.RepeatDateMark == 0) { return; } //无设置执行时间点则跳过 if (task.IntervalTime == 0 && task.ExecTime.Count == 0) { return; } //初始化Timer LibTaskParam param = new LibTaskParam(task); string key = Guid.NewGuid().ToString(); param.Task = new LibTask(new Timer(ExecBusinessTask, param, param.GetTaskDueTime(), Timeout.InfiniteTimeSpan)); TaskList.TryAdd(key, param.Task); TaskMap.TryAdd(task.TaskId, key); if (task.TaskType == LibTaskType.TempTask && needAddDB) { LibDataAccess dataAccess = new LibDataAccess(); dataAccess.ExecuteNonQuery(string.Format("insert into AXPBUSINESSTEMPTASK(TASKID,PROGID,BUSINESSTASKID,EXECDATE,EXECTIME,EXECCONDITION,INTERNALID) values({0},{1},{2},{3},{4},{5},{6})", LibStringBuilder.GetQuotString(task.TaskId), LibStringBuilder.GetQuotString(task.ProgId), LibStringBuilder.GetQuotString(task.BusinessTaskId), task.ExecDate, task.ExecTime[0], LibStringBuilder.GetQuotString(task.ExecCondition), LibStringBuilder.GetQuotString(task.InternalId)), false); } }
public LibTaskParam(LibBusinessTask taskDefine) { TaskDefine = taskDefine; }
private void ExecBusinessTask(object obj) { LibTaskParam param = (LibTaskParam)obj; LibBusinessTask taskDefine = param.TaskDefine; //系统当天是否可以执行 if (IsExecOfDay(taskDefine)) { try { param.Task.TaskState = TaskRunState.Running; LibBcfBase bcf = LibBcfSystem.Default.GetBcfInstance(taskDefine.ProgId); bcf.Handle = LibHandleCache.Default.GetSystemHandle(); Type type = bcf.GetType(); object[] destParam = RestoreParamFormat(type, taskDefine.BusinessTaskId, new string[] { taskDefine.ExecCondition }); object result = bcf.GetType().InvokeMember(taskDefine.BusinessTaskId, BindingFlags.InvokeMethod, null, bcf, destParam); switch (bcf.Template.BillType) { case AxCRL.Template.BillType.Master: case AxCRL.Template.BillType.Bill: break; case AxCRL.Template.BillType.Grid: break; case AxCRL.Template.BillType.DataFunc: break; case AxCRL.Template.BillType.Rpt: case AxCRL.Template.BillType.DailyRpt: DataSet dataSet = result as DataSet; if (dataSet != null) { LibSysNews news = new LibSysNews(); news.Content = taskDefine.MainContent; news.Data = LibBillDataSerializeHelper.Serialize(dataSet); news.PersonId = "SYSTEM"; news.ProgId = taskDefine.ProgId; news.Title = taskDefine.Title; foreach (LibBusinessTaskLiaison item in taskDefine.Liaison) { news.UserList.Add(item.UserId); } LibSysNewsHelper.SendNews(news, false); } break; default: break; } } catch (Exception ex) { //将错误输出 string path = System.IO.Path.Combine(AxCRL.Comm.Runtime.EnvProvider.Default.MainPath, "Output", "Error", "ScheduleTask", string.Format("{0}.txt", DateTime.Now.Ticks)); OutputInfo(path, ex.ToString()); } finally { param.Task.TaskState = TaskRunState.Wait; } } bool canNextExec = true; if (taskDefine.ExecDate != 0) { int curDate = LibDateUtils.GetCurrentDate(); if (taskDefine.ExecDate > curDate) { param.Task.Timer.Dispose(); canNextExec = false; param.Task.TaskState = TaskRunState.Stop; } else if (taskDefine.ExecDate == curDate && taskDefine.ExecTime.Count > 0) { int curTime = LibDateUtils.GetLibTimePart(LibDateUtils.GetCurrentDateTime(), LibDateTimePartEnum.Time); if (taskDefine.ExecTime[taskDefine.ExecTime.Count - 1] < curTime) { param.Task.Timer.Dispose(); canNextExec = false; param.Task.TaskState = TaskRunState.Stop; } } } if (canNextExec) { param.Task.Timer.Change(param.GetTaskDueTime(), Timeout.InfiniteTimeSpan); } else if (taskDefine.TaskType == LibTaskType.TempTask) { //删除临时任务 LibDataAccess dataAccess = new LibDataAccess(); dataAccess.ExecuteNonQuery(string.Format("delete AXPBUSINESSTEMPTASK where TASKID={0}", LibStringBuilder.GetQuotString(taskDefine.TaskId)), false); } }