0
点赞
收藏
分享

微信扫一扫

动态sql获取数据说明

一、操作步骤:

  1. 对线缆或节点添加想要实现动态查询的字段
  2. 编写sql查询运行脚本如:

-- 通过线缆id查询纤芯总芯数
select count(*) from sublinks where link_id = {0}

保存文本内容为.sql结尾,如@ne_link_count_core.sql

  1. 修改对象字段值为 @sql脚本名称(参数1,参数2,参数3......),如@ne_link_count_core(id)
  2. 保存文件到nVisual前端部署目录下/sqlEditor文件夹下
  3. 视图区及组合视图区域查询字段属性时,如果字段属性值中有@符号,则获取@符号后sql文件名称及sql文件内容,实时查询该字段值。

注:当数据库查询错误、输入动态字段值与规则不符、服务器中无sql文件时,动态属性值还为原来输入的值。

二、表达式说明

2.1. @ne_link_totalCores(id)

表达式说明:查询当前线缆的总共芯数

参数说明:

名称

类型

说明

id

bigint

id为当前对象(线缆)的id

sql脚本内容:

select count(*) from sublinks where link_id = {0};

2.2. @ne_link_usefulCores(id)

表达式说明:查询当前线缆的剩余可用芯数

参数说明:

名称

类型

说明

id

bigint

id为当前对象(线缆)的id

sql脚本内容:

select a.total-b.damaged-c.alreadyUsed from (
 select count(*) as total from sublinks where link_id = {0} ) a,
(select count(*) as damaged from sublinks s left join link_property_values lpv on s.id = lpv.link_id
left join link_properties lp on lpv.property_id = lp.id 
where s.link_id = {0} and lp.name = '效果' and lpv.value = 'sublinkBad') b,
(select count(s.id) as alreadyUsed from sublinks s left join link_property_values lpv on s.id = lpv.link_id
left join link_properties lp on lpv.property_id = lp.id 
where s.link_id = {0} and lp.name = '效果' and lpv.value = 'sublinkUsed') c

注:当线芯“效果”字段设置为“已用”时表示线芯已经使用,设置为“损坏”时表示线芯已损坏

2.3. @ne_link_alreadyUseCores(id)

表达式说明:查询当前线缆已经使用芯数

参数说明:

名称

类型

说明

id

bigint

id为当前对象(线缆)的id

sql脚本内容:

select count(s.id) from sublinks s left join link_property_values lpv on s.id = lpv.link_id
left join link_properties lp on lpv.property_id = lp.id 
where s.link_id = {0} and lp.name = '效果' and lpv.value = 'sublinkUsed'

注:当线芯“效果”字段设置为“已用”时表示线芯已经使用,设置为“损坏”时表示线芯已损坏

2.4. @ne_link_damageCores(id)

表达式说明:查询当前线缆已损坏芯数

参数说明:

名称

类型

说明

id

bigint

id为当前对象(线缆)的id

sql脚本内容:

select count(*) from sublinks s left join link_property_values lpv on s.id = lpv.link_id
left join link_properties lp on lpv.property_id = lp.id 
where s.link_id = {0} and lp.name = '效果' and lpv.value = 'sublinkBad'

注:当线芯“效果”字段设置为“已用”时表示线芯已经使用,设置为“损坏”时表示线芯已损坏

2.5. @ne_link_opticalCableCountByPipe(id)

表达式说明:查询管沟内光缆数量

参数说明:

名称

类型

说明

id

bigint

id为当前对象(管沟)的id

sql脚本内容:

select
 case when count(blm.link_id)=0 then 
(select count(blm.link_id) from links l left join bundled_links_mapping blm on l.id = blm.container_id
 where l.id = {0}) 
 else count(blm.link_id) end as count
 from sublinks s inner join bundled_links_mapping blm on s.id = blm.container_id
 where s.link_id = {0}

2.6. @ne_sublink_opticalCableCountByGrill(id)

表达式说明:查询格栅内光缆数量

参数说明:

名称

类型

说明

id

bigint

id为当前对象(格栅sublink)的id

sql脚本内容:

select count(blm.link_id) from sublinks s inner join bundled_links_mapping blm on s.id = blm.container_id
 where s.link_id = {0}

2.7. @ne_link_fromName(id)

表达式说明:查询线缆起始端名称

参数说明:

名称

类型

说明

id

bigint

id为当前对象(线缆)的id

sql脚本内容:

select 
case when left(cast(from_node as varchar),2)='24' then (select name from nodes where id = from_node)
else (select name from nodes_ports where id = from_node) end 
 from links where id = {0}

2.8. @ne_link_toName(id)

表达式说明:查询线缆终端名称

参数说明:

名称

类型

说明

id

bigint

id为当前对象(线缆)的id

sql脚本内容:

select 
case when left(cast(to_node as varchar),2)='24' then (select name from nodes where id = to_node)
else (select name from nodes_ports where id = to_node) end 
 from links where id = {0}

2.9. @ne_node_belong_optical_cble(id)

表达式说明:查询盘留对应所属光缆

参数说明:

名称

类型

说明

id

bigint

id为当前对象(盘留)的id

sql脚本内容:

select name from links where id in(
select r.bid from relations r inner join relation_types rt on r.relation_type_id = rt.id and rt.reverse_name = '线缆包含盘留' where r.aid = {0})

举报

相关推荐

0 条评论