|
|
|
@ -37,7 +37,8 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
public class TaskService : ServiceBase, ITaskService, IAuditTaskService
|
|
|
|
|
{
|
|
|
|
|
internal const long PERMISSION_ID = 1815294400855674880;
|
|
|
|
|
internal const string BillSendingInterval = "BillSendingInterval";
|
|
|
|
|
internal const string DEFAULT_JOB_INTERVAL = "DefaultJobInterval";
|
|
|
|
|
internal const string JOB_MAX_RETRY = "JOB_MAX_RETRY";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取支持审核的任务类型
|
|
|
|
@ -688,10 +689,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var value = await Db.Queryable<SysConfig>().Where(x => x.Code == BillSendingInterval).Select(x => x.Value).FirstAsync();
|
|
|
|
|
if (!int.TryParse(value, out int interval))
|
|
|
|
|
interval = 60;
|
|
|
|
|
|
|
|
|
|
var interval = await GetConfigValueAsync(DEFAULT_JOB_INTERVAL, 60);
|
|
|
|
|
var list = await TenantDb.Queryable<TaskJob>().Where(x => x.TaskId == task.Id && x.Status != TaskJobStatus.Completed)
|
|
|
|
|
.Select(x => new TaskJob
|
|
|
|
|
{
|
|
|
|
@ -1398,7 +1396,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
/// <param name="remark">备注</param>
|
|
|
|
|
/// <param name="taskTypes">任务类型,不指定任务类型则删除全部任务</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult> DeleteAsync(long id, BusinessType? businessType, string? remark = null, params TaskBaseTypeEnum[] taskTypes)
|
|
|
|
|
public virtual async Task<DataResult> DeleteAsync(long id, BusinessType? businessType, string? remark = null, params TaskBaseTypeEnum[] taskTypes)
|
|
|
|
|
{
|
|
|
|
|
if (!await HasAuthorizedAsync())
|
|
|
|
|
return DataResult.SuccessedWithDesc(nameof(MultiLanguageConst.ModuleUnauthorized));
|
|
|
|
@ -1471,15 +1469,40 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
await ManagerService.SetTaskBaseInfoPropertyWithBsno(id, taskType, null, null, x => x.TASK_DESP == description);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取系统配置值
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T">值类型</typeparam>
|
|
|
|
|
/// <param name="key">配值名称</param>
|
|
|
|
|
/// <param name="defaultValue">未获取到配值时的默认值</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected internal async Task<T?> GetConfigValueAsync<T>(string key, T? defaultValue = default)
|
|
|
|
|
{
|
|
|
|
|
var value = await Db.Queryable<SysConfig>().Where(x => x.Code == key).Select(x => x.Value).FirstAsync();
|
|
|
|
|
if (string.IsNullOrEmpty(value))
|
|
|
|
|
return defaultValue;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return (T)Convert.ChangeType(value, typeof(T));
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 运行定时任务
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task RunJobAsync()
|
|
|
|
|
{
|
|
|
|
|
var maxRetry = await GetConfigValueAsync(JOB_MAX_RETRY, 10);
|
|
|
|
|
var jobs = await TenantDb.Queryable<TaskJob>()
|
|
|
|
|
.InnerJoin<BusinessTask>((x, y) => x.TaskId == y.Id)
|
|
|
|
|
.Where((x, y) => y.TaskStatus == TaskStatusEnum.Create && x.Status == TaskJobStatus.Ready && x.NextTriggerTime <= SqlFunc.GetDate())
|
|
|
|
|
.Where((x, y) => y.TaskStatus == TaskStatusEnum.Create && x.Status == TaskJobStatus.Ready &&
|
|
|
|
|
x.NextTriggerTime <= SqlFunc.GetDate() && x.RetryTimes <= maxRetry)
|
|
|
|
|
.Select((x, y) => new TaskJob
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
@ -1492,6 +1515,8 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
if (jobs.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
long userId = long.Parse(User.UserId);
|
|
|
|
|
var dtNow = DateTime.Now;
|
|
|
|
|
var jobContext = new TaskJobContext();
|
|
|
|
|
await TenantDb.Ado.BeginTranAsync();
|
|
|
|
|
try
|
|
|
|
@ -1514,6 +1539,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
item.LastException = $"执行作业({item.Id})时发生错误:" + ex.Message + Environment.NewLine + ex.StackTrace;
|
|
|
|
|
item.RetryTimes++;
|
|
|
|
|
jobContext.Result = DataResult.Failed(item.LastException);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -1523,6 +1549,9 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
item.Status = TaskJobStatus.Completed;
|
|
|
|
|
item.NextTriggerTime = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item.UpdateBy = userId;
|
|
|
|
|
item.UpdateTime = dtNow;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1530,7 +1559,10 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
{
|
|
|
|
|
x.Status,
|
|
|
|
|
x.NextTriggerTime,
|
|
|
|
|
x.LastException
|
|
|
|
|
x.LastException,
|
|
|
|
|
x.RetryTimes,
|
|
|
|
|
x.UpdateBy,
|
|
|
|
|
x.UpdateTime
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
var finishedJobs = jobs.FindAll(x => x.Status == TaskJobStatus.Completed);
|
|
|
|
@ -1545,8 +1577,8 @@ namespace DS.WMS.Core.TaskInteraction.Method
|
|
|
|
|
x.TaskId,
|
|
|
|
|
x.Status
|
|
|
|
|
}).ToListAsync();
|
|
|
|
|
|
|
|
|
|
var groups = list.GroupBy(x => x.TaskId);
|
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
|
|
foreach (var group in groups)
|
|
|
|
|
{
|
|
|
|
|
if (group.Count() == group.Count(x => x.Status == TaskJobStatus.Completed))
|
|
|
|
|