修改树形结构

master
lwj 2024-08-26 20:30:07 +08:00
parent 3df7205054
commit c18f376e2a
3 changed files with 76 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.domain.rep.TableInfoRep;
import com.muyu.domain.rep.TableInfoResp;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -64,4 +65,15 @@ public class TableInfo extends BaseEntity {
.build();
}
public static TableInfoResp toTableInfoResp(TableInfo tableInfo) {
return TableInfoResp.builder()
.id(tableInfo.id)
.tableName(tableInfo.tableName)
.tableRemark(tableInfo.tableRemark)
.isCenter(tableInfo.center)
.dataNum(tableInfo.dataNum)
.build();
}
}

View File

@ -0,0 +1,41 @@
package com.muyu.domain.rep;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class TableInfoResp {
/**
* id
*/
private Long id;
/**
* /
*/
private String tableName;
/**
*
*/
private String tableRemark;
/** 数据量 */
private Long dataNum;
/** 是否核心 'Y'是 'N'不是 */
private String isCenter;
/**
*
*/
private List<TableInfoResp> children;
}

View File

@ -1,11 +1,13 @@
package com.muyu.cloud.etl.controller;
import com.dtflys.forest.annotation.NotNull;
import com.muyu.cloud.etl.service.StructureService;
import com.muyu.cloud.etl.service.TableInfoService;
import com.muyu.common.core.domain.Result;
import com.muyu.domain.Structure;
import com.muyu.domain.TableInfo;
import com.muyu.domain.rep.TableInfoRep;
import com.muyu.domain.rep.TableInfoResp;
import com.muyu.domain.rep.TableInfoTreeRep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -44,4 +46,25 @@ public class TableInfoController {
return Result.success(tableInfoTreeReps);
}
@GetMapping("/findTableInfoList")
public Result findByTableName() {
List<TableInfo> list = tableInfoService.list();
List<TableInfoResp> respList = list.stream().filter(tableInfo -> tableInfo.getParentId()==0).map(tableInfo -> {
TableInfoResp tableInfoResp = TableInfo.toTableInfoResp(tableInfo);
tableInfoResp.setChildren(getChildren(tableInfo, list));
return tableInfoResp;
}).toList();
return Result.success(respList);
}
@NotNull
private static List<TableInfoResp> getChildren(TableInfo tableInfo, List<TableInfo> list) {
return list.stream().filter(tableInfo1 -> tableInfo1.getParentId().equals(tableInfo.getId())).map(
tableInfo2 -> TableInfo.toTableInfoResp(tableInfo2)
).toList();
}
}