DPS/DataPlatform/FindByInterface.cpp

205 lines
5.7 KiB
C++
Raw Normal View History

2025-06-23 10:41:33 +08:00
#include "FindByInterface.h"
#include "M_FindByInterfaceDAO.h"
#include "DataManager.h"
#include "DataAttribute.h"
FindByInterface::FindByInterface()
{}
FindByInterface::~FindByInterface()
{}
// void static backupDAOData(DBPlatformSpace::M_FindByInterfaceDAO& src, DBPlatformSpace::M_FindByInterfaceDAO& dst)
// {
2025-06-23 10:41:33 +08:00
// }
2025-06-23 10:41:33 +08:00
// void static restoreData(DBPlatformSpace::M_FindByInterfaceDAO& src, FindByInterface& dst)
// {
2025-06-23 10:41:33 +08:00
// }
2025-06-23 10:41:33 +08:00
void FindByInterface::saveToDao()
{
using namespace DBPlatformSpace;
M_FindByInterfaceDAO* pDao = dynamic_cast<M_FindByInterfaceDAO*>(_pDBDAO);
if (pDao == nullptr)
{
pDao = new M_FindByInterfaceDAO();
_pDBDAO = pDao;
}
2025-06-23 18:01:09 +08:00
pDao->_name = CommonHelper::qstringToStdString(getName()); //名称标识
2025-06-23 10:41:33 +08:00
pDao->_type = _interfaceType;
pDao->_sortType = _sortType;
pDao->_description = CommonHelper::qstringToStdString(_description);
pDao->_bExport = _bIsExport;
pDao->_paraList = CommonHelper::qstringToStdString(_paraList);
pDao->_sortAttributeList = CommonHelper::qstringToStdString(_sortAtrributeList);
}
2025-06-23 18:01:09 +08:00
/*从数据库加载一条数据到当前对象*/
2025-06-23 10:41:33 +08:00
void FindByInterface::loadData(DBPlatformSpace::DAO* pDao)
{
using namespace DBPlatformSpace;
_pDBDAO = pDao;
M_FindByInterfaceDAO* pFindDAO = dynamic_cast<M_FindByInterfaceDAO*>(pDao);
_id = pFindDAO->_ID;
_bIsExport = pFindDAO->_bExport;
_name = CommonHelper::stringToQstring(pFindDAO->_name);
_description = CommonHelper::stringToQstring(pFindDAO->_description);
_sortType = pFindDAO->_sortType;
_classID = pFindDAO->_t_M_EntityTableID;
_paraList = CommonHelper::stringToQstring(pFindDAO->_paraList);
2025-06-23 18:01:09 +08:00
//排序属性列表
2025-06-23 10:41:33 +08:00
_sortAtrributeList = CommonHelper::stringToQstring(pFindDAO->_sortAttributeList);
}
2025-06-23 18:01:09 +08:00
/*获取新的属性*/
2025-06-23 10:41:33 +08:00
void FindByInterface::getNewProperty(json& parameter, QVariantMap& valueMap)
{
auto data = parameter["data"];
2025-06-23 18:01:09 +08:00
//接口名称
2025-06-23 10:41:33 +08:00
valueMap.insert("name", CommonHelper::utf8ToQString(data["name"]));
2025-06-23 18:01:09 +08:00
//描述
2025-06-23 10:41:33 +08:00
valueMap.insert("description", CommonHelper::utf8ToQString(data["description"]));
//interfaceType
valueMap.insert("Interfacetype", (int)(data["type"]));
//sortType
if (!data["sortType"].is_null())
{
valueMap.insert("sortType", (int)(data["sortType"]));
}
//IsExport
if (!data["beExport"].is_null())
{
valueMap.insert("IsExport", (int)(data["beExport"]));
}
2025-06-23 18:01:09 +08:00
//参数列表
2025-06-23 10:41:33 +08:00
if (!data["paramList"].is_null())
{
valueMap.insert("paralist", CommonHelper::utf8ToQString(data["paramList"]));
}
2025-06-23 18:01:09 +08:00
//排序属性 sortAttributes
2025-06-23 10:41:33 +08:00
if (!data["sortList"].is_null())
{
/*vector<int>*/auto list = data["sortList"];
QStringList sortAttribute;
for (auto j : list)
{
sortAttribute.append(QString::number(j.get<int>()));
}
QString sortList = sortAttribute.join(",");
valueMap.insert("sortAttribute", sortList);
}
}
void FindByInterface::toJson(json& jsonObj, bool)
{
jsonObj["id"] = _id;
jsonObj["name"] = CommonHelper::qstringToUtf8(_name);
jsonObj["description"] = CommonHelper::qstringToUtf8(_description);
jsonObj["type"] = _interfaceType;
jsonObj["beExport"] = _bIsExport == 1 ? true : false;
jsonObj["paramList"] = CommonHelper::qstringToUtf8(_paraList);
jsonObj["sortType"] = _sortType;
if (_sortAtrributeList.isEmpty())
{
jsonObj["sortList"] = json::array();
}
else
{
QStringList sortlist = _sortAtrributeList.split(",");
for (int i = 0; i < sortlist.size(); i++)
{
QString id = sortlist.at(i);
jsonObj["sortList"].push_back(id.toInt());
}
}
// data["sortList"] = json::parse(dstData._sortAtrributeList.begin(), dstData._sortAtrributeList.end());
}
void FindByInterface::setNewData(json& parameter)
{
QVariantMap newValues;
getNewProperty(parameter, newValues);
setProperties(newValues);
}
bool FindByInterface::deleteSelf()
{
using namespace DBPlatformSpace;
ResultMsg rm;
M_FindByInterfaceDAO* pDao = dynamic_cast<M_FindByInterfaceDAO*>(_pDBDAO);
rm = pDao->delself();
if (rm.rCode == 0)
{
LOG(INFO) << CommonHelper::utf8ToStdString("M_FindByInterfaceDAO.delself success");
return true;
}
LOG(INFO) << CommonHelper::utf8ToStdString("M_FindByInterfaceDAO.delself failed");
LOG(INFO) << rm.rMsg;
return false;
}
bool FindByInterface::saveSelf()
{
using namespace DBPlatformSpace;
ResultMsg rm;
2025-06-23 18:01:09 +08:00
/*将这条项目数据写入数据库*/
2025-06-23 10:41:33 +08:00
M_FindByInterfaceDAO* pDao = dynamic_cast<M_FindByInterfaceDAO*>(_pDBDAO);
2025-06-23 18:01:09 +08:00
/*备份DAO数据*/
2025-06-23 10:41:33 +08:00
M_FindByInterfaceDAO oldDaoData;
// backupDAOData(*pDao, oldDaoData);
2025-06-23 10:41:33 +08:00
if (pDao == nullptr)
{
pDao = new M_FindByInterfaceDAO();
}
saveToDao();
rm = pDao->save();
if (rm.rCode == 0)
{
LOG(INFO) << CommonHelper::utf8ToStdString("M_FindByInterfaceDAO.save success");
return true;
}
else
{
// restoreData(oldDaoData, *this);
2025-06-23 10:41:33 +08:00
LOG(INFO) << CommonHelper::utf8ToStdString("M_FindByInterfaceDAO.save failed");
LOG(INFO) << rm.rMsg;
return false;
}
}
void FindByInterface::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();
2025-06-23 18:01:09 +08:00
//查找id对应的名称
2025-06-23 10:41:33 +08:00
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, CommonHelper::convertInterfaceTypeToStr(_interfaceType)));
}
else if (flag.size() == 3)
{
generator->interfaceTableData111.append(new CCS_Report::CCSModelDataSet(flag[0], flag[1], flag[2], _name, paraShow, CommonHelper::convertInterfaceTypeToStr(_interfaceType)));
}
}