2025-06-23 10:41:33 +08:00
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
|
|
|
|
|
|
#include "DataAccessModule.h"
|
|
|
|
|
#include "DataModelData.h"
|
|
|
|
|
#include "DataManager.h"
|
|
|
|
|
#include "ProjectData.h"
|
|
|
|
|
#include "DataClass.h"
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DataAccessModule::DataAccessModule(DataManager* manager)
|
|
|
|
|
: ShareEventModule(), pDataManager(manager)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DataAccessModule::~DataAccessModule()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DataAccessModule::onMessage(const std::string& eventName, json& parameter)
|
|
|
|
|
{
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("DataAccessModule receive message.......");
|
|
|
|
|
LOG(INFO) << eventName;
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
TRY{
|
|
|
|
|
if (!pDataManager->_dbConnected)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
parameter["error"] = "数据库连接失败";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("DataAccessModule::onMessage...DB connect failed");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (eventName == "get-datamodel")
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//获取当前数据模型信息
|
2025-06-23 10:41:33 +08:00
|
|
|
|
getCurrentDataModel(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "get-datamodule")
|
|
|
|
|
{
|
|
|
|
|
return getCurrentDataPack(parameter);
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "get-project-datamodel")
|
|
|
|
|
{
|
|
|
|
|
return getAllDataModel(parameter);
|
|
|
|
|
}
|
|
|
|
|
if (eventName == "get-dataclass")
|
|
|
|
|
{
|
|
|
|
|
getCurrentDataClass(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "get-datamodel-child")
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//获取数据模型下属所有数据
|
2025-06-23 10:41:33 +08:00
|
|
|
|
getAllDataTree(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "get-last-project")
|
|
|
|
|
{
|
|
|
|
|
// getAllProject(parameter);
|
|
|
|
|
getlastProject(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "get-all-project")
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//获取所有项目
|
2025-06-23 10:41:33 +08:00
|
|
|
|
getAllProject(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
CATCH(parameter);
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool DataAccessModule::getCurrentDataPack(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
int id = data["id"];
|
|
|
|
|
DPData* pData = pDataManager->findObjectById(DataManager::DataType::dataPack, id);
|
|
|
|
|
if (pData)
|
|
|
|
|
{
|
|
|
|
|
json data;
|
|
|
|
|
pData->toJson(data, true);
|
|
|
|
|
parameter["response"] = data;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//未找到该数据模型
|
|
|
|
|
parameter["error"] = "未找到该数据模型";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("getCurrentDataClass Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DataAccessModule::getCurrentDataClass(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
int dataClassId = data["id"];
|
|
|
|
|
DPData* pData = pDataManager->findObjectById(DataManager::DataType::dataClass, dataClassId);
|
|
|
|
|
if (pData)
|
|
|
|
|
{
|
|
|
|
|
DataClass* pClass = dynamic_cast<DataClass*>(pData);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//数据模型信息返回
|
2025-06-23 10:41:33 +08:00
|
|
|
|
json data;
|
|
|
|
|
pClass->toJson(data, true);
|
|
|
|
|
parameter["response"] = data;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//未找到该数据模型
|
|
|
|
|
parameter["error"] = "未找到该数据类";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("getCurrentDataClass Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DataAccessModule::getCurrentDataModel(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
int dataModelId = data["id"];
|
|
|
|
|
DPData* pData = pDataManager->findObjectById(DataManager::DataType::dataModel, dataModelId);
|
|
|
|
|
if (pData)
|
|
|
|
|
{
|
|
|
|
|
DataModelData* pDataModel = dynamic_cast<DataModelData*>(pData);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//数据模型信息返回
|
2025-06-23 10:41:33 +08:00
|
|
|
|
json data;
|
|
|
|
|
pDataModel->toJson(data);
|
|
|
|
|
parameter["response"] = data;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//未找到该数据模型
|
|
|
|
|
parameter["error"] = "未找到该数据模型";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("getCurrentDataModel Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DataAccessModule::getAllDataTree(json& parameter)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//获取所有数据
|
2025-06-23 10:41:33 +08:00
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
int dataModelId = data["id"];
|
|
|
|
|
DPData* pData = pDataManager->findObjectById(DataManager::DataType::dataModel, dataModelId);
|
|
|
|
|
DataModelData* pDataModel = dynamic_cast<DataModelData*>(pData);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//如果为空可能是没有获取过数据模型
|
2025-06-23 10:41:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!pDataModel->_initChildren)
|
|
|
|
|
{
|
|
|
|
|
pDataModel->getAllChildren(pDataManager, false);
|
|
|
|
|
pDataModel->_initChildren = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//若是已锁定的版本,重读一下,可能被修改
|
2025-06-23 10:41:33 +08:00
|
|
|
|
if (pDataModel->_isVerLocked == true)
|
|
|
|
|
{
|
|
|
|
|
pDataModel->getAllChildren(pDataManager, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parameter["response"] = json::array();
|
|
|
|
|
//json
|
|
|
|
|
QMap<unsigned int, DPData*>::iterator it = pDataModel->_childrenMap.begin();
|
|
|
|
|
while (it != pDataModel->_childrenMap.end())
|
|
|
|
|
{
|
|
|
|
|
json pack;
|
|
|
|
|
(*it)->toJson(pack, true);
|
|
|
|
|
parameter["response"].push_back(pack);
|
|
|
|
|
it++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("getAllDataTree Sendto web.......");
|
2025-06-23 18:01:09 +08:00
|
|
|
|
// LOG(INFO) << CommonHelper::jsonToString(parameter); //以后再删除
|
2025-06-23 10:41:33 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//获取所有项目信息
|
2025-06-23 10:41:33 +08:00
|
|
|
|
bool DataAccessModule::getAllProject(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
parameter["response"] = json::array();
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//从数据库取
|
2025-06-23 10:41:33 +08:00
|
|
|
|
pDataManager->getAllChildren(pDataManager);
|
|
|
|
|
|
|
|
|
|
QMap<unsigned int, DPData*>::iterator it = pDataManager->_childrenMap.begin();
|
|
|
|
|
while (it != pDataManager->_childrenMap.end())
|
|
|
|
|
{
|
|
|
|
|
ProjectData* pData = dynamic_cast<ProjectData*>(*it);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//将对象信息转json
|
2025-06-23 10:41:33 +08:00
|
|
|
|
json j;
|
|
|
|
|
pData->toJson(j);
|
|
|
|
|
parameter["response"].push_back(j);
|
|
|
|
|
it++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("getAllProject Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DataAccessModule::getlastProject(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
pDataManager->getAllChildren(pDataManager);
|
|
|
|
|
parameter["response"] = json::array();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < pDataManager->lastProject.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
ProjectData* pData = dynamic_cast<ProjectData*>(pDataManager->lastProject.at(i));
|
|
|
|
|
json j;
|
|
|
|
|
pData->toJson(j);
|
|
|
|
|
parameter["response"].push_back(j);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("getlastProject Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
/*获取所有数据模型*/
|
2025-06-23 10:41:33 +08:00
|
|
|
|
bool DataAccessModule::getAllDataModel(json& parameter)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//获得当前项目id
|
2025-06-23 10:41:33 +08:00
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
int projectId = data["id"];
|
|
|
|
|
|
|
|
|
|
DPData* pData = pDataManager->findObjectById(DataManager::DataType::project, projectId);
|
|
|
|
|
ProjectData* pProject = dynamic_cast<ProjectData*>(pData);
|
|
|
|
|
|
|
|
|
|
if (pProject)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//找到该项目
|
2025-06-23 10:41:33 +08:00
|
|
|
|
if (!pProject->_initChildren)
|
|
|
|
|
{
|
|
|
|
|
pProject->getAllChildren(pDataManager);
|
|
|
|
|
pProject->_initChildren = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pProject->_childrenMap.isEmpty())
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
parameter["error"] = "该项目没有数据模型";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("getAllDataModel Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//读取的数据给parameter,返回给界面
|
2025-06-23 10:41:33 +08:00
|
|
|
|
QMap<unsigned int, DPData*>::iterator it = pProject->_childrenMap.begin();
|
|
|
|
|
while (it != pProject->_childrenMap.end())
|
|
|
|
|
{
|
|
|
|
|
DataModelData* pData = dynamic_cast<DataModelData*>(*it);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//将对象信息转json
|
2025-06-23 10:41:33 +08:00
|
|
|
|
if (pData) {
|
|
|
|
|
json j;
|
|
|
|
|
pData->toJson(j);
|
|
|
|
|
parameter["response"].push_back(j);
|
|
|
|
|
}
|
|
|
|
|
it++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
parameter["error"] = "找不到该项目";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("getAllDataModel Sendto web.......");
|
|
|
|
|
// LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|