判断用户是否有菜单操作权限原创
4人赞赏了该文章
200次浏览
编辑于2023年10月17日 19:57:10
男儿何不带吴钩,收取关山五十州。
using Kingdee.BOS; using Kingdee.BOS.ServiceHelper; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Utils { /// <summary> /// 金蝶基础方法工具类,例如用户、权限等操作的方法 /// </summary> public class KingdeeBaseHelper { /// <summary> /// 判断用户是否有菜单操作权限 /// </summary> /// <param name="ctx">上下文</param> /// <param name="billName">单据名称</param> /// <param name="ItemName">菜单名称</param> /// <param name="OrgId">组织ID</param> /// <param name="UserId">用户ID</param> /// <returns>0/1</returns> public int PermissionValidators(Context ctx, string BillName, string ItemName, long OrgId, long UserId) { string sql = string.Format(@"SELECT t2.* , ROW_NUMBER() OVER ( ORDER BY FUserName ASC, FOrgNumber ASC, FTopClassName ASC, FSubSystemName ASC, FObjectTypeName ASC, FPermissionItemName ASC, FPermissionStatusName ASC ) FIDENTITYID FROM ( SELECT DISTINCT t1.* FROM ( SELECT u.FName FUserName , u.FUserID , org1.FNumber FOrgNumber , org2.FName FOrgName , uo.FOrgID , r2.FName FRoleName , p1.FRoleID , t2.FName FTopClassName , s2.FName FSubSystemName , o2.FName FObjectTypeName , p4.FName FPermissionItemName , p2.FPERMISSIONSTATUS FPermissionStatusNumber , ( CASE p2.FPERMISSIONSTATUS WHEN '0' THEN '有权' WHEN '2' THEN '禁止' ELSE '无权' END ) FPermissionStatusName , p3.FSEQ FROM t_sec_FuncPermission p1 --授权 INNER JOIN t_sec_funcPermissionEntry p2 ON p1.FItemID = p2.FItemID --授权明细 INNER JOIN T_SEC_PERMISSIONITEM p3 ON p2.FPermissionItemID = p3.FItemID --权限项 INNER JOIN T_SEC_PERMISSIONITEM_l p4 ON p3.FItemID = p4.FItemID AND p4.FLOCALEID = 2052 --权限项多语言 INNER JOIN t_sec_role r1 ON p1.FRoleID = r1.FRoleID --角色 INNER JOIN t_sec_role_l r2 ON r2.FRoleID = r1.FRoleID AND r2.FLOCALEID = 2052 --角色多语言 INNER JOIN t_sec_userrolemap uor ON uor.FROLEID = p1.FRoleID --用户角色关系 INNER JOIN T_SEC_USERORG uo ON uo.FENTITYID = uor.FENTITYID --用户组织关系 INNER JOIN t_sec_User u ON uo.FUserID = u.FUserID --用户 INNER JOIN t_org_organizations org1 ON org1.FOrgID = uo.FOrgID --组织 INNER JOIN t_org_organizations_l org2 ON org1.FOrgID = org2.FOrgID AND org2.FLOCALEID = 2052 --组织多语言 INNER JOIN t_meta_objectType o1 ON p1.FObjectTypeID = o1.FID INNER JOIN t_meta_objectType_l o2 ON p1.FObjectTypeId = o2.FID AND o2.FLOCALEID = 2052 --业务对象多语言 INNER JOIN t_meta_subsystem s1 ON o1.FSUBSYSID = s1.FID --子系统 INNER JOIN t_meta_subsystem_l s2 ON o1.FSUBSYSID = s2.FID AND s2.FLOCALEID = 2052 --子系统多语言 INNER JOIN T_META_TOPCLASS_L t2 ON t2.FTOPCLASSID = s1.FTOPCLASSID AND t2.FLOCALEID = 2052 --子系统多语言 --inner join T_META_FORMENUMITEM e1 on e1.FValue=p2.FPERMISSIONSTATUS and e1.fid='a1d6b10c-87d4-4fb0-97f8-3fa983f50c44' --枚举值表 是否有权的枚举 --inner join T_META_FORMENUMITEM_l e2 on e2.fenumid=e1.fenumid and e2.FLOCALEID=2052 --枚举多语言 ) t1 ) t2 WHERE fobjecttypename='{0}' AND fpermissionitemname='{1}' AND FPermissionStatusName='有权' AND fUserid={2} and FORGID={3} ", BillName, ItemName, UserId, OrgId); DataSet ds = DBServiceHelper.ExecuteDataSet(ctx, sql); int flag = 0; if (ds.Tables[0].Rows.Count > 0) { flag = 1; } else { flag = 0; } return flag; } } }
推荐阅读