@golemio/energetics 1.12.2-dev.2740928370 → 1.12.2-dev.2741327856

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/db/example/00_clear_test_data.sql +19 -0
  2. package/db/example/06_eno.sql +36 -0
  3. package/db/example/07_enapo_om_detail.sql +140 -0
  4. package/db/example/08_ded_search.sql +25 -0
  5. package/db/migrations/postgresql/20260807090000-enapo-gid-mapping-om-detail.js +53 -0
  6. package/db/migrations/postgresql/20260807091000-enapo-om-detail-porsenna.js +53 -0
  7. package/db/migrations/postgresql/20260807092000-ded-building-search.js +53 -0
  8. package/db/migrations/postgresql/sqls/20260807090000-enapo-gid-mapping-om-detail-down.sql +3 -0
  9. package/db/migrations/postgresql/sqls/20260807090000-enapo-gid-mapping-om-detail-up.sql +182 -0
  10. package/db/migrations/postgresql/sqls/20260807091000-enapo-om-detail-porsenna-down.sql +135 -0
  11. package/db/migrations/postgresql/sqls/20260807091000-enapo-om-detail-porsenna-up.sql +292 -0
  12. package/db/migrations/postgresql/sqls/20260807092000-ded-building-search-down.sql +41 -0
  13. package/db/migrations/postgresql/sqls/20260807092000-ded-building-search-up.sql +262 -0
  14. package/db/scripts/ded_gid_mapping_mock_import.sql +107 -0
  15. package/dist/integration-engine/enapo/ioc/Di.js +5 -1
  16. package/dist/integration-engine/enapo/ioc/Di.js.map +1 -1
  17. package/dist/integration-engine/enapo/ioc/EnapoWorkerContainerToken.d.ts +2 -0
  18. package/dist/integration-engine/enapo/ioc/EnapoWorkerContainerToken.js +2 -0
  19. package/dist/integration-engine/enapo/ioc/EnapoWorkerContainerToken.js.map +1 -1
  20. package/dist/integration-engine/enapo/repositories/DedSearchIndexRepository.d.ts +7 -0
  21. package/dist/integration-engine/enapo/repositories/DedSearchIndexRepository.js +50 -0
  22. package/dist/integration-engine/enapo/repositories/DedSearchIndexRepository.js.map +1 -0
  23. package/dist/integration-engine/enapo/repositories/interfaces/IDedSearchIndexRepository.d.ts +7 -0
  24. package/dist/integration-engine/enapo/repositories/interfaces/IDedSearchIndexRepository.js +3 -0
  25. package/dist/integration-engine/enapo/repositories/interfaces/IDedSearchIndexRepository.js.map +1 -0
  26. package/dist/integration-engine/enapo/workers/EnapoWorker.js +1 -0
  27. package/dist/integration-engine/enapo/workers/EnapoWorker.js.map +1 -1
  28. package/dist/integration-engine/enapo/workers/task/DedSearchIndexRefreshTask.d.ts +21 -0
  29. package/dist/integration-engine/enapo/workers/task/DedSearchIndexRefreshTask.js +58 -0
  30. package/dist/integration-engine/enapo/workers/task/DedSearchIndexRefreshTask.js.map +1 -0
  31. package/dist/integration-engine/enapo/workers/task/EnoGeometryTask.d.ts +13 -1
  32. package/dist/integration-engine/enapo/workers/task/EnoGeometryTask.js +25 -2
  33. package/dist/integration-engine/enapo/workers/task/EnoGeometryTask.js.map +1 -1
  34. package/dist/output-gateway/constants/DedSearchWeights.d.ts +60 -0
  35. package/dist/output-gateway/constants/DedSearchWeights.js +42 -0
  36. package/dist/output-gateway/constants/DedSearchWeights.js.map +1 -0
  37. package/dist/output-gateway/constants/Links.d.ts +1 -0
  38. package/dist/output-gateway/constants/Links.js +2 -1
  39. package/dist/output-gateway/constants/Links.js.map +1 -1
  40. package/dist/output-gateway/controllers/v2/EnoBuildingsController.d.ts +16 -0
  41. package/dist/output-gateway/controllers/v2/EnoBuildingsController.js +80 -0
  42. package/dist/output-gateway/controllers/v2/EnoBuildingsController.js.map +1 -0
  43. package/dist/output-gateway/helpers/objectMappers.d.ts +10 -0
  44. package/dist/output-gateway/helpers/objectMappers.js +37 -0
  45. package/dist/output-gateway/helpers/objectMappers.js.map +1 -0
  46. package/dist/output-gateway/index.js +8 -1
  47. package/dist/output-gateway/index.js.map +1 -1
  48. package/dist/output-gateway/ioc/Di.js +13 -1
  49. package/dist/output-gateway/ioc/Di.js.map +1 -1
  50. package/dist/output-gateway/ioc/ModuleContainerToken.d.ts +6 -0
  51. package/dist/output-gateway/ioc/ModuleContainerToken.js +6 -0
  52. package/dist/output-gateway/ioc/ModuleContainerToken.js.map +1 -1
  53. package/dist/output-gateway/models/DedBuildingSearchViewModel.d.ts +30 -0
  54. package/dist/output-gateway/models/DedBuildingSearchViewModel.js +38 -0
  55. package/dist/output-gateway/models/DedBuildingSearchViewModel.js.map +1 -0
  56. package/dist/output-gateway/models/EnoBuildingDetailViewModel.d.ts +49 -0
  57. package/dist/output-gateway/models/EnoBuildingDetailViewModel.js +57 -0
  58. package/dist/output-gateway/models/EnoBuildingDetailViewModel.js.map +1 -0
  59. package/dist/output-gateway/models/EnoConsumptionPointViewModel.d.ts +106 -0
  60. package/dist/output-gateway/models/EnoConsumptionPointViewModel.js +119 -0
  61. package/dist/output-gateway/models/EnoConsumptionPointViewModel.js.map +1 -0
  62. package/dist/output-gateway/models/EnoPorsennaDeviceViewModel.d.ts +27 -0
  63. package/dist/output-gateway/models/EnoPorsennaDeviceViewModel.js +41 -0
  64. package/dist/output-gateway/models/EnoPorsennaDeviceViewModel.js.map +1 -0
  65. package/dist/output-gateway/models/interfaces/IDedBuildingSearchView.d.ts +24 -0
  66. package/dist/output-gateway/models/interfaces/IDedBuildingSearchView.js +3 -0
  67. package/dist/output-gateway/models/interfaces/IDedBuildingSearchView.js.map +1 -0
  68. package/dist/output-gateway/models/interfaces/IEnoBuildingDetailView.d.ts +44 -0
  69. package/dist/output-gateway/models/interfaces/IEnoBuildingDetailView.js +3 -0
  70. package/dist/output-gateway/models/interfaces/IEnoBuildingDetailView.js.map +1 -0
  71. package/dist/output-gateway/models/interfaces/IEnoConsumptionPointView.d.ts +106 -0
  72. package/dist/output-gateway/models/interfaces/IEnoConsumptionPointView.js +3 -0
  73. package/dist/output-gateway/models/interfaces/IEnoConsumptionPointView.js.map +1 -0
  74. package/dist/output-gateway/models/interfaces/IEnoPorsennaDeviceView.d.ts +22 -0
  75. package/dist/output-gateway/models/interfaces/IEnoPorsennaDeviceView.js +3 -0
  76. package/dist/output-gateway/models/interfaces/IEnoPorsennaDeviceView.js.map +1 -0
  77. package/dist/output-gateway/repositories/AbstractNumericParsingRepository.d.ts +12 -0
  78. package/dist/output-gateway/repositories/AbstractNumericParsingRepository.js +41 -0
  79. package/dist/output-gateway/repositories/AbstractNumericParsingRepository.js.map +1 -0
  80. package/dist/output-gateway/repositories/DedBuildingSearchRepository.d.ts +16 -0
  81. package/dist/output-gateway/repositories/DedBuildingSearchRepository.js +250 -0
  82. package/dist/output-gateway/repositories/DedBuildingSearchRepository.js.map +1 -0
  83. package/dist/output-gateway/repositories/EnoBuildingAddressesRepository.d.ts +8 -0
  84. package/dist/output-gateway/repositories/EnoBuildingAddressesRepository.js +62 -0
  85. package/dist/output-gateway/repositories/EnoBuildingAddressesRepository.js.map +1 -0
  86. package/dist/output-gateway/repositories/EnoBuildingDetailRepository.d.ts +18 -0
  87. package/dist/output-gateway/repositories/EnoBuildingDetailRepository.js +100 -0
  88. package/dist/output-gateway/repositories/EnoBuildingDetailRepository.js.map +1 -0
  89. package/dist/output-gateway/repositories/EnoConsumptionPointsRepository.d.ts +8 -0
  90. package/dist/output-gateway/repositories/EnoConsumptionPointsRepository.js +51 -0
  91. package/dist/output-gateway/repositories/EnoConsumptionPointsRepository.js.map +1 -0
  92. package/dist/output-gateway/repositories/EnoPorsennaDevicesRepository.d.ts +8 -0
  93. package/dist/output-gateway/repositories/EnoPorsennaDevicesRepository.js +51 -0
  94. package/dist/output-gateway/repositories/EnoPorsennaDevicesRepository.js.map +1 -0
  95. package/dist/output-gateway/repositories/PorsennaConsumptionsRepository.d.ts +8 -0
  96. package/dist/output-gateway/repositories/PorsennaConsumptionsRepository.js +52 -0
  97. package/dist/output-gateway/repositories/PorsennaConsumptionsRepository.js.map +1 -0
  98. package/dist/output-gateway/repositories/PpasInvoiceChildRepository.d.ts +13 -0
  99. package/dist/output-gateway/repositories/PpasInvoiceChildRepository.js +39 -0
  100. package/dist/output-gateway/repositories/PpasInvoiceChildRepository.js.map +1 -0
  101. package/dist/output-gateway/repositories/interfaces/IDedBuildingSearchRow.d.ts +14 -0
  102. package/dist/output-gateway/repositories/interfaces/IDedBuildingSearchRow.js +3 -0
  103. package/dist/output-gateway/repositories/interfaces/IDedBuildingSearchRow.js.map +1 -0
  104. package/dist/output-gateway/repositories/interfaces/IEnoBuildingDetailAggregate.d.ts +22 -0
  105. package/dist/output-gateway/repositories/interfaces/IEnoBuildingDetailAggregate.js +3 -0
  106. package/dist/output-gateway/repositories/interfaces/IEnoBuildingDetailAggregate.js.map +1 -0
  107. package/dist/output-gateway/routers/interfaces/IDedBuildingSearchResponse.d.ts +50 -0
  108. package/dist/output-gateway/routers/interfaces/IDedBuildingSearchResponse.js +3 -0
  109. package/dist/output-gateway/routers/interfaces/IDedBuildingSearchResponse.js.map +1 -0
  110. package/dist/output-gateway/routers/interfaces/IEnoBuildingDetailResponse.d.ts +130 -0
  111. package/dist/output-gateway/routers/interfaces/IEnoBuildingDetailResponse.js +3 -0
  112. package/dist/output-gateway/routers/interfaces/IEnoBuildingDetailResponse.js.map +1 -0
  113. package/dist/output-gateway/routers/interfaces/IEnoRegistrationUnit.d.ts +11 -0
  114. package/dist/output-gateway/routers/interfaces/IEnoRegistrationUnit.js +3 -0
  115. package/dist/output-gateway/routers/interfaces/IEnoRegistrationUnit.js.map +1 -0
  116. package/dist/output-gateway/routers/v2/V2EnoBuildingsRouter.d.ts +11 -0
  117. package/dist/output-gateway/routers/v2/V2EnoBuildingsRouter.js +45 -0
  118. package/dist/output-gateway/routers/v2/V2EnoBuildingsRouter.js.map +1 -0
  119. package/dist/output-gateway/transformations/DedBuildingSearchTransformation.d.ts +11 -0
  120. package/dist/output-gateway/transformations/DedBuildingSearchTransformation.js +57 -0
  121. package/dist/output-gateway/transformations/DedBuildingSearchTransformation.js.map +1 -0
  122. package/dist/output-gateway/transformations/EnoBuildingDetailTransformation.d.ts +18 -0
  123. package/dist/output-gateway/transformations/EnoBuildingDetailTransformation.js +193 -0
  124. package/dist/output-gateway/transformations/EnoBuildingDetailTransformation.js.map +1 -0
  125. package/dist/schema-definitions/models/enapo/EnapoGidMappingModel.d.ts +17 -0
  126. package/dist/schema-definitions/models/enapo/EnapoGidMappingModel.js +63 -0
  127. package/dist/schema-definitions/models/enapo/EnapoGidMappingModel.js.map +1 -0
  128. package/dist/schema-definitions/models/enapo/interfaces/IEnapoGidMapping.d.ts +11 -0
  129. package/dist/schema-definitions/models/enapo/interfaces/IEnapoGidMapping.js +3 -0
  130. package/dist/schema-definitions/models/enapo/interfaces/IEnapoGidMapping.js.map +1 -0
  131. package/dist/schema-definitions/models/eno/AddressModel.d.ts +1 -1
  132. package/dist/schema-definitions/models/eno/AddressModel.js +1 -1
  133. package/dist/schema-definitions/models/eno/AddressModel.js.map +1 -1
  134. package/dist/schema-definitions/models/eno/interfaces/IAddress.d.ts +1 -1
  135. package/docs/implementation_documentation.md +90 -2
  136. package/docs/openapi-output.yaml +554 -1
  137. package/package.json +1 -1
