CivInpDbHelper.cpp 15.7 KB
Newer Older
刘乐's avatar
刘乐 committed
1
#include "CivInpDbHelper.h"
刘乐's avatar
刘乐 committed
2
#include "CivTableFields.h"
刘乐's avatar
刘乐 committed
3
#include "CivConnection.h"
4
#include "CivPgDbConnection.h"
刘乐's avatar
刘乐 committed
5

刘乐's avatar
刘乐 committed
6 7
#include <algorithm>

刘乐's avatar
刘乐 committed
8 9
CivInpDbHelper::CivInpDbHelper(const std::string& uri)
	:CivInpHelperAbs(uri)
刘乐's avatar
刘乐 committed
10
{
刘乐's avatar
刘乐 committed
11
	mCondtion = "1=1 ";
刘乐's avatar
刘乐 committed
12
	isDelayTime = true;
刘乐's avatar
刘乐 committed
13 14 15 16 17 18 19 20
}

CivInpDbHelper::~CivInpDbHelper()
{
}

bool CivInpDbHelper::getNode(CivNode& node)
{
刘乐's avatar
刘乐 committed
21
	JunctionTable nodeTableFields;
刘乐's avatar
刘乐 committed
22
	std::vector<std::string> fields;
刘乐's avatar
刘乐 committed
23

刘乐's avatar
刘乐 committed
24 25 26 27
	fields.push_back(nodeTableFields.sn);
	fields.push_back(nodeTableFields.elev);
	fields.push_back(nodeTableFields.baseDemand);
	fields.push_back(nodeTableFields.demandPattern);
刘乐's avatar
刘乐 committed
28 29 30

	std::vector<std::map<std::string,std::string>> resultVector;	
	mDbConn->query(PIPENODE, fields, resultVector, mCondtion);
刘乐's avatar
刘乐 committed
31 32 33 34 35 36 37 38

	// 编辑包装结果
	size_t total = resultVector.size();
	for (int i = 0; i < total; i++)
	{
		std::map<std::string, std::string> map = resultVector[i];
		CivNode::NodeTable nodeTable;

刘乐's avatar
刘乐 committed
39 40
		nodeTable.ID = map.find(nodeTableFields.sn)->second;
		nodeTable.Elev = map.find(nodeTableFields.elev)->second;
刘乐's avatar
刘乐 committed
41

刘乐's avatar
刘乐 committed
42 43 44
		std::string patternID = map.find(nodeTableFields.demandPattern)->second;
		std::string demand = map.find(nodeTableFields.baseDemand)->second;

刘乐's avatar
刘乐 committed
45
		// 处理延时模拟情况
刘乐's avatar
刘乐 committed
46
		handleDelayPattern(demand, patternID, nodeTable.Demand, nodeTable.PatternId);
刘乐's avatar
刘乐 committed
47
		
刘乐's avatar
刘乐 committed
48 49
		node.addItem(nodeTable);
	}
刘乐's avatar
刘乐 committed
50 51 52 53 54 55 56

	// 添加处理的阀门产生的节点
	size_t size = mNodeVec.size();
	for (int i = 0; i < size; i++)
	{
		node.addItem(mNodeVec[i]);
	}
刘乐's avatar
刘乐 committed
57 58 59 60 61
	return true;
}

