# 资产所在业务空间
## 前置条件
    1. 资产有绑定的设备或部件
    2. 绑定的设备或部件有所在业务空间关系
## 依赖函数
    Eq2Sp
## 计算流程
    根据 资产 --> 设备/部件 --> 业务空间 的间接关系, 来获取资产所在业务空间的关系
    
## 函数

<details>
<summary>源码</summary>

```
-- 资产所在业务空间
CREATE OR REPLACE FUNCTION "public"."rel_pe2sp"("project_id" varchar)
  RETURNS "pg_catalog"."bool" AS $BODY$
try:
    # 将下面对数据库的操作作为一个事务, 出异常则自动rollback
    with plpy.subtransaction():
        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
$BODY$
  LANGUAGE plpython3u VOLATILE
  COST 100

select public.rel_pe2sp('Pj1101010015');
```

</details>

## 入参
    1. 项目id
## 例子
    select public.rel_pe2sp('Pj1101010015');