Commit 10eb3705 authored by 刘乐's avatar 刘乐

1, 计算服务接口整改

parent 6021600e
......@@ -6,7 +6,6 @@
CivBuilder::CivBuilder()
{
mNewInp = nullptr;
}
CivBuilder::~CivBuilder()
......@@ -34,18 +33,18 @@ CivInpBuilder::CivInpBuilder(CivDbConn* dbConn)
mNewInp->setTtitle("");
}
CivInpBuilder::~CivInpBuilder()
{
delete mDbConn;
}
void CivInpBuilder::setQualityType(const QualityAnalyType analyType, const std::string& qulityName)
{
mNewInp->setQualityType(analyType, qulityName);
}
void CivInpBuilder::registDb(CivDbConn* dbConn)
{
if (mDbConn != nullptr)
{
delete mDbConn;
mDbConn = nullptr;
}
mDbConn = dbConn;
}
......
......@@ -12,6 +12,8 @@ public:
CivBuilder();
virtual ~CivBuilder();
virtual void setQualityType(const QualityAnalyType analyType, const std::string& qulityName) = 0;
virtual void registDb(CivDbConn* dbConn)=0;
virtual void buildNode() = 0;
virtual void buildPipe() = 0;
......@@ -52,6 +54,7 @@ public:
explicit CivInpBuilder(CivDbConn* dbConn);
~CivInpBuilder();
virtual void setQualityType(const QualityAnalyType analyType, const std::string& qulityName);
// 注册数据库连接
virtual void registDb(CivDbConn* dbConn);
virtual void buildNode();
......
......@@ -72,14 +72,13 @@ int DLLEXPORT hdyrSimulation(char* uri)
CivDbConn* pgConn = new CivPgConn(uri);
// 模拟计算对象
CivHydrSimulation* mHyDr = new CivHydrSimulation();
mHyDr->registDb(pgConn);
CivHydrSimulation* mHyDr = new CivHydrSimulation(pgConn);
//开始模拟
int flag = mHyDr->hdyrSimulation();
/* delete mHyDr;
delete pgConn;*/
delete mHyDr;
delete pgConn;
return flag;
}
......@@ -87,7 +86,7 @@ int DLLEXPORT hdyrSimulation(char* uri)
int DLLEXPORT qualitySimulation(char* uri)
{
// 创建数据库连接
CivPgConn* pgConn = new CivPgConn(uri);
CivDbConn* pgConn = new CivPgConn(uri);
// 模拟计算对象
CivHydrSimulation* mHyDr = new CivHydrSimulation();
......@@ -102,17 +101,23 @@ int DLLEXPORT qualitySimulation(char* uri)
return flag;
}
int DLLEXPORT trackingSimulation(char* uri, char* sN)
int DLLEXPORT trackingSimulation(char* uri, char* sN, int hours, char* result)
{
// 创建数据库连接
CivPgConn* pgConn = new CivPgConn(uri);
CivDbConn* pgConn = new CivPgConn(uri);
// 模拟计算对象
CivHydrSimulation* mHyDr = new CivHydrSimulation();
mHyDr->registDb(pgConn);
//开始模拟
int flag = mHyDr->trackingSimulation(sN);
int flag = mHyDr->trackingSimulation(sN, hours);
if (flag)
{
mHyDr->getTrackingResult(hours, result);
}
delete pgConn;
delete mHyDr;
......
......@@ -6,9 +6,28 @@
extern "C" {
#endif
/**
*@brief 水力计算服务
*@uri:数据库连接地址
*@return 1:成功,其他值失败
*/
int DLLEXPORT hdyrSimulation(char* uri);
/**
*@brief 水质计算
*@uri:数据库连接地址
*@return 1:成功,其他值失败
*/
int DLLEXPORT qualitySimulation(char* uri);
int DLLEXPORT trackingSimulation(char* uri,char* sN);
/**
*@brief 水质追踪分析,扩散分析
*@uri:数据库连接地址
*@sN:追踪节点
*@hours:追踪小时
*@result:输出结果:json字符串
*@return 1:成功,其他值失败
*/
int DLLEXPORT trackingSimulation(char* uri, char* sN, int hours, char* result);
/**
*@brief 模拟计算
......
......@@ -75,9 +75,10 @@ void CivHydrSimulation::registDb(CivDbConn* dbConn)
mDbConn = dbConn;
}
bool CivHydrSimulation::convertInp()
bool CivHydrSimulation::convertInp(const QualityAnalyType analyType, const std::string& qulityName)
{
CivBuilder* builder = new CivInpBuilder();
builder->setQualityType(analyType, qulityName);
builder->registDb(mDbConn);
CivInpDirector director;
......@@ -104,7 +105,7 @@ bool CivHydrSimulation::convertInp()
int CivHydrSimulation::hdyrSimulation()
{
CivSysLog::getInstance()->error("开始水力分析计算", "CivHydrSimulation", __FUNCTION__);
if (!convertInp())
if (!convertInp(ANALYSIS_RESERVE,""))
{
CivSysLog::getInstance()->error("写入inp文件失败", "CivHydrSimulation", __FUNCTION__);
return false;
......@@ -166,6 +167,7 @@ int CivHydrSimulation::hdyrSimulation()
ENclose();
return false;
}
ENnextH(&tstep);
if (isFirst)
{
......@@ -196,15 +198,38 @@ int CivHydrSimulation::hdyrSimulation()
int CivHydrSimulation::qualitySimulation()
{
CivSysLog::getInstance()->error("开始水质分析计算", "CivHydrCalc", __FUNCTION__);
if (!convertInp())
CivSysLog::getInstance()->error("开始水质分析计算", "qualitySimulation", __FUNCTION__);
if (!convertInp(ANALYSIS_RESERVE, ""))
{
CivSysLog::getInstance()->error("写入inp文件失败", "qualitySimulation", __FUNCTION__);
return false;
}
CivSysLog::getInstance()->info("写入inp成功", "qualitySimulation", __FUNCTION__);
// 水质计算
bool flag = qualityCompute();
return flag;
}
int CivHydrSimulation::trackingSimulation(char* snNode, int hour)
{
CivSysLog::getInstance()->error("开始水质分析计算", "qualitySimulation", __FUNCTION__);
if (!convertInp(ANALYSIS_TRACE, snNode))
{
CivSysLog::getInstance()->error("写入inp文件失败", "CivHydrCalc", __FUNCTION__);
CivSysLog::getInstance()->error("写入inp文件失败", "qualitySimulation", __FUNCTION__);
return false;
}
CivSysLog::getInstance()->info("写入inp成功", "CivHydrCalc", __FUNCTION__);
CivSysLog::getInstance()->info("写入inp成功", "qualitySimulation", __FUNCTION__);
// 水质计算
bool flag = qualityCompute();
return flag;
}
bool CivHydrSimulation::qualityCompute()
{
// 运行水质运算需要先进行水力运算,没有直接采用ENSolveH 是为了考虑减压阀的压力曲线设置
long t(0), tstep(0);
int iTime(0);
......@@ -220,21 +245,21 @@ int CivHydrSimulation::qualitySimulation()
{
ENclose();
CivSysLog::getInstance()->error("ENopen inp 失败", "CivHydrCalc", __FUNCTION__);
return -1;
return false;
}
CivSysLog::getInstance()->info("ENopen inp 成功", "CivHydrCalc", __FUNCTION__);
if (ENopenH() > 0)
{
ENclose();
CivSysLog::getInstance()->error("ENopenH inp 失败", "CivHydrCalc", __FUNCTION__);
return -1;
return false;
}
if (ENinitH(EN_SAVE) > 0)
{
ENclose();
CivSysLog::getInstance()->error("ENinitH inp 失败", "CivHydrCalc", __FUNCTION__);
return -1;
return false;
}
CivSysLog::getInstance()->info("ENinitH inp 成功", "CivHydrCalc", __FUNCTION__);
bool isFirst = true;
......@@ -255,7 +280,7 @@ int CivHydrSimulation::qualitySimulation()
{
ENopenQ();
ENclose();
return -1;
return false;
}
if (isFirst)
{
......@@ -288,7 +313,7 @@ int CivHydrSimulation::qualitySimulation()
{
ENcloseQ();
ENclose();
return -1;
return false;
}
// 获取水质模拟结果
......@@ -309,7 +334,7 @@ int CivHydrSimulation::qualitySimulation()
if (!mResultCache.updateToDb(mDbConn))
{
CivSysLog::getInstance()->error("水质分析结果存储失败", "CivHydrCalc", __FUNCTION__);
return -1;
return false;
}
CivSysLog::getInstance()->info("水质分析结果存储成功", "CivHydrCalc", __FUNCTION__);
......@@ -318,12 +343,13 @@ int CivHydrSimulation::qualitySimulation()
(void)mDbConn->updateLinkByInterval(CurrentDate, "0");
CivSysLog::getInstance()->info("结束水质分析计算", "CivHydrCalc", __FUNCTION__);
return 1;
return false;
}
int CivHydrSimulation::trackingSimulation(char* snNode)
void CivHydrSimulation::getTrackingResult(int hours,char* result)
{
return 1;
}
void CivHydrSimulation::getNodeResult(short time)
......
#pragma once
#include "CivSimulResultCache.h"
#include "CivNewInp.h"
class CivDbConn;
/**
水力模拟计算类
*/
......@@ -15,6 +15,7 @@ public:
/**
*@biref 注册数据库
*@dbConn:连接数据库指针
*/
void registDb(CivDbConn* dbConn);
......@@ -31,14 +32,26 @@ public:
/**
*@brief 追踪分析,本质仍然式水质分析
*@snNode:追踪的节点号
*@hours: 小时数
*/
int trackingSimulation(char* snNode);
int trackingSimulation(char* snNode, int hours);
/**
*@导出inp文件
*@brief 导出inp文件
*@analyType: 水质分析类型:水龄,追踪,化合物,none
*@qulityName: 追踪节点值,或者化合物质
*/
bool convertInp();
bool convertInp(const QualityAnalyType analyType, const std::string& qulityName);
/**
*@brief 获取追踪结果值
*@hours:追踪的小时数
*/
void getTrackingResult(int hours, char* result);
/*
inp文件名,输出文件名,二进制文件名设置和获取
*/
inline char* getInpFile();
inline void setInpFile(const std::string& inpFile);
......@@ -49,6 +62,11 @@ public:
inline void setBinFile(const std::string& binFile);
private:
/**
*@brief 水质计算服务
*/
bool qualityCompute();
void getNodeResult(short time);
void getLinkResult(short time);
void getNodeQuality(short time);
......@@ -57,7 +75,8 @@ private:
private:
CivDbConn* mDbConn;
CivSimulResultCache mResultCache; // 存储模拟结果缓存类
std::string mInpFile;// inp文件名
std::string mInpFile; // inp文件名
std::string mRptFile; // 报告文件名
std::string mBinFile;// 二进制文件名
};
......@@ -2,6 +2,27 @@
#include <time.h>
#include<fstream>
CivNewInp::CivNewInp()
{
mParamMap[OPTIONS] = &CivNewInp::setOptions;
mParamMap[REACTIONS] = &CivNewInp::setReactions;
mParamMap[TIMES] = &CivNewInp::setTimes;
mParamMap[REPORT] = &CivNewInp::setReport;
mParamMap[ENERGY] = &CivNewInp::setEnergy;
}
CivNewInp::~CivNewInp()
{
}
void CivNewInp::setQualityType(QualityAnalyType type, const std::string& qualityName)
{
mQualityType = type;
mQualityName = qualityName;
}
bool CivNewInp::writeToFile(char* fileName)
{
// 检查是否存在值
......@@ -338,15 +359,122 @@ void CivNewInp::setMixing(const CivMixing& mixing)
}
// 选项和报表
void CivNewInp::setParamter(const CivParameter& params,const std::string& type)
void CivNewInp::setParamter(const CivParameter& params, const std::string& type)
{
void (CivNewInp:: * funcPrt)(const CivParameter&);
auto iter = mParamMap.find(type);
if (mParamMap.end() == iter)
return;
funcPrt = iter->second;
(this->*funcPrt)(params);
}
void CivNewInp::setReactions(const CivParameter& params)
{
auto tables = params.mTables;
if (tables.size() <= 0)
{
return;
}
writeHead(REACTIONS);
auto iter = tables.rbegin();
for (; iter != tables.rend(); iter++)
{
CivParameter::ParamTable table = *iter;
writeStringFormat(table.name);
writeString(table.val);
}
writeString("");
}
void CivNewInp::setOptions(const CivParameter& params)
{
auto tables = params.mTables;
if (tables.size() <= 0)
{
return;
}
writeHead(OPTIONS);
auto iter = tables.rbegin();
for (; iter != tables.rend(); iter++)
{
CivParameter::ParamTable table = *iter;
std::string strName = table.name;
std::string strValue = table.val;
// 改变quality
if (strName =="Quality")
{
switch (mQualityType)
{
case ANALYSIS_TRACE:
strValue = "Trace " + mQualityName;
break;
case ANALYSIS_AGE:
strValue = "AGE mg / L";
break;
case ANALYSIS_CONCENTRATION:
strValue = mQualityName + " mg / L";
break;
case ANALYSIS_RESERVE:
strValue = "NONE";
break;
default:
break;
}
}
writeStringFormat(strName);
writeString(strValue);
}
writeString("");
}
void CivNewInp::setTimes(const CivParameter& params)
{
auto tables = params.mTables;
if (tables.size() <= 0)
{
return;
}
writeHead(TIMES);
auto iter = tables.rbegin();
for (; iter != tables.rend(); iter++)
{
CivParameter::ParamTable table = *iter;
writeStringFormat(table.name);
writeString(table.val);
}
writeString("");
}
void CivNewInp::setReport(const CivParameter& params)
{
auto tables = params.mTables;
if (tables.size() <= 0)
{
return;
}
writeHead(REPORT);
auto iter = tables.rbegin();
for (; iter != tables.rend(); iter++)
{
CivParameter::ParamTable table = *iter;
writeStringFormat(table.name);
writeString(table.val);
}
writeString("");
}
void CivNewInp::setEnergy(const CivParameter& params)
{
auto tables = params.mTables;
if (tables.size() <= 0)
{
return;
}
writeHead(ENERGY);
auto iter = tables.rbegin();
writeHead(type);
for (; iter != tables.rend(); iter++)
{
CivParameter::ParamTable table = *iter;
......
......@@ -6,17 +6,37 @@
#include <list>
// 水质分析类型枚举
typedef enum
{
ANALYSIS_TRACE = 1, //追踪分析
ANALYSIS_AGE = 2, //水龄分析
ANALYSIS_CONCENTRATION = 3, //化合物分析
ANALYSIS_RESERVE = 4, //系统保留,用户不能使用
}QualityAnalyType;
// 组件常量
#define OPTIONS "OPTIONS"
#define TIMES "TIMES"
#define REACTIONS "REACTIONS"
#define ENERGY "ENERGY"
#define REPORT "REPORT"
#define COORDINATES "COORDINATES"
/**
转inp文件类
*/
class CivNewInp
{
public:
explicit CivNewInp();
~CivNewInp();
bool writeToFile(char* fileName);
/**
管网组件
*/
void setQualityType(QualityAnalyType type,const std::string& qualityName);
void setTtitle(const std::string& title);
void setNode(const CivNode& node);
void setPipes(const CivPipe& pipes);
......@@ -40,13 +60,12 @@ public:
void setMixing(const CivMixing& mixing);
// 选项和报表 ,统一读取参数表
/*
void setReactions();
void setOptions();
void setTimes();
void setReport();
void setEnergy();
*/
void setReactions(const CivParameter& params);
void setOptions(const CivParameter& params);
void setTimes(const CivParameter& params);
void setReport(const CivParameter& params);
void setEnergy(const CivParameter& params);
void setParamter(const CivParameter& params, const std::string& type);
......@@ -64,7 +83,11 @@ private:
std::string currentTime();
private:
std::ostringstream mTextStream;
QualityAnalyType mQualityType = ANALYSIS_AGE; //水质分析类型, 默认水龄
std::string mQualityName; // 追踪的节点名 或者化合物名
std::map<std::string, void (CivNewInp::*)(const CivParameter&)> mParamMap; // 参数类型映射
};
#endif // !CIVNEWINP_H
......@@ -50,6 +50,7 @@ public:
*@dbConn:数据库连接对象
*/
bool updateToDb(CivDbConnection* dbConn);
bool updateToDb(CivDbConn* dbConn);
private:
std::map<int, NodeResultItems> mNodeItemsMap; // 模拟
......
......@@ -8,7 +8,7 @@ CivDbConn::CivDbConn()
CivDbConn::~CivDbConn()
{
}
bool CivDbConn::isValid() const
......@@ -21,245 +21,3 @@ Str CivDbConn::getLastError() const
return mLastError;
}
bool CivDbConn::deleteByField(StrQuote table, StrQuote filedName, StrQuote fieldValue)
{
if (!isValid())
return false;
char delSql[256] = "delete from \"";
strcat_s(delSql, table.c_str());
strcat_s(delSql, "\" where ");
strcat_s(delSql, filedName.c_str());
strcat_s(delSql, "='");
strcat_s(delSql, fieldValue.c_str());
strcat_s(delSql, "'");
std::string utf8Sql = TransUTFCoding(delSql);
if (!execSql(utf8Sql))
return false;
return true;
}
bool CivDbConn::updateNodeByInterval(StrQuote currDate, StrQuote interval)
{
if (!isValid())
return false;
std::stringstream os;
NodeFieldName filedNames;
os << "UPDATE "
<< TransUTFCoding(PIPENODE) << " AS tb1 set ("
<< TransUTFCoding("总水头") << ","
<< TransUTFCoding("压力") << ","
<< TransUTFCoding("实际需水量")
<< ")=( "
<< "tb2." << TransUTFCoding(filedNames.dHead) << ","
<< "tb2." << TransUTFCoding(filedNames.dPressure) << ","
<< "tb2." << TransUTFCoding(filedNames.dDemand) << ")" << " from "
<< TransUTFCoding(NODERESULTTABLE) << " AS tb2 where tb1."
<< TransUTFCoding(filedNames.Number) << "= tb2."
<< TransUTFCoding(filedNames.Number) << " AND tb2."
<< TransUTFCoding(filedNames.dDate) << "='" << currDate << "' AND tb2."
<< TransUTFCoding(filedNames.dInterval) << "=" << interval;
std::string updateSql = os.str();
os.clear();
os.str("");
if (!execSql(updateSql))
return false;
return true;
}
bool CivDbConn::updateLinkByInterval(StrQuote currDate, StrQuote interval)
{
if (!isValid())
return false;
std::stringstream os;
LinkFiledName filedNames;
os << "UPDATE "
<< TransUTFCoding(PIPELINE) << " AS tb1 set ("
<< TransUTFCoding("流量") << ","
<< TransUTFCoding("流速") << ","
<< TransUTFCoding("单位水头损") << ","
<< TransUTFCoding("水头总损失") << ","
<< TransUTFCoding("摩擦水头损") << ","
<< TransUTFCoding("上点水头") << ","
<< TransUTFCoding("本点水头") << ","
<< TransUTFCoding("局部水头损")
<< ")=( "
<< "tb2." << TransUTFCoding(filedNames.dFlow) << ","
<< "tb2." << TransUTFCoding(filedNames.dVelocity) << ","
<< "tb2." << TransUTFCoding(filedNames.dUnitHeadloss) << ","
<< "tb2." << TransUTFCoding(filedNames.dHeadloss) << ","
<< "tb2." << TransUTFCoding(filedNames.dFrictionHeadloss) << ","
<< "tb2." << TransUTFCoding(filedNames.dFromNodHeadloss) << ","
<< "tb2." << TransUTFCoding(filedNames.dToNodHeadloss) << ","
<< "tb2." << TransUTFCoding(filedNames.dLocalHeadloss) << ")" << " from "
<< TransUTFCoding(PIPERESULTTABLE) << " AS tb2 where tb1."
<< TransUTFCoding(filedNames.szNo) << "= tb2."
<< TransUTFCoding(filedNames.szNo) << " AND tb2."
<< TransUTFCoding(filedNames.dDate) << "='" << currDate << "' AND tb2."
<< TransUTFCoding(filedNames.dInterval) << "=" << interval;
std::string updateSql = os.str();
os.clear();
os.str("");
if (!execSql(updateSql))
return false;
return true;
}
bool CivDbConn::updateNode(const NodeResultItems& nodeItems)
{
if (!isValid())
return false;
std::stringstream os;
NodeFieldName filedNames;
os << "INSERT INTO public." << NODERESULTTABLE << " ( ";
os << filedNames.Number << ",";
os << filedNames.dDemand << ",";
os << filedNames.dHead << ",";
os << filedNames.dElevation << ",";
os << filedNames.dPressure << ",";
os << filedNames.dTankLevel << ",";
os << filedNames.dTankMaxVolume << ",";
os << filedNames.dTankVolume << ",";
os << filedNames.dDate << ",";
os << filedNames.dInterval << ",";
os << filedNames.dQuality << ",";
os << filedNames.dModifyTime;
os << ") VALUES";
std::string preSql = os.str();
os.flush();
os.clear();
os.str("");
// 2, 参数值
for (auto iter = nodeItems.begin(); iter != nodeItems.end(); iter++)
{
NodeResultItem item = iter->second;
os << "('" << item.szNo << "',";
os << item.dDemand << ",";
os << item.dHead << ",";
os << item.dElevation << ",";
os << item.dPressure << ",";
os << item.dTankLevel << ",";
os << item.dTankMaxVolume << ",";
os << item.dTankVolume << ",";
os << "'" << CurrentDate << "',";
os << item.dInterval << ",";
os << item.dQuality << ",";
os << "'" << CurrentTime << "'";
auto subiter = iter;
++subiter;
if (subiter == nodeItems.end())
{
os << ")";
}
else
{
os << "),";
}
}
std::string sql = TransUTFCoding(preSql) + os.str();
os.clear();
os.str("");
if (!execSql(sql))
return false;
return true;
}
bool CivDbConn::updateLink(const LinkResultItems& lineItems)
{
if (!isValid())
return false;
std::stringstream os;
LinkFiledName filedNames;
std::string currData = CurrentDate;
os << "INSERT INTO public." << PIPERESULTTABLE << "( ";
os << filedNames.szNo << ",";
os << filedNames.dFlow << ",";
os << filedNames.nFlowDirect << ",";
os << filedNames.dVelocity << ",";
os << filedNames.dHeadloss << ",";
os << filedNames.dUnitHeadloss << ",";
os << filedNames.dFromNodHeadloss << ",";
os << filedNames.dToNodHeadloss << ",";
os << filedNames.dLocalHeadloss << ",";
os << filedNames.dFrictionHeadloss << ",";
os << filedNames.szStatus << ",";
os << filedNames.dDate << ",";
os << filedNames.dInterval << ",";
os << filedNames.dQuality << ",";
os << filedNames.dModifyTime;
os << ") VALUES";
std::string preSql = os.str();
os.clear();
os.str("");
// 2, 参数值
for (auto iter = lineItems.begin(); iter != lineItems.end(); iter++)
{
LinkResultItem item = iter->second;
os << "('" << item.szNo << "'" << ",";
os << item.dFlow << ",";
os << item.nFlowDirect << ",";
os << item.dVelocity << ",";
os << item.dHeadloss << ",";
os << item.dUnitHeadloss << ",";
os << item.dFromNodHeadloss << ",";
os << item.dToNodHeadloss << ",";
os << item.dLocalHeadloss << ",";
os << item.dFrictionHeadloss << ",";
os << "'" << TransUTFCoding(item.szStatus) << "'" << ",";
os << "'" << CurrentDate << "',";
os << item.dInterval << ",";
os << item.dQuality << ",";
os << "'" << CurrentTime << "'";
auto subIte = iter;
++subIte;
if (subIte == lineItems.end())
os << ")";
else
os << "),";
}
std::string utf8Sql = TransUTFCoding(preSql);
std::string sql = utf8Sql + os.str();
os.clear();
os.str("");
if (!execSql(sql))
return false;
return true;
}
bool CivDbConn::createTable(CivTableTemp& temp)
{
if (&temp == NULL)
return false;
Str sql = temp.createSql();
Str finalSql = TransUTFCoding(sql);
return execSql(finalSql);
}
......@@ -57,43 +57,41 @@ public:
*@schema:
*@tableType:表类型,点结果,线结果
*/
bool createTable(CivTableTemp& temp);
virtual bool createTable(CivTableTemp& temp) =0 ;
bool isValid() const;
/**
*@brief 根据字段值条件删除数据
*@table:表
*@filedName:字段名
*@fieldValue:字段值
*/
bool deleteByField(StrQuote table, StrQuote filedName, StrQuote fieldValue);
virtual bool deleteByField(StrQuote table, StrQuote filedName, StrQuote fieldValue) =0 ;
bool updateNodeByInterval(StrQuote currDate, StrQuote interval);
virtual bool updateNodeByInterval(StrQuote currDate, StrQuote interval)=0;
bool updateLinkByInterval(StrQuote currDate, StrQuote interval);
virtual bool updateLinkByInterval(StrQuote currDate, StrQuote interval)=0;
/**
*@brief 更新点表数据
*@nodeItems:需要更新的值
*/
bool updateNode(const NodeResultItems& nodeItems);
virtual bool updateNode(const NodeResultItems& nodeItems) = 0;
/**
*@brief 更新线表的数据
*@lineItems: 线数据
*/
bool updateLink(const LinkResultItems& lineItems);
virtual bool updateLink(const LinkResultItems& lineItems) = 0;
// 获取当前执行错误信息
Str getLastError() const;
private:
/**
*@brief 执行sql语句
*@sql: 需要执行的sql语句
*/
virtual bool execSql(StrQuote sql) = 0;
virtual bool execSql(StrQuote sql)=0;
protected:
bool mIsOpen = false; // 数据库连接信息
......
This diff is collapsed.
......@@ -11,48 +11,76 @@ class DBEXPORT CivPgConn: public CivDbConn
{
public:
CivPgConn(char* uri);
~CivPgConn();
virtual ~CivPgConn();
/**
*@brief 连接数据库,与具体的数据有关子类实现
*/
virtual bool open();
bool open() override;
/**
*@brief 关闭数据库连接,与具体的数据有关子类实现
*/
virtual void close();
void close() override;
/**
*@brief 判断某张表是否存在,判断方法跟具体的数据库有关,延迟到子类实现
*@tableName: 表名称
*/
virtual bool tableExist(StrQuote tableName);
bool tableExist(StrQuote tableName)override;
/**
*@brief 执行sql语句
*@sql: 需要执行的sql语句
*/
virtual bool execSql(StrQuote sql);
virtual bool getNode(CivNode& node) ;
virtual bool getPipe(CivPipe& pipe) ;
virtual bool getTank(CivTank& tank) ;
virtual bool getValve(CivValve& valve) ;
virtual bool getPumps(CivPumps& pump) ;
virtual bool getReservoirs(CivReservoirs& reservoirs) ;
virtual bool getEmitters(CivEmitters& emitter) ;
virtual bool getCoordinates(CivCoordinates& coord) ;
virtual bool getMixing(CivMixing& mixing) ;
virtual bool getParameter(std::vector<CivParameter>& param) ;
virtual bool getPatterns(CivPatterns& patterns) ;
virtual bool getCurves(CivCurves& curves) ;
virtual bool getDemands(CivDemands& demands) ;
virtual bool getSources(CivSources& sources) ;
virtual bool getStatus(CivStatus& status) ;
virtual bool getQuality(CivQuality& quality) ;
virtual bool getLabels(CivLabels& labels) ;
virtual bool getTags(CivTags& tags) ;
bool execSql(StrQuote sql) override;
bool getNode(CivNode& node) override;
bool getPipe(CivPipe& pipe) override;
bool getTank(CivTank& tank) override;
bool getValve(CivValve& valve) override;
bool getPumps(CivPumps& pump) override;
bool getReservoirs(CivReservoirs& reservoirs) override;
bool getEmitters(CivEmitters& emitter) override;
bool getCoordinates(CivCoordinates& coord) override;
bool getMixing(CivMixing& mixing) override;
bool getParameter(std::vector<CivParameter>& param) override;
bool getPatterns(CivPatterns& patterns) override;
bool getCurves(CivCurves& curves) override;
bool getDemands(CivDemands& demands) override;
bool getSources(CivSources& sources) override;
bool getStatus(CivStatus& status) override;
bool getQuality(CivQuality& quality) override;
bool getLabels(CivLabels& labels) override;
bool getTags(CivTags& tags) override;
/**
*@brief 创建表格
*@tableName: 表名
*@schema:
*@tableType:表类型,点结果,线结果
*/
bool createTable(CivTableTemp& temp) override;
/**
*@brief 根据字段值条件删除数据
*@table:表
*@filedName:字段名
*@fieldValue:字段值
*/
bool deleteByField(StrQuote table, StrQuote filedName, StrQuote fieldValue) override;
bool updateNodeByInterval(StrQuote currDate, StrQuote interval) override;
bool updateLinkByInterval(StrQuote currDate, StrQuote interval) override;
/**
*@brief 更新点表数据
*@nodeItems:需要更新的值
*/
bool updateNode(const NodeResultItems& nodeItems) override;
/**
*@brief 更新线表的数据
*@lineItems: 线数据
*/
bool updateLink(const LinkResultItems& lineItems) override;
private:
PGconn* mConn; // 连接对象
PGresult* mResult; // 查询结果集
......
......@@ -72,11 +72,6 @@ enum PumpParameter
PATTERN // 时间模式的ID,描述了速度设置怎样随时间变化
};
// REACTIONS
// 定义对应于管网中与化学成分反应的参数。
struct Reactions {
Str name;
};
// [REPORT]
// 描述模拟生成的输出报表内容。
......@@ -278,6 +273,7 @@ struct LinkResultItem
#define LinkResultItems std::map<Str, LinkResultItem>
#endif // !CIVTYPES_H
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment