请问怎么通过是否配置角色来控制sql查询条件

请问怎么通过是否配置角色来控制 sql查询条件, 请问我的语句该怎么调

-- 有配置角色 看对应团队数据

${if(len(fine_role) == 0,"  

and exists (select 1 

from dw_crm.dws_crm_finereport_role t1 

join (select distinct t.vc_fundcode, t.vc_cust_mngrid, t.vc_objeno,  

t.vc_effectivedate as vc_bgndate, t.vc_enddate, 

t1.vc_ori_dept_crm as c_nodecode

from dw.dw_empl_cust_brok_rela t 

    join dw.dw_empl_main_dept_crm t1

on (t.vc_cust_mngrid = t1.vc_emplno_crm and t.vc_effectivedate <= t1.vc_enddate and t.vc_enddate >= t1.vc_bgndate)

where t.vc_audit_status = '0' -- 审核通过

and t.vc_obje_type = '1' -- 客户

-- and t.vc_cust_mngrid = (select distinct vc_emplid_crm from dw.dw_empl_base_info_crm where vc_email = '${p_email}') 

) t2

on (t1.fr_role_name in ('${REPLACE(fine_role,",","','")}')  

and t2.c_nodecode like t1.c_nodevalue||'%'

)

where t2.vc_fundcode = a1.vc_fundcode

and t2.vc_objeno = a1.vc_custno

and a1.vc_cdate >= t2.vc_bgndate

and a1.vc_cdate <= t2.vc_enddate  

)

"," 

-- 无配置角色-看自己的数据 

and exists (

select 1 

from (select distinct t.vc_fundcode, t.vc_cust_mngrid, t.vc_objeno,  

t.vc_effectivedate as vc_bgndate, t.vc_enddate, 

t1.vc_ori_dept_crm as c_nodecode

from dw.dw_empl_cust_brok_rela t 

    join dw.dw_empl_main_dept_crm t1

on (t.vc_cust_mngrid = t1.vc_emplno_crm and t.vc_effectivedate <= t1.vc_enddate and t.vc_enddate >= t1.vc_bgndate)

where t.vc_audit_status = '0' -- 审核通过

and t.vc_obje_type = '1' -- 客户

and t.vc_cust_mngrid = (select distinct vc_emplid_crm from dw.dw_empl_base_info_crm where vc_email = '${p_email}') 

) t2

where t2.vc_fundcode = a1.vc_fundcode

and t2.vc_objeno = a1.vc_custno

and a1.vc_cdate >= t2.vc_bgndate

and a1.vc_cdate <= t2.vc_enddate  

)

" )}

FineReport Y5266752 发布于 2025-5-20 17:05
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
用户k6280494Lv6专家互助
发布于2025-5-20 17:06(编辑于 2025-5-20 17:10)

根据账号控制查询数据权限

select * from table where 1=1

${if(find('角色A',fine_role)>0,"and xxx","and xxx")}

find('角色A',fine_role)>0含有角色A

最佳回答
0
yzm665590Lv2见习互助
发布于2025-5-20 17:54(编辑于 2025-5-20 18:02)

我之前用的是笨办法,select * from ( select *,(全部)角色字段  from 表A    union all    select *, (自身)角色字段  from 表A)a

where 1=1

${if(len(fine_role) == 0,角色字段="全部",角色字段="自身")}

  • 3关注人数
  • 28浏览人数
  • 最后回答于:2025-5-20 18:02
    请选择关闭问题的原因
    确定 取消
    返回顶部