Bladeren bron

文档错误修改1

jxing 4 jaren geleden
bovenliggende
commit
4a93b9063e
1 gewijzigde bestanden met toevoegingen van 9 en 15 verwijderingen
  1. 9 15
      docs/dev/data-center/relations/belongs/Pe2Sp.md

+ 9 - 15
docs/dev/data-center/relations/belongs/Pe2Sp.md

@@ -14,29 +14,23 @@
 
 ```
 -- 资产所在业务空间
-create or replace function public.rel_pe2sp(project_id character varying) returns boolean
-as
-$$
+CREATE OR REPLACE FUNCTION "public"."rel_pe2sp"("project_id" varchar)
+  RETURNS "pg_catalog"."bool" AS $BODY$
 try:
-    input_tables = ['r_eq_in_sp_zone_air_conditioning', 'r_eq_in_sp_zone_clean', 'r_eq_in_sp_zone_domestic_water_supply', 'r_eq_in_sp_zone_fire', 'r_eq_in_sp_zone_function',
-        'r_eq_in_sp_zone_general', 'r_eq_in_sp_zone_heating', 'r_eq_in_sp_zone_lighting', 'r_eq_in_sp_zone_network', 'r_eq_in_sp_zone_power_supply', 'r_eq_in_sp_zone_security', 'r_eq_in_sp_zone_tenant']
-    output_tables = ['r_pe_in_sp_zone_air_conditioning', 'r_pe_in_sp_zone_clean', 'r_pe_in_sp_zone_domestic_water_supply',
-        'r_pe_in_sp_zone_fire', 'r_pe_in_sp_zone_function', 'r_pe_in_sp_zone_general', 'r_pe_in_sp_zone_heating', 'r_pe_in_sp_zone_lighting',
-        'r_pe_in_sp_zone_network', 'r_pe_in_sp_zone_power_supply', 'r_pe_in_sp_zone_security', 'r_pe_in_sp_zone_tenant']
     # 将下面对数据库的操作作为一个事务, 出异常则自动rollback
     with plpy.subtransaction():
-        for i in range(len(output_tables)):
-            delete_plan = plpy.prepare("delete from {0} where project_id = $1 and sign = 2".format(output_tables[i]), ["text"])
-            delete_plan.execute([project_id])
-            join_plan = plpy.prepare("insert into {1}(equip_id, space_id, project_id, sign) select pe.id, rel.space_id, pe.project_id, 2 from property pe inner join {0} rel on pe.equip_id = rel.equip_id where pe.project_id = $1 and rel.project_id = $1".format(input_tables[i], output_tables[i]), ["text"])
-            rel = join_plan.execute([project_id])
+        delete_plan = plpy.prepare("delete from relationship.r_pe2sp where project_id = $1 and sign = 2", ["text"])
+        delete_plan.execute([project_id])
+        join_plan = plpy.prepare("insert into relationship.r_pe2sp(eq_id, sp_id, project_id, sign, zone_type, type) select pe.id, rel.sp_id, pe.project_id, 2, rel.zone_type, 'pe2sp' from property pe inner join relationship.r_eq2sp rel on pe.equip_id = rel.eq_id where pe.project_id = $1 and rel.project_id = $1", ["text"])
+        rel = join_plan.execute([project_id])
 except Exception as e:
     plpy.warning(e)
     return False
 else:
     return True
-$$
-LANGUAGE 'plpython3u' VOLATILE;
+$BODY$
+  LANGUAGE plpython3u VOLATILE
+  COST 100
 
 select public.rel_pe2sp('Pj1101010015');
 ```