按地市分公司逐个初始化用户数据。每个地市分公司为一个租户模式。
导入数据过程详见上篇文章《新PaaS平台上线数据初始化经验 》。
如下方案前提是已经初始化所有部门信息,详见《通过WebService及存储过程等技术批量初始化系统组织数据 》。
初始化数据涉及到表有:
/* 更新临时表中组织编码、组织名称 */
update tmp_user tt set (tt.deptid,tt.deptname) =( select t1.org_id,t1.org_name from sm_organization t1 where tt.dept = t1.org_code) where tt.deptid is null and tt.tenant_code='MDJ' and exists ( select 1 from sm_organization t1 where tt.dept = t1.org_code);
/* 初始化账户组织及人员组织内排序 */
update sm_account tt set (tt.own_org,tt.sort_no) = (select t.deptid,to_number(t.orderby) from tmp_user t where t.cn = tt.acc_name and t.deptid is not null and t.tenant_code='MDJ') where exists (select 1 from tmp_user t where t.cn = tt.acc_name and t.deptid is not null and t.tenant_code='MDJ') ;
/* 初始化租户用户帐号信息 */
update sm_tenant_account tt set (tt.org_id,tt.tenant_account,tt.tenant_code,tt.tenant_name,tt.tenant_dn) = (select t.own_org,t.acc_name,'MDJ','牡丹江市分公司','o=MDJ,cn=cordys,cn=defaultInst,o=hlcuc.com' from sm_account t where t.acc_id = tt.acc_id and t.own_org is not null and t.acc_name in (select cn from tmp_user where deptid is not null and tenant_code='MDJ')) where exists (select 1 from sm_account t where t.acc_id = tt.acc_id and t.own_org is not null and t.acc_name in (select cn from tmp_user where deptid is not null and tenant_code='MDJ')) ;
/* 初始化租户用户帐号关于租户内容组织信息 */
update sm_tenant_account tt set (tt.org_code,tt.org_name,tt.user_dn) = (select t.org_code,t.org_name,'cn='||tt.tenant_account||',cn=organizational users,o=MDJ,cn=cordys,cn=defaultInst,o=hlcuc.com' from sm_organization t where t.org_id=tt.org_id and tt.tenant_account in (select cn from tmp_user where deptid is not null and tenant_code='MDJ')) where exists (select 1 from sm_organization t where t.org_id=tt.org_id and tt.tenant_account in (select cn from tmp_user where deptid is not null and tenant_code='MDJ'));
通过Test Web Gateway工具,获取角色及角色ID。
其中,调用SOAP内容如下:
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<UpdateSmRole xmlns="http://com.unicom.bopm/organization" reply="yes" commandUpdate="no" preserveSpace="no" batchUpdate="no">
<tuple>
<new>
<SM_ROLE qAccess="0" qConstraint="0" qInit="0" qValues="">
<ROLE_ID></ROLE_ID>
<RE_GROUP_ID>3b33b295-f4f8-11e5-f4ab-580ecf349fbd</RE_GROUP_ID>
<ROLE_NAME>牡丹江_地市部门成员</ROLE_NAME>
<STATUS_SIGN>1</STATUS_SIGN>
<IS_ADMIN>0</IS_ADMIN>
<ROLE_DESC></ROLE_DESC>
<ORG_ID>777cfa77-9924-11e5-f753-f88c31201fbf</ORG_ID>
<TENANT_DN>o=MDJ,cn=cordys,cn=defaultInst,o=hlcuc.com</TENANT_DN>
</SM_ROLE>
</new>
</tuple>
</UpdateSmRole>
</SOAP:Body>
</SOAP:Envelope>
其中,牡丹江市分公司,组织ID = ‘777cfa77-9924-11e5-f753-f88c31201fbf’。
/* 添加牡丹江地市部门成员角色名称 */
update sm_role t set t.re_code = 'MDJ_DSBMCY' where t.role_id = 'ff3f0083-0348-11e5-f7fc-f370324d9799';
/* 把角色为部门成员的角色赋给所有人:角色ID=ff3f0083-0348-11e5-f7fc-f370324d9799 */
insert into sm_orgaccount_role (role_id,org_acc_id,status_sign) select 'ff3f0083-0348-11e5-f7fc-f370324d9799',t.org_acc_id,1 from sm_tenant_account t where not exists (select tt.org_acc_id from sm_orgaccount_role tt where t.org_acc_id=tt.org_acc_id ) and t.tenant_code='MDJ';
/* 把租户菜单都付给地市部门成员(需要去掉系统管理员菜单ID,bb795c0e-6b8b-11e5-f7ca-09b55de95f90) */
insert into sm_role_menu(tenant_menu_id,role_id) select tenant_menu_id, 'ff3f0083-0348-11e5-f7fc-f370324d9799' from sm_tenant_menu where substr(tenant_dn,1,5)='o=MDJ' and tenant_menu_id!='bb795c0e-6b8b-11e5-f7ca-09b55de95f90';
至此,可以找个帐号登录系统试试,出现的问题,下篇文章再分析。