Commit 52f38d22 authored by 刘乐's avatar 刘乐

1, 水力计算结果存储优化

parent 49cdef7f
@echo **************************************************
@echo * *
@echo * System Driver *
@echo * *
@echo **************************************************
@rem 设置工程目录
@set Current_path = %cd%
@Set BtMon_Path = %cd%/Toshiba_System_Driver/BtMon_SystemDriver_0725
@Set RMService_path =
@Set TabSysSvc_path =
@Set tosrfec_path =
@Set TosSysHID_path =
@Set TVALZ_path =
@Set TosQnt_path =
@rem 设置工程目录
@Set VS2019_BuildTool_path = "D:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.exe"
@echo === Starting to Build System Driver for WinXP Win8 Win10 ===
@echo 1,开始编译 hydraulicModel工程
@%VS2019_BuildTool_path% hydraulicModel.sln /rebuild "release|x64" /out "compile.log"
@pause
\ No newline at end of file
......@@ -129,7 +129,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(OUTDIR)..\include</AdditionalIncludeDirectories>
</ClCompile>
......
......@@ -2,6 +2,11 @@
#include <libpq-fe.h>
#include "CivHydrFuncInter.h"
#include "iostream"
#include "time.h"
#include "string.h"
using namespace std;
int main(int argc, char* argv[])
{
......@@ -18,7 +23,7 @@ int main(int argc, char* argv[])
bool msg = simulation(findUri, net, flag);
std::cout << msg << std::endl;
getchar();
return msg;
return 0;
}
\ No newline at end of file
......@@ -6,6 +6,10 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pandaDbManager", "pandaDbManager\pandaDbManager.vcxproj", "{2B673FBC-3F91-4952-BDD3-4B802A761162}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pandaAnalysis", "pandaAnalysis\pandaAnalysis.vcxproj", "{47F29C6C-9170-4188-A7AF-6BBCF38BFF6F}"
ProjectSection(ProjectDependencies) = postProject
{BE73E098-3D8C-4F80-88DD-B36A2BB68B64} = {BE73E098-3D8C-4F80-88DD-B36A2BB68B64}
{2B673FBC-3F91-4952-BDD3-4B802A761162} = {2B673FBC-3F91-4952-BDD3-4B802A761162}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EPNAET2", "EPNAET2\EPNAET2.vcxproj", "{BE73E098-3D8C-4F80-88DD-B36A2BB68B64}"
EndProject
......
......@@ -3,6 +3,7 @@
#include "CivTypes.h"
#include "Epanet2.h"
#include "CivInp.h"
#include <time.h>
#include <iostream>
......@@ -48,6 +49,8 @@ bool CivHydrCalc::hydrSimulation(char* fileName, char* rptFile, char* binOutFile
float dHStep;
ENGetVal(4, &dHStep);
bool isFirst = true;
// 计算
do
{
......@@ -67,7 +70,11 @@ bool CivHydrCalc::hydrSimulation(char* fileName, char* rptFile, char* binOutFile
return false;
}
ENnextH(&tstep);
if (isFirst)
{
mDbConn->deleteByDate(NODERESULTTABLE, "日期", currentDate());
isFirst = false;
}
// 获取当前节点和管段数据
getNodeResult(iTime);
getLinkResult(iTime);
......@@ -446,6 +453,21 @@ void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
}
}
std::string CivHydrCalc::currentDate()
{
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", timeinfo);
return s;
}
void CivHydrCalc::getNodeResult(short time)
{
int nNodeCount;
......@@ -473,6 +495,7 @@ void CivHydrCalc::getNodeResult(short time)
ENgetnodevalue(i, EN_MAXVOLUME, &nodeItem.dTankMaxVolume);
// 液位高度
ENgetnodevalue(i, EN_TANKLEVEL, &nodeItem.dTankLevel);
nodeItem.dInterval = time;
nodeItems.push_back(nodeItem);
}
......@@ -488,6 +511,17 @@ void CivHydrCalc::getLinkResult(short time)
for (int i = 1; i <= nLinkCount; i++)
{
LinkResultItem linkItem;
int *typeCode = (int*)malloc(sizeof(int));
ENgetlinktype(i,typeCode );
if (*typeCode != EN_PIPE)
{
free(typeCode);
continue;
}
free(typeCode);
// 编号
ENgetlinkid(i, linkItem.szNo);
// 流量
......@@ -527,6 +561,8 @@ void CivHydrCalc::getLinkResult(short time)
else
strcpy_s(linkItem.szStatus, "开启");
linkItem.dInterval = time;
linkItems.push_back(linkItem);
}
mDbConn->updateLink(linkItems);
......
......@@ -41,7 +41,7 @@ private:
*@inp: inp文件对象
*/
void assemble(const std::string& table, CivInp& inp);
std::string currentDate();
/*
*@brief 获取节点计算结果
*@time: 时间
......
......@@ -49,7 +49,7 @@
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>false</WholeProgramOptimization>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
......@@ -136,13 +136,13 @@
<PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)pandaDbManager;$(OUTDIR)..\include</AdditionalIncludeDirectories>
<Optimization>Disabled</Optimization>
<Optimization>MaxSpeed</Optimization>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libpq.lib;pandaDbManager.lib;EPNAET2.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OUTDIR)..\lib</AdditionalLibraryDirectories>
<ImportLibrary>$(OutDir)..\lib\$(TargetName).lib</ImportLibrary>
......
#include "CivCommonUtils.h"
#include <Windows.h>
#include <wchar.h>
#include <time.h>
std::string CivCommonUtils::string_To_UTF8(const std::string& str)
{
......@@ -56,5 +58,42 @@ std::string CivCommonUtils::UTF8_To_string(const std::string& str)
std::string CivCommonUtils::currentTime()
{
return std::string();
}
\ No newline at end of file
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 CivCommonUtils::currentDate()
{
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", timeinfo);
return s;
}
std::string CivCommonUtils::currentHour()
{
time_t rawtime;
struct tm* timeinfo;
char s[100];
time(&rawtime);
timeinfo = localtime(&rawtime);
time_t tick = mktime(timeinfo);
strftime(s, sizeof(s), "%H", timeinfo);
return s;
}
......@@ -4,6 +4,16 @@
// #include<json/reader.h>
// 字符串转编码
#define TransUTFCoding(name) CivCommonUtils::string_To_UTF8(name)
// 当前系统日期
#define CurrentDate CivCommonUtils::currentDate()
// 获取当前系统时间
#define CurrentTime CivCommonUtils::currentTime()
#define CurrentHour CivCommonUtils::currentHour()
class CivCommonUtils
{
......@@ -24,6 +34,13 @@ public:
*/
static std::string currentTime();
/**
*@brief 获取系统当前日期
*/
static std::string currentDate();
static std::string currentHour();
///**
//*@brief 将json字符串解析为
//*/
......
......@@ -4,8 +4,6 @@
#include<iostream>
#include <sstream>
#define MAX_BUFFER 16384
CivDbConnection::CivDbConnection(char* uri)
: mConn(NULL), mUri(uri)
{
......@@ -63,7 +61,8 @@ Tables CivDbConnection::getTables(StrQuote netName,StrQuote schema)
if (!isValid())
return Tables();
std::string sql = "select \"name\" from public.__layer_info__ where net_code in(select code from public.__layer_net_info__ where \"name\" ='" + netName + "' and \"schema\" = '"+ schema +"')";
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();
......@@ -84,16 +83,35 @@ Tables CivDbConnection::getTables(StrQuote netName,StrQuote schema)
return tables;
}
bool CivDbConnection::deleteByDate(StrQuote table, StrQuote filedName, StrQuote fieldValue)
{
if (!isValid())
return false;
char delSql[256] = "delete from public.\"";
strcat_s(delSql, table.c_str());
strcat_s(delSql, "\" where ");
strcat_s(delSql, filedName.c_str());
strcat_s(delSql, "='");
strcat_s(delSql, fieldValue.c_str());
strcat_s(delSql, "'");
std::string utf8Sql = TransUTFCoding(delSql);
if (!execSql(utf8Sql))
return false;
return true;
}
bool CivDbConnection::updateNode(const NodeResultItems& nodeItems)
{
if (!isValid())
return false;
std::stringstream os;
NodeFieldName filedNames;
if (createTable(NODERESULTTABLE, "public", NODE_TABLE))
{
NodeFieldName filedNames;
{
os << "INSERT INTO public."<< NODERESULTTABLE<<" ( ";
os <<filedNames.Number<<",";
os<< filedNames.dDemand << ",";
......@@ -102,11 +120,17 @@ bool CivDbConnection::updateNode(const NodeResultItems& nodeItems)
os<< filedNames.dPressure<< ",";
os<< filedNames.dTankLevel<< ",";
os<< filedNames.dTankMaxVolume<< ",";
os<< filedNames.dTankVolume;
/* os<< ",";
os<< filedNames.lTime;*/
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++)
......@@ -119,9 +143,10 @@ bool CivDbConnection::updateNode(const NodeResultItems& nodeItems)
os << item.dPressure << ",";
os << item.dTankLevel << ",";
os << item.dTankMaxVolume << ",";
os << item.dTankVolume;
/* os << ",";
os << item.lTime; */
os << item.dTankVolume << ",";
os <<"'"<< CurrentDate <<"',";
os << item.dInterval<<",";
os << "'"<<CurrentTime<<"'";
if (i == (total - 1))
{
os << ")";
......@@ -131,45 +156,28 @@ bool CivDbConnection::updateNode(const NodeResultItems& nodeItems)
os << "),";
}
}
std::string sql = os.str();
std::string sql = TransUTFCoding(preSql) + os.str();
os.clear();
os.str("");
if (!execSql(sql))
return false;
}
// 2, 参数值
size_t total = nodeItems.size();
os << "update public."<< PIPENODE;
for (int i = 0; i < total; i++)
{
NodeResultItem item = nodeItems[i];
char sql[512] = "update public.";
strcat_s(sql, "节点");
strcat_s(sql, " as tb1 set(");
strcat_s(sql, "总水头");
strcat_s(sql, ",压力");
strcat_s(sql, ",实际需水量");
strcat_s(sql, ")");
strcat_s(sql, "=(");
// 拼接值
strcat_s(sql, std::to_string(item.dHead).c_str());
strcat_s(sql, ",");
strcat_s(sql, std::to_string(item.dPressure).c_str());
strcat_s(sql, ",");
strcat_s(sql, std::to_string(item.dDemand).c_str());
strcat_s(sql, ")");
strcat_s(sql, "where tb1.\"");
strcat_s(sql, "本点号");
strcat_s(sql, "\"='");
strcat_s(sql, item.szNo);
strcat_s(sql, "'");
if (!execSql(sql))
return false;
}
os << "UPDATE "<< TransUTFCoding(PIPENODE) <<" AS tb1 set (" << TransUTFCoding("总水头") << "," << TransUTFCoding("压力") << ","
<< TransUTFCoding("实际需水量") << ")=(select " << TransUTFCoding(filedNames.dHead)<<","
<< TransUTFCoding(filedNames.dPressure)<<","<< TransUTFCoding(filedNames.dDemand)
<<" from "<<TransUTFCoding(NODERESULTTABLE)<<" AS tb2 where tb1."
<<TransUTFCoding(filedNames.Number)<<"= tb2."<< TransUTFCoding(filedNames.Number) <<" AND tb2."
<< TransUTFCoding(filedNames.dDate)<<"='"<<CurrentDate<<"' AND tb2."<< TransUTFCoding(filedNames.dInterval)
<<"="<<CurrentHour<<")";
std::string updateSql = os.str();
std::cout << updateSql << std::endl;
os.clear();
os.str("");
if (!execSql(updateSql))
return false;
return true;
}
......@@ -180,27 +188,33 @@ bool CivDbConnection::updateLink(const LinkResultItems& lineItems)
return false;
std::stringstream os;
LinkFiledName filedNames;
std::string currData = CurrentDate;
if (createTable(PIPERESULTTABLE, "public", PIPE_TABLE))
{
LinkFiledName filedNames;
os<< "INSERT INTO public."<< PIPERESULTTABLE <<"( ";
os<< filedNames.szNo<< ",";
os<< filedNames.dFlow<< ",";
/* os<< filedNames.nFlowDirect;
os<< ",";*/
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<< ",";
os<< filedNames.szStatus;*/
/*os<< ",";
os<< filedNames.lTime;*/
os<< filedNames.dFrictionHeadloss<<",";
os << filedNames.szStatus << ",";
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 = lineItems.size();
for (int i = 0; i < total; i++)
......@@ -208,27 +222,30 @@ bool CivDbConnection::updateLink(const LinkResultItems& lineItems)
LinkResultItem item = lineItems[i];
os<<"('" <<item.szNo<<"'"<< ",";
os<< item.dFlow<< ",";
/* int direct = item.nFlowDirect;
os<< direct;*/
// os<< ",";
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<< ",";
os<< "'"<<item.szStatus<<"'";*/
/*os<< ",";
os<< item.lTime;*/
os<< item.dFrictionHeadloss<< ",";
os<< "'"<<TransUTFCoding(item.szStatus)<<"'"<<",";
os <<"'"<< CurrentDate << "',";
os<< item.dInterval<<",";
os <<"'" <<CurrentTime<<"'";
if (i == (total - 1))
os << ")";
else
os << "),";
}
std::string sql = os.str();
std::string utf8Sql = TransUTFCoding(preSql);
std::string sql = utf8Sql + os.str();
os.flush();
os.clear();
os.str("");
if (!execSql(sql))
return false;
......@@ -247,48 +264,67 @@ bool CivDbConnection::updateLink(const LinkResultItems& lineItems)
表二
where
表一.Id = 表二.Id
Str szNo = "编号";
Str dFlow = " 流量";
Str nFlowDirect = "流向";
Str dVelocity="流速";
Str dHeadloss="水头损失";
Str dUnitHeadloss="单位水头损";
Str dFromNodHeadloss="上点水头";
Str dToNodHeadloss="本点水头";
Str dLocalHeadloss="局部水头损";
Str dFrictionHeadloss="摩擦水头损";
Str szStatus="状态";
Str dDate = "时间";
Str dInterval = "时段";
*/
std::string sql = "update public.管段 as tb1 set(";
for (int i = 0; i < total; i++)
{
LinkResultItem item = lineItems[i];
char sql[512] = "update public.管段 as tb1 set(";
strcat_s(sql, "流量");
strcat_s(sql, ",流速");
strcat_s(sql, ",单位水头损");
strcat_s(sql, ",水头总损失");
strcat_s(sql, ",摩擦水头损");
strcat_s(sql, ",上点水头");
strcat_s(sql, ",本点水头");
strcat_s(sql, ",局部水头损");
strcat_s(sql, ")");
strcat_s(sql, "=(");
// 拼接值
strcat_s(sql, std::to_string(item.dFlow).c_str());
strcat_s(sql, ",");
strcat_s(sql, std::to_string(item.dVelocity).c_str());
strcat_s(sql, ",");
strcat_s(sql, std::to_string(item.dUnitHeadloss).c_str());
strcat_s(sql, ",");
strcat_s(sql, std::to_string(item.dHeadloss).c_str());
strcat_s(sql, ",");
strcat_s(sql, std::to_string(item.dFrictionHeadloss).c_str());
strcat_s(sql, ",");
strcat_s(sql, std::to_string(item.dFromNodHeadloss).c_str());
strcat_s(sql, ",");
strcat_s(sql, std::to_string(item.dToNodHeadloss).c_str());
strcat_s(sql, ",");
strcat_s(sql, std::to_string(item.dLocalHeadloss).c_str());
strcat_s(sql, ")where tb1.\"");
strcat_s(sql, "编号");
strcat_s(sql, "\"='");
strcat_s(sql, item.szNo);
strcat_s(sql, "'");
if (!execSql(sql))
return false;
}
//os<< "update public."<< TransUTFCoding(PIPELINE)<<" as tb1 set("<< TransUTFCoding(filedNames.dFlow)
// << TransUTFCoding(filedNames.dVelocity)<<TransUTFCoding(filedNames.dUnitHeadloss)<<TransUTFCoding(filedNames.dHeadloss)
// <<TransUTFCoding(filedNames.dFrictionHeadloss)<<","<<TransUTFCoding(filedNames.dFromNodHeadloss)<<","
// <<TransUTFCoding(filedNames.dToNodHeadloss)<<","<<TransUTFCoding(filedNames.dLocalHeadloss);
//for (int i = 0; i < total; i++)
//{
// LinkResultItem item = lineItems[i];
// char sql[512] = "update public.管段 as tb1 set(";
// strcat_s(sql, "流量");
// strcat_s(sql, ",流速");
// strcat_s(sql, ",单位水头损");
// strcat_s(sql, ",水头总损失");
// strcat_s(sql, ",摩擦水头损");
// strcat_s(sql, ",上点水头");
// strcat_s(sql, ",本点水头");
// strcat_s(sql, ",局部水头损");
// strcat_s(sql, ")");
// strcat_s(sql, "=(");
// // 拼接值
// strcat_s(sql, std::to_string(item.dFlow).c_str());
// strcat_s(sql, ",");
// strcat_s(sql, std::to_string(item.dVelocity).c_str());
// strcat_s(sql, ",");
// strcat_s(sql, std::to_string(item.dUnitHeadloss).c_str());
// strcat_s(sql, ",");
// strcat_s(sql, std::to_string(item.dHeadloss).c_str());
// strcat_s(sql, ",");
// strcat_s(sql, std::to_string(item.dFrictionHeadloss).c_str());
// strcat_s(sql, ",");
// strcat_s(sql, std::to_string(item.dFromNodHeadloss).c_str());
// strcat_s(sql, ",");
// strcat_s(sql, std::to_string(item.dToNodHeadloss).c_str());
// strcat_s(sql, ",");
// strcat_s(sql, std::to_string(item.dLocalHeadloss).c_str());
// strcat_s(sql, ")where tb1.\"");
// strcat_s(sql, "编号");
// strcat_s(sql, "\"='");
// strcat_s(sql, item.szNo);
// strcat_s(sql, "'");
// // 中文转码
// const std::string finalSql = TransUTFCoding(sql);
// if (!execSql(finalSql))
// return false;
}
return true;
}
......@@ -298,7 +334,8 @@ Componets CivDbConnection::getComponets(StrQuote tableName)
if (!isValid())
return Nodes();
std::string sql = "select * from public.\"" + tableName + "\"";
std::string utf8Name = TransUTFCoding(tableName);
std::string sql = "select * from public.\"" + utf8Name + "\"";
if (!execSql(sql))
{
return Nodes();
......@@ -317,9 +354,11 @@ Componets CivDbConnection::getComponetsByWhere(StrQuote tableName, StrQuote wher
if (!isValid())
return Componets();
std::string utf8Name = TransUTFCoding(tableName);
std::string utf8Where = TransUTFCoding(where);
char sql[128] = "select * from table ";
strcat_s(sql, tableName.c_str());
strcat_s(sql, where.c_str());
strcat_s(sql, utf8Name.c_str());
strcat_s(sql, utf8Where.c_str());
if (!execSql(sql))
{
......@@ -364,8 +403,9 @@ Componets CivDbConnection::getNodeByCode(StrQuote table, StrQuote code)
if (!isValid())
return Nodes();
char sql[256] = "select * from public.\"";
strcat_s(sql, table.c_str());
strcat_s(sql, TransUTFCoding(table).c_str());
strcat_s(sql, "\"");
strcat_s(sql, " where code = '");
strcat_s(sql, code.c_str());
......@@ -388,7 +428,7 @@ Componets CivDbConnection::getLineByCode(StrQuote table, StrQuote code)
return Nodes();
char sql[256] = "select * from public.\"";
strcat_s(sql, table.c_str());
strcat_s(sql, TransUTFCoding(table).c_str());
strcat_s(sql,"\"");
strcat_s(sql, " where from_code = '");
strcat_s(sql, code.c_str());
......@@ -414,8 +454,8 @@ Componets CivDbConnection::getLikelyPipes(StrQuote tableName)
return Componets();
// 查询点数据
char sql[256] = "select * from \"";
strcat_s(sql, tableName.c_str());
char sql[256] = "select * from public.\"";
strcat_s(sql, TransUTFCoding(tableName).c_str());
strcat_s(sql,"\"");
if (!execSql(sql))
......@@ -475,8 +515,6 @@ Componets CivDbConnection::getLikelyPipes(StrQuote tableName)
Str ID = componet.find("id")->second;
Str type = mValvesMap.find(tableName)->second;
Str newbendian = type + ID;
std::string upSql = "Update "+ tableName +" Set 本点号 ='"+ newbendian +"' Where id ='"+ID+"'";
execSql(upSql);
nodes[i]["编号"] = newbendian;
}
else {
......@@ -599,9 +637,10 @@ bool CivDbConnection::createTable(StrQuote tableName, StrQuote schema,TableType
tableTemp.addProperty(filedName.dTankVolume, CivTableTemp::FILED_DOUBLE);
tableTemp.addProperty(filedName.dTankMaxVolume, CivTableTemp::FILED_DOUBLE);
tableTemp.addProperty(filedName.dTankLevel, CivTableTemp::FILED_DOUBLE);
tableTemp.addProperty("水质", CivTableTemp::FILED_DOUBLE);
tableTemp.addProperty("时间", CivTableTemp::FILED_DATETIME);
tableTemp.addProperty("时段", CivTableTemp::FILED_INT);
tableTemp.addProperty(filedName.dQuality, CivTableTemp::FILED_DOUBLE);
tableTemp.addProperty(filedName.dDate, CivTableTemp::FILED_DATE);
tableTemp.addProperty(filedName.dInterval, CivTableTemp::FILED_INT);
tableTemp.addProperty(filedName.dModifyTime, CivTableTemp::FILED_DATETIME);
}
break;
case PIPE_TABLE:
......@@ -618,9 +657,10 @@ bool CivDbConnection::createTable(StrQuote tableName, StrQuote schema,TableType
tableTemp.addProperty(pipeFileds.dLocalHeadloss, CivTableTemp::FILED_DOUBLE);
tableTemp.addProperty(pipeFileds.dFrictionHeadloss, CivTableTemp::FILED_DOUBLE);
tableTemp.addProperty(pipeFileds.szStatus, CivTableTemp::FILED_VARCHAR);
tableTemp.addProperty("水质", CivTableTemp::FILED_DOUBLE);
tableTemp.addProperty("时间", CivTableTemp::FILED_DATETIME);
tableTemp.addProperty("时段", CivTableTemp::FILED_INT);
tableTemp.addProperty(pipeFileds.dQuality, CivTableTemp::FILED_DOUBLE);
tableTemp.addProperty(pipeFileds.dDate, CivTableTemp::FILED_DATE);
tableTemp.addProperty(pipeFileds.dInterval, CivTableTemp::FILED_INT);
tableTemp.addProperty(pipeFileds.dModifyTime, CivTableTemp::FILED_DATETIME);
}
break;
case PATTERN_TABLE:
......@@ -653,26 +693,27 @@ bool CivDbConnection::createTable(StrQuote tableName, StrQuote schema,TableType
break;
}
std::string sql = tableTemp.createSql();
return execSql(sql);
std::string finalSql = TransUTFCoding(sql);
return execSql(finalSql);
}
bool CivDbConnection::execSql(std::string sql)
{
if (sql == "" || sql.empty())
if (sql.empty())
return false;
std::string sqlStr = CivCommonUtils::string_To_UTF8(sql);
const char* finalSql = sqlStr.c_str();
mResult = PQexec(mConn, finalSql);
if (PQstatus(mConn) == PGRES_BAD_RESPONSE)
mResult = PQexec(mConn, sql.c_str());
char* error = PQresultErrorMessage(mResult);
std::string errorStr = error;
if ( !errorStr.empty())
{
mLastError = PQresultErrorMessage(mResult);
mLastError = error;
std::cout << mLastError << std::endl;
PQclear(mResult);
return false;
}
return true;
}
......
......@@ -8,6 +8,7 @@
// 字段过滤
#define FiledFilter std::map<Str,std::set<Str>>
class CivDbConnection;
/**
......@@ -59,6 +60,8 @@ public:
*/
bool createTable(StrQuote tableName, StrQuote schema, TableType tableType);
bool deleteByDate(StrQuote table, StrQuote filedName, StrQuote fieldValue);
/**
*@brief 更新点表数据
*@nodeItems:需要更新的值
......
......@@ -12,6 +12,7 @@ CivTableTemp::CivTableTemp(std::string tableName)
mFieldTyepMap.insert(std::pair<FieldType, std::string>(CivTableTemp::FILED_VARCHAR128, "varchar(20)"));
mFieldTyepMap.insert(std::pair<FieldType, std::string>(CivTableTemp::FILED_DATETIME, "timestamp"));
mFieldTyepMap.insert(std::pair<FieldType, std::string>(CivTableTemp::FILED_JSON, "json"));
mFieldTyepMap.insert(std::pair<FieldType, std::string>(CivTableTemp::FILED_DATE, "date"));
}
CivTableTemp::~CivTableTemp()
......
......@@ -28,7 +28,8 @@ public:
FILED_VARCHAR64,
FILED_VARCHAR128,
FILED_DATETIME,
FILED_JSON
FILED_JSON,
FILED_DATE
};
explicit CivTableTemp(std::string tableName);
......
......@@ -206,8 +206,10 @@ struct NodeFieldName
Str dTankVolume=" 水池容量";
Str dTankMaxVolume=" 水池最大容量";
Str dTankLevel=" 液位高度";
Str lTime = "时间";
Str dQuality = "水质";
Str dDate = "日期";
Str dInterval = "时段";
Str dModifyTime = "修改时间";
};
struct LinkFiledName
......@@ -223,8 +225,10 @@ struct LinkFiledName
Str dLocalHeadloss="局部水头损";
Str dFrictionHeadloss="摩擦水头损";
Str szStatus="状态";
Str lTime = "时间";
Str dQuality = "水质";
Str dDate = "日期";
Str dInterval = "时段";
Str dModifyTime = "修改时间";
};
// 水力计算管点结果缓存
......@@ -239,7 +243,8 @@ struct NodeResultItem
float dTankVolume; // 水池容量
float dTankMaxVolume; // 水池最大容量
float dTankLevel; // 液位高度
long lTime;
char dDate[32];// 日期
int dInterval; // 时段
};
// 水力计算管线结果缓存
......@@ -256,7 +261,8 @@ struct LinkResultItem
float dLocalHeadloss; // 局部水头损失
float dFrictionHeadloss; // 摩擦水头损失
char szStatus[20]; // 状态
long lTime;
char dDate[32];// 日期
int dInterval; // 时段
};
#define NodeResultItems std::vector<NodeResultItem>
......
......@@ -49,7 +49,7 @@
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>false</WholeProgramOptimization>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
......@@ -137,13 +137,13 @@
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WINDOWS</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(OUTDIR)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<Optimization>Disabled</Optimization>
<Optimization>MaxSpeed</Optimization>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libpq.lib;json_vc71_libmt.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OUTDIR)..\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ImportLibrary>$(OutDir)..\lib\$(TargetName).lib</ImportLibrary>
......
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