多表形成树形结构

多表形成树形结构:

package com.js.archive.assistant.domain.vo;

import com.js.core.domain.vo.BaseVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
 * 

* VO *

* * @author js * @date 2024-1-18 * @since JDK 1.8 */
@ApiModel(value="库位号选择对象", description="") @EqualsAndHashCode(callSuper = true) @Data public class ArchiveLocationNumVO extends BaseVO { private static final long serialVersionUID = 1L; @ApiModelProperty(value = "id") private Long dataId; @ApiModelProperty(value = "编号") private String code; @ApiModelProperty(value = "名称") private String name; @ApiModelProperty(value = "父id") private Long parentId; @ApiModelProperty(value = "节点等级") private Integer level; @ApiModelProperty(value = "子节点") private List<ArchiveLocationNumVO> children; }
/**
     * 获取登录者全宗下的智慧库房
     *
     * @return List
     */
    public List<ArchiveLocationNumVO> getAllFloorInfo() {
        List<ArchiveLocationNumVO> archiveLocationNumVOList = new ArrayList<>();
        
//---------------------------------获取每张表的数据------------------------------------------------        
        Long archiveCompanyId = ThreadLocalUtil.getArchiveCompanyId();

        List<KfWarehouse> kfWarehouseList = kfWarehouseService.lambdaQuery()
                .eq(BaseEntity::getArchiveCompanyId, archiveCompanyId).list();

        List<KfArea> bizArchiveCabinetList = kfAreaService.lambdaQuery()
                .eq(BaseEntity::getArchiveCompanyId, archiveCompanyId).list();

        List<KfColumn> bizArchiveFloorList = kfColumnService.lambdaQuery()
                .eq(BaseEntity::getArchiveCompanyId, archiveCompanyId).list();

        List<KfLayerSection> kfLayerSectionList = kfLayerSectionService.lambdaQuery()
                .eq(BaseEntity::getArchiveCompanyId, archiveCompanyId).list();
//----------------------------------------------------------------------------------------------------

        //开始从最外层开始循环查询
        
        if (CollectionUtil.isNotEmpty(kfWarehouseList)) {
            kfWarehouseList.forEach(bizArchiveRoom -> {//库房1级
                List<ArchiveLocationNumVO> cabinetArchiveLocationNumList = new ArrayList<>();
                ArchiveLocationNumVO archiveLocationNumVO = new ArchiveLocationNumVO();
                archiveLocationNumVO.setParentId(0L);
                archiveLocationNumVO.setLevel(1);
                archiveLocationNumVO.setDataId(bizArchiveRoom.getId());
                archiveLocationNumVO.setCode(String.valueOf(bizArchiveRoom.getKfSerialno()));
                archiveLocationNumVO.setName(bizArchiveRoom.getKfName());

                if (CollectionUtil.isNotEmpty(bizArchiveCabinetList)) {//库区2级
                    bizArchiveCabinetList.forEach(bizArchiveCabinet -> {
                        if (bizArchiveRoom.getId() == bizArchiveCabinet.getWarehouseId()) {
                            List<ArchiveLocationNumVO> archiveFloorList = new ArrayList<>();
                            ArchiveLocationNumVO cabinetArchiveLocationNumVO = new ArchiveLocationNumVO();
                            cabinetArchiveLocationNumVO.setParentId(bizArchiveCabinet.getWarehouseId());
                            cabinetArchiveLocationNumVO.setLevel(2);
                            cabinetArchiveLocationNumVO.setDataId(bizArchiveCabinet.getId());
                            cabinetArchiveLocationNumVO.setCode(bizArchiveCabinet.getKqCode());
                            cabinetArchiveLocationNumVO.setName(bizArchiveCabinet.getKqName());

                            if (CollectionUtil.isNotEmpty(bizArchiveFloorList)) {//库列3级
                                bizArchiveFloorList.forEach(bizArchiveFloor -> {
                                    if (bizArchiveCabinet.getId() == bizArchiveFloor.getAreaId()) {
                                        List<ArchiveLocationNumVO> kfColumnList = new ArrayList<>();
                                        ArchiveLocationNumVO kfColumnNumVO = new ArchiveLocationNumVO();
                                        kfColumnNumVO.setParentId(bizArchiveFloor.getAreaId());
                                        kfColumnNumVO.setLevel(3);
                                        kfColumnNumVO.setDataId(bizArchiveFloor.getId());
                                        kfColumnNumVO.setCode(String.valueOf(bizArchiveFloor.getKlSerialno()));
                                        kfColumnNumVO.setName(bizArchiveFloor.getKlName());

                                        if (CollectionUtil.isNotEmpty(kfLayerSectionList)) {//层节4级

                                            kfLayerSectionList.forEach(kfLayerSection -> {
                                                if (bizArchiveFloor.getId() == kfLayerSection.getColumnId()) {
                                                    ArchiveLocationNumVO floorArchiveLocationNumVO = new ArchiveLocationNumVO();
                                                    floorArchiveLocationNumVO.setParentId(kfLayerSection.getColumnId());
                                                    floorArchiveLocationNumVO.setLevel(4);
                                                    floorArchiveLocationNumVO.setDataId(kfLayerSection.getId());
                                                    floorArchiveLocationNumVO.setName(kfLayerSection.getPositionTrans());
                                                    kfColumnList.add(floorArchiveLocationNumVO);
                                                }
                                            });
                                        }
                                        kfColumnNumVO.setChildren(kfColumnList);
                                        archiveFloorList.add(kfColumnNumVO);
                                    }
                                });

                            }

                            cabinetArchiveLocationNumVO.setChildren(archiveFloorList);
                            cabinetArchiveLocationNumList.add(cabinetArchiveLocationNumVO);
                        }
                    });
                }


                archiveLocationNumVO.setChildren(cabinetArchiveLocationNumList);
                archiveLocationNumVOList.add(archiveLocationNumVO);
            });
        }


        return archiveLocationNumVOList;
    }
{"code":0,"msg":null,"data":[{"id":null,"dataId":"1","code":"1","name":"1号库房1","parentId":"0","level":1,"children":[{"id":null,"dataId":"1","code":"1-1","name":"1库区","parentId":"1","level":2,"children":[{"id":null,"dataId":"1","code":"1","name":"1列","parentId":"1","level":3,"children":[{"id":null,"dataId":"1","code":null,"name":"1库区1列左面2节号2层号","parentId":"1","level":4,"children":null}]},{"id":null,"dataId":"2","code":"2","name":"2列","parentId":"1","level":3,"children":[{"id":null,"dataId":"2","code":null,"name":"2库区2列右面1节号2层号","parentId":"2","level":4,"children":null}]},{"id":null,"dataId":"3","code":"3","name":"3列","parentId":"1","level":3,"children":[]}]},{"id":null,"dataId":"2","code":"1-2","name":"2库区","parentId":"1","level":2,"children":[{"id":null,"dataId":"4","code":"4","name":"4列","parentId":"2","level":3,"children":[]},{"id":null,"dataId":"5","code":"5","name":"5列","parentId":"2","level":3,"children":[]}]},{"id":null,"dataId":"3","code":"1-21","name":"1-21","parentId":"1","level":2,"children":[{"id":null,"dataId":"6","code":"1","name":"1列","parentId":"3","level":3,"children":[]}]},{"id":null,"dataId":"4","code":"1-3","name":"3库区","parentId":"1","level":2,"children":[]},{"id":null,"dataId":"5","code":"1-4","name":"1-4","parentId":"1","level":2,"children":[]},{"id":null,"dataId":"6","code":"1-5","name":"1-5","parentId":"1","level":2,"children":[]},{"id":null,"dataId":"7","code":"1-6","name":"6库区","parentId":"1","level":2,"children":[]}]},{"id":null,"dataId":"2","code":"2","name":"2号库房11","parentId":"0","level":1,"children":[]},{"id":null,"dataId":"3","code":"3","name":"3号库房","parentId":"0","level":1,"children":[]},{"id":null,"dataId":"4","code":"4","name":"4号库房","parentId":"0","level":1,"children":[]},{"id":null,"dataId":"5","code":"5","name":"5号库房","parentId":"0","level":1,"children":[]},{"id":null,"dataId":"6","code":"6","name":"6号库房修该","parentId":"0","level":1,"children":[]},{"id":null,"dataId":"7","code":"7","name":"7号库房","parentId":"0","level":1,"children":[]}]}

你可能感兴趣的:(Java基础,java)