DPS/DataPlatform/DelByInterface.cpp

159 lines
4.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "DelByInterface.h"
#include "M_DelByInterfaceDAO.h"
#include "DataManager.h"
#include "DataAttribute.h"
DelByInterface::DelByInterface()
{
}
DelByInterface::~DelByInterface()
{
}
void static backupDAOData(DBPlatformSpace::M_DelByInterfaceDAO& src, DBPlatformSpace::M_DelByInterfaceDAO& dst)
{
}
void static restoreData(DBPlatformSpace::M_DelByInterfaceDAO& src, DelByInterface& dst)
{
}
void DelByInterface::loadData(DBPlatformSpace::DAO* pDao)
{
_pDBDAO = pDao;
DBPlatformSpace::M_DelByInterfaceDAO* pDelDAO = dynamic_cast<DBPlatformSpace::M_DelByInterfaceDAO*>(_pDBDAO);
_id = pDelDAO->_ID;
_bExport = pDelDAO->_bExport;
_name = CommonHelper::stringToQstring(pDelDAO->_name);
_description = CommonHelper::stringToQstring(pDelDAO->_description);
_paraList = CommonHelper::stringToQstring(pDelDAO->_paraList);
}
bool DelByInterface::deleteSelf()
{
using namespace DBPlatformSpace;
ResultMsg rm;
M_DelByInterfaceDAO* pDelDao = dynamic_cast<M_DelByInterfaceDAO*>(_pDBDAO);
rm = pDelDao->delself();
if (rm.rCode == 0)
{
LOG(INFO) << CommonHelper::utf8ToStdString("M_FindByInterfaceDAO.save success");
return true;
}
LOG(INFO) << CommonHelper::utf8ToStdString("M_FindByInterfaceDAO.save failed");
LOG(INFO) << rm.rMsg;
return false;
}
void DelByInterface::saveToDao()
{
using namespace DBPlatformSpace;
M_DelByInterfaceDAO* pDao = dynamic_cast<M_DelByInterfaceDAO*>(_pDBDAO);
if (pDao == nullptr)
{
pDao = new M_DelByInterfaceDAO();
_pDBDAO = pDao;
}
pDao->_name = CommonHelper::qstringToStdString(getName());
pDao->_bExport = _bExport;
pDao->_description = CommonHelper::qstringToStdString(_description);
pDao->_paraList = CommonHelper::qstringToStdString(_paraList);
}
bool DelByInterface::saveSelf()
{
using namespace DBPlatformSpace;
ResultMsg rm;
M_DelByInterfaceDAO* pDao = dynamic_cast<M_DelByInterfaceDAO*>(_pDBDAO);
/*±¸·ÝDAOÊý¾Ý*/
M_DelByInterfaceDAO oldDaoData;
backupDAOData(*pDao, oldDaoData);
if (pDao == nullptr)
{
pDao = new M_DelByInterfaceDAO();
}
saveToDao();
rm = pDao->save();
if (rm.rCode == 0)
{
LOG(INFO) << CommonHelper::utf8ToStdString("DelByInterface.save success");
return true;
}
else
{
restoreData(oldDaoData, *this);
LOG(INFO) << CommonHelper::utf8ToStdString("M_FindByInterfaceDAO.save failed");
LOG(INFO) << rm.rMsg;
return false;
}
}
void DelByInterface::toJson(json& jsonObj, bool)
{
jsonObj["id"] = _id;
jsonObj["name"] = CommonHelper::qstringToUtf8(_name);
jsonObj["description"] = CommonHelper::qstringToUtf8(_description);
jsonObj["beExport"] = _bExport == 1 ? true : false;
jsonObj["paramList"] = CommonHelper::qstringToUtf8(_paraList);
}
/*»ñȡеÄÊôÐÔ*/
void DelByInterface::getNewProperty(json& parameter, QVariantMap& valueMap)
{
auto data = parameter["data"];
//½Ó¿ÚÃû³Æ
valueMap.insert("name", CommonHelper::utf8ToQString(data["name"]));
//ÃèÊö
valueMap.insert("description", CommonHelper::utf8ToQString(data["description"]));
//IsExport
if (!data["beExport"].is_null())
{
valueMap.insert("IsExport", (int)(data["beExport"]));
}
//²ÎÊýÁбí
if (!data["paramList"].is_null())
{
valueMap.insert("paralist", CommonHelper::utf8ToQString(data["paramList"]));
}
}
void DelByInterface::setNewData(json& parameter)
{
QVariantMap newValues;
getNewProperty(parameter, newValues);
setProperties(newValues);
}
void DelByInterface::setFileData(FileGenerate* generator, QStringList flag)
{
DataManager& mgr = GetDataRoot();
QStringList para = _paraList.split("#");
QString paraShow;
for (int i = 0; i < para.size(); i++)
{
QString curStr = para.at(i);
int pos = curStr.indexOf(",");
QString right = curStr.right(curStr.size() - pos - 1);
int id = curStr.left(pos).toInt();
//²éÕÒid¶ÔÓ¦µÄÃû³Æ
DataAttribute* pdata = qobject_cast<DataAttribute*>(mgr.findObjectById(DataManager::DataType::dataAttribute, id));
paraShow += (pdata->_strDisplayName + right) + " ";
}
if (flag.size() == 2)
{
generator->interfaceTableData.append(new CCS_Report::CCSModelDataSet(flag[0], flag[1], _name, paraShow, ""));
}
else if (flag.size() == 3)
{
generator->interfaceTableData111.append(new CCS_Report::CCSModelDataSet(flag[0], flag[1], flag[2], _name, paraShow, ""));
}
}