bool CivInpDbHelper::getPipe(CivPipe& pipes)
{
刘乐's avatar
刘乐 committed
62 63
	PipeTable pipeTable;

刘乐's avatar
刘乐 committed
64 65 66 67 68 69 70 71 72 73 74
	std::vector<std::string> fields;
	fields.push_back(pipeTable.snNo); 
	fields.push_back(pipeTable.startPoint);
	fields.push_back(pipeTable.endPoint); 
	fields.push_back(pipeTable.length); 
	fields.push_back(pipeTable.diameter); 
	fields.push_back(pipeTable.friction); 
	fields.push_back(pipeTable.localLoss);
	fields.push_back(pipeTable.status);
	fields.push_back(pipeTable.code);
	
刘乐's avatar
刘乐 committed
75
	std::vector<std::map<std::string, std::string>> resultVector;
刘乐's avatar
刘乐 committed
76

刘乐's avatar
刘乐 committed
77
	std::string condition = "\"from_layer\" not in ('阀门','水泵' ) and \"to_layer\" not in ('阀门','水泵' )";
刘乐's avatar
刘乐 committed
78 79
	mDbConn->query(PIPELINE, fields, resultVector, condition);

刘乐's avatar
刘乐 committed
80 81 82 83 84 85 86 87
	size_t total = resultVector.size();
    for (int i = 0; i < total; i++)
    {
        CivPipe::PipesTable pipe;

		std::map<std::string, std::string> map = resultVector[i];

		pipe.ID = map.find(pipeTable.snNo)->second;
刘乐's avatar
刘乐 committed
88 89
		pipe.Node1 = map.find(pipeTable.startPoint)->second;
		pipe.Node2 = map.find(pipeTable.endPoint)->second;
刘乐's avatar
刘乐 committed
90 91 92
		pipe.Length = map.find(pipeTable.length)->second;
		pipe.Diameter = map.find(pipeTable.diameter)->second;
		pipe.Roughness = map.find(pipeTable.friction)->second;
刘乐's avatar
刘乐 committed
93
		pipe.MinorLoss = map.find(pipeTable.localLoss)->second;
刘乐's avatar
刘乐 committed
94
		pipe.Status = map.find(pipeTable.status)->second;
刘乐's avatar
刘乐 committed
95
		pipe.code = map.find(pipeTable.code)->second;
刘乐's avatar
刘乐 committed
96 97
		pipes.addItem(pipe);
    }
刘乐's avatar
刘乐 committed
98 99 100 101 102 103
	// 构造的管段
	size_t size = mPipesVec.size();
	for (int i = 0; i < size; i++)
	{
		pipes.addItem(mPipesVec[i]);
	}
刘乐's avatar
刘乐 committed
104 105 106 107 108
	return true;
}

bool CivInpDbHelper::getTank(CivTank& tanks)
{
刘乐's avatar
刘乐 committed
109
	TankTable tankTable;
刘乐's avatar
刘乐 committed
110

刘乐's avatar
刘乐 committed
111 112 113 114 115 116 117 118 119 120
	std::vector<std::string> fields;

	fields.push_back(tankTable.sn);
	fields.push_back(tankTable.elev);
	fields.push_back(tankTable.initLevel);
	fields.push_back(tankTable.minLevel);
	fields.push_back(tankTable.maxLevel);
	fields.push_back(tankTable.diametor);
	fields.push_back(tankTable.minVolume);
	fields.push_back(tankTable.volumeCurve);
刘乐's avatar
刘乐 committed
121 122

	std::vector<std::map<std::string, std::string>> resultVector;
刘乐's avatar
刘乐 committed
123
	mDbConn->query(TANK, fields, resultVector, mCondtion);
刘乐's avatar
刘乐 committed
124 125 126 127 128 129 130

	size_t total = resultVector.size();
	for (int i = 0; i < total; i++)
	{
		CivTank::TankTable tank;
		std::map<std::string, std::string>map = resultVector[i];

刘乐's avatar
刘乐 committed
131
		tank.ID = map.find(tankTable.sn)->second;
刘乐's avatar
刘乐 committed
132 133
		tank.Elev = map.find(tankTable.elev)->second;
		tank.InitLevel = map.find(tankTable.initLevel)->second;
刘乐's avatar
刘乐 committed
134 135
		tank.MinLevel = map.find(tankTable.minLevel)->second;
		tank.MaxLevel = map.find(tankTable.maxLevel)->second;
刘乐's avatar
刘乐 committed
136
		tank.Diameter = map.find(tankTable.diametor)->second;
刘乐's avatar
刘乐 committed
137 138
		tank.MinVol = map.find(tankTable.minVolume)->second;
		tank.VolCurve = map.find(tankTable.volumeCurve)->second;
刘乐's avatar
刘乐 committed
139 140 141 142 143 144 145 146
		
		tanks.addItem(tank);
	}
	return true;
}

