|
@@ 714-754 (lines=41) @@
|
| 711 |
|
meta_result['svg_id'], |
| 712 |
|
meta_result['description'])) |
| 713 |
|
new_id = cursor.lastrowid |
| 714 |
|
if meta_result['circuits'] is not None and len(meta_result['circuits']) > 0: |
| 715 |
|
for circuit in meta_result['circuits']: |
| 716 |
|
add_values = (" INSERT INTO tbl_distribution_circuits " |
| 717 |
|
" (name, uuid, distribution_system_id," |
| 718 |
|
" distribution_room, switchgear, peak_load, peak_current, customers, meters) " |
| 719 |
|
" VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s) ") |
| 720 |
|
cursor.execute(add_values, (circuit['name'], |
| 721 |
|
str(uuid.uuid4()), |
| 722 |
|
new_id, |
| 723 |
|
circuit['distribution_room'], |
| 724 |
|
circuit['switchgear'], |
| 725 |
|
circuit['peak_load'], |
| 726 |
|
circuit['peak_current'], |
| 727 |
|
circuit['customers'], |
| 728 |
|
circuit['meters'])) |
| 729 |
|
circuit_id = cursor.lastrowid |
| 730 |
|
if circuit['points'] is not None and len(circuit['points']) > 0: |
| 731 |
|
for point in circuit['points']: |
| 732 |
|
cursor.execute(" SELECT name " |
| 733 |
|
" FROM tbl_points " |
| 734 |
|
" WHERE id = %s ", (point['id'],)) |
| 735 |
|
if cursor.fetchone() is None: |
| 736 |
|
cursor.close() |
| 737 |
|
cnx.close() |
| 738 |
|
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
| 739 |
|
description='API.POINT_NOT_FOUND') |
| 740 |
|
|
| 741 |
|
query = (" SELECT id " |
| 742 |
|
" FROM tbl_distribution_circuits_points " |
| 743 |
|
" WHERE distribution_circuit_id = %s AND point_id = %s") |
| 744 |
|
cursor.execute(query, (circuit_id, point['id'],)) |
| 745 |
|
if cursor.fetchone() is not None: |
| 746 |
|
cursor.close() |
| 747 |
|
cnx.close() |
| 748 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.ERROR', |
| 749 |
|
description='API.DISTRIBUTION_CIRCUIT_POINT_RELATION_EXISTS') |
| 750 |
|
|
| 751 |
|
add_row = ( |
| 752 |
|
" INSERT INTO tbl_distribution_circuits_points (distribution_circuit_id, point_id) " |
| 753 |
|
" VALUES (%s, %s) ") |
| 754 |
|
cursor.execute(add_row, (circuit_id, point['id'],)) |
| 755 |
|
cnx.commit() |
| 756 |
|
cursor.close() |
| 757 |
|
cnx.close() |
|
@@ 579-618 (lines=40) @@
|
| 576 |
|
svg_id, |
| 577 |
|
description)) |
| 578 |
|
new_id = cursor.lastrowid |
| 579 |
|
if new_values['circuits'] is not None and len(new_values['circuits']) > 0: |
| 580 |
|
for circuit in new_values['circuits']: |
| 581 |
|
add_values = (" INSERT INTO tbl_distribution_circuits " |
| 582 |
|
" (name, uuid, distribution_system_id," |
| 583 |
|
" distribution_room, switchgear, peak_load, peak_current, customers, meters) " |
| 584 |
|
" VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s) ") |
| 585 |
|
cursor.execute(add_values, (circuit['name'], |
| 586 |
|
str(uuid.uuid4()), |
| 587 |
|
new_id, |
| 588 |
|
circuit['distribution_room'], |
| 589 |
|
circuit['switchgear'], |
| 590 |
|
circuit['peak_load'], |
| 591 |
|
circuit['peak_current'], |
| 592 |
|
circuit['customers'], |
| 593 |
|
circuit['meters'])) |
| 594 |
|
circuit_id = cursor.lastrowid |
| 595 |
|
if circuit['points'] is not None and len(circuit['points']) > 0: |
| 596 |
|
for point in circuit['points']: |
| 597 |
|
cursor.execute(" SELECT name " |
| 598 |
|
" FROM tbl_points " |
| 599 |
|
" WHERE id = %s ", (point['id'],)) |
| 600 |
|
if cursor.fetchone() is None: |
| 601 |
|
cursor.close() |
| 602 |
|
cnx.close() |
| 603 |
|
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
| 604 |
|
description='API.POINT_NOT_FOUND') |
| 605 |
|
|
| 606 |
|
query = (" SELECT id " |
| 607 |
|
" FROM tbl_distribution_circuits_points " |
| 608 |
|
" WHERE distribution_circuit_id = %s AND point_id = %s") |
| 609 |
|
cursor.execute(query, (circuit_id, point['id'],)) |
| 610 |
|
if cursor.fetchone() is not None: |
| 611 |
|
cursor.close() |
| 612 |
|
cnx.close() |
| 613 |
|
raise falcon.HTTPError(status=falcon.HTTP_400, title='API.ERROR', |
| 614 |
|
description='API.DISTRIBUTION_CIRCUIT_POINT_RELATION_EXISTS') |
| 615 |
|
|
| 616 |
|
add_row = (" INSERT INTO tbl_distribution_circuits_points (distribution_circuit_id, point_id) " |
| 617 |
|
" VALUES (%s, %s) ") |
| 618 |
|
cursor.execute(add_row, (circuit_id, point['id'],)) |
| 619 |
|
|
| 620 |
|
cnx.commit() |
| 621 |
|
cursor.close() |