Search in sources :

Example 1 with Organizations

use of org.maxkey.entity.Organizations in project MaxKey by dromara.

the class OrganizationsController method buildOrganizationsFromSheetRow.

public Organizations buildOrganizationsFromSheetRow(Row row) {
    Organizations organization = new Organizations();
    // 上级编码
    organization.setParentId(ExcelUtils.getValue(row, 0));
    // 上级名称
    organization.setParentName(ExcelUtils.getValue(row, 1));
    // 组织编码
    organization.setId(ExcelUtils.getValue(row, 2));
    // 组织名称
    organization.setName(ExcelUtils.getValue(row, 3));
    // 组织全称
    organization.setFullName(ExcelUtils.getValue(row, 4));
    // 编码路径
    organization.setCodePath(ExcelUtils.getValue(row, 5));
    // 名称路径
    organization.setNamePath(ExcelUtils.getValue(row, 6));
    // 组织类型
    organization.setType(ExcelUtils.getValue(row, 7));
    // 所属分支机构
    organization.setDivision(ExcelUtils.getValue(row, 8));
    // 级别
    String level = ExcelUtils.getValue(row, 9);
    organization.setLevel(level.equals("") ? 1 : Integer.parseInt(level));
    // 排序
    String sortIndex = ExcelUtils.getValue(row, 10);
    organization.setSortIndex(sortIndex.equals("") ? 1 : Integer.parseInt(sortIndex));
    // 联系人
    organization.setContact(ExcelUtils.getValue(row, 11));
    // 联系电话
    organization.setPhone(ExcelUtils.getValue(row, 12));
    // 邮箱
    organization.setEmail(ExcelUtils.getValue(row, 13));
    // 传真
    organization.setFax(ExcelUtils.getValue(row, 14));
    // 工作-国家
    organization.setCountry(ExcelUtils.getValue(row, 15));
    // 工作-省
    organization.setRegion(ExcelUtils.getValue(row, 16));
    // 工作-城市
    organization.setLocality(ExcelUtils.getValue(row, 17));
    // 工作-地址
    organization.setLocality(ExcelUtils.getValue(row, 18));
    // 邮编
    organization.setPostalCode(ExcelUtils.getValue(row, 19));
    // 详细描述
    organization.setDescription(ExcelUtils.getValue(row, 20));
    organization.setStatus(1);
    organization.setInstId(WebContext.getUserInfo().getInstId());
    return organization;
}
Also used : Organizations(org.maxkey.entity.Organizations)

Example 2 with Organizations

use of org.maxkey.entity.Organizations in project MaxKey by dromara.

the class OrganizationsController method importing.

