树列表

This commit is contained in:
ZZX9599
2025-09-28 15:10:29 +08:00
parent c51652000c
commit dea2dbd508
8 changed files with 201 additions and 79 deletions

View File

@ -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))

View File

@ -18,6 +18,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
@ -72,34 +73,7 @@ public class SourceController {
@Operation(summary = "新增模型资源")
@PostMapping("/addModelSource")
public ApiResponse addModelSource(@RequestBody AddModelSourceDto addModelSourceDto) {
// 获取资源绝对路径
String sourcePath = addModelSourceDto.getSourcePath();
// 获取资源名称
String sourceName = FileUtil.mainName(sourcePath);
// 校验是否通过
String message = sourceService.checkIsPass(addModelSourceDto.getParentId(), sourceName);
if (message != null) {
return ApiResponse.failure(message);
}
// 调用SDK加载资源
String sourceId = sourceService.addAndGetSourceId(sourcePath);
// 获取文件路径并处理详情
String detail = sourceService.getDetail(sourcePath, sourceId);
// 构建并保存资源对象
Source source = new Source();
source.setId(addModelSourceDto.getId());
source.setSourcePath(sourcePath);
source.setSourceName(sourceName);
source.setParentId(addModelSourceDto.getParentId());
source.setTreeIndex(addModelSourceDto.getTreeIndex());
source.setParams(JsonUtil.mapToJson(addModelSourceDto.getParams()));
source.setDetail(detail);
source.setSourceType(MapUtil.getString(MapUtil.jsonToMap(detail), "fileType"));
source.setIsShow(SHOW);
sourceService.save(source);
// 添加资源到该用户的角色下
roleSourceService.addRoleSource(userService.getById(StpUtil.getLoginIdAsString()).getRoleId(), source.getId());
return ApiResponse.success(source);
return ApiResponse.success(sourceService.addModelSource(addModelSourceDto));
}
@Operation(summary = "新增其他资源")
@ -227,6 +201,20 @@ public class SourceController {
return ApiResponse.success(null);
}
@Operation(summary = "更新显示隐藏")
@PostMapping("/updateShowHide")
public ApiResponse updateShowHide(@RequestBody List<UpdateShowHideDto> updateShowHideDtoList) {
for (UpdateShowHideDto updateShowHideDto : updateShowHideDtoList) {
LambdaQueryWrapper<Source> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Source::getId, updateShowHideDto.getId());
Source source = sourceService.getOne(queryWrapper);
source.setIsShow(updateShowHideDto.getIsShow());
sourceService.updateById(source);
}
return ApiResponse.success(null);
}
@PostMapping("/uploadLocationImage")
@Operation(summary = "新增定位图片")
public ApiResponse uploadLocationImage(@RequestParam("ids") @Parameter(description = "上传定位图片ID列表") List<String> ids,

View File

@ -109,7 +109,6 @@ public class UserController {
return ApiResponse.success(userPage);
}
@CheckAuth
@Operation(summary = "设置角色")
@PostMapping("/userBindOrUnBindRole")
@RoleAccess(roleNames = "管理员")

View File

@ -3,6 +3,7 @@ package com.yj.earth.business.service;
import com.yj.earth.business.domain.Source;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yj.earth.common.util.ApiResponse;
import com.yj.earth.dto.source.AddModelSourceDto;
import java.util.List;
@ -22,4 +23,6 @@ public interface SourceService extends IService<Source> {
List<Source> getSourceListByUserId(String userId);
String checkIsPass(String parentId, String sourceName);
Source addModelSource(AddModelSourceDto addModelSourceDto);
}

View File

@ -1,5 +1,6 @@
package com.yj.earth.business.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.io.FileUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -15,6 +16,9 @@ import com.yj.earth.business.service.UserService;
import com.yj.earth.common.config.ServerConfig;
import com.yj.earth.common.util.ApiResponse;
import com.yj.earth.common.util.HttpUtil;
import com.yj.earth.common.util.JsonUtil;
import com.yj.earth.common.util.MapUtil;
import com.yj.earth.dto.source.AddModelSourceDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -24,6 +28,8 @@ import java.util.List;
import java.util.Map;
import java.util.function.Function;
import static com.yj.earth.common.constant.GlobalConstant.SHOW;
@Slf4j
@Service
@ -76,15 +82,41 @@ public class SourceServiceImpl extends ServiceImpl<SourceMapper, Source> impleme
return "父级不存在";
}
}
// // 验证该目录下是否已经存在此资源名一样的
// LambdaQueryWrapper<Source> queryWrapper = new LambdaQueryWrapper<>();
// queryWrapper.eq(Source::getSourceName, sourceName);
// if (sourceService.count(queryWrapper) > 0) {
// return "此目录下已存在此资源";
// }
return null;
}
@Override
public Source addModelSource(AddModelSourceDto addModelSourceDto) {
// 获取资源绝对路径
String sourcePath = addModelSourceDto.getSourcePath();
// 获取资源名称
String sourceName = FileUtil.mainName(sourcePath);
// 校验是否通过
String message = sourceService.checkIsPass(addModelSourceDto.getParentId(), sourceName);
if (message != null) {
return null;
}
// 调用SDK加载资源
String sourceId = sourceService.addAndGetSourceId(sourcePath);
// 获取文件路径并处理详情
String detail = sourceService.getDetail(sourcePath, sourceId);
// 构建并保存资源对象
Source source = new Source();
source.setId(addModelSourceDto.getId());
source.setSourcePath(sourcePath);
source.setSourceName(sourceName);
source.setParentId(addModelSourceDto.getParentId());
source.setTreeIndex(addModelSourceDto.getTreeIndex());
source.setParams(JsonUtil.mapToJson(addModelSourceDto.getParams()));
source.setDetail(detail);
source.setSourceType(MapUtil.getString(MapUtil.jsonToMap(detail), "fileType"));
source.setIsShow(SHOW);
sourceService.save(source);
// 添加资源到该用户的角色下
roleSourceService.addRoleSource(userService.getById(StpUtil.getLoginIdAsString()).getRoleId(), source.getId());
return source;
}
/**
* 根据文件后缀获取详情信息
*/