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;
}
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");
}
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;
}
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();
}
}
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;
}
Aggregations