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

1, 计算服务接口整改

parent 6021600e
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
CivBuilder::CivBuilder() CivBuilder::CivBuilder()
{ {
mNewInp = nullptr;
} }
CivBuilder::~CivBuilder() CivBuilder::~CivBuilder()
...@@ -34,18 +33,18 @@ CivInpBuilder::CivInpBuilder(CivDbConn* dbConn) ...@@ -34,18 +33,18 @@ CivInpBuilder::CivInpBuilder(CivDbConn* dbConn)
mNewInp->setTtitle(""); mNewInp->setTtitle("");
} }
CivInpBuilder::~CivInpBuilder() CivInpBuilder::~CivInpBuilder()
{ {
delete mDbConn; }
void CivInpBuilder::setQualityType(const QualityAnalyType analyType, const std::string& qulityName)
{
mNewInp->setQualityType(analyType, qulityName);
} }
void CivInpBuilder::registDb(CivDbConn* dbConn) void CivInpBuilder::registDb(CivDbConn* dbConn)
{ {
if (mDbConn != nullptr)
{
delete mDbConn;
mDbConn = nullptr;
}
mDbConn = dbConn; mDbConn = dbConn;
} }
......
...@@ -12,6 +12,8 @@ public: ...@@ -12,6 +12,8 @@ public:
CivBuilder(); CivBuilder();
virtual ~CivBuilder(); virtual ~CivBuilder();
virtual void setQualityType(const QualityAnalyType analyType, const std::string& qulityName) = 0;
virtual void registDb(CivDbConn* dbConn)=0; virtual void registDb(CivDbConn* dbConn)=0;
virtual void buildNode() = 0; virtual void buildNode() = 0;
virtual void buildPipe() = 0; virtual void buildPipe() = 0;
...@@ -52,6 +54,7 @@ public: ...@@ -52,6 +54,7 @@ public:
explicit CivInpBuilder(CivDbConn* dbConn); explicit CivInpBuilder(CivDbConn* dbConn);
~CivInpBuilder(); ~CivInpBuilder();
virtual void setQualityType(const QualityAnalyType analyType, const std::string& qulityName);
// 注册数据库连接 // 注册数据库连接
virtual void registDb(CivDbConn* dbConn); virtual void registDb(CivDbConn* dbConn);
virtual void buildNode(); virtual void buildNode();
......
...@@ -72,14 +72,13 @@ int DLLEXPORT hdyrSimulation(char* uri) ...@@ -72,14 +72,13 @@ int DLLEXPORT hdyrSimulation(char* uri)
CivDbConn* pgConn = new CivPgConn(uri); CivDbConn* pgConn = new CivPgConn(uri);
// 模拟计算对象 // 模拟计算对象
CivHydrSimulation* mHyDr = new CivHydrSimulation(); CivHydrSimulation* mHyDr = new CivHydrSimulation(pgConn);
mHyDr->registDb(pgConn);
//开始模拟 //开始模拟
int flag = mHyDr->hdyrSimulation(); int flag = mHyDr->hdyrSimulation();
/* delete mHyDr; delete mHyDr;
delete pgConn;*/ delete pgConn;
return flag; return flag;
} }
...@@ -87,7 +86,7 @@ int DLLEXPORT hdyrSimulation(char* uri) ...@@ -87,7 +86,7 @@ int DLLEXPORT hdyrSimulation(char* uri)
int DLLEXPORT qualitySimulation(char* uri) int DLLEXPORT qualitySimulation(char* uri)
{ {
// 创建数据库连接 // 创建数据库连接
CivPgConn* pgConn = new CivPgConn(uri); CivDbConn* pgConn = new CivPgConn(uri);
// 模拟计算对象 // 模拟计算对象
CivHydrSimulation* mHyDr = new CivHydrSimulation(); CivHydrSimulation* mHyDr = new CivHydrSimulation();
...@@ -102,17 +101,23 @@ int DLLEXPORT qualitySimulation(char* uri) ...@@ -102,17 +101,23 @@ int DLLEXPORT qualitySimulation(char* uri)
return flag; 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(); CivHydrSimulation* mHyDr = new CivHydrSimulation();
mHyDr->registDb(pgConn); mHyDr->registDb(pgConn);
//开始模拟 //开始模拟
int flag = mHyDr->trackingSimulation(sN); int flag = mHyDr->trackingSimulation(sN, hours);
if (flag)
{
mHyDr->getTrackingResult(hours, result);
}
delete pgConn; delete pgConn;
delete mHyDr; delete mHyDr;
......
...@@ -6,9 +6,28 @@ ...@@ -6,9 +6,28 @@
extern "C" { extern "C" {
#endif #endif
/**
*@brief 水力计算服务
*@uri:数据库连接地址
*@return 1:成功,其他值失败
*/
int DLLEXPORT hdyrSimulation(char* uri); int DLLEXPORT hdyrSimulation(char* uri);
/**
*@brief 水质计算
*@uri:数据库连接地址
*@return 1:成功,其他值失败
*/
int DLLEXPORT qualitySimulation(char* uri); 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 模拟计算 *@brief 模拟计算
......
...@@ -75,9 +75,10 @@ void CivHydrSimulation::registDb(CivDbConn* dbConn) ...@@ -75,9 +75,10 @@ void CivHydrSimulation::registDb(CivDbConn* dbConn)
mDbConn = dbConn; mDbConn = dbConn;
} }
bool CivHydrSimulation::convertInp() bool CivHydrSimulation::convertInp(const QualityAnalyType analyType, const std::string& qulityName)
{ {
CivBuilder* builder = new CivInpBuilder(); CivBuilder* builder = new CivInpBuilder();
builder->setQualityType(analyType, qulityName);
builder->registDb(mDbConn); builder->registDb(mDbConn);
CivInpDirector director; CivInpDirector director;
...@@ -104,7 +105,7 @@ bool CivHydrSimulation::convertInp() ...@@ -104,7 +105,7 @@ bool CivHydrSimulation::convertInp()
int CivHydrSimulation::hdyrSimulation() int CivHydrSimulation::hdyrSimulation()
{ {
CivSysLog::getInstance()->error("开始水力分析计算", "CivHydrSimulation", __FUNCTION__); CivSysLog::getInstance()->error("开始水力分析计算", "CivHydrSimulation", __FUNCTION__);
if (!convertInp()) if (!convertInp(ANALYSIS_RESERVE,""))
{ {
CivSysLog::getInstance()->error("写入inp文件失败", "CivHydrSimulation", __FUNCTION__); CivSysLog::getInstance()->error("写入inp文件失败", "CivHydrSimulation", __FUNCTION__);
return false; return false;
...@@ -166,6 +167,7 @@ int CivHydrSimulation::hdyrSimulation() ...@@ -166,6 +167,7 @@ int CivHydrSimulation::hdyrSimulation()
ENclose(); ENclose();
return false; return false;
} }
ENnextH(&tstep); ENnextH(&tstep);
if (isFirst) if (isFirst)
{ {
...@@ -196,15 +198,38 @@ int CivHydrSimulation::hdyrSimulation() ...@@ -196,15 +198,38 @@ int CivHydrSimulation::hdyrSimulation()
int CivHydrSimulation::qualitySimulation() int CivHydrSimulation::qualitySimulation()
{ {
CivSysLog::getInstance()->error("开始水质分析计算", "CivHydrCalc", __FUNCTION__); CivSysLog::getInstance()->error("开始水质分析计算", "qualitySimulation", __FUNCTION__);
if (!convertInp()) 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; return false;
} }
CivSysLog::getInstance()->info("写入inp成功", "CivHydrCalc", __FUNCTION__); CivSysLog::getInstance()->info("写入inp成功", "qualitySimulation", __FUNCTION__);
// 水质计算
bool flag = qualityCompute();
return flag;
}
bool CivHydrSimulation::qualityCompute()
{
// 运行水质运算需要先进行水力运算,没有直接采用ENSolveH 是为了考虑减压阀的压力曲线设置 // 运行水质运算需要先进行水力运算,没有直接采用ENSolveH 是为了考虑减压阀的压力曲线设置
long t(0), tstep(0); long t(0), tstep(0);
int iTime(0); int iTime(0);
...@@ -220,21 +245,21 @@ int CivHydrSimulation::qualitySimulation() ...@@ -220,21 +245,21 @@ int CivHydrSimulation::qualitySimulation()
{ {
ENclose(); ENclose();
CivSysLog::getInstance()->error("ENopen inp 失败", "CivHydrCalc", __FUNCTION__); CivSysLog::getInstance()->error("ENopen inp 失败", "CivHydrCalc", __FUNCTION__);
return -1; return false;
} }
CivSysLog::getInstance()->info("ENopen inp 成功", "CivHydrCalc", __FUNCTION__); CivSysLog::getInstance()->info("ENopen inp 成功", "CivHydrCalc", __FUNCTION__);
if (ENopenH() > 0) if (ENopenH() > 0)
{ {
ENclose(); ENclose();
CivSysLog::getInstance()->error("ENopenH inp 失败", "CivHydrCalc", __FUNCTION__); CivSysLog::getInstance()->error("ENopenH inp 失败", "CivHydrCalc", __FUNCTION__);
return -1; return false;
} }
if (ENinitH(EN_SAVE) > 0) if (ENinitH(EN_SAVE) > 0)
{ {
ENclose(); ENclose();
CivSysLog::getInstance()->error("ENinitH inp 失败", "CivHydrCalc", __FUNCTION__); CivSysLog::getInstance()->error("ENinitH inp 失败", "CivHydrCalc", __FUNCTION__);
return -1; return false;
} }
CivSysLog::getInstance()->info("ENinitH inp 成功", "CivHydrCalc", __FUNCTION__); CivSysLog::getInstance()->info("ENinitH inp 成功", "CivHydrCalc", __FUNCTION__);
bool isFirst = true; bool isFirst = true;
...@@ -255,7 +280,7 @@ int CivHydrSimulation::qualitySimulation() ...@@ -255,7 +280,7 @@ int CivHydrSimulation::qualitySimulation()
{ {
ENopenQ(); ENopenQ();
ENclose(); ENclose();
return -1; return false;
} }
if (isFirst) if (isFirst)
{ {
...@@ -288,7 +313,7 @@ int CivHydrSimulation::qualitySimulation() ...@@ -288,7 +313,7 @@ int CivHydrSimulation::qualitySimulation()
{ {
ENcloseQ(); ENcloseQ();
ENclose(); ENclose();
return -1; return false;
} }
// 获取水质模拟结果 // 获取水质模拟结果
...@@ -309,7 +334,7 @@ int CivHydrSimulation::qualitySimulation() ...@@ -309,7 +334,7 @@ int CivHydrSimulation::qualitySimulation()
if (!mResultCache.updateToDb(mDbConn)) if (!mResultCache.updateToDb(mDbConn))
{ {
CivSysLog::getInstance()->error("水质分析结果存储失败", "CivHydrCalc", __FUNCTION__); CivSysLog::getInstance()->error("水质分析结果存储失败", "CivHydrCalc", __FUNCTION__);
return -1; return false;
} }
CivSysLog::getInstance()->info("水质分析结果存储成功", "CivHydrCalc", __FUNCTION__); CivSysLog::getInstance()->info("水质分析结果存储成功", "CivHydrCalc", __FUNCTION__);
...@@ -318,12 +343,13 @@ int CivHydrSimulation::qualitySimulation() ...@@ -318,12 +343,13 @@ int CivHydrSimulation::qualitySimulation()
(void)mDbConn->updateLinkByInterval(CurrentDate, "0"); (void)mDbConn->updateLinkByInterval(CurrentDate, "0");
CivSysLog::getInstance()->info("结束水质分析计算", "CivHydrCalc", __FUNCTION__); 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) void CivHydrSimulation::getNodeResult(short time)
......
#pragma once #pragma once
#include "CivSimulResultCache.h" #include "CivSimulResultCache.h"
#include "CivNewInp.h"
class CivDbConn; class CivDbConn;
/** /**
水力模拟计算类 水力模拟计算类
*/ */
...@@ -15,6 +15,7 @@ public: ...@@ -15,6 +15,7 @@ public:
/** /**
*@biref 注册数据库 *@biref 注册数据库
*@dbConn:连接数据库指针
*/ */
void registDb(CivDbConn* dbConn); void registDb(CivDbConn* dbConn);
...@@ -31,14 +32,26 @@ public: ...@@ -31,14 +32,26 @@ public:
/** /**
*@brief 追踪分析,本质仍然式水质分析 *@brief 追踪分析,本质仍然式水质分析
*@snNode:追踪的节点号 *@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 char* getInpFile();
inline void setInpFile(const std::string& inpFile); inline void setInpFile(const std::string& inpFile);
...@@ -49,6 +62,11 @@ public: ...@@ -49,6 +62,11 @@ public:
inline void setBinFile(const std::string& binFile); inline void setBinFile(const std::string& binFile);
private: private:
/**
*@brief 水质计算服务
*/
bool qualityCompute();
void getNodeResult(short time); void getNodeResult(short time);
void getLinkResult(short time); void getLinkResult(short time);
void getNodeQuality(short time); void getNodeQuality(short time);
...@@ -57,7 +75,8 @@ private: ...@@ -57,7 +75,8 @@ private:
private: private:
CivDbConn* mDbConn; CivDbConn* mDbConn;
CivSimulResultCache mResultCache; // 存储模拟结果缓存类 CivSimulResultCache mResultCache; // 存储模拟结果缓存类
std::string mInpFile;// inp文件名
std::string mInpFile; // inp文件名
std::string mRptFile; // 报告文件名 std::string mRptFile; // 报告文件名
std::string mBinFile;// 二进制文件名 std::string mBinFile;// 二进制文件名
}; };
...@@ -2,6 +2,27 @@ ...@@ -2,6 +2,27 @@
#include <time.h> #include <time.h>
#include<fstream> #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) bool CivNewInp::writeToFile(char* fileName)
{ {
// 检查是否存在值 // 检查是否存在值
...@@ -338,15 +359,122 @@ void CivNewInp::setMixing(const CivMixing& mixing) ...@@ -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; auto tables = params.mTables;
if (tables.size() <= 0) if (tables.size() <= 0)
{ {
return; return;
} }
writeHead(ENERGY);
auto iter = tables.rbegin(); auto iter = tables.rbegin();
writeHead(type);
for (; iter != tables.rend(); iter++) for (; iter != tables.rend(); iter++)
{ {
CivParameter::ParamTable table = *iter; CivParameter::ParamTable table = *iter;
......
...@@ -6,17 +6,37 @@ ...@@ -6,17 +6,37 @@
#include <list> #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文件类 转inp文件类
*/ */
class CivNewInp class CivNewInp
{ {
public: public:
explicit CivNewInp();
~CivNewInp();
bool writeToFile(char* fileName); bool writeToFile(char* fileName);
/** /**
管网组件 管网组件
*/ */
void setQualityType(QualityAnalyType type,const std::string& qualityName);
void setTtitle(const std::string& title); void setTtitle(const std::string& title);
void setNode(const CivNode& node); void setNode(const CivNode& node);
void setPipes(const CivPipe& pipes); void setPipes(const CivPipe& pipes);
...@@ -40,13 +60,12 @@ public: ...@@ -40,13 +60,12 @@ public:
void setMixing(const CivMixing& mixing); void setMixing(const CivMixing& mixing);
// 选项和报表 ,统一读取参数表 // 选项和报表 ,统一读取参数表
/* void setReactions(const CivParameter& params);
void setReactions(); void setOptions(const CivParameter& params);
void setOptions(); void setTimes(const CivParameter& params);
void setTimes(); void setReport(const CivParameter& params);
void setReport(); void setEnergy(const CivParameter& params);
void setEnergy();
*/
void setParamter(const CivParameter& params, const std::string& type); void setParamter(const CivParameter& params, const std::string& type);
...@@ -64,7 +83,11 @@ private: ...@@ -64,7 +83,11 @@ private:
std::string currentTime(); std::string currentTime();
private: private:
std::ostringstream mTextStream; std::ostringstream mTextStream;
QualityAnalyType mQualityType = ANALYSIS_AGE; //水质分析类型, 默认水龄
std::string mQualityName; // 追踪的节点名 或者化合物名
std::map<std::string, void (CivNewInp::*)(const CivParameter&)> mParamMap; // 参数类型映射
}; };
#endif // !CIVNEWINP_H #endif // !CIVNEWINP_H
...@@ -50,6 +50,7 @@ public: ...@@ -50,6 +50,7 @@ public:
*@dbConn:数据库连接对象 *@dbConn:数据库连接对象
*/ */
bool updateToDb(CivDbConnection* dbConn); bool updateToDb(CivDbConnection* dbConn);
bool updateToDb(CivDbConn* dbConn); bool updateToDb(CivDbConn* dbConn);
private: private:
std::map<int, NodeResultItems> mNodeItemsMap; // 模拟 std::map<int, NodeResultItems> mNodeItemsMap; // 模拟
......
...@@ -8,7 +8,7 @@ CivDbConn::CivDbConn() ...@@ -8,7 +8,7 @@ CivDbConn::CivDbConn()
CivDbConn::~CivDbConn() CivDbConn::~CivDbConn()
{ {
} }
bool CivDbConn::isValid() const bool CivDbConn::isValid() const
...@@ -21,245 +21,3 @@ Str CivDbConn::getLastError() const ...@@ -21,245 +21,3 @@ Str CivDbConn::getLastError() const
return mLastError; 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: ...@@ -57,43 +57,41 @@ public:
*@schema: *@schema:
*@tableType:表类型,点结果,线结果 *@tableType:表类型,点结果,线结果
*/ */
bool createTable(CivTableTemp& temp); virtual bool createTable(CivTableTemp& temp) =0 ;
bool isValid() const; bool isValid() const;
/** /**
*@brief 根据字段值条件删除数据 *@brief 根据字段值条件删除数据
*@table:表 *@table:表
*@filedName:字段名 *@filedName:字段名
*@fieldValue:字段值 *@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 更新点表数据 *@brief 更新点表数据
*@nodeItems:需要更新的值 *@nodeItems:需要更新的值
*/ */
bool updateNode(const NodeResultItems& nodeItems); virtual bool updateNode(const NodeResultItems& nodeItems) = 0;
/** /**
*@brief 更新线表的数据 *@brief 更新线表的数据
*@lineItems: 线数据 *@lineItems: 线数据
*/ */
bool updateLink(const LinkResultItems& lineItems); virtual bool updateLink(const LinkResultItems& lineItems) = 0;
// 获取当前执行错误信息 // 获取当前执行错误信息
Str getLastError() const; Str getLastError() const;
private:
/** /**
*@brief 执行sql语句 *@brief 执行sql语句
*@sql: 需要执行的sql语句 *@sql: 需要执行的sql语句
*/ */
virtual bool execSql(StrQuote sql) = 0; virtual bool execSql(StrQuote sql)=0;
protected: protected:
bool mIsOpen = false; // 数据库连接信息 bool mIsOpen = false; // 数据库连接信息
......
This diff is collapsed.
...@@ -11,48 +11,76 @@ class DBEXPORT CivPgConn: public CivDbConn ...@@ -11,48 +11,76 @@ class DBEXPORT CivPgConn: public CivDbConn
{ {
public: public:
CivPgConn(char* uri); CivPgConn(char* uri);
~CivPgConn(); virtual ~CivPgConn();
/** /**
*@brief 连接数据库,与具体的数据有关子类实现 *@brief 连接数据库,与具体的数据有关子类实现
*/ */
virtual bool open(); bool open() override;
/** /**
*@brief 关闭数据库连接,与具体的数据有关子类实现 *@brief 关闭数据库连接,与具体的数据有关子类实现
*/ */
virtual void close(); void close() override;
/** /**
*@brief 判断某张表是否存在,判断方法跟具体的数据库有关,延迟到子类实现 *@brief 判断某张表是否存在,判断方法跟具体的数据库有关,延迟到子类实现
*@tableName: 表名称 *@tableName: 表名称
*/ */
virtual bool tableExist(StrQuote tableName); bool tableExist(StrQuote tableName)override;
/** /**
*@brief 执行sql语句 *@brief 执行sql语句
*@sql: 需要执行的sql语句 *@sql: 需要执行的sql语句
*/ */
virtual bool execSql(StrQuote sql); bool execSql(StrQuote sql) override;
virtual bool getNode(CivNode& node) ; bool getNode(CivNode& node) override;
virtual bool getPipe(CivPipe& pipe) ; bool getPipe(CivPipe& pipe) override;
virtual bool getTank(CivTank& tank) ; bool getTank(CivTank& tank) override;
virtual bool getValve(CivValve& valve) ; bool getValve(CivValve& valve) override;
virtual bool getPumps(CivPumps& pump) ; bool getPumps(CivPumps& pump) override;
virtual bool getReservoirs(CivReservoirs& reservoirs) ; bool getReservoirs(CivReservoirs& reservoirs) override;
virtual bool getEmitters(CivEmitters& emitter) ; bool getEmitters(CivEmitters& emitter) override;
virtual bool getCoordinates(CivCoordinates& coord) ; bool getCoordinates(CivCoordinates& coord) override;
virtual bool getMixing(CivMixing& mixing) ; bool getMixing(CivMixing& mixing) override;
virtual bool getParameter(std::vector<CivParameter>& param) ; bool getParameter(std::vector<CivParameter>& param) override;
virtual bool getPatterns(CivPatterns& patterns) ; bool getPatterns(CivPatterns& patterns) override;
virtual bool getCurves(CivCurves& curves) ; bool getCurves(CivCurves& curves) override;
virtual bool getDemands(CivDemands& demands) ; bool getDemands(CivDemands& demands) override;
virtual bool getSources(CivSources& sources) ; bool getSources(CivSources& sources) override;
virtual bool getStatus(CivStatus& status) ; bool getStatus(CivStatus& status) override;
virtual bool getQuality(CivQuality& quality) ; bool getQuality(CivQuality& quality) override;
virtual bool getLabels(CivLabels& labels) ; bool getLabels(CivLabels& labels) override;
virtual bool getTags(CivTags& tags) ; 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: private:
PGconn* mConn; // 连接对象 PGconn* mConn; // 连接对象
PGresult* mResult; // 查询结果集 PGresult* mResult; // 查询结果集
......
...@@ -72,11 +72,6 @@ enum PumpParameter ...@@ -72,11 +72,6 @@ enum PumpParameter
PATTERN // 时间模式的ID,描述了速度设置怎样随时间变化 PATTERN // 时间模式的ID,描述了速度设置怎样随时间变化
}; };
// REACTIONS
// 定义对应于管网中与化学成分反应的参数。
struct Reactions {
Str name;
};
// [REPORT] // [REPORT]
// 描述模拟生成的输出报表内容。 // 描述模拟生成的输出报表内容。
...@@ -278,6 +273,7 @@ struct LinkResultItem ...@@ -278,6 +273,7 @@ struct LinkResultItem
#define LinkResultItems std::map<Str, LinkResultItem> #define LinkResultItems std::map<Str, LinkResultItem>
#endif // !CIVTYPES_H #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