27/include/app.hpp

206 lines
7.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef ODF_MANAGER_APP_HPP
#define ODF_MANAGER_APP_HPP
#include <string>
#include <vector>
#include <map>
#include <cstdint>
#include <sstream>
#include <iomanip>
#include <ctime>
#include <algorithm>
// =========================================================================
// ODF 光纤配线单元管理系统 —— 核心数据类型与接口
// =========================================================================
/// @brief 连接器端面类型UPC / APC
enum class PolishType : uint8_t {
UPC, ///< 超物理接触端面,回波损耗 ≥ 50dB
APC ///< 斜角度物理接触端面,回波损耗 ≥ 60dB
};
/// @brief 连接器等级(按标准光纤分类)
enum class FiberGrade : uint8_t {
OM1, ///< 多模 OM1 (62.5/125μm)
OM2, ///< 多模 OM2 (50/125μm)
OM3, ///< 多模 OM3 (50/125μm, 激光优化)
OM4, ///< 多模 OM4 (50/125μm, 高带宽)
OM5, ///< 多模 OM5 (50/125μm, 宽带)
OS2 ///< 单模 OS2 (9/125μm)
};
/// @brief 光接口类型(连接器形式)
enum class ConnectorType : uint8_t {
LC, ///< LC 连接器1.25mm 插芯)
SC, ///< SC 连接器2.5mm 插芯)
MPO ///< MPO 多芯连接器
};
/// @brief 适配器安装方向
enum class MountDirection : uint8_t {
Front, ///< 前面板接入
Rear, ///< 后面板接入
Both ///< 前后均可接入
};
// =========================================================================
// 数据结构定义
// =========================================================================
/**
* @brief 适配器接口规格表
*
* 描述单个适配器端口的光学与机械规格。
*/
struct AdapterSpec {
ConnectorType interface_type; ///< 接口类型LC/SC/MPO
FiberGrade connector_grade; ///< 连接器等级OM1-OS2
PolishType polish_type; ///< 端面类型UPC/APC
double max_insertion_loss_dB; ///< 最大插入损耗 (dB)
double min_return_loss_dB; ///< 最小回波损耗 (dB)
int port_count; ///< 该面板上安装的适配器数量
MountDirection mount_direction; ///< 安装方向
};
/**
* @brief ODF 单元信息
*
* 标识一个物理 ODF 子框/模块的全部关键信息。
*/
struct ODFUnitInfo {
std::string unit_id; ///< 单元全局唯一标识
std::string model_name; ///< 产品型号
std::string location; ///< 安装位置,格式 "机房-机柜-高度U数"
std::string manufacturer; ///< 制造商
std::string production_date; ///< 生产日期 (YYYY-MM-DD)
int max_capacity_cores; ///< 最大支持光纤芯数(≤ 288
std::vector<AdapterSpec> adapters; ///< 已安装的适配器列表
};
/**
* @brief 典型配置方案
*
* 预置的标准场景配置模板。
*/
struct TypicalConfig {
std::string scene_name; ///< 场景名称,如 "数据中心LC单模预端接"
std::string environment; ///< 应用环境:数据中心 / 园区网 / 接入网
std::string fiber_type; ///< 光纤类型:单模/多模
std::string connector_type; ///< 连接器类型描述
int preterminated_len_m; ///< 预端接长度 (米)
int port_density_per_u; ///< 每 U 端口密度
double redundancy_ratio; ///< 冗余比例 (如 0.25 表示 25%)
std::vector<std::string> accessories; ///< 配套附件列表
};
/**
* @brief 项目里程碑计划条目
*/
struct Milestone {
std::string phase_name; ///< 阶段名称
std::string start_date; ///< 开始日期 (YYYY-MM-DD)
std::string end_date; ///< 结束日期 (YYYY-MM-DD)
std::string owner; ///< 负责人
std::string deliverable; ///< 交付物描述
bool is_completed; ///< 完成状态
};
// =========================================================================
// ODF 管理器 —— 核心业务接口
// =========================================================================
/**
* @brief ODF 光纤配线单元管理器
*
* 提供 ODF 单元管理、编码生成、配置查询、兼容性校验等功能。
*/
class ODFManager {
public:
ODFManager() = default;
// ---- 单元管理 ----
/// @brief 注册一个新的 ODF 单元到管理器
void register_unit(const ODFUnitInfo& unit);
/// @brief 按 unit_id 查询已注册的 ODF 单元
/// @return 指向 ODFUnitInfo 的指针,若不存在返回 nullptr
const ODFUnitInfo* find_unit(const std::string& unit_id) const;
/// @brief 返回所有已注册的 ODF 单元列表
const std::vector<ODFUnitInfo>& all_units() const;
// ---- 编码生成 ----
/**
* @brief 根据站点-机柜-槽位生成唯一命名编码
*
* 编码格式:`[site]-[cabinet]-[slot]`,全局唯一且长度 ≤ 64 字符。
*
* @param site 站点代码(如 DC01
* @param cabinet 机柜号(如 RF02
* @param slot 槽位号(如 SL05
* @return 生成的唯一编码字符串
*/
std::string generate_naming_code(const std::string& site,
const std::string& cabinet,
const std::string& slot) const;
// ---- 典型配置 ----
/**
* @brief 获取指定场景名称的典型配置方案
* @param scene_type 场景名称关键字
* @return TypicalConfig 结构,若未找到则返回空场景
*/
TypicalConfig get_typical_config(const std::string& scene_type) const;
/// @brief 注册一个典型配置方案
void register_typical_config(const TypicalConfig& cfg);
// ---- 兼容性校验 ----
/**
* @brief 检查两个连接器是否可物理对接
*
* 检查规则:
* - 接口类型必须相同LC ↔ LCSC ↔ SCMPO ↔ MPO
* - 端面类型允许混合UPC ↔ APC 可以对接,但回波损耗受限)
*
* @param a 连接器 A 的规格描述
* @param b 连接器 B 的规格描述
* @return true 表示可对接false 表示不兼容
*/
bool validate_adapter_compatibility(const AdapterSpec& a,
const AdapterSpec& b) const;
// ---- 报告与标签 ----
/**
* @brief 导出里程碑排期甘特图数据(返回文本表格形式)
* @return 格式化的排期字符串
*/
std::string export_milestone_schedule() const;
/// @brief 添加一个里程碑
void add_milestone(const Milestone& ms);
/// @brief 返回所有里程碑
const std::vector<Milestone>& milestones() const;
/**
* @brief 生成可用于打印的标签内容(含文本与二维码示意)
* @param unit_id ODF 单元 ID
* @return 标签文本,包含单元信息及 [QR] 占位符
*/
std::string print_label(const std::string& unit_id) const;
private:
std::vector<ODFUnitInfo> units_;
std::vector<TypicalConfig> configs_;
std::vector<Milestone> milestones_;
/// @brief 内部辅助:将 ConnectorType 转为字符串
static std::string connector_type_str(ConnectorType t);
/// @brief 内部辅助:将 PolishType 转为字符串
static std::string polish_type_str(PolishType p);
};
#endif // ODF_MANAGER_APP_HPP