klxedu / blog

2 stars 0 forks source link

用户同步方案 #36

Open songhuiqing88 opened 6 years ago

songhuiqing88 commented 6 years ago

机构及用户同步

机构用户同步过程

songhuiqing88 commented 6 years ago

新增同步管理员(带分级权限)

package org.gtiles.components.organization.syncscope.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.gtiles.components.organization.organization.bean.OrganizationBean;
import org.gtiles.components.organization.organization.service.IOrganizationService;
import org.gtiles.components.organization.scope.bean.OrgScopeBean;
import org.gtiles.components.organization.scope.service.IOrgScopeService;
import org.gtiles.components.organization.syncscope.service.ISyncScopeAdminService;
import org.gtiles.components.securityworkbench.core.syncadmin.SyncRoleAdmin;
import org.gtiles.components.securityworkbench.core.syncadmin.service.ISyncAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service("org.gtiles.components.organization.syncscope.service.impl.SyncScopeAdminServiceImpl")
public class SyncScopeAdminServiceImpl implements ISyncScopeAdminService {

    @Autowired
    private ISyncAdminService syncAdminService;
    @Autowired
    @Qualifier("org.gtiles.components.organization.scope.service.impl.OrgScopeServiceImpl")
    private IOrgScopeService orgScopeService;
    @Autowired
    @Qualifier("org.gtiles.components.organization.organization.service.impl.OrganizationServiceImpl")
    private IOrganizationService organizationService;

    @Override
    public void addSyncAdmin(SyncRoleAdmin syncAdmin, Map<String, String[]> orgScopeMap) {
        String adminId = syncAdmin.getSyncUniqueId();
        List<OrgScopeBean> orgScopeList = new ArrayList<OrgScopeBean>();
        if(orgScopeMap==null) {
            throw new RuntimeException("");
        }
        Set<String> keySet = orgScopeMap.keySet();
        Iterator<String> ite = keySet.iterator();
        while(ite.hasNext()) {
            String orgNumber = ite.next();
            OrganizationBean org = organizationService.findOrganizationByorgNumber(orgNumber);
            if(org!=null && orgScopeMap.containsKey(orgNumber)) {
                for(String dataCode:orgScopeMap.get(orgNumber)) {
                    OrgScopeBean scope = new OrgScopeBean();
                    scope.setAdminId(adminId);
                    scope.setDataCode(dataCode);
                    scope.setOrganizationId(org.getOrganizationId());
                    orgScopeList.add(scope);
                }
            }
        }
        syncAdminService.addSyncAdmin(syncAdmin);
        orgScopeService.addBatchOrgScope(orgScopeList, adminId);
    }

}