283 lines
6.7 KiB
C++
283 lines
6.7 KiB
C++
|
#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)
|
|||
|
{
|
|||
|
parameter["error"] = "<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>";
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("DataAccessModule::onMessage...DB connect failed");
|
|||
|
return true;
|
|||
|
}
|
|||
|
if (eventName == "get-datamodel")
|
|||
|
{
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>Ϣ
|
|||
|
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")
|
|||
|
{
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
getAllDataTree(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "get-last-project")
|
|||
|
{
|
|||
|
// getAllProject(parameter);
|
|||
|
getlastProject(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "get-all-project")
|
|||
|
{
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ
|
|||
|
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
|
|||
|
{
|
|||
|
//δ<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
|||
|
parameter["error"] = "δ<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
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);
|
|||
|
//<2F><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|||
|
json data;
|
|||
|
pClass->toJson(data, true);
|
|||
|
parameter["response"] = data;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//δ<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
|||
|
parameter["error"] = "δ<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
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);
|
|||
|
//<2F><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|||
|
json data;
|
|||
|
pDataModel->toJson(data);
|
|||
|
parameter["response"] = data;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//δ<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
|||
|
parameter["error"] = "δ<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("getCurrentDataModel Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
bool DataAccessModule::getAllDataTree(json& parameter)
|
|||
|
{
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
auto data = parameter["data"];
|
|||
|
int dataModelId = data["id"];
|
|||
|
DPData* pData = pDataManager->findObjectById(DataManager::DataType::dataModel, dataModelId);
|
|||
|
DataModelData* pDataModel = dynamic_cast<DataModelData*>(pData);
|
|||
|
//<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD>տ<EFBFBD><D5BF><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>л<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
|||
|
|
|||
|
|
|||
|
if (!pDataModel->_initChildren)
|
|||
|
{
|
|||
|
pDataModel->getAllChildren(pDataManager, false);
|
|||
|
pDataModel->_initChildren = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>İ汾<C4B0><E6B1BE><EFBFBD>ض<EFBFBD>һ<EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD>ܱ<EFBFBD><DCB1><EFBFBD>
|
|||
|
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.......");
|
|||
|
// LOG(INFO) << CommonHelper::jsonToString(parameter); //<2F>Ժ<EFBFBD><D4BA><EFBFBD>ɾ<EFBFBD><C9BE>
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>Ϣ
|
|||
|
bool DataAccessModule::getAllProject(json& parameter)
|
|||
|
{
|
|||
|
parameter["response"] = json::array();
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ȡ
|
|||
|
pDataManager->getAllChildren(pDataManager);
|
|||
|
|
|||
|
QMap<unsigned int, DPData*>::iterator it = pDataManager->_childrenMap.begin();
|
|||
|
while (it != pDataManager->_childrenMap.end())
|
|||
|
{
|
|||
|
ProjectData* pData = dynamic_cast<ProjectData*>(*it);
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣתjson
|
|||
|
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;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*<2A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>*/
|
|||
|
bool DataAccessModule::getAllDataModel(json& parameter)
|
|||
|
{
|
|||
|
//<2F><><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><C7B0>Ŀid
|
|||
|
auto data = parameter["data"];
|
|||
|
int projectId = data["id"];
|
|||
|
|
|||
|
DPData* pData = pDataManager->findObjectById(DataManager::DataType::project, projectId);
|
|||
|
ProjectData* pProject = dynamic_cast<ProjectData*>(pData);
|
|||
|
|
|||
|
if (pProject)
|
|||
|
{
|
|||
|
//<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>Ŀ
|
|||
|
if (!pProject->_initChildren)
|
|||
|
{
|
|||
|
pProject->getAllChildren(pDataManager);
|
|||
|
pProject->_initChildren = true;
|
|||
|
}
|
|||
|
|
|||
|
if (pProject->_childrenMap.isEmpty())
|
|||
|
{
|
|||
|
parameter["error"] = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀû<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>";
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("getAllDataModel Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD>parameter<65><72><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
QMap<unsigned int, DPData*>::iterator it = pProject->_childrenMap.begin();
|
|||
|
while (it != pProject->_childrenMap.end())
|
|||
|
{
|
|||
|
DataModelData* pData = dynamic_cast<DataModelData*>(*it);
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣתjson
|
|||
|
if (pData) {
|
|||
|
json j;
|
|||
|
pData->toJson(j);
|
|||
|
parameter["response"].push_back(j);
|
|||
|
}
|
|||
|
it++;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
parameter["error"] = "<EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ";
|
|||
|
}
|
|||
|
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("getAllDataModel Sendto web.......");
|
|||
|
// LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
|
|||
|
return true;
|
|||
|
}
|