完成文件树的搭建与数据库的搭建,以及基本构造

This commit is contained in:
筱锋xiao_lfeng 2023-08-11 18:37:35 +08:00
parent ad57426bef
commit 99ff3d8fde
11 changed files with 267 additions and 3 deletions

25
pom.xml
View File

@ -21,6 +21,20 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
@ -28,10 +42,15 @@
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.jetbrains</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>annotations</artifactId>
<scope>test</scope> <version>23.0.0</version>
<scope>compile</scope>
</dependency> </dependency>
<!--<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>-->
</dependencies> </dependencies>
<build> <build>

View File

@ -0,0 +1,18 @@
package com.wxjw.common;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* @author 筱锋xiao_lfeng
*/
@Data
@AllArgsConstructor
public class Result<T> {
private int code;
private T data;
private String msg;
public Result() {
}
}

View File

@ -0,0 +1,37 @@
package com.wxjw.controller.openapi;
import com.wxjw.common.Result;
import com.wxjw.dal.dao.ExcelInfoMapper;
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 获取文件树
*
* @author 筱锋xiao_lfeng
*/
@RestController
@RequestMapping("/openapi/")
public class GetFileTreeController {
@Resource
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));
} else {
return ResponseEntity.badRequest()
.body(new Result<>(403, null, "参数错误"));
}
}
}

View File

@ -0,0 +1,48 @@
package com.wxjw.dal.dao;
import com.wxjw.dal.pojo.entity.ExcelInfoEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.context.annotation.ComponentScan;
import java.util.List;
/**
* Mapper 数据库相关 接口
*
* @author 筱锋xiao_lfeng
*/
@Mapper
@ComponentScan
public interface ExcelInfoMapper {
/**
* @return 返回全部的数据不加以修饰
*/
@Select("SELECT * FROM excel_file_handling.excel_info")
List<ExcelInfoEntity> getAllExcelInfos();
/**
* @return 返回全部的文件名称去重
*/
@Select("SELECT t1.* FROM excel_file_handling.excel_info t1 LEFT JOIN excel_file_handling.excel_info t2 ON t1.file_name = t2.file_name AND t1.id < t2.id WHERE t2.id")
List<ExcelInfoEntity> getAllExcelFilesName();
/**
* @param id 主键
* @param parentId 父级 ID
* @param fileName 文件名称
* @param sheetName sheet 名称
* @param tableName 表名称
* @param type 类型
* @param createBy 创建者
* @param createTime 创建时间
* @param updateBy 更新者
* @param updateTime 更新时间
* @return 是否插入成功
*/
@Insert("INSERT INTO excel_file_handling.excel_info (`id`,`parent_id`,`file_name`,`sheet_name`,`table_name`,`type`,`create_by`,`create_time`,`update_by`,`update_time`) VALUES (#{id}, #{parentId},#{fileName},#{sheetName},#{tableName},#{type},#{createBy}, #{createTime},#{updateBy},#{updateTime})")
boolean insertExcelInfo(int id, int parentId, String fileName, String sheetName, String tableName, int type, String createBy, String createTime, String updateBy, String updateTime);
}

View File

@ -0,0 +1,17 @@
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;
}

View File

@ -0,0 +1,17 @@
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;
}

View File

@ -0,0 +1,16 @@
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;
}

View File

@ -0,0 +1,23 @@
package com.wxjw.dal.pojo.entity;
import lombok.Data;
import org.springframework.lang.Nullable;
/**
* Entity Excel数据表实体类
*
* @author 筱锋xiao_lfeng
*/
@Data
public class ExcelInfoEntity {
private int id;
private int parentId;
@Nullable private String fileName;
@Nullable private String sheetName;
@Nullable private String tableName;
private int type;
@Nullable private String createBy;
@Nullable private String createTime;
@Nullable private String updateBy;
@Nullable private String updateTime;
}

View File

@ -0,0 +1,58 @@
package com.wxjw.service;
import com.wxjw.common.Result;
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.entity.ExcelInfoEntity;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
/**
* Service GetFileTree逻辑服务处理
*
* @author 筱锋xiao_lfeng
*/
@Service
public class GetFileTreeService {
public Result<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));
}
}
return new Result<>(200, data, "输出成功");
} else {
return new Result<>(403, null, "数据为空");
}
}
}

View File

@ -0,0 +1,11 @@
spring:
datasource:
url: jdbc:mysql://localhost:3306
username: excel_file_handling
password: 123456789
driver-class-name: com.mysql.cj.jdbc.Driver
mvc:
static-path-pattern: /static/**
mybatis:
configuration:
map-underscore-to-camel-case: true