feat(data): NavDto 脚手架 + parseWorkspaces(含测试接入)

This commit is contained in:
gaozheng 2026-06-09 11:00:39 +08:00
parent fc458ec702
commit bf67c01ac9
5 changed files with 95 additions and 2 deletions

View File

@ -2,8 +2,9 @@ find_package(nlohmann_json CONFIG REQUIRED)
find_package(Qt6 COMPONENTS Core REQUIRED) find_package(Qt6 COMPONENTS Core REQUIRED)
add_library(geopro_data STATIC add_library(geopro_data STATIC
parse/SampleParsers.cpp parse/SampleParsers.cpp
repo/LocalSampleRepository.cpp) repo/LocalSampleRepository.cpp
dto/NavDto.cpp)
target_include_directories(geopro_data PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(geopro_data PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(geopro_data PUBLIC geopro_core Qt6::Core PRIVATE nlohmann_json::nlohmann_json) target_link_libraries(geopro_data PUBLIC geopro_core geopro_net Qt6::Core PRIVATE nlohmann_json::nlohmann_json)
target_compile_features(geopro_data PUBLIC cxx_std_17) target_compile_features(geopro_data PUBLIC cxx_std_17)
set_target_properties(geopro_data PROPERTIES AUTOMOC OFF AUTOUIC OFF AUTORCC OFF) set_target_properties(geopro_data PROPERTIES AUTOMOC OFF AUTOUIC OFF AUTORCC OFF)

33
src/data/dto/NavDto.cpp Normal file
View File

@ -0,0 +1,33 @@
#include "dto/NavDto.hpp"
#include <QJsonValue>
namespace geopro::data::dto {
namespace {
std::string str(const QJsonObject& o, const char* key) {
return o.value(QString::fromLatin1(key)).toString().toStdString();
}
} // namespace
std::vector<Workspace> parseWorkspaces(const QJsonArray& arr) {
std::vector<Workspace> out;
out.reserve(static_cast<size_t>(arr.size()));
for (const QJsonValue& v : arr) {
const QJsonObject o = v.toObject();
Workspace w;
w.id = str(o, "id");
w.name = str(o, "name");
w.ownerType = o.value(QStringLiteral("ownerType")).toInt();
w.isCurrent = o.value(QStringLiteral("isCurTenant")).toInt() == 1;
out.push_back(std::move(w));
}
return out;
}
ProjectPage parseProjects(const QJsonObject&) { return {}; }
std::vector<StructNode> parseStructNodes(const QJsonArray&) { return {}; }
std::vector<DsNode> parseDatasets(const QJsonArray&) { return {}; }
std::vector<StructTreeNode> buildStructTree(const std::vector<StructNode>&) { return {}; }
} // namespace geopro::data::dto

30
src/data/dto/NavDto.hpp Normal file
View File

@ -0,0 +1,30 @@
#pragma once
#include <vector>
#include <QJsonArray>
#include <QJsonObject>
#include "repo/RepoTypes.hpp"
namespace geopro::data::dto {
// 工作空间数组joined/list 的 data["value"])→ 模型。isCurTenant==1 → isCurrent。
std::vector<Workspace> parseWorkspaces(const QJsonArray& arr);
// 项目分页queryByUser 的 data 对象 {hasNextPage, projectList})→ 模型。
struct ProjectPage { std::vector<ProjectSummary> projects; bool hasNextPage = false; };
ProjectPage parseProjects(const QJsonObject& data);
// 结构扁平节点数组queryProjectStruct 的 data["projectStructList"])→ 模型。
std::vector<StructNode> parseStructNodes(const QJsonArray& arr);
// DS 聚合数组queryDsByTmObjectId 的 data["value"])→ DsNode。ddCode → ddType。
std::vector<DsNode> parseDatasets(const QJsonArray& arr);
// 扁平 StructNode 按 parentId 建树。叶子(无子节点)=TM。处理项目直挂 TM、孤儿 parentId、空表。
struct StructTreeNode {
StructNode node;
bool isTm = false;
std::vector<StructTreeNode> children;
};
std::vector<StructTreeNode> buildStructTree(const std::vector<StructNode>& flat);
} // namespace geopro::data::dto

View File

@ -36,6 +36,7 @@ target_link_libraries(geopro_tests PRIVATE geopro_core)
target_sources(geopro_tests PRIVATE data/test_parsers.cpp) target_sources(geopro_tests PRIVATE data/test_parsers.cpp)
target_sources(geopro_tests PRIVATE data/test_local_repo.cpp) target_sources(geopro_tests PRIVATE data/test_local_repo.cpp)
target_sources(geopro_tests PRIVATE data/test_nav_dto.cpp)
target_link_libraries(geopro_tests PRIVATE geopro_data) target_link_libraries(geopro_tests PRIVATE geopro_data)
# net RSA OpenSSL / find_package # net RSA OpenSSL / find_package

View File

@ -0,0 +1,28 @@
#include <gtest/gtest.h>
#include <QByteArray>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include "dto/NavDto.hpp"
using namespace geopro::data;
namespace {
QJsonArray arrOf(const char* json) {
return QJsonDocument::fromJson(QByteArray(json)).array();
}
} // namespace
TEST(NavDto, ParseWorkspacesMapsFieldsAndCurrentFlag) {
const auto arr = arrOf(R"([
{"id":"t1","name":"个人空间","ownerType":1,"isCurTenant":1},
{"id":"t2","name":"企业A","ownerType":2,"isCurTenant":0}
])");
const auto ws = dto::parseWorkspaces(arr);
ASSERT_EQ(ws.size(), 2u);
EXPECT_EQ(ws[0].id, "t1");
EXPECT_EQ(ws[0].ownerType, 1);
EXPECT_TRUE(ws[0].isCurrent);
EXPECT_FALSE(ws[1].isCurrent);
}