DPS/DataPlatform/ProjectModel.cpp

70 lines
1.7 KiB
C++
Raw Normal View History

2025-06-23 10:41:33 +08:00
#include "ProjectModel.h"
#include <fstream>
#include "Session.h"
#include "mainwindow.h"
ProjectModel::ProjectModel()
: ShareEventModule()
{
}
ProjectModel::~ProjectModel()
{
}
bool ProjectModel::onMessage(const std::string& eventName, json& parameter)
{
if (eventName == "get-all-project") {
std::ifstream read("project.json");
try {
json j = json::parse(read);
parameter["response"] = j;
auto j3 = json::parse(QString::fromLocal8Bit(R"({ "id": 8,"follow": false,"name": "33","type": 1,"author": "wuwei","createTime": "2022-02-02 15:00","updateTime": "2022-02-02 15:00"})").toUtf8());
parameter["response"].push_back(j3);
return true;
}
catch (...) {
Session::getSession()->parent()->message(QString::fromLocal8Bit("找不到项目数据"), 2);
}
return false;
}
else if (eventName == "find-project") {
std::ifstream read("project.json");
try {
json j = json::parse(read);
for (auto i : j) {
if (i["id"] == parameter["data"])
{
parameter["response"] = i;
break;
}
}
return true;
}
catch (...) {
Session::getSession()->parent()->message(QString::fromLocal8Bit("找不到数据字典数据"), 2);
}
return false;
}
else if (eventName == "find-DataModel") {
std::ifstream read("project.json");
try {
json j = json::parse(read);
for (auto project : j) {
for (auto dm : project["datamodel"])
if (dm["id"] == parameter["data"])
{
parameter["response"] = dm;
break;
}
}
return true;
}
catch (...) {
Session::getSession()->parent()->message(QString::fromLocal8Bit("找不到数据字典数据"), 2);
}
return false;
}
return ShareEventModule::onMessage(eventName, parameter);
}