Pe2Fl.md 1016 B

资产所在楼层

前置条件

1. 资产有绑定的设备或部件
2. 绑定的设备或部件有所在楼层

依赖函数

Eq2Fl

计算流程

根据 资产 --> 设备/部件 --> 楼层 的间接关系, 来获取资产所在建筑的关系

函数

-- 资产属于楼层
create or replace function public.rel_pe2fl(project_id character varying) returns boolean
as
$$
try:
    # 将下面对数据库的操作作为一个事务, 出异常则自动rollback
    with plpy.subtransaction():
        plan = plpy.prepare("update property as pe set floor_id = eq.floor_id from equipment eq where eq.id = pe.equip_id and eq.floor_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_pe2fl('Pj1101010015');

入参

1. 项目id

例子

select public.rel_pe2fl('Pj1101010015');