2514 lines
68 KiB
C++
2514 lines
68 KiB
C++
|
#pragma execution_character_set("utf-8")
|
|||
|
|
|||
|
#include <QCoreApplication>
|
|||
|
#include <QFileDialog>
|
|||
|
#include <QMessageBox>
|
|||
|
#include "global.h"
|
|||
|
#include "DataClass.h"
|
|||
|
#include "M_EntityTableDAO.h" //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
#include "M_FolderDAO.h"
|
|||
|
#include "M_NormalColumnDAO.h"
|
|||
|
#include "M_EntityModelDAO.h"
|
|||
|
#include "DataManager.h"
|
|||
|
#include "DataAttribute.h"
|
|||
|
#include "global.h"
|
|||
|
#include "FindByInterface.h"
|
|||
|
#include "DelByInterface.h"
|
|||
|
#include "M_FindByInterfaceDAO.h"
|
|||
|
#include "M_DelByInterfaceDAO.h"
|
|||
|
#include "DataModelData.h"
|
|||
|
#include "DataPack.h"
|
|||
|
#include "SceneInfo.h"
|
|||
|
#include "M_SceneInfoDAO.h"
|
|||
|
#include "DataRow.h"
|
|||
|
#include < regex >
|
|||
|
#include <QMap>
|
|||
|
|
|||
|
#include"filter.h"
|
|||
|
#include "CodeGenerator.h"
|
|||
|
|
|||
|
//<2F><><EFBFBD>ݱ༭ģ<E0BCAD>飬char*<2A><>double*<2A><><EFBFBD><EFBFBD>
|
|||
|
typedef struct blobData
|
|||
|
{
|
|||
|
DBPlatformSpace::M_NormalColumnDAO* pCol = nullptr;
|
|||
|
QString v;
|
|||
|
int id;
|
|||
|
}CHARDataToSave;
|
|||
|
|
|||
|
|
|||
|
//<2F>ڲ<EFBFBD>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD>ȡҵ<C8A1><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>id,<2C><><EFBFBD><EFBFBD>
|
|||
|
void getTableDataIds(DBPlatformSpace::M_EntityTableDAO* pT, QMap<int ,int >& idmap)
|
|||
|
{
|
|||
|
list<M_NormalColumnDAO*> collist;//<2F><>ͷ<EFBFBD><CDB7>Ϣ
|
|||
|
list<string> valuelist;
|
|||
|
pT->getData(collist,valuelist);
|
|||
|
if (valuelist.size() == 0) return;
|
|||
|
for (auto v : valuelist)
|
|||
|
{
|
|||
|
QString qv = CommonHelper::stringToQstring(v);
|
|||
|
QStringList vl = qv.split("@#@");
|
|||
|
int id = vl.front().toInt();
|
|||
|
idmap.insert(id, 1);
|
|||
|
}
|
|||
|
}
|
|||
|
//<2F>ڲ<EFBFBD>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>id .<2E><><EFBFBD><EFBFBD> -1 û<><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
int getNewId(DBPlatformSpace::M_EntityTableDAO* pT, QMap<int, int > old_Idmap)
|
|||
|
{
|
|||
|
list<M_NormalColumnDAO*> collist;//<2F><>ͷ<EFBFBD><CDB7>Ϣ
|
|||
|
list<string> valuelist;
|
|||
|
pT->getData(collist, valuelist);
|
|||
|
if (valuelist.size() == 0) return -1;
|
|||
|
for (auto v : valuelist)
|
|||
|
{
|
|||
|
QString qv = CommonHelper::stringToQstring(v);
|
|||
|
QStringList vl = qv.split("@#@");
|
|||
|
int id = vl.front().toInt();
|
|||
|
if (!old_Idmap.contains(id))
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊnew
|
|||
|
return id;
|
|||
|
}
|
|||
|
}
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
DataClass::DataClass()
|
|||
|
{
|
|||
|
_baseType = g_TYPE_DATACLASS;
|
|||
|
}
|
|||
|
|
|||
|
DataClass::~DataClass()
|
|||
|
{
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD> <20><>ѯ<EFBFBD>ӿ<EFBFBD>map
|
|||
|
qDeleteAll(_findByMap);
|
|||
|
_findByMap.clear();
|
|||
|
//<2F><><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD>ӿ<EFBFBD>map
|
|||
|
qDeleteAll(_delByMap);
|
|||
|
_delByMap.clear();
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
qDeleteAll(_sceneMap);
|
|||
|
_sceneMap.clear();
|
|||
|
|
|||
|
qDeleteAll(tableData);
|
|||
|
tableData.clear();
|
|||
|
qDeleteAll(filterItems);
|
|||
|
filterItems.clear();
|
|||
|
|
|||
|
//qDeleteAll(_findbyFuncs);
|
|||
|
//_findbyFuncs.clear();
|
|||
|
//qDeleteAll(_delbyFuncs);
|
|||
|
//_delbyFuncs.clear();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
bool static buildRelation(DPData* pMain, DPData* pSub, QString name, int type)
|
|||
|
{
|
|||
|
//<2F><><EFBFBD>Ʊ<EFBFBD>ʶ<EFBFBD><CAB6>CR+<2B><><EFBFBD><EFBFBD>+ID, <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>web<65><62><EFBFBD><EFBFBD>
|
|||
|
DataAttribute* pNewAttribute = new DataAttribute();
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
QString nameFlag = "CR" + pSub->property("name").toString() + "ID";
|
|||
|
pNewAttribute->setName(nameFlag);
|
|||
|
pNewAttribute->setDisplayName(name);
|
|||
|
pNewAttribute->_FKType = type;
|
|||
|
pNewAttribute->_wFkTableID = pSub->_id;
|
|||
|
pNewAttribute->_wDataType = MNORMALCOL_TYPE_INT;
|
|||
|
if (pMain->addChild(pNewAttribute))
|
|||
|
{
|
|||
|
pNewAttribute->_parent = pMain;
|
|||
|
DataManager* pManager = qobject_cast<DataManager*>(pMain->getDataManager());
|
|||
|
pManager->insertDataMap(DataManager::DataType::dataAttribute, pNewAttribute->_id, pNewAttribute);
|
|||
|
return true;
|
|||
|
}
|
|||
|
delete pNewAttribute;
|
|||
|
pNewAttribute = nullptr;
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
bool static buildMNRelationship(DPData* pClass1, DPData* pClass2, QString nameflag1, QString nameflag2, DataClass*& pNewClass)
|
|||
|
{
|
|||
|
// const int RELATED_CLASS = 2;
|
|||
|
// DataManager* pManager = qobject_cast<DataManager*>(pClass1->getDataManager());
|
|||
|
//<2F><>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD>ʶ<EFBFBD>ԡ<EFBFBD>TR_<52><5F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>_<EFBFBD><5F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
QString classNameFlag = "TR_" + pClass1->property("name").toString() + "_" + pClass2->property("name").toString();
|
|||
|
//<2F><>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD>ཨ<EFBFBD><E0BDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>
|
|||
|
pNewClass = new DataClass();
|
|||
|
pNewClass->setdisplayName(classNameFlag);
|
|||
|
pNewClass->setName(classNameFlag);
|
|||
|
pNewClass->_type = g_RELATED_CLASS; //Ϊ<><CEAA>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
if (pClass1->_parent->addChild(pNewClass))
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ݹ<EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>ӵ<EFBFBD>map<61><70>
|
|||
|
DataManager* pManager = qobject_cast<DataManager*>(pClass1->getDataManager());
|
|||
|
pManager->insertDataMap(DataManager::DataType::dataClass, pNewClass->_id, pNewClass);
|
|||
|
//<2F>½<EFBFBD><C2BD><EFBFBD><EFBFBD>ݹ<EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݹ<EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>
|
|||
|
//<2F><><EFBFBD><EFBFBD>1
|
|||
|
DataAttribute* pNewAttribute1 = new DataAttribute();
|
|||
|
QString name1 = "CR" + pClass1->property("name").toString() + "ID";
|
|||
|
pNewAttribute1->setName(name1);
|
|||
|
pNewAttribute1->setDisplayName(nameflag1);
|
|||
|
pNewAttribute1->_wFkTableID = pClass2->_id; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ֵ<EFBFBD><D6B5>
|
|||
|
pNewAttribute1->_wDataType = MNORMALCOL_TYPE_INT;
|
|||
|
pNewAttribute1->_FKType = FK_1N;
|
|||
|
pNewAttribute1->_parent = pNewClass;
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
|
|||
|
if (pNewClass->addChild(pNewAttribute1))
|
|||
|
{
|
|||
|
//<2F>ɹ<EFBFBD>
|
|||
|
pManager->insertDataMap(DataManager::DataType::dataAttribute, pNewAttribute1->_id, pNewAttribute1);
|
|||
|
//<2F><><EFBFBD><EFBFBD>2
|
|||
|
DataAttribute* pNewAttribute2 = new DataAttribute();
|
|||
|
QString name2 = "CR" + pClass2->property("name").toString() + "ID";
|
|||
|
pNewAttribute2->setDisplayName(nameflag2);
|
|||
|
pNewAttribute2->setName(name2);
|
|||
|
pNewAttribute2->_wFkTableID = pClass1->_id;
|
|||
|
pNewAttribute2->_FKType = FK_1N;
|
|||
|
pNewAttribute2->_wDataType = MNORMALCOL_TYPE_INT;
|
|||
|
pNewAttribute2->_parent = pNewClass;
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2
|
|||
|
if (pNewClass->addChild(pNewAttribute2))
|
|||
|
{
|
|||
|
//<2F>ɹ<EFBFBD>
|
|||
|
pManager->insertDataMap(DataManager::DataType::dataAttribute, pNewAttribute2->_id, pNewAttribute2);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//ʧ<><CAA7>:ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1 2<><32>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD>ݹ<EFBFBD>ϵ<EFBFBD><CFB5>
|
|||
|
if (pNewClass->deleteChild(pNewAttribute1->_id))
|
|||
|
{
|
|||
|
delete pNewAttribute1;
|
|||
|
pNewAttribute1 = nullptr;
|
|||
|
}
|
|||
|
if (pNewClass->deleteChild(pNewAttribute2->_id))
|
|||
|
{
|
|||
|
delete pNewAttribute2;
|
|||
|
pNewAttribute2 = nullptr;
|
|||
|
}
|
|||
|
|
|||
|
if (pNewClass->_parent->deleteChild(pNewClass->_id))
|
|||
|
{
|
|||
|
delete pNewClass;
|
|||
|
pNewClass = nullptr;
|
|||
|
}
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//ʧ<><CAA7>:ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1 <20><>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD>ݹ<EFBFBD>ϵ<EFBFBD><CFB5>
|
|||
|
if (pNewClass->deleteChild(pNewAttribute1->_id))
|
|||
|
{
|
|||
|
delete pNewAttribute1;
|
|||
|
pNewAttribute1 = nullptr;
|
|||
|
}
|
|||
|
|
|||
|
if (pNewClass->_parent->deleteChild(pNewClass->_id))
|
|||
|
{
|
|||
|
delete pNewClass;
|
|||
|
pNewClass = nullptr;
|
|||
|
}
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//ʧ<><CAA7>
|
|||
|
delete pNewClass;
|
|||
|
pNewClass = nullptr;
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void static backupDAOData(DBPlatformSpace::M_EntityTableDAO& src, DBPlatformSpace::M_EntityTableDAO& dst)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void static restoreData(DBPlatformSpace::M_EntityTableDAO& src, DataClass& dst)
|
|||
|
{
|
|||
|
//<2F><>Ҫ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|||
|
}
|
|||
|
|
|||
|
/*<2A><>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
void DataClass::removeChildinDPMap()
|
|||
|
{
|
|||
|
DataManager& mgr = GetDataRoot();
|
|||
|
QMap<unsigned int, DPData*>::iterator it = _childrenMap.begin();
|
|||
|
while (it != _childrenMap.end())
|
|||
|
{
|
|||
|
mgr.deleteInDataMap(DataManager::DataType::dataAttribute, (*it)->_id);
|
|||
|
it++;
|
|||
|
}
|
|||
|
QMap<int, SceneInfo*>::iterator it_sc = _sceneMap.begin();
|
|||
|
while (it_sc != _sceneMap.end())
|
|||
|
{
|
|||
|
mgr.deleteInDataMap(DataManager::DataType::scene, (*it_sc)->_id);
|
|||
|
it_sc++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void DataClass::saveToDao()
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
M_EntityTableDAO* pDao = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
|
|||
|
if (pDao == nullptr)
|
|||
|
{
|
|||
|
pDao = new M_EntityTableDAO();
|
|||
|
_pDBDAO = pDao;
|
|||
|
}
|
|||
|
|
|||
|
pDao->_name = CommonHelper::qstringToStdString(getName()); //<2F><><EFBFBD>Ʊ<EFBFBD>ʶ
|
|||
|
pDao->_type = _type;
|
|||
|
pDao->_description = CommonHelper::qstringToStdString(_strDescription);
|
|||
|
pDao->_displayName = CommonHelper::qstringToStdString(_strDisplayName);
|
|||
|
|
|||
|
pDao->_countType = _wCountType;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/*<2A><><EFBFBD>汾<EFBFBD><E6B1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
bool DataClass::saveSelf()
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>*/
|
|||
|
M_EntityTableDAO* pDao = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
/*<2A><><EFBFBD><EFBFBD>DAO<41><4F><EFBFBD><EFBFBD>*/
|
|||
|
M_EntityTableDAO oldDaoData;
|
|||
|
if (pDao == nullptr)
|
|||
|
{
|
|||
|
pDao = new M_EntityTableDAO();
|
|||
|
_pDBDAO = pDao;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
backupDAOData(*pDao, oldDaoData);
|
|||
|
}
|
|||
|
saveToDao();
|
|||
|
rm = pDao->save();
|
|||
|
if (rm.rCode == 0)
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.save success ");
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.save failed ");
|
|||
|
LOG(ERROR) << rm.rMsg;
|
|||
|
restoreData(oldDaoData, *this);
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/*<2A><><EFBFBD><EFBFBD>child<6C><64><EFBFBD><EFBFBD>*/
|
|||
|
bool DataClass::addChild(DPData* pNewData)
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
pNewData->saveToDao();
|
|||
|
M_NormalColumnDAO* pNewDAO = dynamic_cast<M_NormalColumnDAO*>(pNewData->_pDBDAO);
|
|||
|
M_EntityTableDAO* pClassDAO = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
|||
|
DPData* pDataModel = getDataModelOwner();
|
|||
|
M_EntityModelDAO* pModelDAO = dynamic_cast<M_EntityModelDAO*>(pDataModel->_pDBDAO);
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD> addVersion <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>version
|
|||
|
pNewDAO->_addVersion = pModelDAO->_version;
|
|||
|
rm = pClassDAO->addNormalColumnDAO(pModelDAO, pNewDAO);
|
|||
|
if (rm.rCode == 0)
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.addNormalColumnDAO success ");
|
|||
|
QString msg = "DataClass::addChild: NormalColumn:" + QString::number(pNewDAO->_ID) + "--" + CommonHelper::stringToQstring(pNewDAO->_name) + "<EFBFBD>½<EFBFBD><EFBFBD>ɹ<EFBFBD>";
|
|||
|
LOG(INFO) << CommonHelper::qstringToString(msg);
|
|||
|
DataAttribute* pAttribute = (DataAttribute*)pNewData;
|
|||
|
//<2F><><EFBFBD>ص<EFBFBD>id
|
|||
|
pAttribute->_id = pNewDAO->_ID;
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>汾
|
|||
|
pAttribute->_wCreateVersion = pNewDAO->_addVersion;
|
|||
|
//ɾ<><C9BE><EFBFBD>汾
|
|||
|
pAttribute->_wDeleteVersion = pNewDAO->_delVersion;
|
|||
|
pAttribute->_strInternalName = CommonHelper::stringToQstring(pNewDAO->_innerName);
|
|||
|
_childrenMap.insert(pNewData->_id, pNewData);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.addNormalColumnDAO failed ");
|
|||
|
QString msg = "DataClass::addChild: NormalColumn:" + QString::number(pNewDAO->_ID) + "--" + CommonHelper::stringToQstring(pNewDAO->_name) + "<EFBFBD>½<EFBFBD>ʧ<EFBFBD><EFBFBD>";
|
|||
|
LOG(INFO) << CommonHelper::qstringToString(msg);
|
|||
|
msg = "DataClass::" + QString::number(pClassDAO->_ID) + "--" + CommonHelper::stringToQstring(pClassDAO->_name);
|
|||
|
LOG(INFO) << CommonHelper::qstringToString(msg);
|
|||
|
LOG(ERROR) << rm.rMsg;
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/*ɾ<><C9BE>һ<EFBFBD><D2BB>child<6C><64><EFBFBD><EFBFBD>*/
|
|||
|
bool DataClass::deleteChild(unsigned int id)
|
|||
|
{
|
|||
|
if (_childrenMap.remove(id))
|
|||
|
{
|
|||
|
DataManager& dataMgr = GetDataRoot();
|
|||
|
dataMgr.deleteInDataMap(DataManager::DataType::dataAttribute, id);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*<2A><>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD><D0B3><EFBFBD>*/
|
|||
|
void DataClass::removeSceneinDPMap()
|
|||
|
{
|
|||
|
DataManager& mgr = GetDataRoot();
|
|||
|
QMap<int, SceneInfo*>::iterator it = _sceneMap.begin();
|
|||
|
while (it != _sceneMap.end())
|
|||
|
{
|
|||
|
mgr.deleteInDataMap(DataManager::DataType::scene, (*it)->_id);
|
|||
|
it++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/*ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD>id<69><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
bool DataClass::deleteFromModel(QString& result)
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("DataClass::deleteFromModel ");
|
|||
|
// testfun();
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
if (_pDBDAO)
|
|||
|
{
|
|||
|
DPData* pDataModel = getDataModelOwner();
|
|||
|
std::string deletedResult;
|
|||
|
M_EntityModelDAO* pModelDAO = dynamic_cast<M_EntityModelDAO*>(pDataModel->_pDBDAO);
|
|||
|
M_EntityTableDAO* pclassDao = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
ResultMsg rm = pclassDao->delFromEntityModel(pModelDAO, deletedResult);
|
|||
|
if (rm.rCode == 0)
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.delFromEntityModel success ");
|
|||
|
QString msg = "M_EntityTableDAO:" + QString::number(_id) + "--" + _name + "ɾ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>";
|
|||
|
LOG(INFO) << CommonHelper::qstringToString(msg);
|
|||
|
result = CommonHelper::stringToQstring(deletedResult);
|
|||
|
resolveDeleteResult(result);
|
|||
|
if (_parent)
|
|||
|
{
|
|||
|
DataManager& datamgr = GetDataRoot();
|
|||
|
removeChildinDPMap();
|
|||
|
removeSceneinDPMap();
|
|||
|
_parent->deleteChild(_id);
|
|||
|
datamgr.deleteInDataMap(DataManager::DataType::dataClass, _id);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//_parentΪ<74><CEAA>
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.delFromEntityModel failed ");
|
|||
|
LOG(ERROR) << rm.rMsg;
|
|||
|
//<2F><><EFBFBD>ݿ<EFBFBD>ɾ<EFBFBD><C9BE>ʧ<EFBFBD><CAA7>
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//_pDBDAOΪ<4F><CEAA>
|
|||
|
LOG(ERROR) << CommonHelper::utf8ToStdString("_pDBDao is null");
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>*/
|
|||
|
void DataClass::loadData(DBPlatformSpace::DAO* pDao)
|
|||
|
{
|
|||
|
_pDBDAO = pDao;
|
|||
|
DBPlatformSpace::M_EntityTableDAO* pTableDAO = dynamic_cast<DBPlatformSpace::M_EntityTableDAO*>(_pDBDAO);
|
|||
|
setID(pTableDAO->_ID);
|
|||
|
setName(CommonHelper::stringToQstring(pTableDAO->_name));
|
|||
|
setdisplayName(CommonHelper::stringToQstring(pTableDAO->_displayName));
|
|||
|
setDescription(CommonHelper::stringToQstring(pTableDAO->_description));
|
|||
|
setInternalName(CommonHelper::stringToQstring(pTableDAO->_innerName));
|
|||
|
_wCreateVersion = pTableDAO->_addVersion;
|
|||
|
_wDeleteVersion = pTableDAO->_delVersion;
|
|||
|
_wCountType = pTableDAO->_countType;
|
|||
|
_type = pTableDAO->_type;
|
|||
|
_version = pTableDAO->_version;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/*<2A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>²<EFBFBD><C2B2><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
void DataClass::getAllChildren(DPData* pManager)
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
DataManager* pMng = qobject_cast<DataManager*>(pManager);
|
|||
|
list<M_NormalColumnDAO*> attributeDAOList;
|
|||
|
M_EntityTableDAO* pTableDao = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
|||
|
DPData* pDataModel = getDataModelOwner();
|
|||
|
M_EntityModelDAO* pModelDAO = dynamic_cast<M_EntityModelDAO*>(pDataModel->_pDBDAO);
|
|||
|
rm = pTableDao->getNormalColumnDAOList(pModelDAO, attributeDAOList);
|
|||
|
if (rm.rCode != 0)
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.getNormalColumnDAOList failed ");
|
|||
|
LOG(ERROR) << rm.rMsg;
|
|||
|
return;
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.getNormalColumnDAOList success ");
|
|||
|
for (list<M_NormalColumnDAO*>::iterator it = attributeDAOList.begin(); it != attributeDAOList.end(); ++it)
|
|||
|
{
|
|||
|
DataAttribute* pNew = new DataAttribute();
|
|||
|
pNew->loadData(*it);
|
|||
|
int id = (*it)->_ID;
|
|||
|
pNew->_parent = this;
|
|||
|
_childrenMap.insert(id, pNew);
|
|||
|
pMng->insertDataMap(DataManager::DataType::dataAttribute, id, pNew);
|
|||
|
}
|
|||
|
_initAttriute = true;
|
|||
|
}
|
|||
|
|
|||
|
/*<2A><>ȡ<EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
void DataClass::getNewProperty(json& parameter, QVariantMap& valueMap)
|
|||
|
{
|
|||
|
auto data = parameter["data"];
|
|||
|
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
|||
|
valueMap.insert("displayName", CommonHelper::utf8ToQString(data["label"]));
|
|||
|
//<2F><><EFBFBD>Ʊ<EFBFBD>ʶ
|
|||
|
if (!data["name"].is_null())
|
|||
|
{
|
|||
|
valueMap.insert("name", CommonHelper::utf8ToQString(data["name"]));
|
|||
|
}
|
|||
|
//<2F><><EFBFBD><EFBFBD>
|
|||
|
valueMap.insert("description", CommonHelper::utf8ToQString(data["description"]));
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
valueMap.insert("countType", (unsigned int)(data["countType"]));
|
|||
|
}
|
|||
|
|
|||
|
void DataClass::setNewData(json& parameter)
|
|||
|
{
|
|||
|
QVariantMap newValues;
|
|||
|
getNewProperty(parameter, newValues);
|
|||
|
setProperties(newValues);
|
|||
|
}
|
|||
|
|
|||
|
void DataClass::toJson(json& jsonObj, bool recursive)
|
|||
|
{
|
|||
|
jsonObj["id"] = _id;
|
|||
|
jsonObj["label"] = CommonHelper::qstringToUtf8(_strDisplayName);
|
|||
|
jsonObj["name"] = CommonHelper::qstringToUtf8(_name);
|
|||
|
jsonObj["type"] = _type;
|
|||
|
jsonObj["description"] = CommonHelper::qstringToUtf8(_strDescription);
|
|||
|
jsonObj["classType"] = g_TYPE_DATACLASS;
|
|||
|
jsonObj["createVersion"] = _wCreateVersion;
|
|||
|
jsonObj["delVersion"] = _wDeleteVersion;
|
|||
|
jsonObj["innerName"] = CommonHelper::qstringToUtf8(_strInternalName);
|
|||
|
jsonObj["countType"] = _wCountType;
|
|||
|
|
|||
|
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
|
|||
|
M_EntityTableDAO* pTable = static_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
string name = pTable->tableNameToDAOName(pTable->_name);
|
|||
|
_tableName = QString::fromStdString(name);
|
|||
|
jsonObj["tableName"] = CommonHelper::stringToUtf8(name);
|
|||
|
|
|||
|
|
|||
|
if (recursive)
|
|||
|
{
|
|||
|
if (_childrenMap.size() == 0)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
json attributes;
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
QMap<unsigned int, DPData*>::iterator it = _childrenMap.begin();
|
|||
|
while (it != _childrenMap.end())
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣתjson
|
|||
|
json child;
|
|||
|
(*it)->toJson(child);
|
|||
|
attributes.push_back(child);
|
|||
|
it++;
|
|||
|
}
|
|||
|
jsonObj["attributes"] = attributes;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
|||
|
bool DataClass::moveData(json& parameter, DPData* pManager)
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
DataManager* pMng = qobject_cast<DataManager*>(pManager);
|
|||
|
//Ŀ<><C4BF>ģ<EFBFBD><C4A3>
|
|||
|
auto data = parameter["data"];
|
|||
|
int dstPackId = data["parentid"];
|
|||
|
DataPack* pdstPack = qobject_cast<DataPack*>(pMng->findObjectById(DataManager::DataType::dataPack, dstPackId));
|
|||
|
M_FolderDAO* pDstPackDAO = dynamic_cast<M_FolderDAO*>(pdstPack->_pDBDAO);
|
|||
|
if (!pDstPackDAO)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DAO
|
|||
|
M_EntityTableDAO* pClassDAO = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
//<2F>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>DAO
|
|||
|
M_FolderDAO* pfatherPackDAO = dynamic_cast<M_FolderDAO*>(_parent->_pDBDAO);
|
|||
|
//<2F><><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD>Ƴ<EFBFBD>
|
|||
|
rm = pfatherPackDAO->removeM_EntityTableDAO(pClassDAO);
|
|||
|
if (rm.rCode == 0)
|
|||
|
{
|
|||
|
//<2F>Ƴ<EFBFBD><C6B3>ɹ<EFBFBD>
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_FolderDAO.removeM_EntityTableDAO success ");
|
|||
|
//<2F><><EFBFBD><EFBFBD>
|
|||
|
rm = pDstPackDAO->addM_EntityTableDAO(pClassDAO);
|
|||
|
if (rm.rCode == 0)
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_FolderDAO.addM_EntityTableDAO success ");
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>, <20><><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>children<65><6E><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD>
|
|||
|
_parent->_childrenMap.remove(_id);
|
|||
|
//ָ<><D6B8><EFBFBD>µĸ<C2B5><C4B8><EFBFBD>
|
|||
|
_parent = pdstPack;
|
|||
|
pdstPack->_childrenMap.insert(_id, this);
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_FolderDAO.addM_EntityTableDAO failed ");
|
|||
|
LOG(ERROR) << rm.rMsg;
|
|||
|
//<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_FolderDAO.removeM_EntityTableDAO failed ");
|
|||
|
LOG(ERROR) << rm.rMsg;
|
|||
|
//<2F>Ƴ<EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::buildRelationship(DPData* pClass1, DPData* pClass2, QString name1, QString name2, int type, DataClass*& pNewClass)
|
|||
|
{
|
|||
|
switch (type)
|
|||
|
{
|
|||
|
case RELATION_MN:
|
|||
|
return buildMNRelationship(pClass1, pClass2, name1, name2, pNewClass);
|
|||
|
case RELATION_11:
|
|||
|
return buildRelation(pClass1, pClass2, name1, FK_11);
|
|||
|
case RELATION_1N:
|
|||
|
return buildRelation(pClass2, pClass1, name1, FK_1N);
|
|||
|
case RELATION_N1:
|
|||
|
return buildRelation(pClass1, pClass2, name1, FK_1N);
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//ɾ<><C9BE>mn<6D><6E>ϵ
|
|||
|
bool DataClass::deleteMNrealationship(DPData* pClass1, DPData* pClass2, QString& result)
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD>pclass1<73><31><EFBFBD><EFBFBD><EFBFBD>ݹ<EFBFBD>ϵ<EFBFBD>ֱ࣬<E0A3AC><D6B1>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD>༴<EFBFBD><E0BCB4>
|
|||
|
DataClass* pClassA = qobject_cast<DataClass*>(pClass1);
|
|||
|
if (pClassA->_type == g_RELATED_CLASS)
|
|||
|
{
|
|||
|
if (pClassA->deleteFromModel(result))
|
|||
|
{
|
|||
|
result = QString::number(g_TYPE_DATACLASS) + "," + QString::number(pClassA->_id);
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
DataClass* pClassB = qobject_cast<DataClass*>(pClass2);
|
|||
|
if (pClassB->_type == g_RELATED_CLASS)
|
|||
|
{
|
|||
|
if (pClassB->deleteFromModel(result))
|
|||
|
{
|
|||
|
result = QString::number(g_TYPE_DATACLASS) + "," + QString::number(pClassB->_id);
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݹ<EFBFBD>ϵ<EFBFBD>࣬<EFBFBD><E0A3AC><EFBFBD><EFBFBD>false,˵<><CBB5><EFBFBD><EFBFBD>mn<6D><6E>ϵ
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
//result<6C><74><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD>ϵͬʱɾ<CAB1><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
bool DataClass::deleteRelationship(DPData* pClass1, DPData* pClass2, QString& result)
|
|||
|
{ //pclass1<73><31><EFBFBD><EFBFBD><EFBFBD>ࣨ<EFBFBD><E0A3A8><EFBFBD><EFBFBD><EFBFBD>ڸ<EFBFBD><DAB8><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
QString idAndType; // "id,type"
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mn<6D><6E>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݹ<EFBFBD>ϵ<EFBFBD><CFB5>
|
|||
|
if (deleteMNrealationship(pClass1, pClass2, result))
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//<2F><>1:1 1:n n:1 <20><>ϵ
|
|||
|
//ɾ<><C9BE>class1<73><31> <20><><EFBFBD><EFBFBD>class2<73><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
int deleteAttributeId = 0; //Ҫɾ<D2AA><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>id
|
|||
|
QMap<unsigned int, DPData*>::iterator it;
|
|||
|
it = pClass1->_childrenMap.begin();
|
|||
|
while (it != pClass1->_childrenMap.constEnd())
|
|||
|
{
|
|||
|
if ((*it)->property("fkTableId") == pClass2->_id)
|
|||
|
{
|
|||
|
deleteAttributeId = (*it)->_id;
|
|||
|
break;
|
|||
|
}
|
|||
|
++it;
|
|||
|
}
|
|||
|
|
|||
|
if (deleteAttributeId != 0)
|
|||
|
{
|
|||
|
DPData* deleteAttribute = pClass1->_childrenMap.value(deleteAttributeId);
|
|||
|
//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if (deleteAttribute->deleteSelf())
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>id<69>践<EFBFBD>ظ<EFBFBD>web
|
|||
|
idAndType = QString::number(g_TYPE_DATAATTRUBUTE) + "," + QString::number(deleteAttribute->_id);
|
|||
|
result = idAndType;
|
|||
|
delete deleteAttribute;
|
|||
|
deleteAttribute = nullptr;
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>");
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::resolveDeleteResult(QString deletedResult)
|
|||
|
{
|
|||
|
QString msg = "DPData::resolveDeleteResult: " + deletedResult;
|
|||
|
LOG(INFO) << CommonHelper::qstringToString(msg);
|
|||
|
if (deletedResult != "")
|
|||
|
{
|
|||
|
DataManager& dataMgr = GetDataRoot();
|
|||
|
QStringList typeIdlist = deletedResult.split("#");
|
|||
|
for (int i = 0; i < typeIdlist.size(); i++)
|
|||
|
{
|
|||
|
QString typeId = typeIdlist.at(i);
|
|||
|
int pos = typeId.indexOf(",");
|
|||
|
int type = typeId.left(pos).toInt();
|
|||
|
int id = typeId.right(typeId.size() - 1 - pos).toInt();
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if (type == g_TYPE_DATAATTRUBUTE)
|
|||
|
{
|
|||
|
DataAttribute* pAttribute = qobject_cast<DataAttribute*>(dataMgr.findObjectById(DataManager::DataType::dataAttribute, id));
|
|||
|
if (pAttribute->deleteSelf())
|
|||
|
{
|
|||
|
// pAttribute->_parent->deleteChild(id);
|
|||
|
// dataMgr.deleteInDataMap(DataManager::DataType::dataAttribute, id);
|
|||
|
delete pAttribute;
|
|||
|
pAttribute = nullptr;
|
|||
|
}
|
|||
|
}
|
|||
|
else if (type == g_TYPE_DATACLASS)
|
|||
|
{
|
|||
|
DataClass* pClass = qobject_cast<DataClass*>(dataMgr.findObjectById(DataManager::DataType::dataClass, id));
|
|||
|
QString str;
|
|||
|
if (pClass->deleteFromModel(str))
|
|||
|
{
|
|||
|
// pClass->_parent->deleteChild(id);
|
|||
|
// dataMgr.deleteInDataMap(DataManager::DataType::dataClass, id);
|
|||
|
delete pClass;
|
|||
|
pClass = nullptr;
|
|||
|
}
|
|||
|
}
|
|||
|
else if (type == g_TYPE_SCENEINFO)
|
|||
|
{
|
|||
|
SceneInfo* pScene = qobject_cast<SceneInfo*>(dataMgr.findObjectById(DataManager::DataType::scene, id));
|
|||
|
if (pScene)
|
|||
|
{
|
|||
|
if (pScene->deleteSelf())
|
|||
|
{
|
|||
|
if (pScene->_parentType == g_TYPE_DATACLASS)
|
|||
|
{
|
|||
|
DataClass* pClass = qobject_cast<DataClass*>(pScene->_parent);
|
|||
|
pClass->_sceneMap.remove(id);
|
|||
|
}
|
|||
|
else if (pScene->_parentType == g_TYPE_DATAPACK)
|
|||
|
{
|
|||
|
DataPack* pack = qobject_cast<DataPack*>(pScene->_parent);
|
|||
|
pack->_sceneMap.remove(id);
|
|||
|
}
|
|||
|
dataMgr.deleteInDataMap(DataManager::DataType::scene, id);
|
|||
|
delete pScene;
|
|||
|
pScene = nullptr;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
void DataClass::dictToJson(json& jsonObj)
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
jsonObj = json::array();
|
|||
|
//<2F><>ȡ<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
list<M_NormalColumnDAO*> headlist;//<2F><>ͷ<EFBFBD><CDB7>Ϣ
|
|||
|
list<string> valuelist; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ӿڻ<D3BF>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
M_EntityTableDAO* pTable = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
rm = pTable->exportData(headlist, valuelist);
|
|||
|
if (rm.rCode != 0)
|
|||
|
{
|
|||
|
if (rm.rMsg != "δ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("dictToJson:M_EntityTableDAO.exportData failed");
|
|||
|
LOG(INFO) << rm.rMsg;
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("dictToJson:M_EntityTableDAO.exportData success");
|
|||
|
if (valuelist.size() == 0)
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("dictToJson : Dict has no data ! ");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
list<string>::iterator value_it = valuelist.begin();
|
|||
|
while (value_it != valuelist.end())
|
|||
|
{
|
|||
|
int index = 0;
|
|||
|
QStringList v = CommonHelper::stringToQstring((*value_it)).split("@#@");
|
|||
|
json j;
|
|||
|
list<M_NormalColumnDAO*>::iterator it = headlist.begin();
|
|||
|
while (it != headlist.end())
|
|||
|
{
|
|||
|
string item = (*it)->_name;//<2F><><EFBFBD>Ʊ<EFBFBD>ʶ
|
|||
|
QString value = v.at(index);
|
|||
|
j[item] = CommonHelper::qstringToUtf8(value);
|
|||
|
index++;
|
|||
|
it++;
|
|||
|
}
|
|||
|
jsonObj.push_back(j);
|
|||
|
value_it++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::importDict(QString& retMsg)
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
QList<QStringList> dictionaryData; //<2F><><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
|
|||
|
M_EntityTableDAO* pTableDAO = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
bool hasEmptyCell;
|
|||
|
QString curPath = QCoreApplication::applicationDirPath();
|
|||
|
QString selectDir = QFileDialog::getOpenFileName(nullptr, "ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>", "", "*.xlsx");
|
|||
|
if (!selectDir.isEmpty())
|
|||
|
{
|
|||
|
if (!excel.OpenFile(selectDir))
|
|||
|
{
|
|||
|
QString msg = "DataClass::importDict:<3A><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>" + selectDir + "ʧ<EFBFBD><EFBFBD>";
|
|||
|
LOG(ERROR) << CommonHelper::qstringToString(msg);
|
|||
|
return false;
|
|||
|
}
|
|||
|
if (!excel.readSheetData("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>", dictionaryData, hasEmptyCell))
|
|||
|
{
|
|||
|
retMsg = "<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD><EFBFBD>";
|
|||
|
return false;
|
|||
|
}
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>пյ<D0BF>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if (hasEmptyCell)
|
|||
|
{
|
|||
|
QString dlgTitle = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>ർ<EFBFBD><EFBFBD>";
|
|||
|
QString msgInfo = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><EFBFBD>룿";
|
|||
|
QMessageBox::StandardButton defaultBtn = QMessageBox::NoButton;
|
|||
|
QMessageBox::StandardButton result;
|
|||
|
result = QMessageBox::question(nullptr, dlgTitle, msgInfo, QMessageBox::Yes | QMessageBox::No, defaultBtn);
|
|||
|
if (result == QMessageBox::No)
|
|||
|
{
|
|||
|
retMsg = "";
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
//<2F><> <20><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
|
|||
|
list<M_NormalColumnDAO*> collist;//<2F><>ͷ<EFBFBD><CDB7>Ϣ
|
|||
|
QStringList headlist; //<2F><><EFBFBD>ݿ<EFBFBD><DDBF>еı<D0B5>ͷ<EFBFBD><CDB7>Ϣ
|
|||
|
list<string> valuelist; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1>ͷ list<M_NormalColumnDAO*>
|
|||
|
DataModelData* pModel = qobject_cast<DataModelData*>(getDataModelOwner());
|
|||
|
M_EntityModelDAO* pEntityModel1 = dynamic_cast<M_EntityModelDAO*>(pModel->_pDBDAO);
|
|||
|
|
|||
|
pTableDAO->getNormalColumnDAOList(pEntityModel1, collist);
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>ͷ<EFBFBD><CDB7>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1>Ƚ<EFBFBD>
|
|||
|
list<M_NormalColumnDAO*>::iterator it = collist.begin();
|
|||
|
while (it != collist.end())
|
|||
|
{
|
|||
|
headlist.append(CommonHelper::stringToQstring((*it)->_name));
|
|||
|
it++;
|
|||
|
}
|
|||
|
if (!CommonHelper::compareQStringlist(headlist, dictionaryData[0]))
|
|||
|
{
|
|||
|
//<2F><>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ͬ
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ䵼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><EFBFBD>ͬ");
|
|||
|
retMsg = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ䵼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><EFBFBD>ͬ";
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
for (int i = 1; i < dictionaryData.size(); i++)
|
|||
|
{
|
|||
|
QString data = dictionaryData[i].join("@#@");
|
|||
|
string value = CommonHelper::qstringToStdString(data);
|
|||
|
valuelist.push_back(value);
|
|||
|
}
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
rm = pTableDAO->importData(collist, valuelist);
|
|||
|
if (rm.rCode != 0)
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.importData failed");
|
|||
|
LOG(INFO) << rm.rMsg;
|
|||
|
retMsg = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ䵼<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>";
|
|||
|
return false;
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.importData success");
|
|||
|
}
|
|||
|
catch (exception& e)
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.importData failed");
|
|||
|
retMsg = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ䵼<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>";
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//δѡ<CEB4><D1A1>·<EFBFBD><C2B7>
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("δѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>");
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
/*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>0 <20>ɹ<EFBFBD> 1 ʧ<><CAA7> 2 <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>δָ<CEB4><D6B8>*/
|
|||
|
int DataClass::exportTemplate()
|
|||
|
{
|
|||
|
QList<QStringList> tableValue; //<2F><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
QStringList headstr;
|
|||
|
|
|||
|
QString file = QFileDialog::getSaveFileName(nullptr, tr("<EFBFBD><EFBFBD><EFBFBD>浼<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>"), "", tr("*.xlsx"));
|
|||
|
|
|||
|
if (file.isEmpty())
|
|||
|
{
|
|||
|
// LOG(INFO) << CommonHelper::utf8ToStdString(" <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>δָ<CEB4><D6B8><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
return 2;
|
|||
|
}
|
|||
|
|
|||
|
QFileInfo openfile(file);
|
|||
|
if (openfile.isFile())
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ڣ<EFBFBD>
|
|||
|
if (excel.OpenFile(file))
|
|||
|
{
|
|||
|
excel.clearAllSheet();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return 1;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
excel.clearAllSheet();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
QMap<unsigned int, DPData*>::iterator it = _childrenMap.begin();
|
|||
|
while (it != _childrenMap.end())
|
|||
|
{
|
|||
|
QString name = (*it)->_name;
|
|||
|
headstr.append(name);
|
|||
|
it++;
|
|||
|
}
|
|||
|
tableValue.append(headstr);
|
|||
|
excel.writeSheetData("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>", tableValue);
|
|||
|
excel.saveFile(file);
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::exportDict()
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
list<M_NormalColumnDAO*> headlist;//<2F><>ͷ<EFBFBD><CDB7>Ϣ
|
|||
|
list<string> valuelist; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
QList<QStringList> tableValue; //<2F><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
QStringList headstr;
|
|||
|
list<string>::iterator it_list;
|
|||
|
|
|||
|
QString file = QFileDialog::getSaveFileName(nullptr, tr("<EFBFBD><EFBFBD><EFBFBD>浼<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>"), "", tr("*.xlsx"));
|
|||
|
|
|||
|
if (file.isEmpty())
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>δָ<EFBFBD><EFBFBD>");
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
QFileInfo openfile(file);
|
|||
|
if (openfile.isFile())
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ڣ<EFBFBD>
|
|||
|
if (excel.OpenFile(file))
|
|||
|
{
|
|||
|
excel.clearAllSheet();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
excel.clearAllSheet();
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ӿڻ<D3BF>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
M_EntityTableDAO* pTable = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
rm = pTable->exportData(headlist, valuelist);
|
|||
|
if (rm.rCode != 0)
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.exportData failed");
|
|||
|
LOG(INFO) << rm.rMsg;
|
|||
|
return false;
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.exportData success");
|
|||
|
if (valuelist.size() == 0)
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("exportDict : Dict has no data ! ");
|
|||
|
return false;
|
|||
|
}
|
|||
|
//<2F><>headlistתΪ Qstringlist
|
|||
|
list<M_NormalColumnDAO*>::iterator it;
|
|||
|
for (it = headlist.begin(); it != headlist.end(); it++)
|
|||
|
{
|
|||
|
headstr.append(CommonHelper::stringToQstring((*it)->_name));
|
|||
|
}
|
|||
|
|
|||
|
tableValue.append(headstr);
|
|||
|
for (it_list = valuelist.begin(); it_list != valuelist.end(); it_list++)
|
|||
|
{
|
|||
|
string rowValue = *it_list;
|
|||
|
QStringList value = (CommonHelper::stringToQstring(rowValue)).split("@#@");
|
|||
|
tableValue.append(value);
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>excel<65><6C>
|
|||
|
excel.writeSheetData("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>", tableValue);
|
|||
|
excel.saveFile(file);
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::getFindByInterface()
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
list<M_FindByInterfaceDAO*> findBylist;
|
|||
|
rm = M_FindByInterfaceDAO::FindByT_M_EntityTableID(_id, findBylist);
|
|||
|
// M_EntityTableDAO* p = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
if (rm.rCode == 0)
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_FindByInterfaceDAO.FindByT_M_EntityTableID success");
|
|||
|
if (findBylist.size() > 0)
|
|||
|
{
|
|||
|
qDeleteAll(_findByMap);
|
|||
|
_findByMap.clear();
|
|||
|
}
|
|||
|
for (list<M_FindByInterfaceDAO*>::iterator it = findBylist.begin(); it != findBylist.end(); ++it)
|
|||
|
{
|
|||
|
FindByInterface* pNew = new FindByInterface();
|
|||
|
pNew->loadData(*it);
|
|||
|
_findByMap.insert(pNew->_id, pNew);
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_FindByInterfaceDAO.FindByT_M_EntityTableID failed");
|
|||
|
LOG(INFO) << rm.rMsg;
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::getDelByInterface()
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
list<M_DelByInterfaceDAO*> delByDAOlist;
|
|||
|
// M_EntityTableDAO* p = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
rm = M_DelByInterfaceDAO::FindByT_M_EntityTableID(_id, delByDAOlist);
|
|||
|
if (rm.rCode == 0)
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_DelByInterfaceDAO.FindByT_M_EntityTableID success");
|
|||
|
if (delByDAOlist.size() > 0)
|
|||
|
{
|
|||
|
qDeleteAll(_delByMap);
|
|||
|
_delByMap.clear();
|
|||
|
}
|
|||
|
for (list<M_DelByInterfaceDAO*>::iterator it = delByDAOlist.begin(); it != delByDAOlist.end(); ++it)
|
|||
|
{
|
|||
|
DelByInterface* pNew = new DelByInterface();
|
|||
|
pNew->loadData(*it);
|
|||
|
_delByMap.insert(pNew->_id, pNew);
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_DelByInterfaceDAO.FindByT_M_EntityTableID failed");
|
|||
|
LOG(INFO) << rm.rMsg;
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::addFindByInterface(FindByInterface* pNew)
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
M_EntityTableDAO* ptableDAO = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
pNew->saveToDao();
|
|||
|
M_FindByInterfaceDAO* pFindByDao = dynamic_cast<M_FindByInterfaceDAO*>(pNew->_pDBDAO);
|
|||
|
|
|||
|
rm = ptableDAO->addFindByInterfaceDAO(pFindByDao);
|
|||
|
if (rm.rCode == 0)
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.addFindByInterfaceDAO success");
|
|||
|
pNew->_id = pFindByDao->_ID;
|
|||
|
_findByMap.insert(pNew->_id, pNew);
|
|||
|
return true;
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.addFindByInterfaceDAO failed");
|
|||
|
LOG(INFO) << rm.rMsg;
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::delFindByInterfaceById(int id)
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
FindByInterface* pdata = _findByMap.value(id);
|
|||
|
if (pdata->deleteSelf())
|
|||
|
{
|
|||
|
//ɾ<><C9BE>findby<62>ӿڳɹ<DAB3><C9B9><EFBFBD><EFBFBD><EFBFBD>findbylist<73><74>ɾ<EFBFBD><C9BE>
|
|||
|
_findByMap.remove(id);
|
|||
|
delete pdata;
|
|||
|
pdata = nullptr;
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::updateFindByInterfaceById(json& parameter)
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
auto data = parameter["data"];
|
|||
|
int id = data["id"];
|
|||
|
|
|||
|
FindByInterface* pdata = _findByMap.value(id);
|
|||
|
pdata->setNewData(parameter);
|
|||
|
|
|||
|
if (pdata->saveSelf())
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//<2F>IJ<DEB8>ѯ<EFBFBD>ӿ<EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
bool DataClass::addDelByInterface(DelByInterface* pNew)
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
M_EntityTableDAO* ptableDAO = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
pNew->saveToDao();
|
|||
|
M_DelByInterfaceDAO* pDelByDao = dynamic_cast<M_DelByInterfaceDAO*>(pNew->_pDBDAO);
|
|||
|
|
|||
|
rm = ptableDAO->addDelByInterfaceDAO(pDelByDao);
|
|||
|
if (rm.rCode == 0)
|
|||
|
{
|
|||
|
pNew->_id = pDelByDao->_ID;
|
|||
|
_delByMap.insert(pNew->_id, pNew);
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_DelByInterfaceDAO.addDelByInterfaceDAO success");
|
|||
|
return true;
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_DelByInterfaceDAO.addDelByInterfaceDAO failed");
|
|||
|
LOG(INFO) << rm.rMsg;
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::delDelByInterfaceById(int id)
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
DelByInterface* pdata = _delByMap.value(id);
|
|||
|
if (pdata->deleteSelf())
|
|||
|
{
|
|||
|
//ɾ<><C9BE>delby<62>ӿڳɹ<DAB3><C9B9><EFBFBD><EFBFBD><EFBFBD>findbylist<73><74>ɾ<EFBFBD><C9BE>
|
|||
|
_delByMap.remove(id);
|
|||
|
delete pdata;
|
|||
|
pdata = nullptr;
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::updateDelByInterfaceById(json& parameter)
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
auto data = parameter["data"];
|
|||
|
int id = data["id"];
|
|||
|
|
|||
|
DelByInterface* pdata = _delByMap.value(id);
|
|||
|
pdata->setNewData(parameter);
|
|||
|
if (pdata->saveSelf())
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//<2F>Ľӿ<C4BD>ʧ<EFBFBD><CAA7>
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::addScene(DPData* pNew)
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
SceneInfo* pScene = qobject_cast<SceneInfo*>(pNew);
|
|||
|
DPData* pModel = getDataModelOwner();
|
|||
|
M_EntityModelDAO* pModelDao = nullptr;
|
|||
|
if (pModel)
|
|||
|
{
|
|||
|
pModelDao = dynamic_cast<M_EntityModelDAO*>(pModel->_pDBDAO);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LOG(ERROR) << CommonHelper::utf8ToStdString("can't find datamodelOwner");
|
|||
|
return false;
|
|||
|
}
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
|
|||
|
M_EntityTableDAO* pClassDao = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
pScene->saveToDao();
|
|||
|
M_SceneInfoDAO* pSceneDao = dynamic_cast<M_SceneInfoDAO*>(pScene->_pDBDAO);
|
|||
|
rm = pClassDao->addSceneInfo(pModelDao, pSceneDao);
|
|||
|
if (rm.rCode == 0)
|
|||
|
{
|
|||
|
pScene->_id = pSceneDao->_ID;
|
|||
|
pScene->_parentId = pSceneDao->_parentID;
|
|||
|
pScene->_parent = this;
|
|||
|
_sceneMap.insert(pScene->_id, pScene);
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.addSceneInfo success");
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.addSceneInfo failed");
|
|||
|
LOG(INFO) << rm.rMsg;
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::deleteScene(int id)
|
|||
|
{
|
|||
|
_sceneMap.remove(id);
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
//bool DataClass::moveScene(json& parameter)
|
|||
|
//{
|
|||
|
// return true;
|
|||
|
//}
|
|||
|
|
|||
|
bool DataClass::getScene(DPData* pMng)
|
|||
|
{
|
|||
|
DataManager* pManager = qobject_cast<DataManager*>(pMng);
|
|||
|
//<2F><>ȡ
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
list<M_SceneInfoDAO*> sceneList;
|
|||
|
DPData* pModel = getDataModelOwner();
|
|||
|
M_EntityModelDAO* pModelDao = nullptr;
|
|||
|
if (pModel)
|
|||
|
{
|
|||
|
pModelDao = dynamic_cast<M_EntityModelDAO*>(pModel->_pDBDAO);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LOG(ERROR) << CommonHelper::utf8ToStdString("can't find datamodelOwner");
|
|||
|
return false;
|
|||
|
}
|
|||
|
M_EntityTableDAO* pClassDao = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
|
|||
|
rm = pClassDao->getSceneInfoList(pModelDao, sceneList);
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>߲<EFBFBD><DFB2>ȣ<EFBFBD><C8A3><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>,<2C>Է<EFBFBD><D4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿⲻһ<E2B2BB><D2BB>
|
|||
|
if (sceneList.size() != _sceneMap.size())
|
|||
|
{
|
|||
|
qDeleteAll(_sceneMap);
|
|||
|
_sceneMap.clear();
|
|||
|
}
|
|||
|
if (rm.rCode == 0)
|
|||
|
{
|
|||
|
for (list<M_SceneInfoDAO*>::iterator it = sceneList.begin(); it != sceneList.end(); ++it)
|
|||
|
{
|
|||
|
SceneInfo* pScene;
|
|||
|
if (_sceneMap.contains((*it)->_ID))
|
|||
|
{
|
|||
|
//ȷ<><C8B7>ͳһ<CDB3><D2BB><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD><EFBFBD>ݿ⸲<DDBF><E2B8B2>
|
|||
|
pScene = _sceneMap.value((*it)->_ID);
|
|||
|
pScene->loadData(*it);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
pScene = new SceneInfo();
|
|||
|
pScene->loadData(*it);
|
|||
|
pScene->_parent = this;
|
|||
|
_sceneMap.insert(pScene->_id, pScene);
|
|||
|
pManager->insertDataMap(DataManager::DataType::scene, pScene->_id, pScene);
|
|||
|
}
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.getSceneInfoList success");
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.getSceneInfoList failed");
|
|||
|
LOG(INFO) << rm.rMsg;
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
QString DataClass::getWhiteBoxType()
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
string whiteBoxStListStr; //<2F>нӿ<D0BD><D3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
M_EntityTableDAO* pClassDao = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
|
|||
|
whiteBoxStListStr = pClassDao->_whiteBoxType;
|
|||
|
|
|||
|
|
|||
|
return CommonHelper::stringToQstring(whiteBoxStListStr);
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::setWhiteBoxType(json& parameter)
|
|||
|
{
|
|||
|
auto data = parameter["data"];
|
|||
|
int code = data["code"];
|
|||
|
bool status = data["status"];
|
|||
|
DBPlatformSpace::M_EntityTableDAO* pClassDao = dynamic_cast<DBPlatformSpace::M_EntityTableDAO*>(_pDBDAO);
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>ġ<EFBFBD>
|
|||
|
QString whiteboxStr = CommonHelper::stringToQstring(pClassDao->_whiteBoxType);
|
|||
|
// if (whiteboxStr.isEmpty())
|
|||
|
// {
|
|||
|
// whiteboxStr = "1:1,2:1,3:1,4:1,5:1,6:1,7:1";
|
|||
|
// }
|
|||
|
int pos = whiteboxStr.indexOf(QString::number(code));
|
|||
|
int st = (status == true) ? 1 : 0;
|
|||
|
whiteboxStr.replace(pos + 2, 1, QString::number(st));
|
|||
|
pClassDao->_whiteBoxType = CommonHelper::qstringToStdString(whiteboxStr);
|
|||
|
DBPlatformSpace::ResultMsg rm = pClassDao->save();
|
|||
|
if (rm.rCode == 0)
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.getSceneInfoList success");
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LOG(ERROR) << CommonHelper::utf8ToStdString("M_EntityTableDAO.getSceneInfoList failed");
|
|||
|
LOG(ERROR) << rm.rMsg;
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>T_<54><5F><EFBFBD>жϵ<D0B6>3λ<33>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA>ĸ
|
|||
|
void DataClass::reName()
|
|||
|
{
|
|||
|
QString head = _name.left(2);
|
|||
|
if (head != "T_")
|
|||
|
{
|
|||
|
_name = "T_" + _name;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
void DataClass::setFileData(FileGenerate* generator, QStringList flag)
|
|||
|
{
|
|||
|
// int pos = flag.size();
|
|||
|
QString chapterName = _strDisplayName + "(" + _name + ")";
|
|||
|
|
|||
|
if (flag.size() == 2)
|
|||
|
{
|
|||
|
//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
generator->classGroupItem.append(new CCS_Report::CCSModelDataSet(flag[0], flag[1]));
|
|||
|
generator->classname.append(new CCS_Report::CCSModelDataSet(flag[0], flag[1], chapterName/*_strDisplayName*/));
|
|||
|
if (_fkTableName.size() > 0)
|
|||
|
{
|
|||
|
for (int i = 0; i < _fkTableName.size(); i++)
|
|||
|
{
|
|||
|
generator->relatTableData.append(new CCS_Report::CCSModelDataSet(flag[0], flag[1], _fkTableName[i], _fkTypeName[i], _relTableName[i]));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else if (flag.size() == 3)
|
|||
|
{
|
|||
|
//<2F>ڶ<EFBFBD><DAB6><EFBFBD>
|
|||
|
generator->classGroupItem111.append(new CCS_Report::CCSModelDataSet(flag[0], flag[1], flag[2]));
|
|||
|
generator->classname5.append(new CCS_Report::CCSModelDataSet(flag[0], flag[1], flag[2], chapterName/*_strDisplayName*/));
|
|||
|
if (_fkTableName.size() > 0)
|
|||
|
{
|
|||
|
for (int i = 0; i < _fkTableName.size(); i++)
|
|||
|
{
|
|||
|
generator->relatTableData111.append(new CCS_Report::CCSModelDataSet(flag[0], flag[1], flag[2], _fkTableName[i], _fkTypeName[i], _relTableName[i]));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (_childrenMap.size() > 0)
|
|||
|
{ //<2F><><EFBFBD><EFBFBD>
|
|||
|
QMap<unsigned int, DPData*>::iterator it = _childrenMap.begin();
|
|||
|
while (it != _childrenMap.end())
|
|||
|
{
|
|||
|
(*it)->setFileData(generator, flag);
|
|||
|
it++;
|
|||
|
}
|
|||
|
}
|
|||
|
if (_findByMap.size() > 0)
|
|||
|
{
|
|||
|
QMap<int, FindByInterface*>::iterator find_it = _findByMap.begin();
|
|||
|
while (find_it != _findByMap.end())
|
|||
|
{
|
|||
|
(*find_it)->setFileData(generator, flag);
|
|||
|
find_it++;
|
|||
|
}
|
|||
|
}
|
|||
|
if (_delByMap.size() > 0)
|
|||
|
{
|
|||
|
QMap<int, DelByInterface*>::iterator del_it = _delByMap.begin();
|
|||
|
while (del_it != _delByMap.end())
|
|||
|
{
|
|||
|
(*del_it)->setFileData(generator, flag);
|
|||
|
del_it++;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//<2F>Ϸ<EFBFBD> true. <20><><EFBFBD>Ϸ<EFBFBD> false
|
|||
|
bool DataClass::checkNameSize(int min, int max, QString& errMsg)
|
|||
|
{
|
|||
|
if (_name.size() >=min && _name.size() <= max )
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
errMsg = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD>ʶ<EFBFBD><EFBFBD><EFBFBD>Ȳ<EFBFBD><EFBFBD>Ϸ<EFBFBD>:" + _name;
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
//<2F>жϵ<D0B6>index+1λ <20>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>true, <20><EFBFBD>false
|
|||
|
bool DataClass::checkLetter(QString& errmsg, int index)
|
|||
|
{
|
|||
|
if (_name.at(index).isLetter())
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
errmsg = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD>ʶ<EFBFBD><EFBFBD>" + QString::number(index + 1) + "λ<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>ĸ<EFBFBD><EFBFBD>" + _name;
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD>, ȫ<><C8AB>Ϊ<EFBFBD>Ϸ<EFBFBD><CFB7>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>true,
|
|||
|
bool DataClass::checkNameillegal(QString& errMsg)
|
|||
|
{
|
|||
|
bool foundmatch = false;
|
|||
|
try {
|
|||
|
std::regex re(R"(^[\w\(\)\[\]\<EFBFBD><EFBFBD>\<EFBFBD><EFBFBD>]+$)");
|
|||
|
foundmatch = std::regex_search(_name.toStdString(), re);
|
|||
|
}
|
|||
|
catch (std::regex_error& e) {
|
|||
|
// Syntax error in the regular expression
|
|||
|
}
|
|||
|
if (foundmatch)
|
|||
|
{//<2F>Ϸ<EFBFBD>
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
errMsg = "<EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD>ʶ " + _name + " <20><><EFBFBD><EFBFBD>Ч<EFBFBD>ַ<EFBFBD>";
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true; //<2F>Ϸ<EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::getAllDataToJson(json& jsonObj)
|
|||
|
{
|
|||
|
qDeleteAll(tableData);
|
|||
|
tableData.clear();
|
|||
|
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
DataManager* pManager = qobject_cast<DataManager*>(getDataManager());
|
|||
|
ResultMsg rm;
|
|||
|
jsonObj = json::array();
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
list<M_NormalColumnDAO*> headlist;//<2F><>ͷ<EFBFBD><CDB7>Ϣ
|
|||
|
list<string> valuelist; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ӿڻ<D3BF>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
M_EntityTableDAO* pTable = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
DataAttribute* pAtt = nullptr;
|
|||
|
|
|||
|
|
|||
|
rm = pTable->getData(headlist, valuelist);
|
|||
|
if (rm.rCode != 0 )
|
|||
|
{
|
|||
|
if (rm.rMsg != "δ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("getData failed");
|
|||
|
LOG(INFO) << rm.rMsg;
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("getData success");
|
|||
|
if (valuelist.size() == 0)
|
|||
|
{
|
|||
|
//û<><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
list<M_NormalColumnDAO*>::iterator it = headlist.begin();
|
|||
|
while (it != headlist.end())
|
|||
|
{
|
|||
|
string item = (*it)->_name;//<2F><><EFBFBD>Ʊ<EFBFBD>ʶ
|
|||
|
if (item != "id")
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD>»<EFBFBD>ȡ<EFBFBD><C8A1>ʾ<EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
|
|||
|
// item = (*it)->_displayName + "_new"; //<2F><>ʱд<CAB1><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
item = (*it)->NameToDAOAttriName((*it)->_name);
|
|||
|
pAtt = qobject_cast<DataAttribute*>(pManager->findObjectById(DataManager::DataType::dataAttribute, (*it)->_ID));
|
|||
|
pAtt->_displayfield = QString::fromStdString(item);
|
|||
|
colType.insert(pAtt->_displayfield, pAtt->_wDataType);
|
|||
|
}
|
|||
|
it++;
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("getAllDataToJson : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> !");
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
list<string>::iterator value_it = valuelist.begin();
|
|||
|
while (value_it != valuelist.end())
|
|||
|
{
|
|||
|
int index = 0;
|
|||
|
DataRow* pDataCol = new DataRow(); //<2F><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
pDataCol->colnum = static_cast<int>(headlist.size());
|
|||
|
QStringList v = CommonHelper::stringToQstring((*value_it)).split("@#@");
|
|||
|
int id = v[0].toInt();//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ϊid
|
|||
|
|
|||
|
json j;
|
|||
|
list<M_NormalColumnDAO*>::iterator it = headlist.begin();
|
|||
|
tableData.append(pDataCol);
|
|||
|
while (it != headlist.end())
|
|||
|
{
|
|||
|
string item = (*it)->_name;//<2F><><EFBFBD>Ʊ<EFBFBD>ʶ
|
|||
|
if (item != "id")
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD>»<EFBFBD>ȡ<EFBFBD><C8A1>ʾ<EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
|
|||
|
// item = (*it)->_displayName + "_new"; //<2F><>ʱд<CAB1><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
item = (*it)->NameToDAOAttriName((*it)->_name);
|
|||
|
pAtt = qobject_cast<DataAttribute*>(pManager->findObjectById(DataManager::DataType::dataAttribute, (*it)->_ID));
|
|||
|
pAtt->_displayfield = QString::fromStdString(item);
|
|||
|
colType.insert(pAtt->_displayfield, pAtt->_wDataType);
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>char*<2A><>double*<2A>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ȡֵ
|
|||
|
QString value;
|
|||
|
if ((*it)->_dataType == MNORMALCOL_TYPE_CHARPTR || (*it)->_dataType == MNORMALCOL_TYPE_DOUBLEPTR)
|
|||
|
{
|
|||
|
double* pData = nullptr;
|
|||
|
int size = 0;
|
|||
|
rm = pTable->getBlobData(*it, id, pData, size);
|
|||
|
if (rm.rCode != 0)
|
|||
|
{
|
|||
|
QString msg = "getBlobData failed. id = " + QString::number(id);
|
|||
|
LOG(INFO) << CommonHelper::qstringToStdString(msg);
|
|||
|
LOG(INFO) << rm.rMsg;
|
|||
|
return false;
|
|||
|
}
|
|||
|
if (size > 0)
|
|||
|
{
|
|||
|
QByteArray bytes( (char*)pData, size);
|
|||
|
//ֻ<><D6BB><EFBFBD><EFBFBD>size
|
|||
|
value = QString("%1 bytes").arg(size);
|
|||
|
//תbase64
|
|||
|
// value = bytes.toBase64();
|
|||
|
//// QByteArray aa = QByteArray::fromBase64(QString(base64).toLocal8Bit());
|
|||
|
// QString retValue = QString::fromLocal8Bit(bytes); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><D6BE>
|
|||
|
// QString msg = "getBlobData from DB : " + retValue + "; id = " + QString::number(id);
|
|||
|
// LOG(INFO) << CommonHelper::qstringToStdString(msg);
|
|||
|
delete[] pData;
|
|||
|
}
|
|||
|
else {
|
|||
|
//size = 0 <20><>
|
|||
|
LOG(INFO) << "getBlob size = 0";
|
|||
|
// QByteArray bytes("NULL");
|
|||
|
// value = bytes.toBase64();
|
|||
|
value = "NULL";
|
|||
|
// QByteArray aa = QByteArray::fromBase64(QString(value).toLocal8Bit());
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
else {
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
value = v.at(index);
|
|||
|
|
|||
|
}
|
|||
|
j[item] = CommonHelper::qstringToUtf8(value);
|
|||
|
pDataCol->colName[index] = QString::fromStdString(item);
|
|||
|
pDataCol->value[index] = value;
|
|||
|
index++;
|
|||
|
it++;
|
|||
|
}
|
|||
|
|
|||
|
jsonObj.push_back(j);
|
|||
|
value_it++;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
/*20240613 <20>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݺϷ<DDBA><CFB7>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>ݡ<EFBFBD>
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>浽<EFBFBD><EFBFBD><EFBFBD>ݿ⣬<EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>id, ij<EFBFBD><EFBFBD>ʧ<EFBFBD>ܻ<EFBFBD><EFBFBD>߳ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>id<EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD>ǰ<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
|
|||
|
bool DataClass::saveTableData(json& jsonObj, DPData* /*pModel*/)
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
auto data = jsonObj["data"];
|
|||
|
auto items = data["items"];
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1>棬<EFBFBD><E6A3AC>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>
|
|||
|
if (items.size() == 0)
|
|||
|
return true;
|
|||
|
//<2F><><EFBFBD>ر<EFBFBD><D8B1><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>ids
|
|||
|
json ids = json::array();
|
|||
|
|
|||
|
//<2F><> <20><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
|
|||
|
list<M_NormalColumnDAO*> collist;//<2F><>ͷ<EFBFBD><CDB7>Ϣ
|
|||
|
list<string> valuelist;
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>base64
|
|||
|
//QString aa = "qwe";
|
|||
|
//QByteArray bytes = aa.toLocal8Bit();
|
|||
|
//QString base64 = bytes.toBase64();
|
|||
|
//QByteArray ab = QByteArray::fromBase64(QString(base64).toLocal8Bit());
|
|||
|
//QString str = QString::fromLocal8Bit(ab);
|
|||
|
|
|||
|
|
|||
|
string value;
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
|
|||
|
M_EntityTableDAO* pTableDAO = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
pTableDAO->getData(collist, valuelist);
|
|||
|
valuelist.clear();
|
|||
|
|
|||
|
DataManager* pManager = qobject_cast<DataManager*>( getDataManager());
|
|||
|
int error = 0; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
list<M_NormalColumnDAO*> collist_to_save;
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>в<EFBFBD><D0B2><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// QMap<string, M_NormalColumnDAO*> displayNameToCol ; //<2F><>ʾ<EFBFBD><CABE>----<2D><>
|
|||
|
for (auto& kv : items)
|
|||
|
{
|
|||
|
list<M_NormalColumnDAO*>::iterator it = collist.begin();
|
|||
|
for (; it != collist.end(); ++it)
|
|||
|
{
|
|||
|
if ((*it)->_name == "id")
|
|||
|
{
|
|||
|
continue;
|
|||
|
}
|
|||
|
DataAttribute* pAtt = qobject_cast<DataAttribute*>(pManager->findObjectById(DataManager::DataType::dataAttribute, (*it)->_ID));
|
|||
|
string key = CommonHelper::qstringToStdString(pAtt->_displayfield);
|
|||
|
string v = CommonHelper::utf8ToStdString(kv[key]);
|
|||
|
// displayNameToCol.insert(key, (*it));
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if (pAtt->_wDataType == MNORMALCOL_TYPE_INT)
|
|||
|
{
|
|||
|
if (0 == atoi(v.c_str()) && v.size() > 1)
|
|||
|
{
|
|||
|
error += 1;
|
|||
|
QString name = CommonHelper::stringToQstring(v);
|
|||
|
// QString str = QString("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ \"%1\" <20><><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD><EFBFBD><EFBFBD>").arg(name);
|
|||
|
json j;
|
|||
|
j["column"] = CommonHelper::stringToUtf8(key);
|
|||
|
j["value"] = CommonHelper::stringToUtf8(v);
|
|||
|
jsonObj["response"]["error"].push_back(j);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (error > 0)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
//2. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
//<2F>Ȼ<EFBFBD>ȡһ<C8A1><D2BB><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>id
|
|||
|
QMap<int, int> oldIds;
|
|||
|
|
|||
|
for (auto& kv : items)
|
|||
|
{
|
|||
|
//<2F><>blob<6F><62><EFBFBD><EFBFBD>
|
|||
|
list<M_NormalColumnDAO*> cols_not_blob;
|
|||
|
list<string> vals_not_blob;
|
|||
|
//blob
|
|||
|
list<M_NormalColumnDAO*> cols_blob;
|
|||
|
QList<CHARDataToSave*> Blob_cols_toWrite; //<2F>豣<EFBFBD><E8B1A3><EFBFBD><EFBFBD>char*<2A><>double*<2A><><EFBFBD><EFBFBD>
|
|||
|
// CHARDataToSave* pBlobData = nullptr;
|
|||
|
QString itemVal;
|
|||
|
QStringList qValue; //ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
int id = (CommonHelper::utf8ToQString(kv["id"])).toInt();
|
|||
|
list<M_NormalColumnDAO*>::iterator it = collist.begin();
|
|||
|
for (; it != collist.end(); ++it)
|
|||
|
{
|
|||
|
itemVal = "";
|
|||
|
if ((*it)->_name == "id")
|
|||
|
{
|
|||
|
itemVal = CommonHelper::stringToQstring(kv["id"]);
|
|||
|
cols_not_blob.push_back((*it));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
DataAttribute* pAtt = qobject_cast<DataAttribute*>(pManager->findObjectById(DataManager::DataType::dataAttribute, (*it)->_ID));
|
|||
|
string key = CommonHelper::qstringToStdString(pAtt->_displayfield);
|
|||
|
string v = CommonHelper::utf8ToStdString(kv[key]);
|
|||
|
//blob<6F><62><EFBFBD><EFBFBD>
|
|||
|
int type = pAtt->_wDataType;
|
|||
|
if (type == MNORMALCOL_TYPE_CHARPTR || type == MNORMALCOL_TYPE_DOUBLEPTR)
|
|||
|
{
|
|||
|
cols_blob.push_back(*it);
|
|||
|
CHARDataToSave* pBlobData = new CHARDataToSave();
|
|||
|
pBlobData->pCol = (*it);
|
|||
|
if (kv[key] == "")
|
|||
|
{
|
|||
|
pBlobData->v = "";
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
pBlobData->v = CommonHelper::utf8ToQString(kv[key]);
|
|||
|
}
|
|||
|
|
|||
|
pBlobData->id = id;
|
|||
|
Blob_cols_toWrite.push_back(pBlobData);
|
|||
|
continue;
|
|||
|
}
|
|||
|
else
|
|||
|
{//<2F><>blob<6F><62><EFBFBD><EFBFBD>
|
|||
|
if (v == "")
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>ֵ
|
|||
|
if (type == MNORMALCOL_TYPE_INT) //<2F><><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
itemVal = "0";
|
|||
|
}
|
|||
|
else if (type == MNORMALCOL_TYPE_STRING)//<2F>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
{
|
|||
|
itemVal = " ";
|
|||
|
}
|
|||
|
else if (type == MNORMALCOL_TYPE_DOUBLE) //ʵ<><CAB5>
|
|||
|
{
|
|||
|
itemVal = "0.0";
|
|||
|
}
|
|||
|
}
|
|||
|
else {
|
|||
|
itemVal = CommonHelper::stringToQstring(v);
|
|||
|
}
|
|||
|
cols_not_blob.push_back((*it));
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
qValue.push_back(itemVal);
|
|||
|
}
|
|||
|
|
|||
|
string value = CommonHelper::qstringToStdString(qValue.join("@#@"));
|
|||
|
vals_not_blob.push_back(value);
|
|||
|
//ÿ<>α<EFBFBD><CEB1><EFBFBD>֮ǰ<D6AE><C7B0>ȡһ<C8A1><D2BB>
|
|||
|
getTableDataIds(pTableDAO, oldIds);
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>blob<6F><62><EFBFBD><EFBFBD>
|
|||
|
ResultMsg rm = pTableDAO->saveData(cols_not_blob, vals_not_blob);
|
|||
|
if (rm.rCode != 0)
|
|||
|
{
|
|||
|
LOG(ERROR) << CommonHelper::utf8ToStdString("DataClass:saveData failed");
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
jsonObj["error"] = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>";
|
|||
|
jsonObj["response"]["returnIDs"] = ids;
|
|||
|
LOG(ERROR) << rm.rMsg;
|
|||
|
return false;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (id == -1)
|
|||
|
{
|
|||
|
int newId = getNewId(pTableDAO, oldIds);
|
|||
|
if (newId != -1)
|
|||
|
{
|
|||
|
ids.push_back(newId);
|
|||
|
id = newId; //<2F><>ǰ<EFBFBD>½<EFBFBD><C2BD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>id
|
|||
|
}
|
|||
|
}
|
|||
|
else {
|
|||
|
ids.push_back(id);
|
|||
|
}
|
|||
|
}
|
|||
|
//<2F><><EFBFBD><EFBFBD>blob<6F><62><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
if (Blob_cols_toWrite.size()>0)
|
|||
|
{
|
|||
|
for (auto clchar : Blob_cols_toWrite)
|
|||
|
{
|
|||
|
if (clchar->v == "")
|
|||
|
{
|
|||
|
delete clchar;
|
|||
|
clchar = nullptr;
|
|||
|
continue;
|
|||
|
}
|
|||
|
int buffsize = 0;
|
|||
|
char* buf = nullptr;
|
|||
|
QByteArray fileData;
|
|||
|
// QByteArray bytesToWrite = QByteArray::fromBase64(clchar->v.toLocal8Bit());
|
|||
|
|
|||
|
//if (bytesToWrite != "NULL" && bytesToWrite != "")
|
|||
|
//{
|
|||
|
// len = bytesToWrite.size();
|
|||
|
// buf = bytesToWrite.data();
|
|||
|
//}
|
|||
|
if (clchar->v != "NULL")
|
|||
|
{
|
|||
|
//˵<><CBB5>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|||
|
QString filename = clchar->v;
|
|||
|
QFile sFile(filename);
|
|||
|
//<2F><>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ļ<EFBFBD><C4BC>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF>У<EFBFBD>
|
|||
|
if (!sFile.open(QIODevice::Truncate | QIODevice::ReadOnly))
|
|||
|
printf("Open file failed!\n");
|
|||
|
QByteArray tep = sFile.readAll();
|
|||
|
buffsize = tep.size();
|
|||
|
fileData = QByteArray::fromRawData(tep, tep.size());
|
|||
|
buf = fileData.data();
|
|||
|
sFile.close();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("DataClass:saveBlobData NULL");
|
|||
|
}
|
|||
|
|
|||
|
if (clchar->id == -1)
|
|||
|
{//<2F><><EFBFBD>»<EFBFBD>ȡid
|
|||
|
clchar->id = id;
|
|||
|
}
|
|||
|
|
|||
|
// QString valuew = QString::fromLocal8Bit(bytesToWrite.toBase64());
|
|||
|
rm = pTableDAO->saveBlobData(clchar->pCol, (double*)buf, buffsize, clchar->id);
|
|||
|
|
|||
|
if (rm.rCode != 0)
|
|||
|
{
|
|||
|
LOG(ERROR) << CommonHelper::utf8ToStdString("DataClass:saveBlobData failed");
|
|||
|
LOG(ERROR) << rm.rMsg;
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|||
|
jsonObj["error"] = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>";
|
|||
|
jsonObj["response"]["returnIDs"] = ids;
|
|||
|
qDeleteAll(Blob_cols_toWrite);
|
|||
|
Blob_cols_toWrite.clear();
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
delete clchar;
|
|||
|
clchar = nullptr;
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("DataClass:saveBlobData success");
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
QString tempFilePath = QCoreApplication::applicationDirPath() + "/temp/";
|
|||
|
CommonHelper::deleteFilesInFolder(tempFilePath);
|
|||
|
jsonObj["response"]["returnIDs"] = ids;
|
|||
|
|
|||
|
return true;
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::delTableData(json& jsonObj)
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
auto data = jsonObj["data"];
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
|
|||
|
M_EntityTableDAO* pTableDAO = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
if (data["items"].size() == 0)
|
|||
|
{
|
|||
|
//ȫɾ<C8AB><C9BE>
|
|||
|
ResultMsg rm = pTableDAO->delAllData();
|
|||
|
if (rm.rCode == 0)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
jsonObj["error"] = "ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>";
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
vector<int> ids = data["items"];
|
|||
|
ResultMsg rm = pTableDAO->delData(ids);
|
|||
|
if (rm.rCode == 0)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
jsonObj["error"] = "ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>";
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
int DataClass::filterData(QString filterStr, json& jsonRet)
|
|||
|
{
|
|||
|
//tableData.clear();
|
|||
|
////<2F><><EFBFBD><EFBFBD>
|
|||
|
//for (int i = 0; i < 10000; i++)
|
|||
|
//{
|
|||
|
// DataRow* pdata = new DataRow();
|
|||
|
// if (pdata)
|
|||
|
// {
|
|||
|
// for (int j = 0; j < 6; j++)
|
|||
|
// {
|
|||
|
// double a = (rand() % (10000 - 6000 + 1) + 6000) / 100.0;
|
|||
|
// pdata->value[j] = QString::number(a);
|
|||
|
//
|
|||
|
// }
|
|||
|
// tableData.append(pdata);
|
|||
|
// }
|
|||
|
//}
|
|||
|
|
|||
|
opStack.clear();
|
|||
|
QStringList filterStrList = filterStr.split("#");
|
|||
|
for (auto str: filterStrList)
|
|||
|
{
|
|||
|
if (str.split(",").size() > 3)
|
|||
|
{
|
|||
|
int pos = str.lastIndexOf(",");
|
|||
|
opStack.push_back(str.left(pos));
|
|||
|
opStack.push_back(str.right(str.length() - pos - 1));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
opStack.push_back(str);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//<2F><><EFBFBD>ṹ()//1 int 2 string 3 double
|
|||
|
//colType.insert("id", 1);
|
|||
|
//colType.insert("proA", 2);
|
|||
|
//colType.insert("proB", 3);
|
|||
|
//colType.insert("proC", 2);
|
|||
|
//colType.insert("proD", 1);
|
|||
|
//colType.insert("proE", 1);
|
|||
|
// colnum = 6;
|
|||
|
|
|||
|
//<2F><>ʼɸѡ
|
|||
|
doFilter(jsonRet);
|
|||
|
|
|||
|
return 1;
|
|||
|
}
|
|||
|
|
|||
|
void DataClass::doFilter( json& jsonRet)
|
|||
|
{
|
|||
|
// long t1 = clock();
|
|||
|
for (int i = 0; i < tableData.size(); i++)
|
|||
|
{
|
|||
|
QStack tpStack = opStack;
|
|||
|
DataRow* pData = tableData[i];
|
|||
|
while (tpStack.size() > 0)
|
|||
|
{
|
|||
|
QString op = tpStack.pop();
|
|||
|
QStringList str = op.split(",");
|
|||
|
if (str.size() >= 3)
|
|||
|
{
|
|||
|
//˵<><CBB5><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
Filter* pFilter = new Filter();
|
|||
|
pFilter->field = str[0];
|
|||
|
pFilter->condition = str[1];
|
|||
|
pFilter->value = str[2];
|
|||
|
bool b = pFilter->checkRow(pData, getFieldType(pFilter->field));
|
|||
|
midResultStack.push_back(b);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//˵<><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӷ<EFBFBD> and or
|
|||
|
if (op == "and")
|
|||
|
{ //<2F><>ȡһ<C8A1><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
op = tpStack.pop();
|
|||
|
Filter* pFilter = new Filter();
|
|||
|
QStringList str = op.split(",");
|
|||
|
pFilter->field = str[0];
|
|||
|
pFilter->condition = str[1];
|
|||
|
pFilter->value = str[2];
|
|||
|
bool b = pFilter->checkRow(pData, getFieldType(pFilter->field));
|
|||
|
bool last = midResultStack.pop();
|
|||
|
midResultStack.push_back(b && last);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//or
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
//<2F>жϸ<D0B6><CFB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
while (midResultStack.size() > 0)
|
|||
|
{//<2F><><EFBFBD><EFBFBD><EFBFBD>涼<EFBFBD><E6B6BC>or<6F>Ĺ<EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ϊ true<75><65>Ϊtrue
|
|||
|
if (midResultStack.pop())
|
|||
|
{
|
|||
|
json j;
|
|||
|
pData->toJson(j);
|
|||
|
jsonRet.push_back(j);
|
|||
|
midResultStack.clear();
|
|||
|
continue;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
//long t2 = clock();
|
|||
|
//int t = t2 - t1;
|
|||
|
}
|
|||
|
|
|||
|
int DataClass::getFieldType(QString fieldname)
|
|||
|
{
|
|||
|
//if (!_initAttriute)
|
|||
|
// getAllChildren(pDManager);
|
|||
|
|
|||
|
//for (auto child : _childrenMap)
|
|||
|
//{
|
|||
|
// if (QString::compare(fieldname, child->_name) == 0)
|
|||
|
// {
|
|||
|
// DataAttribute* pAtt = qobject_cast<DataAttribute*>(child);
|
|||
|
// return pAtt->_wDataType;
|
|||
|
// }
|
|||
|
//}
|
|||
|
if (colType.contains(fieldname))
|
|||
|
return colType[fieldname];
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
bool DataClass::generateCode(QStringList& qfileList)
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>б<EFBFBD><D0B1><EFBFBD>
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
ResultMsg rm;
|
|||
|
SysManager& sysMgr = GetSysManager();
|
|||
|
QString codeFileFolderPath = sysMgr._codeGeneratePath;
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|||
|
codeFileFolderPath += "/C++/";
|
|||
|
list<string> fileList;
|
|||
|
DataModelData* pModel = qobject_cast<DataModelData*>(getDataModelOwner());
|
|||
|
M_EntityModelDAO* pModelDao = dynamic_cast<M_EntityModelDAO*>(pModel->_pDBDAO);
|
|||
|
M_EntityTableDAO* pTablDao = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
rm = pTablDao->CreateCode(pModelDao, CommonHelper::qstringToStdString(codeFileFolderPath), fileList);
|
|||
|
// pTablDao = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
if (rm.rCode == 0)
|
|||
|
{
|
|||
|
for (auto i : fileList)
|
|||
|
{
|
|||
|
qfileList.append(CommonHelper::stringToQstring(i));
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.CreateCode success");
|
|||
|
return true;
|
|||
|
}
|
|||
|
LOG(ERROR) << CommonHelper::utf8ToStdString("DataClass:M_EntityTableDAO.CreateCode failed");
|
|||
|
LOG(ERROR) << rm.rMsg;
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
bool DataClass::generateCSharpCode(QStringList& qfileList)
|
|||
|
{
|
|||
|
using namespace DBPlatformSpace;
|
|||
|
|
|||
|
CodeGenerator generator;
|
|||
|
SysManager& sysMgr = GetSysManager();
|
|||
|
QString codeFileFolderPath = sysMgr._codeGeneratePath;
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
|
|||
|
codeFileFolderPath += "/NET/";
|
|||
|
//<2F><>ǰģ<C7B0><C4A3>
|
|||
|
DataModelData* pModel = qobject_cast<DataModelData*>(getDataModelOwner());
|
|||
|
M_EntityModelDAO* pModelDao = dynamic_cast<M_EntityModelDAO*>(pModel->_pDBDAO);
|
|||
|
//<2F><>ǰTable
|
|||
|
M_EntityTableDAO* pTablDao = dynamic_cast<M_EntityTableDAO*>(_pDBDAO);
|
|||
|
|
|||
|
ResultMsg rm;
|
|||
|
list<string> fileList;
|
|||
|
rm = generator.generateCSharpCode(pTablDao, pModelDao, CommonHelper::qstringToStdString(codeFileFolderPath), fileList);
|
|||
|
|
|||
|
if (rm.rCode == 0)
|
|||
|
{
|
|||
|
for (auto i : fileList)
|
|||
|
{
|
|||
|
qfileList.append(CommonHelper::stringToQstring(i));
|
|||
|
}
|
|||
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_EntityTableDAO.generateCSharpCode success");
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
LOG(ERROR) << CommonHelper::utf8ToStdString("DataClass:M_EntityTableDAO.generateCSharpCode failed");
|
|||
|
LOG(ERROR) << rm.rMsg;
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
//bool DataClass::generateHeadfile(QString& filename,QString path)
|
|||
|
//{
|
|||
|
// QString fileDao = getCodeFileName();
|
|||
|
// filename = path + fileDao + "Wrapper.h";
|
|||
|
// QFile hfile(filename);
|
|||
|
// if (!hfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|||
|
// return -1;
|
|||
|
// }
|
|||
|
// QString content;
|
|||
|
// content += "#pragma once";
|
|||
|
// content += "\n";
|
|||
|
// content += "#include \"common.h\"\n";
|
|||
|
// content += "#include \"" + fileDao + ".h\"";
|
|||
|
// content += "\n";
|
|||
|
// content += "#include \"DAOWrapper.h\"";
|
|||
|
// content += "\n";
|
|||
|
// content += "using namespace System;\n";
|
|||
|
// content += "using namespace System::Collections::Generic;\n";
|
|||
|
// content += "using namespace DBPlatformSpace;\n";
|
|||
|
// content += "\n";
|
|||
|
// content += "namespace clrDBwrapper { \n";
|
|||
|
// content += QString(" public ref class %1Wrapper:public DAOWrapper\n").arg(fileDao);
|
|||
|
// content += " {\n";
|
|||
|
// content += " public:\n";
|
|||
|
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// //ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD>FindBy<42><79><EFBFBD><EFBFBD>
|
|||
|
// for(const auto key:_childrenMap.keys())
|
|||
|
// {
|
|||
|
// DataAttribute* pA = qobject_cast<DataAttribute*>(_childrenMap.value(key));
|
|||
|
// QString type;
|
|||
|
// QString value;
|
|||
|
// string sname = pA->_pDBDAO->_name;
|
|||
|
// QString name = CommonHelper::stringToQstring(DBPlatformSpace::M_NormalColumnDAO::NameToDAOAttriName(sname));
|
|||
|
//
|
|||
|
// if(pA->_wDataType == 1)
|
|||
|
// {//<2F><><EFBFBD><EFBFBD>
|
|||
|
// type = "int";
|
|||
|
// value = "0";
|
|||
|
// }
|
|||
|
// else if(pA->_wDataType == 2)
|
|||
|
// {//<2F>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
// type = "String^";
|
|||
|
// value = "\"\"";
|
|||
|
// }
|
|||
|
// else if(pA->_wDataType == 3)
|
|||
|
// {
|
|||
|
// type = "double";
|
|||
|
// value = "0.0";
|
|||
|
// }
|
|||
|
// content += QString(" %1 %2 = %3; //%4\n").arg(type).arg(name).arg(value).arg(pA->_strDisplayName);
|
|||
|
//
|
|||
|
// //<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// if (pA->_wIsFindKey)
|
|||
|
// {
|
|||
|
// ByFunction* pfun = new ByFunction();
|
|||
|
// QString byAttr = name.right(name.size() - 1);
|
|||
|
// QString funcName = "FindBy" + (byAttr[0].toUpper() + byAttr.mid(1));
|
|||
|
//
|
|||
|
// pfun->name = funcName;
|
|||
|
// pfun->paraCount = 1;
|
|||
|
// pfun->paraType[0] = pA->_wDataType;
|
|||
|
// pfun->paraName.append(byAttr);
|
|||
|
// QString para = QString("(%1 %2, List<%3Wrapper^>^% pnewlist)").arg(type).arg(byAttr).arg(fileDao);
|
|||
|
// pfun->nameAndParastr = pfun->name + para;
|
|||
|
// _findbyFuncs.append(pfun);
|
|||
|
// }
|
|||
|
//
|
|||
|
// }
|
|||
|
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// content += "\n";
|
|||
|
// content += QString(" %1Wrapper();\n").arg(fileDao);
|
|||
|
// content += QString(" ~%1Wrapper();\n").arg(fileDao);
|
|||
|
// //save<76><65>delself.delAll
|
|||
|
// content += "\n";
|
|||
|
// content += " RMWrapper^ save() ;\n";
|
|||
|
// content += " RMWrapper^ delself() ;\n";
|
|||
|
// content += " RMWrapper^ delAll() ;\n";
|
|||
|
//
|
|||
|
// //<2F>̶<EFBFBD><CCB6><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>
|
|||
|
// content += "\n";
|
|||
|
// content += QString(" static RMWrapper^ FindAll(List<%1Wrapper^>^% pnewlist);\n").arg(fileDao);
|
|||
|
// content += QString(" static RMWrapper^ FindByID(int id, %1Wrapper^% pnewdao);\n").arg(fileDao);
|
|||
|
//
|
|||
|
// ////<2F><><EFBFBD>õ<EFBFBD>findby<62><79><EFBFBD><EFBFBD>
|
|||
|
// //_findbyFuncs.clear();
|
|||
|
// //_findbyParas.clear();
|
|||
|
// //<2F><>ѯ<EFBFBD><D1AF><EFBFBD>к<EFBFBD><D0BA><EFBFBD>
|
|||
|
// for (int i = 0; i < _findbyFuncs.size(); i++)
|
|||
|
// {
|
|||
|
// ByFunction* pf = _findbyFuncs[i];
|
|||
|
// content += QString(" static RMWrapper^ %1;\n").arg(pf->nameAndParastr);
|
|||
|
// }
|
|||
|
//
|
|||
|
// //ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õĽӿ<C4BD>
|
|||
|
// for (const auto key : _findByMap.keys())
|
|||
|
// {
|
|||
|
// FindByInterface* pFb = qobject_cast<FindByInterface*>(_findByMap.value(key));
|
|||
|
// ByFunction* pfun = new ByFunction();
|
|||
|
// pfun->name = pFb->_name; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// QStringList parals = pFb->_paraList.split("#");
|
|||
|
//
|
|||
|
// QStringList funPara;
|
|||
|
// //QStringList callPara;
|
|||
|
//
|
|||
|
// for (int i = 0; i< parals.size(); i++)
|
|||
|
// {
|
|||
|
// pfun->paraCount += 1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// QStringList para = parals[i].split(",");
|
|||
|
// int attId = para.at(0).toInt(); //<2F><><EFBFBD><EFBFBD>id
|
|||
|
// DataAttribute* pA = qobject_cast<DataAttribute*>(getAttributeById(attId));
|
|||
|
// pfun->paraType[i] = pA->_wDataType;
|
|||
|
// pfun->paraName.append(pA->_name.toLower());
|
|||
|
//
|
|||
|
// //<2F><><EFBFBD><EFBFBD>
|
|||
|
// if (pA->_wDataType == 1)
|
|||
|
// {
|
|||
|
// funPara.push_back(QString("int %1").arg(pA->_name.toLower()));
|
|||
|
// }
|
|||
|
// else if (pA->_wDataType == 2) //<2F>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
// {
|
|||
|
// funPara.push_back(QString("String^ %1").arg(pA->_name.toLower()));
|
|||
|
// }
|
|||
|
// else if (pA->_wDataType == 3)
|
|||
|
// {
|
|||
|
// funPara.push_back(QString("double %1").arg(pA->_name.toLower()));
|
|||
|
// }
|
|||
|
// }
|
|||
|
// funPara.push_back(QString("List<%1Wrapper^>^% pnewlist").arg(fileDao));
|
|||
|
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// content += "\n";
|
|||
|
// QString para = QString("(%2)").arg(funPara.join(", "));
|
|||
|
// pfun->nameAndParastr = pfun->name + para;
|
|||
|
// _findbyFuncs.append(pfun);
|
|||
|
// // content += QString(" static RMWrapper %1(%2);\n").arg(funName).arg(funPara.join(", "));
|
|||
|
// content += QString(" static RMWrapper^ %1;\n").arg(pfun->nameAndParastr);
|
|||
|
// // _findbyFuncs.append(funcName);
|
|||
|
// // _findbyParas.append(callPara.join(", "));
|
|||
|
// }
|
|||
|
//
|
|||
|
// //<2F><><EFBFBD>õ<EFBFBD>delby<62><79><EFBFBD><EFBFBD>
|
|||
|
//// _delbyFuncs.clear();
|
|||
|
//// _delbyParas.clear();
|
|||
|
// for (const auto key : _delByMap.keys())
|
|||
|
// {
|
|||
|
// DelByInterface* pDb = qobject_cast<DelByInterface*>(_delByMap.value(key));
|
|||
|
// ByFunction* pfun = new ByFunction();
|
|||
|
// pfun->name = pDb->_name; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// QStringList parals = pDb->_paraList.split("#");
|
|||
|
// // QString funName = "DelBy";
|
|||
|
// QStringList funPara;
|
|||
|
// // QStringList callPara;
|
|||
|
// for (int i = 0; i < parals.size(); i++)
|
|||
|
// {
|
|||
|
// pfun->paraCount += 1;
|
|||
|
// QStringList para = parals[i].split(",");
|
|||
|
// int attId = para.at(0).toInt(); //<2F><><EFBFBD><EFBFBD>id
|
|||
|
// DataAttribute* pA = qobject_cast<DataAttribute*>(getAttributeById(attId));
|
|||
|
// pfun->paraType[i] = pA->_wDataType;
|
|||
|
// pfun->paraName.append(pA->_name.toLower());
|
|||
|
//
|
|||
|
// //<2F><><EFBFBD><EFBFBD>
|
|||
|
// if (pA->_wDataType == 1)
|
|||
|
// {
|
|||
|
// funPara.push_back(QString("int %1").arg(pA->_name.toLower()));
|
|||
|
// }
|
|||
|
// else if (pA->_wDataType == 2) //<2F>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
// {
|
|||
|
// funPara.push_back(QString("String^ %1").arg(pA->_name.toLower()));
|
|||
|
// }
|
|||
|
// else if (pA->_wDataType == 3)
|
|||
|
// {
|
|||
|
// funPara.push_back(QString("double %1").arg(pA->_name.toLower()));
|
|||
|
// }
|
|||
|
//
|
|||
|
// }
|
|||
|
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// content += "\n";
|
|||
|
// QString para = QString("(%1)").arg(funPara.join(", "));;
|
|||
|
// pfun->nameAndParastr = pfun->name + para;
|
|||
|
// content += QString(" static RMWrapper^ %1;\n").arg(pfun->nameAndParastr);
|
|||
|
// //_delbyFuncs.append(funcname);
|
|||
|
// //_delbyParas.append(callPara.join(", "));
|
|||
|
// }
|
|||
|
//
|
|||
|
// //˽<><CBBD>dao<61><6F>Ա
|
|||
|
// content += "\n";
|
|||
|
// content += " public:\n";
|
|||
|
// content += QString(" void load();\n");
|
|||
|
// content += QString(" void savetoDao();\n");
|
|||
|
// content += QString(" %1* _pdao = NULL;\n").arg(fileDao);
|
|||
|
//
|
|||
|
// content += " };\n";
|
|||
|
// content += "}\n";
|
|||
|
//
|
|||
|
// hfile.write(content.toStdString().c_str());
|
|||
|
// hfile.close();
|
|||
|
//
|
|||
|
//
|
|||
|
// return true;
|
|||
|
//}
|
|||
|
//
|
|||
|
//bool DataClass::generateSrcfile(QString& filename, QString path)
|
|||
|
//{
|
|||
|
// //.cpp<70>ļ<EFBFBD>
|
|||
|
// QString fileDao = getCodeFileName();
|
|||
|
// filename = path + fileDao + "Wrapper.cpp";
|
|||
|
// QFile srcFile(filename);
|
|||
|
// if (!srcFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|||
|
// return -1;
|
|||
|
// }
|
|||
|
// QString content;
|
|||
|
// content += QString("#include \"%1Wrapper.h\"\n").arg(fileDao);
|
|||
|
// content += QString("#include \"templateFun.h\"\n");
|
|||
|
// content += "using namespace System::Runtime::InteropServices;\n";
|
|||
|
// content += "using namespace clrDBwrapper;\n";
|
|||
|
// //<2F><><EFBFBD>캯<EFBFBD><ECBAAF>
|
|||
|
// content += "\n";
|
|||
|
// content += QString("%1Wrapper::%2Wrapper()\n").arg(fileDao).arg(fileDao);
|
|||
|
// content += "{\n";
|
|||
|
// content += "}\n";
|
|||
|
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
// content += "\n";
|
|||
|
// content += "\n";
|
|||
|
// content += QString("%1Wrapper::~%2Wrapper()\n").arg(fileDao).arg(fileDao);
|
|||
|
// content += "{\n";
|
|||
|
// content += " if (_pdao)\n";
|
|||
|
// content += " {\n";
|
|||
|
// content += QString(" delete _pdao;\n");
|
|||
|
// content += QString(" _pdao = NULL;\n");
|
|||
|
// content += " }\n";
|
|||
|
// content += "}\n";
|
|||
|
// //<2F>̶<EFBFBD>find<6E><64><EFBFBD><EFBFBD>
|
|||
|
// //findAll
|
|||
|
// content += "\n";
|
|||
|
// content += QString("RMWrapper^ %1Wrapper::FindAll(List<%2Wrapper^>^% pnewlist)\n").arg(fileDao).arg(fileDao);
|
|||
|
// content += "{\n";
|
|||
|
// content += QString(" list<%1*> daolist;\n").arg(fileDao);
|
|||
|
// content += QString(" ResultMsg rm = %1::FindAll(daolist);\n").arg(fileDao);
|
|||
|
// content += QString(" copydaolistT<%1,%2Wrapper>(daolist, pnewlist);\n").arg(fileDao).arg(fileDao);
|
|||
|
// content += QString(" RMWrapper^ ret = gcnew RMWrapper(rm.rCode, rm.rMsg);\n");
|
|||
|
// content += QString(" return ret;\n");
|
|||
|
// content += "}\n";
|
|||
|
// //findbyID
|
|||
|
// content += "\n";
|
|||
|
// content += QString("RMWrapper^ %1Wrapper::FindByID(int id, %2Wrapper^% pnewdao)\n").arg(fileDao).arg(fileDao);
|
|||
|
// content += "{\n";
|
|||
|
// content += QString(" return findbyIdT<%1,%2Wrapper>(id,pnewdao);\n").arg(fileDao).arg(fileDao);
|
|||
|
// content += "}\n";
|
|||
|
// //<2F><><EFBFBD><EFBFBD>save/delself/delall<6C><6C><EFBFBD><EFBFBD>
|
|||
|
// generateSaveDelselfFunc(content);
|
|||
|
// //<2F><><EFBFBD>õ<EFBFBD>findby<62><79><EFBFBD><EFBFBD>
|
|||
|
// generateFindbyFunction(content);
|
|||
|
// //<2F><><EFBFBD>õ<EFBFBD>delby<62><79><EFBFBD><EFBFBD>
|
|||
|
// generateDelbyFunction(content);
|
|||
|
// //<2F><><EFBFBD><EFBFBD>load<61><64><EFBFBD><EFBFBD>
|
|||
|
// generateLoadFunc(content);
|
|||
|
// //<2F><><EFBFBD><EFBFBD>savetoDao<61><6F><EFBFBD><EFBFBD>
|
|||
|
// generateSavetoDaoFunc(content);
|
|||
|
//
|
|||
|
// srcFile.write(content.toStdString().c_str());
|
|||
|
// srcFile.close();
|
|||
|
//
|
|||
|
// return true;
|
|||
|
//}
|
|||
|
//
|
|||
|
//void DataClass::generateFindbyFunction(QString& content)
|
|||
|
//{
|
|||
|
// QString fileDao = getCodeFileName();
|
|||
|
//
|
|||
|
// for (int i = 0; i < _findbyFuncs.size(); i++)
|
|||
|
// {
|
|||
|
// content += "\n";
|
|||
|
// ByFunction *pf = _findbyFuncs[i];
|
|||
|
// content += QString("RMWrapper^ %1Wrapper::%2\n").arg(fileDao).arg(pf->nameAndParastr);
|
|||
|
// content += "{\n";
|
|||
|
// content += QString(" list<%1*> daolist;\n").arg(fileDao);
|
|||
|
// //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>string<6E><67><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD>Ҫת<D2AA><D7AA>
|
|||
|
// QStringList callpara;//<2F><><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
// for (int i = 0; i < pf->paraCount; i++)
|
|||
|
// {
|
|||
|
// QString namestring = pf->paraName[i];
|
|||
|
// if (pf->paraType[i] == 2) //<2F>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
// {
|
|||
|
// namestring = QString("str%1").arg(pf->paraName[i]);
|
|||
|
// content += QString(" string %1 = (char*)(Marshal::StringToHGlobalAnsi(%2)).ToPointer();\n").arg(namestring).arg(pf->paraName[i]);
|
|||
|
// }
|
|||
|
// callpara.append(namestring);
|
|||
|
// }
|
|||
|
// //findby<62><79><EFBFBD><EFBFBD>
|
|||
|
// content += QString(" ResultMsg rm = %1::%2(%3,daolist);\n").arg(fileDao).arg(pf->name).arg(callpara.join(","));
|
|||
|
//
|
|||
|
// content += QString(" copydaolistT<%1,%2Wrapper>(daolist, pnewlist);\n").arg(fileDao).arg(fileDao);
|
|||
|
// content += QString(" RMWrapper^ ret = gcnew RMWrapper(rm.rCode, rm.rMsg);\n");
|
|||
|
// content += QString(" return ret;\n");
|
|||
|
// content += "}\n";
|
|||
|
// }
|
|||
|
//
|
|||
|
//}
|
|||
|
//
|
|||
|
//void DataClass::generateDelbyFunction(QString& content)
|
|||
|
//{
|
|||
|
// //QString fileDao = getCodeFileName();
|
|||
|
// //for (int i = 0; i < _delbyFuncs.size(); i++)
|
|||
|
// //{
|
|||
|
// // content += "\n";
|
|||
|
// // content += QString("RMWrapper^ %1Wrapper::%2\n").arg(fileDao).arg(_delbyFuncs[i]);
|
|||
|
// // content += "{\n";
|
|||
|
// // int pos = _delbyFuncs[i].indexOf("(");
|
|||
|
// // QString func = _delbyFuncs[i].left(pos);
|
|||
|
// // content += QString(" ResultMsg rm = %1::%2(%3);\n").arg(fileDao).arg(func).arg(_delbyParas[i]);
|
|||
|
// // content += QString(" RMWrapper^ ret = gcnew RMWrapper(rm.rCode, rm.rMsg);\n");
|
|||
|
// // content += QString(" return ret;\n");
|
|||
|
// // content += "}\n";
|
|||
|
// //}
|
|||
|
//}
|
|||
|
//
|
|||
|
//
|
|||
|
//DPData* DataClass::getAttributeById(int id)
|
|||
|
//{
|
|||
|
// for (const auto key : _childrenMap.keys())
|
|||
|
// {
|
|||
|
// if (_childrenMap.value(key)->_id == id)
|
|||
|
// return _childrenMap.value(key);
|
|||
|
// }
|
|||
|
// return nullptr;
|
|||
|
//}
|
|||
|
//
|
|||
|
////<2F><><EFBFBD><EFBFBD>load<61><64><EFBFBD><EFBFBD>
|
|||
|
//void DataClass::generateLoadFunc(QString& content)
|
|||
|
//{
|
|||
|
// content += "\n";
|
|||
|
// QString fileDao = getCodeFileName();
|
|||
|
// content += QString("void %1Wrapper::load()\n").arg(fileDao);
|
|||
|
// content += "{\n";
|
|||
|
// content += QString(" _id = _pdao->_ID;\n");
|
|||
|
// for (const auto key : _childrenMap.keys())
|
|||
|
// {
|
|||
|
// DataAttribute* pA = qobject_cast<DataAttribute*>(_childrenMap.value(key));
|
|||
|
// string sname = pA->_pDBDAO->_name;
|
|||
|
// QString name = CommonHelper::stringToQstring(DBPlatformSpace::M_NormalColumnDAO::NameToDAOAttriName(sname));
|
|||
|
// if (pA->_wDataType == 2)
|
|||
|
// {
|
|||
|
// //<2F>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
// content += QString(" %1 = gcnew String(_pdao->%2.c_str());\n").arg(name).arg(name);
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// content += QString(" %1 = _pdao->%2;\n").arg(name).arg(name);
|
|||
|
// }
|
|||
|
// }
|
|||
|
// content += "}\n";
|
|||
|
//}
|
|||
|
////<2F><><EFBFBD><EFBFBD>savetoDao<61><6F><EFBFBD><EFBFBD>
|
|||
|
//void DataClass::generateSavetoDaoFunc(QString& content)
|
|||
|
//{
|
|||
|
// content += "\n";
|
|||
|
// QString fileDao = getCodeFileName();
|
|||
|
// content += QString("void %1Wrapper::savetoDao()\n").arg(fileDao);
|
|||
|
// content += "{\n";
|
|||
|
//
|
|||
|
// for (const auto key : _childrenMap.keys())
|
|||
|
// {
|
|||
|
// DataAttribute* pA = qobject_cast<DataAttribute*>(_childrenMap.value(key));
|
|||
|
// string sname = pA->_pDBDAO->_name;
|
|||
|
// QString name = CommonHelper::stringToQstring(DBPlatformSpace::M_NormalColumnDAO::NameToDAOAttriName(sname));
|
|||
|
// if (pA->_wDataType == 2)
|
|||
|
// {
|
|||
|
// //<2F>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
// content += QString(" _pdao->%1 = (char*)(Marshal::StringToHGlobalAnsi(%2)).ToPointer();\n").arg(name).arg(name);
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// content += QString(" _pdao->%1 = this->%2;\n").arg(name).arg(name);
|
|||
|
// }
|
|||
|
// }
|
|||
|
//
|
|||
|
// content += "}\n";
|
|||
|
//}
|
|||
|
//
|
|||
|
//void DataClass::generateSaveDelselfFunc(QString& content)
|
|||
|
//{
|
|||
|
// QString fileDao = getCodeFileName();
|
|||
|
// content += "\n";
|
|||
|
// //save
|
|||
|
// content += QString("RMWrapper^ %1Wrapper::save()\n").arg(fileDao);
|
|||
|
// content += "{\n";
|
|||
|
// content += " if( !_pdao )\n";
|
|||
|
// content += " {\n";
|
|||
|
// content += QString(" _pdao = new %1();\n").arg(fileDao);
|
|||
|
// content += " }\n";
|
|||
|
// //for (const auto key : _childrenMap.keys())
|
|||
|
// //{
|
|||
|
// // DataAttribute* pA = qobject_cast<DataAttribute*>(_childrenMap.value(key));
|
|||
|
// // if (pA->_wDataType == 2)
|
|||
|
// // {
|
|||
|
// // //<2F>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
// // content += QString(" _pdao->_%1 = (char*)(Marshal::StringToHGlobalAnsi(_%3)).ToPointer();\n").arg(pA->_name.at(1).toLower() + pA->_name.right(pA->_name.size() - 2)).arg(pA->_name.at(1).toLower() + pA->_name.right(pA->_name.size() - 2));
|
|||
|
// // }
|
|||
|
// // else
|
|||
|
// // {
|
|||
|
// // content += QString(" _pdao->_%1 = this->_%2;\n").arg(pA->_name.at(1).toLower() + pA->_name.right(pA->_name.size() - 2)).arg(pA->_name.at(1).toLower() + pA->_name.right(pA->_name.size() - 2));
|
|||
|
// // }
|
|||
|
// //}
|
|||
|
// content += QString(" return saveT<%1,%2Wrapper>(_pdao, this);\n").arg(fileDao).arg(fileDao);
|
|||
|
// content += "}\n";
|
|||
|
//
|
|||
|
// //delself
|
|||
|
// content += "\n";
|
|||
|
// content += QString("RMWrapper^ %1Wrapper::delself()\n").arg(fileDao);
|
|||
|
// content += "{\n";
|
|||
|
// content += QString(" return delselfT(_pdao);\n");
|
|||
|
// content += "}\n";
|
|||
|
// //delall
|
|||
|
// content += "\n";
|
|||
|
// content += QString("RMWrapper^ %1Wrapper::delAll()\n").arg(fileDao);
|
|||
|
// content += "{\n";
|
|||
|
// content += QString(" return delAllT(_pdao);\n");
|
|||
|
// content += "}\n";
|
|||
|
//
|
|||
|
//}
|