系统定制员修复

前不久客户不小心把系统定制员这个角色删除了,导致不能新建实体,在MSCRM4中倒是可以导入,但MSCRM3中没有定制员的导入,所以运行了一下代码,才算修复.

1create function dbo.GetPrivilegeDepthMask(@isbasic bit@islocal bit@isdeep bit@isglobal bit@parentRoleId uniqueidentifier)returns int as
  2
  3begin 
  4
  5declare @mask int 
  6
  7select @mask = 0 
  8
  9 
 10
 11if (@isbasic <> 0
 12
 13begin 
 14
 15if (@parentRoleId is null
 16
 17begin 
 18
 19select @mask = 1 
 20
 21end 
 22
 23if (@parentRoleId is not null
 24
 25begin 
 26
 27select @mask = 0x00000010 
 28
 29end 
 30
 31end 
 32
 33if (@islocal <> 0
 34
 35begin 
 36
 37if (@parentRoleId is null)
 38
 39begin 
 40
 41select @mask = 2 
 42
 43end 
 44
 45if (@parentRoleId is not null
 46
 47begin 
 48
 49select @mask = 0x00000020 
 50
 51end 
 52
 53end 
 54
 55if (@isdeep <> 0
 56
 57begin 
 58
 59if (@parentRoleId is null
 60
 61begin 
 62
 63select @mask = 4 
 64
 65end 
 66
 67if (@parentRoleId is not null
 68
 69begin 
 70
 71select @mask = 0x00000040 
 72
 73end 
 74
 75end 
 76
 77if (@isglobal <> 0
 78
 79begin 
 80
 81if (@parentRoleId is null
 82
 83begin 
 84
 85select @mask = 8 
 86
 87end 
 88
 89if (@parentRoleId is not null
 90
 91begin 
 92
 93select @mask = 0x00000080 
 94
 95end 
 96
 97end 
 98
 99 
100
101return @mask 
102
103end 
104
105go 
106
107 
108
109declare @rootBiz uniqueidentifier 
110
111declare @rootId uniqueidentifier 
112
113declare @organizationid uniqueidentifier 
114
115 
116
117declare @roleTemplateId uniqueidentifier 
118
119select @roleTemplateId = '119F245C-3CC8-4B62-B31C-D1A046CED15D' 
120
121declare @roleTemplateName nvarchar(256
122
123select @roleTemplateName = Name from RoleTemplateBase where RoleTemplateId = @roleTemplateId 
124
125 
126
127declare @parentRoleId uniqueidentifier 
128
129select @parentRoleId = null 
130
131 
132
133declare @roleid uniqueidentifier 
134
135select @roleid = null 
136
137 
138
139select @rootBiz = BusinessUnitId from BusinessUnitBase where ParentBusinessUnitId is null 
140
141declare c cursor FORWARD_ONLY READ_ONLY for select businessunitid from dbo.GetSubsidiaryBusinesses(@rootBizorder by depth 
142
143open c 
144
145fetch next from c into @rootId 
146
147while (@@fetch_status = 0
148
149begin 
150
151-- Get ParentRoleId 
152
153select @parentRoleId = RoleId from RoleBase where BusinessUnitId = (select ParentBusinessUnitId from BusinessUnitBase where BusinessUnitId = @rootIdand RoleTemplateId = @roleTemplateId select @roleid = RoleId from RoleBase where BusinessUnitId = @rootId and RoleTemplateId = @roleTemplateId 
154
155if (@roleid is null
156
157begin 
158
159select @roleid = newid() 
160
161insert into RoleBase(RoleId, RoleTemplateId, OrganizationId, DeletionStateCode, Name, BusinessUnitId, CreatedOn, ModifiedOn, CreatedBy, ModifiedBy, ParentRoleId) values(@roleid@roleTemplateId@organizationid0@roleTemplateName@rootId, getutcdate(), getutcdate(), nullnull@parentRoleId
162
163end 
164
165delete from RolePrivileges where RoleId = @roleid 
166
167insert into RolePrivileges(RoleId, PrivilegeId, PrivilegeDepthMask) 
168
169select @roleid, rtp.PrivilegeId, dbo.GetPrivilegeDepthMask(rtp.IsBasic, rtp.IsLocal, rtp.IsDeep, rtp.IsGlobal, @parentRoleIdfrom RoleTemplatePrivileges rtp where rtp.RoleTemplateId = @roleTemplateId 
170
171fetch next from c into @rootId 
172
173select @roleid = null 
174
175end 
176
177close c 
178
179deallocate c   

posted @ 2009-03-20 11:35  LiuLin  阅读(108)  评论(0)    收藏  举报