Commit f932ec47 authored by 刘乐's avatar 刘乐

1,转inp文件接口代码重写

parent 3f06f4e3
......@@ -23,13 +23,13 @@ int main(int argc, char* argv[])
strcpy_s(net, "水力模型管网");
strcpy_s(flag, "QUALITY");
/*bool msg = simulation(findUri, net, flag);
/* bool msg = simulation(findUri, net, flag);
std::cout << msg << std::endl;*/
const char* date = "2020-07-01";
const char* date = "2020-07-02";
char* dates = const_cast<char*>(date);
const char* interval = "3";
const char* interval = "4";
char* intervals = const_cast<char*>(interval);
bool isSucces = getDataByInterval(findUri, dates, intervals);
std::cout << isSucces << std::endl;
......
......@@ -15,6 +15,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EPNAET2", "EPNAET2\EPNAET2.
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "funcDemo", "funcDemo\funcDemo.vcxproj", "{6A4F723D-C24B-4B16-A230-9C39A379F082}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pandaLog", "pandaLog\pandaLog.vcxproj", "{4C38D294-830F-441E-B892-60117ABA8BFE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -65,6 +67,16 @@ Global
{6A4F723D-C24B-4B16-A230-9C39A379F082}.Release|x64.Build.0 = Release|x64
{6A4F723D-C24B-4B16-A230-9C39A379F082}.Release|x86.ActiveCfg = Release|Win32
{6A4F723D-C24B-4B16-A230-9C39A379F082}.Release|x86.Build.0 = Release|Win32
{4C38D294-830F-441E-B892-60117ABA8BFE}.Debug|Any CPU.ActiveCfg = Debug|Win32
{4C38D294-830F-441E-B892-60117ABA8BFE}.Debug|x64.ActiveCfg = Debug|x64
{4C38D294-830F-441E-B892-60117ABA8BFE}.Debug|x64.Build.0 = Debug|x64
{4C38D294-830F-441E-B892-60117ABA8BFE}.Debug|x86.ActiveCfg = Debug|Win32
{4C38D294-830F-441E-B892-60117ABA8BFE}.Debug|x86.Build.0 = Debug|Win32
{4C38D294-830F-441E-B892-60117ABA8BFE}.Release|Any CPU.ActiveCfg = Release|Win32
{4C38D294-830F-441E-B892-60117ABA8BFE}.Release|x64.ActiveCfg = Release|x64
{4C38D294-830F-441E-B892-60117ABA8BFE}.Release|x64.Build.0 = Release|x64
{4C38D294-830F-441E-B892-60117ABA8BFE}.Release|x86.ActiveCfg = Release|Win32
{4C38D294-830F-441E-B892-60117ABA8BFE}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -49,37 +49,86 @@ void CivInpBuilder::registDb(CivDbConn* dbConn)
void CivInpBuilder::buildNode()
{
ASSERT(mDbConn, mNewInp)
CivNode node;
bool succ = mDbConn->getNode(node);
if (succ)
return;
mNewInp->setNode(node);
}
void CivInpBuilder::buildPipe()
{
ASSERT(mDbConn, mNewInp)
CivPipe pipe;
bool succ = mDbConn->getPipe(pipe);
if (succ)
return;
mNewInp->setPipes(pipe);
}
void CivInpBuilder::buildTank()
{
ASSERT(mDbConn, mNewInp)
CivTank tank;
bool succ = mDbConn->getTank(tank);
if (succ)
return;
mNewInp->setTank(tank);
}
void CivInpBuilder::buildVavle()
{
ASSERT(mDbConn, mNewInp)
CivValve valve;
bool succ = mDbConn->getValve(valve);
if (succ)
return;
mNewInp->setValves(valve);
}
void CivInpBuilder::buildPump()
{
ASSERT(mDbConn, mNewInp)
CivPumps valve;
bool succ = mDbConn->getPumps(valve);
if (succ)
return;
mNewInp->setPumps(valve);
}
void CivInpBuilder::buildReservoir()
{
ASSERT(mDbConn, mNewInp)
CivReservoirs res;
bool succ = mDbConn->getReservoirs(res);
if (succ)
return;
mNewInp->setReservoirs(res);
}
void CivInpBuilder::buildEmitter()
{
ASSERT(mDbConn, mNewInp)
CivEmitters emmiters;
bool succ = mDbConn->getEmitters(emmiters);
if (succ)
return;
mNewInp->setEmitters(emmiters);
}
CivNewInp* CivInpBuilder::getNewInp()
......@@ -89,32 +138,70 @@ CivNewInp* CivInpBuilder::getNewInp()
void CivInpBuilder::buildPatterns()
{
ASSERT(mDbConn, mNewInp)
CivPatterns pattern;
if (!mDbConn->getPatterns(pattern))
return;
mNewInp->setPatterns(pattern);
}
void CivInpBuilder::buildParamter()
{
ASSERT(mDbConn, mNewInp)
std::vector<CivParameter> parameters;
if (!mDbConn->getParameter(parameters))
return;
size_t total = parameters.size();
for (int i = 0; i < total; i++)
{
CivParameter param = parameters[i];
mNewInp->setParamter(param, param.mType);
}
}
void CivInpBuilder::buildCoordnates()
{
ASSERT(mDbConn, mNewInp)
CivCoordinates coords;
bool succ = mDbConn->getCoordinates(coords);
if (succ)
return;
mNewInp->setCoordnates(coords);
}
void CivInpBuilder::buildVertices()
{
}
void CivInpBuilder::buildLabels()
{
ASSERT(mDbConn, mNewInp)
CivLabels labels;
bool succ = mDbConn->getLabels(labels);
if (succ)
return;
mNewInp->setLabels(labels);
}
void CivInpBuilder::buildTags()
{
ASSERT(mDbConn, mNewInp)
CivTags tag;
bool succ = mDbConn->getTags(tag);
if (succ)
return;
mNewInp->setTags(tag);
}
void CivInpBuilder::buildBackDrop()
......@@ -124,27 +211,62 @@ void CivInpBuilder::buildBackDrop()
void CivInpBuilder::buildQuality()
{
ASSERT(mDbConn, mNewInp)
CivQuality quality;
bool succ = mDbConn->getQuality(quality);
if (succ)
return;
mNewInp->setQuality(quality);
}
void CivInpBuilder::buildSources()
{
ASSERT(mDbConn, mNewInp)
CivSources sources;
bool succ = mDbConn->getSources(sources);
if (succ)
return;
mNewInp->setSources(sources);
}
void CivInpBuilder::buildMixing()
{
ASSERT(mDbConn, mNewInp)
CivMixing mixing;
bool succ = mDbConn->getMixing(mixing);
if (succ)
return;
mNewInp->setMixing(mixing);
}
void CivInpBuilder::buildCurves()
{
ASSERT(mDbConn, mNewInp)
CivCurves curves;
bool succ = mDbConn->getCurves(curves);
if (succ)
return;
mNewInp->setCurves(curves);
}
void CivInpBuilder::buildStatus()
{
ASSERT(mDbConn, mNewInp)
CivStatus status;
bool succ = mDbConn->getStatus(status);
if (succ)
return;
mNewInp->setStatus(status);
}
void CivInpBuilder::buildControls()
......@@ -154,10 +276,17 @@ void CivInpBuilder::buildControls()
void CivInpBuilder::buildRules()
{
}
void CivInpBuilder::buildDemands()
{
ASSERT(mDbConn, mNewInp)
CivDemands mand;
bool succ = mDbConn->getDemands(mand);
if (succ)
return;
mNewInp->setDemands(mand);
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ public:
CivBuilder();
virtual ~CivBuilder();
virtual void registDb(CivDbConn* dbConn)=0;
virtual void buildNode() = 0;
virtual void buildPipe() = 0;
virtual void buildTank() = 0;
......@@ -52,8 +53,7 @@ public:
~CivInpBuilder();
// 注册数据库连接
void registDb(CivDbConn* dbConn);
virtual void registDb(CivDbConn* dbConn);
virtual void buildNode();
virtual void buildPipe();
virtual void buildTank();
......
......@@ -2,16 +2,20 @@
#include "CivDbConnection.h"
#include "CivTypes.h"
#include "Epanet2.h"
#include "CivInp.h"
#include "../pandaDbManager/CivCommonUtils.h"
#include <time.h>
#include <time.h>
#include "CivBuilder.h"
#include "CivInpDirector.h"
#include"CivDbConn.h"
#include"CivPgConn.h"
#include <iostream>
CivHydrCalc::CivHydrCalc(char* uri, std::string netName)
: mNetname(netName)
{
mDbConn = new CivDbConnection(uri);
mPgConn = new CivPgConn(uri);
}
CivHydrCalc::~CivHydrCalc()
......@@ -22,7 +26,11 @@ CivHydrCalc::~CivHydrCalc()
bool CivHydrCalc::hydrSimulation(char* fileName, char* rptFile, char* binOutFile)
{
if (!exportInp(fileName))
{
CivSysLog::getInstance()->error("写入inp文件失败", "CivHydrCalc", __FUNCTION__);
return false;
}
CivSysLog::getInstance()->info("写入inp成功", "CivHydrCalc", __FUNCTION__);
short hydCode = 1;
long t(0), tstep(0);
......@@ -33,20 +41,24 @@ bool CivHydrCalc::hydrSimulation(char* fileName, char* rptFile, char* binOutFile
if (errcode > 0)
{
ENclose();
CivSysLog::getInstance()->error("ENopen inp 失败", "CivHydrCalc", __FUNCTION__);
return false;
}
CivSysLog::getInstance()->info("ENopen inp 成功", "CivHydrCalc", __FUNCTION__);
if (ENopenH() > 0)
{
ENclose();
CivSysLog::getInstance()->error("ENopenH inp 失败", "CivHydrCalc", __FUNCTION__);
return false;
}
if (ENinitH(0) > 0)
{
ENclose();
CivSysLog::getInstance()->error("ENinitH inp 失败", "CivHydrCalc", __FUNCTION__);
return false;
}
CivSysLog::getInstance()->info("ENinitH inp 成功", "CivHydrCalc", __FUNCTION__);
float dHStep;
ENGetVal(4, &dHStep);
......@@ -83,7 +95,12 @@ bool CivHydrCalc::hydrSimulation(char* fileName, char* rptFile, char* binOutFile
getLinkResult(iTime);
iTime++;
} while (tstep > 0);
// 更新数据
if (!mResultCache.updateToDb(mDbConn))
{
CivSysLog::getInstance()->error("水力分析结果存储失败", "CivHydrCalc", __FUNCTION__);
return false;
}
// 更新管网数据库数据
(void)mDbConn->updateNodeByInterval(CurrentDate, "0");
(void)mDbConn->updateLinkByInterval(CurrentDate,"0");
......@@ -95,8 +112,13 @@ bool CivHydrCalc::hydrSimulation(char* fileName, char* rptFile, char* binOutFile
bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFile)
{
CivSysLog::getInstance()->error("开始水质分析计算", "CivHydrCalc", __FUNCTION__);
if (!exportInp(inpFile))
{
CivSysLog::getInstance()->error("写入inp文件失败", "CivHydrCalc", __FUNCTION__);
return false;
}
CivSysLog::getInstance()->info("写入inp成功", "CivHydrCalc", __FUNCTION__);
// 运行水质运算需要先进行水力运算,没有直接采用ENSolveH 是为了考虑减压阀的压力曲线设置
......@@ -109,26 +131,25 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi
errcode = ENopen(inpFile, rptFile, binOutFile);
if (errcode > 0)
{
ENclose();
CivSysLog::getInstance()->error("ENopen inp 失败", "CivHydrCalc", __FUNCTION__);
return false;
}
errcode = ENopenH();
if (errcode > 0)
CivSysLog::getInstance()->info("ENopen inp 成功", "CivHydrCalc", __FUNCTION__);
if (ENopenH() > 0)
{
ENclose();
CivSysLog::getInstance()->error("ENopenH inp 失败", "CivHydrCalc", __FUNCTION__);
return false;
}
// 根据类型 更改值
errcode = ENinitH(EN_SAVE);
if (errcode > 0)
if (ENinitH(EN_SAVE) > 0)
{
ENcloseH();
ENclose();
CivSysLog::getInstance()->error("ENinitH inp 失败", "CivHydrCalc", __FUNCTION__);
return false;
}
CivSysLog::getInstance()->info("ENinitH inp 成功", "CivHydrCalc", __FUNCTION__);
bool isFirst = true;
do
{
......@@ -192,13 +213,17 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi
// 更新数据
if (!mResultCache.updateToDb(mDbConn))
{
CivSysLog::getInstance()->error("水质分析结果存储失败", "CivHydrCalc", __FUNCTION__);
return false;
}
CivSysLog::getInstance()->info("水质分析结果存储成功", "CivHydrCalc", __FUNCTION__);
// 更新管网数据库数据
(void)mDbConn->updateNodeByInterval(CurrentDate, "0");
(void)mDbConn->updateLinkByInterval(CurrentDate, "0");
CivSysLog::getInstance()->info("结束水质分析计算", "CivHydrCalc", __FUNCTION__);
return true;
}
......@@ -210,8 +235,25 @@ bool CivHydrCalc::exportInp(char* fileName)
if (!mDbConn->open())
return false;
CivBuilder* builder = new CivInpBuilder();
builder->registDb(mPgConn);
CivInpDirector director;
director.setBuilder(builder);
director.create();
CivNewInp* newInp = builder->getNewInp();
if (!newInp->writeToFile(fileName))
{
delete builder;
delete newInp;
return false;
}
delete builder;
delete newInp;
return true;
/*bool pattern = mDbConn->createTable(*CivPatternTableTemp());
bool cii = mDbConn->createTable(OPTIONTTABLE, "public", CivTableTemp::PARAMETER_TABLE);
bool curve = mDbConn->createTable(CURVETABLE, "public", CivTableTemp::CURVE_TABLE);
......@@ -220,6 +262,8 @@ bool CivHydrCalc::exportInp(char* fileName)
// 获取表格
Tables tables = mDbConn->getTables(mNetname);
if(tables.size()<=0)
CivSysLog::getInstance()->error(mNetname+ "查询不到表", "CivHydrCalc", __FUNCDNAME__);
//2,解析管网组件
// 解析管网组件顺序: 管线放最后
......@@ -593,7 +637,7 @@ void CivHydrCalc::getNodeResult(short time)
{
int nNodeCount;
ENgetcount(EN_NODECOUNT, &nNodeCount);
for (int i = 1; i <= nNodeCount; i++)
{
NodeResultItem nodeItem;
......
......@@ -2,9 +2,11 @@
#include<string>
#include<set>
#include "CivInp.h"
#include "CivSysLog.h"
#include "CivSimulResultCache.h"
class CivDbConnection;
class CivDbConn;
/**
* 水力计算类
......@@ -73,6 +75,7 @@ private:
private:
CivDbConnection* mDbConn;
CivDbConn* mPgConn;
std::string mNetname;
CivSimulResultCache mResultCache; // 存储模拟结果缓存类
......
#include "CivHydrFuncInter.h"
#include "CivHydrCalc.h"
#include "CivSysLog.h"
bool DLLEXPORT simulation(char* uri, char* netName, char* flag)
{
......@@ -13,13 +14,21 @@ bool DLLEXPORT simulation(char* uri, char* netName, char* flag)
strcpy_s(outBinFile, "test.bin");
CivHydrCalc* calc = new CivHydrCalc(uri, netName);
bool msg = false;;
CivSysLog::getInstance()->info("ʼ", "interface", __FUNCTION__);
bool msg = false;
if (strcmp(flag,"HDY")==0)
msg = calc->hydrSimulation( fileName, rptR, outBinFile);
else if(strcmp(flag, "QUALITY")==0)
msg = calc->qualitySimulation(fileName, rptR, outBinFile);
if (msg)
{
CivSysLog::getInstance()->info("ɹ", "interface", __FUNCTION__);
}
else
{
CivSysLog::getInstance()->info("ʧ", "interface", __FUNCTION__);
}
delete calc;
return msg;
}
......@@ -35,15 +44,22 @@ bool DLLEXPORT qualitySimulation(char* uri, char* netName, char* type)
return true;
}
bool DLLEXPORT qualityTrackingSimulation(char* uri, char* netName, char* nodeSn)
bool DLLEXPORT qualityTrackingSimulation(char* uri, char* netName, char* nodeSn, char* time)
{
return true;
}
bool DLLEXPORT getDataByInterval(char* uri, char* date, char* interval)
{
CivHydrCalc* calc = new CivHydrCalc(uri, "");
bool flag = calc->getDataByInterval(date, interval);
char inp[128];
strcpy(inp, "test.inp");
bool flag = calc->exportInp(inp);
std::cout << flag << std::endl;
//flag = calc->getDataByInterval(date, interval);
delete calc;
return flag;
}
\ No newline at end of file
......@@ -28,14 +28,14 @@ extern "C" {
*/
bool DLLEXPORT qualitySimulation(char* uri, char* netName, char* type);
/**
*@brief 水质追踪模拟计算
*@uri: 管网数据库连接
*@netName: 管网名
*@nodeSn: 追踪节点编号
*@time: 追踪时段
*/
bool DLLEXPORT qualityTrackingSimulation(char* uri, char* netName, char* nodeSn);
bool DLLEXPORT qualityTrackingSimulation(char* uri, char* netName, char* nodeSn, char* time);
/**
*@brief 获取管网计算特定时段的结果
......
#include "CivNewInp.h"
#include <time.h>
#include<fstream>
bool CivNewInp::writeToFile(char* fileName)
{
std::ofstream outFile(fileName);
if (!outFile)
{
mTextStream.clear();
mTextStream.str("");
return false;
}
else
{
outFile <<mTextStream.str();
outFile.close();
mTextStream.clear();
mTextStream.str("");
return true;
}
}
void CivNewInp::setTtitle(const std::string& title)
{
......
......@@ -12,6 +12,8 @@
class CivNewInp
{
public:
bool writeToFile(char* fileName);
/**
管网组件
*/
......
#include "CivSimulResultCache.h"
#include"CivSysLog.h"
void CivSimulResultCache::addNodeQuality(float quality, int interval, Str sNo)
{
......@@ -36,20 +37,32 @@ void CivSimulResultCache::addLinkItems(const LinkResultItem& linkItem)
bool CivSimulResultCache::updateToDb(CivDbConnection* dbConn)
{
CivSysLog::getInstance()->error("开始写入数据库", "CivSimulResultCache", __FUNCTION__);
if (dbConn == nullptr)
{
CivSysLog::getInstance()->error("dbConn == nullptr", "CivSimulResultCache", __FUNCTION__);
return false;
}
for (auto iter = mNodeItemsMap.begin(); iter != mNodeItemsMap.end(); iter++)
{
NodeResultItems nodeItems = iter->second;
dbConn->updateNode(nodeItems);
if (!dbConn->updateNode(nodeItems))
{
CivSysLog::getInstance()->error("存储节点数据失败", "CivSimulResultCache", __FUNCTION__);
}
}
for (auto iter = mLinkItemsMap.begin(); iter != mLinkItemsMap.end(); iter++)
{
LinkResultItems nodeItems = iter->second;
dbConn->updateLink(nodeItems);
if (!dbConn->updateLink(nodeItems))
{
CivSysLog::getInstance()->error("存储管段数据失败", "CivSimulResultCache", __FUNCTION__);
}
}
CivSysLog::getInstance()->error("写入数据库完成", "CivSimulResultCache", __FUNCTION__);
clear();
return true;
}
......
......@@ -143,7 +143,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libpq.lib;pandaDbManager.lib;EPNAET2.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>libpq.lib;pandaDbManager.lib;EPNAET2.lib;pandaLog.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OUTDIR)..\lib</AdditionalLibraryDirectories>
<ImportLibrary>$(OutDir)..\lib\$(TargetName).lib</ImportLibrary>
</Link>
......
......@@ -15,45 +15,11 @@ bool CivDbConn::isValid() const
return mIsOpen;
}
void CivDbConn::addFilter(Str type, Str number)
{
mFilter[type].insert(number);
}
FiledFilter CivDbConn::getFilter() const
{
return mFilter;
}
Str CivDbConn::getLastError() const
{
return mLastError;
}
Componets CivDbConn::getValueByCode(StrQuote table, StrQuote code)
{
if (!isValid())
return Componets();
char sql[256] = "select * from public.\"";
strcat_s(sql, TransUTFCoding(table).c_str());
strcat_s(sql, "\"");
strcat_s(sql, " where code = '");
strcat_s(sql, code.c_str());
strcat_s(sql, "'");
if (!execSql(sql))
{
return Nodes();
}
Componets componets;
getData(componets);
return componets;
}
bool CivDbConn::deleteByField(StrQuote table, StrQuote filedName, StrQuote fieldValue)
{
if (!isValid())
......@@ -286,156 +252,6 @@ bool CivDbConn::updateLink(const LinkResultItems& lineItems)
return true;
}
Componets CivDbConn::getComponets(StrQuote tableName)
{
if (!isValid())
return Nodes();
std::string utf8Name = TransUTFCoding(tableName);
std::string sql = "select * from public.\"" + utf8Name + "\"";
if (!execSql(sql))
{
return Nodes();
}
Componets nodes;
// 取数据到容器中
getData(nodes);
return nodes;
}
Componets CivDbConn::getComponetsByWhere(StrQuote tableName, StrQuote where)
{
if (!isValid())
return Componets();
std::string utf8Name = TransUTFCoding(tableName);
std::string utf8Where = TransUTFCoding(where);
char sql[128] = "select * from public.";
strcat_s(sql, utf8Name.c_str());
strcat_s(sql, utf8Where.c_str());
if (!execSql(sql))
{
return Componets();
}
Componets comps;
// 取数据到容器中
getData(comps);
return comps;
}
Componets CivDbConn::getLikelyPipes(StrQuote tableName)
{
if (!isValid())
return Componets();
// 查询点数据
char sql[256] = "select * from public.\"";
strcat_s(sql, TransUTFCoding(tableName).c_str());
strcat_s(sql, "\"");
if (!execSql(sql))
{
return Componets();
}
Componets nodes;
getData(nodes);
// 查询线表
if (nodes.size() <= 0)
return Componets();
// 查询:连接节点也有可能连接水源,或者水库
std::vector<Str> tables;
tables.push_back(PIPENODE);
tables.push_back(RESIVOIR);
tables.push_back(TANK);
// 阀门类型映射
std::map<Str, Str> mValvesMap;
mValvesMap.insert(std::pair<Str, Str>(PRV_TYPE, "PRV"));
mValvesMap.insert(std::pair<Str, Str>(PSV_TYPE, "PSV"));
mValvesMap.insert(std::pair<Str, Str>(PBV_TYPE, "PBV"));
mValvesMap.insert(std::pair<Str, Str>(FCV_TYPE, "FCV"));
mValvesMap.insert(std::pair<Str, Str>(TCV_TYPE, "TCV"));
mValvesMap.insert(std::pair<Str, Str>(GPV_TYPE, "PRV"));
std::vector<Str> mVavesTables;
mVavesTables.push_back(PRV_TYPE);
mVavesTables.push_back(PSV_TYPE);
mVavesTables.push_back(PBV_TYPE);
mVavesTables.push_back(FCV_TYPE);
mVavesTables.push_back(TCV_TYPE);
mVavesTables.push_back(GPV_TYPE);
// 不同阀门对应的特殊参数
std::map<Str, Str> mParameterMap;
mParameterMap.insert(std::pair<Str, Str>(PRV_TYPE, "恒定压力值"));
mParameterMap.insert(std::pair<Str, Str>(PSV_TYPE, "恒定压力值"));
mParameterMap.insert(std::pair<Str, Str>(PBV_TYPE, "恒定压力值"));
mParameterMap.insert(std::pair<Str, Str>(FCV_TYPE, "流量设置"));
mParameterMap.insert(std::pair<Str, Str>(TCV_TYPE, "流量设置"));
mParameterMap.insert(std::pair<Str, Str>(GPV_TYPE, "水头损失曲"));
// 根据点数据查询起点和终点,管径
size_t total = nodes.size();
for (int i = 0; i < total; i++)
{
Componet componet = nodes[i];
Str bendianhao = componet.find("本点号")->second;
if (bendianhao.empty())
{
Str ID = componet.find("id")->second;
Str type = mValvesMap.find(tableName)->second;
Str newbendian = type + ID;
nodes[i]["编号"] = newbendian;
}
else {
nodes[i]["编号"] = bendianhao;
}
Str code = componet.find("code")->second;
// 跟点
Componets lines = getValueByCode(PIPELINE, code);
size_t lTotal = lines.size();
if (lTotal == 2)
{
Componet lin = lines[0];
nodes[i]["上点号"] = lin.find("本点号")->second;
nodes[i]["本点号"] = lin.find("上点号")->second;
Str diameter = lin.find("管径")->second;
nodes[i]["管径"] = diameter;
Str number = lin.find("id")->second;
addFilter(PIPELINE, number);
// 阀门类型设置特殊字段
std::vector<Str>::iterator iter = std::find(mVavesTables.begin(), mVavesTables.end(), tableName);
if (iter != mVavesTables.end())
{
nodes[i]["类型"] = mValvesMap.find(tableName)->second;
Str fieldType = mParameterMap.find(tableName)->second;
nodes[i]["参数设置"] = componet.find(fieldType)->second;
}
}
}
return nodes;
}
bool CivDbConn::createTable(CivTableTemp& temp)
{
if (&temp == NULL)
......
......@@ -25,8 +25,8 @@ public:
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 getParameter(std::vector <CivParameter>& params)=0;
virtual bool getPatterns(CivPatterns& patterns)=0;
virtual bool getCurves(CivCurves& curves)=0;
virtual bool getDemands(CivDemands& demands)=0;
virtual bool getSources(CivSources& sources)=0;
......@@ -63,20 +63,6 @@ public:
private:
/**
*@brief 获取管网组件数据:管线,节点,水源等(必须组件)
*@tableName: 组件表
*/
Componets getComponets(StrQuote tableName);
Componets getComponetsByWhere(StrQuote tableName, StrQuote where);
/**
*@brief 水泵,阀门 (节点转换为管线)
*@tableName: 组件表
*/
Componets getLikelyPipes(StrQuote tableName);
/**
*@brief 根据字段值条件删除数据
*@table:表
......@@ -100,46 +86,18 @@ private:
*/
bool updateLink(const LinkResultItems& lineItems);
// 添加过滤类型字段值
void addFilter(Str type, Str number);
// 获取过滤集
FiledFilter getFilter() const;
// 获取当前执行错误信息
Str getLastError() const;
/**
*@brief 根据code值寻数据
*@table: 线表
*@code: code
*/
Componets getValueByCode(StrQuote table, StrQuote code);
/**
*@brief 执行sql语句
*@sql: 需要执行的sql语句
*/
virtual bool execSql(Str sql) = 0;
/**
*@brief 清除查询结果集数据
*/
virtual void clearResult() = 0;
/**
*@brief 从查询集取出数据
*@result: 查询结果集
*@comp: 数据容器
*/
virtual void getData(Componets& comp) = 0;
protected:
bool mIsOpen = false; // 数据库连接信息
char* mLastError; // 执行sql的错误信息
private:
FiledFilter mFilter; // 表名:对应的编号
};
......
#include "CivDbConnection.h"
#include "CivCommonUtils.h"
#include<iostream>
#include <sstream>
......@@ -577,12 +578,11 @@ bool CivDbConnection::execSql(std::string sql)
if ( !errorStr.empty())
{
mLastError = error;
std::cout << mLastError << std::endl;
CivSysLog::getInstance()->error(mLastError, "CivDbConnection", __FUNCTION__);
PQclear(mResult);
return false;
}
return true;
}
......
......@@ -4,6 +4,7 @@
#include <set>
#include <libpq-fe.h>
#include "CivTableTemp.h"
#include "CivSysLog.h"
#define DLLEXPORT __declspec(dllexport)
......
#ifndef CIVPGCONN_H
#define CIVPGCONN_H
#include "CivDbConn.h"
#include <libpq-fe.h>
#include "CivDbConn.h"
/**
postgress 数据库
*/
......
......@@ -144,7 +144,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libpq.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>libpq.lib;pandaLog.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OUTDIR)..\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ImportLibrary>$(OutDir)..\lib\$(TargetName).lib</ImportLibrary>
</Link>
......
#include"CivSysLog.h"
#include <time.h>
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
CivSysLog* CivSysLog::mInstance = nullptr;
CivSysLog::SafeClass CivSysLog::safeClass;
CivSysLog::CivSysLog()
{
mLogName = "动态水力计算日志_"+ getCurrentTime2()+".log";
}
CivSysLog* CivSysLog::getInstance()
{
if (mInstance == nullptr)
{
mInstance = new CivSysLog();
}
return mInstance;
}
void CivSysLog::setLog(const std::string& logName)
{
mLogName = logName;
}
std::string CivSysLog::log()
{
return mLogName;
}
std::string CivSysLog::getLogPath()
{
std::string finalPath;
#ifdef _WIN32
wchar_t exeFullPath[MAX_PATH]; // Full path
std::string strPath = "";
GetModuleFileName(NULL, exeFullPath, MAX_PATH);
char CharString[MAX_PATH];
size_t convertedChars = 0;
wcstombs_s(&convertedChars, CharString, MAX_PATH, exeFullPath, _TRUNCATE);
strPath = (std::string)CharString; // Get full path of the file
int pos = strPath.find_last_of('\\', strPath.length());
finalPath = strPath.substr(0, pos); // Return the directory without the file name
#else
char buf1[256];
_getcwd(buf1, sizeof(buf1));
finalPath = buf1;
#endif // _WIN32
return finalPath;
}
// 错误记录
void CivSysLog::error(std::string text, std::string handler, std::string method)
{
writeMesssage(text, handler, method, std::string("error"));
}
// 调试信息记录
void CivSysLog::debug(std::string text, std::string handler, std::string method)
{
writeMesssage(text, handler, method, std::string("debug"));
}
// 一般信息记录
void CivSysLog::info(std::string text, std::string handler, std::string method)
{
writeMesssage(text, handler, method,"Info");
}
// 警告记录
void CivSysLog::warning(std::string text, std::string handler, std::string method)
{
writeMesssage(text,handler,method,"Warning");
}
void CivSysLog::writeMesssage(std::string text, std::string handler, std::string method, std::string loglevel)
{
mOutfile.open(mLogName.c_str(), std::ios::app);
if(mOutfile)
{
mOutfile << "[" << getCurrentTime() << "]" << "[" << loglevel << "] " << method << " " << text << std::endl;
mOutfile.close();
}
}
// 获取当前时间
std::string CivSysLog::getCurrentTime()
{
time_t rawtime;
struct tm* timeinfo;
char s[100];
time(&rawtime);
timeinfo = localtime(&rawtime);
time_t tick = mktime(timeinfo);
strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", timeinfo);
return s;
}
// 获取当前时间
std::string CivSysLog::getCurrentTime2()
{
time_t rawtime;
struct tm* timeinfo;
char s[100];
time(&rawtime);
timeinfo = localtime(&rawtime);
time_t tick = mktime(timeinfo);
strftime(s, sizeof(s), "%Y%m%d%H%M%S", timeinfo);
return s;
}
#ifndef CIVSYSLOG_H
#define CIVSYSLOG_H
#include <string>
#include<iostream>
#include<fstream>
#define SYSLOGEXPORT __declspec(dllexport)
/**
日志记录接口
*/
class SYSLOGEXPORT CivSysLog {
private:
CivSysLog();
// 记录日志级别
enum LogLevel
{
Error,
Warning,
Info
};
// 静态实例化接口
static CivSysLog* mInstance;
std::string getLogPath();
public:
static CivSysLog* getInstance();
/**
* @brief 错误记录
* @param text 日志内容
* @param handler 操作类
* @param methodName 操作方法
*/
void error(std::string text, std::string handler, std::string methodName);
/**
* @brief debug级别信息
* @param text 日志内容
* @param handler 操作类
* @param methodName 操作方法
*/
void debug(std::string text, std::string handler, std::string methodName);
/**
* @brief 一般操作信息信息
* @param text 日志内容
* @param handler 操作类
* @param methodName 调用的操作方法
*/
void info(std::string text, std::string handler, std::string methodName);
/**
* @brief 警告级别
* @param text 日志内容
* @param handler 操作类
* @param methodName 调用的操作方法
*/
void warning(std::string text, std::string handler, std::string methodName);
private:
// 获取当前时间
std::string getCurrentTime();
std::string getCurrentTime2();
void setLog(const std::string& logName);
std::string log();
// 写入日志
void writeMesssage(std::string text, std::string handler, std::string methodName, std::string loglevel);
// 日志文件名
std::string mLogName;
std::ofstream mOutfile;
public:
class SafeClass {
public:
~SafeClass() {
if (mInstance != nullptr) {
delete mInstance;
mInstance = nullptr;
}
}
};
static SafeClass safeClass;
};
#endif // !CIVSYSLOG_H
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{4c38d294-830f-441e-b892-60117aba8bfe}</ProjectGuid>
<RootNamespace>pandaLog</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>..\..\hModelProgram\Program\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(OUTDIR)..\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ImportLibrary>$(OutDir)..\lib\$(TargetName).lib</ImportLibrary>
</Link>
<PostBuildEvent>
<Command>copy CivSysLog.h $(OutDir)..\include /y</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="CivSysLog.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="CivSysLog.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CivSysLog.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CivSysLog.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
\ No newline at end of file
......@@ -18,6 +18,14 @@ CREATE TABLE public.__pattern__
"类型" integer
)
CREATE TABLE public.__pattern__
(
id serial primary key,
model_name character varying(64),
model_type integer,
model_data character varying
)
--曲线表--
CREATE TABLE public.__curve__
(
......
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