树列表
This commit is contained in:
@ -20,6 +20,7 @@ import com.yj.earth.vo.ModelVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@ -153,20 +154,7 @@ public class ModelLibraryController {
|
||||
@Operation(summary = "模型类型列表")
|
||||
@GetMapping("/modelTypeList")
|
||||
public ApiResponse modelTypeTree() throws SQLException, IllegalAccessException, InstantiationException {
|
||||
String modelPath = getModelLibrary();
|
||||
if (modelPath == null) {
|
||||
return ApiResponse.failure("请先创建或导入模型库");
|
||||
}
|
||||
String sql = """
|
||||
SELECT id, name, parent_id as parentId,
|
||||
tree_index as treeIndex, created_at as createdAt,
|
||||
updated_at as updatedAt FROM model_type ORDER BY tree_index ASC
|
||||
""";
|
||||
// 查询所有模型类型
|
||||
List<ModelType> modelTypes = SQLiteUtil.queryForList(modelPath, sql, null, ModelType.class);
|
||||
// 转换为树形结构
|
||||
List<ModelTypeVo> treeList = buildModelTypeTree(modelTypes);
|
||||
return ApiResponse.success(treeList);
|
||||
return ApiResponse.success(modelTypeList());
|
||||
}
|
||||
|
||||
@Operation(summary = "拖动模型类型树")
|
||||
@ -200,7 +188,6 @@ public class ModelLibraryController {
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "添加模型文件")
|
||||
@PostMapping("/addModelFile")
|
||||
public ApiResponse addModelFile(@RequestParam("files") MultipartFile[] files, @Parameter(description = "模型类型ID") @RequestParam("modelTypeId") String modelTypeId) throws IOException, SQLException {
|
||||
@ -325,6 +312,44 @@ public class ModelLibraryController {
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
|
||||
@Operation(summary = "拖动层级")
|
||||
@PostMapping("/dragModelType")
|
||||
public ApiResponse dragModelType(@RequestBody List<DragModelTypeDto> dragModelTypeDtoList) throws SQLException, IllegalAccessException, InstantiationException {
|
||||
String modelPath = getModelLibrary();
|
||||
if (modelPath == null) {
|
||||
return ApiResponse.failure("请先创建或导入模型库");
|
||||
}
|
||||
// 遍历数据列表
|
||||
for (DragModelTypeDto dragModelTypeDto : dragModelTypeDtoList) {
|
||||
String id = dragModelTypeDto.getId();
|
||||
String parentId = dragModelTypeDto.getParentId();
|
||||
String treeIndex = dragModelTypeDto.getTreeIndex();
|
||||
List<Object> params = new ArrayList<>();
|
||||
params.add(parentId);
|
||||
params.add(treeIndex);
|
||||
params.add(id);
|
||||
SQLiteUtil.executeUpdate(modelPath, "UPDATE model_type SET parent_id = ?, tree_index = ? WHERE id = ?", params);
|
||||
}
|
||||
// 返回树列表
|
||||
return ApiResponse.success(modelTypeList());
|
||||
}
|
||||
|
||||
private List<ModelTypeVo> modelTypeList() throws SQLException, IllegalAccessException, InstantiationException {
|
||||
String modelPath = getModelLibrary();
|
||||
if (modelPath == null) {
|
||||
return null;
|
||||
}
|
||||
String sql = """
|
||||
SELECT id, name, parent_id as parentId,
|
||||
tree_index as treeIndex, created_at as createdAt,
|
||||
updated_at as updatedAt FROM model_type ORDER BY tree_index ASC
|
||||
""";
|
||||
// 查询所有模型类型
|
||||
List<ModelType> modelTypes = SQLiteUtil.queryForList(modelPath, sql, null, ModelType.class);
|
||||
// 转换为树形结构
|
||||
return buildModelTypeTree(modelTypes);
|
||||
}
|
||||
|
||||
private List<ModelTypeVo> buildModelTypeTree(List<ModelType> modelTypes) {
|
||||
List<ModelTypeVo> treeNodes = modelTypes.stream()
|
||||
.map(modelType -> new ModelTypeVo(modelType))
|
||||
|
||||
Reference in New Issue
Block a user