树列表
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))
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -109,7 +109,6 @@ public class UserController {
|
||||
return ApiResponse.success(userPage);
|
||||
}
|
||||
|
||||
@CheckAuth
|
||||
@Operation(summary = "设置角色")
|
||||
@PostMapping("/userBindOrUnBindRole")
|
||||
@RoleAccess(roleNames = "管理员")
|
||||
|
||||
Reference in New Issue
Block a user