资产所在建筑
1. 资产有绑定的设备或部件
2. 绑定的设备或部件有所在建筑
Eq2Bd
根据 资产 --> 设备/部件 --> 建筑 的间接关系, 来获取资产和建筑的所在关系
-- 资产属于建筑体
create or replace function public.rel_pe2bd(project_id character varying) returns boolean
as
$$
try:
# 将下面对数据库的操作作为一个事务, 出异常则自动rollback
with plpy.subtransaction():
plan = plpy.prepare("update property as pe set building_id = eq.building_id from equipment eq where eq.id = pe.equip_id and eq.building_id is not null and eq.project_id = $1 and pe.project_id = $1", ["text"])
rel = plan.execute([project_id])
except Exception as e:
plpy.warning(e)
return False
else:
return True
$$
LANGUAGE 'plpython3u' VOLATILE;
select public.rel_pe2bd('Pj1101010015');
1. 项目id
select public.rel_pe2bd('Pj1101010015');