bool CivInpDbHelper::getValve(CivValve& valves)
{
刘乐's avatar
刘乐 committed
147 148 149 150
	size_t size = mValuvesVec.size();
	for (int i = 0; i < size; i++)
	{
		valves.addItem(mValuvesVec[i]);
刘乐's avatar
刘乐 committed
151
	}
刘乐's avatar
刘乐 committed
152

刘乐's avatar
刘乐 committed
153 154 155 156 157
	return true;
}

bool CivInpDbHelper::getPumps(CivPumps& pumps)
{
刘乐's avatar
刘乐 committed
158
	PumpTable pmTable;
刘乐's avatar
刘乐 committed
159 160 161 162 163 164 165
	std::vector<std::string> fields;

	fields.push_back(pmTable.sn);
	fields.push_back(pmTable.startPoint);
	fields.push_back(pmTable.endPoint);
	fields.push_back(pmTable.headCurve);
	fields.push_back(pmTable.power);
刘乐's avatar
刘乐 committed
166 167

	std::vector<std::map<std::string, std::string>> resultVector;
刘乐's avatar
刘乐 committed
168
	mDbConn->query(PUMP, fields, resultVector, mCondtion);
刘乐's avatar
刘乐 committed
169 170 171 172 173 174 175
	
	size_t totals = resultVector.size();
	for (int i = 0; i < totals; i++)
	{
		CivPumps::PumpTable pump;
		std::map<std::string, std::string> map = resultVector[i];

刘乐's avatar
刘乐 committed
176
		pump.ID = map.find(pmTable.sn)->second;
刘乐's avatar
刘乐 committed
177 178
		pump.Node1 = map.find(pmTable.startPoint)->second;
		pump.Node2 = map.find(pmTable.endPoint)->second;
刘乐's avatar
刘乐 committed
179 180 181 182 183
		std::string param;
		
		std::string curve = map.find(pmTable.headCurve)->second;
		if (curve != "")
			param.append("head " + curve);
刘乐's avatar
刘乐 committed
184

刘乐's avatar
刘乐 committed
185 186 187 188 189
		std::string power = map.find(pmTable.power)->second;
		if (power != "")
			param.append(" power " + power);
	
		pump.Parameters = param;
刘乐's avatar
刘乐 committed
190 191 192 193 194 195 196
		pumps.addItem(pump);
	}
	return true;
}

bool CivInpDbHelper::getReservoirs(CivReservoirs& reservoirs)
{
刘乐's avatar
刘乐 committed
197
	ResourcesTable restemTable;
刘乐's avatar
刘乐 committed
198

刘乐's avatar
刘乐 committed
199 200 201 202 203
	std::vector<std::string> fields;

	fields.push_back(restemTable.sn);
	fields.push_back(restemTable.totalHead);
	fields.push_back(restemTable.headPattern);
刘乐's avatar
刘乐 committed
204 205

	std::vector<std::map<std::string, std::string>> resultVector;
刘乐's avatar
刘乐 committed
206
	mDbConn->query(RESIVOIR, fields, resultVector, mCondtion);
刘乐's avatar
刘乐 committed
207 208 209 210 211 212 213

	size_t totals = resultVector.size();
	for (int i = 0; i < totals; i++)
	{
		CivReservoirs::ReservoirsTable resTable;
		std::map<std::string, std::string> map = resultVector[i];

刘乐's avatar
刘乐 committed
214 215
		resTable.ID = map.find(restemTable.sn)->second;
		resTable.Head = map.find(restemTable.totalHead)->second;
刘乐's avatar
刘乐 committed
216 217 218 219 220 221 222 223 224
		resTable.Pattern = map.find(restemTable.headPattern)->second;

		reservoirs.addItem(resTable);
	}
	return true;
}