@RequestMapping(value = "/import")
public ModelAndView importing(@ModelAttribute("excelImportFile") ExcelImport excelImportFile) {
    if (excelImportFile.isExcelNotEmpty()) {
        try {
            List<Organizations> orgsList = Lists.newArrayList();
            Workbook workbook = excelImportFile.biuldWorkbook();
            int sheetSize = workbook.getNumberOfSheets();
            // 遍历sheet页
            for (int i = 0; i < sheetSize; i++) {
                Sheet sheet = workbook.getSheetAt(i);
                int rowSize = sheet.getLastRowNum() + 1;
                for (int j = 1; j < rowSize; j++) {
                    // 遍历行
                    Row row = sheet.getRow(j);
                    if (row == null || j < 3) {
                        // 略过空行和前3行
                        continue;
                    } else {
                        // 其他行是数据行
                        orgsList.add(buildOrganizationsFromSheetRow(row));
                    }
                }
            }
            // 数据去重
            if (!CollectionUtils.isEmpty(orgsList)) {
                orgsList = orgsList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getId()))), ArrayList::new));
                if (organizationsService.insertBatch(orgsList)) {
                    new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS), null, MessageType.success, OperateType.add, MessageScope.DB);
                } else {
                    new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR), MessageType.error);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            excelImportFile.closeWorkbook();
        }
    } else {
        new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR), MessageType.error);
    }
    return new ModelAndView("/orgs/orgsImport");
}
Also used : TreeNode(org.maxkey.web.component.TreeNode) PathVariable(org.springframework.web.bind.annotation.PathVariable) MessageType(org.maxkey.web.message.MessageType) OperateType(org.maxkey.web.message.OperateType) RequestParam(org.springframework.web.bind.annotation.RequestParam) MessageScope(org.maxkey.web.message.MessageScope) ExcelUtils(org.maxkey.util.ExcelUtils) LoggerFactory(org.slf4j.LoggerFactory) ConstsOperateMessage(org.maxkey.constants.ConstsOperateMessage) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) Controller(org.springframework.stereotype.Controller) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Message(org.maxkey.web.message.Message) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) Lists(com.google.common.collect.Lists) Organizations(org.maxkey.entity.Organizations) Sheet(org.apache.poi.ss.usermodel.Sheet) Logger(org.slf4j.Logger) OrganizationsService(org.maxkey.persistence.service.OrganizationsService) IOException(java.io.IOException) TreeNodeList(org.maxkey.web.component.TreeNodeList) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) ModelAndView(org.springframework.web.servlet.ModelAndView) List(java.util.List) Workbook(org.apache.poi.ss.usermodel.Workbook) JpaPageResults(org.apache.mybatis.jpa.persistence.JpaPageResults) WebContext(org.maxkey.web.WebContext) CollectionUtils(org.springframework.util.CollectionUtils) Row(org.apache.poi.ss.usermodel.Row) Comparator(java.util.Comparator) ExcelImport(org.maxkey.entity.ExcelImport) ConstsOperateMessage(org.maxkey.constants.ConstsOperateMessage) Message(org.maxkey.web.message.Message) TreeSet(java.util.TreeSet) Organizations(org.maxkey.entity.Organizations) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) Row(org.apache.poi.ss.usermodel.Row) IOException(java.io.IOException) Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Organizations

use of org.maxkey.entity.Organizations in project MaxKey by dromara.

the class WorkweixinOrganizationService method buildOrganization.

public Organizations buildOrganization(WorkWeixinDepts dept) {
    // Parent
    SynchroRelated synchroRelatedParent = synchroRelatedService.findByOriginId(this.synchronizer, dept.getParentid() + "", Organizations.CLASS_TYPE);
    Organizations org = new Organizations();
    org.setName(dept.getName());
    org.setCode(dept.getId() + "");
    org.setParentId(synchroRelatedParent.getObjectId());
    org.setParentName(synchroRelatedParent.getObjectName());
    org.setSortIndex(dept.getOrder());
    org.setInstId(this.synchronizer.getInstId());
    org.setStatus(ConstsStatus.ACTIVE);
    org.setDescription("WorkWeixin");
    return org;
}
Also used : SynchroRelated(org.maxkey.entity.SynchroRelated) Organizations(org.maxkey.entity.Organizations)

Example 4 with Organizations

use of org.maxkey.entity.Organizations in project MaxKey by dromara.

the class WorkweixinOrganizationService method sync.

