NC65 单据模板查询分配的用户、角色和职责 sql

NC65 单据模板查询分配的用户、角色和职责 sql

/* 
 operator_type 的值:

1——操作员,即用户
2——角色
3——岗位
4——公司
5——流程用户组
6——用户组
7——角色组
8——业务单元
9——业务汇报关系 
10——虚拟角色(目前只有所有制单人)
11——职责 
12——自定义参与者
13——常用规则
14——自定义规则 
*/

select * from pub_systemplate; --operator  operator_type

select * from pub_billtemplet;

select * from pub_systemplate_base


select * from pub_billtemplet_t

select * from pub_billtemplet_b b where b.pk_billtemplet = '1001Z31000000000E0MT' and itemkey = 'iscostshare'

--职责表
select * from sm_responsibility

--角色
select * from sm_role

--用户角色
select * from sm_user_role

--功能权限分配实体 
select * from sm_perm_func


--按用户
select st.pk_systemplate, st.funnode, st.nodekey, st.operator, st.operator_type, case when st.operator_type = 1 then '用户' end as operator_type_name, bt.pk_billtemplet, bt.pk_billtypecode, bt.bill_templetname, su.user_code as operator_code, su.user_name as operator_name from pub_systemplate st inner join pub_billtemplet bt on st.templateid = bt.pk_billtemplet inner join sm_user su on st.operator = su.cuserid where st.operator_type = parameter('operator_type') and st.nodekey = parameter('nodekey') and st.pk_org = parameter('pk_org') and su.cuserid = parameter('cuserid') and bt.pk_billtemplet = parameter('pk_billtemplet')

union all

--按角色
select st.pk_systemplate, st.funnode, st.nodekey, st.operator, st.operator_type, case when st.operator_type = 2 then '角色' end as operator_type_name, bt.pk_billtemplet, bt.pk_billtypecode, bt.bill_templetname, sr.role_code as operator_code, sr.role_name as operator_name from pub_systemplate st inner join pub_billtemplet bt on st.templateid = bt.pk_billtemplet inner join sm_role sr on st.operator = sr.pk_role where st.operator_type = parameter('operator_type') and st.nodekey = parameter('nodekey') and st.pk_org = parameter('pk_org') and sr.pk_role = parameter('pk_role') and bt.pk_billtemplet = parameter('pk_billtemplet')

union all

--按职责
select st.pk_systemplate, st.funnode, st.nodekey, st.operator, st.operator_type, case when st.operator_type = 11 then '职责' end as operator_type_name, bt.pk_billtemplet, bt.pk_billtypecode, bt.bill_templetname, sry.code as operator_code, sry.name as operator_name from pub_systemplate st inner join pub_billtemplet bt on st.templateid = bt.pk_billtemplet inner join sm_responsibility sry on st.operator = sry.pk_responsibility where st.operator_type = parameter('operator_type') and st.nodekey = parameter('nodekey') and st.pk_org = parameter('pk_org') and sry.pk_responsibility = parameter('pk_responsibility') and bt.pk_billtemplet = parameter('pk_billtemplet')

上面的sql有点问题,现在用下面的sql

SELECT st.pk_systemplate pk_systemplate, st.funnode funnode, st.nodekey nodekey, st.operator operator, st.operator_type operator_type, CASE WHEN st.operator_type = 1 THEN '用户' WHEN st.operator_type = 2 THEN '角色' WHEN st.operator_type = 11 THEN '职责' END operator_type_name, bt.pk_billtemplet pk_billtemplet, bt.pk_billtypecode pk_billtypecode, bt.bill_templetname bill_templetname, CASE WHEN st.operator_type = 1 THEN su.user_code WHEN st.operator_type = 2 THEN sr.role_code WHEN st.operator_type = 11 THEN sry.code END AS operator_code, CASE WHEN st.operator_type = 1 THEN su.user_name WHEN st.operator_type = 2 THEN sr.role_name WHEN st.operator_type = 11 THEN sry.name END AS operator_name
FROM pub_systemplate st
INNER JOIN pub_billtemplet bt ON st.templateid = bt.pk_billtemplet
LEFT JOIN sm_user su ON st.operator = su.cuserid
LEFT JOIN sm_role sr ON st.operator = sr.pk_role
LEFT JOIN sm_responsibility sry ON st.operator = sry.pk_responsibility
WHERE st.operator_type = parameter('operator_type') AND st.nodekey = parameter('nodekey') AND st.pk_org = parameter('pk_org') AND su.cuserid = parameter('cuserid') AND sr.pk_role = parameter('pk_role') AND sry.pk_responsibility = parameter('pk_responsibility') AND bt.pk_billtemplet = parameter('pk_billtemplet')

自由报表发布为节点:
NC65 单据模板查询分配的用户、角色和职责 sql_第1张图片

你可能感兴趣的:(NC,数据库,NC,数据库)