bool CivInpDbHelper::getCoordinates(CivCoordinates& coord)
{
刘乐's avatar
刘乐 committed
225
	JunctionTable nodeTable;
刘乐's avatar
刘乐 committed
226

刘乐's avatar
刘乐 committed
227 228 229 230 231 232 233
	std::vector<std::string> fields;

	fields.push_back(nodeTable.sn);
	fields.push_back(nodeTable.xCoord);
	fields.push_back(nodeTable.yCoord);
	fields.push_back(nodeTable.code);

刘乐's avatar
刘乐 committed
234
	std::vector<std::map<std::string, std::string>> resultVector;
刘乐's avatar
刘乐 committed
235 236 237
	mDbConn->query(PIPENODE, fields, resultVector, mCondtion);
	mDbConn->query(TANK, fields, resultVector, mCondtion);
	mDbConn->query(RESIVOIR, fields, resultVector, mCondtion);
刘乐's avatar
刘乐 committed
238 239 240 241 242 243 244 245 246 247

	size_t totals = resultVector.size();
	for (int i = 0; i < totals; i++)
	{
		CivCoordinates::CoordTable coordTable;
		std::map<std::string, std::string> map = resultVector[i];

		coordTable.ID = map.find(fields[0])->second;
		coordTable.XCoord = map.find(fields[1])->second;
		coordTable.YCoord = map.find(fields[2])->second;
刘乐's avatar
刘乐 committed
248
		coordTable.code = map.find(nodeTable.code)->second;
刘乐's avatar
刘乐 committed
249 250 251

		coord.addItem(coordTable);
	}
刘乐's avatar
刘乐 committed
252 253 254 255 256 257
	// 加入阀门处理的节点坐标
	size_t size = mCoords.size();
	for (int i = 0; i < size; i++)
	{
		coord.addItem(mCoords[i]);
	}
刘乐's avatar
刘乐 committed
258 259 260 261 262 263

	return true;
}

bool CivInpDbHelper::getQuality(CivQuality& quality)
{
刘乐's avatar
刘乐 committed
264
	JunctionTable nodeTable;
刘乐's avatar
刘乐 committed
265

刘乐's avatar
刘乐 committed
266 267 268 269 270 271
	std::vector<std::string> fields;

	fields.push_back(nodeTable.sn);
	fields.push_back(nodeTable.initQuality);
	fields.push_back(nodeTable.chlorine);

刘乐's avatar
刘乐 committed
272
	std::vector<std::map<std::string, std::string>> resultVector;
刘乐's avatar
刘乐 committed
273
	mDbConn->query(PIPENODE, fields, resultVector, mCondtion);
刘乐's avatar
刘乐 committed
274 275
	mDbConn->query(RESIVOIR, fields, resultVector,mCondtion);
	mDbConn->query(TANK, fields, resultVector, mCondtion);
刘乐's avatar
刘乐 committed
276 277 278 279 280 281 282

	size_t totals = resultVector.size();
	for (int i = 0; i < totals; i++)
	{
		CivQuality::QualityTable quliTable;

		std::map<std::string, std::string> map = resultVector[i];
刘乐's avatar
刘乐 committed
283 284 285 286 287 288 289 290 291 292 293 294
		quliTable.ID = map.find(nodeTable.sn)->second;
		switch (mQualityType)
		{
		
		case Chlorine:
			quliTable.InitQuality = map.find(nodeTable.chlorine)->second;
			break;
		case Age:
		default:
			quliTable.InitQuality = map.find(nodeTable.initQuality)->second;
			break;
		}
刘乐's avatar
刘乐 committed
295 296 297 298 299

		quality.addItem(quliTable);
	}

	return true;
刘乐's avatar
刘乐 committed
300 301 302 303
}

bool CivInpDbHelper::getStatus(CivStatus& status)
{
刘乐's avatar
刘乐 committed
304 305 306 307 308
	// 阀门状态值,
	size_t statuSize = mStatusVec.size();
	for (int i = 0; i < statuSize; i++)
	{
		status.addItem(mStatusVec[i]);
刘乐's avatar
刘乐 committed
309 310 311 312 313
	}
	
	return true;
}

