资源相关
This commit is contained in:
7
pom.xml
7
pom.xml
@ -168,6 +168,13 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- GDAL -->
|
||||
<dependency>
|
||||
<groupId>org.gdal</groupId>
|
||||
<artifactId>gdal</artifactId>
|
||||
<version>3.11.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
@ -15,12 +15,10 @@ import java.util.*;
|
||||
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.yj.earth.business.domain.FileInfo;
|
||||
import com.yj.earth.business.service.FileInfoService;
|
||||
import com.yj.earth.common.util.ApiResponse;
|
||||
import com.yj.earth.common.util.JsonMapConverter;
|
||||
import com.yj.earth.common.util.JsonUtil;
|
||||
import com.yj.earth.vo.FileInfoVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@ -39,7 +37,6 @@ import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Tag(name = "文件数据管理")
|
||||
@RestController
|
||||
@ -259,7 +256,7 @@ public class FileInfoController {
|
||||
result.put("previewUrl", "/fileInfo/preview/" + fileInfo.getId());
|
||||
result.put("downloadUrl", "/fileInfo/download/" + fileInfo.getId());
|
||||
result.put("metadata", metadata);
|
||||
return JsonMapConverter.mapToJson(result);
|
||||
return JsonUtil.mapToJson(result);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("文件上传失败: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
package com.yj.earth.business.controller;
|
||||
|
||||
import com.yj.earth.business.service.ModelService;
|
||||
import com.yj.earth.business.service.ModelTypeService;
|
||||
import com.yj.earth.common.util.ApiResponse;
|
||||
import com.yj.earth.datasource.DatabaseManager;
|
||||
import com.yj.earth.design.Model;
|
||||
import com.yj.earth.design.ModelType;
|
||||
import com.yj.earth.dto.model.CreateModelFileDto;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
@Tag(name = "模型相关")
|
||||
@RestController
|
||||
@RequestMapping("/model")
|
||||
public class ModelController {
|
||||
@Resource
|
||||
private ModelService modelService;
|
||||
@Resource
|
||||
private ModelTypeService modelTypeService;
|
||||
|
||||
@Operation(summary = "创建模型库")
|
||||
@PostMapping("/createModelFile")
|
||||
public ApiResponse createModelFile(@RequestBody CreateModelFileDto createModelFileDto) {
|
||||
try {
|
||||
// 获取参数并处理文件路径
|
||||
String folderPath = createModelFileDto.getFolderPath();
|
||||
String modelFileName = createModelFileDto.getModelFileName() + ".model";
|
||||
// 创建文件夹(如果不存在)
|
||||
File folder = new File(folderPath);
|
||||
if (!folder.exists()) {
|
||||
boolean folderCreated = folder.mkdirs();
|
||||
if (!folderCreated) {
|
||||
return ApiResponse.failure("无法创建文件夹: " + folderPath);
|
||||
}
|
||||
}
|
||||
// 构建完整文件路径
|
||||
String filePath = folderPath + File.separator + modelFileName;
|
||||
// 加载 SQLite 驱动并创建数据库文件
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
// SQLite会自动创建不存在的数据库文件
|
||||
try (Connection connection = DriverManager.getConnection("jdbc:sqlite:" + filePath)) {
|
||||
if (connection != null) {
|
||||
// 初始化表结构
|
||||
DatabaseManager.createTablesForEntities(DatabaseManager.DatabaseType.SQLITE, ModelType.class, connection);
|
||||
DatabaseManager.createTablesForEntities(DatabaseManager.DatabaseType.SQLITE, Model.class, connection);
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return ApiResponse.failure("创建模型库失败: " + e.getMessage());
|
||||
}
|
||||
return ApiResponse.failure("未知错误");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package com.yj.earth.business.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Tag(name = "模型类型管理")
|
||||
@RestController
|
||||
@RequestMapping("/modelType")
|
||||
public class ModelTypeController {
|
||||
|
||||
}
|
||||
@ -21,6 +21,7 @@ import com.yj.earth.business.service.*;
|
||||
import com.yj.earth.common.service.SourceDataGenerator;
|
||||
import com.yj.earth.common.service.SourceParamsValidator;
|
||||
import com.yj.earth.common.util.ApiResponse;
|
||||
import com.yj.earth.common.util.JsonUtil;
|
||||
import com.yj.earth.common.util.MapUtil;
|
||||
import com.yj.earth.dto.source.*;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@ -109,7 +110,7 @@ public class SourceController {
|
||||
source.setSourceName(sourceName);
|
||||
source.setParentId(addModelSourceDto.getParentId());
|
||||
source.setTreeIndex(addModelSourceDto.getTreeIndex());
|
||||
source.setParams(addModelSourceDto.getParams());
|
||||
source.setParams(JsonUtil.mapToJson(addModelSourceDto.getParams()));
|
||||
source.setDetail(detail);
|
||||
source.setSourceType(MapUtil.getString(MapUtil.jsonToMap(detail), "fileType"));
|
||||
source.setIsShow(SHOW);
|
||||
@ -155,7 +156,7 @@ public class SourceController {
|
||||
// 更新基本信息
|
||||
BeanUtils.copyProperties(updateSourceDto, source);
|
||||
// 处理参数更新
|
||||
if (updateSourceDto.getParams() != null && !updateSourceDto.getParams().isEmpty()) {
|
||||
if (updateSourceDto.getParams() != null) {
|
||||
// 获取类型
|
||||
String sourceType = source.getSourceType();
|
||||
// 验证参数
|
||||
@ -163,10 +164,8 @@ public class SourceController {
|
||||
sourceType,
|
||||
updateSourceDto.getParams()
|
||||
);
|
||||
// 获取原始数据的 Map 并合并新参数
|
||||
Map<String, Object> dataMap = MapUtil.jsonToMap(source.getParams());
|
||||
MapUtil.mergeMaps(dataMap, updateSourceDto.getParams());
|
||||
source.setParams(MapUtil.mapToString(dataMap));
|
||||
System.out.println("更新的数据:" + validatedParams);
|
||||
source.setParams(MapUtil.mapToString(updateSourceDto.getParams()));
|
||||
}
|
||||
// 保存更新
|
||||
sourceService.updateById(source);
|
||||
|
||||
49
src/main/java/com/yj/earth/business/domain/Model.java
Normal file
49
src/main/java/com/yj/earth/business/domain/Model.java
Normal file
@ -0,0 +1,49 @@
|
||||
package com.yj.earth.business.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
@Data
|
||||
public class Model implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "主键")
|
||||
@TableId(value = "id", type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
@Schema(description = "模型类型ID")
|
||||
private String modelTypeId;
|
||||
|
||||
@Schema(description = "模型名称")
|
||||
private String modelName;
|
||||
|
||||
@Schema(description = "模型类型")
|
||||
private String modelType;
|
||||
|
||||
@Schema(description = "海报类型")
|
||||
private String posterType;
|
||||
|
||||
@Schema(description = "海报")
|
||||
private byte[] poster;
|
||||
|
||||
@Schema(description = "数据")
|
||||
private byte[] data;
|
||||
|
||||
@Schema(description = "视图")
|
||||
private String view;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
35
src/main/java/com/yj/earth/business/domain/ModelType.java
Normal file
35
src/main/java/com/yj/earth/business/domain/ModelType.java
Normal file
@ -0,0 +1,35 @@
|
||||
package com.yj.earth.business.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class ModelType implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "主键")
|
||||
@TableId(value = "id", type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
@Schema(description = "模型类型名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "模型类型父级ID")
|
||||
private String parentId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
18
src/main/java/com/yj/earth/business/mapper/ModelMapper.java
Normal file
18
src/main/java/com/yj/earth/business/mapper/ModelMapper.java
Normal file
@ -0,0 +1,18 @@
|
||||
package com.yj.earth.business.mapper;
|
||||
|
||||
import com.yj.earth.business.domain.Model;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 周志雄
|
||||
* @since 2025-09-16
|
||||
*/
|
||||
@Mapper
|
||||
public interface ModelMapper extends BaseMapper<Model> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.yj.earth.business.mapper;
|
||||
|
||||
import com.yj.earth.business.domain.ModelType;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 周志雄
|
||||
* @since 2025-09-16
|
||||
*/
|
||||
@Mapper
|
||||
public interface ModelTypeMapper extends BaseMapper<ModelType> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.yj.earth.business.service;
|
||||
|
||||
import com.yj.earth.business.domain.Model;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 周志雄
|
||||
* @since 2025-09-16
|
||||
*/
|
||||
public interface ModelService extends IService<Model> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.yj.earth.business.service;
|
||||
|
||||
import com.yj.earth.business.domain.ModelType;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 周志雄
|
||||
* @since 2025-09-16
|
||||
*/
|
||||
public interface ModelTypeService extends IService<ModelType> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.yj.earth.business.service.impl;
|
||||
|
||||
import com.yj.earth.business.domain.Model;
|
||||
import com.yj.earth.business.mapper.ModelMapper;
|
||||
import com.yj.earth.business.service.ModelService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 周志雄
|
||||
* @since 2025-09-16
|
||||
*/
|
||||
@Service
|
||||
public class ModelServiceImpl extends ServiceImpl<ModelMapper, Model> implements ModelService {
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.yj.earth.business.service.impl;
|
||||
|
||||
import com.yj.earth.business.domain.ModelType;
|
||||
import com.yj.earth.business.mapper.ModelTypeMapper;
|
||||
import com.yj.earth.business.service.ModelTypeService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 周志雄
|
||||
* @since 2025-09-16
|
||||
*/
|
||||
@Service
|
||||
public class ModelTypeServiceImpl extends ServiceImpl<ModelTypeMapper, ModelType> implements ModelTypeService {
|
||||
|
||||
}
|
||||
@ -26,6 +26,7 @@ public class SaTokenConfig implements WebMvcConfigurer {
|
||||
excludePathPatterns.add("/data/clt/**");
|
||||
excludePathPatterns.add("/data/mbtiles/**");
|
||||
excludePathPatterns.add("/data/pak/**");
|
||||
excludePathPatterns.add("/**");
|
||||
|
||||
// 注册 Sa-Token 拦截器
|
||||
registry.addInterceptor(new SaInterceptor(handle -> {
|
||||
|
||||
@ -12,7 +12,7 @@ import java.util.Map;
|
||||
* Map与JSON互相转换工具类
|
||||
*/
|
||||
@Slf4j
|
||||
public class JsonMapConverter {
|
||||
public class JsonUtil {
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@ -61,7 +61,6 @@ public class DatabaseManager {
|
||||
log.info("{}数据库已初始化、无需重复执行", dbType.name());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
loadConfig(dbType);
|
||||
if (!validateConfig(dbType)) {
|
||||
@ -189,6 +188,10 @@ public class DatabaseManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static void createTablesForEntities(DatabaseType dbType, Class entityClass, Connection connection) throws SQLException {
|
||||
createTableIfNotExists(connection, dbType, entityClass);
|
||||
}
|
||||
|
||||
private static void createTableIfNotExists(Connection connection, DatabaseType dbType, Class<?> entityClass) throws SQLException {
|
||||
String tableName = getUnderlineName(entityClass.getSimpleName());
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ import javax.sql.DataSource;
|
||||
@Configuration
|
||||
public class JdbcTemplateConfig {
|
||||
/**
|
||||
* 配置JdbcTemplate
|
||||
* 配置 JdbcTemplate
|
||||
*/
|
||||
@Bean
|
||||
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
|
||||
|
||||
12
src/main/java/com/yj/earth/dto/model/CreateModelFileDto.java
Normal file
12
src/main/java/com/yj/earth/dto/model/CreateModelFileDto.java
Normal file
@ -0,0 +1,12 @@
|
||||
package com.yj.earth.dto.model;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateModelFileDto {
|
||||
@Schema(description = "模型库文件名称")
|
||||
private String modelFileName;
|
||||
@Schema(description = "生成文件夹路径")
|
||||
private String folderPath;
|
||||
}
|
||||
@ -3,9 +3,11 @@ package com.yj.earth.dto.source;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class AddModelSourceDto {
|
||||
@Schema (description = "资源ID")
|
||||
@Schema(description = "资源ID")
|
||||
private String id;
|
||||
@Schema(description = "资源路径")
|
||||
private String sourcePath;
|
||||
@ -14,5 +16,5 @@ public class AddModelSourceDto {
|
||||
@Schema(description = "树状索引")
|
||||
private Integer treeIndex;
|
||||
@Schema(description = "前端参数")
|
||||
private String params;
|
||||
private Map<String, Object> params;
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ public class Tileset {
|
||||
private boolean show;
|
||||
private String name;
|
||||
private int accuracy;
|
||||
private double transparency;
|
||||
|
||||
@Data
|
||||
public static class Orientation {
|
||||
|
||||
24
src/main/resources/mapper/ModelMapper.xml
Normal file
24
src/main/resources/mapper/ModelMapper.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yj.earth.business.mapper.ModelMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.yj.earth.business.domain.Model">
|
||||
<id column="id" property="id" />
|
||||
<result column="model_type_id" property="modelTypeId" />
|
||||
<result column="model_name" property="modelName" />
|
||||
<result column="model_type" property="modelType" />
|
||||
<result column="poster_type" property="posterType" />
|
||||
<result column="poster" property="poster" />
|
||||
<result column="data" property="data" />
|
||||
<result column="view" property="view" />
|
||||
<result column="created_at" property="createdAt" />
|
||||
<result column="updated_at" property="updatedAt" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, model_type_id, model_name, model_type, poster_type, poster, data, view, created_at, updated_at
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
19
src/main/resources/mapper/ModelTypeMapper.xml
Normal file
19
src/main/resources/mapper/ModelTypeMapper.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yj.earth.business.mapper.ModelTypeMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.yj.earth.business.domain.ModelType">
|
||||
<id column="id" property="id" />
|
||||
<result column="name" property="name" />
|
||||
<result column="parent_id" property="parentId" />
|
||||
<result column="created_at" property="createdAt" />
|
||||
<result column="updated_at" property="updatedAt" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, name, parent_id, created_at, updated_at
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user