137 lines
3.0 KiB
C++
137 lines
3.0 KiB
C++
#pragma execution_character_set("utf-8")
|
|
|
|
#include "DictData.h"
|
|
#include "M_DictDataDAO.h"
|
|
|
|
DictData::DictData()
|
|
{}
|
|
|
|
DictData::~DictData()
|
|
{}
|
|
|
|
|
|
/*获取新的属性*/
|
|
void DictData::getNewProperty(json& parameter, QVariantMap& valueMap)
|
|
{
|
|
auto data = parameter["data"];
|
|
//名称,内部名称,编号
|
|
valueMap.insert("showName", CommonHelper::utf8ToQString(data["name"]));
|
|
valueMap.insert("innerName", CommonHelper::utf8ToQString(data["innerName"]));
|
|
valueMap.insert("code", int(data["code"]));
|
|
}
|
|
|
|
bool DictData::saveSelf()
|
|
{
|
|
using namespace DBPlatformSpace;
|
|
ResultMsg rm;
|
|
/*将这条项目数据写入数据库*/
|
|
M_DictDataDAO* pDao = dynamic_cast<M_DictDataDAO*>(_pDBDAO);
|
|
/*备份DAO数据*/
|
|
M_DictDataDAO oldDaoData;
|
|
// backupDAOData(*pDao, oldDaoData);
|
|
|
|
saveToDao();
|
|
|
|
rm = pDao->save();
|
|
if (rm.rCode == 0)
|
|
{
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_DictDataDAO.save success");
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_DictDataDAO.save failed");
|
|
LOG(ERROR) << rm.rMsg;
|
|
// restoreData(oldDaoData, *this);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
bool DictData::deleteSelf(QString& msg)
|
|
{
|
|
if (_pDBDAO)
|
|
{
|
|
DBPlatformSpace::ResultMsg rm = _pDBDAO->delself();
|
|
if (rm.rCode == 0)
|
|
{
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_DictDataDAO.delself success");
|
|
if (_parent)
|
|
{
|
|
_parent->deleteChild(_id);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
//_parent为空
|
|
LOG(ERROR) << CommonHelper::utf8ToStdString("DictData::deleteSelf: parent is null");
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("M_DictDataDAO.delself failed");
|
|
LOG(ERROR) << rm.rMsg;
|
|
msg = CommonHelper::stringToQstring(rm.rMsg);
|
|
//数据库删除失败
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//_pDBDAO为空
|
|
return false;
|
|
}
|
|
}
|
|
|
|
void DictData::saveToDao()
|
|
{
|
|
using namespace DBPlatformSpace;
|
|
M_DictDataDAO* pDao = dynamic_cast<M_DictDataDAO*>(_pDBDAO);
|
|
|
|
if (pDao == nullptr)
|
|
{
|
|
pDao = new M_DictDataDAO();
|
|
_pDBDAO = pDao;
|
|
}
|
|
|
|
// pDao->_ID = getID();
|
|
pDao->_code = _code;
|
|
pDao->_internalName = CommonHelper::qstringToStdString(_internalName);
|
|
pDao->_showName = CommonHelper::qstringToStdString(_showName);
|
|
// pDao->_default = _bused;
|
|
}
|
|
|
|
void DictData::setNewData(json& parameter)
|
|
{
|
|
QVariantMap newValues;
|
|
getNewProperty(parameter, newValues);
|
|
setProperties(newValues);
|
|
}
|
|
|
|
void DictData::toJson(json& jsonObj, bool)
|
|
{
|
|
jsonObj["id"] = _id;
|
|
jsonObj["name"] = CommonHelper::qstringToUtf8(_showName);
|
|
jsonObj["innerName"] = CommonHelper::qstringToUtf8(_internalName);
|
|
jsonObj["code"] = _code;
|
|
jsonObj["default"] = CommonHelper::intTobool(_bUsed);
|
|
}
|
|
|
|
void DictData::loadData(DBPlatformSpace::DAO* pDao)
|
|
{
|
|
_pDBDAO = pDao;
|
|
DBPlatformSpace::M_DictDataDAO* pDictDataDAO = dynamic_cast<DBPlatformSpace::M_DictDataDAO*>(_pDBDAO);
|
|
setID(pDictDataDAO->_ID);
|
|
_internalName = CommonHelper::stringToQstring(pDictDataDAO->_internalName);
|
|
_showName = CommonHelper::stringToQstring(pDictDataDAO->_showName);
|
|
_code = pDictDataDAO->_code;
|
|
if (pDictDataDAO->_default == "TRUE")
|
|
{
|
|
_bUsed = true;
|
|
}
|
|
else {
|
|
_bUsed = false;
|
|
}
|
|
|
|
}
|