feat: 3d模型

This commit is contained in:
2025-12-09 17:13:20 +08:00
parent 5f603bc69d
commit 358639a8ac
492 changed files with 74670 additions and 190 deletions
@@ -0,0 +1,178 @@
package com.central.device.controller;
import com.central.common.model.PageResult;
import com.central.common.model.Result;
import com.central.device.model.dto.ThreeDModelFileDTO;
import com.central.device.model.vo.ThreeDModelFileVO;
import com.central.device.service.IThreeDModelFileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
/**
* 3D模型文件管理Controller
*
* @author claude
* @date 2024-12-08
*/
@Slf4j
@RestController
@RequestMapping("/3d-model")
@RequiredArgsConstructor
@Tag(name = "3D模型文件管理")
public class ThreeDModelFileController {
private final IThreeDModelFileService modelFileService;
/**
* 分页查询模型列表
*/
@GetMapping
@Operation(summary = "分页查询模型列表")
public PageResult<ThreeDModelFileVO> list(@RequestParam Map<String, Object> params) {
return modelFileService.findList(params);
}
/**
* 获取模型详情
*/
@GetMapping("/{id}")
@Operation(summary = "获取模型详情")
public Result<ThreeDModelFileVO> getById(
@Parameter(description = "模型ID") @PathVariable Long id) {
ThreeDModelFileVO vo = modelFileService.getDetailById(id);
return vo != null ? Result.succeed(vo) : Result.failed("模型不存在");
}
/**
* 根据景区ID获取模型列表
*/
@GetMapping("/tourism/{tourismId}")
@Operation(summary = "根据景区ID获取模型列表")
public Result<List<ThreeDModelFileVO>> getByTourismId(
@Parameter(description = "景区ID") @PathVariable Long tourismId) {
return Result.succeed(modelFileService.getByTourismId(tourismId));
}
/**
* 获取所有可用模型(用于3D地图加载)
*/
@GetMapping("/available")
@Operation(summary = "获取所有可用模型")
public Result<List<ThreeDModelFileVO>> getAllAvailable() {
return Result.succeed(modelFileService.getAllAvailableModels());
}
/**
* 创建模型记录
*/
@PostMapping
@Operation(summary = "创建模型记录")
public Result<Long> create(@Valid @RequestBody ThreeDModelFileDTO dto) {
Long id = modelFileService.create(dto);
return Result.succeed(id, "创建成功");
}
/**
* 更新模型信息
*/
@PutMapping
@Operation(summary = "更新模型信息")
public Result<Void> update(@Valid @RequestBody ThreeDModelFileDTO dto) {
boolean success = modelFileService.update(dto);
return success ? Result.succeed("更新成功") : Result.failed("更新失败");
}
/**
* 删除模型
*/
@DeleteMapping("/{id}")
@Operation(summary = "删除模型")
public Result<Void> delete(
@Parameter(description = "模型ID") @PathVariable Long id) {
boolean success = modelFileService.delete(id);
return success ? Result.succeed("删除成功") : Result.failed("删除失败");
}
/**
* 批量上传模型文件
*/
@PostMapping("/{modelId}/upload")
@Operation(summary = "批量上传模型文件")
public Result<Map<String, Object>> uploadFiles(
@Parameter(description = "模型ID") @PathVariable Long modelId,
@Parameter(description = "文件列表") @RequestParam("files") MultipartFile[] files,
@Parameter(description = "基础路径") @RequestParam(value = "basePath", required = false) String basePath) {
Map<String, Object> result = modelFileService.uploadModelFiles(modelId, files, basePath);
return Result.succeed(result);
}
/**
* 上传单个文件
*/
@PostMapping("/{modelId}/upload/single")
@Operation(summary = "上传单个模型文件")
public Result<String> uploadSingleFile(
@Parameter(description = "模型ID") @PathVariable Long modelId,
@Parameter(description = "文件") @RequestParam("file") MultipartFile file,
@Parameter(description = "文件相对路径") @RequestParam("filePath") String filePath) {
String url = modelFileService.uploadSingleFile(modelId, file, filePath);
return Result.succeed(url, "上传成功");
}
/**
* 完成上传
*/
@PostMapping("/{modelId}/complete")
@Operation(summary = "完成上传(更新状态)")
public Result<Void> completeUpload(
@Parameter(description = "模型ID") @PathVariable Long modelId) {
boolean success = modelFileService.completeUpload(modelId);
return success ? Result.succeed("完成") : Result.failed("操作失败");
}
/**
* 更新上传进度
*/
@PostMapping("/{modelId}/progress")
@Operation(summary = "更新上传进度")
public Result<Void> updateProgress(
@Parameter(description = "模型ID") @PathVariable Long modelId,
@Parameter(description = "进度(0-100)") @RequestParam Integer progress) {
modelFileService.updateProgress(modelId, progress);
return Result.succeed("上传完成");
}
/**
* 启用/禁用模型
*/
@PutMapping("/{id}/status")
@Operation(summary = "启用/禁用模型")
public Result<Void> updateStatus(
@Parameter(description = "模型ID") @PathVariable Long id,
@Parameter(description = "状态: 0-禁用 1-启用") @RequestParam Integer status) {
boolean success = modelFileService.updateStatus(id, status);
return success ? Result.succeed("操作成功") : Result.failed("操作失败");
}
/**
* 关联景区
*/
@PutMapping("/{id}/bindTourism")
@Operation(summary = "关联景区")
public Result<Void> bindTourism(
@Parameter(description = "模型ID") @PathVariable Long id,
@Parameter(description = "景区ID") @RequestParam Long tourismId,
@Parameter(description = "景区名称") @RequestParam(required = false) String tourismName) {
boolean success = modelFileService.bindTourism(id, tourismId, tourismName);
return success ? Result.succeed("关联成功") : Result.failed("关联失败");
}
}
@@ -5,7 +5,9 @@ import com.central.common.model.FileInfo;
import com.central.common.model.Result;
import com.central.device.feign.fallback.FileCenterServiceFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
@@ -67,7 +69,56 @@ public interface FileCenterService {
* @return 预热任务执行结果
*/
@PostMapping("/cdn/batch/prefetch")
Result<Boolean> batchPrefetchFiles(@RequestBody List<String> urls,
Result<Boolean> batchPrefetchFiles(@RequestBody List<String> urls,
@RequestParam(value = "batchSize", defaultValue = "100") int batchSize,
@RequestParam(value = "area", required = false) String area);
// ========== 3D模型文件上传相关接口 ==========
/**
* 上传单个模型文件到MinIO(goflymodel桶)
*
* @param file 文件
* @param folderPath 模型文件夹路径
* @param filePath 文件相对路径
* @return 上传结果
*/
@PostMapping(value = "/model-file/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
Result<Map<String, Object>> uploadModelFile(
@RequestPart("file") MultipartFile file,
@RequestParam("folderPath") String folderPath,
@RequestParam("filePath") String filePath);
/**
* 删除模型文件夹
*
* @param folderPath 文件夹路径
* @return 操作结果
*/
@DeleteMapping("/model-file/folder")
Result<Void> deleteModelFolder(@RequestParam("folderPath") String folderPath);
/**
* 检查模型文件是否存在
*
* @param folderPath 文件夹路径
* @param filePath 文件相对路径
* @return 是否存在
*/
@GetMapping("/model-file/exists")
Result<Boolean> checkModelFileExists(
@RequestParam("folderPath") String folderPath,
@RequestParam("filePath") String filePath);
/**
* 获取模型文件CDN URL
*
* @param folderPath 文件夹路径
* @param filePath 文件相对路径
* @return CDN URL
*/
@GetMapping("/model-file/url")
Result<String> getModelFileUrl(
@RequestParam("folderPath") String folderPath,
@RequestParam("filePath") String filePath);
}
@@ -6,6 +6,7 @@ import com.central.device.feign.FileCenterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
@@ -73,6 +74,32 @@ public class FileCenterServiceFallbackFactory implements FallbackFactory<FileCen
return Result.failed("CDN批量预热文件失败: " + cause.getMessage());
}
// ========== 3D模型文件上传相关接口 ==========
@Override
public Result<Map<String, Object>> uploadModelFile(MultipartFile file, String folderPath, String filePath) {
log.error("上传模型文件失败: folderPath={}, filePath={}", folderPath, filePath, cause);
return Result.failed("上传模型文件失败: " + cause.getMessage());
}
@Override
public Result<Void> deleteModelFolder(String folderPath) {
log.error("删除模型文件夹失败: folderPath={}", folderPath, cause);
return Result.failed("删除模型文件夹失败: " + cause.getMessage());
}
@Override
public Result<Boolean> checkModelFileExists(String folderPath, String filePath) {
log.error("检查模型文件失败: folderPath={}, filePath={}", folderPath, filePath, cause);
return Result.failed("检查模型文件失败: " + cause.getMessage());
}
@Override
public Result<String> getModelFileUrl(String folderPath, String filePath) {
log.error("获取模型文件URL失败: folderPath={}, filePath={}", folderPath, filePath, cause);
return Result.failed("获取模型文件URL失败: " + cause.getMessage());
}
};
}
}
@@ -0,0 +1,47 @@
package com.central.device.mapper;
import com.central.db.mapper.SuperMapper;
import com.central.device.model.ThreeDModelFileDetail;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* 3D模型文件详情Mapper
*
* @author claude
* @date 2024-12-08
*/
@Mapper
public interface ThreeDModelFileDetailMapper extends SuperMapper<ThreeDModelFileDetail> {
/**
* 根据模型ID查询文件详情列表
*
* @param modelId 模型ID
* @return 文件列表
*/
@Select("SELECT * FROM 3d_model_file_detail WHERE model_id = #{modelId} ORDER BY file_type, lod_level")
List<ThreeDModelFileDetail> findByModelId(@Param("modelId") Long modelId);
/**
* 根据模型ID删除所有文件详情
*
* @param modelId 模型ID
* @return 影响行数
*/
@Delete("DELETE FROM 3d_model_file_detail WHERE model_id = #{modelId}")
int deleteByModelId(@Param("modelId") Long modelId);
/**
* 统计模型的文件数量和总大小
*
* @param modelId 模型ID
* @return [文件数量, 总大小]
*/
@Select("SELECT COUNT(*) as count, COALESCE(SUM(file_size), 0) as totalSize FROM 3d_model_file_detail WHERE model_id = #{modelId}")
java.util.Map<String, Object> countFileStats(@Param("modelId") Long modelId);
}
@@ -0,0 +1,83 @@
package com.central.device.mapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.central.db.mapper.SuperMapper;
import com.central.device.model.ThreeDModelFile;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
import java.util.Map;
/**
* 3D模型文件Mapper
*
* @author claude
* @date 2024-12-08
*/
@Mapper
public interface ThreeDModelFileMapper extends SuperMapper<ThreeDModelFile> {
/**
* 分页查询
*
* @param page 分页参数
* @param params 查询参数
* @return 列表
*/
List<ThreeDModelFile> findList(Page<ThreeDModelFile> page, @Param("p") Map<String, Object> params);
/**
* 根据景区ID查询模型列表
*
* @param tourismId 景区ID
* @return 模型列表
*/
@Select("SELECT * FROM 3d_model_file WHERE tourism_id = #{tourismId} AND is_del = 0 AND status = 1 ORDER BY create_time DESC")
List<ThreeDModelFile> findByTourismId(@Param("tourismId") Long tourismId);
/**
* 根据工作空间ID查询模型列表
*
* @param workspaceId 工作空间ID
* @return 模型列表
*/
@Select("SELECT * FROM 3d_model_file WHERE workspace_id = #{workspaceId} AND is_del = 0 ORDER BY create_time DESC")
List<ThreeDModelFile> findByWorkspaceId(@Param("workspaceId") String workspaceId);
/**
* 更新上传进度
*
* @param id 模型ID
* @param uploadStatus 上传状态
* @param progress 进度
* @return 影响行数
*/
@Update("UPDATE 3d_model_file SET upload_status = #{uploadStatus}, upload_progress = #{progress}, update_time = NOW() WHERE id = #{id}")
int updateUploadProgress(@Param("id") Long id, @Param("uploadStatus") Integer uploadStatus, @Param("progress") Integer progress);
/**
* 更新文件统计信息
*
* @param id 模型ID
* @param fileCount 文件数量
* @param totalSize 总大小
* @return 影响行数
*/
@Update("UPDATE 3d_model_file SET file_count = #{fileCount}, total_size = #{totalSize}, update_time = NOW() WHERE id = #{id}")
int updateFileStats(@Param("id") Long id, @Param("fileCount") Integer fileCount, @Param("totalSize") Long totalSize);
/**
* 统计模型数量
*
* @param modelType 模型类型(可选)
* @return 数量
*/
@Select("<script>" +
"SELECT COUNT(*) FROM 3d_model_file WHERE is_del = 0 " +
"<if test='modelType != null'> AND model_type = #{modelType}</if>" +
"</script>")
Long countByType(@Param("modelType") Integer modelType);
}
@@ -0,0 +1,174 @@
package com.central.device.model;
import com.baomidou.mybatisplus.annotation.*;
import com.central.common.model.SuperEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.util.Date;
/**
* 3D模型文件实体类
* 用于存储大疆建图等工具生成的倾斜摄影、点云等3D模型
*
* 位置调整参数 (通常保持默认 0,模型会自动定位):
* | 参数 | 说明 | 范围 | 使用场景 |
* |------|-----------|-----------------|--------------|
* | 经度偏移 | 正值向东,负值向西 | -180 ~ 180 度 | 模型偏离实际位置时调整 |
* | 纬度偏移 | 正值向北,负值向南 | -90 ~ 90 度 | 模型偏离实际位置时调整 |
* | 高度偏移 | 正值向上,负值向下 | -1000 ~ 10000 米 | 模型悬空或陷入地面时调整 |
*
* 变换参数 (通常保持默认,除非模型方向不正确):
* | 参数 | 说明 | 范围 | 默认值 |
* |------|-----------------|------------|-----|
* | 缩放比例 | 1=原始大小,0.5=缩小一半 | 0.01 ~ 100 | 1 |
* | X轴旋转 | 俯仰角(弧度) | -2π ~ 2π | 0 |
* | Y轴旋转 | 翻滚角(弧度) | -2π ~ 2π | 0 |
* | Z轴旋转 | 航向角(弧度) | -2π ~ 2π | 0 |
*
* 渲染配置 (核心清晰度设置):
* | 参数 | 说明 | 推荐值 |
* |--------|------------------------|--------------|
* | LOD精度 | 核心参数!1-2=高清,8=中等,16=较低 | 1-4 (类似大疆司空) |
* | 最大内存 | 越大越能加载高清瓦片 | 1024-2048 MB |
* | 跳过LOD | 否=更清晰,是=更快 | 否 |
* | 优先叶子节点 | 优先加载最精细瓦片 | 是 |
* @author dzc
* @date 2024-12-08
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("3d_model_file")
@Schema(description = "3D模型文件")
public class ThreeDModelFile extends SuperEntity {
@Schema(description = "模型名称")
private String modelName;
@Schema(description = "模型类型: 1-倾斜摄影 2-点云 3-BIM 4-其他")
private Integer modelType;
@Schema(description = "模型格式: 3dtiles/osgb/obj/ply/las")
private String modelFormat;
@Schema(description = "模型描述")
private String description;
// ========== 文件存储信息 ==========
@Schema(description = "tileset.json的CDN访问URL")
private String tilesetUrl;
@Schema(description = "tileset.json在MinIO的存储路径")
private String tilesetPath;
@Schema(description = "MinIO桶名称")
private String bucketName;
@Schema(description = "模型文件夹路径(相对于bucket)")
private String folderPath;
@Schema(description = "模型文件总数")
private Integer fileCount;
@Schema(description = "模型文件总大小(bytes)")
private Long totalSize;
// ========== 关联信息 ==========
@Schema(description = "关联景区ID")
private Long tourismId;
@Schema(description = "关联景区名称")
private String tourismName;
@Schema(description = "工作空间ID")
private String workspaceId;
// ========== 位置调整参数 ==========
@Schema(description = "经度偏移(度)")
private BigDecimal offsetLongitude;
@Schema(description = "纬度偏移(度)")
private BigDecimal offsetLatitude;
@Schema(description = "高度偏移(米)")
private BigDecimal offsetHeight;
// ========== 变换参数 ==========
@Schema(description = "缩放比例")
private BigDecimal scale;
@Schema(description = "X轴旋转(弧度)")
private BigDecimal rotationX;
@Schema(description = "Y轴旋转(弧度)")
private BigDecimal rotationY;
@Schema(description = "Z轴旋转(弧度)")
private BigDecimal rotationZ;
// ========== 渲染配置 ==========
@Schema(description = "LOD精度控制(默认16)")
private Integer maxScreenSpaceError;
@Schema(description = "最大内存使用(MB)")
private Integer maxMemoryUsage;
@Schema(description = "是否跳过LOD: 0-否 1-是")
private Integer skipLod;
@Schema(description = "是否优先加载叶子节点: 0-否 1-是")
private Integer preferLeaves;
// ========== 元数据 ==========
@Schema(description = "来源类型: dji_terra/cesium_ion/custom")
private String sourceType;
@Schema(description = "缩略图URL")
private String thumbnailUrl;
@Schema(description = "包围盒信息(JSON格式)")
private String boundingBox;
@Schema(description = "模型中心点(JSON格式)")
private String centerPoint;
// ========== 状态与审计 ==========
@Schema(description = "状态: 0-禁用 1-启用 2-处理中")
private Integer status;
@Schema(description = "上传状态: 0-待上传 1-上传中 2-已完成 3-失败")
private Integer uploadStatus;
@Schema(description = "上传进度(0-100)")
private Integer uploadProgress;
@Schema(description = "租户ID")
private String tenantId;
@Schema(description = "创建人")
private String createBy;
@TableField(fill = FieldFill.INSERT)
@Schema(description = "创建时间")
private Date createTime;
@Schema(description = "更新人")
private String updateBy;
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description = "更新时间")
private Date updateTime;
@TableLogic
@Schema(description = "是否删除: 0-否 1-是")
private Integer isDel;
}
@@ -0,0 +1,52 @@
package com.central.device.model;
import com.baomidou.mybatisplus.annotation.*;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.Date;
/**
* 3D模型文件详情实体类
* 用于存储单个模型包含的所有文件信息
*
* @author claude
* @date 2024-12-08
*/
@Data
@TableName("3d_model_file_detail")
@Schema(description = "3D模型文件详情")
public class ThreeDModelFileDetail {
@TableId(type = IdType.AUTO)
@Schema(description = "主键ID")
private Long id;
@Schema(description = "关联的模型ID")
private Long modelId;
@Schema(description = "文件名")
private String fileName;
@Schema(description = "MinIO存储路径")
private String filePath;
@Schema(description = "CDN访问URL")
private String fileUrl;
@Schema(description = "文件大小(bytes)")
private Long fileSize;
@Schema(description = "文件类型: tileset/b3dm/i3dm/pnts/cmpt/json/texture")
private String fileType;
@Schema(description = "LOD层级(如L14, L15等)")
private String lodLevel;
@Schema(description = "上传状态: 0-待上传 1-上传中 2-已完成 3-失败")
private Integer uploadStatus;
@TableField(fill = FieldFill.INSERT)
@Schema(description = "创建时间")
private Date createTime;
}
@@ -0,0 +1,93 @@
package com.central.device.model.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import jakarta.validation.constraints.NotBlank;
import java.math.BigDecimal;
/**
* 3D模型文件DTO - 用于创建/更新操作
*
* @author claude
* @date 2024-12-08
*/
@Data
@Schema(description = "3D模型文件DTO")
public class ThreeDModelFileDTO {
@Schema(description = "ID(更新时必填)")
private Long id;
@NotBlank(message = "模型名称不能为空")
@Schema(description = "模型名称", required = true)
private String modelName;
@Schema(description = "模型类型: 1-倾斜摄影 2-点云 3-BIM 4-其他", defaultValue = "1")
private Integer modelType = 1;
@Schema(description = "模型格式: 3dtiles/osgb/obj/ply/las", defaultValue = "3dtiles")
private String modelFormat = "3dtiles";
@Schema(description = "模型描述")
private String description;
@Schema(description = "关联景区ID")
private Long tourismId;
@Schema(description = "关联景区名称")
private String tourismName;
@Schema(description = "工作空间ID")
private String workspaceId;
// ========== 位置调整参数 ==========
@Schema(description = "经度偏移(度)", defaultValue = "0")
private BigDecimal offsetLongitude = BigDecimal.ZERO;
@Schema(description = "纬度偏移(度)", defaultValue = "0")
private BigDecimal offsetLatitude = BigDecimal.ZERO;
@Schema(description = "高度偏移(米)", defaultValue = "0")
private BigDecimal offsetHeight = BigDecimal.ZERO;
// ========== 变换参数 ==========
@Schema(description = "缩放比例", defaultValue = "1.0")
private BigDecimal scale = BigDecimal.ONE;
@Schema(description = "X轴旋转(弧度)", defaultValue = "0")
private BigDecimal rotationX = BigDecimal.ZERO;
@Schema(description = "Y轴旋转(弧度)", defaultValue = "0")
private BigDecimal rotationY = BigDecimal.ZERO;
@Schema(description = "Z轴旋转(弧度)", defaultValue = "0")
private BigDecimal rotationZ = BigDecimal.ZERO;
// ========== 渲染配置 ==========
@Schema(description = "LOD精度控制(默认16)", defaultValue = "16")
private Integer maxScreenSpaceError = 16;
@Schema(description = "最大内存使用(MB)", defaultValue = "512")
private Integer maxMemoryUsage = 512;
@Schema(description = "是否跳过LOD: 0-否 1-是", defaultValue = "1")
private Integer skipLod = 1;
@Schema(description = "是否优先加载叶子节点: 0-否 1-是", defaultValue = "1")
private Integer preferLeaves = 1;
// ========== 元数据 ==========
@Schema(description = "来源类型: dji_terra/cesium_ion/custom", defaultValue = "dji_terra")
private String sourceType = "dji_terra";
@Schema(description = "状态: 0-禁用 1-启用", defaultValue = "1")
private Integer status = 1;
@Schema(description = "租户ID")
private String tenantId;
}
@@ -0,0 +1,208 @@
package com.central.device.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
* 3D模型文件VO - 用于前端展示
*
* @author claude
* @date 2024-12-08
*/
@Data
@Schema(description = "3D模型文件VO")
public class ThreeDModelFileVO {
@Schema(description = "ID")
private Long id;
@Schema(description = "模型名称")
private String modelName;
@Schema(description = "模型类型: 1-倾斜摄影 2-点云 3-BIM 4-其他")
private Integer modelType;
@Schema(description = "模型类型名称")
private String modelTypeName;
@Schema(description = "模型格式")
private String modelFormat;
@Schema(description = "模型描述")
private String description;
// ========== 文件信息 ==========
@Schema(description = "tileset.json的CDN访问URL")
private String tilesetUrl;
@Schema(description = "模型文件总数")
private Integer fileCount;
@Schema(description = "模型文件总大小(bytes)")
private Long totalSize;
@Schema(description = "格式化的文件大小")
private String totalSizeFormat;
// ========== 关联信息 ==========
@Schema(description = "关联景区ID")
private Long tourismId;
@Schema(description = "关联景区名称")
private String tourismName;
// ========== 位置参数 ==========
@Schema(description = "位置配置")
private PositionConfig position;
@Schema(description = "变换配置")
private TransformConfig transform;
@Schema(description = "渲染样式配置")
private StyleConfig style;
// ========== 状态信息 ==========
@Schema(description = "状态: 0-禁用 1-启用 2-处理中")
private Integer status;
@Schema(description = "状态名称")
private String statusName;
@Schema(description = "上传状态: 0-待上传 1-上传中 2-已完成 3-失败")
private Integer uploadStatus;
@Schema(description = "上传状态名称")
private String uploadStatusName;
@Schema(description = "上传进度(0-100)")
private Integer uploadProgress;
@Schema(description = "缩略图URL")
private String thumbnailUrl;
@Schema(description = "来源类型")
private String sourceType;
@Schema(description = "创建时间")
private Date createTime;
@Schema(description = "更新时间")
private Date updateTime;
/**
* 位置配置
*/
@Data
@Schema(description = "位置配置")
public static class PositionConfig {
@Schema(description = "经度偏移")
private BigDecimal longitude;
@Schema(description = "纬度偏移")
private BigDecimal latitude;
@Schema(description = "高度偏移")
private BigDecimal height;
}
/**
* 变换配置
*/
@Data
@Schema(description = "变换配置")
public static class TransformConfig {
@Schema(description = "缩放比例")
private BigDecimal scale;
@Schema(description = "X轴旋转")
private BigDecimal rotationX;
@Schema(description = "Y轴旋转")
private BigDecimal rotationY;
@Schema(description = "Z轴旋转")
private BigDecimal rotationZ;
}
/**
* 渲染样式配置
*/
@Data
@Schema(description = "渲染样式配置")
public static class StyleConfig {
@Schema(description = "LOD精度")
private Integer maximumScreenSpaceError;
@Schema(description = "最大内存(MB)")
private Integer maximumMemoryUsage;
@Schema(description = "跳过LOD")
private Boolean skipLevelOfDetail;
@Schema(description = "优先叶子节点")
private Boolean preferLeaves;
}
/**
* 获取模型类型名称
*/
public String getModelTypeName() {
if (modelType == null) return "未知";
switch (modelType) {
case 1: return "倾斜摄影";
case 2: return "点云";
case 3: return "BIM";
case 4: return "其他";
default: return "未知";
}
}
/**
* 获取状态名称
*/
public String getStatusName() {
if (status == null) return "未知";
switch (status) {
case 0: return "禁用";
case 1: return "启用";
case 2: return "处理中";
default: return "未知";
}
}
/**
* 获取上传状态名称
*/
public String getUploadStatusName() {
if (uploadStatus == null) return "未知";
switch (uploadStatus) {
case 0: return "待上传";
case 1: return "上传中";
case 2: return "已完成";
case 3: return "失败";
default: return "未知";
}
}
/**
* 获取格式化的文件大小
*/
public String getTotalSizeFormat() {
if (totalSize == null || totalSize == 0) return "0 B";
String[] units = {"B", "KB", "MB", "GB", "TB"};
int unitIndex = 0;
double size = totalSize;
while (size >= 1024 && unitIndex < units.length - 1) {
size /= 1024;
unitIndex++;
}
return String.format("%.2f %s", size, units[unitIndex]);
}
}
@@ -0,0 +1,130 @@
package com.central.device.service;
import com.central.common.model.PageResult;
import com.central.common.service.ISuperService;
import com.central.device.model.ThreeDModelFile;
import com.central.device.model.dto.ThreeDModelFileDTO;
import com.central.device.model.vo.ThreeDModelFileVO;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
/**
* 3D模型文件服务接口
*
* @author claude
* @date 2024-12-08
*/
public interface IThreeDModelFileService extends ISuperService<ThreeDModelFile> {
/**
* 分页查询模型列表
*
* @param params 查询参数
* @return 分页结果
*/
PageResult<ThreeDModelFileVO> findList(Map<String, Object> params);
/**
* 根据ID获取模型详情
*
* @param id 模型ID
* @return 模型VO
*/
ThreeDModelFileVO getDetailById(Long id);
/**
* 根据景区ID获取模型列表(用于前端加载)
*
* @param tourismId 景区ID
* @return 模型列表
*/
List<ThreeDModelFileVO> getByTourismId(Long tourismId);
/**
* 获取所有可用模型列表(用于前端3D地图加载)
*
* @return 模型列表
*/
List<ThreeDModelFileVO> getAllAvailableModels();
/**
* 创建模型记录(不含文件上传)
*
* @param dto 模型信息
* @return 模型ID
*/
Long create(ThreeDModelFileDTO dto);
/**
* 更新模型信息
*
* @param dto 模型信息
* @return 是否成功
*/
boolean update(ThreeDModelFileDTO dto);
/**
* 删除模型(逻辑删除)
*
* @param id 模型ID
* @return 是否成功
*/
boolean delete(Long id);
/**
* 上传模型文件夹(批量上传所有文件)
*
* @param modelId 模型ID
* @param files 文件列表
* @param basePath 基础路径(文件夹结构)
* @return 上传结果
*/
Map<String, Object> uploadModelFiles(Long modelId, MultipartFile[] files, String basePath);
/**
* 上传单个模型文件
*
* @param modelId 模型ID
* @param file 文件
* @param filePath 文件相对路径
* @return 文件CDN URL
*/
String uploadSingleFile(Long modelId, MultipartFile file, String filePath);
/**
* 完成上传(更新状态和统计信息)
*
* @param modelId 模型ID
* @return 是否成功
*/
boolean completeUpload(Long modelId);
/**
* 更新上传进度
*
* @param modelId 模型ID
* @param progress 进度(0-100)
*/
void updateProgress(Long modelId, Integer progress);
/**
* 启用/禁用模型
*
* @param id 模型ID
* @param status 状态
* @return 是否成功
*/
boolean updateStatus(Long id, Integer status);
/**
* 关联景区
*
* @param id 模型ID
* @param tourismId 景区ID
* @param tourismName 景区名称
* @return 是否成功
*/
boolean bindTourism(Long id, Long tourismId, String tourismName);
}
@@ -0,0 +1,434 @@
package com.central.device.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.central.common.model.PageResult;
import com.central.common.model.Result;
import com.central.common.service.impl.SuperServiceImpl;
import com.central.device.feign.FileCenterService;
import com.central.device.mapper.ThreeDModelFileDetailMapper;
import com.central.device.mapper.ThreeDModelFileMapper;
import com.central.device.model.ThreeDModelFile;
import com.central.device.model.ThreeDModelFileDetail;
import com.central.device.model.dto.ThreeDModelFileDTO;
import com.central.device.model.vo.ThreeDModelFileVO;
import com.central.device.service.IThreeDModelFileService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.util.*;
import java.util.stream.Collectors;
/**
* 3D模型文件服务实现类
*
* @author claude
* @date 2024-12-08
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class ThreeDModelFileServiceImpl extends SuperServiceImpl<ThreeDModelFileMapper, ThreeDModelFile>
implements IThreeDModelFileService {
private final ThreeDModelFileDetailMapper detailMapper;
private final FileCenterService fileCenterService;
@Override
public PageResult<ThreeDModelFileVO> findList(Map<String, Object> params) {
Page<ThreeDModelFile> page = new Page<>(
MapUtils.getInteger(params, "page", 1),
MapUtils.getInteger(params, "limit", 10)
);
List<ThreeDModelFile> list = baseMapper.findList(page, params);
List<ThreeDModelFileVO> voList = list.stream()
.map(this::convertToVO)
.collect(Collectors.toList());
return PageResult.<ThreeDModelFileVO>builder()
.data(voList)
.resp_code(0)
.count(page.getTotal())
.build();
}
@Override
public ThreeDModelFileVO getDetailById(Long id) {
ThreeDModelFile model = getById(id);
if (model == null) {
return null;
}
return convertToVO(model);
}
@Override
public List<ThreeDModelFileVO> getByTourismId(Long tourismId) {
List<ThreeDModelFile> list = baseMapper.findByTourismId(tourismId);
return list.stream()
.map(this::convertToVO)
.collect(Collectors.toList());
}
@Override
public List<ThreeDModelFileVO> getAllAvailableModels() {
Map<String, Object> params = new HashMap<>();
params.put("status", 1);
params.put("uploadStatus", 2); // 已完成上传
params.put("page", 1);
params.put("limit", 1000);
Page<ThreeDModelFile> page = new Page<>(1, 1000);
List<ThreeDModelFile> list = baseMapper.findList(page, params);
return list.stream()
.map(this::convertToVO)
.collect(Collectors.toList());
}
@Override
@Transactional(rollbackFor = Exception.class)
public Long create(ThreeDModelFileDTO dto) {
ThreeDModelFile model = new ThreeDModelFile();
BeanUtil.copyProperties(dto, model);
// 设置默认值
model.setBucketName("goflymodel");
model.setUploadStatus(0); // 待上传
model.setUploadProgress(0);
model.setFileCount(0);
model.setTotalSize(0L);
model.setTilesetUrl("");
model.setTilesetPath("");
model.setStatus(0); // 默认禁用,上传完成后启用
// 生成文件夹路径
String folderPath = generateFolderPath(dto.getModelName());
model.setFolderPath(folderPath);
save(model);
return model.getId();
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean update(ThreeDModelFileDTO dto) {
if (dto.getId() == null) {
throw new IllegalArgumentException("ID不能为空");
}
ThreeDModelFile model = getById(dto.getId());
if (model == null) {
throw new IllegalArgumentException("模型不存在");
}
// 更新字段
if (StrUtil.isNotBlank(dto.getModelName())) {
model.setModelName(dto.getModelName());
}
if (dto.getModelType() != null) {
model.setModelType(dto.getModelType());
}
if (StrUtil.isNotBlank(dto.getDescription())) {
model.setDescription(dto.getDescription());
}
if (dto.getTourismId() != null) {
model.setTourismId(dto.getTourismId());
model.setTourismName(dto.getTourismName());
}
// 更新位置参数
if (dto.getOffsetLongitude() != null) {
model.setOffsetLongitude(dto.getOffsetLongitude());
}
if (dto.getOffsetLatitude() != null) {
model.setOffsetLatitude(dto.getOffsetLatitude());
}
if (dto.getOffsetHeight() != null) {
model.setOffsetHeight(dto.getOffsetHeight());
}
// 更新变换参数
if (dto.getScale() != null) {
model.setScale(dto.getScale());
}
if (dto.getRotationX() != null) {
model.setRotationX(dto.getRotationX());
}
if (dto.getRotationY() != null) {
model.setRotationY(dto.getRotationY());
}
if (dto.getRotationZ() != null) {
model.setRotationZ(dto.getRotationZ());
}
// 更新渲染配置
if (dto.getMaxScreenSpaceError() != null) {
model.setMaxScreenSpaceError(dto.getMaxScreenSpaceError());
}
if (dto.getMaxMemoryUsage() != null) {
model.setMaxMemoryUsage(dto.getMaxMemoryUsage());
}
if (dto.getSkipLod() != null) {
model.setSkipLod(dto.getSkipLod());
}
if (dto.getPreferLeaves() != null) {
model.setPreferLeaves(dto.getPreferLeaves());
}
if (dto.getStatus() != null) {
model.setStatus(dto.getStatus());
}
return updateById(model);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean delete(Long id) {
ThreeDModelFile model = getById(id);
if (model == null) {
return false;
}
// 删除MinIO中的文件(可选,也可以保留)
// minioUploadService.deleteFolder(model.getBucketName(), model.getFolderPath());
// 删除文件详情
detailMapper.deleteByModelId(id);
// 逻辑删除模型
model.setIsDel(1);
return updateById(model);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, Object> uploadModelFiles(Long modelId, MultipartFile[] files, String basePath) {
ThreeDModelFile model = getById(modelId);
if (model == null) {
throw new IllegalArgumentException("模型不存在");
}
// 更新上传状态
model.setUploadStatus(1); // 上传中
updateById(model);
Map<String, Object> result = new HashMap<>();
List<String> successFiles = new ArrayList<>();
List<String> failedFiles = new ArrayList<>();
long totalSize = 0;
try {
for (int i = 0; i < files.length; i++) {
MultipartFile file = files[i];
String relativePath = StrUtil.isNotBlank(basePath) ?
basePath + "/" + file.getOriginalFilename() :
file.getOriginalFilename();
try {
String fileUrl = uploadSingleFile(modelId, file, relativePath);
successFiles.add(relativePath);
totalSize += file.getSize();
// 更新进度
int progress = (int) ((i + 1) * 100.0 / files.length);
updateProgress(modelId, progress);
} catch (Exception e) {
log.error("上传文件失败: {}", relativePath, e);
failedFiles.add(relativePath);
}
}
// 完成上传
if (failedFiles.isEmpty()) {
completeUpload(modelId);
} else {
model.setUploadStatus(3); // 部分失败
updateById(model);
}
result.put("success", true);
result.put("successFiles", successFiles);
result.put("failedFiles", failedFiles);
result.put("totalSize", totalSize);
result.put("tilesetUrl", model.getTilesetUrl());
} catch (Exception e) {
log.error("批量上传文件失败", e);
model.setUploadStatus(3); // 失败
updateById(model);
result.put("success", false);
result.put("error", e.getMessage());
}
return result;
}
@Override
@Transactional(rollbackFor = Exception.class)
public String uploadSingleFile(Long modelId, MultipartFile file, String filePath) {
ThreeDModelFile model = getById(modelId);
if (model == null) {
throw new IllegalArgumentException("模型不存在");
}
String folderPath = model.getFolderPath();
// 通过Feign调用file-center上传到MinIO
Result<Map<String, Object>> uploadResult = fileCenterService.uploadModelFile(file, folderPath, filePath);
if (uploadResult == null || uploadResult.getResp_code() != 0) {
String errorMsg = uploadResult != null ? uploadResult.getResp_msg() : "上传失败";
throw new RuntimeException("上传文件失败: " + errorMsg);
}
Map<String, Object> resultData = uploadResult.getData();
String fileUrl = (String) resultData.get("cdnUrl");
String objectKey = (String) resultData.get("objectKey");
// 保存文件详情
ThreeDModelFileDetail detail = new ThreeDModelFileDetail();
detail.setModelId(modelId);
detail.setFileName(file.getOriginalFilename());
detail.setFilePath(objectKey);
detail.setFileUrl(fileUrl);
detail.setFileSize(file.getSize());
detail.setFileType(getFileType(file.getOriginalFilename()));
detail.setLodLevel(extractLodLevel(file.getOriginalFilename()));
detail.setUploadStatus(2); // 已完成
detailMapper.insert(detail);
// 如果是tileset.json,更新主记录
if (filePath.endsWith("tileset.json") && !filePath.contains("/Block/")) {
model.setTilesetPath(objectKey);
model.setTilesetUrl(fileUrl);
updateById(model);
}
return fileUrl;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean completeUpload(Long modelId) {
ThreeDModelFile model = getById(modelId);
if (model == null) {
return false;
}
// 统计文件信息
Map<String, Object> stats = detailMapper.countFileStats(modelId);
int fileCount = ((Number) stats.get("count")).intValue();
long totalSize = ((Number) stats.get("totalSize")).longValue();
model.setFileCount(fileCount);
model.setTotalSize(totalSize);
model.setUploadStatus(2); // 已完成
model.setUploadProgress(100);
model.setStatus(1); // 启用
return updateById(model);
}
@Override
public void updateProgress(Long modelId, Integer progress) {
baseMapper.updateUploadProgress(modelId, 1, progress);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateStatus(Long id, Integer status) {
ThreeDModelFile model = getById(id);
if (model == null) {
return false;
}
model.setStatus(status);
return updateById(model);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean bindTourism(Long id, Long tourismId, String tourismName) {
ThreeDModelFile model = getById(id);
if (model == null) {
return false;
}
model.setTourismId(tourismId);
model.setTourismName(tourismName);
return updateById(model);
}
/**
* 转换为VO
*/
private ThreeDModelFileVO convertToVO(ThreeDModelFile model) {
ThreeDModelFileVO vo = new ThreeDModelFileVO();
BeanUtil.copyProperties(model, vo);
// 设置位置配置
ThreeDModelFileVO.PositionConfig position = new ThreeDModelFileVO.PositionConfig();
position.setLongitude(model.getOffsetLongitude());
position.setLatitude(model.getOffsetLatitude());
position.setHeight(model.getOffsetHeight());
vo.setPosition(position);
// 设置变换配置
ThreeDModelFileVO.TransformConfig transform = new ThreeDModelFileVO.TransformConfig();
transform.setScale(model.getScale());
transform.setRotationX(model.getRotationX());
transform.setRotationY(model.getRotationY());
transform.setRotationZ(model.getRotationZ());
vo.setTransform(transform);
// 设置样式配置
ThreeDModelFileVO.StyleConfig style = new ThreeDModelFileVO.StyleConfig();
style.setMaximumScreenSpaceError(model.getMaxScreenSpaceError());
style.setMaximumMemoryUsage(model.getMaxMemoryUsage());
style.setSkipLevelOfDetail(model.getSkipLod() != null && model.getSkipLod() == 1);
style.setPreferLeaves(model.getPreferLeaves() != null && model.getPreferLeaves() == 1);
vo.setStyle(style);
return vo;
}
/**
* 生成文件夹路径
*/
private String generateFolderPath(String modelName) {
String timestamp = String.valueOf(System.currentTimeMillis());
String safeName = modelName.replaceAll("[^a-zA-Z0-9\\u4e00-\\u9fa5]", "_");
return "model_" + timestamp + "_" + safeName;
}
/**
* 获取文件类型
*/
private String getFileType(String fileName) {
if (fileName == null) return "other";
String lower = fileName.toLowerCase();
if (lower.endsWith(".json")) return "json";
if (lower.endsWith(".b3dm")) return "b3dm";
if (lower.endsWith(".i3dm")) return "i3dm";
if (lower.endsWith(".pnts")) return "pnts";
if (lower.endsWith(".cmpt")) return "cmpt";
if (lower.endsWith(".glb") || lower.endsWith(".gltf")) return "gltf";
if (lower.endsWith(".jpg") || lower.endsWith(".jpeg") || lower.endsWith(".png")) return "texture";
return "other";
}
/**
* 提取LOD层级
*/
private String extractLodLevel(String fileName) {
if (fileName == null) return null;
// 匹配 L14, L15 等模式
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("L(\\d+)");
java.util.regex.Matcher matcher = pattern.matcher(fileName);
if (matcher.find()) {
return "L" + matcher.group(1);
}
return null;
}
}