/**保存部门层级名称**/ public void saveDeptPathName(List<Department> departmentLists){ if(!StringUtils.isEmpty(departmentLists)&&departmentLists.size()>0){ for (Department depts:departmentLists) { ArrayList<String> pathIds =new ArrayList<>(); ArrayList<String> pathNames =new ArrayList<>(); getDeptNames(departmentLists,depts.getDingtalkId(),pathIds,pathNames); Collections.reverse(pathNames); String pathName = org.apache.commons.lang3.StringUtils.join(pathNames, "-"); Collections.reverse(pathIds); String pathids = org.apache.commons.lang3.StringUtils.join(pathIds, ","); jpaQueryFactory.update(DEPARTMENT) .set(DEPARTMENT.pathName,pathName) .set(DEPARTMENT.path,pathids) .where(DEPARTMENT.id.eq(depts.getId())) .execute(); } } } /**获取部门名称**/ public void getDeptNames(List<Department> departmentLists,Long dingtalkId,ArrayList<String> pathIds,ArrayList<String> pathNames){ Department department = departmentLists.stream().filter(x -> x.getDingtalkId().longValue() == dingtalkId.longValue()) .collect(Collectors.toList()).get(0); if(!StringUtils.isEmpty(department)){ pathIds.add(department.getId() + ""); pathNames.add(department.getName()); if(!StringUtils.isEmpty(department.getDingtalkParentid())){ getDeptNames(departmentLists, department.getDingtalkParentid(),pathIds,pathNames); } } }
/**保存部门父级id**/ public void saveDeptPid(List<Department> departmentLists){ if(!StringUtils.isEmpty(departmentLists)&&departmentLists.size()>0){ for (Department dep:departmentLists) { long pid = 0; if (!StringUtils.isEmpty(dep.getDingtalkParentid())) { Department department = departmentLists.stream() .filter(x -> x.getDingtalkId().longValue() == dep.getDingtalkParentid().longValue()) .collect(Collectors.toList()).get(0); if (!StringUtils.isEmpty(department)) { pid = department.getId(); } } jpaQueryFactory.update(DEPARTMENT) .set(DEPARTMENT.parentId,pid) .where(DEPARTMENT.id.eq(dep.getId())) .execute(); } }
}
|