|
|
/**
|
|
|
* Haoliang.Core.Services - 核心业务服务接口层
|
|
|
*
|
|
|
* 本文件定义CNC机床数据采集分析系统的所有核心业务服务接口。
|
|
|
* 采用依赖注入模式,确保各层解耦和可测试性。
|
|
|
*
|
|
|
* 接口设计原则:
|
|
|
* 1. 每个接口职责单一,便于实现和测试
|
|
|
* 2. 方法命名清晰,体现业务语义
|
|
|
* 3. 支持异步操作,提升系统吞吐量
|
|
|
* 4. 返回类型明确,便于调用方处理
|
|
|
*
|
|
|
* 修订历史:
|
|
|
* - 2024-01-01: 初始版本,定义系统核心服务接口
|
|
|
*/
|
|
|
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Threading.Tasks;
|
|
|
using Haoliang.Models.User;
|
|
|
using Haoliang.Models.Device;
|
|
|
using Haoliang.Models.Production;
|
|
|
using Haoliang.Models.System;
|
|
|
using Haoliang.Models.Template;
|
|
|
using Haoliang.Models.DataCollection;
|
|
|
|
|
|
namespace Haoliang.Core.Services
|
|
|
{
|
|
|
#region ========== 用户与认证服务 ==========
|
|
|
|
|
|
/// <summary>
|
|
|
/// 认证服务接口
|
|
|
///
|
|
|
/// 负责用户登录、登出、令牌刷新等认证相关业务逻辑。
|
|
|
/// 支持JWT令牌认证机制,提供安全的会话管理。
|
|
|
/// </summary>
|
|
|
public interface IAuthService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 用户登录
|
|
|
/// </summary>
|
|
|
/// <param name="request">登录请求,包含用户名和密码</param>
|
|
|
/// <returns>认证结果,包含令牌和用户信息</returns>
|
|
|
Task<AuthResult> LoginAsync(LoginRequest request);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 用户登出
|
|
|
/// </summary>
|
|
|
/// <param name="userId">用户ID</param>
|
|
|
/// <returns>登出是否成功</returns>
|
|
|
Task<bool> LogoutAsync(int userId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 刷新访问令牌
|
|
|
/// </summary>
|
|
|
/// <param name="refreshToken">刷新令牌</param>
|
|
|
/// <returns>新的认证结果</returns>
|
|
|
Task<AuthResult> RefreshTokenAsync(string refreshToken);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 检查用户名是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="username">用户名</param>
|
|
|
/// <returns>是否存在</returns>
|
|
|
Task<bool> UsernameExistsAsync(string username);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 检查邮箱是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="email">邮箱地址</param>
|
|
|
/// <returns>是否存在</returns>
|
|
|
Task<bool> EmailExistsAsync(string email);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 用户服务接口
|
|
|
///
|
|
|
/// 负责用户 CRUD 操作、密码管理、用户状态维护等。
|
|
|
/// 与认证服务配合完成完整的用户管理功能。
|
|
|
/// </summary>
|
|
|
public interface IUserService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 创建用户
|
|
|
/// </summary>
|
|
|
/// <param name="user">用户实体</param>
|
|
|
/// <returns>创建的用户视图模型</returns>
|
|
|
Task<UserViewModel> CreateUserAsync(User user);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据ID获取用户
|
|
|
/// </summary>
|
|
|
/// <param name="userId">用户ID</param>
|
|
|
/// <returns>用户视图模型,不存在返回null</returns>
|
|
|
Task<UserViewModel> GetUserByIdAsync(int userId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取所有用户
|
|
|
/// </summary>
|
|
|
/// <returns>用户列表</returns>
|
|
|
Task<IEnumerable<UserViewModel>> GetAllUsersAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新用户信息
|
|
|
/// </summary>
|
|
|
/// <param name="userId">用户ID</param>
|
|
|
/// <param name="user">用户更新数据</param>
|
|
|
/// <returns>更新后的用户视图模型</returns>
|
|
|
Task<UserViewModel> UpdateUserAsync(int userId, User user);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 修改密码
|
|
|
/// </summary>
|
|
|
/// <param name="userId">用户ID</param>
|
|
|
/// <param name="oldPassword">旧密码</param>
|
|
|
/// <param name="newPassword">新密码</param>
|
|
|
/// <returns>修改是否成功</returns>
|
|
|
Task<bool> ChangePasswordAsync(int userId, string oldPassword, string newPassword);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 激活用户
|
|
|
/// </summary>
|
|
|
/// <param name="userId">用户ID</param>
|
|
|
/// <returns>操作是否成功</returns>
|
|
|
Task<bool> ActivateUserAsync(int userId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 停用用户
|
|
|
/// </summary>
|
|
|
/// <param name="userId">用户ID</param>
|
|
|
/// <returns>操作是否成功</returns>
|
|
|
Task<bool> DeactivateUserAsync(int userId);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 权限服务接口
|
|
|
///
|
|
|
/// 负责权限和角色的管理、用户权限分配、权限验证等。
|
|
|
/// 支持基于角色的访问控制(RBAC)和基于权限的访问控制。
|
|
|
/// </summary>
|
|
|
public interface IPermissionService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 获取用户的权限列表
|
|
|
/// </summary>
|
|
|
/// <param name="userId">用户ID</param>
|
|
|
/// <returns>权限标识列表</returns>
|
|
|
Task<IEnumerable<string>> GetUserPermissionsAsync(int userId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 检查用户是否拥有指定权限
|
|
|
/// </summary>
|
|
|
/// <param name="userId">用户ID</param>
|
|
|
/// <param name="permission">权限标识</param>
|
|
|
/// <returns>是否拥有权限</returns>
|
|
|
Task<bool> HasPermissionAsync(int userId, string permission);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 分配权限给用户
|
|
|
/// </summary>
|
|
|
/// <param name="userId">用户ID</param>
|
|
|
/// <param name="permissions">权限列表</param>
|
|
|
Task AssignPermissionsToUserAsync(int userId, IEnumerable<string> permissions);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 移除用户的所有权限
|
|
|
/// </summary>
|
|
|
/// <param name="userId">用户ID</param>
|
|
|
Task RemoveAllPermissionsFromUserAsync(int userId);
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region ========== 日志与缓存服务 ==========
|
|
|
|
|
|
/// <summary>
|
|
|
/// 日志服务接口
|
|
|
///
|
|
|
/// 提供结构化日志记录功能,支持多级别日志、日志查询和归档。
|
|
|
/// 日志级别:Debug、Info、Warning、Error、Critical
|
|
|
/// </summary>
|
|
|
public interface ILoggingService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 记录信息日志
|
|
|
/// </summary>
|
|
|
/// <param name="message">日志消息</param>
|
|
|
Task LogInformationAsync(string message);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 记录警告日志
|
|
|
/// </summary>
|
|
|
/// <param name="message">日志消息</param>
|
|
|
Task LogWarningAsync(string message);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 记录错误日志
|
|
|
/// </summary>
|
|
|
/// <param name="message">日志消息</param>
|
|
|
/// <param name="exception">异常对象</param>
|
|
|
Task LogErrorAsync(string message, Exception? exception = null);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取日志列表
|
|
|
/// </summary>
|
|
|
/// <param name="logLevel">日志级别过滤</param>
|
|
|
/// <param name="startDate">开始日期</param>
|
|
|
/// <param name="endDate">结束日期</param>
|
|
|
/// <param name="category">日志类别</param>
|
|
|
/// <returns>日志条目列表</returns>
|
|
|
Task<IEnumerable<Haoliang.Models.System.LogEntry>> GetLogsAsync(Haoliang.Models.System.LogLevel? logLevel, DateTime? startDate, DateTime? endDate, string? category = null);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取错误日志
|
|
|
/// </summary>
|
|
|
/// <param name="startDate">开始日期</param>
|
|
|
/// <param name="endDate">结束日期</param>
|
|
|
/// <returns>错误日志列表</returns>
|
|
|
Task<IEnumerable<Haoliang.Models.System.LogEntry>> GetErrorLogsAsync(DateTime? startDate = null, DateTime? endDate = null);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取日志数量
|
|
|
/// </summary>
|
|
|
/// <param name="logLevel">日志级别过滤</param>
|
|
|
/// <param name="startDate">开始日期</param>
|
|
|
/// <param name="endDate">结束日期</param>
|
|
|
/// <returns>日志数量</returns>
|
|
|
Task<int> GetLogCountAsync(Haoliang.Models.System.LogLevel? logLevel = null, DateTime? startDate = null, DateTime? endDate = null);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 归档日志
|
|
|
/// </summary>
|
|
|
/// <param name="daysToKeep">保留天数</param>
|
|
|
Task ArchiveLogsAsync(int daysToKeep = 90);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 清除所有日志
|
|
|
/// </summary>
|
|
|
Task ClearLogsAsync();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 缓存服务接口
|
|
|
///
|
|
|
/// 提供内存缓存和分布式缓存支持,用于提升系统性能。
|
|
|
/// 支持缓存过期、缓存失效、缓存统计等功能。
|
|
|
/// </summary>
|
|
|
public interface ICacheService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 获取缓存值
|
|
|
/// </summary>
|
|
|
/// <typeparam name="T">缓存值类型</typeparam>
|
|
|
/// <param name="key">缓存键</param>
|
|
|
/// <returns>缓存值,不存在返回null</returns>
|
|
|
T? Get<T>(string key) where T : class;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 设置缓存值
|
|
|
/// </summary>
|
|
|
/// <typeparam name="T">缓存值类型</typeparam>
|
|
|
/// <param name="key">缓存键</param>
|
|
|
/// <param name="value">缓存值</param>
|
|
|
/// <param name="expiration">过期时间</param>
|
|
|
void Set<T>(string key, T value, TimeSpan? expiration = null) where T : class;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 移除缓存
|
|
|
/// </summary>
|
|
|
/// <param name="key">缓存键</param>
|
|
|
/// <returns>是否成功移除</returns>
|
|
|
bool Remove(string key);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 检查缓存是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="key">缓存键</param>
|
|
|
/// <returns>是否存在</returns>
|
|
|
bool Exists(string key);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取或设置缓存
|
|
|
/// </summary>
|
|
|
/// <typeparam name="T">缓存值类型</typeparam>
|
|
|
/// <param name="key">缓存键</param>
|
|
|
/// <param name="factory">缓存不存在时的工厂方法</param>
|
|
|
/// <param name="expiration">过期时间</param>
|
|
|
/// <returns>缓存值</returns>
|
|
|
T GetOrSet<T>(string key, Func<T> factory, TimeSpan? expiration = null) where T : class;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 清除所有缓存
|
|
|
/// </summary>
|
|
|
void Clear();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取缓存统计信息
|
|
|
/// </summary>
|
|
|
/// <returns>缓存统计</returns>
|
|
|
CacheStats GetStatistics();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 缓存统计信息
|
|
|
/// </summary>
|
|
|
public class CacheStats
|
|
|
{
|
|
|
public long TotalItems { get; set; }
|
|
|
public long HitCount { get; set; }
|
|
|
public long MissCount { get; set; }
|
|
|
public double HitRate => HitCount + MissCount > 0 ? (double)HitCount / (HitCount + MissCount) : 0;
|
|
|
public long MemoryUsageBytes { get; set; }
|
|
|
public DateTime LastCleared { get; set; }
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region ========== 设备与采集服务 ==========
|
|
|
|
|
|
/// <summary>
|
|
|
/// 设备采集服务接口
|
|
|
///
|
|
|
/// 负责CNC设备的添加、删除、更新、查询,
|
|
|
/// 以及设备数据采集的启动、停止、状态监控等功能。
|
|
|
/// 支持多品牌CNC设备(发那科、三菱、西门子等)的统一采集。
|
|
|
/// </summary>
|
|
|
public interface IDeviceCollectionService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 获取所有设备
|
|
|
/// </summary>
|
|
|
/// <returns>设备列表</returns>
|
|
|
Task<IEnumerable<CNCDevice>> GetAllDevicesAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据ID获取设备
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <returns>设备信息,不存在返回null</returns>
|
|
|
Task<CNCDevice?> GetDeviceByIdAsync(int deviceId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 创建设备
|
|
|
/// </summary>
|
|
|
/// <param name="device">设备信息</param>
|
|
|
/// <returns>创建的设备</returns>
|
|
|
Task<CNCDevice> CreateDeviceAsync(CNCDevice device);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新设备信息
|
|
|
/// </summary>
|
|
|
/// <param name="device">设备信息</param>
|
|
|
/// <returns>更新后的设备,不存在返回null</returns>
|
|
|
Task<CNCDevice?> UpdateDeviceAsync(CNCDevice device);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除设备
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <returns>是否删除成功</returns>
|
|
|
Task<bool> DeleteDeviceAsync(int deviceId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 采集指定设备数据
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
Task CollectDeviceAsync(int deviceId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 采集所有设备数据
|
|
|
/// </summary>
|
|
|
Task CollectAllDevicesAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取设备状态
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <returns>设备状态信息</returns>
|
|
|
Task<DeviceStatus> GetDeviceStatusAsync(int deviceId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取设备健康状态
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <returns>健康状态信息</returns>
|
|
|
Task<DeviceHealth> GetDeviceHealthAsync(int deviceId);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 设备状态机服务接口
|
|
|
///
|
|
|
/// 管理和维护设备状态转换逻辑,包括:
|
|
|
/// - 在线/离线状态
|
|
|
/// - 运行/空闲/报警状态
|
|
|
/// - 状态转换规则和事件触发
|
|
|
///
|
|
|
/// 采用状态模式实现,支持自定义状态转换规则。
|
|
|
/// </summary>
|
|
|
public interface IDeviceStateMachine
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 获取设备当前状态
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <returns>设备状态</returns>
|
|
|
DeviceStatus GetCurrentState(int deviceId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 触发状态转换
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <param name="newState">新状态</param>
|
|
|
/// <returns>转换是否成功</returns>
|
|
|
bool TransitionTo(int deviceId, DeviceStatus newState);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 注册状态变更监听器
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <param name="callback">回调函数</param>
|
|
|
void RegisterStateChangeHandler(int deviceId, Action<int, DeviceStatus, DeviceStatus> callback);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取设备状态历史
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <param name="fromTime">开始时间</param>
|
|
|
/// <param name="toTime">结束时间</param>
|
|
|
/// <returns>状态历史记录</returns>
|
|
|
IEnumerable<DeviceStatusChange> GetStateHistory(int deviceId, DateTime fromTime, DateTime toTime);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Ping服务接口
|
|
|
///
|
|
|
/// 提供设备网络连通性检测功能,用于判断设备是否在线。
|
|
|
/// 支持批量Ping和异步Ping操作。
|
|
|
/// </summary>
|
|
|
public interface IPingService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// Ping指定设备
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <param name="ipAddress">IP地址</param>
|
|
|
/// <returns>Ping结果</returns>
|
|
|
Task<PingResult> PingAsync(int deviceId, string ipAddress);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 批量Ping设备
|
|
|
/// </summary>
|
|
|
/// <param name="devices">设备列表(ID和IP)</param>
|
|
|
/// <returns>Ping结果列表</returns>
|
|
|
Task<IEnumerable<PingResult>> PingAllAsync(IEnumerable<(int DeviceId, string IpAddress)> devices);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 检查设备是否可达
|
|
|
/// </summary>
|
|
|
/// <param name="ipAddress">IP地址</param>
|
|
|
/// <param name="timeout">超时时间</param>
|
|
|
/// <returns>是否可达</returns>
|
|
|
Task<bool> IsReachableAsync(string ipAddress, TimeSpan? timeout = null);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Ping结果
|
|
|
/// </summary>
|
|
|
public class PingResult
|
|
|
{
|
|
|
public int DeviceId { get; set; }
|
|
|
public string IpAddress { get; set; } = string.Empty;
|
|
|
public bool Success { get; set; }
|
|
|
public long RoundtripTime { get; set; }
|
|
|
public string? ErrorMessage { get; set; }
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 设备状态变更记录
|
|
|
/// </summary>
|
|
|
public class DeviceStatusChange
|
|
|
{
|
|
|
public int DeviceId { get; set; }
|
|
|
public DeviceStatus? FromState { get; set; }
|
|
|
public DeviceStatus? ToState { get; set; }
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
public string? Reason { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 设备健康状态
|
|
|
/// </summary>
|
|
|
public class DeviceHealth
|
|
|
{
|
|
|
public int DeviceId { get; set; }
|
|
|
public bool IsHealthy { get; set; }
|
|
|
public double CpuUsage { get; set; }
|
|
|
public double MemoryUsage { get; set; }
|
|
|
public double DiskUsage { get; set; }
|
|
|
public int ActiveAlerts { get; set; }
|
|
|
public DateTime LastCheck { get; set; }
|
|
|
public List<HealthIssue>? Issues { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 健康问题
|
|
|
/// </summary>
|
|
|
public class HealthIssue
|
|
|
{
|
|
|
public string? Type { get; set; }
|
|
|
public string? Description { get; set; }
|
|
|
public string? Severity { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 设备状态
|
|
|
/// </summary>
|
|
|
public class DeviceStatus
|
|
|
{
|
|
|
public int DeviceId { get; set; }
|
|
|
public string? Status { get; set; }
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
public string? OperatingMode { get; set; }
|
|
|
public string? RunState { get; set; }
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region ========== 生产与统计服务 ==========
|
|
|
|
|
|
/// <summary>
|
|
|
/// 生产服务接口
|
|
|
///
|
|
|
/// 负责生产数据的查询、计算、导出等功能。
|
|
|
/// 支持按设备、程序、日期等多维度统计。
|
|
|
/// 采用差分计算逻辑处理累计值,详见设计文档。
|
|
|
/// </summary>
|
|
|
public interface IProductionService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 获取生产汇总
|
|
|
/// </summary>
|
|
|
/// <param name="date">日期</param>
|
|
|
/// <returns>生产汇总</returns>
|
|
|
Task<ProductionSummary> GetProductionSummaryAsync(DateTime date);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取生产统计
|
|
|
/// </summary>
|
|
|
/// <param name="date">日期</param>
|
|
|
/// <returns>统计结果</returns>
|
|
|
Task<ProductionStatistics> GetProductionStatisticsAsync(DateTime date);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取指定设备的今日生产数据
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <returns>生产数据</returns>
|
|
|
Task<ProductionRecord> GetTodayProductionAsync(int deviceId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取指定设备的生产统计
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <param name="date">日期</param>
|
|
|
/// <returns>统计结果</returns>
|
|
|
Task<ProductionStatistics> GetProductionStatisticsAsync(int deviceId, DateTime date);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取质量率
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <param name="date">日期</param>
|
|
|
/// <returns>质量率百分比</returns>
|
|
|
Task<decimal> GetQualityRateAsync(int deviceId, DateTime date);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 计算所有设备的生产数据
|
|
|
/// </summary>
|
|
|
Task CalculateAllProductionAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 计算指定设备的生产数据
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
Task CalculateProductionAsync(int deviceId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取生产程序列表
|
|
|
/// </summary>
|
|
|
/// <param name="date">日期</param>
|
|
|
/// <returns>程序列表</returns>
|
|
|
Task<IEnumerable<string>> GetProductionProgramsAsync(DateTime date);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取指定程序的生产数据
|
|
|
/// </summary>
|
|
|
/// <param name="programName">程序名</param>
|
|
|
/// <param name="date">日期</param>
|
|
|
/// <returns>程序生产数据</returns>
|
|
|
Task<Haoliang.Models.Production.ProgramProductionSummary> GetProgramProductionAsync(string programName, DateTime date);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 导出生产数据
|
|
|
/// </summary>
|
|
|
/// <param name="startDate">开始日期</param>
|
|
|
/// <param name="endDate">结束日期</param>
|
|
|
/// <returns>CSV文件字节数组</returns>
|
|
|
Task<byte[]> ExportProductionDataAsync(DateTime startDate, DateTime endDate);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 归档生产数据
|
|
|
/// </summary>
|
|
|
/// <param name="daysToKeep">保留天数</param>
|
|
|
Task ArchiveProductionDataAsync(int daysToKeep = 90);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 生产计算器接口
|
|
|
///
|
|
|
/// 负责根据采集的原始数据计算生产数量。
|
|
|
/// 实现差分计算逻辑,处理程序切换、跨天等情况。
|
|
|
/// </summary>
|
|
|
public interface IProductionCalculator
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 计算单个设备的生产增量
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <param name="currentValue">当前累计值</param>
|
|
|
/// <param name="programName">当前程序名</param>
|
|
|
/// <param name="timestamp">时间戳</param>
|
|
|
/// <returns>生产增量</returns>
|
|
|
Task<decimal> CalculateProductionIncrementAsync(int deviceId, decimal currentValue, string programName, DateTime timestamp);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 重置设备的生产状态
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
void ResetDeviceProductionState(int deviceId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 验证生产数据的有效性
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <param name="value">累计值</param>
|
|
|
/// <returns>是否有效</returns>
|
|
|
bool ValidateProductionValue(int deviceId, decimal value);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 生产调度器接口
|
|
|
///
|
|
|
/// 负责生产统计任务的调度执行,
|
|
|
/// 包括定时计算、数据归档、报表生成等。
|
|
|
/// </summary>
|
|
|
public interface IProductionScheduler
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 启动调度器
|
|
|
/// </summary>
|
|
|
Task StartAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 停止调度器
|
|
|
/// </summary>
|
|
|
Task StopAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 注册定时任务
|
|
|
/// </summary>
|
|
|
/// <param name="taskId">任务ID</param>
|
|
|
/// <param name="schedule">调度表达式</param>
|
|
|
/// <param name="action">任务动作</param>
|
|
|
void RegisterTask(string taskId, string schedule, Func<Task> action);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 移除定时任务
|
|
|
/// </summary>
|
|
|
/// <param name="taskId">任务ID</param>
|
|
|
void RemoveTask(string taskId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取调度器状态
|
|
|
/// </summary>
|
|
|
/// <returns>是否运行中</returns>
|
|
|
bool IsRunning { get; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 生产统计服务接口
|
|
|
///
|
|
|
/// 提供高级生产分析功能,包括:
|
|
|
/// - 生产趋势分析
|
|
|
/// - OEE计算
|
|
|
/// - 效率指标
|
|
|
/// - 质量分析
|
|
|
/// - 预测分析
|
|
|
/// - 异常检测
|
|
|
/// </summary>
|
|
|
public interface IProductionStatisticsService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 计算生产趋势
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <param name="startDate">开始日期</param>
|
|
|
/// <param name="endDate">结束日期</param>
|
|
|
/// <returns>趋势分析结果</returns>
|
|
|
Task<ProductionTrendAnalysis> CalculateProductionTrendsAsync(int deviceId, DateTime startDate, DateTime endDate);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 生成生产报表
|
|
|
/// </summary>
|
|
|
/// <param name="filter">报表过滤条件</param>
|
|
|
/// <returns>生产报表</returns>
|
|
|
Task<ProductionReport> GenerateProductionReportAsync(ReportFilter filter);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 计算效率指标
|
|
|
/// </summary>
|
|
|
/// <param name="filter">过滤条件</param>
|
|
|
/// <returns>效率指标</returns>
|
|
|
Task<EfficiencyMetrics> CalculateEfficiencyMetricsAsync(EfficiencyFilter filter);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 执行质量分析
|
|
|
/// </summary>
|
|
|
/// <param name="filter">过滤条件</param>
|
|
|
/// <returns>质量分析结果</returns>
|
|
|
Task<QualityAnalysis> PerformQualityAnalysisAsync(QualityFilter filter);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取仪表盘汇总
|
|
|
/// </summary>
|
|
|
/// <param name="filter">过滤条件</param>
|
|
|
/// <returns>仪表盘数据</returns>
|
|
|
Task<DashboardSummary> GetDashboardSummaryAsync(DashboardFilter filter);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 计算OEE
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <param name="date">日期</param>
|
|
|
/// <returns>OEE指标</returns>
|
|
|
Task<OeeMetrics> CalculateOeeAsync(int deviceId, DateTime date);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 生成生产预测
|
|
|
/// </summary>
|
|
|
/// <param name="filter">预测过滤条件</param>
|
|
|
/// <returns>预测结果</returns>
|
|
|
Task<ProductionForecast> GenerateProductionForecastAsync(ForecastFilter filter);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 检测生产异常
|
|
|
/// </summary>
|
|
|
/// <param name="filter">过滤条件</param>
|
|
|
/// <returns>异常分析结果</returns>
|
|
|
Task<AnomalyAnalysis> DetectProductionAnomaliesAsync(AnomalyFilter filter);
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region ========== 告警服务 ==========
|
|
|
|
|
|
/// <summary>
|
|
|
/// 告警服务接口
|
|
|
///
|
|
|
/// 负责告警的创建、查询、更新、解决等功能。
|
|
|
/// 支持多种告警类型:设备故障、产量异常、运行异常等。
|
|
|
/// </summary>
|
|
|
public interface IAlarmService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 获取所有告警
|
|
|
/// </summary>
|
|
|
/// <returns>告警列表</returns>
|
|
|
Task<IEnumerable<Alarm>> GetAllAlarmsAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据类型获取告警
|
|
|
/// </summary>
|
|
|
/// <param name="type">告警类型</param>
|
|
|
/// <returns>告警列表</returns>
|
|
|
Task<IEnumerable<Alarm>> GetAlarmsByTypeAsync(AlarmType type);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取活跃告警
|
|
|
/// </summary>
|
|
|
/// <returns>活跃告警列表</returns>
|
|
|
Task<IEnumerable<Alarm>> GetActiveAlarmsAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据ID获取告警
|
|
|
/// </summary>
|
|
|
/// <param name="alarmId">告警ID</param>
|
|
|
/// <returns>告警信息</returns>
|
|
|
Task<Alarm?> GetAlarmByIdAsync(int alarmId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 创建告警
|
|
|
/// </summary>
|
|
|
/// <param name="alarm">告警信息</param>
|
|
|
/// <returns>创建的告警</returns>
|
|
|
Task<Alarm> CreateAlarmAsync(Alarm alarm);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新告警
|
|
|
/// </summary>
|
|
|
/// <param name="alarmId">告警ID</param>
|
|
|
/// <param name="alarm">告警信息</param>
|
|
|
/// <returns>更新后的告警</returns>
|
|
|
Task<Alarm?> UpdateAlarmAsync(int alarmId, Alarm alarm);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除告警
|
|
|
/// </summary>
|
|
|
/// <param name="alarmId">告警ID</param>
|
|
|
/// <returns>是否删除成功</returns>
|
|
|
Task<bool> DeleteAlarmAsync(int alarmId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 解决告警
|
|
|
/// </summary>
|
|
|
/// <param name="alarmId">告警ID</param>
|
|
|
/// <param name="resolutionNote">解决备注</param>
|
|
|
/// <returns>是否成功</returns>
|
|
|
Task<bool> ResolveAlarmAsync(int alarmId, string? resolutionNote);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 确认告警
|
|
|
/// </summary>
|
|
|
/// <param name="alarmId">告警ID</param>
|
|
|
/// <param name="acknowledgeNote">确认备注</param>
|
|
|
/// <returns>是否成功</returns>
|
|
|
Task<bool> AcknowledgeAlarmAsync(int alarmId, string? acknowledgeNote);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取设备的告警
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <param name="days">查询天数</param>
|
|
|
/// <returns>告警列表</returns>
|
|
|
Task<IEnumerable<Alarm>> GetDeviceAlarmsAsync(int deviceId, int days = 7);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取严重告警
|
|
|
/// </summary>
|
|
|
/// <returns>严重告警列表</returns>
|
|
|
Task<IEnumerable<Alarm>> GetCriticalAlarmsAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取告警统计
|
|
|
/// </summary>
|
|
|
/// <param name="date">日期</param>
|
|
|
/// <returns>统计结果</returns>
|
|
|
Task<AlarmStatistics> GetAlarmStatisticsAsync(DateTime date);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 按日期范围获取告警
|
|
|
/// </summary>
|
|
|
/// <param name="startDate">开始日期</param>
|
|
|
/// <param name="endDate">结束日期</param>
|
|
|
/// <returns>告警列表</returns>
|
|
|
Task<IEnumerable<Alarm>> GetAlarmsByDateRangeAsync(DateTime startDate, DateTime endDate);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 告警规则服务接口
|
|
|
///
|
|
|
/// 负责告警规则的CRUD和规则测试。
|
|
|
/// 支持自定义告警条件和触发阈值。
|
|
|
/// </summary>
|
|
|
public interface IAlarmRuleService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 获取所有告警规则
|
|
|
/// </summary>
|
|
|
/// <returns>规则列表</returns>
|
|
|
Task<IEnumerable<AlarmRule>> GetAllAlarmRulesAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据ID获取告警规则
|
|
|
/// </summary>
|
|
|
/// <param name="ruleId">规则ID</param>
|
|
|
/// <returns>规则信息</returns>
|
|
|
Task<AlarmRule?> GetAlarmRuleByIdAsync(int ruleId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 创建告警规则
|
|
|
/// </summary>
|
|
|
/// <param name="rule">规则信息</param>
|
|
|
/// <returns>创建的规则</returns>
|
|
|
Task<AlarmRule> CreateAlarmRuleAsync(AlarmRule rule);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新告警规则
|
|
|
/// </summary>
|
|
|
/// <param name="ruleId">规则ID</param>
|
|
|
/// <param name="rule">规则信息</param>
|
|
|
/// <returns>更新后的规则</returns>
|
|
|
Task<AlarmRule?> UpdateAlarmRuleAsync(int ruleId, AlarmRule rule);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除告警规则
|
|
|
/// </summary>
|
|
|
/// <param name="ruleId">规则ID</param>
|
|
|
/// <returns>是否删除成功</returns>
|
|
|
Task<bool> DeleteAlarmRuleAsync(int ruleId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 测试告警规则
|
|
|
/// </summary>
|
|
|
/// <param name="ruleId">规则ID</param>
|
|
|
Task TestAlarmRuleAsync(int ruleId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 启用/禁用告警规则
|
|
|
/// </summary>
|
|
|
/// <param name="ruleId">规则ID</param>
|
|
|
/// <param name="enabled">是否启用</param>
|
|
|
Task SetAlarmRuleEnabledAsync(int ruleId, bool enabled);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 告警通知服务接口
|
|
|
///
|
|
|
/// 负责告警通知的发送和跟踪。
|
|
|
/// 支持多种通知渠道:邮件、短信、微信、Webhook等。
|
|
|
/// </summary>
|
|
|
public interface IAlarmNotificationService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 发送告警通知
|
|
|
/// </summary>
|
|
|
/// <param name="notification">通知信息</param>
|
|
|
Task SendAlarmNotificationAsync(AlarmNotification notification);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 发送告警通知到多个渠道
|
|
|
/// </summary>
|
|
|
/// <param name="alarm">告警信息</param>
|
|
|
/// <param name="channels">通知渠道列表</param>
|
|
|
Task SendAlarmNotificationToChannelsAsync(Alarm alarm, IEnumerable<NotificationChannel> channels);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取通知状态
|
|
|
/// </summary>
|
|
|
/// <param name="notificationId">通知ID</param>
|
|
|
/// <returns>通知状态</returns>
|
|
|
Task<NotificationStatus> GetNotificationStatusAsync(int notificationId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 重试失败的通知
|
|
|
/// </summary>
|
|
|
/// <param name="notificationId">通知ID</param>
|
|
|
Task RetryNotificationAsync(int notificationId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 取消通知
|
|
|
/// </summary>
|
|
|
/// <param name="notificationId">通知ID</param>
|
|
|
Task CancelNotificationAsync(int notificationId);
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region ========== 模板服务 ==========
|
|
|
|
|
|
/// <summary>
|
|
|
/// 模板服务接口
|
|
|
///
|
|
|
/// 负责CNC品牌模板的CRUD、验证、克隆等功能。
|
|
|
/// 支持多品牌(发那科、三菱、西门子等)的字段映射配置。
|
|
|
/// </summary>
|
|
|
public interface ITemplateService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 获取所有模板
|
|
|
/// </summary>
|
|
|
/// <returns>模板列表</returns>
|
|
|
Task<IEnumerable<CNCBrandTemplate>> GetAllTemplatesAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据ID获取模板
|
|
|
/// </summary>
|
|
|
/// <param name="templateId">模板ID</param>
|
|
|
/// <returns>模板信息</returns>
|
|
|
Task<CNCBrandTemplate?> GetTemplateByIdAsync(int templateId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 创建模板
|
|
|
/// </summary>
|
|
|
/// <param name="template">模板信息</param>
|
|
|
/// <returns>创建的模板</returns>
|
|
|
Task<CNCBrandTemplate> CreateTemplateAsync(CNCBrandTemplate template);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新模板
|
|
|
/// </summary>
|
|
|
/// <param name="templateId">模板ID</param>
|
|
|
/// <param name="template">模板信息</param>
|
|
|
/// <returns>更新后的模板</returns>
|
|
|
Task<CNCBrandTemplate?> UpdateTemplateAsync(int templateId, CNCBrandTemplate template);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除模板
|
|
|
/// </summary>
|
|
|
/// <param name="templateId">模板ID</param>
|
|
|
/// <returns>是否删除成功</returns>
|
|
|
Task<bool> DeleteTemplateAsync(int templateId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 启用模板
|
|
|
/// </summary>
|
|
|
/// <param name="templateId">模板ID</param>
|
|
|
/// <returns>是否成功</returns>
|
|
|
Task<bool> EnableTemplateAsync(int templateId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 禁用模板
|
|
|
/// </summary>
|
|
|
/// <param name="templateId">模板ID</param>
|
|
|
/// <returns>是否成功</returns>
|
|
|
Task<bool> DisableTemplateAsync(int templateId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 克隆模板
|
|
|
/// </summary>
|
|
|
/// <param name="templateId">源模板ID</param>
|
|
|
/// <param name="newName">新模板名称</param>
|
|
|
/// <returns>克隆的模板</returns>
|
|
|
Task<CNCBrandTemplate> CloneTemplateAsync(int templateId, string newName);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 测试模板
|
|
|
/// </summary>
|
|
|
/// <param name="templateId">模板ID</param>
|
|
|
Task TestTemplateAsync(int templateId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据品牌获取模板
|
|
|
/// </summary>
|
|
|
/// <param name="brandName">品牌名称</param>
|
|
|
/// <returns>模板列表</returns>
|
|
|
Task<IEnumerable<CNCBrandTemplate>> GetTemplatesByBrandAsync(string brandName);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取启用的模板
|
|
|
/// </summary>
|
|
|
/// <returns>启用状态的模板列表</returns>
|
|
|
Task<IEnumerable<CNCBrandTemplate>> GetActiveTemplatesAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 验证模板
|
|
|
/// </summary>
|
|
|
/// <param name="template">模板信息</param>
|
|
|
/// <returns>是否有效</returns>
|
|
|
Task<bool> ValidateTemplateAsync(CNCBrandTemplate template);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 标签映射服务接口
|
|
|
///
|
|
|
/// 负责CNC设备标签与系统标准字段的映射配置管理。
|
|
|
/// 将不同品牌的原始标签映射为系统统一字段。
|
|
|
/// </summary>
|
|
|
public interface ITagMappingService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 获取模板的标签映射
|
|
|
/// </summary>
|
|
|
/// <param name="templateId">模板ID</param>
|
|
|
/// <returns>映射列表</returns>
|
|
|
Task<IEnumerable<TagMapping>> GetMappingsByTemplateAsync(int templateId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 创建标签映射
|
|
|
/// </summary>
|
|
|
/// <param name="mapping">映射信息</param>
|
|
|
/// <returns>创建的映射</returns>
|
|
|
Task<TagMapping> CreateTagMappingAsync(TagMapping mapping);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 批量创建标签映射
|
|
|
/// </summary>
|
|
|
/// <param name="templateId">模板ID</param>
|
|
|
/// <param name="mappings">映射列表</param>
|
|
|
Task CreateTagMappingsAsync(int templateId, IEnumerable<TagMapping> mappings);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新标签映射
|
|
|
/// </summary>
|
|
|
/// <param name="mappingId">映射ID</param>
|
|
|
/// <param name="mapping">映射信息</param>
|
|
|
/// <returns>更新的映射</returns>
|
|
|
Task<TagMapping> UpdateTagMappingAsync(int mappingId, TagMapping mapping);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除标签映射
|
|
|
/// </summary>
|
|
|
/// <param name="mappingId">映射ID</param>
|
|
|
/// <returns>是否删除成功</returns>
|
|
|
Task<bool> DeleteTagMappingAsync(int mappingId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 映射设备标签
|
|
|
/// </summary>
|
|
|
/// <param name="deviceTags">设备原始标签</param>
|
|
|
/// <param name="templateId">模板ID</param>
|
|
|
/// <returns>映射后的标签数据</returns>
|
|
|
Task<IEnumerable<Haoliang.Models.Device.TagData>> MapDeviceTagsAsync(IEnumerable<Haoliang.Models.Device.TagData> deviceTags, int templateId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据系统字段ID获取映射
|
|
|
/// </summary>
|
|
|
/// <param name="templateId">模板ID</param>
|
|
|
/// <param name="systemFieldId">系统字段ID</param>
|
|
|
/// <returns>映射信息</returns>
|
|
|
Task<TagMapping?> GetMappingBySystemFieldAsync(int templateId, string systemFieldId);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 模板验证服务接口
|
|
|
///
|
|
|
/// 负责模板的验证、迁移分析和兼容性检查。
|
|
|
/// 支持跨品牌模板迁移的可行性分析。
|
|
|
/// </summary>
|
|
|
public interface ITemplateValidationService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 验证模板对指定设备的适用性
|
|
|
/// </summary>
|
|
|
/// <param name="templateId">模板ID</param>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <returns>验证错误列表,无错误返回空列表</returns>
|
|
|
Task<IEnumerable<string>> ValidateTemplateForDeviceAsync(int templateId, int deviceId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 生成迁移报告
|
|
|
/// </summary>
|
|
|
/// <param name="template">源模板</param>
|
|
|
/// <param name="targetBrand">目标品牌</param>
|
|
|
/// <returns>迁移报告</returns>
|
|
|
Task<TemplateMigrationReport> GenerateMigrationReportAsync(CNCBrandTemplate template, string targetBrand);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 检查模板完整性
|
|
|
/// </summary>
|
|
|
/// <param name="template">模板信息</param>
|
|
|
/// <returns>完整性检查结果</returns>
|
|
|
Task<TemplateValidationResult> ValidateTemplateCompletenessAsync(CNCBrandTemplate template);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 模板迁移服务接口
|
|
|
///
|
|
|
/// 负责模板的跨品牌迁移转换。
|
|
|
/// 将一个品牌的模板转换为另一个品牌的模板。
|
|
|
/// </summary>
|
|
|
public interface ITemplateMigrationService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 执行模板迁移
|
|
|
/// </summary>
|
|
|
/// <param name="sourceTemplateId">源模板ID</param>
|
|
|
/// <param name="targetBrand">目标品牌</param>
|
|
|
/// <returns>迁移后的模板</returns>
|
|
|
Task<CNCBrandTemplate> MigrateTemplateAsync(int sourceTemplateId, string targetBrand);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 验证迁移可行性
|
|
|
/// </summary>
|
|
|
/// <param name="sourceTemplateId">源模板ID</param>
|
|
|
/// <param name="targetBrand">目标品牌</param>
|
|
|
/// <returns>是否可行</returns>
|
|
|
Task<bool> CanMigrateAsync(int sourceTemplateId, string targetBrand);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取迁移映射建议
|
|
|
/// </summary>
|
|
|
/// <param name="sourceTemplateId">源模板ID</param>
|
|
|
/// <param name="targetBrand">目标品牌</param>
|
|
|
/// <returns>映射建议列表</returns>
|
|
|
Task<IEnumerable<TagMappingSuggestion>> GetMigrationMappingSuggestionsAsync(int sourceTemplateId, string targetBrand);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 模板迁移报告
|
|
|
/// </summary>
|
|
|
public class TemplateMigrationReport
|
|
|
{
|
|
|
public bool CanMigrate { get; set; }
|
|
|
public List<string>? Issues { get; set; }
|
|
|
public List<string>? Warnings { get; set; }
|
|
|
public List<string>? MappedFields { get; set; }
|
|
|
public List<string>? UnmappedFields { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 模板验证结果
|
|
|
/// </summary>
|
|
|
public class TemplateValidationResult
|
|
|
{
|
|
|
public bool IsValid { get; set; }
|
|
|
public List<string>? Errors { get; set; }
|
|
|
public List<string>? Warnings { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 标签映射建议
|
|
|
/// </summary>
|
|
|
public class TagMappingSuggestion
|
|
|
{
|
|
|
public string? SourceField { get; set; }
|
|
|
public string? SuggestedTargetField { get; set; }
|
|
|
public double Confidence { get; set; }
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region ========== 系统与配置服务 ==========
|
|
|
|
|
|
/// <summary>
|
|
|
/// 系统服务接口
|
|
|
///
|
|
|
/// 提供系统级别的操作和管理功能,
|
|
|
/// 包括系统状态、健康检查、调度器管理等。
|
|
|
/// </summary>
|
|
|
public interface ISystemService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 获取系统状态
|
|
|
/// </summary>
|
|
|
/// <returns>系统状态信息</returns>
|
|
|
Task<SystemStatusInfo> GetSystemStatusAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 执行健康检查
|
|
|
/// </summary>
|
|
|
/// <returns>健康检查结果</returns>
|
|
|
Task<HealthCheckResult> PerformHealthCheckAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取系统指标
|
|
|
/// </summary>
|
|
|
/// <returns>系统指标数据</returns>
|
|
|
Task<SystemMetrics> GetSystemMetricsAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 重启系统服务
|
|
|
/// </summary>
|
|
|
Task RestartAsync();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 系统配置服务接口
|
|
|
///
|
|
|
/// 提供系统配置项的CRUD和缓存管理。
|
|
|
/// 支持配置的分类查询和动态更新。
|
|
|
/// </summary>
|
|
|
public interface ISystemConfigService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 获取所有配置
|
|
|
/// </summary>
|
|
|
/// <returns>配置列表</returns>
|
|
|
Task<IEnumerable<SystemConfig>> GetAllConfigsAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取指定配置
|
|
|
/// </summary>
|
|
|
/// <param name="key">配置键</param>
|
|
|
/// <returns>配置值</returns>
|
|
|
Task<SystemConfig?> GetConfigAsync(string key);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 设置配置
|
|
|
/// </summary>
|
|
|
/// <param name="key">配置键</param>
|
|
|
/// <param name="value">配置值</param>
|
|
|
/// <returns>设置后的配置</returns>
|
|
|
Task<SystemConfig> SetConfigAsync(string key, string value);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除配置
|
|
|
/// </summary>
|
|
|
/// <param name="key">配置键</param>
|
|
|
/// <returns>是否删除成功</returns>
|
|
|
Task<bool> DeleteConfigAsync(string key);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 检查配置是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="key">配置键</param>
|
|
|
/// <returns>是否存在</returns>
|
|
|
Task<bool> ConfigExistsAsync(string key);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 按分类获取配置
|
|
|
/// </summary>
|
|
|
/// <param name="category">分类名称</param>
|
|
|
/// <returns>配置列表</returns>
|
|
|
Task<IEnumerable<SystemConfig>> GetConfigsByCategoryAsync(string category);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 刷新配置缓存
|
|
|
/// </summary>
|
|
|
Task RefreshConfigCacheAsync();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 调度器服务接口
|
|
|
///
|
|
|
/// 提供后台任务调度功能,
|
|
|
/// 支持定时任务、周期任务和一次性任务。
|
|
|
/// </summary>
|
|
|
public interface ISchedulerService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 获取所有调度任务
|
|
|
/// </summary>
|
|
|
/// <returns>任务列表</returns>
|
|
|
Task<IEnumerable<ScheduledTask>> GetAllScheduledTasksAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据ID获取任务
|
|
|
/// </summary>
|
|
|
/// <param name="taskId">任务ID</param>
|
|
|
/// <returns>任务信息</returns>
|
|
|
Task<ScheduledTask?> GetTaskByIdAsync(string taskId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 调度任务
|
|
|
/// </summary>
|
|
|
/// <param name="task">任务信息</param>
|
|
|
Task ScheduleTaskAsync(ScheduledTask task);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 执行任务
|
|
|
/// </summary>
|
|
|
/// <param name="taskId">任务ID</param>
|
|
|
Task ExecuteTaskAsync(string taskId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 移除任务
|
|
|
/// </summary>
|
|
|
/// <param name="taskId">任务ID</param>
|
|
|
/// <returns>是否成功</returns>
|
|
|
Task<bool> RemoveTaskAsync(string taskId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 启动调度器
|
|
|
/// </summary>
|
|
|
Task StartSchedulerAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 停止调度器
|
|
|
/// </summary>
|
|
|
Task StopSchedulerAsync();
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region ========== 实时与数据处理服务 ==========
|
|
|
|
|
|
/// <summary>
|
|
|
/// 实时服务接口
|
|
|
///
|
|
|
/// 提供WebSocket实时通信功能,
|
|
|
/// 支持设备状态推送、生产数据推送、告警通知等。
|
|
|
/// </summary>
|
|
|
public interface IRealTimeService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 获取已连接客户端数量
|
|
|
/// </summary>
|
|
|
/// <returns>客户端数量</returns>
|
|
|
Task<int> GetConnectedClientsCountAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 按类型获取已连接客户端
|
|
|
/// </summary>
|
|
|
/// <param name="clientType">客户端类型</param>
|
|
|
/// <returns>客户端信息列表</returns>
|
|
|
Task<IEnumerable<ClientInfo>> GetConnectedClientsByTypeAsync(string clientType);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取设备监控状态
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <returns>监控状态</returns>
|
|
|
Task<DeviceMonitoringStatus> GetDeviceMonitoringStatusAsync(int deviceId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 启动设备流
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <param name="intervalMs">推送间隔(毫秒)</param>
|
|
|
Task StartDeviceStreamingAsync(int deviceId, int intervalMs = 1000);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 停止设备流
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
Task StopDeviceStreamingAsync(int deviceId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取活跃流设备
|
|
|
/// </summary>
|
|
|
/// <returns>设备ID列表</returns>
|
|
|
Task<IEnumerable<int>> GetActiveStreamingDevicesAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 广播设备状态
|
|
|
/// </summary>
|
|
|
/// <param name="statusUpdate">状态更新</param>
|
|
|
Task BroadcastDeviceStatusAsync(DeviceStatusUpdate statusUpdate);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 广播生产更新
|
|
|
/// </summary>
|
|
|
/// <param name="productionUpdate">生产更新</param>
|
|
|
Task BroadcastProductionUpdateAsync(ProductionUpdate productionUpdate);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 广播告警
|
|
|
/// </summary>
|
|
|
/// <param name="alertUpdate">告警更新</param>
|
|
|
Task BroadcastAlertAsync(AlertUpdate alertUpdate);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 发送系统通知
|
|
|
/// </summary>
|
|
|
/// <param name="notification">系统通知</param>
|
|
|
Task SendSystemNotificationAsync(SystemNotification notification);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 发送仪表盘更新
|
|
|
/// </summary>
|
|
|
/// <param name="dashboardUpdate">仪表盘更新</param>
|
|
|
Task SendDashboardUpdateAsync(DashboardUpdate dashboardUpdate);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 发送命令到客户端
|
|
|
/// </summary>
|
|
|
/// <param name="connectionId">连接ID</param>
|
|
|
/// <param name="command">命令</param>
|
|
|
Task SendCommandToClientAsync(string connectionId, RealTimeCommand command);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 广播命令到所有客户端
|
|
|
/// </summary>
|
|
|
/// <param name="command">命令</param>
|
|
|
Task BroadcastCommandAsync(RealTimeCommand command);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 客户端信息
|
|
|
/// </summary>
|
|
|
public class ClientInfo
|
|
|
{
|
|
|
public string? ConnectionId { get; set; }
|
|
|
public string? ClientType { get; set; }
|
|
|
public string? IpAddress { get; set; }
|
|
|
public DateTime ConnectedAt { get; set; }
|
|
|
public Dictionary<string, string>? Metadata { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 设备监控状态
|
|
|
/// </summary>
|
|
|
public class DeviceMonitoringStatus
|
|
|
{
|
|
|
public int DeviceId { get; set; }
|
|
|
public bool IsStreaming { get; set; }
|
|
|
public int ConnectedClients { get; set; }
|
|
|
public DateTime LastUpdate { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 设备状态更新
|
|
|
/// </summary>
|
|
|
public class DeviceStatusUpdate
|
|
|
{
|
|
|
public int DeviceId { get; set; }
|
|
|
public string? Status { get; set; }
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
public Dictionary<string, object>? Data { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 生产更新
|
|
|
/// </summary>
|
|
|
public class ProductionUpdate
|
|
|
{
|
|
|
public int DeviceId { get; set; }
|
|
|
public decimal Quantity { get; set; }
|
|
|
public string? ProgramName { get; set; }
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 告警更新
|
|
|
/// </summary>
|
|
|
public class AlertUpdate
|
|
|
{
|
|
|
public int AlarmId { get; set; }
|
|
|
public AlarmType Type { get; set; }
|
|
|
public string? Message { get; set; }
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 系统通知
|
|
|
/// </summary>
|
|
|
public class SystemNotification
|
|
|
{
|
|
|
public string? Title { get; set; }
|
|
|
public string? Message { get; set; }
|
|
|
public NotificationSeverity Severity { get; set; }
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 通知严重程度
|
|
|
/// </summary>
|
|
|
public enum NotificationSeverity
|
|
|
{
|
|
|
Info,
|
|
|
Warning,
|
|
|
Error,
|
|
|
Critical
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 仪表盘更新
|
|
|
/// </summary>
|
|
|
public class DashboardUpdate
|
|
|
{
|
|
|
public string? DashboardId { get; set; }
|
|
|
public Dictionary<string, object>? Data { get; set; }
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 实时命令
|
|
|
/// </summary>
|
|
|
public class RealTimeCommand
|
|
|
{
|
|
|
public string? CommandId { get; set; }
|
|
|
public string? CommandType { get; set; }
|
|
|
public Dictionary<string, object>? Parameters { get; set; }
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// WebSocket测试结果
|
|
|
/// </summary>
|
|
|
public class TestResult
|
|
|
{
|
|
|
public string TestId { get; set; } = string.Empty;
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
public int ConnectedClients { get; set; }
|
|
|
public List<int> ActiveStreamingDevices { get; set; } = new List<int>();
|
|
|
public string Status { get; set; } = string.Empty;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// WebSocket统计信息
|
|
|
/// </summary>
|
|
|
public class WebSocketStatistics
|
|
|
{
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
public int ConnectedClients { get; set; }
|
|
|
public int ActiveStreamingDevices { get; set; }
|
|
|
public int TotalSessions { get; set; }
|
|
|
public long MessageCount { get; set; }
|
|
|
public long BytesTransferred { get; set; }
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region ========== 规则服务 ==========
|
|
|
|
|
|
/// <summary>
|
|
|
/// 规则服务接口
|
|
|
///
|
|
|
/// 提供业务规则的管理和执行功能。
|
|
|
/// 支持规则配置、规则执行历史记录。
|
|
|
/// </summary>
|
|
|
public interface IRulesService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 获取所有规则
|
|
|
/// </summary>
|
|
|
/// <returns>规则列表</returns>
|
|
|
Task<IEnumerable<BusinessRule>> GetAllRulesAsync();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据ID获取规则
|
|
|
/// </summary>
|
|
|
/// <param name="ruleId">规则ID</param>
|
|
|
/// <returns>规则信息</returns>
|
|
|
Task<BusinessRule?> GetRuleByIdAsync(int ruleId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 创建规则
|
|
|
/// </summary>
|
|
|
/// <param name="rule">规则信息</param>
|
|
|
/// <returns>创建的规则</returns>
|
|
|
Task<BusinessRule> CreateRuleAsync(BusinessRule rule);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新规则
|
|
|
/// </summary>
|
|
|
/// <param name="ruleId">规则ID</param>
|
|
|
/// <param name="rule">规则信息</param>
|
|
|
/// <returns>更新的规则</returns>
|
|
|
Task<BusinessRule?> UpdateRuleAsync(int ruleId, BusinessRule rule);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除规则
|
|
|
/// </summary>
|
|
|
/// <param name="ruleId">规则ID</param>
|
|
|
/// <returns>是否删除成功</returns>
|
|
|
Task<bool> DeleteRuleAsync(int ruleId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 执行规则
|
|
|
/// </summary>
|
|
|
/// <param name="ruleId">规则ID</param>
|
|
|
/// <param name="context">执行上下文</param>
|
|
|
/// <returns>执行结果</returns>
|
|
|
Task<RuleExecutionResult> ExecuteRuleAsync(int ruleId, Dictionary<string, object> context);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 测试规则
|
|
|
/// </summary>
|
|
|
/// <param name="ruleId">规则ID</param>
|
|
|
/// <param name="testData">测试数据</param>
|
|
|
/// <returns>测试结果</returns>
|
|
|
Task<RuleTestResult> TestRuleAsync(int ruleId, Dictionary<string, object> testData);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取规则执行历史
|
|
|
/// </summary>
|
|
|
/// <param name="ruleId">规则ID</param>
|
|
|
/// <param name="fromTime">开始时间</param>
|
|
|
/// <param name="toTime">结束时间</param>
|
|
|
/// <returns>执行历史</returns>
|
|
|
Task<IEnumerable<RuleExecutionHistory>> GetRuleExecutionHistoryAsync(int ruleId, DateTime fromTime, DateTime toTime);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 业务规则
|
|
|
/// </summary>
|
|
|
public class BusinessRule
|
|
|
{
|
|
|
public int RuleId { get; set; }
|
|
|
public string? Name { get; set; }
|
|
|
public string? Description { get; set; }
|
|
|
public string? Category { get; set; }
|
|
|
public string? Expression { get; set; }
|
|
|
public bool IsEnabled { get; set; }
|
|
|
public DateTime CreatedAt { get; set; }
|
|
|
public DateTime UpdatedAt { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 规则执行结果
|
|
|
/// </summary>
|
|
|
public class RuleExecutionResult
|
|
|
{
|
|
|
public bool Success { get; set; }
|
|
|
public bool Result { get; set; }
|
|
|
public string? Message { get; set; }
|
|
|
public TimeSpan ExecutionTime { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 规则测试结果
|
|
|
/// </summary>
|
|
|
public class RuleTestResult
|
|
|
{
|
|
|
public bool Success { get; set; }
|
|
|
public bool Result { get; set; }
|
|
|
public List<string>? Errors { get; set; }
|
|
|
public Dictionary<string, object>? Output { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 规则执行历史
|
|
|
/// </summary>
|
|
|
public class RuleExecutionHistory
|
|
|
{
|
|
|
public int ExecutionId { get; set; }
|
|
|
public int RuleId { get; set; }
|
|
|
public string? RuleName { get; set; }
|
|
|
public bool Success { get; set; }
|
|
|
public string? Result { get; set; }
|
|
|
public TimeSpan ExecutionTime { get; set; }
|
|
|
public DateTime ExecutionTimeUtc { get; set; }
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region ========== 数据处理服务 ==========
|
|
|
|
|
|
/// <summary>
|
|
|
/// 数据解析服务接口
|
|
|
///
|
|
|
/// 负责解析CNC设备返回的原始JSON数据,
|
|
|
/// 将其转换为系统标准格式。
|
|
|
/// </summary>
|
|
|
public interface IDataParserService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 解析设备原始数据
|
|
|
/// </summary>
|
|
|
/// <param name="rawData">原始JSON数据</param>
|
|
|
/// <param name="templateId">模板ID</param>
|
|
|
/// <returns>解析后的数据</returns>
|
|
|
Task<ParsedDeviceData> ParseRawDataAsync(string rawData, int templateId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 解析多设备数据
|
|
|
/// </summary>
|
|
|
/// <param name="rawData">原始JSON数据(数组)</param>
|
|
|
/// <param name="templateId">模板ID</param>
|
|
|
/// <returns>解析后的数据列表</returns>
|
|
|
Task<IEnumerable<ParsedDeviceData>> ParseMultiDeviceDataAsync(string rawData, int templateId);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 验证数据格式
|
|
|
/// </summary>
|
|
|
/// <param name="rawData">原始数据</param>
|
|
|
/// <returns>是否有效</returns>
|
|
|
bool ValidateDataFormat(string rawData);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 数据存储服务接口
|
|
|
///
|
|
|
/// 负责将解析后的数据存储到数据库。
|
|
|
/// 支持批量存储和事务处理。
|
|
|
/// </summary>
|
|
|
public interface IDataStorageService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 存储设备数据
|
|
|
/// </summary>
|
|
|
/// <param name="data">解析后的数据</param>
|
|
|
Task StoreDeviceDataAsync(ParsedDeviceData data);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 批量存储设备数据
|
|
|
/// </summary>
|
|
|
/// <param name="dataList">数据列表</param>
|
|
|
Task StoreDeviceDataBatchAsync(IEnumerable<ParsedDeviceData> dataList);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 存储生产记录
|
|
|
/// </summary>
|
|
|
/// <param name="record">生产记录</param>
|
|
|
Task StoreProductionRecordAsync(ProductionRecord record);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新设备状态
|
|
|
/// </summary>
|
|
|
/// <param name="deviceId">设备ID</param>
|
|
|
/// <param name="status">状态信息</param>
|
|
|
Task UpdateDeviceStatusAsync(int deviceId, DeviceStatus status);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 重试服务接口
|
|
|
///
|
|
|
/// 提供失败操作的重试机制,
|
|
|
/// 支持指数退避和最大重试次数限制。
|
|
|
/// </summary>
|
|
|
public interface IRetryService
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 执行带重试的操作
|
|
|
/// </summary>
|
|
|
/// <typeparam name="T">返回类型</typeparam>
|
|
|
/// <param name="operation">操作</param>
|
|
|
/// <param name="maxRetries">最大重试次数</param>
|
|
|
/// <param name="delay">重试延迟</param>
|
|
|
/// <returns>操作结果</returns>
|
|
|
Task<T> ExecuteWithRetryAsync<T>(Func<Task<T>> operation, int maxRetries = 3, TimeSpan? delay = null);
|
|
|
|
|
|
/// <summary>
|
|
|
/// 执行带重试的操作(无返回)
|
|
|
/// </summary>
|
|
|
/// <param name="operation">操作</param>
|
|
|
/// <param name="maxRetries">最大重试次数</param>
|
|
|
/// <param name="delay">重试延迟</param>
|
|
|
Task ExecuteWithRetryAsync(Func<Task> operation, int maxRetries = 3, TimeSpan? delay = null);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 解析后的设备数据
|
|
|
/// </summary>
|
|
|
public class ParsedDeviceData
|
|
|
{
|
|
|
public int DeviceId { get; set; }
|
|
|
public string? DeviceName { get; set; }
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
public Dictionary<string, TagValue>? Tags { get; set; }
|
|
|
public string? RawJson { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 标签值
|
|
|
/// </summary>
|
|
|
public class TagValue
|
|
|
{
|
|
|
public string? Id { get; set; }
|
|
|
public string? Description { get; set; }
|
|
|
public object? Value { get; set; }
|
|
|
public string? Quality { get; set; }
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region ========== 数据模型(用于接口返回) ==========
|
|
|
|
|
|
/// <summary>
|
|
|
/// 系统状态信息
|
|
|
/// </summary>
|
|
|
public class SystemStatusInfo
|
|
|
{
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
public TimeSpan Uptime { get; set; }
|
|
|
public double MemoryUsage { get; set; }
|
|
|
public double CpuUsage { get; set; }
|
|
|
public int DatabaseConnections { get; set; }
|
|
|
public int ActiveConnections { get; set; }
|
|
|
public DateTime? LastBackupTime { get; set; }
|
|
|
public string? SystemVersion { get; set; }
|
|
|
public bool IsHealthy { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 健康检查结果
|
|
|
/// </summary>
|
|
|
public class HealthCheckResult
|
|
|
{
|
|
|
public bool IsHealthy { get; set; }
|
|
|
public List<HealthCheckItem>? Checks { get; set; }
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 健康检查项
|
|
|
/// </summary>
|
|
|
public class HealthCheckItem
|
|
|
{
|
|
|
public string? Name { get; set; }
|
|
|
public string? Status { get; set; }
|
|
|
public string? Message { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 系统指标
|
|
|
/// </summary>
|
|
|
public class SystemMetrics
|
|
|
{
|
|
|
public double CpuUsage { get; set; }
|
|
|
public double MemoryUsage { get; set; }
|
|
|
public double DiskUsage { get; set; }
|
|
|
public int ThreadCount { get; set; }
|
|
|
public int HandleCount { get; set; }
|
|
|
public long WorkingSet { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 系统配置
|
|
|
/// </summary>
|
|
|
public class SystemConfig
|
|
|
{
|
|
|
public string? Key { get; set; }
|
|
|
public string? Value { get; set; }
|
|
|
public string? Category { get; set; }
|
|
|
public string? Description { get; set; }
|
|
|
public DateTime UpdatedAt { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 定时任务
|
|
|
/// </summary>
|
|
|
public class ScheduledTask
|
|
|
{
|
|
|
public string? TaskId { get; set; }
|
|
|
public string? Name { get; set; }
|
|
|
public string? Description { get; set; }
|
|
|
public string? Schedule { get; set; }
|
|
|
public TaskType Type { get; set; }
|
|
|
public bool IsEnabled { get; set; }
|
|
|
public DateTime? LastRunTime { get; set; }
|
|
|
public DateTime? NextRunTime { get; set; }
|
|
|
public TaskStatus LastRunStatus { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 任务类型
|
|
|
/// </summary>
|
|
|
public enum TaskType
|
|
|
{
|
|
|
Once,
|
|
|
Periodic,
|
|
|
Cron
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 任务状态
|
|
|
/// </summary>
|
|
|
public enum TaskStatus
|
|
|
{
|
|
|
Pending,
|
|
|
Running,
|
|
|
Completed,
|
|
|
Failed
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region ========== 统计相关模型 ==========
|
|
|
|
|
|
/// <summary>
|
|
|
/// 报表过滤条件
|
|
|
/// </summary>
|
|
|
public class ReportFilter
|
|
|
{
|
|
|
public List<int>? DeviceIds { get; set; }
|
|
|
public DateTime StartDate { get; set; }
|
|
|
public DateTime EndDate { get; set; }
|
|
|
public GroupBy GroupBy { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 分组方式
|
|
|
/// </summary>
|
|
|
public enum GroupBy
|
|
|
{
|
|
|
Date,
|
|
|
Hour,
|
|
|
Device,
|
|
|
Program
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 效率过滤条件
|
|
|
/// </summary>
|
|
|
public class EfficiencyFilter
|
|
|
{
|
|
|
public List<int>? DeviceIds { get; set; }
|
|
|
public DateTime StartDate { get; set; }
|
|
|
public DateTime EndDate { get; set; }
|
|
|
public EfficiencyMetric Metrics { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 效率指标类型
|
|
|
/// </summary>
|
|
|
[Flags]
|
|
|
public enum EfficiencyMetric
|
|
|
{
|
|
|
Availability = 1,
|
|
|
Performance = 2,
|
|
|
Quality = 4,
|
|
|
Oee = 8
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 质量过滤条件
|
|
|
/// </summary>
|
|
|
public class QualityFilter
|
|
|
{
|
|
|
public List<int>? DeviceIds { get; set; }
|
|
|
public DateTime StartDate { get; set; }
|
|
|
public DateTime EndDate { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 仪表盘过滤条件
|
|
|
/// </summary>
|
|
|
public class DashboardFilter
|
|
|
{
|
|
|
public List<int>? DeviceIds { get; set; }
|
|
|
public DateTime Date { get; set; }
|
|
|
public bool IncludeAlerts { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 预测过滤条件
|
|
|
/// </summary>
|
|
|
public class ForecastFilter
|
|
|
{
|
|
|
public int DeviceId { get; set; }
|
|
|
public int DaysToForecast { get; set; }
|
|
|
public DateTime StartDate { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 异常过滤条件
|
|
|
/// </summary>
|
|
|
public class AnomalyFilter
|
|
|
{
|
|
|
public int DeviceId { get; set; }
|
|
|
public DateTime StartDate { get; set; }
|
|
|
public DateTime EndDate { get; set; }
|
|
|
public double Sensitivity { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 生产趋势分析
|
|
|
/// </summary>
|
|
|
public class ProductionTrendAnalysis
|
|
|
{
|
|
|
public int DeviceId { get; set; }
|
|
|
public List<TrendDataPoint>? DataPoints { get; set; }
|
|
|
public decimal AverageQuantity { get; set; }
|
|
|
public decimal MaxQuantity { get; set; }
|
|
|
public decimal MinQuantity { get; set; }
|
|
|
public string? TrendDirection { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 趋势数据点
|
|
|
/// </summary>
|
|
|
public class TrendDataPoint
|
|
|
{
|
|
|
public DateTime Date { get; set; }
|
|
|
public decimal Quantity { get; set; }
|
|
|
public decimal TargetQuantity { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 生产报表
|
|
|
/// </summary>
|
|
|
public class ProductionReport
|
|
|
{
|
|
|
public ReportFilter? Filter { get; set; }
|
|
|
public List<ReportSummaryItem>? SummaryItems { get; set; }
|
|
|
public decimal TotalQuantity { get; set; }
|
|
|
public decimal AverageQualityRate { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 报表汇总项
|
|
|
/// </summary>
|
|
|
public class ReportSummaryItem
|
|
|
{
|
|
|
public DateTime Date { get; set; }
|
|
|
public int? Hour { get; set; }
|
|
|
public int? DeviceId { get; set; }
|
|
|
public string? ProgramName { get; set; }
|
|
|
public decimal Quantity { get; set; }
|
|
|
public decimal TargetQuantity { get; set; }
|
|
|
public decimal Efficiency { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 效率指标
|
|
|
/// </summary>
|
|
|
public class EfficiencyMetrics
|
|
|
{
|
|
|
public decimal Availability { get; set; }
|
|
|
public decimal Performance { get; set; }
|
|
|
public decimal Quality { get; set; }
|
|
|
public decimal Oee { get; set; }
|
|
|
public List<HourlyEfficiencyData>? HourlyData { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 每小时效率数据
|
|
|
/// </summary>
|
|
|
public class HourlyEfficiencyData
|
|
|
{
|
|
|
public DateTime Hour { get; set; }
|
|
|
public decimal Availability { get; set; }
|
|
|
public decimal Performance { get; set; }
|
|
|
public decimal Quality { get; set; }
|
|
|
public decimal Oee { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 质量分析
|
|
|
/// </summary>
|
|
|
public class QualityAnalysis
|
|
|
{
|
|
|
public decimal OverallQualityRate { get; set; }
|
|
|
public int TotalProduced { get; set; }
|
|
|
public int Qualified { get; set; }
|
|
|
public int Defective { get; set; }
|
|
|
public List<DefectCategory>? DefectsByCategory { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 缺陷类别
|
|
|
/// </summary>
|
|
|
public class DefectCategory
|
|
|
{
|
|
|
public string? Category { get; set; }
|
|
|
public int Count { get; set; }
|
|
|
public decimal Rate { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 仪表盘汇总
|
|
|
/// </summary>
|
|
|
public class DashboardSummary
|
|
|
{
|
|
|
public DateTime GeneratedAt { get; set; }
|
|
|
public int TotalDevices { get; set; }
|
|
|
public int ActiveDevices { get; set; }
|
|
|
public int OfflineDevices { get; set; }
|
|
|
public decimal TotalProductionToday { get; set; }
|
|
|
public decimal TotalProductionThisWeek { get; set; }
|
|
|
public decimal TotalProductionThisMonth { get; set; }
|
|
|
public decimal OverallEfficiency { get; set; }
|
|
|
public decimal QualityRate { get; set; }
|
|
|
public List<DeviceSummary>? DeviceSummaries { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 设备汇总
|
|
|
/// </summary>
|
|
|
public class DeviceSummary
|
|
|
{
|
|
|
public int DeviceId { get; set; }
|
|
|
public string? DeviceName { get; set; }
|
|
|
public string? Status { get; set; }
|
|
|
public decimal TodayProduction { get; set; }
|
|
|
public decimal Efficiency { get; set; }
|
|
|
public int ActiveAlerts { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// OEE指标
|
|
|
/// </summary>
|
|
|
public class OeeMetrics
|
|
|
{
|
|
|
public int DeviceId { get; set; }
|
|
|
public DateTime Date { get; set; }
|
|
|
public decimal Availability { get; set; }
|
|
|
public decimal Performance { get; set; }
|
|
|
public decimal Quality { get; set; }
|
|
|
public decimal Oee { get; set; }
|
|
|
public TimeSpan PlannedProductionTime { get; set; }
|
|
|
public TimeSpan ActualProductionTime { get; set; }
|
|
|
public TimeSpan DownTime { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 生产预测
|
|
|
/// </summary>
|
|
|
public class ProductionForecast
|
|
|
{
|
|
|
public int DeviceId { get; set; }
|
|
|
public DateTime StartDate { get; set; }
|
|
|
public int DaysForecasted { get; set; }
|
|
|
public List<ForecastDataPoint>? DataPoints { get; set; }
|
|
|
public decimal PredictedTotal { get; set; }
|
|
|
public decimal Confidence { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 预测数据点
|
|
|
/// </summary>
|
|
|
public class ForecastDataPoint
|
|
|
{
|
|
|
public DateTime Date { get; set; }
|
|
|
public decimal PredictedQuantity { get; set; }
|
|
|
public decimal LowerBound { get; set; }
|
|
|
public decimal UpperBound { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 异常分析
|
|
|
/// </summary>
|
|
|
public class AnomalyAnalysis
|
|
|
{
|
|
|
public int DeviceId { get; set; }
|
|
|
public List<AnomalyDataPoint>? Anomalies { get; set; }
|
|
|
public int TotalAnomalies { get; set; }
|
|
|
public string? MostCommonType { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 异常数据点
|
|
|
/// </summary>
|
|
|
public class AnomalyDataPoint
|
|
|
{
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
public string? Type { get; set; }
|
|
|
public decimal Value { get; set; }
|
|
|
public decimal ExpectedValue { get; set; }
|
|
|
public decimal Deviation { get; set; }
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
} |