用友U8增加自定义权限功能

在用友U8中,会遇到一些在标准权限之外的按钮权限,比如在采购订单新增权限,我们要限制权限类型为[]用户名起的好]的才允许新增采购订单.

1.先加入自定义的权限类型

delete UFSystem.dbo.ua_auth_base
where cAuth_Id like 'OLL%';

delete UFSystem.dbo.UA_Auth_lang
where cAuth_ID like 'OLL%';

--权限目录
insert into UFSystem.dbo.ua_auth_base
(
    cAuth_Id,
    cSub_Id,
    iGrade,
    cSupAuth_Id,
    bEndGrade,
    iOrder,
    cAcc_Id,
    cAuthType,
    cAllSupAuths,
    irepnum,
    cRepellent,
    cRepellentModule,
    cNotRepellent,
    cRepInDB,
    cRepModInDB,
    cNotRepInDB
)
values
('OLL', 'UA', '1', null, 'False', '10', null, null, null, null, null, null, null, null, null, null);


insert into UFSystem.dbo.UA_Auth_lang
(
    localeid,
    cAuth_ID,
    cAuth_Name
)
values
('zh-CN', 'OLL', '二次开发权限');

--具体的权限
insert into UFSystem.dbo.ua_auth_base
(
    cAuth_Id,
    cSub_Id,
    iGrade,
    cSupAuth_Id,
    bEndGrade,
    iOrder,
    cAcc_Id,
    cAuthType,
    cAllSupAuths,
    irepnum,
    cRepellent,
    cRepellentModule,
    cNotRepellent,
    cRepInDB,
    cRepModInDB,
    cNotRepInDB
)
values
('OLL40', 'UA', '3', 'OLL', 'True', '10', null, null, null, null, null, null, null, null, null, null);

insert into UFSystem.dbo.UA_Auth_lang
(
    localeid,
    cAuth_ID,
    cAuth_Name
)
values
('zh-CN', 'OLL40', '用户名起的好');


新增的权限位置(自定义的权限在实例中,挂在UAP目录下,如果要放在别的目录下,自行修cSub_Id字段中的值):

 

 2.在单据中的自定义按钮或者标准的按钮中(如何拦截用友标准按钮,或者自定义按钮的功能,参考其已发布的其他的文章),调用判断是否有相应权限的方法.

  public bool CheckIsHaveRight(string userId ,string authId )
  {
    try
     {
     
                string sql = @"
 select u.iAdmin ,
        h.cAuth_Id
 from   UFSystem.dbo.UA_User U
        left join UFSystem.dbo.UA_Role R on U.cUser_Id = R.cUser_Id
        left join UFSystem.dbo.UA_HoldAuth H on r.cGroup_Id = h.cUser_Id
 where  h.iIsUser = 0
        and u.cUser_Id = '{0}'
        and h.cAcc_Id = '{1}'
 union all
 select u.iAdmin ,
        h.cAuth_Id
 from   UFSystem.dbo.UA_User U
        left join UFSystem.dbo.UA_HoldAuth H on U.cUser_Id = H.cUser_Id
 where  h.iIsUser = 1
        and u.cUser_Id = '{0}'
        and h.cAcc_Id = '{1}'
";

                sql = string.Format(sql, userId, Config.AccId);
                DataTable dt = SqlHelper.ExecuteDataset(Config.UFConn, CommandType.Text, sql).Tables[0];
                if (dt.Rows.Count == 0)
                {
                    throw new Exception("当前用户:" + userId + "不存在");
                }

                DataRow[] adminRows = dt.Select("cAuth_Id='admin'");
                if (adminRows.Length > 0)
                {
                    return  true;
                }

                DataRow[] authRows = dt.Select("cAuth_Id='" + authId + "'");
                if (authRows.Length > 0)
                {
                    return  true;
                }
                throw new Exception("没有权限,用户[" + userId + "]权限[" + authId + "]");

            }
            catch (Exception error)
            {
               return  false ;

            }
               return  false ;
        }

userId:当前用户的账号

authId:就是权限的编号了.在本例子中,要判断用户名起得好的权限,authId=OLL40

cAccId:是当前用友的账套号


版权声明:本文为daniel_qsy原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。