Commit cb17f35f authored by 刘乐's avatar 刘乐

1, 新增接口

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