2025-06-23 10:41:33 +08:00
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include<Qtime>
|
|
|
|
|
#include<QProcess>
|
|
|
|
|
|
|
|
|
|
#include"SearchEditEventModule.h"
|
|
|
|
|
#include"DataManager.h"
|
|
|
|
|
#include"DataModelData.h"
|
|
|
|
|
#include"M_EntityModelDAO.h"
|
|
|
|
|
#include"M_EntityTableDAO.h"
|
|
|
|
|
#include"M_NormalColumnDAO.h"
|
|
|
|
|
#include"DataAttribute.h"
|
|
|
|
|
#include"DataClass.h"
|
|
|
|
|
#include"Connection.h"
|
|
|
|
|
#include"global.h"
|
|
|
|
|
#include"ProjectData.h"
|
|
|
|
|
#include"SqlcipherTool.h"
|
|
|
|
|
|
|
|
|
|
//#define QTDEBUG
|
|
|
|
|
|
|
|
|
|
#ifdef QTDEBUG
|
|
|
|
|
|
|
|
|
|
json ret16 = json::array();
|
|
|
|
|
json ret17 = json::array();
|
|
|
|
|
json ret18 = json::array();
|
|
|
|
|
json ret30 = json::array();
|
|
|
|
|
json ret31 = json::array();
|
|
|
|
|
|
|
|
|
|
QStringList head;
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//测试数据生成
|
2025-06-23 10:41:33 +08:00
|
|
|
|
void buildTestData()
|
|
|
|
|
{
|
|
|
|
|
head << "id" << "proA" << "proB" << "proC" << "proD" << "proE";
|
|
|
|
|
for (int index = 1; index <= 5; index++)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//少量数据
|
2025-06-23 10:41:33 +08:00
|
|
|
|
for (int i = 0; i < index*1000; i++)
|
|
|
|
|
{
|
|
|
|
|
json col;
|
|
|
|
|
col["id"] = QString::number(i + 1).toStdString();
|
|
|
|
|
for (int j = 1; j < head.size(); j++)
|
|
|
|
|
{
|
|
|
|
|
col[head[j].toStdString()] = QString::number(qrand() % 10).toStdString();
|
|
|
|
|
}
|
|
|
|
|
switch (index)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
ret16.push_back(col);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
ret17.push_back(col);
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
ret18.push_back(col);
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
ret30.push_back(col);
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
ret31.push_back(col);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void getfile(json& parameter)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//打开文件夹选择
|
2025-06-23 10:41:33 +08:00
|
|
|
|
QString curPath = QCoreApplication::applicationDirPath();
|
2025-06-23 18:01:09 +08:00
|
|
|
|
QString selectDir = QFileDialog::getOpenFileName(nullptr, "选择文件", curPath, "");
|
2025-06-23 10:41:33 +08:00
|
|
|
|
if (!selectDir.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
parameter["response"] = CommonHelper::qstringToUtf8(selectDir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString buildTmpFileName(QString type, int id, int colid)
|
|
|
|
|
{
|
|
|
|
|
QString tail = type.section('.', 1);
|
|
|
|
|
if (tail == "*")
|
|
|
|
|
{
|
|
|
|
|
return QString("%1@%2").arg(id).arg(colid);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return QString("%1@%2.%3").arg(id).arg(colid).arg(tail);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString checkFileType(QByteArray bytes)
|
|
|
|
|
{
|
|
|
|
|
QByteArray fileHead = bytes.left(50);
|
|
|
|
|
if (fileHead.startsWith("\xFF\xD8\xFF"))
|
|
|
|
|
{
|
|
|
|
|
return "*.jpg";
|
|
|
|
|
}
|
|
|
|
|
else if (fileHead.startsWith("\x42\x4D"))
|
|
|
|
|
{
|
|
|
|
|
return "*.bmp";
|
|
|
|
|
}
|
|
|
|
|
else if (fileHead.startsWith("\x89\x50\x4E\x47"))
|
|
|
|
|
{
|
|
|
|
|
return "*.png";
|
|
|
|
|
}
|
|
|
|
|
else if (fileHead.startsWith("\x47\x49\x46\x38"))
|
|
|
|
|
{
|
|
|
|
|
return "*.gif";
|
|
|
|
|
}
|
|
|
|
|
else if (fileHead.startsWith("\x3c\x3F\x78\x6D\x6C"))
|
|
|
|
|
{
|
|
|
|
|
return "*.xml";
|
|
|
|
|
}
|
|
|
|
|
else if (fileHead.startsWith("\x68\x74\x6D\x6C\x3E"))
|
|
|
|
|
{
|
|
|
|
|
return "*.html";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SearchEditEventModule::SearchEditEventModule(QObject* /*parent*/, DataManager* manager)
|
|
|
|
|
:BaseEventModule(manager, "SearchEditModule")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#ifdef QTDEBUG
|
|
|
|
|
buildTestData();
|
|
|
|
|
#endif // QTDEBUG
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SearchEditEventModule::~SearchEditEventModule()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchEditEventModule::onMessage(const std::string& eventName, json& parameter)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("SearchEditEventModule receive message.......");
|
|
|
|
|
LOG(INFO) << eventName;
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//检查是否连接数据库
|
2025-06-23 10:41:33 +08:00
|
|
|
|
DataManager& dataRoot = GetDataRoot();
|
|
|
|
|
if (!dataRoot.pTheDBPlatform)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
parameter["error"] = "请先连接数据库文件!";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//using namespace DBPlatformSpace;
|
|
|
|
|
//DBPlatformNew::setCurrentWorkDB("d:\\test1");
|
|
|
|
|
//M_EntityTableDAO* pTable = NULL;
|
|
|
|
|
//M_EntityTableDAO::FindByID(422, pTable);
|
|
|
|
|
//list<M_NormalColumnDAO*> columnList;
|
|
|
|
|
//list<string>valueList, valuelist2;
|
|
|
|
|
//ResultMsg rm3 = pTable->getData(columnList, valueList);
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//valuelist2.push_back("-1@#@202@#@BBC大大小@#@101");
|
|
|
|
|
//valuelist2.push_back("-1@#@201@#@BB大大小多多少少@#@103");
|
|
|
|
|
//valuelist2.push_back("-1@#@203@#@BB大大小多少@#@101");
|
2025-06-23 10:41:33 +08:00
|
|
|
|
//ResultMsg rm4 = pTable->saveData(columnList, valuelist2);
|
|
|
|
|
//rm3 = pTable->getData(columnList, valueList);
|
|
|
|
|
|
|
|
|
|
TRY{
|
|
|
|
|
if (eventName == "open-file-dir")
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
////打开文件夹选择
|
2025-06-23 10:41:33 +08:00
|
|
|
|
//QString curPath = QCoreApplication::applicationDirPath();
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//QString selectDir = QFileDialog::getOpenFileName(nullptr, "选择文件", curPath, "");
|
2025-06-23 10:41:33 +08:00
|
|
|
|
//if (!selectDir.isEmpty())
|
|
|
|
|
//{
|
|
|
|
|
// parameter["response"] = CommonHelper::qstringToUtf8(selectDir);
|
|
|
|
|
//}
|
|
|
|
|
getfile(parameter);
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("open-file-dir Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "open-data-file")
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//连接指定的数据文件
|
2025-06-23 10:41:33 +08:00
|
|
|
|
return connectDBFile(parameter);
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "save-connection")
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//保存连接信息
|
2025-06-23 10:41:33 +08:00
|
|
|
|
return saveConnection(parameter);
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "close-connection")
|
2025-06-23 18:01:09 +08:00
|
|
|
|
{//关闭连接
|
2025-06-23 10:41:33 +08:00
|
|
|
|
return closeConnection(parameter);
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "delete-connection")
|
2025-06-23 18:01:09 +08:00
|
|
|
|
{//删除连接
|
2025-06-23 10:41:33 +08:00
|
|
|
|
return delConnection(parameter);
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "get-table-stru")
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//获取数据类结构
|
2025-06-23 10:41:33 +08:00
|
|
|
|
return getTableStru(parameter);
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "get-table-data")
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//获取数据类数据
|
2025-06-23 10:41:33 +08:00
|
|
|
|
return getTableData(parameter);
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "save-table-item")
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//添加和修改数据
|
2025-06-23 10:41:33 +08:00
|
|
|
|
return saveTableItem(parameter);
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "delete-table-item")
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//删除
|
2025-06-23 10:41:33 +08:00
|
|
|
|
return delTableItem(parameter);
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "save-new-data-file")
|
2025-06-23 18:01:09 +08:00
|
|
|
|
{ //另存为
|
2025-06-23 10:41:33 +08:00
|
|
|
|
return saveNewFile(parameter);
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "filter-data")
|
2025-06-23 18:01:09 +08:00
|
|
|
|
{ //筛选数据
|
2025-06-23 10:41:33 +08:00
|
|
|
|
return filterData(parameter);
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "get-src-file")
|
2025-06-23 18:01:09 +08:00
|
|
|
|
{ //获取需要加/解密的数据文件
|
2025-06-23 10:41:33 +08:00
|
|
|
|
getfile(parameter);
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("get-src-file Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "set-new-file")
|
|
|
|
|
{
|
|
|
|
|
setNewFile(parameter);
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("seet-new-file Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "do-encryption")
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//进行加解密
|
2025-06-23 10:41:33 +08:00
|
|
|
|
sqlcipherDo(parameter);
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("do-encryption Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "save-data-to-file")
|
2025-06-23 18:01:09 +08:00
|
|
|
|
{//保存blob数据到本地
|
2025-06-23 10:41:33 +08:00
|
|
|
|
saveBlobToFile(parameter);
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("save-data-to-file Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == "copy-blob-data")
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//复制blob
|
2025-06-23 10:41:33 +08:00
|
|
|
|
copyBlobData(parameter);
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("copy-blob-data Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CATCH(parameter);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return EventModule::onMessage(eventName, parameter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool SearchEditEventModule::connectDBFile(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
#ifdef QTDEBUG
|
|
|
|
|
json ret;
|
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
int id = data["id"];
|
|
|
|
|
int modelId = 0;
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//查找连接
|
2025-06-23 10:41:33 +08:00
|
|
|
|
SysManager& sysMnr = GetSysManager();
|
|
|
|
|
Connection* pCon = sysMnr.findConnection(id);
|
|
|
|
|
if (!pCon)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//没找到连接
|
|
|
|
|
parameter["error"] = "找不到连接";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("open-data-file Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
QString name = pCon->getPath().right(4);
|
|
|
|
|
if (name == "A.db")
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//失败
|
2025-06-23 10:41:33 +08:00
|
|
|
|
parameter["response"]["status"] = false;
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("open-data-file Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (name == "B.db")
|
|
|
|
|
{
|
|
|
|
|
modelId = 3;
|
|
|
|
|
}
|
|
|
|
|
else if (name == "C.db")
|
|
|
|
|
{
|
|
|
|
|
modelId = 6;
|
|
|
|
|
}
|
|
|
|
|
else if (name == "D.db")
|
|
|
|
|
{
|
|
|
|
|
modelId = 7;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//当前时间
|
2025-06-23 10:41:33 +08:00
|
|
|
|
QString curTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm");
|
|
|
|
|
pCon->setTime(curTime);
|
|
|
|
|
pCon->setStatus(true);
|
|
|
|
|
pCon->toJson(ret);
|
|
|
|
|
|
|
|
|
|
DataModelData* pCurrentModel = qobject_cast<DataModelData*>(pDataManager->findObjectById(DataManager::DataType::dataModel, modelId));
|
|
|
|
|
ret["dataclass"] = json::array();
|
|
|
|
|
if (pCurrentModel)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//如果找到模型,获得所有的数据类
|
2025-06-23 10:41:33 +08:00
|
|
|
|
if (!pCurrentModel->_initChildren)
|
|
|
|
|
{
|
|
|
|
|
pCurrentModel->getAllChildren(pDataManager, false);
|
|
|
|
|
pCurrentModel->_initChildren = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//json
|
|
|
|
|
QMap<unsigned int, DPData*>::iterator it = pCurrentModel->_childrenMap.begin();
|
|
|
|
|
while (it != pCurrentModel->_childrenMap.end())
|
|
|
|
|
{
|
|
|
|
|
json pack;
|
|
|
|
|
(*it)->toJson(pack, true);
|
|
|
|
|
ret["dataclass"].push_back(pack);
|
|
|
|
|
it++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
parameter["response"] = ret;
|
|
|
|
|
#else
|
|
|
|
|
using namespace DBPlatformSpace;
|
|
|
|
|
json ret;
|
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
int id = data["id"];
|
2025-06-23 18:01:09 +08:00
|
|
|
|
QString modelName; //数据文件对应模型名,确认是 名称标识还是显示名称?
|
|
|
|
|
//查找连接
|
2025-06-23 10:41:33 +08:00
|
|
|
|
SysManager& sysMnr = GetSysManager();
|
|
|
|
|
Connection* pCon = sysMnr.findConnection(id);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//确认连接文件是否存在
|
2025-06-23 10:41:33 +08:00
|
|
|
|
QFile file(pCon->getPath());
|
|
|
|
|
if (file.exists())
|
|
|
|
|
{
|
|
|
|
|
ResultMsg rm = DBPlatformSpace::DBPlatformNew::setCurrentWorkDB(CommonHelper::qstringToStdString(pCon->getPath()),0);
|
|
|
|
|
if (rm.rCode == 0)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//获取对应的数据模型
|
2025-06-23 10:41:33 +08:00
|
|
|
|
M_EntityModelDAO* pMEntityModel = nullptr;
|
|
|
|
|
ResultMsg rm = M_EntityModelDAO::getInstanceInfo(CommonHelper::qstringToStdString(pCon->getPath()), pMEntityModel);
|
|
|
|
|
if (rm.rCode == 0)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//设置当前文件路径
|
2025-06-23 10:41:33 +08:00
|
|
|
|
currentFilePath = pCon->getPath();
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//文件设置成功
|
2025-06-23 10:41:33 +08:00
|
|
|
|
pCon->setStatus(true);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//连接类型:置为 sqlite
|
2025-06-23 10:41:33 +08:00
|
|
|
|
pCon->setType("sqlite");
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//当前时间
|
2025-06-23 10:41:33 +08:00
|
|
|
|
QString curTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm");
|
|
|
|
|
pCon->setTime(curTime);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
pCon->toJson(ret); //连接信息返回
|
2025-06-23 10:41:33 +08:00
|
|
|
|
ret["dataclass"] = json::array();
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
////先找项目
|
2025-06-23 10:41:33 +08:00
|
|
|
|
ProjectData* pPro = qobject_cast<ProjectData*>(pDataManager->findObjectById(DataManager::DataType::project, pMEntityModel->_rProjectID));
|
|
|
|
|
if (pPro)
|
|
|
|
|
{
|
|
|
|
|
if (!pPro->_initChildren)
|
|
|
|
|
pPro->getAllChildren(pDataManager);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//获取数据模型名
|
2025-06-23 10:41:33 +08:00
|
|
|
|
pCurrentModel = qobject_cast<DataModelData*>(pDataManager->findObjectById(DataManager::DataType::dataModel, pMEntityModel->_ID));
|
|
|
|
|
if (pCurrentModel)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//如果找到模型,获得所有的数据类
|
2025-06-23 10:41:33 +08:00
|
|
|
|
if (!pCurrentModel->_initChildren)
|
|
|
|
|
{
|
|
|
|
|
pCurrentModel->getAllChildren(pDataManager, false);
|
|
|
|
|
pCurrentModel->_initChildren = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parameter["response"] = json::array();
|
|
|
|
|
//json
|
|
|
|
|
QMap<unsigned int, DPData*>::iterator it = pCurrentModel->_childrenMap.begin();
|
|
|
|
|
while (it != pCurrentModel->_childrenMap.end())
|
|
|
|
|
{
|
|
|
|
|
json pack;
|
|
|
|
|
(*it)->toJson(pack, true);
|
|
|
|
|
ret["dataclass"].push_back(pack);
|
|
|
|
|
it++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//找不到数据模型
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//找不到项目提示错误信息
|
2025-06-23 10:41:33 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//查询实例文件和项目信息失败
|
2025-06-23 10:41:33 +08:00
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityModelDAO::getInstanceInfo failed ");
|
2025-06-23 18:01:09 +08:00
|
|
|
|
parameter["error"] = "打开连接失败,请检查文件是否有效";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
LOG(ERROR) << rm.rMsg;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("setCurrentWorkDB failed ");
|
2025-06-23 18:01:09 +08:00
|
|
|
|
parameter["error"] = "打开连接失败,请检查文件是否有效";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
LOG(ERROR) << rm.rMsg;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
LOG(INFO) << "连接文件不存在";
|
|
|
|
|
parameter["error"] = "连接文件不存在,请检查。";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("open-data-file Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parameter["response"] = ret;
|
|
|
|
|
#endif
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("open-data-file 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 SearchEditEventModule::saveConnection(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
int id = data["id"];
|
|
|
|
|
Connection* pConn = nullptr;
|
|
|
|
|
SysManager& sysMnr = GetSysManager();
|
|
|
|
|
if (id == -1)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//新建连接
|
2025-06-23 10:41:33 +08:00
|
|
|
|
pConn = new Connection();
|
|
|
|
|
id = sysMnr.IDTool.new_id();
|
|
|
|
|
pConn->save(parameter);
|
|
|
|
|
pConn->setID(id);
|
|
|
|
|
sysMnr.addConnection(id, pConn);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pConn = sysMnr.findConnection(id);
|
|
|
|
|
if (pConn)
|
|
|
|
|
{
|
|
|
|
|
pConn->save(parameter);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("save-connection cannot find connection");
|
|
|
|
|
parameter["response"]["status"] = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
json j;
|
|
|
|
|
sysMnr.getConnectionJson(j);
|
|
|
|
|
parameter["response"] = j;
|
|
|
|
|
|
|
|
|
|
//sysMnr.saveConnectionProfile();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("save-connection 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 SearchEditEventModule::closeConnection(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
int id = data["id"];
|
|
|
|
|
SysManager& sysMnr = GetSysManager();
|
|
|
|
|
Connection* pCon = sysMnr.findConnection(id);
|
|
|
|
|
if (!pCon)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
parameter["error"] = "找不到连接";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
pCon->setStatus(false);
|
|
|
|
|
// pDataManager->pTheDBPlatform->setCurrentWorkDB("");
|
|
|
|
|
parameter["response"]["status"] = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//删除数据连接
|
2025-06-23 10:41:33 +08:00
|
|
|
|
bool SearchEditEventModule::delConnection(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
int id = data["id"];
|
|
|
|
|
SysManager& sysMnr = GetSysManager();
|
|
|
|
|
if (sysMnr.delConnection(id))
|
|
|
|
|
{
|
|
|
|
|
json j;
|
|
|
|
|
sysMnr.getConnectionJson(j);
|
|
|
|
|
parameter["response"] = j;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("del-connection failed.......");
|
|
|
|
|
parameter["response"]["status"] = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sysMnr.IDTool.recylce_id(id);
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchEditEventModule::getTableStru(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
int id = data["tableId"];
|
|
|
|
|
#ifdef QTDEBUG
|
|
|
|
|
DataClass* pTable = qobject_cast<DataClass*>(pDataManager->findObjectById(DataManager::DataType::dataClass, id));
|
|
|
|
|
if (!pTable)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
parameter["error"] = "找不到数据类";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//json
|
|
|
|
|
QMap<unsigned int, DPData*>::iterator it = pTable->_childrenMap.begin();
|
|
|
|
|
while (it != pTable->_childrenMap.end())
|
|
|
|
|
{
|
|
|
|
|
json pack;
|
|
|
|
|
(*it)->toJson(pack, true);
|
|
|
|
|
parameter["response"].push_back(pack);
|
|
|
|
|
it++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
DPData* pTable = pDataManager->findObjectById(DataManager::DataType::dataClass, id);
|
|
|
|
|
DBPlatformSpace::M_EntityTableDAO* pT = dynamic_cast<DBPlatformSpace::M_EntityTableDAO*>(pTable->_pDBDAO);
|
|
|
|
|
|
|
|
|
|
string currWorkDBFilePath = "";
|
|
|
|
|
currWorkDBFilePath = DBPlatformSpace::DBPlatformNew::getCurrentWorkDB();
|
|
|
|
|
DBPlatformSpace::M_EntityModelDAO* pMmodelOwner = NULL;
|
|
|
|
|
DBPlatformSpace::M_EntityModelDAO::getInstanceInfo(currWorkDBFilePath, pMmodelOwner);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//获取数据列信息
|
2025-06-23 10:41:33 +08:00
|
|
|
|
list<DBPlatformSpace::M_NormalColumnDAO*> colInDbList;
|
|
|
|
|
pT->getNormalColumnDAOList(pMmodelOwner, colInDbList);
|
|
|
|
|
|
|
|
|
|
for (auto el:colInDbList)
|
|
|
|
|
{
|
|
|
|
|
json j;
|
|
|
|
|
DataAttribute att;
|
|
|
|
|
att.loadData(el);
|
|
|
|
|
att.toJson(j);
|
|
|
|
|
parameter["response"].push_back(j);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("getTableStru Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchEditEventModule::getTableData(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
int id = data["tableId"];
|
|
|
|
|
|
|
|
|
|
#ifdef QTDEBUG
|
|
|
|
|
json ret;
|
|
|
|
|
|
|
|
|
|
if (id == 16)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//少量数据
|
2025-06-23 10:41:33 +08:00
|
|
|
|
//for (int i = 0; i < 10; i++)
|
|
|
|
|
//{
|
|
|
|
|
// json col;
|
|
|
|
|
// for (int j = 0; j < head.size(); j++)
|
|
|
|
|
// {
|
|
|
|
|
// col[head[j].toStdString()] = qrand() % 10;
|
|
|
|
|
// }
|
|
|
|
|
// ret.push_back(col);
|
|
|
|
|
//}
|
|
|
|
|
ret = ret16;
|
|
|
|
|
}
|
|
|
|
|
else if (id == 17)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//大量数据
|
2025-06-23 10:41:33 +08:00
|
|
|
|
//for (int i = 0; i < 10000; i++)
|
|
|
|
|
//{
|
|
|
|
|
// json col;
|
|
|
|
|
// for (int j = 0; j < head.size(); j++)
|
|
|
|
|
// {
|
|
|
|
|
// col[head[j].toStdString()] = qrand() % 30;
|
|
|
|
|
// }
|
|
|
|
|
// ret.push_back(col);
|
|
|
|
|
//}
|
|
|
|
|
ret = ret17;
|
|
|
|
|
}
|
|
|
|
|
else if (id == 18)
|
|
|
|
|
{
|
|
|
|
|
ret = ret18;
|
|
|
|
|
}
|
|
|
|
|
else if (id == 30)
|
|
|
|
|
{
|
|
|
|
|
ret = ret30;
|
|
|
|
|
}
|
|
|
|
|
else if (id == 31)
|
|
|
|
|
{
|
|
|
|
|
ret = ret31;
|
|
|
|
|
}
|
|
|
|
|
parameter["response"] = ret;
|
|
|
|
|
#else
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//查找该数据类
|
2025-06-23 10:41:33 +08:00
|
|
|
|
DPData* pTable = pDataManager->findObjectById(DataManager::DataType::dataClass,id);
|
|
|
|
|
|
|
|
|
|
if (pTable)
|
|
|
|
|
{
|
|
|
|
|
json j;
|
|
|
|
|
bool ret = qobject_cast<DataClass*>(pTable)->getAllDataToJson(j);
|
|
|
|
|
parameter["response"] = j;
|
|
|
|
|
if (ret == false)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
parameter["error"] = "获取数据失败";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
parameter["error"] = "获取数据类数据失败";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("getTableData Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchEditEventModule::saveNewFile(json& parameter)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//打开文件夹选择
|
2025-06-23 10:41:33 +08:00
|
|
|
|
QString curPath = QCoreApplication::applicationDirPath();
|
2025-06-23 18:01:09 +08:00
|
|
|
|
QString selectDir = QFileDialog::getSaveFileName(nullptr, tr("文件另存为"), "", "", nullptr, QFileDialog::DontConfirmOverwrite);
|
2025-06-23 10:41:33 +08:00
|
|
|
|
|
|
|
|
|
auto data = parameter["data"];
|
2025-06-23 18:01:09 +08:00
|
|
|
|
int id = data["id"]; //当前连接 id
|
2025-06-23 10:41:33 +08:00
|
|
|
|
|
|
|
|
|
if (!selectDir.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
QFileInfo selectFile(selectDir);
|
|
|
|
|
if (selectFile.isFile())
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//文件存在
|
|
|
|
|
QString msg = "文件已存在,请重新命名!";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
parameter["error"] = CommonHelper::qstringToUtf8(msg);
|
|
|
|
|
parameter["response"]["status"] = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parameter["response"] = CommonHelper::qstringToUtf8(selectDir);
|
|
|
|
|
#ifdef QTDEBUG
|
|
|
|
|
return true;
|
|
|
|
|
#endif // QTDEBUG
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
parameter["response"]["status"] = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//关闭连接
|
2025-06-23 10:41:33 +08:00
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//复制
|
2025-06-23 10:41:33 +08:00
|
|
|
|
oldFile = currentFilePath;
|
|
|
|
|
bool ret = QFile::copy(currentFilePath, selectDir);
|
|
|
|
|
if (ret)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//切换到新文件
|
2025-06-23 10:41:33 +08:00
|
|
|
|
DBPlatformSpace::ResultMsg rm = DBPlatformSpace::DBPlatformNew::setCurrentWorkDB(CommonHelper::qstringToStdString(selectDir),0);
|
|
|
|
|
if (rm.rCode != 0)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//此时恢复
|
|
|
|
|
parameter["error"] = "无法另存为该数据文件";
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("复制文件成功,但设置新文件路径失败");
|
2025-06-23 10:41:33 +08:00
|
|
|
|
rm = DBPlatformSpace::DBPlatformNew::setCurrentWorkDB(CommonHelper::qstringToStdString(oldFile));
|
|
|
|
|
if (rm.rCode == 0)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("恢复到原路径成功");
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("恢复到原路径失败");
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
bool ret = QFile::remove(selectDir);
|
|
|
|
|
if (ret == true)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("删除新文件成功");
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("删除新文件失败");
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("copytoNewFile Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::stringToUtf8(rm.rMsg);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
currentFilePath = selectDir;
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//更新连接信息
|
2025-06-23 10:41:33 +08:00
|
|
|
|
SysManager& sysMnr = GetSysManager();
|
|
|
|
|
Connection* pCon = sysMnr.findConnection(id);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//保存当前连接id
|
2025-06-23 10:41:33 +08:00
|
|
|
|
currentConnectID = id;
|
|
|
|
|
if (pCon)
|
|
|
|
|
{
|
|
|
|
|
pCon->setPath(currentFilePath);
|
|
|
|
|
}
|
|
|
|
|
json j;
|
|
|
|
|
pCon->toJson(j);
|
|
|
|
|
parameter["response"] = j;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
parameter["error"] = "另存数据文件失败";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("copytoNewFile Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//修改
|
|
|
|
|
//proA = 100时,返回修改失败
|
2025-06-23 10:41:33 +08:00
|
|
|
|
bool modify(json& j, int id, json& src)
|
|
|
|
|
{
|
|
|
|
|
for (auto& x : src)
|
|
|
|
|
{
|
|
|
|
|
if (x["id"] == id)
|
|
|
|
|
{
|
|
|
|
|
if (j["proA"] == "100") return false;
|
|
|
|
|
x["proA"] = j["proA"];
|
|
|
|
|
x["proB"] = j["proB"];
|
|
|
|
|
x["proC"] = j["proC"];
|
|
|
|
|
x["proD"] = j["proD"];
|
|
|
|
|
x["proE"] = j["proE"];
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("can not find modify data");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchEditEventModule::saveTableItem(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
int id = data["tableId"];
|
|
|
|
|
auto saveas = data["saveas"];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef QTDEBUG
|
|
|
|
|
|
|
|
|
|
bool ret;
|
|
|
|
|
auto items = data["items"];
|
|
|
|
|
for (auto& x : items)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//每行数据
|
2025-06-23 10:41:33 +08:00
|
|
|
|
// map<string, string> mp = x;
|
|
|
|
|
json j = x;
|
|
|
|
|
if (id == 16)
|
|
|
|
|
{
|
|
|
|
|
if (j["id"] == "-1")
|
|
|
|
|
{
|
|
|
|
|
j["id"] = "200";
|
|
|
|
|
ret16.push_back(j);
|
|
|
|
|
ret = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
2025-06-23 18:01:09 +08:00
|
|
|
|
{//修改
|
2025-06-23 10:41:33 +08:00
|
|
|
|
ret = modify(j, j["id"], ret16);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (id == 17)
|
|
|
|
|
{
|
|
|
|
|
if (j["id"] == "-1")
|
|
|
|
|
{
|
|
|
|
|
j["id"] = "20000";
|
|
|
|
|
ret17.push_back(j);
|
|
|
|
|
ret = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//修改
|
2025-06-23 10:41:33 +08:00
|
|
|
|
ret = modify(j, j["id"], ret17);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
parameter["response"]["status"] = ret;
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
//list<string> valuelist;
|
|
|
|
|
|
|
|
|
|
//auto items = data["items"];
|
|
|
|
|
//for (auto& x : items)
|
|
|
|
|
//{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
// QStringList qValue; //每行数据
|
2025-06-23 10:41:33 +08:00
|
|
|
|
// map<string, string> mp = x;
|
|
|
|
|
// for (auto& y : mp)
|
|
|
|
|
// {
|
|
|
|
|
// string v = y.second;
|
|
|
|
|
// qValue.push_back(QString::fromStdString(v));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// string value = CommonHelper::qstringToStdString(qValue.join(","));
|
|
|
|
|
// valuelist.push_back(value);
|
|
|
|
|
//}
|
|
|
|
|
DPData* pTable = pDataManager->findObjectById(DataManager::DataType::dataClass,id);
|
|
|
|
|
if (pTable)
|
|
|
|
|
{
|
|
|
|
|
bool ret = qobject_cast<DataClass*>(pTable)->saveTableData(parameter, pCurrentModel);
|
|
|
|
|
parameter["response"]["status"] = ret;
|
|
|
|
|
if (ret == false && saveas == true)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//如果是另存为失败,删除新生成的另存文件
|
2025-06-23 10:41:33 +08:00
|
|
|
|
SysManager& sysMnr = GetSysManager();
|
|
|
|
|
Connection* pCon = sysMnr.findConnection(currentConnectID);
|
|
|
|
|
QString newfile = pCon->getPath();
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//恢复连接信息
|
|
|
|
|
//切换到原文件
|
2025-06-23 10:41:33 +08:00
|
|
|
|
DBPlatformSpace::ResultMsg rm = DBPlatformSpace::DBPlatformNew::setCurrentWorkDB(CommonHelper::qstringToStdString(oldFile),0);
|
|
|
|
|
if (rm.rCode == 0)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//切换到原文件成功恢复连接信息
|
2025-06-23 10:41:33 +08:00
|
|
|
|
pCon->setPath(oldFile);
|
|
|
|
|
currentFilePath = oldFile;
|
2025-06-23 18:01:09 +08:00
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("另存失败,切换到原数据文件连接");
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//切换到原文件失败
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("另存失败,切换原数据文件失败");
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
bool ret = QFile::remove(newfile);
|
|
|
|
|
if (ret == false)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//删除原文件失败
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("另存失败时,删除新文件失败");
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//删除原文件失败
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("另存失败时,删除新文件成功");
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
parameter["error"] = "找不到数据类";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("savetableItem Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchEditEventModule::delTableItem(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
int id = data["tableId"];
|
|
|
|
|
auto items = data["items"];
|
|
|
|
|
auto saveas = data["saveas"];
|
|
|
|
|
json ret;
|
|
|
|
|
#ifdef QTDEBUG
|
|
|
|
|
if (items.size() == 0)
|
|
|
|
|
{
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("clear the table");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (id == 16)
|
|
|
|
|
{
|
|
|
|
|
for (auto& i : items)
|
|
|
|
|
{
|
|
|
|
|
for (json::iterator it = ret16.begin(); it != ret16.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if ((*it)["id"] == i)
|
|
|
|
|
{
|
|
|
|
|
ret16.erase(it);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
parameter["response"]["status"] = true;
|
|
|
|
|
}
|
|
|
|
|
if (id == 17)
|
|
|
|
|
{
|
|
|
|
|
parameter["response"]["status"] = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
DPData* pTable = pDataManager->findObjectById(DataManager::DataType::dataClass, id);
|
|
|
|
|
if (pTable)
|
|
|
|
|
{
|
|
|
|
|
bool ret = qobject_cast<DataClass*>(pTable)->delTableData(parameter);
|
|
|
|
|
parameter["response"]["status"] = ret;
|
|
|
|
|
if (ret == false && saveas == true)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//如果是删除(另存为)失败,删除新生成的另存文件
|
2025-06-23 10:41:33 +08:00
|
|
|
|
SysManager& sysMnr = GetSysManager();
|
|
|
|
|
Connection* pCon = sysMnr.findConnection(currentConnectID);
|
|
|
|
|
QString newfile = pCon->getPath();
|
|
|
|
|
bool ret = QFile::remove(newfile);
|
|
|
|
|
if (ret == false)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//删除原文件失败
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString( "(删除)另存失败时,删除新文件失败");
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//恢复连接信息
|
|
|
|
|
//切换到原文件
|
2025-06-23 10:41:33 +08:00
|
|
|
|
DBPlatformSpace::ResultMsg rm = DBPlatformSpace::DBPlatformNew::setCurrentWorkDB(CommonHelper::qstringToStdString(oldFile),0);
|
|
|
|
|
if (rm.rCode == 0)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//恢复连接信息
|
2025-06-23 10:41:33 +08:00
|
|
|
|
pCon->setPath(oldFile);
|
|
|
|
|
currentFilePath = oldFile;
|
2025-06-23 18:01:09 +08:00
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("(删除)另存失败,恢复原数据文件连接");
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("(删除)另存失败,恢复原连接信息失败");
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
parameter["error"] = "找不到数据类";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SearchEditEventModule::filterData(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
auto data = parameter["data"];
|
2025-06-23 18:01:09 +08:00
|
|
|
|
int id = data["tableId"]; //要做筛选的数据类id
|
2025-06-23 10:41:33 +08:00
|
|
|
|
QString filterStr = CommonHelper::utf8ToQString(data["filter"]);
|
|
|
|
|
|
|
|
|
|
DPData* pData = pDataManager->findObjectById(DataManager::DataType::dataClass, id);
|
|
|
|
|
DataClass* pTable = qobject_cast<DataClass*>(pData);
|
|
|
|
|
json result;
|
|
|
|
|
pTable->filterData(filterStr, result);
|
|
|
|
|
parameter["response"] = result;
|
|
|
|
|
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("filterData Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchEditEventModule::setNewFile(json& parameter)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//选择新文件全路径
|
|
|
|
|
QString file = QFileDialog::getSaveFileName(nullptr, tr("保存为文件"), "", "", nullptr, QFileDialog::DontConfirmOverwrite);
|
2025-06-23 10:41:33 +08:00
|
|
|
|
|
|
|
|
|
if (file.isEmpty())
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
// parameter["error"] = "未确定文件";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QFileInfo selectFile(file);
|
|
|
|
|
if (selectFile.isFile())
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//文件存在
|
|
|
|
|
parameter["error"] = "文件已存在,请重新命名";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
parameter["response"] = CommonHelper::qstringToUtf8(file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchEditEventModule::sqlcipherDo(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
SqlcipherTool sqliteTool;
|
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
string srcFile = data["srcfile"];
|
|
|
|
|
string dstFile = data["dstfile"];
|
|
|
|
|
string key = data["key"];
|
|
|
|
|
auto type = data["type"];
|
|
|
|
|
if (type == 0)
|
2025-06-23 18:01:09 +08:00
|
|
|
|
{ //加密
|
2025-06-23 10:41:33 +08:00
|
|
|
|
string msg;
|
|
|
|
|
int ret = sqliteTool.encryption(srcFile, dstFile, key, msg);
|
|
|
|
|
if (ret != 0)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
parameter["error"] = "加密失败!请检查文件是否有效";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
parameter["response"]["status"] = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
parameter["response"]["status"] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//解密
|
2025-06-23 10:41:33 +08:00
|
|
|
|
string msg;
|
|
|
|
|
int ret = sqliteTool.decrypt(srcFile, dstFile, key, msg);
|
|
|
|
|
if (ret != 0)
|
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
|
parameter["error"] = "解密失败!请检查文件或密码是否有效";
|
2025-06-23 10:41:33 +08:00
|
|
|
|
parameter["response"]["status"] = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
parameter["response"]["status"] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//保存blob数据到本地文件
|
2025-06-23 10:41:33 +08:00
|
|
|
|
void SearchEditEventModule::saveBlobToFile(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
int tableid = data["tableid"];
|
|
|
|
|
int id = (CommonHelper::utf8ToQString(data["id"])).toInt();
|
2025-06-23 18:01:09 +08:00
|
|
|
|
int colid = data["colid"]; //列的id
|
2025-06-23 10:41:33 +08:00
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//读取该blob数据
|
2025-06-23 10:41:33 +08:00
|
|
|
|
using namespace DBPlatformSpace;
|
|
|
|
|
double* buf = NULL;
|
|
|
|
|
int size = 0;
|
|
|
|
|
M_NormalColumnDAO* curCol = NULL;
|
|
|
|
|
ResultMsg rm = M_NormalColumnDAO::FindByID(colid, curCol);
|
|
|
|
|
M_EntityTableDAO* curTable = NULL;
|
|
|
|
|
rm = M_EntityTableDAO::FindByID(tableid, curTable);
|
|
|
|
|
rm = curTable->getBlobData(curCol, id, buf, size);
|
|
|
|
|
|
|
|
|
|
QByteArray bytes = QByteArray::fromRawData((char*)buf, size);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//根据bytes内容判断所存文件数据为哪种类型
|
2025-06-23 10:41:33 +08:00
|
|
|
|
QString fileType = checkFileType(bytes);
|
|
|
|
|
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//选择新文件全路径
|
|
|
|
|
QString file = QFileDialog::getSaveFileName(nullptr, tr("保存为文件"), "", fileType,NULL, QFileDialog::DontConfirmOverwrite);
|
2025-06-23 10:41:33 +08:00
|
|
|
|
|
|
|
|
|
if (!file.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
QFile sFile(file);
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//以重写、只写方式打开文件(运行到此时,文件已经存在目录中)
|
2025-06-23 10:41:33 +08:00
|
|
|
|
if (!sFile.open(QIODevice::Truncate | QIODevice::WriteOnly ))
|
|
|
|
|
printf("Open jsonfile failed!\n");
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//写入文件内容
|
2025-06-23 10:41:33 +08:00
|
|
|
|
sFile.write((char*)buf, size);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//关闭文件
|
2025-06-23 10:41:33 +08:00
|
|
|
|
sFile.close();
|
|
|
|
|
|
|
|
|
|
parameter["response"] = { {"status",true} };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("exportxmlFile Sendto web.......");
|
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SearchEditEventModule::copyBlobData(json& parameter)
|
|
|
|
|
{
|
|
|
|
|
auto data = parameter["data"];
|
|
|
|
|
int tableid = data["tableid"];
|
|
|
|
|
int srcid = data["srcID"];
|
|
|
|
|
vector<int> cols = data["srcCol"];
|
|
|
|
|
parameter["response"]["retFilePath"] = json::array();
|
|
|
|
|
|
|
|
|
|
using namespace DBPlatformSpace;
|
2025-06-23 18:01:09 +08:00
|
|
|
|
M_NormalColumnDAO* curCol = NULL; //当前列
|
2025-06-23 10:41:33 +08:00
|
|
|
|
M_EntityTableDAO* curTable = NULL;
|
|
|
|
|
ResultMsg rm = M_EntityTableDAO::FindByID(tableid, curTable);
|
|
|
|
|
|
|
|
|
|
for (int curColid : cols)
|
|
|
|
|
{
|
|
|
|
|
json j;
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//读取该行该列的blob数据
|
2025-06-23 10:41:33 +08:00
|
|
|
|
rm = M_NormalColumnDAO::FindByID(curColid, curCol);
|
|
|
|
|
double* buf = NULL;
|
|
|
|
|
int size = 0;
|
|
|
|
|
QByteArray bytes;
|
|
|
|
|
if (srcid == -1)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rm = curTable->getBlobData(curCol, srcid, buf, size);
|
|
|
|
|
bytes = QByteArray::fromRawData((char*)buf, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString tempFilePath = QCoreApplication::applicationDirPath() + "/temp/";
|
|
|
|
|
bool ret = CommonHelper::checkDir(tempFilePath);
|
|
|
|
|
if (ret)
|
|
|
|
|
{
|
|
|
|
|
QString filePath = tempFilePath + buildTmpFileName(checkFileType(bytes), srcid, curColid);
|
|
|
|
|
QFile sFile(filePath);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//以重写、只写方式打开文件(运行到此时,文件已经存在目录中)
|
2025-06-23 10:41:33 +08:00
|
|
|
|
if (!sFile.open(QIODevice::Truncate | QIODevice::WriteOnly))
|
|
|
|
|
printf("Open jsonfile failed!\n");
|
|
|
|
|
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//写入文件内容
|
2025-06-23 10:41:33 +08:00
|
|
|
|
sFile.write((char*)buf, size);
|
2025-06-23 18:01:09 +08:00
|
|
|
|
//关闭文件
|
2025-06-23 10:41:33 +08:00
|
|
|
|
sFile.close();
|
|
|
|
|
|
|
|
|
|
string name = curCol->NameToDAOAttriName(curCol->_name);
|
|
|
|
|
j["col"] = CommonHelper::stringToUtf8(name);
|
|
|
|
|
j["filePath"] = CommonHelper::qstringToUtf8(filePath);
|
|
|
|
|
parameter["response"]["retFilePath"].push_back(j);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|