zoukankan      html  css  js  c++  java
  • 最简单的组织树

    同步部门例子代码:
    /**保存部门层级名称**/
    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();
    }
    }

    }


    部门树代码:
    /***
    * 来源分类树列表
    * @return
    */
    @Override
    public List<SourceTypeTreeDto> list() {
    List<SourceTypeTreeDto> all = this.all();
    List<SourceTypeTreeDto> sourceTypeTreeDtoList = new ArrayList<>();
    this.digui(0l, all, sourceTypeTreeDtoList);
    return sourceTypeTreeDtoList;
    }

    private List<SourceTypeTreeDto> all() {
    return this.jpaQueryFactory.selectFrom(Q_SOURCE_TYPE).
    where(
    Q_SOURCE_TYPE.corpId.eq(EmployeeContext.get().getCorpId()),
    Q_SOURCE_TYPE.state.eq(SourceTypeState.NORMAL)
    ).fetch().
    stream().map(res -> BeanPlusUtils.copyPropertiesPlus(res, new SourceTypeTreeDto())).collect(Collectors.toList());
    }

    private void digui(Long parentId, List<SourceTypeTreeDto> all, List<SourceTypeTreeDto> sourceTypeTreeDtoList) {
    /**jdk1.8**/
    List<SourceTypeTreeDto> child = all.stream().filter(x -> x.getParentId().longValue() == parentId.longValue()).collect(Collectors.toList());
    if (child.size() > 0) {
    if (parentId == 0l) {
    for (SourceTypeTreeDto dto : child) {
    dto.setChildren(new ArrayList<>());
    sourceTypeTreeDtoList.add(dto);
    this.digui(dto.getId(), all, sourceTypeTreeDtoList);
    }
    } else {
    SourceTypeTreeDto parent = all.stream().filter(x -> x.getId().longValue() == parentId.longValue()).collect(Collectors.toList()).get(0);
    parent.setChildren(child);
    for (SourceTypeTreeDto c : child) {
    c.setChildren(new ArrayList<>());
    this.digui(c.getId(), all, sourceTypeTreeDtoList);
    }
    }
    }
    }
    }
  • 相关阅读:
    NTC3950-10K温度传感器
    Maven常用命令:
    Linux-IIC驱动(详解)
    sourceinsight4 用设置
    LTDC/DMA2D—液晶显示***
    STM32F429的LTDC和DMA2D ***
    python机器学习sklearn 岭回归(Ridge、RidgeCV)
    random_state 参数
    python3 文件及文件夹路径相关
    机器学习:简单线性回归
  • 原文地址:https://www.cnblogs.com/zxy-come-on/p/14209183.html
Copyright © 2011-2022 走看看