/// <summary> /// 移动到已经完成系统任务中 /// </summary> /// <param name="taskID">被移动的任务的ID</param> /// <param name="status">重置任务的状态</param> public SysAccomplishedTask MoveToCompletedSysTask(string taskID, SysTaskStatus status, string statusText) { SysTask task = this.Load(taskID); (task != null).FalseThrow <ArgumentException>("ID为 {0} 的任务不存在", taskID); return(MoveToCompletedSysTask(task, status, statusText)); }
/// <summary> /// 移动到已经完成系统任务中 /// </summary> /// <param name="taskID">被移动的任务的ID</param> /// <param name="status">重置任务的状态</param> public SysAccomplishedTask MoveToCompletedSysTask(SysTask task, SysTaskStatus status, string statusText) { SysAccomplishedTask result = null; PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("MoveToAccomplished({0})", this.GetType().FullName), () => { Dictionary <string, object> context = new Dictionary <string, object>(); ORMappingItemCollection mappings = GetMappingInfo(context); WhereSqlClauseBuilder builder = ORMapping.GetWhereSqlClauseBuilderByPrimaryKey(task, mappings); ORMappingItemCollection mappingsCompleted = ORMapping.GetMappingInfo <SysAccomplishedTask>(); SysAccomplishedTask taskCompleted = new SysAccomplishedTask(task); taskCompleted.Status = status; taskCompleted.StatusText = statusText; StringBuilder sql = new StringBuilder(); sql.AppendFormat("DELETE FROM {0} WHERE {1}", mappingsCompleted.TableName, builder.ToSqlString(TSqlBuilder.Instance)); sql.Append(TSqlBuilder.Instance.DBStatementSeperator); sql.Append(GetMoveSysTaskSql(taskCompleted, context)); sql.Append(TSqlBuilder.Instance.DBStatementSeperator); sql.Append("IF @@ROWCOUNT = 0"); sql.Append(TSqlBuilder.Instance.DBStatementSeperator); sql.Append("\t" + ORMapping.GetInsertSql(taskCompleted, mappingsCompleted, TSqlBuilder.Instance)); sql.Append(TSqlBuilder.Instance.DBStatementSeperator); sql.AppendFormat("DELETE FROM {0} WHERE {1}", mappings.TableName, builder.ToSqlString(TSqlBuilder.Instance)); using (TransactionScope scope = TransactionScopeFactory.Create()) { DbHelper.RunSql(sql.ToString(), this.GetConnectionName()); scope.Complete(); } result = taskCompleted; }); return(result); }
private static void SetSysTaskToCompletedSub(DO.SysTask task1, SysTaskStatus status, string statusText) { DO.SysTaskAdapter.Instance.Update(task1); SysTaskAdapter.Instance.MoveToCompletedSysTask(task1.TaskID, status, statusText); DO.SysTask task11 = SysTaskAdapter.Instance.Load(task1.TaskID); Assert.IsNull(task11); var task12 = SysAccomplishedTaskAdapter.Instance.Load(task1.TaskID); Assert.IsNotNull(task12); Assert.AreEqual(status, task12.Status); }
/// <summary> /// 更新任务的状态 /// </summary> /// <param name="taskID"></param> /// <param name="status"></param> /// <returns></returns> public bool UpdateStatus(string taskID, SysTaskStatus status) { taskID.CheckStringIsNullOrEmpty("taskID"); ORMappingItemCollection mapping = GetMappingInfo(new Dictionary <string, object>()); UpdateSqlClauseBuilder ub = new UpdateSqlClauseBuilder(); ub.AppendItem("STATUS", status.ToString()); ub.AppendItem("START_TIME", "GETDATE()", "=", true); WhereSqlClauseBuilder wb = new WhereSqlClauseBuilder(); wb.AppendItem("TASK_GUID", taskID); wb.AppendTenantCode(typeof(T)); string sql = string.Format("UPDATE {0} SET {1} WHERE {2}", mapping.TableName, ub.ToSqlString(TSqlBuilder.Instance), wb.ToSqlString(TSqlBuilder.Instance)); return(DbHelper.RunSql(sql, this.GetConnectionName()) > 0); }