295 lines
9.6 KiB
C++
295 lines
9.6 KiB
C++
#ifndef OCPM_APP_HPP
|
|
#define OCPM_APP_HPP
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <functional>
|
|
#include <chrono>
|
|
#include <ostream>
|
|
#include <stdexcept>
|
|
|
|
/// @brief 命名空间 ocpm — 作战指挥计划管理系统核心逻辑
|
|
namespace ocpm {
|
|
|
|
// ============================================================================
|
|
// 枚举定义
|
|
// ============================================================================
|
|
|
|
/// @brief 计划状态
|
|
enum class PlanStatus : int {
|
|
DRAFT = 0, ///< 草稿
|
|
ACTIVE = 1, ///< 生效
|
|
ARCHIVED = 2 ///< 归档
|
|
};
|
|
|
|
/// @brief 计划类型
|
|
enum class PlanType : int {
|
|
CENTRALIZED = 0, ///< 集中式
|
|
DISTRIBUTED = 1 ///< 分布式
|
|
};
|
|
|
|
/// @brief 资产状态码 (SRS-OCPM_I_COM_001)
|
|
enum class AssetStatusCode : int {
|
|
READY = 0, ///< 就绪 (绿灯)
|
|
BUSY = 1, ///< 忙碌 (黄灯)
|
|
FAULT = 2, ///< 故障 (红灯)
|
|
OFFLINE = 3 ///< 离线 (灰色)
|
|
};
|
|
|
|
/// @brief 排序方向 (SRS-OCPM_I_UI_002)
|
|
enum class SortDirection {
|
|
ASC, ///< 升序
|
|
DESC ///< 降序
|
|
};
|
|
|
|
/// @brief 异常等级
|
|
enum class AlertLevel {
|
|
INFO, ///< 信息
|
|
WARNING, ///< 警告
|
|
ERROR, ///< 错误
|
|
CRITICAL ///< 严重
|
|
};
|
|
|
|
// ============================================================================
|
|
// 核心数据结构
|
|
// ============================================================================
|
|
|
|
/// @brief 作战计划实体 — 对应数据库 Plan_Info 表
|
|
struct PlanInfo {
|
|
std::string plan_id; ///< 计划唯一标识
|
|
std::string plan_name; ///< 计划名称
|
|
std::string create_time; ///< 创建时间 (ISO 8601)
|
|
std::string update_time; ///< 最后修改时间
|
|
PlanStatus status = PlanStatus::DRAFT; ///< 计划状态
|
|
int priority = 0; ///< 优先级 (0~100)
|
|
PlanType plan_type = PlanType::CENTRALIZED; ///< 计划类型
|
|
std::string creator; ///< 创建人
|
|
};
|
|
|
|
/// @brief 计划查询请求 (SRS-OCPM_I_UI_001)
|
|
struct PlanQueryRequest {
|
|
int status_filter = -1; ///< 按状态过滤, -1 表示不限
|
|
int priority_min = 0;
|
|
std::string keyword; ///< 关键字模糊匹配
|
|
int page = 1; ///< 页码
|
|
int page_size = 100; ///< 每页条数, 上限 100
|
|
};
|
|
|
|
/// @brief 排序参数 (SRS-OCPM_I_UI_002)
|
|
struct SortParam {
|
|
std::string field; ///< 排序字段名 (如 "priority", "create_time")
|
|
SortDirection direction = SortDirection::ASC;
|
|
};
|
|
|
|
/// @brief 网络拓扑节点 — 用于分布式计划 (SRS-OCPM_I_DB_002)
|
|
struct TopoNode {
|
|
std::string node_id; ///< 节点标识
|
|
std::string label; ///< 显示标签
|
|
double x = 0.0; ///< 布局坐标 X
|
|
double y = 0.0; ///< 布局坐标 Y
|
|
};
|
|
|
|
/// @brief 网络拓扑边
|
|
struct TopoEdge {
|
|
std::string edge_id; ///< 边标识
|
|
std::string source_id; ///< 源节点
|
|
std::string target_id; ///< 目标节点
|
|
int bandwidth = 0; ///< 带宽 (Mbps)
|
|
};
|
|
|
|
/// @brief 分布式计划拓扑数据
|
|
struct DistributedPlanGraph {
|
|
std::vector<TopoNode> nodes; ///< 节点列表
|
|
std::vector<TopoEdge> edges; ///< 边列表
|
|
};
|
|
|
|
/// @brief HITL 事件 (SRS-OCPM_I_ALG_001)
|
|
struct HitlEvent {
|
|
std::string request_id; ///< 请求标识
|
|
std::string reason; ///< 需要人工干预的原因
|
|
std::vector<std::string> options; ///< 可选方案列表
|
|
std::string deadline; ///< 截止时间
|
|
};
|
|
|
|
/// @brief 重构指令 (SRS-OCPM_I_UI_007)
|
|
struct ReconstructCommand {
|
|
std::string plan_id; ///< 目标计划 ID
|
|
std::vector<std::string> modifications; ///< 修改描述列表
|
|
std::vector<std::string> target_tasks; ///< 目标任务列表
|
|
};
|
|
|
|
/// @brief 重构结果 (SRS-OCPM_O_UI_007)
|
|
struct ReconstructResult {
|
|
bool success = false; ///< 是否成功
|
|
std::string message; ///< 结果消息
|
|
std::string new_version; ///< 新版本号 (成功时)
|
|
};
|
|
|
|
/// @brief 子任务节点 — 用于流程图 (SRS-OCPM_I_SYS_004)
|
|
struct TaskNode {
|
|
std::string task_id; ///< 任务标识
|
|
std::string name; ///< 任务名称
|
|
std::string status; ///< 状态 (pending/running/completed/failed)
|
|
std::vector<std::string> dependency_ids; ///< 依赖的任务 ID 列表
|
|
};
|
|
|
|
/// @brief 异常事件 (SRS-OCPM_I_SYS_005)
|
|
struct AlertEvent {
|
|
int code; ///< 异常编码
|
|
AlertLevel level = AlertLevel::INFO;
|
|
std::string timestamp; ///< 发生时间
|
|
std::string task_id; ///< 关联任务
|
|
std::string description; ///< 描述
|
|
};
|
|
|
|
/// @brief 执行统计数据 (SRS-OCPM_I_SYS_003)
|
|
struct ExecutionStats {
|
|
int completed_tasks = 0; ///< 已完成任务数
|
|
int total_tasks = 0; ///< 总任务数
|
|
double remaining_time = 0.0; ///< 剩余时间 (分钟)
|
|
};
|
|
|
|
/// @brief 仪表盘聚合数据 (SRS-OCPM_I_SYS_006)
|
|
struct DashboardData {
|
|
ExecutionStats execution; ///< 执行进度
|
|
double resource_rate; ///< 资源剩余率 (0.0~1.0)
|
|
std::vector<AlertEvent> recent_alerts; ///< 最近异常
|
|
};
|
|
|
|
// ============================================================================
|
|
// 模块管理器类声明
|
|
// ============================================================================
|
|
|
|
/// @brief 计划管理器 — 负责集中式计划的 CRUD、排序、对比、重构
|
|
class PlanManager {
|
|
public:
|
|
PlanManager() = default;
|
|
virtual ~PlanManager() = default;
|
|
|
|
/// @brief 查询计划列表
|
|
/// @param query 查询请求参数
|
|
/// @param sort 排序参数
|
|
/// @return 计划列表
|
|
std::vector<PlanInfo> queryPlans(const PlanQueryRequest& query,
|
|
const SortParam& sort = {"priority", SortDirection::DESC});
|
|
|
|
/// @brief 获取单个计划详情
|
|
/// @param plan_id 计划 ID
|
|
/// @return PlanInfo
|
|
/// @throws std::invalid_argument 如果 plan_id 不存在
|
|
PlanInfo getPlanDetail(const std::string& plan_id);
|
|
|
|
/// @brief 对比两个计划
|
|
/// @param id_a 计划 A ID
|
|
/// @param id_b 计划 B ID
|
|
/// @return 差异描述列表 (每项格式: "字段名: A值 vs B值")
|
|
std::vector<std::string> comparePlans(const std::string& id_a, const std::string& id_b);
|
|
|
|
/// @brief 执行重构操作
|
|
/// @param cmd 重构指令
|
|
/// @return 重构结果
|
|
ReconstructResult reconstruct(const ReconstructCommand& cmd);
|
|
|
|
/// @brief 提交 HITL 事件通知
|
|
/// @param event HITL 事件
|
|
void notifyHitlEvent(const HitlEvent& event);
|
|
|
|
/// @brief 设置算法进度回调
|
|
/// @param cb 回调函数, 参数为 (stage, progress%)
|
|
void setAlgorithmProgressCallback(std::function<void(const std::string&, int)> cb);
|
|
|
|
/// @brief 模拟加载示例数据
|
|
void loadSampleData();
|
|
|
|
private:
|
|
std::vector<PlanInfo> plans_;
|
|
std::function<void(const std::string&, int)> algo_callback_;
|
|
};
|
|
|
|
/// @brief 分布式计划管理器
|
|
class DistributedPlanManager {
|
|
public:
|
|
DistributedPlanManager() = default;
|
|
virtual ~DistributedPlanManager() = default;
|
|
|
|
/// @brief 获取当前拓扑图
|
|
const DistributedPlanGraph& getGraph() const { return graph_; }
|
|
|
|
/// @brief 添加节点
|
|
/// @param node 新节点
|
|
void addNode(const TopoNode& node);
|
|
|
|
/// @brief 移除节点 (同时移除关联边)
|
|
/// @param node_id 节点 ID
|
|
void removeNode(const std::string& node_id);
|
|
|
|
/// @brief 添加边
|
|
/// @param edge 新边
|
|
void addEdge(const TopoEdge& edge);
|
|
|
|
/// @brief 移除边
|
|
/// @param edge_id 边 ID
|
|
void removeEdge(const std::string& edge_id);
|
|
|
|
/// @brief 模拟加载示例拓扑
|
|
void loadSampleData();
|
|
|
|
private:
|
|
DistributedPlanGraph graph_;
|
|
|
|
/// @brief 检查图连通性 (简单 BFS)
|
|
bool isConnected() const;
|
|
};
|
|
|
|
/// @brief 指令分发与执行监控管理器
|
|
class DispatchManager {
|
|
public:
|
|
DispatchManager() = default;
|
|
virtual ~DispatchManager() = default;
|
|
|
|
/// @brief 分发计划至多个资产
|
|
/// @param plan_id 计划 ID
|
|
/// @param asset_ids 目标资产 ID 列表
|
|
/// @return 成功分发的资产数
|
|
int dispatchPlan(const std::string& plan_id, const std::vector<std::string>& asset_ids);
|
|
|
|
/// @brief 查询资产状态
|
|
/// @param asset_id 资产 ID
|
|
/// @return 资产状态码
|
|
AssetStatusCode getAssetStatus(const std::string& asset_id);
|
|
|
|
/// @brief 获取执行统计
|
|
/// @return ExecutionStats
|
|
ExecutionStats getExecutionStats() const;
|
|
|
|
/// @brief 获取仪表盘数据
|
|
/// @return DashboardData
|
|
DashboardData getDashboardData() const;
|
|
|
|
/// @brief 获取子任务流程图
|
|
/// @return 子任务列表
|
|
std::vector<TaskNode> getTaskFlow() const;
|
|
|
|
/// @brief 获取未清除的异常事件列表
|
|
/// @param level_filter 按等级过滤, 传入 nullptr 不限制
|
|
std::vector<AlertEvent> getAlerts(const AlertLevel* level_filter = nullptr) const;
|
|
|
|
/// @brief 清除所有异常
|
|
void clearAlerts();
|
|
|
|
/// @brief 模拟加载示例数据
|
|
void loadSampleData();
|
|
|
|
private:
|
|
std::map<std::string, AssetStatusCode> asset_statuses_;
|
|
std::vector<AlertEvent> alerts_;
|
|
std::vector<TaskNode> task_flow_;
|
|
ExecutionStats stats_;
|
|
};
|
|
|
|
} // namespace ocpm
|
|
|
|
#endif // OCPM_APP_HPP
|