7/src/app.cpp

128 lines
3.6 KiB
C++

#include "app.hpp"
#include <iostream>
#include <sstream>
#include <algorithm>
App::App() {
// 加载内置模板
templates_ = ConfigTemplate::builtInTemplates();
}
// ==================== ODF 单元管理 ====================
void App::addOdfUnit(const OdfUnit& unit) {
units_.push_back(unit);
}
std::string App::listOdfUnits() const {
if (units_.empty()) {
return "(无 ODF 单元数据)\n";
}
std::ostringstream oss;
oss << "=== ODF 单元列表 ===\n";
for (size_t i = 0; i < units_.size(); ++i) {
oss << "[" << i << "] " << units_[i].summary();
}
return oss.str();
}
// ==================== 适配器接口管理 ====================
void App::addAdapterInterface(const AdapterInterface& iface) {
adapters_.push_back(iface);
}
std::string App::listAdapterInterfaces() const {
if (adapters_.empty()) {
return "(无适配器接口数据)\n";
}
std::ostringstream oss;
oss << "=== 适配器接口列表 ===\n";
for (size_t i = 0; i < adapters_.size(); ++i) {
oss << "[" << i << "] " << adapters_[i].summary();
}
return oss.str();
}
// ==================== 命名工具 ====================
std::string App::validateNamingFormat(const std::string& code) {
auto result = NamingHelper::validateFormat(code);
if (result.has_value()) {
return result.value();
}
return "编号格式不正确: " + code + "\n规则: " + NamingHelper::PATTERN;
}
std::string App::generateSampleNaming() {
return NamingHelper::generate("DC01", "F03", "TX", "ODP", "LC24", "001", "A");
}
// ==================== 端口密度计算 ====================
uint32_t App::calculatePortDensity(uint32_t rackHeightU, uint32_t totalPorts) {
if (rackHeightU == 0) {
return 0;
}
return totalPorts / rackHeightU;
}
// ==================== 配置模板 ====================
std::string App::listTemplates() const {
if (templates_.empty()) {
return "(无可用配置模板)\n";
}
std::ostringstream oss;
oss << "=== 典型场景配置模板 ===\n";
for (size_t i = 0; i < templates_.size(); ++i) {
oss << "[" << i << "] " << templates_[i].summary();
}
return oss.str();
}
std::string App::generateBom(size_t templateIndex, uint32_t cabinetCount) const {
if (templateIndex >= templates_.size()) {
return "错误:无效的模板索引 " + std::to_string(templateIndex) + "\n";
}
return templates_[templateIndex].generateBomSummary(cabinetCount);
}
// ==================== 项目里程碑 ====================
void App::addMilestone(const ProjectMilestone& ms) {
milestones_.push_back(ms);
}
std::string App::listMilestones() const {
if (milestones_.empty()) {
return "(无里程碑数据)\n";
}
std::ostringstream oss;
oss << "=== 项目里程碑 ===\n";
for (size_t i = 0; i < milestones_.size(); ++i) {
oss << "[" << i << "] " << milestones_[i].summary();
}
return oss.str();
}
std::string App::checkMilestonesConstraint() const {
if (milestones_.empty()) {
return "(无里程碑数据,跳过约束检查)\n";
}
std::ostringstream oss;
oss << "=== 里程碑时间约束检查 ===\n";
bool allOk = true;
for (const auto& ms : milestones_) {
if (!ms.checkTimeConstraint()) {
allOk = false;
oss << "⚠ 阶段 [" << ms.stageString() << "] 时间超限!"
<< " 结束周=" << ms.weekEnd << "\n";
}
}
if (allOk) {
oss << "所有里程碑时间约束均满足 ✓\n";
}
return oss.str();
}