[AX2012 R3]关于Named user license report

时间:2023-03-08 18:56:37
[AX2012 R3]关于Named user license report

Named user license报表是用来统计各种授权类型用户数的,这里来看看报表数据具体是如何来的。这是一个SSRS的报表,最主要的数据源是来自于类SysUserLicenseCountReport定义的RDP,在SysUserLicenseCountReport的方法processReport中使用SysUserLicenseMiner::fillUserLicenseCountTmpTbl()填充一个临时表,最核心的部分就是这个方法:

public static void fillUserLicenseCountTmpTbl(SysUserLicenseCountTmp _userLicCountTblTmp, date _reportStateDate)
{
SysUserLicenseCount sulcTbl;
SysUserLicenseList sullTbl;
SecurityUserRole surTbl;
SecurityRole rTbl;
SysRoleLicenseType userRoleLicense;
delete_from _userLicCountTblTmp; ttsbegin; while select validTimeState(_reportStateDate, _reportStateDate) * from sulcTbl
outer join sullTbl
outer join User, SecurityRole from surTbl
join SecurityRole, UserLicenseType from userRoleLicense
join RecId, Name from rTbl
order by sulcTbl.UserLicenseType desc
where (sulcTbl.RecId == sullTbl.SysUserLicenseCount
&& sullTbl.UserName == surTbl.User
&& userRoleLicense.SecurityRole ==surTbl.SecurityRole
&& rTbl.RecId == surTbl.SecurityRole)
{
_userLicCountTblTmp.UserLicenseType = sulcTbl.UserLicenseType;
_userLicCountTblTmp.LicensedCount = sulcTbl.LicensedCount;
_userLicCountTblTmp.ActualCount = sulcTbl.ActualCount;
_userLicCountTblTmp.ValidFor = sulcTbl.ValidFrom;
_userLicCountTblTmp.NetworkDomain =sullTbl.NetworkDomain;
_userLicCountTblTmp.NetworkAlias =sullTbl.NetworkAlias;
_userLicCountTblTmp.Username =sullTbl.UserName;
_userLicCountTblTmp.SecurityRole = rTbl.Name;
_userLicCountTblTmp.SecurityRoleLicenseType = userRoleLicense.UserLicenseType;
_userLicCountTblTmp.insert();
} ttscommit;
}

这里用到好几个表,SysUserLicenseCount保存的是四种用户授权类型(枚举UserLicenseType:Enterprise,Functional,Task,Self serve)相应的用户数;SysUserLicenseList保存的是每个用户的授权记录,其SysUserLicenseCount记录的是表SysUserLicenseCount的recId;SecurityUserRole表不在AOT中,查看数据库得知保存的是每个用户对应的Role,如果一个用户被指定了多个Role,每个Role在这表中对应一条记录,列SecurityRole保存的是具体Role的ID;SecurityRole既不在AOT,连SQL数据库中也没有这个表,好在上面的代码中可以推测是AOT中所有Security roles的列表,这里用到的只是Role的名称;SysRoleLicenseType也不在AOT,但是在SQL数据库中,重要的是SecurityRole和UserlicenseType两个字段,前者记录的是每种Role的ID,后者则是这个Role相应的用户授权类型,每个Role只有一种用户授权类型。

因此上面的代码完成的就是构建一个临时表来记录每个用户的名称、网络别名、对应的每个角色、角色对应的用户授权类型、用户授权类型的授权用户数、用户授权类型的当前使用数。需要注意的是角色“System administrator”和“System user”在表SysRoleLicenseType是没有记录的,如果一个用户只有这两种角色,这个用户不会出现在报表中,但是System administrator仍然会占用一个Enterprise授权,仅仅是System user是不会影响到授权数的。

运行报表总是得到空白的结果,仔细查看发现上面的代码中有一行是有问题的(R3 CU8的系统),“&& sullTbl.UserName == surTbl.User”,查看数据库表SecurityUserRole,User一列实际上保存的是用户的网络别名,更改为“&& sullTbl.NetworkAlias == surTbl.User”后运行报表得到结果,类似:

[AX2012 R3]关于Named user license report

还需要注意必须切换到DAT公司下才会有数据,用到的表SysUserLicenseCount等等是不保存公司信息的,按照我的理解应该不管在哪个公司下都应该得到相同的结果,可实际上只有切换到DAT公司报表才有数据。

接下来的问题相关表中的数据又是哪里来的呢?在部署系统的时候系统会自动为我们创建一个名为“Named user license count reports processing”的批处理任务,由它更新数据到这些表中,默认一周运行一次。这个批处理任务具体执行的是SysUserLicenseMiner类,run方法调用SysUserLicenseMiner::GenerateUserLicenseCountReportInfo(),我们直接调用这个方法也是可以更新授权数数据的。如果你在批处理列表中找不到这个job,可以调用SysUserLicenseMiner::createBatchJob()为你创建一个。而具体是如何更新的呢?答案自然也是在 SysUserLicenseMiner中,这里就不翻代码了,就别的地方看到的总结一下。AOT中打开一个Menu item,有两个属性是和授权相关的,ViewUserLicense和MaintainUserLicense,前者是查看需要的授权,后者是维护数据需要的授权,它们的值都是前面提到的枚举UserLicenseType。SysUserLicenseMiner的工作就是遍历所有Menu item,找出相应的用户授权,接着遍历用户用户角色,找出每个用户角色对应的用户授权类型,最后遍历每个用户,找出用户的最高用户授权类型(Enterprise最高)。所以问题的核心在于菜单项的用户授权类型,如果我们新建一个自己的菜单项会怎样?默认ViewUserLicense和MaintainUserLicense都是NONE,是不影响授权数的,当然你可以闲着没事修改这两个属性成其他数值。我们可以duplicate系统自带的菜单项,然后修改这两个属性为NONE,后面就不细说了。

最后要说的是这个报表的格式,无论我是否选中“show list of users per access license type ”结果都是一样,Report的design也只有上面图中的一个,有知道原因的朋友请告诉我为什么...