T1-T4: TaskController+3个IJob改用IServiceProvider构造注入+RuleEngineJob标记废弃
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using VolPro.Core.Filters;
|
||||
using Warehouse.Services;
|
||||
|
||||
namespace Warehouse.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 定时任务 API 端点。
|
||||
/// VolPro 框架通过 Sys_QuartzOptions 配置 URL+Cron 定时调用。
|
||||
/// 每个方法加 [ApiTask] 属性以允许框架匿名调用。
|
||||
///
|
||||
/// 管理端配置:
|
||||
/// syncDevices: 0 */5 * * * ?
|
||||
/// heartbeatMonitor: 0/15 * * * * ?
|
||||
/// realtimePoll: 0/10 * * * * ?
|
||||
/// ruleEngine: 0/10 * * * * ?
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/task")]
|
||||
public class TaskController : Controller
|
||||
{
|
||||
/// <summary>设备同步 — 遍历在线网关触发全量设备同步</summary>
|
||||
[ApiTask]
|
||||
[HttpGet, HttpPost, Route("syncDevices")]
|
||||
public async Task<IActionResult> SyncDevices()
|
||||
{
|
||||
var sp = HttpContext.RequestServices;
|
||||
var engine = sp.GetService<SyncDevicesJob>();
|
||||
if (engine != null) await engine.Execute(null!);
|
||||
return Ok(new { time = DateTime.Now, status = "ok" });
|
||||
}
|
||||
|
||||
/// <summary>心跳监控 — 扫描超时网关标记离线</summary>
|
||||
[ApiTask]
|
||||
[HttpGet, HttpPost, Route("heartbeatMonitor")]
|
||||
public async Task<IActionResult> HeartbeatMonitor()
|
||||
{
|
||||
var sp = HttpContext.RequestServices;
|
||||
var engine = sp.GetService<HeartbeatMonitorJob>();
|
||||
if (engine != null) await engine.Execute(null!);
|
||||
return Ok(new { time = DateTime.Now, status = "ok" });
|
||||
}
|
||||
|
||||
/// <summary>实时轮询 — 拉取 MC4 IoT 实时值写入 iot_devicedata</summary>
|
||||
[ApiTask]
|
||||
[HttpGet, HttpPost, Route("realtimePoll")]
|
||||
public async Task<IActionResult> RealtimePoll()
|
||||
{
|
||||
var sp = HttpContext.RequestServices;
|
||||
var engine = sp.GetService<RealtimePollJob>();
|
||||
if (engine != null) await engine.Execute(null!);
|
||||
return Ok(new { time = DateTime.Now, status = "ok" });
|
||||
}
|
||||
|
||||
/// <summary>规则引擎 — 评估规则条件+执行告警/控制/通知动作</summary>
|
||||
[ApiTask]
|
||||
[HttpGet, HttpPost, Route("ruleEngine")]
|
||||
public async Task<IActionResult> RuleEngine()
|
||||
{
|
||||
var sp = HttpContext.RequestServices;
|
||||
var engine = sp.GetService<RuleEngineService>();
|
||||
if (engine != null) await engine.EvaluateAllAsync();
|
||||
return Ok(new { time = DateTime.Now, status = "ok" });
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,12 @@ namespace VolPro.Warehouse.Services;
|
||||
/// </summary>
|
||||
public class HeartbeatMonitorJob : IJob
|
||||
{
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
private readonly IServiceProvider _sp;
|
||||
public HeartbeatMonitorJob(IServiceProvider sp) { _sp = sp; }
|
||||
|
||||
public async Task Execute(IJobExecutionContext? context)
|
||||
{
|
||||
var sp = (IServiceProvider)context.JobDetail.JobDataMap["ServiceProvider"];
|
||||
var sp = _sp;
|
||||
if (sp == null) return;
|
||||
|
||||
var gwSvc = sp.GetService<Igateway_nodesService>();
|
||||
|
||||
@@ -18,9 +18,12 @@ namespace VolPro.Warehouse.Services;
|
||||
/// </summary>
|
||||
public class RealtimePollJob : IJob
|
||||
{
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
private readonly IServiceProvider _sp;
|
||||
public RealtimePollJob(IServiceProvider sp) { _sp = sp; }
|
||||
|
||||
public async Task Execute(IJobExecutionContext? context)
|
||||
{
|
||||
var sp = (IServiceProvider)context.JobDetail.JobDataMap["ServiceProvider"];
|
||||
var sp = _sp;
|
||||
if (sp == null) return;
|
||||
|
||||
var gwSvc = sp.GetService<Igateway_nodesService>();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Quartz;
|
||||
// 已迁移到 TaskController.RuleEngine() — 构建时需删除此文件
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
@@ -14,9 +14,12 @@ namespace VolPro.Warehouse.Services;
|
||||
/// </summary>
|
||||
public class SyncDevicesJob : IJob
|
||||
{
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
private readonly IServiceProvider _sp;
|
||||
public SyncDevicesJob(IServiceProvider sp) { _sp = sp; }
|
||||
|
||||
public async Task Execute(IJobExecutionContext? context)
|
||||
{
|
||||
var sp = (IServiceProvider)context.JobDetail.JobDataMap["ServiceProvider"];
|
||||
var sp = _sp;
|
||||
var gwSvc = sp.GetService<Igateway_nodesService>();
|
||||
var client = sp.GetService<GatewayClient>();
|
||||
if (gwSvc == null || client == null) return;
|
||||
|
||||
Reference in New Issue
Block a user