Commit 4db5b9f4 authored by 刘乐's avatar 刘乐

1,水力模型代码整改

parent fb7f3be1
......@@ -18,21 +18,22 @@ int main(int argc, char* argv[])
char net[128];
char flag[128];
const char* file = "test.inp";
const char netName[128] = "水力模型管网";
const char netName[128] = "管网水力模型";
strcpy_s(net, "水力模型管网");
strcpy_s(flag, "QUALITY");
strcpy_s(net, "管网水力模型");
strcpy_s(flag, "HDY");
bool msg = simulation(findUri, net, flag);
bool msg = simulation(findUri, net, flag);
std::cout << msg << std::endl;
getchar();
/* const char* date = "2020-06-19";
char* dates = const_cast<char*>(date);
const char* interval = "0";
/*const char* date = "2020-6-29";
char* dates = const_cast<char*>(date);
const char* interval = "13";
char* intervals = const_cast<char*>(interval);
getDataByInterval(findUri, dates, intervals);*/
// std::cout << flag << std::endl;
bool isSucces = getDataByInterval(findUri, dates, intervals);
std::cout << isSucces << std::endl;*/
getchar();
return 0;
}
\ No newline at end of file
This diff is collapsed.
#ifndef _CIVINPEXPOTER_H
#define _CIVINPEXPOTER_H
#include "CivPgConn.h"
#include "CivInp.h"
#include "CivNewInp.h"
/**
......@@ -12,7 +11,7 @@ class CivBuilder
public:
CivBuilder();
~CivBuilder();
virtual ~CivBuilder();
virtual void buildNode() = 0;
virtual void buildPipe() = 0;
virtual void buildTank() = 0;
......@@ -35,12 +34,10 @@ public:
virtual void buildControls() = 0;
virtual void buildRules() = 0;
virtual void buildDemands() = 0;
virtual CivNewInp* getNewInp();
protected:
CivNewInp* mNewInp;
};
......@@ -57,18 +54,6 @@ public:
// 注册数据库连接
void registDb(CivDbConn* dbConn);
/**
*@brief 导出inp文件
*/
bool exportInp(char* fileName);
/**
*@brief 解析表字段名,按顺序写入
*@table:表
*@inp: inp文件对象
*/
void builder(StrQuote table, CivInp& inp);
virtual void buildNode();
virtual void buildPipe();
virtual void buildTank();
......
......@@ -211,11 +211,12 @@ bool CivHydrCalc::exportInp(char* fileName)
if (!mDbConn->open())
return false;
bool pattern = mDbConn->createTable(PATTERNTABLE, "public", CivTableTemp::PATTERN_TABLE);
/*bool pattern = mDbConn->createTable(*CivPatternTableTemp());
bool cii = mDbConn->createTable(OPTIONTTABLE, "public", CivTableTemp::PARAMETER_TABLE);
bool curve = mDbConn->createTable(CURVETABLE, "public", CivTableTemp::CURVE_TABLE);
bool node = mDbConn->createTable(NODERESULTTABLE, "public", CivTableTemp::NODE_TABLE);
bool link = mDbConn->createTable(PIPERESULTTABLE, "public", CivTableTemp::PIPE_TABLE);
bool link = mDbConn->createTable(PIPERESULTTABLE, "public", CivTableTemp::PIPE_TABLE);*/
// 获取表格
Tables tables = mDbConn->getTables(mNetname);
......
......@@ -24,6 +24,22 @@ bool DLLEXPORT simulation(char* uri, char* netName, char* flag)
return msg;
}
bool DLLEXPORT hdySimulation(char* uri, char* netName)
{
return true;
}
bool DLLEXPORT qualitySimulation(char* uri, char* netName, char* type)
{
return true;
}
bool DLLEXPORT qualityTrackingSimulation(char* uri, char* netName, char* nodeSn)
{
return true;
}
bool DLLEXPORT getDataByInterval(char* uri, char* date, char* interval)
{
CivHydrCalc* calc = new CivHydrCalc(uri, "");
......
#pragma once
#include<string>
#ifndef CIVHYDRFUNCINTER_H
#define CIVHYDRFUNCINTER_H
#define DLLEXPORT __declspec(dllexport)
#if defined(__cplusplus)
......@@ -11,7 +11,31 @@ extern "C" {
*@netName: 管网名
*@flag: 标记
*/
bool DLLEXPORT simulation(char* uri, char* netName,char* flag);
bool DLLEXPORT simulation(char* uri, char* netName, char* flag);
/**
*@brief 水力模拟计算
*@uri: 管网数据库连接
*@netName: 管网名
*/
bool DLLEXPORT hdySimulation(char* uri, char* netName);
/**
*@brief 水力模拟计算
*@uri: 管网数据库连接
*@netName: 管网名
*@type: 水质模拟类型选择,水龄,追踪,化学成分
*/
bool DLLEXPORT qualitySimulation(char* uri, char* netName, char* type);
/**
*@brief 水质追踪模拟计算
*@uri: 管网数据库连接
*@netName: 管网名
*@nodeSn: 追踪节点编号
*/
bool DLLEXPORT qualityTrackingSimulation(char* uri, char* netName, char* nodeSn);
/**
*@brief 获取管网计算特定时段的结果
......@@ -25,3 +49,7 @@ extern "C" {
}
#endif
#endif // ! CIVHYDRFUNCINTER_H
#ifndef CIVMIDDLEWAREQUERY_H
#define CIVMIDDLEWAREQUERY_H
/**
ݿѯ
*/
class CivMiddlewareQuery
{
public:
};
#endif // !CIVMIDDLEWAREQUERY_H
......@@ -153,7 +153,6 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\pandaDbManager\CivCommonUtils.cpp" />
<ClCompile Include="CivAssembly.cpp" />
<ClCompile Include="CivHydrCalc.cpp" />
<ClCompile Include="CivHydrFuncInter.cpp" />
<ClCompile Include="CivInp.cpp" />
......@@ -163,12 +162,12 @@
<ClCompile Include="CivSimulResultCache.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="CivAssembly.h" />
<ClInclude Include="CivHydrCalc.h" />
<ClInclude Include="CivHydrFuncInter.h" />
<ClInclude Include="CivInp.h" />
<ClInclude Include="CivBuilder.h" />
<ClInclude Include="CivInpDirector.h" />
<ClInclude Include="CivMiddlewareQuery.h" />
<ClInclude Include="CivNewInp.h" />
<ClInclude Include="CivSimulResultCache.h" />
</ItemGroup>
......
......@@ -27,9 +27,6 @@
<ClCompile Include="..\pandaDbManager\CivCommonUtils.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="CivAssembly.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="CivBuilder.cpp">
<Filter>源文件</Filter>
</ClCompile>
......@@ -53,9 +50,6 @@
<ClInclude Include="CivHydrFuncInter.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivAssembly.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivNewInp.h">
<Filter>头文件</Filter>
</ClInclude>
......@@ -68,5 +62,8 @@
<ClInclude Include="CivSimulResultCache.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivMiddlewareQuery.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
#include "CivAssembly.h"
Str CivAssembly::toString()
{
return Str();
}
void CivNode::addItem(NodeTable table)
void CivNode::addItem(const NodeTable& table)
{
mTables.push_back(table);
}
void CivPipe::addItem(PipesTable table)
void CivPipe::addItem(const PipesTable& table)
{
mTables.push_back(table);
}
void CivTank::addItem(TankTable table)
void CivTank::addItem(const TankTable& table)
{
mTables.push_back(table);
}
void CivValve::addItem(ValveTable table)
void CivValve::addItem(const ValveTable& table)
{
mTables.push_back(table);
}
void CivPumps::addItem(PumpTable table)
void CivPumps::addItem(const PumpTable& table)
{
mTables.push_back(table);
}
void CivReservoirs::addItem(ReservoirsTable table)
void CivReservoirs::addItem(const ReservoirsTable& table)
{
mTables.push_back(table);
}
void CivEmitters::addItem(EmittersTable table)
void CivEmitters::addItem(const EmittersTable& table)
{
mTables.push_back(table);
}
void CivCoordinates::addItem(CoordTable table)
void CivCoordinates::addItem(const CoordTable& table)
{
mTables.push_back(table);
}
void CivMixing::addItem(MixingTable table)
void CivMixing::addItem(const MixingTable& table)
{
mTables.push_back(table);
}
void CivParameter::addItem(ParamTable table)
void CivParameter::addItem(const ParamTable& table)
{
mTables.push_back(table);
}
void CivPatterns::addItem(PatternTable table)
void CivPatterns::addItem(const PatternTable& table)
{
mTables.push_back(table);
}
void CivCurves::addItem(CurvesTable table)
void CivCurves::addItem(const CurvesTable& table)
{
mTables.push_back(table);
}
void CivDemands::addItem(DemandsTable table)
void CivDemands::addItem(const DemandsTable& table)
{
mTables.push_back(table);
}
void CivSources::addItem(CurvesTable table)
void CivSources::addItem(const CurvesTable& table)
{
mTables.push_back(table);
}
void CivStatus::addItem(StatusTable table)
void CivStatus::addItem(const StatusTable& table)
{
mTables.push_back(table);
}
void CivQuality::addItem(QualityTable table)
void CivQuality::addItem(const QualityTable& table)
{
mTables.push_back(table);
}
void CivLabels::addItem(LabelTable table)
void CivLabels::addItem(const LabelTable& table)
{
mTables.push_back(table);
}
void CivTags::addItem(TagsTable table)
void CivTags::addItem(const TagsTable& table)
{
mTables.push_back(table);
}
\ No newline at end of file
......@@ -2,6 +2,8 @@
#define CIVASSEMBLY_H
#include "CivTypes.h"
#include <list>
#pragma warning(disable:4251)
#define DBEXPORT __declspec(dllexport)
class CivAssembly;
class CivNode;
......@@ -25,7 +27,7 @@ class CivAssembly
/**
节点类型
*/
class CivNode: public CivAssembly
class DBEXPORT CivNode: public CivAssembly
{
public:
typedef struct Table
......@@ -37,24 +39,14 @@ public:
Str PatternId;
} NodeTable;
// 定义字段中文映射
typedef struct TableField
{
Str ID;
Str Elev;
Str Demand;
Str PatternId;
}NodeTableField;
void addItem(NodeTable table);
void addItem(const NodeTable& table);
std::list<NodeTable> mTables;
};
/**
* 管线类型
*/
class CivPipe: public CivAssembly
class DBEXPORT CivPipe: public CivAssembly
{
public:
typedef struct Table
......@@ -70,7 +62,7 @@ public:
Str Status;
} PipesTable;
void addItem(PipesTable table);
void addItem(const PipesTable& table);
std::list<PipesTable> mTables;
};
......@@ -78,7 +70,7 @@ public:
/*
水池类型
*/
class CivTank:public CivAssembly
class DBEXPORT CivTank:public CivAssembly
{
public:
typedef struct Table
......@@ -94,14 +86,14 @@ public:
Str VolCurve;
} TankTable;
void addItem(TankTable table);
void addItem(const TankTable& table);
std::list<TankTable> mTables;
};
/*
定义包含在管网中所有控制阀门。
*/
class CivValve :public CivAssembly
class DBEXPORT CivValve :public CivAssembly
{
public:
typedef struct Table
......@@ -124,14 +116,14 @@ public:
Str MinorLoss;
} ValveTable;
void addItem(ValveTable table);
void addItem(const ValveTable& table);
std::list<ValveTable> mTables;
};
/**
水泵
*/
class CivPumps :public CivAssembly
class DBEXPORT CivPumps :public CivAssembly
{
public:
typedef struct Table
......@@ -143,14 +135,14 @@ public:
Str Parameters;
} PumpTable;
void addItem(PumpTable table);
void addItem(const PumpTable& table);
std::list<PumpTable> mTables;
};
/*
定义管网中包含的所有水库节点
*/
class CivReservoirs :public CivAssembly
class DBEXPORT CivReservoirs :public CivAssembly
{
public:
typedef struct Table
......@@ -165,7 +157,7 @@ public:
Str Pattern;
} ReservoirsTable;
void addItem(ReservoirsTable table);
void addItem(const ReservoirsTable& table);
std::list<ReservoirsTable> mTables;
};
......@@ -173,7 +165,7 @@ public:
/**
EMITTERS将模拟节点定义为扩散器(喷嘴或者孔口)。
*/
class CivEmitters :public CivAssembly
class DBEXPORT CivEmitters :public CivAssembly
{
public:
typedef struct Table
......@@ -186,14 +178,14 @@ public:
Str coeff;
} EmittersTable;
void addItem(EmittersTable table);
void addItem(const EmittersTable& table);
std::list<EmittersTable> mTables;
};
/**
坐标
*/
class CivCoordinates :public CivAssembly
class DBEXPORT CivCoordinates :public CivAssembly
{
public:
typedef struct Table
......@@ -204,14 +196,14 @@ public:
Str YCoord;
} CoordTable;
void addItem(CoordTable table);
void addItem(const CoordTable& table);
std::list<CoordTable> mTables;
};
/**
参数控制选项
*/
class CivMixing :public CivAssembly
class DBEXPORT CivMixing :public CivAssembly
{
public:
typedef struct Table
......@@ -226,14 +218,14 @@ public:
Str volume;
} MixingTable;
void addItem(MixingTable table);
void addItem(const MixingTable& table);
std::list<MixingTable> mTables;
};
/**
确定控制蓄水池混合的模型。
*/
class CivParameter :public CivAssembly
class DBEXPORT CivParameter :public CivAssembly
{
public:
typedef struct Table
......@@ -249,7 +241,7 @@ public:
Str val;
} ParamTable;
void addItem(ParamTable table);
void addItem(const ParamTable& table);
void setType(const std::string& type) { mType = type; }
std::string mType;
......@@ -259,7 +251,7 @@ public:
/**
模式
*/
class CivPatterns :public CivAssembly
class DBEXPORT CivPatterns :public CivAssembly
{
public:
typedef struct Table
......@@ -268,14 +260,14 @@ public:
Str val; // 模式值
} PatternTable;
void addItem(PatternTable table);
void addItem(const PatternTable& table);
std::list<PatternTable> mTables;
};
/*
定义数据曲线及其X、Y点。
*/
class CivCurves :public CivAssembly
class DBEXPORT CivCurves :public CivAssembly
{
public:
typedef struct Table
......@@ -285,14 +277,14 @@ public:
Str YCoord; // Y数值
} CurvesTable;
void addItem(CurvesTable table);
void addItem(const CurvesTable& table);
std::list<CurvesTable> mTables;
};
/**
定义连接节点的多模式需水,是对[JUNCTIONS]的补充。
*/
class CivDemands :public CivAssembly
class DBEXPORT CivDemands :public CivAssembly
{
public:
typedef struct Table
......@@ -309,12 +301,12 @@ public:
Str DemandType;
} DemandsTable;
void addItem(DemandsTable table);
void addItem(const DemandsTable& table);
std::list<DemandsTable> mTables;
};
// 定义水质源头的位置。
class CivSources :public CivAssembly
class DBEXPORT CivSources :public CivAssembly
{
public:
typedef struct Table
......@@ -331,12 +323,12 @@ public:
Str Pattern;
} CurvesTable;
void addItem(CurvesTable table);
void addItem(const CurvesTable& table);
std::list<CurvesTable> mTables;
};
// 定义模拟开始时被选管段的初始状态。
class CivStatus :public CivAssembly
class DBEXPORT CivStatus :public CivAssembly
{
public:
typedef struct Table
......@@ -349,12 +341,12 @@ public:
Str Setting;
} StatusTable;
void addItem(StatusTable table);
void addItem(const StatusTable& table);
std::list<StatusTable> mTables;
};
// 定义节点的初始水质。
class CivQuality :public CivAssembly
class DBEXPORT CivQuality :public CivAssembly
{
public:
typedef struct Table
......@@ -367,12 +359,12 @@ public:
Str InitQuality;
} QualityTable;
void addItem(QualityTable table);
void addItem(const QualityTable& table);
std::list<QualityTable> mTables;
};
// 给地图标签赋以坐标值。
class CivLabels :public CivAssembly
class DBEXPORT CivLabels :public CivAssembly
{
public:
typedef struct Table
......@@ -389,13 +381,13 @@ public:
Str ID;
} LabelTable;
void addItem(LabelTable table);
void addItem(const LabelTable& table);
std::list<LabelTable> mTables;
};
// 将类型标签与特定节点和管段相连。
class CivTags :public CivAssembly
class DBEXPORT CivTags :public CivAssembly
{
public:
typedef struct Table
......@@ -410,7 +402,7 @@ public:
Str Label;
} TagsTable;
void addItem(TagsTable table);
void addItem(const TagsTable& table);
std::list<TagsTable> mTables;
};
......
......@@ -157,58 +157,61 @@ bool CivDbConn::updateNode(const NodeResultItems& nodeItems)
std::stringstream os;
NodeFieldName filedNames;
if (createTable(NODERESULTTABLE, "public", CivTableTemp::NODE_TABLE))
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++)
{
os << "INSERT INTO " << 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.dModifyTime;
os << ") VALUES";
std::string preSql = os.str();
os.flush();
os.clear();
os.str("");
//// 2, 参数值
//size_t total = nodeItems.size();
//for (int i = 0; i < total; i++)
//{
// NodeResultItem item = nodeItems[i];
// 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 << "'" << CurrentTime << "'";
// if (i == (total - 1))
// {
// os << ")";
// }
// else
// {
// os << "),";
// }
//}
//std::string sql = TransUTFCoding(preSql) + os.str();
//os.clear();
//os.str("");
//if (!execSql(sql))
// return false;
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;
}
......@@ -218,69 +221,67 @@ bool CivDbConn::updateLink(const LinkResultItems& lineItems)
if (!isValid())
return false;
//std::stringstream os;
//LinkFiledName filedNames;
//std::string currData = CurrentDate;
//if (createTable(PIPERESULTTABLE, "public", CivTableTemp::PIPE_TABLE))
//{
// 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.dModifyTime;
// os << ") VALUES";
// std::string preSql = os.str();
// os.clear();
// os.str("");
// // 2, 参数值
// size_t total = lineItems.size();
// for (int i = 0; i < total; i++)
// {
// LinkResultItem item = lineItems[i];
// 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 << "'" << CurrentTime << "'";
// if (i == (total - 1))
// os << ")";
// else
// os << "),";
// }
// std::string utf8Sql = TransUTFCoding(preSql);
// std::string sql = utf8Sql + os.str();
// os.clear();
// os.str("");
// if (!execSql(sql))
// 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;
}
......@@ -435,15 +436,13 @@ Componets CivDbConn::getLikelyPipes(StrQuote tableName)
return nodes;
}
bool CivDbConn::createTable(StrQuote tableName, StrQuote schema, CivTableTemp::TableType tableType)
bool CivDbConn::createTable(CivTableTemp& temp)
{
if (tableExist(tableName))
return true;
CivTableTemp tableTemp(tableName, tableType);
if (&temp == NULL)
return false;
Str sql = tableTemp.createSql();
Str sql = temp.createSql();
Str finalSql = TransUTFCoding(sql);
return execSql(finalSql);
}
\ No newline at end of file
}
#ifndef CIVDBCONN_H
#define CIVDBCONN
#include "CivTypes.h"
#include "CivAssembly.h"
#include "CivTableTemp.h"
#define DBEXPORT __declspec(dllexport)
......@@ -14,6 +15,26 @@ public:
CivDbConn();
virtual ~CivDbConn();
// 获取组件对象
virtual bool getNode(CivNode& node)=0;
virtual bool getPipe(CivPipe& pipe)=0;
virtual bool getTank(CivTank& tank)=0;
virtual bool getValve(CivValve& valve)=0;
virtual bool getPumps(CivPumps& pump)=0;
virtual bool getReservoirs(CivReservoirs& reservoirs)=0;
virtual bool getEmitters(CivEmitters& emitter)=0;
virtual bool getCoordinates(CivCoordinates& coord)=0;
virtual bool getMixing(CivMixing& mixing)=0;
virtual bool getParameter(CivParameter& params)=0;
virtual bool getPatterns(std::vector<CivPatterns>& patterns)=0;
virtual bool getCurves(CivCurves& curves)=0;
virtual bool getDemands(CivDemands& demands)=0;
virtual bool getSources(CivSources& sources)=0;
virtual bool getStatus(CivStatus& status)=0;
virtual bool getQuality(CivQuality& quality)=0;
virtual bool getLabels(CivLabels& labels)=0;
virtual bool getTags(CivTags& tags)=0;
/**
*@brief 连接数据库,与具体的数据有关子类实现
*/
......@@ -23,11 +44,6 @@ public:
*@brief 关闭数据库连接,与具体的数据有关子类实现
*/
virtual void close() = 0;
/**
*@brief 获取管网的所有表,与具体数据库相关,子类实现
*@netName: 管网名
*/
virtual Tables getTables(StrQuote netName, StrQuote schema) = 0;
/**
*@brief 判断某张表是否存在,判断方法跟具体的数据库有关,延迟到子类实现
......@@ -41,7 +57,9 @@ public:
*@schema:
*@tableType:表类型,点结果,线结果
*/
bool createTable(StrQuote tableName, StrQuote schema, CivTableTemp::TableType tableType);
bool createTable(CivTableTemp& temp);
bool isValid() const;
private:
......@@ -91,9 +109,6 @@ private:
// 获取当前执行错误信息
Str getLastError() const;
bool isValid() const;
/**
*@brief 根据code值寻数据
*@table: 线表
......
......@@ -250,10 +250,12 @@ bool CivDbConnection::updateNodeByInterval(StrQuote currDate, StrQuote interval)
<< TransUTFCoding(PIPENODE) << " AS tb1 set ("
<< TransUTFCoding("总水头") << ","
<< TransUTFCoding("压力") << ","
<< TransUTFCoding("实际需水量")
<< TransUTFCoding("实际需水量")<<","
<<TransUTFCoding("水质")
<< ")=( "
<< "tb2." << TransUTFCoding(filedNames.dHead) << ","
<< "tb2." << TransUTFCoding(filedNames.dPressure) << ","
<< "tb2." << TransUTFCoding(filedNames.dQuality) << ","
<< "tb2." << TransUTFCoding(filedNames.dDemand) << ")" << " from "
<< TransUTFCoding(NODERESULTTABLE) << " AS tb2 where tb1."
<< TransUTFCoding(filedNames.Number) << "= tb2."
......@@ -289,6 +291,7 @@ bool CivDbConnection::updateLinkByInterval(StrQuote currDate, StrQuote interval)
<< TransUTFCoding("摩擦水头损")<<","
<< TransUTFCoding("上点水头")<<","
<< TransUTFCoding("本点水头")<<","
<< TransUTFCoding("水质") << ","
<< TransUTFCoding("局部水头损")
<<")=( "
<< "tb2." <<TransUTFCoding(filedNames.dFlow) << ","
......@@ -298,6 +301,7 @@ bool CivDbConnection::updateLinkByInterval(StrQuote currDate, StrQuote interval)
<< "tb2." << TransUTFCoding(filedNames.dFrictionHeadloss) << ","
<< "tb2." << TransUTFCoding(filedNames.dFromNodHeadloss) << ","
<< "tb2." << TransUTFCoding(filedNames.dToNodHeadloss) << ","
<< "tb2." << TransUTFCoding(filedNames.dQuality) << ","
<< "tb2." << TransUTFCoding(filedNames.dLocalHeadloss) <<")"<< " from "
<< TransUTFCoding(PIPERESULTTABLE) << " AS tb2 where tb1."
<< TransUTFCoding(filedNames.szNo) << "= tb2."
......@@ -550,14 +554,12 @@ FiledFilter CivDbConnection::getFilter() const
return mFilter;
}
bool CivDbConnection::createTable( StrQuote tableName, StrQuote schema, CivTableTemp::TableType tableType)
bool CivDbConnection::createTable(CivTableTemp& temp)
{
if (tableExist(tableName))
return true;
if (&temp == NULL)
return false;
CivTableTemp tableTemp(tableName,tableType);
Str sql = tableTemp.createSql();
Str sql = temp.createSql();
Str finalSql = TransUTFCoding(sql);
return execSql(finalSql);
......
......@@ -7,8 +7,6 @@
#define DLLEXPORT __declspec(dllexport)
class CivDbConnection;
/**
......@@ -48,7 +46,7 @@ public:
*@schema:
*@tableType:表类型,点结果,线结果
*/
bool createTable(StrQuote tableName, StrQuote schema,CivTableTemp::TableType tableType);
bool createTable(CivTableTemp& temp);
bool deleteByDate(StrQuote table, StrQuote filedName, StrQuote fieldValue);
......
This diff is collapsed.
......@@ -24,11 +24,6 @@ private:
*@brief 关闭数据库连接,与具体的数据有关子类实现
*/
virtual void close();
/**
*@brief 获取管网的所有表,与具体数据库相关,子类实现
*@netName: 管网名
*/
virtual Tables getTables(StrQuote netName, StrQuote schema);
/**
*@brief 判断某张表是否存在,判断方法跟具体的数据库有关,延迟到子类实现
......@@ -41,22 +36,28 @@ private:
*@sql: 需要执行的sql语句
*/
virtual bool execSql(Str sql);
/**
*@brief 清除查询结果集数据
*/
virtual void clearResult();
/**
*@brief 从查询集取出数据
*@result: 查询结果集
*@comp: 数据容器
*/
virtual void getData(Componets& comp);
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) ;
private:
PGconn* mConn;
PGresult* mResult;
PGconn* mConn; // 连接对象
PGresult* mResult; // 查询结果集
char* mUri;
};
......
This diff is collapsed.
......@@ -7,31 +7,20 @@
#include "CivTypes.h"
typedef struct FieldProperty
struct FieldProperty
{
std::string mFiledName; //字段名
std::string mFieldType; // 字段类型
};
#define FiledPropertys std::vector<FieldProperty>
class CivDbConn;
/**
* 数据库表模板
*/
class CivTableTemp
{
public:
// 表类型
enum TableType
{
NODE_TABLE, // 计算结果点表
PIPE_TABLE, // 计算结果线表
PATTERN_TABLE, // 模式表
CURVE_TABLE, //曲线表
PARAMETER_TABLE // 参数表
};
// 字段类型
enum FieldType {
FILED_INT,
......@@ -45,26 +34,32 @@ public:
FILED_DATE
};
explicit CivTableTemp(Str tableName);
explicit CivTableTemp();
~CivTableTemp();
// 返回创建表的sql语句
Str createSql();
/*
* @brief 表名
*/
Str name() const { return mTableName; }
void setName(StrQuote name) { mTableName = name; }
/**
*@brief 添加字段属性
*@fileName:字段名
*@filedType:字段类型
*/
virtual void addProperty(std::string fileName, FieldType filedType);
// 添加批量属性字段
void addPropertys(FiledPropertys props);
void addProperty(std::string fileName, FieldType filedType);
// 返回创建表的sql语句
Str createSql();
/*
* @brief 表名
/**
*@brief 数据库创建模板表
*@dbConn: 数据库连接对象
*/
Str name();
bool updateToDb(CivDbConn* dbConn);
protected:
Str mTableName; // 表名
......@@ -101,9 +96,10 @@ public:
Str compType = "组分类型";
Str pressure = "压力";
Str quality = "水质";
};
Str initQuality = "初始水质";
}JunctionTable;
CivJunctionTableTemp(Str tableName);
explicit CivJunctionTableTemp(Str tableName);
};
......@@ -154,8 +150,8 @@ public:
Str modifyTime = "modify_time";
Str remarks = "备注";
Str quality = "水质";
};
CivPipeTableTemp();
}PipeTable;
explicit CivPipeTableTemp();
};
/**
......@@ -164,7 +160,7 @@ public:
class CivPumpTableTemp :public CivTableTemp
{
public:
typedef struct TableFiled
typedef struct TableFileds
{
Str ID = "id";
Str geom = "geom";
......@@ -173,15 +169,10 @@ public:
Str yCoord = "纵坐标";
Str startPoint = "起始节点";
Str endPoint = "终止节点";
Str ID = "下游管段";
Str ID = "高程";
Str ID = "水泵状态";
Str ID = "水泵曲线";
Str ID = "转速比";
Str ID = "流量";
Str ID = "入口水头";
Str ID = "出口水头";
Str pattern = "扬程曲线";
Str curve = "水泵曲线";
Str ratio = "转速比";
Str flow = "流量";
Str headCurve = "扬程曲线";
Str status = "状态";
Str code = "code";
Str createUser = "create_user";
......@@ -190,9 +181,9 @@ public:
Str modifyTime = "modify_time";
Str SymbolAngle = "symbol_angle";
Str compType = "组分类型";
Str ID = "功率";
};
CivPumpTableTemp();
Str power = "功率";
} PumpTable;
explicit CivPumpTableTemp();
};
/**
......@@ -201,7 +192,7 @@ public:
class CivTankTableTemp :public CivTableTemp
{
public:
typedef struct TableField
typedef struct TableFileds
{
Str ID = "id";
Str geom = "geom";
......@@ -218,6 +209,7 @@ public:
Str flowOut = "输出流量";
Str leveHeight = "液位高度";
Str capacity = "容量";
Str volCurve = "容积曲线";
Str percentage = "装满水池百";
Str status = "状态";
Str code = "code";
......@@ -227,8 +219,8 @@ public:
Str modifyTime = "modify_time";
Str SymbolAngle = "symbol_angle";
Str compType = "组分类型";
};
CivTankTableTemp();
}TankTable;
explicit CivTankTableTemp();
};
/**
......@@ -237,7 +229,7 @@ public:
class CivResourcesTableTemp :public CivTableTemp
{
public:
typedef struct TableField
typedef struct TableFileds
{
Str ID = "id";
Str geom = "geom";
......@@ -255,8 +247,8 @@ public:
Str modifyTime = "modify_time";
Str SymbolAngle = "symbol_angle";
Str compType = "组分类型";
};
CivResourcesTableTemp();
}ResourcesTable;
explicit CivResourcesTableTemp();
};
/**
......@@ -266,7 +258,7 @@ class CivValveTableTemp :public CivTableTemp
{
public:
typedef struct TableField
typedef struct TableFileds
{
Str id = "本点号";
Str geom = "geom";
......@@ -289,8 +281,111 @@ public:
Str modifyTime = "modify_time" ;
Str symbolAngle= "symbol_angle";
Str compType = "组分类型";
};
CivValveTableTemp();
}ValveTable;
explicit CivValveTableTemp();
};
/**
节点模拟结果存储表
*/
class CivNodeResultTableTemp :public CivTableTemp
{
public:
typedef struct TableField
{
Str Number = "本点号";
Str dFlow = "流量";
Str dHead = "水头";
Str dPressure = "压力";
Str dElevation = "标高";
Str dDemand = "实际需水量";
Str dTankVolume = "水池容量";
Str dTankMaxVolume = "水池最大容量";
Str dTankLevel = "液位高度";
Str dQuality = "水质";
Str dDate = "日期";
Str dInterval = "时段";
Str dModifyTime = "修改时间";
} NodeResultTable;
explicit CivNodeResultTableTemp();
};
/**
模拟结果线表
*/
class CivPipeResultTableTemp :public CivTableTemp
{
public:
typedef struct TableField
{
Str szNo = "编号";
Str dFlow = "流量";
Str nFlowDirect = "流向";
Str dVelocity = "流速";
Str dHeadloss = "水头损失";
Str dUnitHeadloss = "单位水头损";
Str dFromNodHeadloss = "上点水头";
Str dToNodHeadloss = "本点水头";
Str dLocalHeadloss = "局部水头损";
Str dFrictionHeadloss = "摩擦水头损";
Str szStatus = "状态";
Str dQuality = "水质";
Str dDate = "日期";
Str dInterval = "时段";
Str dModifyTime = "修改时间";
}PipeResultTable;
explicit CivPipeResultTableTemp();
};
/**
模式表
*/
class CivPatternTableTemp :public CivTableTemp
{
public:
typedef struct TableField
{
Str Name = "模式名";
Str Value = "系数";
Str time = "时段";
Str type = "类型";
} PatternTable;
explicit CivPatternTableTemp();
};
/**
参数表
*/
class CivParametorTableTemp :public CivTableTemp
{
public:
typedef struct TableField
{
Str name = "参数名";
Str val = "参数值";
Str type = "参数类型";
Str netName = "管网名";
}ParametorTable;
explicit CivParametorTableTemp();
};
/**
曲线表
*/
class CivCurveTableTemp :public CivTableTemp
{
public:
typedef struct TableField
{
Str Label = "曲线名";
Str XCoord = "x";
Str YCoord = "y";
Str Type = "类型";
}CurveTable;
explicit CivCurveTableTemp();
};
#endif // !CIVTABLETEMP_H
......
......@@ -16,6 +16,7 @@ typedef const std::string& StrQuote;
#define RESIVOIR Str("水库")
#define TANK Str("水池")
#define PUMP Str("水泵")
#define VALVE Str("阀门")
#define NODERESULTTABLE Str("__node_result__")
#define PIPERESULTTABLE Str("__pipe_result__")
......@@ -195,7 +196,7 @@ struct TanksFields {
Str MaxLevel = "最高水位";
Str Diameter = "直径";
Str MinVol = "容量";
Str VolCurve = "容积";
Str VolCurve = "容积曲线";
Str X_Coord = "横坐标";
Str Y_Coord = "纵坐标";
};
......
......@@ -152,10 +152,12 @@
<Command>copy CivDbConnection.h $(OutDir)..\include /y
copy CivTypes.h $(OutDir)..\include /y
copy CivPgConn.h $(OutDir)..\include /y
copy CivAssembly.h $(OutDir)..\include /y
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="CivAssembly.h" />
<ClInclude Include="CivCommonUtils.h" />
<ClInclude Include="CivDbConn.h" />
<ClInclude Include="CivDbConnection.h" />
......@@ -164,6 +166,7 @@ copy CivPgConn.h $(OutDir)..\include /y
<ClInclude Include="CivTypes.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="CivAssembly.cpp" />
<ClCompile Include="CivCommonUtils.cpp" />
<ClCompile Include="CivDbConn.cpp" />
<ClCompile Include="CivDbConnection.cpp" />
......
......@@ -33,6 +33,9 @@
<ClInclude Include="CivPgConn.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivAssembly.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CivDbConnection.cpp">
......@@ -50,5 +53,8 @@
<ClCompile Include="CivPgConn.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="CivAssembly.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
--参数--
CREATE TABLE public.__parameter__
(
id serial primary key,
"参数名" character varying(64),
"参数值" character varying(128),
"参数类型" character varying(20),
"管网名" character varying(64)
);
--模式表--
CREATE TABLE public.__pattern__
(
id serial primary key,
"模式名" character varying(64),
"时段" integer,
"系数" double precision,
"类型" integer
)
--曲线表--
CREATE TABLE public.__curve__
(
id serial primary key,
"曲线名" character varying(64),
"类型" character varying(64),
x double precision,
y double precision
)
--结果点表--
CREATE TABLE public.__node_result__
(
id serial primary key,
"本点号" character varying(20),
"类型" integer,
"压力" double precision,
"水头" double precision,
"标高" double precision,
"实际需水量" double precision,
"水池容量" double precision,
"水池最大容量" double precision,
"液位高度" double precision,
"水质" double precision,
"时间" timestamp without time zone
)
--结果线表--
CREATE TABLE public.__pipe_result__
(
id serial primary key,
"编号" character varying(20),
"流量" double precision,
"流向" integer,
"流速" double precision,
"水头损失" double precision,
"单位水头损" double precision,
"上点水头" double precision,
"本点水头" double precision,
"局部水头损" double precision,
"摩擦水头损" double precision,
"状态" character varying(20),
"水质" double precision,
"时间" timestamp without time zone
)
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