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
......@@ -3,7 +3,7 @@
CivBuilder::CivBuilder()
{
mNewInp = nullptr;
}
CivBuilder::~CivBuilder()
......@@ -44,367 +44,9 @@ void CivInpBuilder::registDb(CivDbConn* dbConn)
mDbConn = dbConn;
}
bool CivInpBuilder::exportInp(char* fileName)
{
//1 ,获取管网组件
if (!mDbConn)
return false;
if (!mDbConn->open())
return false;
bool pattern = mDbConn->createTable(PATTERNTABLE, "public", CivTableTemp::PATTERN_TABLE);
bool cii = mDbConn->createTable(OPTIONTTABLE, "public", CivTableTemp::PARAMETER_TABLE);
// 获取表格
Tables tables = mDbConn->getTables("进贤","public");
//2,解析管网组件
// 解析管网组件顺序: 管线放最后
CivInp civInp(CivInp::HOURS);
int total = tables.size();
for (int i = 0; i < total; i++)
{
std::string table = tables[i];
if (PIPELINE == table)
continue;
builder(table, civInp);
}
builder(PIPELINE, civInp);
// 设置曲线
// Componets curves = mDbConn->getComponets(CURVETABLE);
// 初始化参数
Options options;
options.units = Options::UNITS::LPS;
options.TRIALS = "40";
options.ACCURACY = "0.001 ";
options.EMITTEREXPONENT = "0.5";
options.SpecificGravity = "0.998";
options.headLoss = Options::HEADLOSS::HW;
options.TOLERANCE = "0.0166666666666667 ";
options.quality = Options::QUALITY::AGE;
std::map<std::string, std::string> optMap;
optMap.insert(std::pair<std::string, std::string>("DAMPLIMIT", "0"));
optMap.insert(std::pair<std::string, std::string>("CHECKFREQ", "2"));
optMap.insert(std::pair<std::string, std::string>("MAXCHECK", "10"));
civInp.setOption(options, optMap);
// 设置
civInp.setDuration(24);
civInp.setTimestep("PATTERN", 1);
civInp.setTimestep("HYDRAULIC", 1);
civInp.setTimestep("QUALITY", 1);
civInp.setTimeStart("REPORT", 1);
civInp.writeToFile(fileName);
return true;
}
void CivInpBuilder::builder(StrQuote table, CivInp& inp)
{
// 根据组建类型解析字段
if (PIPELINE == table)
{
// 管线
//;ID Node1 Node2 Length Diameter Roughness MinorLoss Status
// 必备参数
Componets comps = mDbConn->getComponets(table);
PipeFields pipes;
Civitems items;
int total = comps.size();
for (int i = 0; i < total; i++)
{
Componet comp = comps[i];
// 过滤掉与阀门和水泵连接的管线
Str number = comp.find("id")->second;
FiledFilter filter = mDbConn->getFilter();
auto iter = filter.find(PIPELINE);
if (iter != filter.end())
{
auto lineFilter = iter->second;
if (lineFilter.count(number) > 0)
continue;
}
Str id = comp.find(pipes.ID)->second;
Str startNode = comp.find(pipes.Node1)->second;
Str endNode = comp.find(pipes.Node2)->second;
Str length = comp.find(pipes.Length)->second;
Str diameter = comp.find(pipes.Diameter)->second;
Str roughness = comp.find(pipes.Roughness)->second;
Str minorLoss = comp.find(pipes.MinorLoss)->second;
Str status = comp.find(pipes.Status)->second;
// 注意顺序
CivItem civItem;
if (id == "" || id.empty())
id = "GD" + comp.find("id")->second;
civItem.push_back(id);
civItem.push_back(startNode);
civItem.push_back(endNode);
civItem.push_back(length);
civItem.push_back(diameter);
civItem.push_back(roughness);
civItem.push_back(minorLoss);
civItem.push_back(status);
items.push_back(civItem);
}
inp.writeComponet(items, _PIPES);
}
else if (PIPENODE == table)
{
Componets comps = mDbConn->getComponets(table);
// 节点参数
// ;ID Elev Demand Pattern
// 坐标
//;Node X-Coord Y-Coord
JunctionsFields jontionFields;
Civitems jounItems;
Civitems nodeCoordItems;
Civitems patternItems;
int total = comps.size();
std::set<Str> patterNams;
for (int i = 0; i < total; i++)
{
Componet comp = comps[i];
Str id = comp.find(jontionFields.ID)->second;
Str elevation = comp.find(jontionFields.Elev)->second;
Str demand = comp.find(jontionFields.Demand)->second;
Str pattern = comp.find(jontionFields.Pattern)->second;
Str x_coord = comp.find(jontionFields.X_Coord)->second;
Str y_coord = comp.find(jontionFields.Y_Coord)->second;
// 注意顺序
//1, 节点
CivItem civItem;
civItem.push_back(id);
civItem.push_back(elevation);
civItem.push_back(demand);
civItem.push_back(pattern);
jounItems.push_back(civItem);
// 2, 节点坐标
CivItem nodeCoordItem;
nodeCoordItem.push_back(id);
nodeCoordItem.push_back(x_coord);
nodeCoordItem.push_back(y_coord);
nodeCoordItems.push_back(nodeCoordItem);
if (!pattern.empty())
{
patterNams.insert(pattern);
}
}
Componets patterns = mDbConn->getComponets(PATTERNTABLE);
PatternFields fileds;
size_t patternSize = patterns.size();
for (int i = 0; i < patternSize; i++)
{
Componet pattern = patterns[i];
Str paternName = pattern.find(fileds.Name)->second;
Str paternValue = pattern.find(fileds.Value)->second;
CivItem item;
item.push_back(paternName);
item.push_back(paternValue);
patternItems.push_back(item);
}
inp.writeComponet(jounItems, _JUNCTIONS);
inp.writeComponet(nodeCoordItems, _COORDS);
inp.writeComponet(patternItems, _PATTERNS);
}
else if (RESIVOIR == table) // 水源
{
Componets comps = mDbConn->getComponets(table);
//;ID Head Pattern
Civitems coordItems;
Civitems resirvoirItems;
ResivoirFields fields;
int total = comps.size();
for (int i = 0; i < total; i++)
{
Componet comp = comps[i];
Str id = comp.find(fields.ID)->second;
Str elevation = comp.find(fields.Elev)->second;
Str flow = comp.find(fields.Flow)->second;
Str head = comp.find(fields.Head)->second;
Str pattern = comp.find(fields.Pattern)->second;
Str x_coord = comp.find(fields.X_Coord)->second;
Str y_coord = comp.find(fields.Y_Coord)->second;
// 注意顺序
//1, coord
CivItem civItem;
civItem.push_back(id);
civItem.push_back(head);
civItem.push_back(pattern);
resirvoirItems.push_back(civItem);
// 2, 节点坐标
CivItem nodeCoordItem;
nodeCoordItem.push_back(id);
nodeCoordItem.push_back(x_coord);
nodeCoordItem.push_back(y_coord);
coordItems.push_back(nodeCoordItem);
}
inp.writeComponet(coordItems, _COORDS);
inp.writeComponet(resirvoirItems, _RESERVOIRS);
}
else if (PUMP == table) // 水泵
{
//;ID Node1 Node2 Parameters
Componets comps = mDbConn->getLikelyPipes(table);
PumpFields fields;
Civitems pumpItems;
int total = comps.size();
for (int i = 0; i < total; i++)
{
Componet comp = comps[i];
Str id = comp.find(fields.ID)->second;
Str node1 = comp.find(fields.node1)->second;
Str node2 = comp.find(fields.node2)->second;
std::vector<Str> vec;
Str head = comp.find(fields.head)->second;
if (!head.empty())
vec.push_back("HEAD " + head);
Str power = comp.find(fields.power)->second;
if (!power.empty())
vec.push_back("POWER " + power);
Str pattern = comp.find(fields.pattern)->second;
if (!pattern.empty())
vec.push_back("PATTERN " + pattern);
Str speed = comp.find(fields.speed)->second;
if (!speed.empty())
vec.push_back("SPEED " + speed);
// 水池数据
CivItem tankNode;
tankNode.push_back(id);
tankNode.push_back(node1);
tankNode.push_back(node2);
// 构建参数
char param[128] = " ";
int total = vec.size();
for (int i = 0; i < total; i++)
{
strcat_s(param, vec[i].c_str());
}
tankNode.push_back(param);
pumpItems.push_back(tankNode);
}
inp.writeComponet(pumpItems, _PUMPS);
}
else if (TANK == table) // 水池
{
Componets comps = mDbConn->getComponets(table);
// ; ID Elevation InitLevel MinLevel MaxLevel Diameter MinVol VolCurve
TanksFields tkfFileds;
Civitems nodeCoordItems;
Civitems tankItems;
int total = comps.size();
for (int i = 0; i < total; i++)
{
Componet comp = comps[i];
Str id = comp.find(tkfFileds.ID)->second;
Str elevation = comp.find(tkfFileds.Elev)->second;
Str initLevel = comp.find(tkfFileds.InitLevel)->second;
Str minLevel = comp.find(tkfFileds.MinLevel)->second;
Str maxLevel = comp.find(tkfFileds.MaxLevel)->second;
Str diametor = comp.find(tkfFileds.Diameter)->second;
Str minVol = comp.find(tkfFileds.MinVol)->second;
Str x_coord = comp.find(tkfFileds.X_Coord)->second;
Str y_coord = comp.find(tkfFileds.Y_Coord)->second;
// 水池数据
CivItem tankNode;
tankNode.push_back(id);
tankNode.push_back(elevation);
tankNode.push_back(initLevel);
tankNode.push_back(minLevel);
tankNode.push_back(maxLevel);
tankNode.push_back(diametor);
tankNode.push_back(minVol);
tankItems.push_back(tankNode);
// 2, 节点坐标
CivItem nodeCoordItem;
nodeCoordItem.push_back(id);
nodeCoordItem.push_back(x_coord);
nodeCoordItem.push_back(y_coord);
nodeCoordItems.push_back(nodeCoordItem);
}
inp.writeComponet(nodeCoordItems, _COORDS);
inp.writeComponet(tankItems, _TANKS);
}
else
{
// 阀门
//;ID Node1 Node2 Diameter Type Setting MinorLoss
Componets comps = mDbConn->getLikelyPipes(table);
ValvesFields fields;
Civitems vavleItems;
int total = comps.size();
for (int i = 0; i < total; i++)
{
Componet comp = comps[i];
Str id = comp.find(fields.ID)->second;
Str node1 = comp.find(fields.node1)->second;
Str node2 = comp.find(fields.node2)->second;
Str diametor = comp.find(fields.Diameter)->second;
Str label = comp.find(fields.type)->second;
Str typeSeting = comp.find(fields.setting)->second;
Str minorLoss = comp.find(fields.minorLoss)->second;
// 阀门数据
CivItem vavleNode;
vavleNode.push_back(id);
vavleNode.push_back(node1);
vavleNode.push_back(node2);
vavleNode.push_back(diametor);
vavleNode.push_back(label);
vavleNode.push_back(typeSeting);
vavleNode.push_back(minorLoss);
vavleItems.push_back(vavleNode);
}
inp.writeComponet(vavleItems, _VALVES);
}
}
void CivInpBuilder::buildNode()
{
mDbConn->getComponets(PIPENODE);
}
void CivInpBuilder::buildPipe()
......
#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);
......
......@@ -32,33 +32,6 @@ void CivPgConn::close()
mIsOpen = false;
}
Tables CivPgConn::getTables(StrQuote netName, StrQuote schema)
{
if (!isValid())
return Tables();
std::string utf8NetName = TransUTFCoding(netName); // 中文乱码
std::string sql = "select \"name\" from public.__layer_info__ where net_code in(select code from public.__layer_net_info__ where \"name\" ='" + utf8NetName + "' and \"schema\" = '" + schema + "')";
if (!execSql(sql))
return Tables();
Tables tables;
int rows = PQntuples(mResult);
int columns = PQnfields(mResult);
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
char* item = PQgetvalue(mResult, i, j);
std::string ss = UTFTransCoding(item);
tables.push_back(ss);
}
}
PQclear(mResult);
return tables;
}
bool CivPgConn::tableExist(StrQuote tableName)
{
char sql[256] = "select count(*) from pg_class where relname = '";
......@@ -77,6 +50,9 @@ bool CivPgConn::tableExist(StrQuote tableName)
bool CivPgConn::execSql(Str sql)
{
if (mConn == nullptr)
return false;
if (sql.empty())
return false;
......@@ -89,38 +65,472 @@ bool CivPgConn::execSql(Str sql)
mLastError = error;
PQclear(mResult);
return false;
}
return true;
}
bool CivPgConn::getNode(CivNode& node)
{
CivJunctionTableTemp::JunctionTable nodeTable;
char sql[256] = "select ";
strcat_s(sql, nodeTable.thePoint.c_str());
strcat_s(sql, ",");
strcat_s(sql, nodeTable.elev.c_str());
strcat_s(sql, ",");
strcat_s(sql, nodeTable.pattern.c_str());
strcat_s(sql, ",");
strcat_s(sql, nodeTable.demand.c_str());
strcat_s(sql, " from 节点");
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
return false;
int rows = PQntuples(mResult);
int columns = PQnfields(mResult);
for (int i = 0; i < rows; i++)
{
CivNode::NodeTable nodeTable;
nodeTable.ID = PQgetvalue(mResult, i, 0);
nodeTable.Elev = PQgetvalue(mResult, i, 1);
nodeTable.Demand = PQgetvalue(mResult, i, 2);
nodeTable.PatternId = PQgetvalue(mResult, i, 3);
node.addItem(nodeTable);
}
PQclear(mResult);
return true;
}
bool CivPgConn::getPipe(CivPipe& pipe)
{
CivPipeTableTemp::PipeTable pipeTable;
//;ID Node1 Node2 Length Diameter Roughness MinorLoss Status
char sql[256] = "select ";
strcat_s(sql, pipeTable.snNo.c_str());
strcat_s(sql, ",");
strcat_s(sql, pipeTable.lastPoint.c_str());
strcat_s(sql, ",");
strcat_s(sql, pipeTable.thePoint.c_str());
strcat_s(sql, ",");
strcat_s(sql, pipeTable.length.c_str());
strcat_s(sql, ",");
strcat_s(sql, pipeTable.diameter.c_str());
strcat_s(sql, ",");
strcat_s(sql, pipeTable.friction.c_str());
strcat_s(sql, ",");
strcat_s(sql, pipeTable.localHeadLoss.c_str());
strcat_s(sql, ",");
strcat_s(sql, pipeTable.status.c_str());
strcat_s(sql, " from 管段");
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
return false;
int rows = PQntuples(mResult);
int columns = PQnfields(mResult);
for (int i = 0; i < rows; i++)
{
CivPipe::PipesTable pipeTable;
pipeTable.ID = PQgetvalue(mResult, i, 0);
pipeTable.Node1 = PQgetvalue(mResult, i, 1);
pipeTable.Node2 = PQgetvalue(mResult, i, 2);
pipeTable.Length = PQgetvalue(mResult, i, 3);
pipeTable.Diameter = PQgetvalue(mResult, i, 4);
pipeTable.Roughness = PQgetvalue(mResult, i, 5);
pipeTable.MinorLoss = PQgetvalue(mResult, i, 6);
pipeTable.Status = PQgetvalue(mResult, i, 7);
pipe.addItem(pipeTable);
}
PQclear(mResult);
return true;
}
void CivPgConn::clearResult()
bool CivPgConn::getTank(CivTank& tank)
{
CivTankTableTemp::TankTable tankTable;
//;ID Elevation InitLevel MinLevel MaxLevel Diameter MinVol VolCurve
char sql[512] = "select ";
strcat_s(sql, tankTable.thePoint.c_str());
strcat_s(sql, ",");
strcat_s(sql, tankTable.elev.c_str());
strcat_s(sql, ",");
strcat_s(sql, tankTable.initLevel.c_str());
strcat_s(sql, ",");
strcat_s(sql, tankTable.lowLevel.c_str());
strcat_s(sql, ",");
strcat_s(sql, tankTable.highLevel.c_str());
strcat_s(sql, ",");
strcat_s(sql, tankTable.diametor.c_str());
strcat_s(sql, ",");
strcat_s(sql, tankTable.capacity.c_str());
strcat_s(sql, ",");
strcat_s(sql, tankTable.volCurve.c_str());
strcat_s(sql, " from 水池");
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
return false;
int rows = PQntuples(mResult);
int columns = PQnfields(mResult);
for (int i = 0; i < rows; i++)
{
CivTank::TankTable tankTable;
tankTable.ID= PQgetvalue(mResult, i, 0);
tankTable.Elev = PQgetvalue(mResult, i, 1);
tankTable.InitLevel= PQgetvalue(mResult, i, 2);
tankTable.MinLevel= PQgetvalue(mResult, i, 3);
tankTable.MaxLevel= PQgetvalue(mResult, i, 4);
tankTable.Diameter= PQgetvalue(mResult, i, 5);
tankTable.MinVol= PQgetvalue(mResult, i, 6);
tankTable.VolCurve= PQgetvalue(mResult, i, 7);
tank.addItem(tankTable);
}
PQclear(mResult);
return true;
}
void CivPgConn::getData(Componets& comp)
bool CivPgConn::getValve(CivValve& valve)
{
if (mResult == NULL)
return;
CivValveTableTemp::ValveTable vaveTable;
//;ID Node1 Node2 Length Diameter Roughness MinorLoss Status
char sql[256] = "select ";
strcat_s(sql, vaveTable.id.c_str());
strcat_s(sql, ",");
strcat_s(sql, vaveTable.startPoint.c_str());
strcat_s(sql, ",");
strcat_s(sql, vaveTable.endPoint.c_str());
strcat_s(sql, ",");
strcat_s(sql, vaveTable.diameter.c_str());
strcat_s(sql, ",");
strcat_s(sql, vaveTable.type.c_str());
strcat_s(sql, ",");
strcat_s(sql, vaveTable.setting.c_str());
strcat_s(sql, ",");
strcat_s(sql, vaveTable.loss.c_str());
strcat_s(sql, " from 阀门");
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
return false;
int rows = PQntuples(mResult);
int columns = PQnfields(mResult);
for (int i = 0; i < rows; i++)
{
Componet node;
for (int j = 0; j < columns; j++)
{
char* item = PQgetvalue(mResult, i, j);
char* fieldName = PQfname(mResult, j); // 获取列表字段名
CivValve::ValveTable vaveTable;
vaveTable.ID = PQgetvalue(mResult, i, 0);
vaveTable.Node1 = PQgetvalue(mResult, i, 1);
vaveTable.Node2 = PQgetvalue(mResult, i, 2);
vaveTable.Diameter= PQgetvalue(mResult, i, 3);
vaveTable.Type = PQgetvalue(mResult, i, 4);
vaveTable.Setting = PQgetvalue(mResult, i, 5);
vaveTable.MinorLoss = PQgetvalue(mResult, i, 6);
valve.addItem(vaveTable);
}
PQclear(mResult);
return true;
}
bool CivPgConn::getPumps(CivPumps& pump)
{
CivPumpTableTemp::PumpTable pmTable;
//;ID Node1 Node2 Length Diameter Roughness MinorLoss Status
char sql[256] = "select ";
strcat_s(sql, pmTable.thePoint.c_str());
strcat_s(sql, ",");
strcat_s(sql, pmTable.startPoint.c_str());
strcat_s(sql, ",");
strcat_s(sql, pmTable.endPoint.c_str());
strcat_s(sql, ",");
strcat_s(sql, pmTable.headCurve.c_str());
strcat_s(sql, " from 水泵");
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
return false;
int rows = PQntuples(mResult);
int columns = PQnfields(mResult);
for (int i = 0; i < rows; i++)
{
CivPumps::PumpTable pumpTable;
pumpTable.ID = PQgetvalue(mResult, i, 0);
pumpTable.Node1 = PQgetvalue(mResult, i, 1);
pumpTable.Node2 = PQgetvalue(mResult, i, 2);
pumpTable.Parameters = PQgetvalue(mResult, i, 3);
pump.addItem(pumpTable);
}
PQclear(mResult);
return true;
}
bool CivPgConn::getReservoirs(CivReservoirs& reservoirs)
{
CivResourcesTableTemp::ResourcesTable restemTable;
//;ID Head Pattern
char sql[512] = "select ";
strcat_s(sql, restemTable.thePoint.c_str());
strcat_s(sql, ",");
strcat_s(sql, restemTable.head.c_str());
strcat_s(sql, ",");
strcat_s(sql, restemTable.headPattern.c_str());
strcat_s(sql, " from public.\"__pattern__\"");
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
return false;
int rows = PQntuples(mResult);
int columns = PQnfields(mResult);
for (int i = 0; i < rows; i++)
{
CivReservoirs::ReservoirsTable resTable;
resTable.ID = PQgetvalue(mResult, i, 0);
resTable.Head = PQgetvalue(mResult, i, 1);
resTable.Pattern = PQgetvalue(mResult, i, 2);
reservoirs.addItem(resTable);
}
PQclear(mResult);
return true;
}
bool CivPgConn::getEmitters(CivEmitters& emitter)
{
return true;
}
bool CivPgConn::getCoordinates(CivCoordinates& coord)
{
CivJunctionTableTemp::JunctionTable nodeTable;
char sql[256] = "select ";
strcat_s(sql, nodeTable.thePoint.c_str());
strcat_s(sql, ",");
strcat_s(sql, nodeTable.xCoord.c_str());
strcat_s(sql, ",");
strcat_s(sql, nodeTable.yCoord.c_str());
strcat_s(sql, " from 节点");
std::string itemStr = UTFTransCoding(item);
std::string fieldStr = UTFTransCoding(fieldName);
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
return false;
node.insert(std::pair<std::string, std::string>(fieldStr, itemStr));
int rows = PQntuples(mResult);
int columns = PQnfields(mResult);
for (int i = 0; i < rows; i++)
{
CivCoordinates::CoordTable coordTable;
nodeTable.ID = PQgetvalue(mResult, i, 0);
coordTable.XCoord = PQgetvalue(mResult, i, 1);
coordTable.YCoord = PQgetvalue(mResult, i, 2);
coord.addItem(coordTable);
}
PQclear(mResult);
return true;
}
bool CivPgConn::getMixing(CivMixing& mixing)
{
return true;
}
bool CivPgConn::getParameter(std::vector<CivParameter>& params)
{
CivParametorTableTemp::ParametorTable restemTable;
char sql[512] = "select ";
strcat_s(sql, restemTable.name.c_str());
strcat_s(sql, ",");
strcat_s(sql, restemTable.val.c_str());
strcat_s(sql, ",");
strcat_s(sql, restemTable.type.c_str());
strcat_s(sql, " from public.\"__parameter__\"");
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
return false;
int rows = PQntuples(mResult);
int columns = PQnfields(mResult);
std::map<std::string, std::vector<CivParameter::ParamTable>> tempMap;
CivParameter::ParamTable resTable;
for (int i = 0; i < rows; i++)
{
CivParameter::ParamTable pTable;
pTable.name = PQgetvalue(mResult, i, 0);
pTable.val = PQgetvalue(mResult, i, 1);
char* type = PQgetvalue(mResult, i, 1);
tempMap[type].push_back(pTable);
}
// 遍历临时存储的数据拼接参数对象
for (auto iter = tempMap.begin(); iter != tempMap.end(); iter++)
{
CivParameter param;
std::string type = iter->first;
std::vector<CivParameter::ParamTable> paramTables = iter->second;
param.setType(type);
int total = paramTables.size();
for (int i = 0; i < total; i++)
param.addItem(paramTables[i]);
params.push_back(param);
}
PQclear(mResult);
return true;
}
bool CivPgConn::getPatterns(CivPatterns& patterns)
{
CivPatternTableTemp::PatternTable patternTable;
char sql[512] = "select ";
strcat_s(sql, patternTable.Name.c_str());
strcat_s(sql, ",");
strcat_s(sql, patternTable.time.c_str());
strcat_s(sql, ",");
strcat_s(sql, patternTable.Value.c_str());
strcat_s(sql, ",");
strcat_s(sql, patternTable.type.c_str());
strcat_s(sql, " from public.\"__pattern__\"");
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
return false;
int rows = PQntuples(mResult);
int columns = PQnfields(mResult);
std::map<std::string, std::vector<std::string>> typeMap;
for (int i = 0; i < rows; i++)
{
char* val = PQgetvalue(mResult, i, 2);
char* type = PQgetvalue(mResult, i, 3);
typeMap[type].push_back(val);
}
for (auto iter = typeMap.begin(); iter != typeMap.end(); iter++)
{
CivPatterns::PatternTable pTable;
pTable.name = iter->first;
std::vector<std::string> valVec = iter->second;
int total = valVec.size();
// 拼接字符串
char value[512] = "";
for (int i = 0; i < total; i++)
{
strcat_s(value, valVec[i].c_str());
strcat_s(value, " ");
}
comp.push_back(node);
pTable.val = value;
patterns.addItem(pTable);
}
PQclear(mResult);
return true;
}
bool CivPgConn::getCurves(CivCurves& curves)
{
CivCurveTableTemp::CurveTable curveTable;
char sql[512] = "select ";
strcat_s(sql, curveTable.Label.c_str());
strcat_s(sql, ",");
strcat_s(sql, curveTable.XCoord.c_str());
strcat_s(sql, ",");
strcat_s(sql, curveTable.YCoord.c_str());
strcat_s(sql, " from public.\"__curve__\"");
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
return false;
int rows = PQntuples(mResult);
int columns = PQnfields(mResult);
for (int i = 0; i < rows; i++)
{
CivCurves::CurvesTable cTable;
cTable.ID = PQgetvalue(mResult, i, 0);
cTable.XCoord = PQgetvalue(mResult, i, 1);
cTable.YCoord = PQgetvalue(mResult, i,2);
curves.addItem(cTable);
}
PQclear(mResult);
return true;
}
bool CivPgConn::getDemands(CivDemands& demands)
{
return true;
}
bool CivPgConn::getSources(CivSources& sources)
{
return true;
}
bool CivPgConn::getStatus(CivStatus& status)
{
return true;
}
bool CivPgConn::getQuality(CivQuality& quality)
{
CivJunctionTableTemp::JunctionTable nodeTable;
char sql[256] = "select ";
strcat_s(sql, nodeTable.thePoint.c_str());
strcat_s(sql, ",");
strcat_s(sql, nodeTable.initQuality.c_str());
strcat_s(sql, " from 节点");
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
return false;
int rows = PQntuples(mResult);
int columns = PQnfields(mResult);
for (int i = 0; i < rows; i++)
{
CivQuality::QualityTable quliTable;
quliTable.ID = PQgetvalue(mResult, i, 0);
quliTable.InitQuality = PQgetvalue(mResult, i, 1);
quality.addItem(quliTable);
}
PQclear(mResult);
return true;
}
bool CivPgConn::getLabels(CivLabels& labels)
{
return true;
}
bool CivPgConn::getTags(CivTags& tags)
{
return true;
}
\ No newline at end of file
......@@ -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;
};
......
#include "CivTableTemp.h"
#include "CivDbConn.h"
CivTableTemp::CivTableTemp(Str tableName, TableType tableType)
:mTableName(tableName),mTableType(tableType)
CivTableTemp::CivTableTemp()
{
mFieldTyepMap.insert(std::pair<FieldType, std::string>(CivTableTemp::FILED_INT, "int"));
mFieldTyepMap.insert(std::pair<FieldType, std::string>(CivTableTemp::FILED_INTEGER,"integer"));
......@@ -25,86 +25,8 @@ void CivTableTemp::addProperty(Str fileName, FieldType filedType)
mPropertys.push_back(prop);
}
void CivTableTemp::addPropertys(FiledPropertys props)
{
mPropertys.insert(mPropertys.end(), props.begin(), props.end());
}
Str CivTableTemp::name()
{
return mTableName;
}
Str CivTableTemp::createSql()
{
switch (mTableType)
{
case NODE_TABLE:
{
NodeFieldName filedName;
addProperty(filedName.Number, CivTableTemp::FILED_VARCHAR);
addProperty(filedName.dPressure, CivTableTemp::FILED_DOUBLE);
addProperty(filedName.dHead, CivTableTemp::FILED_DOUBLE);
addProperty(filedName.dElevation, CivTableTemp::FILED_DOUBLE);
addProperty(filedName.dDemand, CivTableTemp::FILED_DOUBLE);
addProperty(filedName.dTankVolume, CivTableTemp::FILED_DOUBLE);
addProperty(filedName.dTankMaxVolume, CivTableTemp::FILED_DOUBLE);
addProperty(filedName.dTankLevel, CivTableTemp::FILED_DOUBLE);
addProperty(filedName.dQuality, CivTableTemp::FILED_DOUBLE);
addProperty(filedName.dDate, CivTableTemp::FILED_DATE);
addProperty(filedName.dInterval, CivTableTemp::FILED_INT);
addProperty(filedName.dModifyTime, CivTableTemp::FILED_DATETIME);
}
break;
case PIPE_TABLE:
{
LinkFiledName pipeFileds;
addProperty(pipeFileds.szNo, CivTableTemp::FILED_VARCHAR);
addProperty(pipeFileds.dFlow, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.nFlowDirect, CivTableTemp::FILED_INT);
addProperty(pipeFileds.dVelocity, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.dHeadloss, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.dUnitHeadloss, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.dFromNodHeadloss, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.dToNodHeadloss, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.dLocalHeadloss, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.dFrictionHeadloss, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.szStatus, CivTableTemp::FILED_VARCHAR);
addProperty(pipeFileds.dQuality, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.dDate, CivTableTemp::FILED_DATE);
addProperty(pipeFileds.dInterval, CivTableTemp::FILED_INT);
addProperty(pipeFileds.dModifyTime, CivTableTemp::FILED_DATETIME);
}
break;
case PATTERN_TABLE:
{
PatternFields fileds;
addProperty(fileds.Name, CivTableTemp::FILED_VARCHAR);
addProperty(fileds.Value, CivTableTemp::FILED_VARCHAR64);
addProperty(fileds.NetName, CivTableTemp::FILED_VARCHAR);
}
break;
case CURVE_TABLE:
{
CurvesFields fileds;
addProperty(fileds.Label, CivTableTemp::FILED_VARCHAR);
addProperty(fileds.Type, CivTableTemp::FILED_VARCHAR);
addProperty(fileds.XCoord, CivTableTemp::FILED_DOUBLE);
addProperty(fileds.YCoord, CivTableTemp::FILED_DOUBLE);
}
break;
case PARAMETER_TABLE:
{
ParameterFileds fileds;
addProperty(fileds.name, CivTableTemp::FILED_VARCHAR);
addProperty(fileds.val, CivTableTemp::FILED_VARCHAR);
addProperty(fileds.type, CivTableTemp::FILED_VARCHAR);
addProperty(fileds.netName, CivTableTemp::FILED_VARCHAR64);
}
break;
default:
break;
}
if (mPropertys.size() <= 0)
return Str();
......@@ -124,4 +46,303 @@ Str CivTableTemp::createSql()
strcat_s(sql, ")");
return sql;
}
\ No newline at end of file
}
bool CivTableTemp::updateToDb(CivDbConn* dbConn)
{
if (dbConn == nullptr)
return false;
Str sql = createSql();
return true;
}
CivJunctionTableTemp::CivJunctionTableTemp(Str tableName)
{
setName(PIPENODE);
TableFileds fileds;
addProperty(fileds.ID ,CivTableTemp::FILED_VARCHAR);// "id";
addProperty(fileds.geom ,CivTableTemp::FILED_VARCHAR);// "geom";
addProperty(fileds.thePoint ,CivTableTemp::FILED_VARCHAR);// "本点号";
addProperty(fileds.xCoord ,CivTableTemp::FILED_VARCHAR);// "横坐标";
addProperty(fileds.yCoord ,CivTableTemp::FILED_VARCHAR);// "纵坐标";
addProperty(fileds.elev ,CivTableTemp::FILED_VARCHAR);// "高程";
addProperty(fileds.demand ,CivTableTemp::FILED_VARCHAR);// "需水量";
addProperty(fileds.pattern ,CivTableTemp::FILED_VARCHAR);// "需水量模式";
addProperty(fileds.head ,CivTableTemp::FILED_VARCHAR);// "总水头";
addProperty(fileds.freeHead ,CivTableTemp::FILED_VARCHAR);// "自由水头";
addProperty(fileds.actualDemand ,CivTableTemp::FILED_VARCHAR);// "实际需水量";
addProperty(fileds.code ,CivTableTemp::FILED_VARCHAR);// "code";
addProperty(fileds.createUser ,CivTableTemp::FILED_VARCHAR);// "create_user";
addProperty(fileds.modifyUser ,CivTableTemp::FILED_VARCHAR);// "modify_user";
addProperty(fileds.createTime ,CivTableTemp::FILED_VARCHAR);// "create_time";
addProperty(fileds. modifyTime ,CivTableTemp::FILED_VARCHAR);// "modify_time";
addProperty(fileds.symbolAngle ,CivTableTemp::FILED_VARCHAR);// "symbol_angle";
addProperty(fileds.compType ,CivTableTemp::FILED_VARCHAR);// "组分类型";
addProperty(fileds.pressure ,CivTableTemp::FILED_VARCHAR);// "压力";
addProperty(fileds.quality ,CivTableTemp::FILED_VARCHAR);// "水质";
};
/**
管线表模板
*/
CivPipeTableTemp::CivPipeTableTemp() :CivTableTemp()
{
setName(PIPELINE);
TableFileds fileds;
addProperty(fileds.ID ,CivTableTemp::FILED_VARCHAR);// "id";
addProperty(fileds.geom ,CivTableTemp::FILED_VARCHAR);// "geom";
addProperty(fileds.snNo ,CivTableTemp::FILED_VARCHAR);// "编号";
addProperty(fileds.thePoint ,CivTableTemp::FILED_VARCHAR);// "上点号";
addProperty(fileds.lastPoint ,CivTableTemp::FILED_VARCHAR);// "本点号";
addProperty(fileds.length ,CivTableTemp::FILED_VARCHAR);// "管长";
addProperty(fileds.material ,CivTableTemp::FILED_VARCHAR);// "管材";
addProperty(fileds.diameter ,CivTableTemp::FILED_VARCHAR);// "管径";
addProperty(fileds.friction ,CivTableTemp::FILED_VARCHAR);// "摩阻系数";
addProperty(fileds.localLoss ,CivTableTemp::FILED_VARCHAR);// "局部损失系";
addProperty(fileds.initStatus ,CivTableTemp::FILED_VARCHAR);// "初始状态";
addProperty(fileds.buryingTime ,CivTableTemp::FILED_VARCHAR);// "埋设时间";
addProperty(fileds.flow ,CivTableTemp::FILED_VARCHAR);// "流量";
addProperty(fileds.velocity ,CivTableTemp::FILED_VARCHAR);// "流速";
addProperty(fileds.unitHeadLoss ,CivTableTemp::FILED_VARCHAR);// "单位水头损";
addProperty(fileds.headLoss ,CivTableTemp::FILED_VARCHAR);// "水头总损失";
addProperty(fileds.unitPressLoss ,CivTableTemp::FILED_VARCHAR);// "单位压力损";
addProperty(fileds.pressLoss ,CivTableTemp::FILED_VARCHAR);// "压力总损失";
addProperty(fileds.lastHead ,CivTableTemp::FILED_VARCHAR);// "上点水头";
addProperty(fileds.theHead ,CivTableTemp::FILED_VARCHAR);// "本点水头";
addProperty(fileds.lastPress ,CivTableTemp::FILED_VARCHAR);// "上点压力";
addProperty(fileds.thePress ,CivTableTemp::FILED_VARCHAR);// "本点压力";
addProperty(fileds.localHeadLoss ,CivTableTemp::FILED_VARCHAR);// "局部水头损";
addProperty(fileds.fracHeadLoss ,CivTableTemp::FILED_VARCHAR);// "摩擦水头损";
addProperty(fileds.status ,CivTableTemp::FILED_VARCHAR);// "状态";
addProperty(fileds.guid ,CivTableTemp::FILED_VARCHAR);// "guid";
addProperty(fileds.code ,CivTableTemp::FILED_VARCHAR);// "code";
addProperty(fileds.fromCode ,CivTableTemp::FILED_VARCHAR);// "from_code";
addProperty(fileds.fromLayer ,CivTableTemp::FILED_VARCHAR);// "from_layer";
addProperty(fileds.toCode ,CivTableTemp::FILED_VARCHAR);// "to_code";
addProperty(fileds.toLayer ,CivTableTemp::FILED_VARCHAR);// "to_layer";
addProperty(fileds.createUser ,CivTableTemp::FILED_VARCHAR);// "create_user";
addProperty(fileds.modifyUser ,CivTableTemp::FILED_VARCHAR);// "modify_user";
addProperty(fileds.createTime ,CivTableTemp::FILED_VARCHAR);// "create_time";
addProperty(fileds.modifyTime ,CivTableTemp::FILED_VARCHAR);// "modify_time";
addProperty(fileds.remarks ,CivTableTemp::FILED_VARCHAR);// "备注";
addProperty(fileds.quality ,CivTableTemp::FILED_VARCHAR);// "水质";
}
/**
水泵
*/
CivPumpTableTemp::CivPumpTableTemp() :CivTableTemp()
{
setName(PUMP);
TableFileds fileds;
addProperty(fileds.ID, CivTableTemp::FILED_VARCHAR);// "id";
addProperty(fileds.geom, CivTableTemp::FILED_VARCHAR);// "geom";
addProperty(fileds.thePoint, CivTableTemp::FILED_VARCHAR);// "本点号";
addProperty(fileds.xCoord, CivTableTemp::FILED_VARCHAR);// "横坐标";
addProperty(fileds.yCoord, CivTableTemp::FILED_VARCHAR);// "纵坐标";
addProperty(fileds.startPoint, CivTableTemp::FILED_VARCHAR);// "起始节点";
addProperty(fileds.endPoint, CivTableTemp::FILED_VARCHAR);// "终止节点";
addProperty(fileds.curve, CivTableTemp::FILED_VARCHAR);// "水泵曲线";
addProperty(fileds.ratio, CivTableTemp::FILED_VARCHAR);// "转速比";
addProperty(fileds.flow, CivTableTemp::FILED_VARCHAR);// "流量";
addProperty(fileds.headCurve, CivTableTemp::FILED_VARCHAR);// "扬程曲线";
addProperty(fileds.status, CivTableTemp::FILED_VARCHAR);// "状态";
addProperty(fileds.code, CivTableTemp::FILED_VARCHAR);// "code";
addProperty(fileds.createUser, CivTableTemp::FILED_VARCHAR);// "create_user";
addProperty(fileds.modifyUser, CivTableTemp::FILED_VARCHAR);// "modify_user";
addProperty(fileds.createTime, CivTableTemp::FILED_VARCHAR);// "create_time";
addProperty(fileds.modifyTime, CivTableTemp::FILED_VARCHAR);// "modify_time";
addProperty(fileds.SymbolAngle, CivTableTemp::FILED_VARCHAR);// "symbol_angle";
addProperty(fileds.compType, CivTableTemp::FILED_VARCHAR);// "组分类型";
addProperty(fileds.power, CivTableTemp::FILED_VARCHAR);// "功率";
}
/**
水池
*/
CivTankTableTemp::CivTankTableTemp() :CivTableTemp()
{
setName(TANK);
TableFileds fileds;
addProperty(fileds.ID ,CivTableTemp::FILED_VARCHAR);// "id";
addProperty(fileds.geom ,CivTableTemp::FILED_VARCHAR);// "geom";
addProperty(fileds.thePoint ,CivTableTemp::FILED_VARCHAR);// "本点号";
addProperty(fileds.xCoord ,CivTableTemp::FILED_VARCHAR);// "横坐标";
addProperty(fileds.yCoord ,CivTableTemp::FILED_VARCHAR);// "纵坐标";
addProperty(fileds.elev ,CivTableTemp::FILED_VARCHAR);// "高程";
addProperty(fileds.diametor ,CivTableTemp::FILED_VARCHAR);// "直径";
addProperty(fileds.baseLevel ,CivTableTemp::FILED_VARCHAR);// "基础水位";
addProperty(fileds.initLevel ,CivTableTemp::FILED_VARCHAR);// "初始水位";
addProperty(fileds.highLevel ,CivTableTemp::FILED_VARCHAR);// "最高水位";
addProperty(fileds.lowLevel ,CivTableTemp::FILED_VARCHAR);// "最低水位";
addProperty(fileds.flowIn ,CivTableTemp::FILED_VARCHAR);// "输入流量";
addProperty(fileds.flowOut ,CivTableTemp::FILED_VARCHAR);// "输出流量";
addProperty(fileds.leveHeight ,CivTableTemp::FILED_VARCHAR);// "液位高度";
addProperty(fileds.capacity ,CivTableTemp::FILED_VARCHAR);// "容量";
addProperty(fileds.percentage ,CivTableTemp::FILED_VARCHAR);// "装满水池百";
addProperty(fileds.status ,CivTableTemp::FILED_VARCHAR);// "状态";
addProperty(fileds.code ,CivTableTemp::FILED_VARCHAR);// "code";
addProperty(fileds.createUser ,CivTableTemp::FILED_VARCHAR);// "create_user";
addProperty(fileds.modifyUser ,CivTableTemp::FILED_VARCHAR);// "modify_user";
addProperty(fileds.createTime ,CivTableTemp::FILED_VARCHAR);// "create_time";
addProperty(fileds.modifyTime ,CivTableTemp::FILED_VARCHAR);// "modify_time";
addProperty(fileds.SymbolAngle ,CivTableTemp::FILED_VARCHAR);// "symbol_angle";
addProperty(fileds.compType ,CivTableTemp::FILED_VARCHAR);// "组分类型";
}
/**
水库
*/
CivResourcesTableTemp::CivResourcesTableTemp() :CivTableTemp()
{
setName(RESIVOIR);
TableFileds fileds;
addProperty(fileds.ID ,CivTableTemp::FILED_VARCHAR);// "id";
addProperty(fileds.geom ,CivTableTemp::FILED_VARCHAR);// "geom";
addProperty(fileds.thePoint ,CivTableTemp::FILED_VARCHAR);// "本点号";
addProperty(fileds.xCoord ,CivTableTemp::FILED_VARCHAR);// "横坐标";
addProperty(fileds.yCoord ,CivTableTemp::FILED_VARCHAR);// "纵坐标";
addProperty(fileds.headPattern ,CivTableTemp::FILED_VARCHAR);// "水头模式曲";
addProperty(fileds.elev ,CivTableTemp::FILED_VARCHAR);// "高程";
addProperty(fileds.head ,CivTableTemp::FILED_VARCHAR);// "水头";
addProperty(fileds.flow ,CivTableTemp::FILED_VARCHAR);// "流出流量";
addProperty(fileds.code ,CivTableTemp::FILED_VARCHAR);// "code";
addProperty(fileds.createUser ,CivTableTemp::FILED_VARCHAR);// "create_user";
addProperty(fileds.modifyUser ,CivTableTemp::FILED_VARCHAR);// "modify_user";
addProperty(fileds.createTime ,CivTableTemp::FILED_VARCHAR);// "create_time";
addProperty(fileds.modifyTime ,CivTableTemp::FILED_VARCHAR);// "modify_time";
addProperty(fileds.SymbolAngle ,CivTableTemp::FILED_VARCHAR);// "symbol_angle";
addProperty(fileds.compType ,CivTableTemp::FILED_VARCHAR);// "组分类型";
}
/**
阀门
*/
CivValveTableTemp::CivValveTableTemp() :CivTableTemp()
{
setName(VALVE);
TableFileds fileds;
addProperty(fileds.id ,CivTableTemp::FILED_VARCHAR);// "本点号";
addProperty(fileds.geom ,CivTableTemp::FILED_VARCHAR);// "geom";
addProperty(fileds.xCoord ,CivTableTemp::FILED_VARCHAR);// "横坐标";
addProperty(fileds.yCoord ,CivTableTemp::FILED_VARCHAR);// "纵坐标";
addProperty(fileds.startPoint ,CivTableTemp::FILED_VARCHAR);// "起始节点";
addProperty(fileds.endPoint ,CivTableTemp::FILED_VARCHAR);// "终止节点";
addProperty(fileds.diameter ,CivTableTemp::FILED_VARCHAR);// "直径";
addProperty(fileds.status ,CivTableTemp::FILED_VARCHAR);// "状态";
addProperty(fileds.type ,CivTableTemp::FILED_VARCHAR);// "阀门类型";
addProperty(fileds.setting ,CivTableTemp::FILED_VARCHAR);// "阀门设置";
addProperty(fileds.loss ,CivTableTemp::FILED_VARCHAR);// "损失系数";
addProperty(fileds.flow ,CivTableTemp::FILED_VARCHAR);// "流量 ";
addProperty(fileds.veclocity ,CivTableTemp::FILED_VARCHAR);// "流速";
addProperty(fileds.headLoss ,CivTableTemp::FILED_VARCHAR);// "水头损失";
addProperty(fileds.code ,CivTableTemp::FILED_VARCHAR);// "code";
addProperty(fileds.createUser ,CivTableTemp::FILED_VARCHAR);// "create_user";
addProperty(fileds.modityUser ,CivTableTemp::FILED_VARCHAR);// "modify_user";
addProperty(fileds.createTime ,CivTableTemp::FILED_VARCHAR);// "create_time";
addProperty(fileds.modifyTime ,CivTableTemp::FILED_VARCHAR);// "modify_time";
addProperty(fileds.symbolAngle ,CivTableTemp::FILED_VARCHAR);// "symbol_angle";
addProperty(fileds.compType ,CivTableTemp::FILED_VARCHAR);// "组分类型";
}
/**
节点模拟结果存储表
*/
CivNodeResultTableTemp::CivNodeResultTableTemp() :CivTableTemp()
{
setName(NODERESULTTABLE);
NodeResultTable nodeTable;
addProperty(nodeTable.Number, CivTableTemp::FILED_VARCHAR);
addProperty(nodeTable.dPressure, CivTableTemp::FILED_DOUBLE);
addProperty(nodeTable.dHead, CivTableTemp::FILED_DOUBLE);
addProperty(nodeTable.dElevation, CivTableTemp::FILED_DOUBLE);
addProperty(nodeTable.dDemand, CivTableTemp::FILED_DOUBLE);
addProperty(nodeTable.dTankVolume, CivTableTemp::FILED_DOUBLE);
addProperty(nodeTable.dTankMaxVolume, CivTableTemp::FILED_DOUBLE);
addProperty(nodeTable.dTankLevel, CivTableTemp::FILED_DOUBLE);
addProperty(nodeTable.dQuality, CivTableTemp::FILED_DOUBLE);
addProperty(nodeTable.dDate, CivTableTemp::FILED_DATE);
addProperty(nodeTable.dInterval, CivTableTemp::FILED_INT);
addProperty(nodeTable.dModifyTime, CivTableTemp::FILED_DATETIME);
}
/**
模拟结果线表
*/
CivPipeResultTableTemp::CivPipeResultTableTemp() :CivTableTemp()
{
setName(PIPERESULTTABLE);
TableField pipeFileds;
addProperty(pipeFileds.szNo, CivTableTemp::FILED_VARCHAR);
addProperty(pipeFileds.dFlow, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.nFlowDirect, CivTableTemp::FILED_INT);
addProperty(pipeFileds.dVelocity, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.dHeadloss, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.dUnitHeadloss, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.dFromNodHeadloss, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.dToNodHeadloss, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.dLocalHeadloss, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.dFrictionHeadloss, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.szStatus, CivTableTemp::FILED_VARCHAR);
addProperty(pipeFileds.dQuality, CivTableTemp::FILED_DOUBLE);
addProperty(pipeFileds.dDate, CivTableTemp::FILED_DATE);
addProperty(pipeFileds.dInterval, CivTableTemp::FILED_INT);
addProperty(pipeFileds.dModifyTime, CivTableTemp::FILED_DATETIME);
}
/**
模式表
*/
CivPatternTableTemp::CivPatternTableTemp() :CivTableTemp()
{
setName(PATTERNTABLE);
TableField fileds;
addProperty(fileds.Name, CivTableTemp::FILED_VARCHAR);
addProperty(fileds.Value, CivTableTemp::FILED_VARCHAR64);
}
/**
参数表
*/
CivParametorTableTemp::CivParametorTableTemp() :CivTableTemp()
{
setName(OPTIONTTABLE);
TableField fileds;
addProperty(fileds.name, CivTableTemp::FILED_VARCHAR);
addProperty(fileds.val, CivTableTemp::FILED_VARCHAR);
addProperty(fileds.type, CivTableTemp::FILED_VARCHAR);
addProperty(fileds.netName, CivTableTemp::FILED_VARCHAR64);
}
/**
曲线表
*/
CivCurveTableTemp::CivCurveTableTemp() :CivTableTemp()
{
setName(CURVETABLE);
TableField fileds;
addProperty(fileds.Label, CivTableTemp::FILED_VARCHAR);
addProperty(fileds.Type, CivTableTemp::FILED_VARCHAR);
addProperty(fileds.XCoord, CivTableTemp::FILED_DOUBLE);
addProperty(fileds.YCoord, CivTableTemp::FILED_DOUBLE);
}
......@@ -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