From bf67c01ac96e5a8d535458c89bbb30ed28e7828d Mon Sep 17 00:00:00 2001 From: gaozheng Date: Tue, 9 Jun 2026 11:00:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(data):=20NavDto=20=E8=84=9A=E6=89=8B?= =?UTF-8?q?=E6=9E=B6=20+=20parseWorkspaces=EF=BC=88=E5=90=AB=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=8E=A5=E5=85=A5=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/data/CMakeLists.txt | 5 +++-- src/data/dto/NavDto.cpp | 33 +++++++++++++++++++++++++++++++++ src/data/dto/NavDto.hpp | 30 ++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 1 + tests/data/test_nav_dto.cpp | 28 ++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 src/data/dto/NavDto.cpp create mode 100644 src/data/dto/NavDto.hpp create mode 100644 tests/data/test_nav_dto.cpp diff --git a/src/data/CMakeLists.txt b/src/data/CMakeLists.txt index 71d062a..b513412 100644 --- a/src/data/CMakeLists.txt +++ b/src/data/CMakeLists.txt @@ -2,8 +2,9 @@ find_package(nlohmann_json CONFIG REQUIRED) find_package(Qt6 COMPONENTS Core REQUIRED) add_library(geopro_data STATIC parse/SampleParsers.cpp - repo/LocalSampleRepository.cpp) + repo/LocalSampleRepository.cpp + dto/NavDto.cpp) 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) set_target_properties(geopro_data PROPERTIES AUTOMOC OFF AUTOUIC OFF AUTORCC OFF) diff --git a/src/data/dto/NavDto.cpp b/src/data/dto/NavDto.cpp new file mode 100644 index 0000000..57a9046 --- /dev/null +++ b/src/data/dto/NavDto.cpp @@ -0,0 +1,33 @@ +#include "dto/NavDto.hpp" + +#include + +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 parseWorkspaces(const QJsonArray& arr) { + std::vector out; + out.reserve(static_cast(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 parseStructNodes(const QJsonArray&) { return {}; } +std::vector parseDatasets(const QJsonArray&) { return {}; } +std::vector buildStructTree(const std::vector&) { return {}; } + +} // namespace geopro::data::dto diff --git a/src/data/dto/NavDto.hpp b/src/data/dto/NavDto.hpp new file mode 100644 index 0000000..20141c8 --- /dev/null +++ b/src/data/dto/NavDto.hpp @@ -0,0 +1,30 @@ +#pragma once +#include +#include +#include +#include "repo/RepoTypes.hpp" + +namespace geopro::data::dto { + +// 工作空间数组(joined/list 的 data["value"])→ 模型。isCurTenant==1 → isCurrent。 +std::vector parseWorkspaces(const QJsonArray& arr); + +// 项目分页(queryByUser 的 data 对象 {hasNextPage, projectList})→ 模型。 +struct ProjectPage { std::vector projects; bool hasNextPage = false; }; +ProjectPage parseProjects(const QJsonObject& data); + +// 结构扁平节点数组(queryProjectStruct 的 data["projectStructList"])→ 模型。 +std::vector parseStructNodes(const QJsonArray& arr); + +// DS 聚合数组(queryDsByTmObjectId 的 data["value"])→ DsNode。ddCode → ddType。 +std::vector parseDatasets(const QJsonArray& arr); + +// 扁平 StructNode 按 parentId 建树。叶子(无子节点)=TM。处理:项目直挂 TM、孤儿 parentId、空表。 +struct StructTreeNode { + StructNode node; + bool isTm = false; + std::vector children; +}; +std::vector buildStructTree(const std::vector& flat); + +} // namespace geopro::data::dto diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 06b572b..7296aaf 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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_local_repo.cpp) +target_sources(geopro_tests PRIVATE data/test_nav_dto.cpp) target_link_libraries(geopro_tests PRIVATE geopro_data) # net 层:RSA 加密器。测试需直接用 OpenSSL 生成/解密密钥,故显式 find_package diff --git a/tests/data/test_nav_dto.cpp b/tests/data/test_nav_dto.cpp new file mode 100644 index 0000000..5f5b72a --- /dev/null +++ b/tests/data/test_nav_dto.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include + +#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); +}