不同分公司只可以查看本公司的数据,根据工号查询分公司。工号为101700075的人员可以查看所有数据

image.png

报错信息

SELECT * FROM(

SELECT province , city , cus_code , cus_name , build_time , 

case when cus_type like '%销售商%' then '代理商' else cus_type end AS custype  , REPLACE(case when position('/' in dept_info) > 3 then split_part(dept_info , '/',5) else dept_info end ,'T','') as dept_info

FROM dw.tbl_dw_h3yun_sunrain_cus

WHERE 1=1

AND cus_type in ('运营商' , '代理商' , '工程商')

AND cus_status in ('正常' , '整改中')

AND COALESCE(toc_display_flag ,'') != '否'

AND length(cus_code) = 10

)A

WHERE dept_info not like '%一线%'

AND length(dept_info) > 0

and dept_info in (

SELECT distinct  SUBSTRING(dpt_name,2)as dpt_name  

FROM dw.tbl_dw_dingtalk_user2

WHERE  dpt_id in (select dpt_id FROM dw.tbl_dw_dingtalk_user2 

where 1=1

${if((fine_username)='101700075',"","AND dpt_id in (select dpt_id FROM dw.tbl_dw_dingtalk_user2 where user_id = '${fine_username}')

or parent_dpt_id in (select dpt_id FROM dw.tbl_dw_dingtalk_user2 where user_jobnum = '${fine_username}') ")}  

image.png问题应该就在这里image.png

(fine_username)='100500470',(fine_username)='101700075'这两个工号没有问题,但用其他人的工号报错

FineReport uBLWMMqv 发布于 2024-6-18 09:09 (编辑于 2024-6-18 09:47)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共4回答
最佳回答
0
snrtuemcLv8专家互助
发布于2024-6-18 09:13

最后问题

改成

where 1=1

${if((fine_username)='101700075',"","AND dpt_id in (select dpt_id FROM dw.tbl_dw_dingtalk_user2 where user_id = '"+fine_username+"')

or parent_dpt_id in (select dpt_id FROM dw.tbl_dw_dingtalk_user2 where user_jobnum = '"+fine_username+"') ")}  

  • uBLWMMqv uBLWMMqv(提问者) 用(fine_username)='100500470',(fine_username)='101700075'这两个工号没有问题,但用其他人的工号报错 我已经更新了问题,麻烦帮我看一下,谢谢
    2024-06-18 09:48 
  • snrtuemc snrtuemc 回复 uBLWMMqv(提问者) 看了下,sql写法没问题,看下是不是()用的是中文状态下符号,需要英文状态的
    2024-06-18 09:53 
最佳回答
0
用户k6280494Lv6资深互助
发布于2024-6-18 09:10(编辑于 2024-6-18 09:13)

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

权限细粒度模板内容控制

SELECT * FROM(

SELECT province , city , cus_code , cus_name , build_time , 

case when cus_type like '%销售商%' then '代理商' else cus_type end AS custype  , REPLACE(case when position('/' in dept_info) > 3 then split_part(dept_info , '/',5) else dept_info end ,'T','') as dept_info

FROM dw.tbl_dw_h3yun_sunrain_cus

WHERE 1=1

AND cus_type in ('运营商' , '代理商' , '工程商')

AND cus_status in ('正常' , '整改中')

AND COALESCE(toc_display_flag ,'') != '否'

AND length(cus_code) = 10

)A

WHERE dept_info not like '%一线%'

AND length(dept_info) > 0

and dept_info in (

SELECT distinct  SUBSTRING(dpt_name,2)as dpt_name  

FROM dw.tbl_dw_dingtalk_user2

WHERE  dpt_id in (select dpt_id FROM dw.tbl_dw_dingtalk_user2 

where 1=1

${if(fine_username='101700075',"","AND dpt_id in (select dpt_id FROM dw.tbl_dw_dingtalk_user2 where user_id = '"+fine_username+"')

or parent_dpt_id in (select dpt_id FROM dw.tbl_dw_dingtalk_user2 where user_jobnum = '"+fine_username+"') ")}  

最佳回答
0
1592Lv6高级互助
发布于2024-6-18 09:12

试试

where 1=1

${if((fine_username)='101700075',"","AND dpt_id in (select dpt_id FROM dw.tbl_dw_dingtalk_user2 where user_id = '"+fine_username+"')

or parent_dpt_id in (select dpt_id FROM dw.tbl_dw_dingtalk_user2 where user_jobnum = '"+fine_username+"') ")}  

最佳回答
0
坚果联盟Lv5见习互助
发布于2024-6-18 10:58

在and后面加上括号

where 1=1

${if((fine_username)='101700075',"","AND (dpt_id in (select dpt_id FROM dw.tbl_dw_dingtalk_user2 where user_id = '${fine_username}')

or parent_dpt_id in (select dpt_id FROM dw.tbl_dw_dingtalk_user2 where user_jobnum = '${fine_username}') )")} 

  • 5关注人数
  • 202浏览人数
  • 最后回答于:2024-6-18 10:58
    请选择关闭问题的原因
    确定 取消
    返回顶部