Commit cb17f35f authored by 刘乐's avatar 刘乐

1, 新增接口

parent 52f38d22
#include "CivHydrFuncInter.h" #include "CivHydrFuncInter.h"
#include "CivHydrCalc.h" #include "CivHydrCalc.h"
#include "CivDbConnection.h"
bool DLLEXPORT simulation(char* uri, char* netName, char* flag) bool DLLEXPORT simulation(char* uri, char* netName, char* flag)
...@@ -23,4 +24,12 @@ bool DLLEXPORT simulation(char* uri, char* netName, char* flag) ...@@ -23,4 +24,12 @@ bool DLLEXPORT simulation(char* uri, char* netName, char* flag)
delete calc; delete calc;
return msg; return msg;
}
bool DLLEXPORT getDataByInterval(char* uri, char* netName, char* date, char* interval)
{
CivDbConnection* dbConn = new CivDbConnection(uri);
bool flag = dbConn->updateLinkByInterval(date, interval);
delete dbConn;
return flag;
} }
\ No newline at end of file
...@@ -13,6 +13,15 @@ extern "C" { ...@@ -13,6 +13,15 @@ extern "C" {
*/ */
bool DLLEXPORT simulation(char* uri, char* netName,char* flag); bool DLLEXPORT simulation(char* uri, char* netName,char* flag);
/**
*@brief 获取管网计算特定时段的结果
*@uri: 管网数据库连接
*@netName: 管网名
*@date: 日期
*@interval: 时段,整数
*/
bool DLLEXPORT getDataByInterval(char* uri, char* netName, char* date, char* interval);
#if defined(__cplusplus) #if defined(__cplusplus)
} }
#endif #endif
......
...@@ -164,21 +164,10 @@ bool CivDbConnection::updateNode(const NodeResultItems& nodeItems) ...@@ -164,21 +164,10 @@ bool CivDbConnection::updateNode(const NodeResultItems& nodeItems)
return false; return false;
} }
os << "UPDATE "<< TransUTFCoding(PIPENODE) <<" AS tb1 set (" << TransUTFCoding("总水头") << "," << TransUTFCoding("压力") << "," // 更新管网数据表
<< TransUTFCoding("实际需水量") << ")=(select " << TransUTFCoding(filedNames.dHead)<<"," if (!updateNodeByInterval(CurrentDate, CurrentHour))
<< TransUTFCoding(filedNames.dPressure)<<","<< TransUTFCoding(filedNames.dDemand)
<<" from "<<TransUTFCoding(NODERESULTTABLE)<<" AS tb2 where tb1."
<<TransUTFCoding(filedNames.Number)<<"= tb2."<< TransUTFCoding(filedNames.Number) <<" AND tb2."
<< TransUTFCoding(filedNames.dDate)<<"='"<<CurrentDate<<"' AND tb2."<< TransUTFCoding(filedNames.dInterval)
<<"="<<CurrentHour<<")";
std::string updateSql = os.str();
std::cout << updateSql << std::endl;
os.clear();
os.str("");
if (!execSql(updateSql))
return false; return false;
return true; return true;
} }
...@@ -250,85 +239,88 @@ bool CivDbConnection::updateLink(const LinkResultItems& lineItems) ...@@ -250,85 +239,88 @@ bool CivDbConnection::updateLink(const LinkResultItems& lineItems)
return false; return false;
} }
if (!updateLinkByInterval(CurrentDate, CurrentHour))
{ return false;
// 2, 参数值
size_t total = lineItems.size(); return true;
/* }
update
表一 bool CivDbConnection::updateNodeByInterval(StrQuote currDate, StrQuote interval)
set {
表一的字段 = 表2的字段 if (!isValid())
from return false;
表一,
表二 std::stringstream os;
where NodeFieldName filedNames;
表一.Id = 表二.Id
os << "UPDATE "
Str szNo = "编号"; << TransUTFCoding(PIPENODE) << " AS tb1 set ("
Str dFlow = " 流量"; << TransUTFCoding("总水头") << ","
Str nFlowDirect = "流向"; << TransUTFCoding("压力") << ","
Str dVelocity="流速"; << TransUTFCoding("实际需水量") << ")=(select "
Str dHeadloss="水头损失"; << TransUTFCoding(filedNames.dHead) << ","
Str dUnitHeadloss="单位水头损"; << TransUTFCoding(filedNames.dPressure) << ","
Str dFromNodHeadloss="上点水头"; << TransUTFCoding(filedNames.dDemand) << " from "
Str dToNodHeadloss="本点水头"; << TransUTFCoding(NODERESULTTABLE) << " AS tb2 where tb1."
Str dLocalHeadloss="局部水头损"; << TransUTFCoding(filedNames.Number) << "= tb2."
Str dFrictionHeadloss="摩擦水头损"; << TransUTFCoding(filedNames.Number) << " AND tb2."
Str szStatus="状态"; << TransUTFCoding(filedNames.dDate) << "='" << currDate << "' AND tb2."
Str dDate = "时间"; << TransUTFCoding(filedNames.dInterval) << "=" << interval << ")";
Str dInterval = "时段";
*/ std::string updateSql = os.str();
//os<< "update public."<< TransUTFCoding(PIPELINE)<<" as tb1 set("<< TransUTFCoding(filedNames.dFlow) std::cout << updateSql << std::endl;
// << TransUTFCoding(filedNames.dVelocity)<<TransUTFCoding(filedNames.dUnitHeadloss)<<TransUTFCoding(filedNames.dHeadloss) os.clear();
// <<TransUTFCoding(filedNames.dFrictionHeadloss)<<","<<TransUTFCoding(filedNames.dFromNodHeadloss)<<"," os.str("");
// <<TransUTFCoding(filedNames.dToNodHeadloss)<<","<<TransUTFCoding(filedNames.dLocalHeadloss); if (!execSql(updateSql))
//for (int i = 0; i < total; i++) return false;
//{
// LinkResultItem item = lineItems[i]; return true;
// char sql[512] = "update public.管段 as tb1 set("; }
// strcat_s(sql, "流量");
// strcat_s(sql, ",流速"); bool CivDbConnection::updateLinkByInterval(StrQuote currDate, StrQuote interval)
// strcat_s(sql, ",单位水头损"); {
// strcat_s(sql, ",水头总损失"); if (!isValid())
// strcat_s(sql, ",摩擦水头损"); return false;
// strcat_s(sql, ",上点水头");
// strcat_s(sql, ",本点水头"); std::stringstream os;
// strcat_s(sql, ",局部水头损"); LinkFiledName filedNames;
// strcat_s(sql, ")");
// strcat_s(sql, "=(");
os << "UPDATE "
// // 拼接值 << TransUTFCoding(PIPELINE) << " AS tb1 set ("
// strcat_s(sql, std::to_string(item.dFlow).c_str()); << TransUTFCoding("流量") << ","
// strcat_s(sql, ","); << TransUTFCoding("流速") << ","
// strcat_s(sql, std::to_string(item.dVelocity).c_str()); << TransUTFCoding("单位水头损") <<","
// strcat_s(sql, ","); << TransUTFCoding("水头总损失")<< ","
// strcat_s(sql, std::to_string(item.dUnitHeadloss).c_str()); << TransUTFCoding("摩擦水头损")<<","
// strcat_s(sql, ","); << TransUTFCoding("上点水头")<<","
// strcat_s(sql, std::to_string(item.dHeadloss).c_str()); << TransUTFCoding("本点水头")<<","
// strcat_s(sql, ","); << TransUTFCoding("局部水头损")
// strcat_s(sql, std::to_string(item.dFrictionHeadloss).c_str()); <<")=(select "
// strcat_s(sql, ","); << TransUTFCoding(filedNames.dFlow) << ","
// strcat_s(sql, std::to_string(item.dFromNodHeadloss).c_str()); << TransUTFCoding(filedNames.dVelocity) << ","
// strcat_s(sql, ","); << TransUTFCoding(filedNames.dUnitHeadloss)<<","
// strcat_s(sql, std::to_string(item.dToNodHeadloss).c_str()); << TransUTFCoding(filedNames.dFrictionHeadloss) << ","
// strcat_s(sql, ","); << TransUTFCoding(filedNames.dFromNodHeadloss) << ","
// strcat_s(sql, std::to_string(item.dLocalHeadloss).c_str()); << TransUTFCoding(filedNames.dToNodHeadloss) << ","
// strcat_s(sql, ")where tb1.\""); << TransUTFCoding(filedNames.dLocalHeadloss) << " from "
// strcat_s(sql, "编号"); << TransUTFCoding(PIPERESULTTABLE) << " AS tb2 where tb1."
// strcat_s(sql, "\"='"); << TransUTFCoding(filedNames.szNo) << "= tb2."
// strcat_s(sql, item.szNo); << TransUTFCoding(filedNames.szNo) << " AND tb2."
// strcat_s(sql, "'"); << TransUTFCoding(filedNames.dDate) << "='" << currDate << "' AND tb2."
<< TransUTFCoding(filedNames.dInterval) << "=" << interval << ")";
// // 中文转码
// const std::string finalSql = TransUTFCoding(sql); std::string updateSql = os.str();
// if (!execSql(finalSql)) std::cout << updateSql << std::endl;
// return false; os.clear();
os.str("");
} if (!execSql(updateSql))
return false;
return true; return true;
} }
Componets CivDbConnection::getComponets(StrQuote tableName) Componets CivDbConnection::getComponets(StrQuote tableName)
{ {
if (!isValid()) if (!isValid())
......
...@@ -31,9 +31,9 @@ public: ...@@ -31,9 +31,9 @@ public:
~CivDbConnection(); ~CivDbConnection();
/** /**
*@brief 获取管网的所有表 *@brief 获取管网的所有表
*@netName: 管网名 *@netName: 管网名
*/ */
Tables getTables(StrQuote netName, StrQuote schema = "public"); Tables getTables(StrQuote netName, StrQuote schema = "public");
/** /**
...@@ -53,25 +53,27 @@ public: ...@@ -53,25 +53,27 @@ public:
bool tableExist(StrQuote tableName); bool tableExist(StrQuote tableName);
/** /**
*@brief 创建表格 *@brief 创建表格
*@tableName: 表名 *@tableName: 表名
*@schema: *@schema:
*@tableType:表类型,点结果,线结果 *@tableType:表类型,点结果,线结果
*/ */
bool createTable(StrQuote tableName, StrQuote schema, TableType tableType); bool createTable(StrQuote tableName, StrQuote schema, TableType tableType);
bool deleteByDate(StrQuote table, StrQuote filedName, StrQuote fieldValue); bool deleteByDate(StrQuote table, StrQuote filedName, StrQuote fieldValue);
bool updateNodeByInterval(StrQuote currDate, StrQuote interval);
bool updateLinkByInterval(StrQuote currDate, StrQuote interval);
/** /**
*@brief 更新点表数据 *@brief 更新点表数据
*@nodeItems:需要更新的值 *@nodeItems:需要更新的值
*/ */
bool updateNode(const NodeResultItems& nodeItems); bool updateNode(const NodeResultItems& nodeItems);
/** /**
*@brief 更新线表的数据 *@brief 更新线表的数据
*@lineItems: 线数据 *@lineItems: 线数据
*/ */
bool updateLink(const LinkResultItems& lineItems); bool updateLink(const LinkResultItems& lineItems);
bool open(); bool open();
...@@ -85,27 +87,27 @@ private: ...@@ -85,27 +87,27 @@ private:
bool isValid() const; bool isValid() const;
/** /**
*@brief 查询与点连接的线 *@brief 查询与点连接的线
*@table: 线表 *@table: 线表
*@code: *@code:
*/ */
Componets getLineByCode(StrQuote table, StrQuote code); Componets getLineByCode(StrQuote table, StrQuote code);
Componets getNodeByCode(StrQuote table, StrQuote code); Componets getNodeByCode(StrQuote table, StrQuote code);
/** /**
*@brief 执行sql语句 *@brief 执行sql语句
*@sql: 需要执行的sql语句 *@sql: 需要执行的sql语句
*/ */
bool execSql(std::string sql); bool execSql(std::string sql);
void clearResult(); void clearResult();
/** /**
*@brief 从查询集取出数据 *@brief 从查询集取出数据
*@result: 查询结果集 *@result: 查询结果集
*@comp: 数据容器 *@comp: 数据容器
*/ */
void getData(PGresult* result, Componets& comp); void getData(PGresult* result, Componets& comp);
private: private:
......
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