#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(_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(_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(_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(_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(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, "")); } }