刘乐's avatar
刘乐 committed
314
void CivInpDbHelper::handlePump()
刘乐's avatar
刘乐 committed
315
{
刘乐's avatar
刘乐 committed
316 317
	
}
刘乐's avatar
刘乐 committed
318

刘乐's avatar
刘乐 committed
319 320 321 322 323
void CivInpDbHelper::handleValve()
{
		  //阀门的下游管段
		std::string dwPipeSql = "select pipe.\"编号\", ('UP' || pipe.\"起始节点\") as \"起始节点\", pipe.\"终止节点\", pipe.\"管长\", pipe.\"管径\",\
			pipe.\"摩阻系数\" ,pipe.\"局损系数\" from \"管段\" as pipe where pipe.\"from_layer\" = '阀门'";
刘乐's avatar
刘乐 committed
324

刘乐's avatar
刘乐 committed
325 326
		if (!mDbConn->execSql(dwPipeSql))
			return;
刘乐's avatar
刘乐 committed
327

刘乐's avatar
刘乐 committed
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
		std::vector<std::map<std::string, std::string>> upPipes;
		mDbConn->queryResult(upPipes);
	
		size_t total = upPipes.size();
		for (int i = 0; i < total; i++)
		{
			std::map<std::string, std::string> pipe = upPipes[i];

			CivPipe::Table pipeStruct;
			pipeStruct.ID = pipe.find("编号")->second;
			pipeStruct.code = pipe.find("code")->second;
			pipeStruct.Node1 = pipe.find("起始节点")->second;
			pipeStruct.Node2 = pipe.find("终止节点")->second;
			pipeStruct.Length = pipe.find("管长")->second;
			pipeStruct.Diameter = pipe.find("管径")->second;
			pipeStruct.Roughness = pipe.find("摩阻系数")->second;
			pipeStruct.Status = "Open";
			pipeStruct.MinorLoss = pipe.find("局损系数")->second;

			mPipesVec.push_back(pipeStruct);
		}
	
		 // 阀门的上游管段
		std::string upPipeSql = "select pipe.\"编号\", pipe.\"起始节点\", ('DW' || pipe.\"终止节点\") as \"终止节点\", pipe.\"管长\", pipe.\"管径\", \
			pipe.\"摩阻系数\",pipe.\"局损系数\" from \"管段\" as pipe where pipe.\"to_layer\" = '阀门'";
刘乐's avatar
刘乐 committed
353

刘乐's avatar
刘乐 committed
354 355
		if (!mDbConn->execSql(upPipeSql))
			return;
刘乐's avatar
刘乐 committed
356

刘乐's avatar
刘乐 committed
357 358
		std::vector<std::map<std::string, std::string>> downPipes;
		mDbConn->queryResult(downPipes);
刘乐's avatar
刘乐 committed
359

刘乐's avatar
刘乐 committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
		size_t dtotal = downPipes.size();
		for (int i = 0; i < dtotal; i++)
		{
			std::map<std::string, std::string> pipe = downPipes[i];

			CivPipe::Table pipeStruct;
			pipeStruct.ID = pipe.find("编号")->second;
			pipeStruct.code = pipe.find("code")->second;
			pipeStruct.Node1 = pipe.find("起始节点")->second;
			pipeStruct.Node2 = pipe.find("终止节点")->second;
			pipeStruct.Length = pipe.find("管长")->second;
			pipeStruct.Diameter = pipe.find("管径")->second;
			pipeStruct.Roughness = pipe.find("摩阻系数")->second;
			pipeStruct.Status = "Open";
			pipeStruct.MinorLoss = pipe.find("局损系数")->second;

			mPipesVec.push_back(pipeStruct);
		}
刘乐's avatar
刘乐 committed
378

刘乐's avatar
刘乐 committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
		//-- 阀门信息--
		// 构造阀门起始节点
		std::string vaStartSql = "SELECT \
		'UP' || va.\"本点号\" AS \"本点号\", vnode.\"高程\", vnode.\"基本需水量\", vnode.\"需水量模式\" \
		, (va.\"横坐标\" - 1) AS \"横坐标\", (va.\"纵坐标\" - 1) AS \"纵坐标\", va.\"本点号\" as \"阀门本点号\",\
		va.\"类型\" as \"阀门类型\", ('UP' || va.\"本点号\") as \"阀门起始节点\", \
		va.\"直径\" as \"阀门直径\",va.\"固定状态\" as \"阀门状态\",va.\"设置\" as \"阀门设置\",va.\"水损系数\"\
		FROM \"阀门\" va, ( \
			SELECT node.\"本点号\", node.\"高程\", node.\"基本需水量\", node.\"需水量模式\", node.\"横坐标\"\
			, node.\"纵坐标\", va.\"终止节点\"\
			FROM \"节点\" node, (\
				SELECT pipe.\"编号\", pipe.\"起始节点\", pipe.\"终止节点\", pipe.\"管长\", pipe.\"管径\"\
				, pipe.\"摩阻系数\"\
				FROM \"管段\" pipe\
				WHERE pipe.\"to_layer\" = '阀门'\
				) va\
			WHERE node.\"本点号\" = va.\"起始节点\"\
			) vnode \
		WHERE vnode.\"终止节点\" = va.\"本点号\"";

		if (!mDbConn->execSql(vaStartSql))
			return;

		std::vector<std::map<std::string, std::string>> valvesVec;
		mDbConn->queryResult(valvesVec);

		std::map<std::string, CivValve::ValveTable> valveTableMap;
		std::map<std::string, CivPipe::PipesTable> pipeTableMap;
		size_t valvsSize = valvesVec.size();
		for (int i = 0; i < valvsSize; i++)
		{
			std::map<std::string, std::string> valveMap = valvesVec[i];
刘乐's avatar
刘乐 committed
411

刘乐's avatar
刘乐 committed
412 413 414 415 416 417 418 419 420
			// 构造节点
			CivNode::NodeTable nodeTable;
			std::string szNo = valveMap.find("本点号")->second;
			nodeTable.ID = szNo;	
			nodeTable.Elev = valveMap.find("高程")->second;
			
			std::string patternID = valveMap.find("需水量模式")->second;
			std::string demand = valveMap.find("基本需水量")->second;
			handleDelayPattern(demand, patternID, nodeTable.Demand, nodeTable.PatternId);
刘乐's avatar
刘乐 committed
421

刘乐's avatar
刘乐 committed
422
			mNodeVec.push_back(nodeTable);
刘乐's avatar
刘乐 committed
423

刘乐's avatar
刘乐 committed
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
			// 节点坐标
			CivCoordinates::CoordTable coordTable;
			coordTable.ID = szNo;
			coordTable.XCoord = valveMap.find("横坐标")->second;
			coordTable.YCoord = valveMap.find("纵坐标")->second;

			mCoords.push_back(coordTable);
	
			std::string valveSn = valveMap.find("阀门本点号")->second;
			std::string valveType = valveMap.find("阀门类型")->second;
			
			if (valveType == "BV") // 止回阀,转成管段
			{
				CivPipe::Table pipeStruct;

				pipeStruct.ID = valveSn;
				pipeStruct.Node1 = szNo;
				pipeStruct.Length = "2";
				pipeStruct.Diameter = valveMap.find("阀门直径")->second;
				pipeStruct.Roughness =std::string("130");//valveMap.find("摩阻系数")->second;
				pipeStruct.Status = (valveMap.find("阀门状态")->second == "Open")?"Open":"CV";
				pipeStruct.MinorLoss = "0";

				auto pter = std::make_pair(valveSn, pipeStruct);
				pipeTableMap.insert(pter);
刘乐's avatar
刘乐 committed
449
			}
刘乐's avatar
刘乐 committed
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
			else
			{
				// 阀门
				CivValve::ValveTable valveTable;
				valveTable.ID = valveSn;
				valveTable.Node1 = szNo;
				valveTable.Diameter = valveMap.find("阀门直径")->second;
				valveTable.Type = valveType;
				valveTable.Setting = valveMap.find("阀门设置")->second;
				valveTable.MinorLoss = valveMap.find("水损系数")->second;

				valveTableMap.insert(std::make_pair(szNo, valveTable));

				// 阀门状态组件
				CivStatus::StatusTable statusTable;
				statusTable.ID = valveSn;
				statusTable.Setting = valveMap.find("固定状态")->second;
				
				mStatusVec.push_back(statusTable);
			}
			
		}

	//--构造阀门终止节点
	std::string vaEndSql =	"SELECT\
		'DW' || va.\"本点号\" AS \"本点号\", vnode.\"高程\", vnode.\"基本需水量\", vnode.\"需水量模式\"\
		, (va.\"横坐标\" + 1) AS \"横坐标\", (va.\"纵坐标\" + 1) AS \"纵坐标\", va.\"本点号\" as \"阀门本点号\",\
		va.\"类型\" as \"阀门类型\", ('DW' || va.\"本点号\") as \"阀门终止节点\"\
		FROM \"阀门\" va, (\
			SELECT node.\"本点号\", node.\"高程\", node.\"基本需水量\", node.\"需水量模式\", node.\"横坐标\"\
			, node.\"纵坐标\", va.\"起始节点\"\
			FROM \"节点\" node, (\
				SELECT pipe.\"编号\", pipe.\"起始节点\", pipe.\"终止节点\", pipe.\"管长\", pipe.\"管径\"\
				, pipe.\"摩阻系数\"\
				FROM \"管段\" pipe\
				WHERE pipe.\"from_layer\" = '阀门'\
				) va\
			WHERE node.\"本点号\" = va.\"终止节点\"\
			) vnode\
		WHERE vnode.\"起始节点\" = va.\"本点号\"";

	if (!mDbConn->execSql(vaEndSql))
		return;

	std::vector<std::map<std::string, std::string>> valvesEndVec;
	mDbConn->queryResult(valvesEndVec);

	size_t endVecSize = valvesEndVec.size();
	for (int i = 0; i < endVecSize; i++)
	{
		std::map<std::string, std::string> valveMap = valvesEndVec[i];

		// 构造节点
		CivNode::NodeTable nodeTable;
		std::string szNo = valveMap.find("本点号")->second;
		nodeTable.ID = szNo;
		nodeTable.Elev = valveMap.find("高程")->second;

		std::string patternID = valveMap.find("需水量模式")->second;
		std::string demand = valveMap.find("基本需水量")->second;
		handleDelayPattern(demand, patternID, nodeTable.Demand, nodeTable.PatternId);
刘乐's avatar
刘乐 committed
511

刘乐's avatar
刘乐 committed
512
		mNodeVec.push_back(nodeTable);
刘乐's avatar
刘乐 committed
513

刘乐's avatar
刘乐 committed
514 515 516 517 518 519 520 521 522 523
		// 节点坐标
		CivCoordinates::CoordTable coordTable;
		coordTable.ID = szNo;
		coordTable.XCoord = valveMap.find("横坐标")->second;
		coordTable.YCoord = valveMap.find("纵坐标")->second;

		mCoords.push_back(coordTable);

		std::string valveSn = valveMap.find("阀门本点号")->second;
		std::string valveType = valveMap.find("阀门类型")->second;
刘乐's avatar
刘乐 committed
524

刘乐's avatar
刘乐 committed
525 526 527 528 529 530 531 532 533
		if (valveType == "BV") // 止回阀,转成管段
		{
			auto iter = pipeTableMap.find(valveSn);
			if (iter != pipeTableMap.end())
			{
				pipeTableMap[valveSn].Node2 = szNo;
				mPipesVec.push_back(iter->second);
			}
		}
刘乐's avatar
刘乐 committed
534 535
		else
		{
刘乐's avatar
刘乐 committed
536 537 538 539 540 541 542
			// 阀门
			auto iter = valveTableMap.find(valveSn);
			if (iter != valveTableMap.end())
			{
				valveTableMap[valveSn].Node2 = szNo;
				mValuvesVec.push_back(iter->second);
			}
刘乐's avatar
刘乐 committed
543 544
		}
	}
刘乐's avatar
刘乐 committed
545
}