Skip to content

Commit

Permalink
优化延迟任务和错误任务查询
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Sep 19, 2024
1 parent fc99dd7 commit 39fa220
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
8 changes: 6 additions & 2 deletions AntJob.Data/Entity/作业任务.Biz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,15 @@ public static IList<JobTask> FindAllByJobIDAndDataTime(Int32 jobId, DateTime dat
/// <param name="appid"></param>
/// <param name="jobid"></param>
/// <param name="status"></param>
/// <param name="dataStart"></param>
/// <param name="dataEnd"></param>
/// <param name="start"></param>
/// <param name="end"></param>
/// <param name="client"></param>
/// <param name="key"></param>
/// <param name="p"></param>
/// <returns></returns>
public static IEnumerable<JobTask> Search(Int32 id, Int32 appid, Int32 jobid, JobStatus status, DateTime start, DateTime end, String client, String key, PageParameter p)
public static IEnumerable<JobTask> Search(Int32 id, Int32 appid, Int32 jobid, JobStatus status, DateTime dataStart, DateTime dataEnd, DateTime start, DateTime end, String client, String key, PageParameter p)
{
var exp = new WhereExpression();

Expand All @@ -153,6 +155,8 @@ public static IEnumerable<JobTask> Search(Int32 id, Int32 appid, Int32 jobid, Jo
if (status >= JobStatus.就绪) exp &= _.Status == status;
if (!client.IsNullOrEmpty()) exp &= _.Client == client;
if (!key.IsNullOrEmpty()) exp &= _.Data.Contains(key) | _.Message.Contains(key) | _.Key == key;

exp &= _.DataTime.Between(dataStart, dataEnd);
exp &= _.DataTime.Between(start, end);

return FindAll(exp, p);
Expand Down Expand Up @@ -180,7 +184,7 @@ public static IList<JobTask> Search(Int32 taskid, DateTime start, DateTime end,
if (start.Year > 2000) exp &= _.UpdateTime >= start;
if (end.Year > 2000) exp &= _.UpdateTime < end;

return FindAll(exp, _.ID.Asc(), null, 0, count);
return FindAll(exp, _.UpdateTime.Asc(), null, 0, count);
}
#endregion

Expand Down
8 changes: 5 additions & 3 deletions AntJob.Web/Areas/Ant/Controllers/JobTaskController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.AspNetCore.Mvc;
using NewLife;
using NewLife.Cube;
using NewLife.Cube.Entity;
using NewLife.Cube.Extensions;
using NewLife.Cube.ViewModels;
using NewLife.Data;
Expand Down Expand Up @@ -137,16 +136,19 @@ protected override IEnumerable<JobTask> Search(Pager p)
var jobid = p["JobID"].ToInt(-1);
var appid = p["AppID"].ToInt(-1);
var status = (JobStatus)p["Status"].ToInt(-1);
var client = p["Client"];

var dataStart = p["dataStart"].ToDateTime();
var dataEnd = p["dataEnd"].ToDateTime();
var start = p["dtStart"].ToDateTime();
var end = p["dtEnd"].ToDateTime();
var client = p["Client"];

if (jobid > 0)
{
ListFields.RemoveField("JobID");
}

return JobTask.Search(id, appid, jobid, status, start, end, client, p["q"], p);
return JobTask.Search(id, appid, jobid, status, dataStart, dataEnd, start, end, client, p["q"], p);
}

/// <summary>修改状态</summary>
Expand Down
42 changes: 42 additions & 0 deletions AntJob.Web/Areas/Ant/Views/JobTask/_DataRange.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@using NewLife;
@{
var fmt = Model as String;
var formatStr = !fmt.IsNullOrEmpty() ? fmt : "yyyy-MM-dd";
var p = ViewBag.Page as Pager;

var dataStart = p["dataStart"].ToDateTime();
var dataEnd = p["dataEnd"].ToDateTime();
var step = (Int32)(dataEnd - dataStart).TotalDays + 1;
}
<div class="form-group">
<label for="dataStart" class="control-label">数据时间:</label>
<div class="input-group">
@if (formatStr == "yyyy-MM-dd" && (dataStart.Year > 2000 || dataEnd.Year > 2000))
{
var url = p.GetBaseUrl(true, true, true, new[] { "dataStart", "dataEnd" });
if (dataStart.Year > 2000 && dataEnd.Year > 2000) url.UrlParam("dataStart", dataStart.AddDays(-step).ToString("yyyy-MM-dd"));
if (dataStart.Year > 2000 && dataEnd.Year > 2000) url.UrlParam("dataEnd", dataEnd.AddDays(-step).ToString("yyyy-MM-dd"));
<span class="input-group-addon"><a href="[email protected](url)" title="前一段"><i class="fa fa-calendar"></i></a></span>
}
else
{
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
}
<input name="dataStart" id="dataStart" value="@p["dataStart"]" dateformat="@formatStr" class="form-control form_datetime" autocomplete="off" />
</div>
@if (formatStr == "yyyy-MM-dd" && (dataStart.Year > 2000 || dataEnd.Year > 2000))
{
var url = p.GetBaseUrl(true, true, true, new[] { "dataStart", "dataEnd" });
if (dataStart.Year > 2000 && dataEnd.Year > 2000) url.UrlParam("dataStart", dataStart.AddDays(step).ToString("yyyy-MM-dd"));
if (dataStart.Year > 2000 && dataEnd.Year > 2000) url.UrlParam("dataEnd", dataEnd.AddDays(step).ToString("yyyy-MM-dd"));
<label for="dataEnd" class="control-label"><a href="[email protected](url)" title="后一段">~</a></label>
}
else
{
<label for="dataEnd" class="control-label">~</label>
}
<div class="input-group">
@*<span class="input-group-addon"><i class="fa fa-calendar"></i></span>*@
<input name="dataEnd" id="dataEnd" value="@p["dataEnd"]" dateformat="@formatStr" class="form-control form_datetime" autocomplete="off" />
</div>
</div>

0 comments on commit 39fa220

Please sign in to comment.