2025-06-23 10:41:33 +08:00
|
|
|
#include "DictItem.h"
|
|
|
|
#include "M_DictItemDAO.h"
|
|
|
|
#include "M_DictDataDAO.h"
|
|
|
|
#include "DictData.h"
|
|
|
|
|
|
|
|
DictItem::DictItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DictItem::~DictItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DictItem::deleteChild(unsigned int id)
|
|
|
|
{
|
|
|
|
if (_dataMap.remove(id))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DictItem::addChild(DPData* pNewData)
|
|
|
|
{
|
|
|
|
using namespace DBPlatformSpace;
|
|
|
|
ResultMsg rm;
|
|
|
|
M_DictItemDAO* pDictItemDao = dynamic_cast<M_DictItemDAO*>(_pDBDAO);
|
|
|
|
pNewData->saveToDao();
|
|
|
|
M_DictDataDAO* pDictDataDao = dynamic_cast<M_DictDataDAO*>(pNewData->_pDBDAO);
|
|
|
|
rm = pDictItemDao->addDictData(pDictDataDao);
|
|
|
|
if (rm.rCode == 0)
|
|
|
|
{
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_DictItemDAO::addDictData success");
|
|
|
|
pNewData->_id = pDictDataDao->_ID;
|
|
|
|
pNewData->_parent = this;
|
|
|
|
_dataMap.insert(pNewData->_id, qobject_cast<DictData*>(pNewData));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_DictItemDAO::addDictData failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DictItem::loadData(DBPlatformSpace::DAO* pDao)
|
|
|
|
{
|
|
|
|
_pDBDAO = pDao;
|
|
|
|
DBPlatformSpace::M_DictItemDAO* pDictItemDAO = dynamic_cast<DBPlatformSpace::M_DictItemDAO*>(_pDBDAO);
|
|
|
|
setID(pDictItemDAO->_ID);
|
|
|
|
_innerName = CommonHelper::stringToQstring(pDictItemDAO->_innerName);
|
|
|
|
_ItemName = CommonHelper::stringToQstring(pDictItemDAO->_dictName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void DictItem::getAllChildren(DPData*)
|
|
|
|
{
|
|
|
|
using namespace DBPlatformSpace;
|
|
|
|
ResultMsg rm;
|
|
|
|
M_DictItemDAO* pDictItemDao = dynamic_cast<M_DictItemDAO*>(_pDBDAO);
|
|
|
|
list<M_DictDataDAO*> dictDataList;
|
|
|
|
rm = pDictItemDao->getDictDataList(dictDataList);
|
|
|
|
if (rm.rCode == 0)
|
|
|
|
{
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_DictItemDAO::getDictDataList success");
|
|
|
|
for (list<M_DictDataDAO*>::iterator it = dictDataList.begin(); it != dictDataList.end(); it++)
|
|
|
|
{
|
|
|
|
DictData* pDictData;
|
|
|
|
if (_dataMap.contains((*it)->_ID))
|
|
|
|
{
|
2025-06-23 18:01:09 +08:00
|
|
|
//´ÓÊý¾Ý¿â¸²¸Ç
|
2025-06-23 10:41:33 +08:00
|
|
|
pDictData = _dataMap.value((*it)->_ID);
|
|
|
|
pDictData->loadData(*it);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pDictData = new DictData();
|
|
|
|
pDictData->loadData(*it);
|
|
|
|
_dataMap.insert(pDictData->_id, pDictData);
|
|
|
|
pDictData->_parent = this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_DictItemDAO::getDictDataList failed");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DictItem::toJson(json& jsonObj, bool recursive)
|
|
|
|
{
|
|
|
|
jsonObj["id"] = _id;
|
|
|
|
jsonObj["name"] = CommonHelper::qstringToUtf8(_ItemName);
|
|
|
|
jsonObj["innerName"] = CommonHelper::qstringToUtf8(_innerName);
|
|
|
|
jsonObj["default"] = true;
|
|
|
|
jsonObj["code"] = 0;
|
|
|
|
|
|
|
|
if (recursive)
|
|
|
|
{
|
|
|
|
json subData;
|
|
|
|
QMap<int, DictData*>::iterator it = _dataMap.begin();
|
|
|
|
while (it != _dataMap.end())
|
|
|
|
{
|
|
|
|
json child;
|
|
|
|
(*it)->toJson(child);
|
|
|
|
subData.push_back(child);
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
jsonObj["children"] = subData;
|
|
|
|
}
|
|
|
|
}
|