获取文件树
This commit is contained in:
parent
9477a107aa
commit
3e80f8843c
@ -1,16 +1,16 @@
|
||||
package com.wxjw.controller.openapi;
|
||||
|
||||
import com.wxjw.common.Result;
|
||||
import com.wxjw.common.BaseResponse;
|
||||
import com.wxjw.common.ResultUtil;
|
||||
import com.wxjw.dal.dao.ExcelInfoMapper;
|
||||
import com.wxjw.dal.pojo.ErrorCode;
|
||||
import com.wxjw.dal.pojo.data.getFileTree.GetFileTreeResultBody;
|
||||
import com.wxjw.service.GetFileTreeService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Controller 获取文件树
|
||||
*
|
||||
@ -24,14 +24,11 @@ public class GetFileTreeController {
|
||||
ExcelInfoMapper excelInfoMapper;
|
||||
|
||||
@PostMapping("/files/tree")
|
||||
public ResponseEntity<Result<Object>> getFileTree(@RequestBody @NotNull HashMap<String, String> resultBody) {
|
||||
String getResult = resultBody.get("action");
|
||||
if ("getfiletree".equals(getResult)) {
|
||||
return ResponseEntity.ok()
|
||||
.body(new GetFileTreeService().getFileTreeService(excelInfoMapper));
|
||||
public ResponseEntity<BaseResponse<Object>> getFileTree(@RequestBody @NotNull GetFileTreeResultBody resultBody) {
|
||||
if ("getfiletree".equals(resultBody.getAction())) {
|
||||
return new GetFileTreeService().getFileTreeService(excelInfoMapper);
|
||||
} else {
|
||||
return ResponseEntity.badRequest()
|
||||
.body(new Result<>(403, null, "参数错误"));
|
||||
return ResultUtil.error(ErrorCode.PARAMETER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
package com.wxjw.dal.pojo.data.getFileTree;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Data 自定义 GetFileTreeController 实体类构造 父亲
|
||||
*
|
||||
* @author 筱锋xiao_lfeng
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class GetFileTreeChildren<T> {
|
||||
private String name;
|
||||
private int id;
|
||||
private T children;
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.wxjw.dal.pojo.data.getFileTree;
|
||||
|
||||
import com.wxjw.dal.dao.ExcelInfoMapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Data 自定义 GetFileTreeController 实体类构造 父亲
|
||||
*
|
||||
* @author 筱锋xiao_lfeng
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class GetFileTreeData {
|
||||
private String name;
|
||||
private boolean open;
|
||||
private ArrayList<Object> children;
|
||||
|
||||
public GetFileTreeData setData(@NotNull ExcelInfoMapper excelInfoMapper, int id) {
|
||||
ArrayList<Object> children = new ArrayList<>();
|
||||
excelInfoMapper.getAllExcelFilesName().forEach(name -> {
|
||||
if (id == name.getType()) {
|
||||
ArrayList<Object> childrenSheet = new ArrayList<>();
|
||||
excelInfoMapper.getAllExcelInfos().forEach(sheet -> {
|
||||
if (name.getFileName() != null && id == sheet.getType() && name.getFileName().equals(sheet.getFileName())) {
|
||||
childrenSheet.add(new Sheet(sheet.getSheetName(), sheet.getId()));
|
||||
}
|
||||
});
|
||||
children.add(new Children<>(name.getFileName(), name.getId(), childrenSheet));
|
||||
}
|
||||
});
|
||||
this.children = children;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
class Children<T> {
|
||||
private String name;
|
||||
private int id;
|
||||
private T children;
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
class Sheet {
|
||||
private String name;
|
||||
private int id;
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.wxjw.dal.pojo.data.getFileTree;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Data 自定义 GetFileTreeController 实体类构造 父亲
|
||||
*
|
||||
* @author 筱锋xiao_lfeng
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class GetFileTreeFather<T> {
|
||||
private String name;
|
||||
private boolean open;
|
||||
private T children;
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.wxjw.dal.pojo.data.getFileTree;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* GetFileTreeResultBody
|
||||
*
|
||||
* @author 筱锋xiao_lfeng
|
||||
*/
|
||||
@Getter
|
||||
public class GetFileTreeResultBody {
|
||||
private String action;
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.wxjw.dal.pojo.data.getFileTree;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Data 自定义 GetFileTreeController 实体类构造 父亲
|
||||
*
|
||||
* @author 筱锋xiao_lfeng
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class GetFileTreeSheet {
|
||||
private String name;
|
||||
private int id;
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
package com.wxjw.service;
|
||||
|
||||
import com.wxjw.common.Result;
|
||||
import com.wxjw.common.BaseResponse;
|
||||
import com.wxjw.common.ResultUtil;
|
||||
import com.wxjw.dal.dao.ExcelInfoMapper;
|
||||
import com.wxjw.dal.pojo.data.getFileTree.GetFileTreeChildren;
|
||||
import com.wxjw.dal.pojo.data.getFileTree.GetFileTreeFather;
|
||||
import com.wxjw.dal.pojo.data.getFileTree.GetFileTreeSheet;
|
||||
import com.wxjw.dal.pojo.ErrorCode;
|
||||
import com.wxjw.dal.pojo.data.getFileTree.GetFileTreeData;
|
||||
import com.wxjw.dal.pojo.entity.ExcelInfoEntity;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -20,39 +20,22 @@ import java.util.ArrayList;
|
||||
@Service
|
||||
public class GetFileTreeService {
|
||||
|
||||
public Result<Object> getFileTreeService(ExcelInfoMapper excelInfoMapper) {
|
||||
public ResponseEntity<BaseResponse<Object>> getFileTreeService(ExcelInfoMapper excelInfoMapper) {
|
||||
// 从数据库读取数据
|
||||
ArrayList<ExcelInfoEntity> allExcelFileName = (ArrayList<ExcelInfoEntity>) excelInfoMapper.getAllExcelFilesName();
|
||||
// 检查所得数据是否为空
|
||||
if (!allExcelFileName.isEmpty() && !excelInfoMapper.getAllExcelInfos().isEmpty()) {
|
||||
ArrayList<Object> data = new ArrayList<>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
// 循环创建
|
||||
ArrayList<Object> fatherList = new ArrayList<>();
|
||||
for (ExcelInfoEntity excelInfoEntityFather : allExcelFileName) {
|
||||
if (excelInfoEntityFather.getType() == i) {
|
||||
ArrayList<Object> childrenList = new ArrayList<>();
|
||||
for (ExcelInfoEntity excelInfoEntityChildren : excelInfoMapper.getAllExcelInfos()) {
|
||||
GetFileTreeSheet getFileTreeSheet;
|
||||
getFileTreeSheet = new GetFileTreeSheet(excelInfoEntityChildren.getSheetName(), excelInfoEntityChildren.getId());
|
||||
childrenList.add(getFileTreeSheet);
|
||||
}
|
||||
|
||||
|
||||
GetFileTreeChildren<Object> getFileTreeChildren;
|
||||
getFileTreeChildren = new GetFileTreeChildren<>(excelInfoEntityFather.getFileName(), excelInfoEntityFather.getId(), childrenList);
|
||||
fatherList.add(getFileTreeChildren);
|
||||
}
|
||||
}
|
||||
switch (i) {
|
||||
case 0 -> data.add(new GetFileTreeFather<>("公共库", true, fatherList));
|
||||
case 1 -> data.add(new GetFileTreeFather<>("高级库", true, fatherList));
|
||||
case 2 -> data.add(new GetFileTreeFather<>("个人库", true, fatherList));
|
||||
case 0 -> data.add(new GetFileTreeData("公共库", true, null).setData(excelInfoMapper, i));
|
||||
case 1 -> data.add(new GetFileTreeData("高级库", true, null).setData(excelInfoMapper, i));
|
||||
case 2 -> data.add(new GetFileTreeData("个人库", true, null).setData(excelInfoMapper, i));
|
||||
}
|
||||
}
|
||||
return new Result<>(200, data, "输出成功");
|
||||
return ResultUtil.success(data, "输出成功");
|
||||
} else {
|
||||
return new Result<>(403, null, "数据为空");
|
||||
return ResultUtil.error(ErrorCode.DATA_IS_EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user