@@ -0,0 +1,135 @@
1
+ DROP VIEW IF EXISTS v_enapo_building_consumption_points;
2
+
3
+ CREATE VIEW v_enapo_building_consumption_points AS
4
+ SELECT
5
+ m.gid,
6
+ m.place_id,
7
+ m.id_type,
8
+ m.commodity,
9
+ m.is_first_gid,
10
+ m.link_source,
11
+ m.valid_from,
12
+ m.valid_to,
13
+ (m.valid_to IS NULL OR m.valid_to >= CURRENT_DATE) AS is_active,
14
+ pm.*,
15
+ di.*,
16
+ ci.*
17
+ FROM enapo_gid_mapping m
18
+ LEFT JOIN LATERAL (
19
+ SELECT
20
+ h."year" AS md_year,
21
+ h."month" AS md_month,
22
+ h.month_name AS md_month_name,
23
+ h.days_in_stored_month AS md_days_in_stored_month,
24
+ h.consumption_point AS md_consumption_point,
25
+ h.address AS md_address,
26
+ h.location_type AS md_location_type,
27
+ h.company_name AS md_company_name,
28
+ h.company_id AS md_company_id,
29
+ h.tarif_type AS md_tarif_type,
30
+ h.tarif_1t2t AS md_tarif_1t2t,
31
+ h.phases AS md_phases,
32
+ h.circuit_breaker AS md_circuit_breaker,
33
+ h.type_b_meter AS md_type_b_meter,
34
+ h.meter_replaced AS md_meter_replaced
35
+ FROM enapo_pre_metadata_history h
36
+ WHERE h.ean = m.place_id
37
+ ORDER BY h."year" DESC, h."month" DESC
38
+ LIMIT 1
39
+ ) pm ON m.id_type = 'ean'
40
+ LEFT JOIN LATERAL (
41
+ SELECT
42
+ i.id AS di_id,
43
+ i.preceding_id AS di_preceding_id,
44
+ i.customer_id AS di_customer_id,
45
+ i.customer_company_id AS di_customer_company_id,
46
+ i.customer_name AS di_customer_name,
47
+ i.customer_contract_account_id AS di_customer_contract_account_id,
48
+ i.customer_address_street AS di_customer_address_street,
49
+ i.customer_address_house_number AS di_customer_address_house_number,
50
+ i.customer_address_house_org_number AS di_customer_address_house_org_number,
51
+ i.customer_address_city AS di_customer_address_city,
52
+ i.customer_address_city_part AS di_customer_address_city_part,
53
+ i.customer_address_post_code AS di_customer_address_post_code,
54
+ i.customer_address_country AS di_customer_address_country,
55
+ i.customer_address_ruian_id AS di_customer_address_ruian_id,
56
+ i.facts_doc_date AS di_facts_doc_date,
57
+ i.facts_net_date AS di_facts_net_date,
58
+ i.facts_billing_transaction AS di_facts_billing_transaction,
59
+ i.facts_to_pay_amount AS di_facts_to_pay_amount,
60
+ i.facts_currency AS di_facts_currency,
61
+ i.facts_price_brutto AS di_facts_price_brutto,
62
+ i.is_canceled AS di_is_canceled,
63
+ i.canceled_reason AS di_canceled_reason,
64
+ ins.place_id AS dinst_place_id,
65
+ ins.billing_class AS dinst_billing_class,
66
+ ins.measurement_type AS dinst_measurement_type,
67
+ ins.contract_contract_id AS dinst_contract_contract_id,
68
+ ins.contract_move_in_date AS dinst_contract_move_in_date,
69
+ ins.contract_move_out_date AS dinst_contract_move_out_date,
70
+ ins.tdd_class AS dinst_tdd_class,
71
+ ins.address_street AS dinst_address_street,
72
+ ins.address_house_number AS dinst_address_house_number,
73
+ ins.address_house_org_number AS dinst_address_house_org_number,
74
+ ins.address_city AS dinst_address_city,
75
+ ins.address_city_part AS dinst_address_city_part,
76
+ ins.address_post_code AS dinst_address_post_code,
77
+ ins.address_country AS dinst_address_country,
78
+ ins.address_ruian_id AS dinst_address_ruian_id
79
+ FROM enapo_ppas_distribution_installation ins
80
+ INNER JOIN enapo_ppas_distribution_invoice i
81
+ ON i.id = ins.invoice_id AND i.customer_id = ins.customer_id
82
+ WHERE ins.eic = m.place_id
83
+ AND COALESCE(i.is_canceled, false) = false
84
+ ORDER BY i.facts_doc_date DESC
85
+ LIMIT 1
86
+ ) di ON m.id_type = 'eic'
87
+ LEFT JOIN LATERAL (
88
+ SELECT
89
+ i.id AS ci_id,
90
+ i.preceding_id AS ci_preceding_id,
91
+ i.customer_id AS ci_customer_id,
92
+ i.customer_company_id AS ci_customer_company_id,
93
+ i.customer_name AS ci_customer_name,
94
+ i.customer_contract_account_id AS ci_customer_contract_account_id,
95
+ i.customer_address_street AS ci_customer_address_street,
96
+ i.customer_address_house_number AS ci_customer_address_house_number,
97
+ i.customer_address_house_org_number AS ci_customer_address_house_org_number,
98
+ i.customer_address_city AS ci_customer_address_city,
99
+ i.customer_address_city_part AS ci_customer_address_city_part,
100
+ i.customer_address_post_code AS ci_customer_address_post_code,
101
+ i.customer_address_country AS ci_customer_address_country,
102
+ i.customer_address_ruian_id AS ci_customer_address_ruian_id,
103
+ i.facts_doc_date AS ci_facts_doc_date,
104
+ i.facts_net_date AS ci_facts_net_date,
105
+ i.facts_billing_transaction AS ci_facts_billing_transaction,
106
+ i.facts_to_pay_amount AS ci_facts_to_pay_amount,
107
+ i.facts_currency AS ci_facts_currency,
108
+ i.facts_price_brutto AS ci_facts_price_brutto,
109
+ i.is_canceled AS ci_is_canceled,
110
+ i.canceled_reason AS ci_canceled_reason,
111
+ ins.place_id AS cinst_place_id,
112
+ ins.billing_class AS cinst_billing_class,
113
+ ins.measurement_type AS cinst_measurement_type,
114
+ ins.contract_contract_id AS cinst_contract_contract_id,
115
+ ins.contract_move_in_date AS cinst_contract_move_in_date,
116
+ ins.contract_move_out_date AS cinst_contract_move_out_date,
117
+ ins.tdd_class AS cinst_tdd_class,
118
+ ins.address_street AS cinst_address_street,
119
+ ins.address_house_number AS cinst_address_house_number,
120
+ ins.address_house_org_number AS cinst_address_house_org_number,
121
+ ins.address_city AS cinst_address_city,
122
+ ins.address_city_part AS cinst_address_city_part,
123
+ ins.address_post_code AS cinst_address_post_code,
124
+ ins.address_country AS cinst_address_country,
125
+ ins.address_ruian_id AS cinst_address_ruian_id
126
+ FROM enapo_ppas_commercial_invoice_installations ins
127
+ INNER JOIN enapo_ppas_commercial_invoice i
128
+ ON i.id = ins.invoice_id AND i.customer_id = ins.customer_id
129
+ WHERE ins.eic = m.place_id
130
+ AND COALESCE(i.is_canceled, false) = false
131
+ ORDER BY i.facts_doc_date DESC
132
+ LIMIT 1
133
+ ) ci ON m.id_type = 'eic';
134
+
135
+ DROP VIEW IF EXISTS v_enapo_building_porsenna_devices;
@@ -0,0 +1,292 @@
1
+ CREATE OR REPLACE VIEW v_enapo_building_porsenna_devices AS
2
+ SELECT
3
+ pb.gid,
4
+ d.source,
5
+ d.id AS device_id,
6
+ d.parent_device_id,
7
+ d.identifier,
8
+ d."type",
9
+ d."level",
10
+ d.name,
11
+ d.measurement_target,
12
+ d.meter_number,
13
+ d.supply_point_number,
14
+ d.disabled_at,
15
+ d.show_in_output,
16
+ pb.id AS building_id,
17
+ pb.name AS building_name,
18
+ pb.street AS building_street,
19
+ pb.house_number AS building_house_number,
20
+ pb.street_number AS building_street_number,
21
+ pb.city AS building_city,
22
+ pb.postcode AS building_postcode
23
+ FROM enapo_porsenna_devices d
24
+ INNER JOIN enapo_porsenna_buildings pb
25
+ ON pb.source = d.source AND pb.id = d.building_id
26
+ WHERE pb.gid IS NOT NULL;
27
+
28
+ DROP VIEW IF EXISTS v_enapo_building_consumption_points;
29
+
30
+ CREATE VIEW v_enapo_building_consumption_points AS
31
+ SELECT
32
+ m.gid,
33
+ m.place_id,
34
+ m.id_type,
35
+ m.commodity,
36
+ m.is_first_gid,
37
+ m.link_source,
38
+ m.valid_from,
39
+ m.valid_to,
40
+ (m.valid_to IS NULL OR m.valid_to >= CURRENT_DATE) AS is_active,
41
+ pm.*,
42
+ di.*,
43
+ ci.*
44
+ FROM enapo_gid_mapping m
45
+ LEFT JOIN LATERAL (
46
+ SELECT
47
+ h."year" AS md_year,
48
+ h."month" AS md_month,
49
+ h.month_name AS md_month_name,
50
+ h.days_in_stored_month AS md_days_in_stored_month,
51
+ h.consumption_point AS md_consumption_point,
52
+ h.address AS md_address,
53
+ h.location_type AS md_location_type,
54
+ h.company_name AS md_company_name,
55
+ h.company_id AS md_company_id,
56
+ h.tarif_type AS md_tarif_type,
57
+ h.tarif_1t2t AS md_tarif_1t2t,
58
+ h.phases AS md_phases,
59
+ h.circuit_breaker AS md_circuit_breaker,
60
+ h.type_b_meter AS md_type_b_meter,
61
+ h.meter_replaced AS md_meter_replaced
62
+ FROM enapo_pre_metadata_history h
63
+ WHERE h.ean = m.place_id
64
+ ORDER BY h."year" DESC, h."month" DESC
65
+ LIMIT 1
66
+ ) pm ON m.id_type = 'ean'
67
+ LEFT JOIN LATERAL (
68
+ SELECT
69
+ i.id AS di_id,
70
+ i.preceding_id AS di_preceding_id,
71
+ i.customer_id AS di_customer_id,
72
+ i.customer_company_id AS di_customer_company_id,
73
+ i.customer_name AS di_customer_name,
74
+ i.customer_contract_account_id AS di_customer_contract_account_id,
75
+ i.customer_address_street AS di_customer_address_street,
76
+ i.customer_address_house_number AS di_customer_address_house_number,
77
+ i.customer_address_house_org_number AS di_customer_address_house_org_number,
78
+ i.customer_address_city AS di_customer_address_city,
79
+ i.customer_address_city_part AS di_customer_address_city_part,
80
+ i.customer_address_post_code AS di_customer_address_post_code,
81
+ i.customer_address_country AS di_customer_address_country,
82
+ i.customer_address_ruian_id AS di_customer_address_ruian_id,
83
+ i.facts_doc_date AS di_facts_doc_date,
84
+ i.facts_net_date AS di_facts_net_date,
85
+ i.facts_billing_transaction AS di_facts_billing_transaction,
86
+ i.facts_to_pay_amount AS di_facts_to_pay_amount,
87
+ i.facts_currency AS di_facts_currency,
88
+ i.facts_price_brutto AS di_facts_price_brutto,
89
+ i.is_canceled AS di_is_canceled,
90
+ i.canceled_reason AS di_canceled_reason,
91
+ ins.place_id AS dinst_place_id,
92
+ ins.billing_class AS dinst_billing_class,
93
+ ins.measurement_type AS dinst_measurement_type,
94
+ ins.contract_contract_id AS dinst_contract_contract_id,
95
+ ins.contract_move_in_date AS dinst_contract_move_in_date,
96
+ ins.contract_move_out_date AS dinst_contract_move_out_date,
97
+ ins.tdd_class AS dinst_tdd_class,
98
+ ins.address_street AS dinst_address_street,
99
+ ins.address_house_number AS dinst_address_house_number,
100
+ ins.address_house_org_number AS dinst_address_house_org_number,
101
+ ins.address_city AS dinst_address_city,
102
+ ins.address_city_part AS dinst_address_city_part,
103
+ ins.address_post_code AS dinst_address_post_code,
104
+ ins.address_country AS dinst_address_country,
105
+ ins.address_ruian_id AS dinst_address_ruian_id
106
+ FROM enapo_ppas_distribution_installation ins
107
+ INNER JOIN enapo_ppas_distribution_invoice i
108
+ ON i.id = ins.invoice_id AND i.customer_id = ins.customer_id
109
+ WHERE ins.eic = m.place_id
110
+ AND COALESCE(i.is_canceled, false) = false
111
+ ORDER BY i.facts_doc_date DESC
112
+ LIMIT 1
113
+ ) di ON m.id_type = 'eic'
114
+ LEFT JOIN LATERAL (
115
+ SELECT
116
+ i.id AS ci_id,
117
+ i.preceding_id AS ci_preceding_id,
118
+ i.customer_id AS ci_customer_id,
119
+ i.customer_company_id AS ci_customer_company_id,
120
+ i.customer_name AS ci_customer_name,
121
+ i.customer_contract_account_id AS ci_customer_contract_account_id,
122
+ i.customer_address_street AS ci_customer_address_street,
123
+ i.customer_address_house_number AS ci_customer_address_house_number,
124
+ i.customer_address_house_org_number AS ci_customer_address_house_org_number,
125
+ i.customer_address_city AS ci_customer_address_city,
126
+ i.customer_address_city_part AS ci_customer_address_city_part,
127
+ i.customer_address_post_code AS ci_customer_address_post_code,
128
+ i.customer_address_country AS ci_customer_address_country,
129
+ i.customer_address_ruian_id AS ci_customer_address_ruian_id,
130
+ i.facts_doc_date AS ci_facts_doc_date,
131
+ i.facts_net_date AS ci_facts_net_date,
132
+ i.facts_billing_transaction AS ci_facts_billing_transaction,
133
+ i.facts_to_pay_amount AS ci_facts_to_pay_amount,
134
+ i.facts_currency AS ci_facts_currency,
135
+ i.facts_price_brutto AS ci_facts_price_brutto,
136
+ i.is_canceled AS ci_is_canceled,
137
+ i.canceled_reason AS ci_canceled_reason,
138
+ ins.place_id AS cinst_place_id,
139
+ ins.billing_class AS cinst_billing_class,
140
+ ins.measurement_type AS cinst_measurement_type,
141
+ ins.contract_contract_id AS cinst_contract_contract_id,
142
+ ins.contract_move_in_date AS cinst_contract_move_in_date,
143
+ ins.contract_move_out_date AS cinst_contract_move_out_date,
144
+ ins.tdd_class AS cinst_tdd_class,
145
+ ins.address_street AS cinst_address_street,
146
+ ins.address_house_number AS cinst_address_house_number,
147
+ ins.address_house_org_number AS cinst_address_house_org_number,
148
+ ins.address_city AS cinst_address_city,
149
+ ins.address_city_part AS cinst_address_city_part,
150
+ ins.address_post_code AS cinst_address_post_code,
151
+ ins.address_country AS cinst_address_country,
152
+ ins.address_ruian_id AS cinst_address_ruian_id
153
+ FROM enapo_ppas_commercial_invoice_installations ins
154
+ INNER JOIN enapo_ppas_commercial_invoice i
155
+ ON i.id = ins.invoice_id AND i.customer_id = ins.customer_id
156
+ WHERE ins.eic = m.place_id
157
+ AND COALESCE(i.is_canceled, false) = false
158
+ ORDER BY i.facts_doc_date DESC
159
+ LIMIT 1
160
+ ) ci ON m.id_type = 'eic'
161
+
162
+ UNION ALL
163
+
164
+ -- Consumption points known only to Porsenna (e-manazer): any commodity whose identifier
165
+ -- is not already mapped to this building by enapo_gid_mapping. One row per main-level device;
166
+ -- sub-meters and consumption are served as enrichment, not as separate points.
167
+ SELECT
168
+ pd.gid,
169
+ pd.identifier AS place_id,
170
+ -- EAN exists only for electricity and EIC only for gas; heat/water have no standard identifier
171
+ CASE c.commodity
172
+ WHEN 'electricity' THEN 'ean'
173
+ WHEN 'gas' THEN 'eic'
174
+ ELSE 'om'
175
+ END AS id_type,
176
+ c.commodity,
177
+ true AS is_first_gid,
178
+ 'porsenna' AS link_source,
179
+ NULL AS valid_from,
180
+ pd.disabled_at::date AS valid_to,
181
+ (pd.disabled_at IS NULL) AS is_active,
182
+ -- PRE metadata (md_*); aliases document the positional mapping to the first UNION branch
183
+ NULL AS md_year,
184
+ NULL AS md_month,
185
+ NULL AS md_month_name,
186
+ NULL AS md_days_in_stored_month,
187
+ NULL AS md_consumption_point,
188
+ NULL AS md_address,
189
+ NULL AS md_location_type,
190
+ NULL AS md_company_name,
191
+ NULL AS md_company_id,
192
+ NULL AS md_tarif_type,
193
+ NULL AS md_tarif_1t2t,
194
+ NULL AS md_phases,
195
+ NULL AS md_circuit_breaker,
196
+ NULL AS md_type_b_meter,
197
+ NULL AS md_meter_replaced,
198
+ -- distribution invoice (di_*)
199
+ NULL AS di_id,
200
+ NULL AS di_preceding_id,
201
+ NULL AS di_customer_id,
202
+ NULL AS di_customer_company_id,
203
+ NULL AS di_customer_name,
204
+ NULL AS di_customer_contract_account_id,
205
+ NULL AS di_customer_address_street,
206
+ NULL AS di_customer_address_house_number,
207
+ NULL AS di_customer_address_house_org_number,
208
+ NULL AS di_customer_address_city,
209
+ NULL AS di_customer_address_city_part,
210
+ NULL AS di_customer_address_post_code,
211
+ NULL AS di_customer_address_country,
212
+ NULL AS di_customer_address_ruian_id,
213
+ NULL AS di_facts_doc_date,
214
+ NULL AS di_facts_net_date,
215
+ NULL AS di_facts_billing_transaction,
216
+ NULL AS di_facts_to_pay_amount,
217
+ NULL AS di_facts_currency,
218
+ NULL AS di_facts_price_brutto,
219
+ NULL AS di_is_canceled,
220
+ NULL AS di_canceled_reason,
221
+ -- distribution installation (dinst_*)
222
+ NULL AS dinst_place_id,
223
+ NULL AS dinst_billing_class,
224
+ NULL AS dinst_measurement_type,
225
+ NULL AS dinst_contract_contract_id,
226
+ NULL AS dinst_contract_move_in_date,
227
+ NULL AS dinst_contract_move_out_date,
228
+ NULL AS dinst_tdd_class,
229
+ NULL AS dinst_address_street,
230
+ NULL AS dinst_address_house_number,
231
+ NULL AS dinst_address_house_org_number,
232
+ NULL AS dinst_address_city,
233
+ NULL AS dinst_address_city_part,
234
+ NULL AS dinst_address_post_code,
235
+ NULL AS dinst_address_country,
236
+ NULL AS dinst_address_ruian_id,
237
+ -- commercial invoice (ci_*)
238
+ NULL AS ci_id,
239
+ NULL AS ci_preceding_id,
240
+ NULL AS ci_customer_id,
241
+ NULL AS ci_customer_company_id,
242
+ NULL AS ci_customer_name,
243
+ NULL AS ci_customer_contract_account_id,
244
+ NULL AS ci_customer_address_street,
245
+ NULL AS ci_customer_address_house_number,
246
+ NULL AS ci_customer_address_house_org_number,
247
+ NULL AS ci_customer_address_city,
248
+ NULL AS ci_customer_address_city_part,
249
+ NULL AS ci_customer_address_post_code,
250
+ NULL AS ci_customer_address_country,
251
+ NULL AS ci_customer_address_ruian_id,
252
+ NULL AS ci_facts_doc_date,
253
+ NULL AS ci_facts_net_date,
254
+ NULL AS ci_facts_billing_transaction,
255
+ NULL AS ci_facts_to_pay_amount,
256
+ NULL AS ci_facts_currency,
257
+ NULL AS ci_facts_price_brutto,
258
+ NULL AS ci_is_canceled,
259
+ NULL AS ci_canceled_reason,
260
+ -- commercial installation (cinst_*)
261
+ NULL AS cinst_place_id,
262
+ NULL AS cinst_billing_class,
263
+ NULL AS cinst_measurement_type,
264
+ NULL AS cinst_contract_contract_id,
265
+ NULL AS cinst_contract_move_in_date,
266
+ NULL AS cinst_contract_move_out_date,
267
+ NULL AS cinst_tdd_class,
268
+ NULL AS cinst_address_street,
269
+ NULL AS cinst_address_house_number,
270
+ NULL AS cinst_address_house_org_number,
271
+ NULL AS cinst_address_city,
272
+ NULL AS cinst_address_city_part,
273
+ NULL AS cinst_address_post_code,
274
+ NULL AS cinst_address_country,
275
+ NULL AS cinst_address_ruian_id
276
+ FROM v_enapo_building_porsenna_devices pd
277
+ CROSS JOIN LATERAL (
278
+ SELECT CASE pd."type"
279
+ WHEN 'electricity_meter' THEN 'electricity'
280
+ WHEN 'gasometer' THEN 'gas'
281
+ WHEN 'heat_meter' THEN 'heat'
282
+ WHEN 'water_meter' THEN 'water'
283
+ END AS commodity
284
+ ) c
285
+ WHERE pd."type" IN ('electricity_meter', 'gasometer', 'heat_meter', 'water_meter')
286
+ AND (pd."level" IS NULL OR pd."level" = 'main')
287
+ AND pd.identifier IS NOT NULL
288
+ AND NOT EXISTS (
289
+ SELECT 1
290
+ FROM enapo_gid_mapping m
291
+ WHERE m.place_id = pd.identifier AND m.gid = pd.gid
292
+ );
@@ -0,0 +1,41 @@
1
+ DROP MATERIALIZED VIEW IF EXISTS mv_ded_building_search;
2
+
3
+ DROP FUNCTION IF EXISTS f_ded_safe_geom(text, varchar);
4
+
5
+ -- Restore v_enapo_building_detail to the pre-search definition (migration 20260807090000), dropping the
6
+ -- ENO lookup columns this migration added. The view is dropped and recreated rather than replaced because
7
+ -- CREATE OR REPLACE VIEW cannot remove columns; the dependent mv_ded_building_search is already gone above.
8
+ DROP VIEW IF EXISTS v_enapo_building_detail;
9
+
10
+ CREATE VIEW v_enapo_building_detail AS
11
+ SELECT DISTINCT ON (b.gid)
12
+ b.gid,
13
+ b.zdroj,
14
+ b.nazev,
15
+ b.oznaceni,
16
+ b.druh_vytapeni,
17
+ b.pripojka_elektro,
18
+ b.pripojka_voda,
19
+ b.pripojka_kanalizace,
20
+ b.budova_rozdelena_byt_nebyt,
21
+ b.celkova_plocha_budova,
22
+ b.celkova_plocha_byt_budova,
23
+ b.celkova_plocha_nebyt_budova,
24
+ b.zastavena_plocha,
25
+ b.obestaveny_prostor,
26
+ b.pocet_byt,
27
+ b.pocet_nebyt_budova,
28
+ b.pocet_nadzem_podlazi,
29
+ b.pocet_podzem_podlazi,
30
+ b.pocet_podkrovi,
31
+ b.vytah,
32
+ b.czcc,
33
+ b.id_cuzk,
34
+ b.id_objekt,
35
+ b.kod_vyuziti,
36
+ b.nazev_vyuziti,
37
+ b.kod_ochrana,
38
+ b.nazev_ochrana,
39
+ b.platnost_od
40
+ FROM eno_budova b
41
+ ORDER BY b.gid, b.zdroj;