全量提交: KMS适配器终检修复+warehouse P0修复+MC4认证修复+网关B路由+接口文档+代码审核报告
This commit is contained in:
@@ -1,66 +1,80 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using VolPro.Core.Filters;
|
||||
using Warehouse.Services;
|
||||
using Warehouse.IServices;
|
||||
|
||||
namespace Warehouse.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 定时任务 API 端点。
|
||||
/// VolPro 框架通过 Sys_QuartzOptions 配置 URL+Cron 定时调用。
|
||||
/// Vol.Pro 框架通过 Sys_QuartzOptions 表配置 URL+Cron 定时调用。
|
||||
/// 每个方法加 [ApiTask] 属性以允许框架匿名调用。
|
||||
///
|
||||
/// 管理端配置:
|
||||
/// syncDevices: 0 */5 * * * ?
|
||||
/// heartbeatMonitor: 0/15 * * * * ?
|
||||
/// realtimePoll: 0/10 * * * * ?
|
||||
/// ruleEngine: 0/10 * * * * ?
|
||||
/// 不在 Controller 层注入具体业务类——通过 HttpContext.RequestServices 按需解析,
|
||||
/// 避免 Controller 构造函数的 DI 依赖链过长。
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/task")]
|
||||
public class TaskController : Controller
|
||||
{
|
||||
/// <summary>设备同步 — 遍历在线网关触发全量设备同步</summary>
|
||||
/// <summary>T1: 设备同步 — 遍历在线网关触发全量设备同步(每5分钟)</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!);
|
||||
if (sp.GetService<Igateway_nodesService>() == null)
|
||||
return StatusCode(500, new { error = "服务未注册: gateway_nodesService" });
|
||||
|
||||
// 复用 SyncDevicesJob 的核心流程(Job 内部自行创建 GatewayClient)
|
||||
var job = new VolPro.Warehouse.Services.SyncDevicesJob(sp);
|
||||
await job.Execute(null!);
|
||||
return Ok(new { time = DateTime.Now, status = "ok" });
|
||||
}
|
||||
|
||||
/// <summary>心跳监控 — 扫描超时网关标记离线</summary>
|
||||
/// <summary>T2: 心跳监控 — 扫描超时网关标记离线(每15秒)</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!);
|
||||
var gwSvc = sp.GetService<Igateway_nodesService>();
|
||||
if (gwSvc == null)
|
||||
return StatusCode(500, new { error = "服务未注册: gateway_nodesService" });
|
||||
|
||||
var job = new VolPro.Warehouse.Services.HeartbeatMonitorJob(sp);
|
||||
await job.Execute(null!);
|
||||
return Ok(new { time = DateTime.Now, status = "ok" });
|
||||
}
|
||||
|
||||
/// <summary>实时轮询 — 拉取 MC4 IoT 实时值写入 iot_devicedata</summary>
|
||||
/// <summary>T3: 实时轮询 — 拉取 MC4 IoT 实时值(每10秒)</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!);
|
||||
var gwSvc = sp.GetService<Igateway_nodesService>();
|
||||
if (gwSvc == null)
|
||||
return StatusCode(500, new { error = "服务未注册: gateway_nodesService" });
|
||||
|
||||
var job = new VolPro.Warehouse.Services.RealtimePollJob(sp);
|
||||
await job.Execute(null!);
|
||||
return Ok(new { time = DateTime.Now, status = "ok" });
|
||||
}
|
||||
|
||||
/// <summary>规则引擎 — 评估规则条件+执行告警/控制/通知动作</summary>
|
||||
/// <summary>T4: 规则引擎 — 评估规则+执行动作(每10秒)</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();
|
||||
var ruleRepo = sp.GetService<Warehouse.IRepositories.Iwarehouse_ruleRepository>();
|
||||
if (ruleRepo == null)
|
||||
return StatusCode(500, new { error = "服务未注册: Iwarehouse_ruleRepository" });
|
||||
|
||||
var engine = new Warehouse.Services.RuleEngineService(ruleRepo);
|
||||
await engine.EvaluateAllAsync();
|
||||
return Ok(new { time = DateTime.Now, status = "ok" });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user