|
@@ -1,21 +1,23 @@
|
|
|
-设备所在业务空间
|
|
|
+# 设备所在业务空间
|
|
|
## 前置条件
|
|
|
- 1. 业务空间有所属楼层
|
|
|
- 2. 设备有所属楼层
|
|
|
- 3. 业务空间有轮廓数据(outline)
|
|
|
- 4. 设备有坐标信息(bimLocation)
|
|
|
+ 1. 业务空间有所属楼层关系
|
|
|
+ 2. 设备有所属楼层关系
|
|
|
+ 3. 业务空间有轮廓数据(outline信息点)
|
|
|
+ 4. 设备有坐标信息(bimLocation信息点)
|
|
|
## 依赖函数
|
|
|
- Eq2Fl
|
|
|
-## 处理方式
|
|
|
- 将在同一楼层内的设备和业务空间取出, 判断设备的bim_location是否在业务空间的outline内,
|
|
|
- 如果在, 则添加进对应的关系表内, 控制sign = 2
|
|
|
+ Eq2Fl, Sp2Fl
|
|
|
+## 处理逻辑
|
|
|
+ 1. 取出项目内的所有业务空间和设备, 将在同一楼层内的设备和业务空间分成一组
|
|
|
+ 2. 在一组内, 判断设备的bim_location是否在业务空间的outline内, 即做点在多边形内的判断, 点在多边形内则认为有关系
|
|
|
|
|
|
# 函数
|
|
|
## 代码
|
|
|
+<details>
|
|
|
+<summary>源码</summary>
|
|
|
+
|
|
|
```
|
|
|
-create or replace function public.rel_eq2sp(tables text, out_tables text, project_id character varying, sign1 integer, sign2 integer) returns boolean
|
|
|
-as
|
|
|
-$$
|
|
|
+CREATE OR REPLACE FUNCTION "public"."rel_eq2sp"("tables" text, "out_tables" text, "project_id" varchar, "sign1" int4, "sign2" int4)
|
|
|
+ RETURNS "pg_catalog"."bool" AS $BODY$
|
|
|
from matplotlib.path import Path
|
|
|
import json
|
|
|
|
|
@@ -80,8 +82,9 @@ with plpy.subtransaction():
|
|
|
if len(equips) == 0:
|
|
|
continue
|
|
|
# 获取楼层下的业务空间
|
|
|
- space_plan = plpy.prepare("select id, outline from {0} as sp where project_id = $1 and outline is not null and floor_id = $2".format(in_table_name), ["text", "text"])
|
|
|
- spaces = space_plan.execute([project_id, floor_id])
|
|
|
+
|
|
|
+ space_plan = plpy.prepare("select sp.id, sp.outline, sp.object_type from public.r_sp_in_fl rel inner join {0} sp on rel.space_id = sp.id where outline is not null and rel.floor_id = $1".format(in_table_name), ["text"])
|
|
|
+ spaces = space_plan.execute([floor_id])
|
|
|
if len(spaces) == 0:
|
|
|
continue
|
|
|
# 判断设备的bim_location是否在业务空间的outline内
|
|
@@ -91,18 +94,23 @@ with plpy.subtransaction():
|
|
|
location = equip['bim_location'].split(',')
|
|
|
if is_point_in_polygon(location[0], location[1], space['outline']):
|
|
|
# 设备在业务空间内, 添加关系
|
|
|
- insert_plan = plpy.prepare("insert into {0}(equip_id, space_id, project_id, sign) values($1, $2, $3, 2) ".format(out_table_name.strip()), ["text", "text", 'text'])
|
|
|
- insert_plan.execute([equip['id'], space['id'], project_id])
|
|
|
+ insert_plan = plpy.prepare("insert into {0}(eq_id, sp_id, project_id, sign, type, zone_type) values($1, $2, $3, 2, 'eq2sp_in', $4)".format(out_table_name.strip()), ["text", "text", "text", "text"])
|
|
|
+ insert_plan.execute([equip['id'], space['id'], project_id, space['object_type']])
|
|
|
except Exception as ex:
|
|
|
+ plpy.warning(ex)
|
|
|
continue
|
|
|
return True
|
|
|
-$$
|
|
|
-LANGUAGE 'plpython3u' VOLATILE;
|
|
|
+$BODY$
|
|
|
+ LANGUAGE plpython3u VOLATILE
|
|
|
+ COST 100
|
|
|
|
|
|
|
|
|
例子:
|
|
|
select public.rel_eq2sp('zone_general,zone_lighting', 'r_eq_in_sp_zone_general,r_eq_in_sp_zone_lighting', 'Pj1101010015', 2, 2);
|
|
|
```
|
|
|
+</details>
|
|
|
+
|
|
|
+
|
|
|
## 输入
|
|
|
1. 参与计算的业务空间表的全名称, 带schema名, 以英文逗号隔开
|
|
|
2. 关系计算结果存储的表, 跟第一个参数一一对应, 带schema名, 以英文逗号隔开
|