public void sync() {
    _logger.info("Sync Workweixin Organizations ...");
    try {
        WorkWeixinDeptsResponse rsp = requestDepartmentList(access_token);
        for (WorkWeixinDepts dept : rsp.getDepartment()) {
            _logger.debug("dept : " + dept.getId() + " " + dept.getName() + " " + dept.getParentid());
            // root
            if (dept.getId() == ROOT_DEPT_ID) {
                Organizations rootOrganization = organizationsService.get(Organizations.ROOT_ORG_ID);
                SynchroRelated rootSynchroRelated = buildSynchroRelated(rootOrganization, dept);
                synchroRelatedService.updateSynchroRelated(this.synchronizer, rootSynchroRelated, Organizations.CLASS_TYPE);
            } else {
                // synchro Related
                SynchroRelated synchroRelated = synchroRelatedService.findByOriginId(this.synchronizer, dept.getId() + "", Organizations.CLASS_TYPE);
                Organizations organization = buildOrganization(dept);
                if (synchroRelated == null) {
                    organization.setId(organization.generateId());
                    organizationsService.insert(organization);
                    _logger.debug("Organizations : " + organization);
                    synchroRelated = buildSynchroRelated(organization, dept);
                } else {
                    organization.setId(synchroRelated.getObjectId());
                    organizationsService.update(organization);
                }
                synchroRelatedService.updateSynchroRelated(this.synchronizer, synchroRelated, Organizations.CLASS_TYPE);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : WorkWeixinDeptsResponse(org.maxkey.synchronizer.workweixin.entity.WorkWeixinDeptsResponse) Organizations(org.maxkey.entity.Organizations) SynchroRelated(org.maxkey.entity.SynchroRelated) WorkWeixinDepts(org.maxkey.synchronizer.workweixin.entity.WorkWeixinDepts)

Example 5 with Organizations

use of org.maxkey.entity.Organizations in project MaxKey by dromara.

the class ActiveDirectoryOrganizationService method buildOrganization.

public Organizations buildOrganization(HashMap<String, Attribute> attributeMap, String name, String nameInNamespace) {
    try {
        Organizations org = new Organizations();
        org.setLdapDn(nameInNamespace);
        String[] namePaths = name.replaceAll(",OU=", "/").replaceAll("OU=", "/").split("/");
        String namePah = "/" + rootOrganization.getName();
        for (int i = namePaths.length - 1; i >= 0; i--) {
            namePah = namePah + "/" + namePaths[i];
        }
        namePah = namePah.substring(0, namePah.length() - 1);
        org.setId(org.generateId());
        org.setCode(org.getId());
        org.setNamePath(namePah);
        org.setLevel(namePaths.length);
        org.setName(LdapUtils.getAttributeStringValue(OrganizationalUnit.OU, attributeMap));
        org.setCountry(LdapUtils.getAttributeStringValue(OrganizationalUnit.CO, attributeMap));
        org.setRegion(LdapUtils.getAttributeStringValue(OrganizationalUnit.ST, attributeMap));
        org.setLocality(LdapUtils.getAttributeStringValue(OrganizationalUnit.L, attributeMap));
        org.setStreet(LdapUtils.getAttributeStringValue(OrganizationalUnit.STREET, attributeMap));
        org.setPostalCode(LdapUtils.getAttributeStringValue(OrganizationalUnit.POSTALCODE, attributeMap));
        org.setDescription(LdapUtils.getAttributeStringValue(OrganizationalUnit.DESCRIPTION, attributeMap));
        org.setInstId(this.synchronizer.getInstId());
        org.setStatus(ConstsStatus.ACTIVE);
        _logger.debug("Organization " + org);
        return org;
    } catch (NamingException e) {
        _logger.error("NamingException ", e);
    }
    return null;
}
Also used : Organizations(org.maxkey.entity.Organizations) NamingException(javax.naming.NamingException)

Aggregations

Organizations (org.maxkey.entity.Organizations)29 SynchroRelated (org.maxkey.entity.SynchroRelated)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 NamingException (javax.naming.NamingException)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 HistorySynchronizer (org.maxkey.entity.HistorySynchronizer)4 NoSuchElementException (java.util.NoSuchElementException)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 Attribute (javax.naming.directory.Attribute)2 SearchControls (javax.naming.directory.SearchControls)2 SearchResult (javax.naming.directory.SearchResult)2 UserInfo (org.maxkey.entity.UserInfo)2 ScimOrganization (org.maxkey.identity.scim.resources.ScimOrganization)2 TreeNode (org.maxkey.web.component.TreeNode)2 TreeNodeList (org.maxkey.web.component.TreeNodeList)2 MappingJacksonValue (org.springframework.http.converter.json.MappingJacksonValue)2 OapiV2DepartmentGetResponse (com.dingtalk.api.response.OapiV2DepartmentGetResponse)1 OapiV2DepartmentListsubResponse (com.dingtalk.api.response.OapiV2DepartmentListsubResponse)1 DeptBaseResponse (com.dingtalk.api.response.OapiV2DepartmentListsubResponse.DeptBaseResponse)1