539 lines
14 KiB
C++
539 lines
14 KiB
C++
|
#pragma execution_character_set("utf-8")
|
|||
|
|
|||
|
#include "CodeGenerateEventModule.h"
|
|||
|
#include "CodeDisplayView.h"
|
|||
|
#include "DataAccessModule.h"
|
|||
|
#include "DataClass.h"
|
|||
|
#include "DataPack.h"
|
|||
|
#include "DataManager.h"
|
|||
|
#include "FindByInterface.h"
|
|||
|
#include "DelByInterface.h"
|
|||
|
#include <QDir>
|
|||
|
#include <QTextCodec>
|
|||
|
|
|||
|
#include "global.h"
|
|||
|
|
|||
|
|
|||
|
CodeGenerateEventModule::CodeGenerateEventModule(QObject* , DataManager* manager)
|
|||
|
:BaseEventModule(manager, "CodeGenerate")
|
|||
|
{
|
|||
|
codeDisplayView = nullptr;
|
|||
|
addShareEventModule(new DataAccessModule(pDataManager));
|
|||
|
}
|
|||
|
|
|||
|
CodeGenerateEventModule::~CodeGenerateEventModule()
|
|||
|
{
|
|||
|
if (codeDisplayView) {
|
|||
|
codeDisplayView->Close();
|
|||
|
delete codeDisplayView;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void CodeGenerateEventModule::closeCodeDisplay()
|
|||
|
{
|
|||
|
if (codeDisplayView) {
|
|||
|
codeDisplayView->Close();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
bool CodeGenerateEventModule::onMessage(const std::string& eventName, json& parameter)
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("CodeGenerateEventModule receive message.......");
|
|||
|
LOG(INFO) << eventName;
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
TRY{
|
|||
|
if (eventName == "code-generate-opened") {
|
|||
|
// if (codeDisplayView == nullptr)
|
|||
|
// codeDisplayView = new CodeDisplayView(nullptr);
|
|||
|
// codeDisplayView->show();
|
|||
|
}
|
|||
|
else if (eventName == "code-generate-closed") {
|
|||
|
if (codeDisplayView) {
|
|||
|
codeDisplayView->Close();
|
|||
|
}
|
|||
|
}
|
|||
|
else if (eventName == "get-delby-interface")
|
|||
|
{
|
|||
|
getDelByInterface(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "add-delby-interface")
|
|||
|
{
|
|||
|
addDelBy(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "delete-delby-interface")
|
|||
|
{
|
|||
|
deleteDelBy(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "save-delby-interface")
|
|||
|
{
|
|||
|
updateDelBy(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "get-findby-interface")
|
|||
|
{
|
|||
|
getFindByInterface(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "add-findby-interface")
|
|||
|
{
|
|||
|
addFindBy(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "delete-findby-interface")
|
|||
|
{
|
|||
|
deleteFindBy(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "save-findby-interface")
|
|||
|
{
|
|||
|
updateFindBy(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "get-all-file")
|
|||
|
{
|
|||
|
//<2F><>ȡ<EFBFBD>ļ<EFBFBD><C4BC>б<EFBFBD>
|
|||
|
getFileList(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "get-whiteboxtest-interface")
|
|||
|
{
|
|||
|
//<2F><>ȡ<EFBFBD>в<D7BA><D0B2>Խӿ<D4BD><D3BF><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
getWhiteBoxType(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "set-whiteboxtest-interface")
|
|||
|
{
|
|||
|
//<2F><><EFBFBD>ðв<D7BA><D0B2>Խӿ<D4BD><D3BF><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
setWhiteBoxType(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "generate-code")
|
|||
|
{
|
|||
|
generateCode(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else if (eventName == "code-preview")
|
|||
|
{
|
|||
|
codePreview(parameter);
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
CATCH(parameter);
|
|||
|
|
|||
|
return EventModule::onMessage(eventName, parameter);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1>ѯ<EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD>Ϣ
|
|||
|
void CodeGenerateEventModule::getFindByInterface(json& parameter)
|
|||
|
{
|
|||
|
auto data = parameter["data"];
|
|||
|
int classId = data["id"];
|
|||
|
_currentDataClassId = classId;
|
|||
|
parameter["response"] = json::array();
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
DataClass* pClass = qobject_cast<DataClass*>(pDataManager->findObjectById(DataManager::DataType::dataClass, classId));
|
|||
|
if (pClass && pClass->getFindByInterface())
|
|||
|
{
|
|||
|
QMap<int, FindByInterface*>::iterator it = pClass->_findByMap.begin();
|
|||
|
while (it != pClass->_findByMap.end())
|
|||
|
{
|
|||
|
FindByInterface* pData = (*it);
|
|||
|
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("getFindByInterface Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡɾ<C8A1><C9BE><EFBFBD>ӿ<EFBFBD>
|
|||
|
void CodeGenerateEventModule::getDelByInterface(json& parameter)
|
|||
|
{
|
|||
|
auto data = parameter["data"];
|
|||
|
int classId = data["id"];
|
|||
|
_currentDataClassId = classId;
|
|||
|
parameter["response"] = json::array();
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
DataClass* pClass = qobject_cast<DataClass*>(pDataManager->findObjectById(DataManager::DataType::dataClass, classId));
|
|||
|
|
|||
|
if (pClass && pClass->getDelByInterface())
|
|||
|
{
|
|||
|
QMap<int, DelByInterface*>::iterator it = pClass->_delByMap.begin();
|
|||
|
while (it != pClass->_delByMap.end())
|
|||
|
{
|
|||
|
DelByInterface* pData = (*it);
|
|||
|
json j;
|
|||
|
pData->toJson(j);
|
|||
|
parameter["response"].push_back(j);
|
|||
|
it++;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
parameter["error"] = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>";
|
|||
|
}
|
|||
|
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("getDelByInterface Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD>Ӳ<EFBFBD>ѯ<EFBFBD>ӿ<EFBFBD>
|
|||
|
void CodeGenerateEventModule::addFindBy(json& parameter)
|
|||
|
{
|
|||
|
|
|||
|
auto data = parameter["data"];
|
|||
|
int classId = data["parentid"];
|
|||
|
FindByInterface* pNewInterface = new FindByInterface();
|
|||
|
pNewInterface->setNewData(parameter);
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
DataClass* pClass = qobject_cast<DataClass*>(pDataManager->findObjectById(DataManager::DataType::dataClass, classId));
|
|||
|
if (pClass && pClass->addFindByInterface(pNewInterface))
|
|||
|
{
|
|||
|
json j;
|
|||
|
pNewInterface->toJson(j);
|
|||
|
parameter["response"] = j;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
parameter["error"] = "<EFBFBD>½<EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD>ӿ<EFBFBD>ʧ<EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("addFindBy Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
}
|
|||
|
|
|||
|
//ɾ<><C9BE><EFBFBD><EFBFBD>ѯ<EFBFBD>ӿ<EFBFBD>
|
|||
|
void CodeGenerateEventModule::deleteFindBy(json& parameter)
|
|||
|
{
|
|||
|
auto data = parameter["data"];
|
|||
|
int id = data["id"]; //<2F><>ǰ<EFBFBD>ӿ<EFBFBD>id
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
DataClass* pClass = qobject_cast<DataClass*>(pDataManager->findObjectById(DataManager::DataType::dataClass, _currentDataClassId));
|
|||
|
if (pClass && pClass->delFindByInterfaceById(id))
|
|||
|
{
|
|||
|
parameter["response"] = { {"status",true} };
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
parameter["response"] = { {"status",false} };
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("deleteFindBy Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
}
|
|||
|
|
|||
|
//<2F>IJ<DEB8>ѯ<EFBFBD>ӿ<EFBFBD>
|
|||
|
void CodeGenerateEventModule::updateFindBy(json& parameter)
|
|||
|
{
|
|||
|
auto data = parameter["data"];
|
|||
|
//<2F><><EFBFBD>ҵ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
DataClass* pClass = qobject_cast<DataClass*>(pDataManager->findObjectById(DataManager::DataType::dataClass, _currentDataClassId));
|
|||
|
if (pClass && pClass->updateFindByInterfaceById(parameter))
|
|||
|
{
|
|||
|
parameter["response"] = data;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("update FindbyInterface failed");
|
|||
|
parameter["error"] = "<EFBFBD>IJ<EFBFBD>ѯ<EFBFBD>ӿ<EFBFBD>ʧ<EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("updateFindBy Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD>ӿ<EFBFBD>
|
|||
|
void CodeGenerateEventModule::addDelBy(json& parameter)
|
|||
|
{
|
|||
|
auto data = parameter["data"];
|
|||
|
int classId = data["parentid"];
|
|||
|
DelByInterface* pNewInterface = new DelByInterface();
|
|||
|
pNewInterface->setNewData(parameter);
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
DataClass* pClass = qobject_cast<DataClass*>(pDataManager->findObjectById(DataManager::DataType::dataClass, classId));
|
|||
|
if (pClass && pClass->addDelByInterface(pNewInterface))
|
|||
|
{
|
|||
|
json j;
|
|||
|
pNewInterface->toJson(j);
|
|||
|
parameter["response"] = j;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
parameter["error"] = "<EFBFBD>½<EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>ʧ<EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("addDelBy Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
}
|
|||
|
|
|||
|
//ɾ<><C9BE>ɾ<EFBFBD><C9BE><EFBFBD>ӿ<EFBFBD>
|
|||
|
void CodeGenerateEventModule::deleteDelBy(json& parameter)
|
|||
|
{
|
|||
|
auto data = parameter["data"];
|
|||
|
int id = data["id"]; //<2F><>ǰ<EFBFBD>ӿ<EFBFBD>id
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
DataClass* pClass = qobject_cast<DataClass*>(pDataManager->findObjectById(DataManager::DataType::dataClass, _currentDataClassId));
|
|||
|
if (pClass && pClass->delDelByInterfaceById(id))
|
|||
|
{
|
|||
|
parameter["response"]["status"] = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
parameter["response"]["status"] = false;
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("deleteDelBy Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
}
|
|||
|
|
|||
|
//<2F><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD>ӿ<EFBFBD>
|
|||
|
void CodeGenerateEventModule::updateDelBy(json& parameter)
|
|||
|
{
|
|||
|
// auto data = parameter["data"];
|
|||
|
// int id = data["id"]; //<2F><>ǰ<EFBFBD>ĵĽӿ<C4BD>id
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
DataClass* pClass = qobject_cast<DataClass*>(pDataManager->findObjectById(DataManager::DataType::dataClass, _currentDataClassId));
|
|||
|
if (pClass && pClass->updateDelByInterfaceById(parameter))
|
|||
|
{
|
|||
|
parameter["response"]["status"] = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
parameter["response"]["status"] = false;
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("updateDelBy Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD>
|
|||
|
void CodeGenerateEventModule::generateCode(json& parameter)
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA>
|
|||
|
SysManager& sysMgr = GetSysManager();
|
|||
|
QString codeFileFolderPath = sysMgr._codeGeneratePath;
|
|||
|
|
|||
|
if (codeFileFolderPath.isEmpty())
|
|||
|
{
|
|||
|
parameter["error"] = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>";
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("DataClass::generateCode failed. codePath is empty");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
auto data = parameter["data"];
|
|||
|
QStringList cfilelist;
|
|||
|
QStringList netfilelist;
|
|||
|
auto objlist = data["codeDataList"];
|
|||
|
int codeType = data["codeType"];
|
|||
|
for (auto para : objlist)
|
|||
|
{
|
|||
|
int id = para["id"];
|
|||
|
int type = para["classType"];
|
|||
|
// int interfaceType = para["interface"]; //<2F><><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD><EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if (type == g_TYPE_DATACLASS)
|
|||
|
{ //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
DataClass* pClass = qobject_cast<DataClass*>(pDataManager->findObjectById(DataManager::DataType::dataClass, id));
|
|||
|
if (pClass)
|
|||
|
{
|
|||
|
switch (codeType)
|
|||
|
{
|
|||
|
case 1: //C++
|
|||
|
if (!pClass->generateCode(cfilelist))
|
|||
|
{
|
|||
|
//<2F><><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
parameter["response"]["error"] = "<EFBFBD><EFBFBD><EFBFBD>ɴ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>";
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("generateCode Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
return ;
|
|||
|
}
|
|||
|
break;
|
|||
|
case 2://.NET
|
|||
|
if (!pClass->generateCSharpCode(netfilelist))
|
|||
|
{
|
|||
|
//<2F><><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
parameter["response"]["error"] = "<EFBFBD><EFBFBD><EFBFBD>ɴ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>";
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("generateCode Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
return;
|
|||
|
}
|
|||
|
break;
|
|||
|
case 3: //<2F><><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
if (!pClass->generateCode(cfilelist) || !pClass->generateCSharpCode(netfilelist))
|
|||
|
{
|
|||
|
//<2F><><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
parameter["response"]["error"] = "<EFBFBD><EFBFBD><EFBFBD>ɴ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>";
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("generateCode Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else if (type == g_TYPE_DATAPACK)
|
|||
|
{
|
|||
|
DataPack* pPack = qobject_cast<DataPack*>(pDataManager->findObjectById(DataManager::DataType::dataPack, id));
|
|||
|
if (pPack)
|
|||
|
{
|
|||
|
switch (codeType)
|
|||
|
{
|
|||
|
case 1://C++
|
|||
|
if(!pPack->generateCode(/*pDataManager,*/ cfilelist))
|
|||
|
{
|
|||
|
//<2F><><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
parameter["response"]["error"] = "<EFBFBD><EFBFBD><EFBFBD>ɴ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>";
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("generateCode Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
return;
|
|||
|
}
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
break;
|
|||
|
case 3:
|
|||
|
if (!pPack->generateCode(/*pDataManager,*/ cfilelist))
|
|||
|
{
|
|||
|
//<2F><><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
parameter["response"]["error"] = "<EFBFBD><EFBFBD><EFBFBD>ɴ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>";
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("generateCode Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
return;
|
|||
|
}
|
|||
|
break;
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
parameter["response"]["CFileList"] = json::array();
|
|||
|
parameter["response"]["NetFileList"] = json::array();
|
|||
|
for (auto i : cfilelist)
|
|||
|
{
|
|||
|
string file = CommonHelper::qstringToUtf8(i);
|
|||
|
parameter["response"]["CFileList"].push_back(file);
|
|||
|
}
|
|||
|
for (auto i : netfilelist)
|
|||
|
{
|
|||
|
string file = CommonHelper::qstringToUtf8(i);
|
|||
|
parameter["response"]["NetFileList"].push_back(file);
|
|||
|
}
|
|||
|
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("generateCode Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡ<EFBFBD>ļ<EFBFBD><C4BC>б<EFBFBD>
|
|||
|
void CodeGenerateEventModule::getFileList(json& parameter)
|
|||
|
{
|
|||
|
auto data = parameter["data"];
|
|||
|
auto filePath = data["filePath"];
|
|||
|
QDir dir(CommonHelper::utf8ToQString(filePath));
|
|||
|
QStringList fileName;
|
|||
|
fileName << "*.h" << "*.cpp" << "*.test";
|
|||
|
QStringList result;
|
|||
|
result = dir.entryList(fileName, QDir::Files | QDir::Readable, QDir::Name);
|
|||
|
for (int i = 0; i < result.size(); i++)
|
|||
|
{
|
|||
|
parameter["response"]["filename"].push_back(CommonHelper::qstringToUtf8(result.at(i)));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void CodeGenerateEventModule::getWhiteBoxType(json& parameter)
|
|||
|
{
|
|||
|
auto data = parameter["data"];
|
|||
|
int id = data["id"];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>id
|
|||
|
QString strWhiteboxTest;
|
|||
|
parameter["response"] = json::array();
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
DataClass* pClass = qobject_cast<DataClass*>(pDataManager->findObjectById(DataManager::DataType::dataClass, id));
|
|||
|
try
|
|||
|
{
|
|||
|
if (!pClass) {
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("getWhiteBoxType Sendto web.......");
|
|||
|
parameter["error"] = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
return;
|
|||
|
}
|
|||
|
strWhiteboxTest = pClass->getWhiteBoxType();
|
|||
|
if (strWhiteboxTest.isEmpty())
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("getWhiteBoxType Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
return;
|
|||
|
}
|
|||
|
QStringList list = strWhiteboxTest.split(",");
|
|||
|
for (int i = 0; i < list.size(); i++)
|
|||
|
{
|
|||
|
QString str = list.at(i);
|
|||
|
QString type = str.front();
|
|||
|
QString status = str.at(str.size() - 1);
|
|||
|
json j;
|
|||
|
bool bSt = (status == "1") ? true : false;
|
|||
|
j["code"] = type.toInt();
|
|||
|
j["status"] = bSt;
|
|||
|
parameter["response"].push_back(j);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
catch (exception& e)
|
|||
|
{
|
|||
|
parameter["error"] = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
LOG(ERROR) << e.what();
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("getWhiteBoxType Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
}
|
|||
|
|
|||
|
void CodeGenerateEventModule::setWhiteBoxType(json& parameter)
|
|||
|
{
|
|||
|
auto data = parameter["data"];
|
|||
|
int id = data["id"];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>id
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
DataClass* pClass = qobject_cast<DataClass*>(pDataManager->findObjectById(DataManager::DataType::dataClass, id));
|
|||
|
try
|
|||
|
{
|
|||
|
if (!pClass) {
|
|||
|
parameter["error"] = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("setWhiteBoxType Sendto web.......");
|
|||
|
return;
|
|||
|
}
|
|||
|
parameter["response"]["status"] = pClass->setWhiteBoxType(parameter);
|
|||
|
}
|
|||
|
catch (exception& e)
|
|||
|
{
|
|||
|
LOG(ERROR) << e.what();
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("setWhiteBoxType Sendto web.......");
|
|||
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|||
|
}
|
|||
|
|
|||
|
void CodeGenerateEventModule::codePreview(json& parameter)
|
|||
|
{
|
|||
|
auto data = parameter["data"];
|
|||
|
if (codeDisplayView == nullptr)
|
|||
|
codeDisplayView = new CodeDisplayView(nullptr);
|
|||
|
codeDisplayView->cfileList.clear();
|
|||
|
codeDisplayView->netfileList.clear();
|
|||
|
codeDisplayView->setMinimumSize(QSize(600, 400));
|
|||
|
auto cfiles = data["CFileList"];
|
|||
|
for (auto i : cfiles)
|
|||
|
{
|
|||
|
codeDisplayView->cfileList.append(CommonHelper::utf8ToQString(i));
|
|||
|
}
|
|||
|
auto netfilelist = data["NetFileList"];
|
|||
|
for (auto i : netfilelist)
|
|||
|
{
|
|||
|
codeDisplayView->netfileList.append(CommonHelper::utf8ToQString(i));
|
|||
|
}
|
|||
|
codeDisplayView->show();
|
|||
|
codeDisplayView->updateFileList();
|
|||
|
}
|
|||
|
|