From 273fc16f87072d6338e21c8d7cd96d379a22b508 Mon Sep 17 00:00:00 2001 From: ZZX9599 <536509593@qq.com> Date: Fri, 26 Sep 2025 13:46:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=9B=E6=A0=87=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BusinessConfigController.java | 36 ++ .../controller/IconLibraryController.java | 396 ++++++++++++++++++ .../controller/MilitaryLibraryController.java | 387 +++++++++++++++++ .../controller/ModelLibraryController.java | 395 +++++++++++++++++ .../earth/business/domain/BusinessConfig.java | 40 ++ .../yj/earth/business/domain/IconLibrary.java | 53 +++ .../business/domain/MilitaryLibrary.java | 42 ++ .../earth/business/domain/ModelLibrary.java | 42 ++ .../business/mapper/BusinessConfigMapper.java | 18 + .../business/mapper/IconLibraryMapper.java | 18 + .../mapper/MilitaryLibraryMapper.java | 18 + .../business/mapper/ModelLibraryMapper.java | 18 + .../service/BusinessConfigService.java | 16 + .../business/service/IconLibraryService.java | 16 + .../service/MilitaryLibraryService.java | 16 + .../business/service/ModelLibraryService.java | 16 + .../impl/BusinessConfigServiceImpl.java | 20 + .../service/impl/IconLibraryServiceImpl.java | 20 + .../impl/MilitaryLibraryServiceImpl.java | 20 + .../service/impl/ModelLibraryServiceImpl.java | 20 + .../resources/mapper/BusinessConfigMapper.xml | 19 + .../resources/mapper/IconLibraryMapper.xml | 20 + .../mapper/MilitaryLibraryMapper.xml | 20 + .../resources/mapper/ModelLibraryMapper.xml | 20 + 24 files changed, 1686 insertions(+) create mode 100644 src/main/java/com/yj/earth/business/controller/BusinessConfigController.java create mode 100644 src/main/java/com/yj/earth/business/controller/IconLibraryController.java create mode 100644 src/main/java/com/yj/earth/business/controller/MilitaryLibraryController.java create mode 100644 src/main/java/com/yj/earth/business/controller/ModelLibraryController.java create mode 100644 src/main/java/com/yj/earth/business/domain/BusinessConfig.java create mode 100644 src/main/java/com/yj/earth/business/domain/IconLibrary.java create mode 100644 src/main/java/com/yj/earth/business/domain/MilitaryLibrary.java create mode 100644 src/main/java/com/yj/earth/business/domain/ModelLibrary.java create mode 100644 src/main/java/com/yj/earth/business/mapper/BusinessConfigMapper.java create mode 100644 src/main/java/com/yj/earth/business/mapper/IconLibraryMapper.java create mode 100644 src/main/java/com/yj/earth/business/mapper/MilitaryLibraryMapper.java create mode 100644 src/main/java/com/yj/earth/business/mapper/ModelLibraryMapper.java create mode 100644 src/main/java/com/yj/earth/business/service/BusinessConfigService.java create mode 100644 src/main/java/com/yj/earth/business/service/IconLibraryService.java create mode 100644 src/main/java/com/yj/earth/business/service/MilitaryLibraryService.java create mode 100644 src/main/java/com/yj/earth/business/service/ModelLibraryService.java create mode 100644 src/main/java/com/yj/earth/business/service/impl/BusinessConfigServiceImpl.java create mode 100644 src/main/java/com/yj/earth/business/service/impl/IconLibraryServiceImpl.java create mode 100644 src/main/java/com/yj/earth/business/service/impl/MilitaryLibraryServiceImpl.java create mode 100644 src/main/java/com/yj/earth/business/service/impl/ModelLibraryServiceImpl.java create mode 100644 src/main/resources/mapper/BusinessConfigMapper.xml create mode 100644 src/main/resources/mapper/IconLibraryMapper.xml create mode 100644 src/main/resources/mapper/MilitaryLibraryMapper.xml create mode 100644 src/main/resources/mapper/ModelLibraryMapper.xml diff --git a/src/main/java/com/yj/earth/business/controller/BusinessConfigController.java b/src/main/java/com/yj/earth/business/controller/BusinessConfigController.java new file mode 100644 index 0000000..e17b6d4 --- /dev/null +++ b/src/main/java/com/yj/earth/business/controller/BusinessConfigController.java @@ -0,0 +1,36 @@ +package com.yj.earth.business.controller; + +import com.yj.earth.annotation.CheckAuth; +import com.yj.earth.business.domain.BusinessConfig; +import com.yj.earth.business.service.BusinessConfigService; +import com.yj.earth.common.util.ApiResponse; +import com.yj.earth.dto.businessConfig.AddBusinessConfigDto; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.beans.BeanUtils; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +@Tag(name = "业务配置管理") +@CheckAuth +@RestController +@RequestMapping("/businessConfig") +public class BusinessConfigController { + @Resource + private BusinessConfigService businessConfigService; + + @Operation(summary = "业务配置列表") + @GetMapping("/list") + public ApiResponse list() { + return ApiResponse.success(businessConfigService.list()); + } + + @PostMapping("/addBusinessConfig") + @Operation(summary = "新增业务配置") + public ApiResponse addBusinessConfig(@RequestBody AddBusinessConfigDto addBusinessConfigDto) { + BusinessConfig businessConfig = new BusinessConfig(); + BeanUtils.copyProperties(addBusinessConfigDto, businessConfig); + return ApiResponse.success(businessConfigService.save(businessConfig)); + } +} diff --git a/src/main/java/com/yj/earth/business/controller/IconLibraryController.java b/src/main/java/com/yj/earth/business/controller/IconLibraryController.java new file mode 100644 index 0000000..e350475 --- /dev/null +++ b/src/main/java/com/yj/earth/business/controller/IconLibraryController.java @@ -0,0 +1,396 @@ +package com.yj.earth.business.controller; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.lang.UUID; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.yj.earth.annotation.CheckAuth; +import com.yj.earth.business.domain.IconLibrary; +import com.yj.earth.business.domain.IconType; +import com.yj.earth.business.service.FileInfoService; +import com.yj.earth.business.service.IconLibraryService; +import com.yj.earth.common.util.ApiResponse; +import com.yj.earth.common.util.SQLiteUtil; +import com.yj.earth.dto.iconLibrary.AddIconTypeDto; +import com.yj.earth.dto.iconLibrary.CreateIconLibraryDto; +import com.yj.earth.dto.iconLibrary.DragIconTypeDto; +import com.yj.earth.dto.iconLibrary.UpdateIconTypeNameDto; +import com.yj.earth.vo.IconTypeVo; +import com.yj.earth.vo.IconVo; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.io.File; +import java.io.IOException; +import java.sql.SQLException; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Tag(name = "图标库管理") +@CheckAuth +@RestController +@RequestMapping("/iconLibrary") +public class IconLibraryController { + @Resource + private IconLibraryService iconLibraryService; + @Resource + private FileInfoService fileInfoService; + + @Operation(summary = "创建图标库") + @PostMapping("/createIconLibrary") + public ApiResponse createIconLibrary(@RequestBody CreateIconLibraryDto createIconLibraryDto) { + try { + // 参数校验与路径处理 + String folderPath = createIconLibraryDto.getPath(); + String iconName = createIconLibraryDto.getName(); + File parentDir = new File(folderPath); + File iconFile = new File(parentDir, iconName); + String iconPath = iconFile.getAbsolutePath().replace("\\", "/"); + + // 检查父目录(不存在则创建) + if (!parentDir.exists()) { + boolean mkdirsSuccess = parentDir.mkdirs(); + if (!mkdirsSuccess) { + return ApiResponse.failure("创建图标库父目录失败:" + folderPath); + } + } + + // 检查图标库文件是否已存在 + if (iconFile.exists()) { + if (iconFile.isDirectory()) { + return ApiResponse.failure("同名目录已存在、无法创建图标库文件:" + iconPath); + } + return ApiResponse.failure("图标库文件已存在:" + iconPath); + } + + // 创建图标库文件 + boolean createSuccess = iconFile.createNewFile(); + if (!createSuccess) { + return ApiResponse.failure("创建图标库文件失败:" + iconPath); + } + + // 新增图标库记录并初始化SQLite表结构 + addIconLibrary(iconPath); + SQLiteUtil.initializationIcon(iconPath); + return ApiResponse.success(null); + } catch (Exception e) { + return ApiResponse.failure("创建图标库失败:" + e.getMessage()); + } + } + + @Operation(summary = "导入图标库") + @PostMapping("/importIconLibrary") + public ApiResponse importIconLibrary(@RequestParam("iconPath") @Parameter(description = "图标库路径") String iconPath) { + addIconLibrary(iconPath); + return ApiResponse.success(null); + } + + @Operation(summary = "添加图标类型") + @PostMapping("/addIconType") + public ApiResponse addIconType(@RequestBody AddIconTypeDto addIconTypeDto) throws SQLException, IllegalAccessException, InstantiationException { + String iconPath = getIconLibrary(); + if (iconPath == null) { + return ApiResponse.failure("请先创建或导入图标库"); + } + + // 检查父级图标类型是否存在 + String parentId = addIconTypeDto.getParentId(); + if (parentId != null) { + String sql = "SELECT * FROM icon_type WHERE id = ?"; + List params = new ArrayList<>(); + params.add(parentId); + IconType iconType = SQLiteUtil.queryForObject(iconPath, sql, params, IconType.class); + if (iconType == null) { + return ApiResponse.failure("父级图标类型不存在"); + } + } + + // 插入图标类型 + String sql = "INSERT INTO icon_type " + + "(id, name, parent_id, tree_index, created_at) " + + "VALUES (?, ?, ?, ?, ?)"; + List params = new ArrayList<>(); + params.add(UUID.fastUUID().toString(true)); + params.add(addIconTypeDto.getName()); + params.add(addIconTypeDto.getParentId()); + params.add(0); + params.add(LocalDateTime.now()); + SQLiteUtil.executeUpdate(iconPath, sql, params); + return ApiResponse.success(null); + } + + @Operation(summary = "删除图标类型") + @PostMapping("/deleteIconType") + public ApiResponse deleteIconType(@Parameter(description = "图标类型ID") @RequestParam("iconTypeId") String iconTypeId) throws SQLException { + String iconPath = getIconLibrary(); + if (iconPath == null) { + return ApiResponse.failure("请先创建或导入图标库"); + } + + // 删除图标类型 + String sql = "DELETE FROM icon_type WHERE id = ?"; + List params = new ArrayList<>(); + params.add(iconTypeId); + SQLiteUtil.executeUpdate(iconPath, sql, params); + return ApiResponse.success(null); + } + + @Operation(summary = "修改图标类型名称") + @PostMapping("/updateIconTypeName") + public ApiResponse updateIconTypeName(@RequestBody UpdateIconTypeNameDto updateIconTypeNameDto) throws SQLException { + String iconPath = getIconLibrary(); + if (iconPath == null) { + return ApiResponse.failure("请先创建或导入图标库"); + } + + // 更新图标类型名称 + String sql = "UPDATE icon_type SET name = ? WHERE id = ?"; + List params = new ArrayList<>(); + params.add(updateIconTypeNameDto.getName()); + params.add(updateIconTypeNameDto.getId()); + SQLiteUtil.executeUpdate(iconPath, sql, params); + return ApiResponse.success(null); + } + + @Operation(summary = "图标类型列表") + @GetMapping("/iconTypeTree") + public ApiResponse iconTypeTree() throws SQLException, IllegalAccessException, InstantiationException { + String iconPath = getIconLibrary(); + if (iconPath == 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 icon_type ORDER BY tree_index ASC + """; + List iconTypes = SQLiteUtil.queryForList(iconPath, sql, null, IconType.class); + + // 构建树形结构 + List treeList = buildIconTypeTree(iconTypes); + return ApiResponse.success(treeList); + } + + @Operation(summary = "拖动图标类型树") + @PostMapping("/dragIconType") + public ApiResponse dragIconType(@RequestBody DragIconTypeDto dragIconTypeDto) throws SQLException { + String iconPath = getIconLibrary(); + if (iconPath == null) { + return ApiResponse.failure("请先创建或导入图标库"); + } + + // 动态构建更新SQL + List updateFields = new ArrayList<>(); + List params = new ArrayList<>(); + + if (dragIconTypeDto.getParentId() != null) { + updateFields.add("parent_id = ?"); + params.add(dragIconTypeDto.getParentId()); + } + if (dragIconTypeDto.getTreeIndex() != null) { + updateFields.add("tree_index = ?"); + params.add(dragIconTypeDto.getTreeIndex()); + } + + String sql = "UPDATE icon_type SET " + String.join(", ", updateFields) + " WHERE id = ?"; + params.add(dragIconTypeDto.getId()); + SQLiteUtil.executeUpdate(iconPath, sql, params); + return ApiResponse.success(null); + } + + @Operation(summary = "添加图标文件") + @PostMapping("/addIconFile") + public ApiResponse addIconFile(@RequestParam("files") MultipartFile[] files, + @Parameter(description = "图标类型ID") @RequestParam("iconTypeId") String iconTypeId) + throws IOException, SQLException { + String iconPath = getIconLibrary(); + if (iconPath == null) { + return ApiResponse.failure("请先创建或导入图标库"); + } + + // 循环处理上传文件 + for (MultipartFile file : files) { + if (file.isEmpty()) continue; + + String fileName = file.getOriginalFilename(); + if (fileName == null) continue; + + String fileSuffix = FileUtil.extName(fileName); + String fileNameWithoutSuffix = FileUtil.mainName(fileName); + + // 上传文件并获取访问URL + String url = fileInfoService.uploadWithPreview(file); + + // 插入图标记录 + String sql = "INSERT INTO icon " + + "(id, icon_type_id, icon_name, icon_type, data, created_at) " + + "VALUES (?, ?, ?, ?, ?, ?)"; + List params = new ArrayList<>(); + params.add(UUID.fastUUID().toString(true)); + params.add(iconTypeId); + params.add(fileNameWithoutSuffix); + params.add(fileSuffix); + params.add(url); + params.add(LocalDateTime.now()); + + SQLiteUtil.executeUpdate(iconPath, sql, params); + } + + return ApiResponse.success(null); + } + + @Operation(summary = "根据图标类型查看图标列表") + @PostMapping("/iconList") + public ApiResponse iconList(@Parameter(description = "图标类型ID") @RequestParam("iconTypeId") String iconTypeId) + throws SQLException, IllegalAccessException, InstantiationException { + String iconPath = getIconLibrary(); + if (iconPath == null) { + return ApiResponse.failure("请先创建或导入图标库"); + } + + // 多表联查图标数据 + String sql = """ + SELECT + icon.id, + icon.icon_type_id as iconTypeId, + icon.icon_name as iconName, + icon.icon_type as iconType, + icon.data, + icon.view, + icon.created_at as createdAt, + icon.updated_at as updatedAt, + icon_type.name as iconTypeName + FROM icon + JOIN icon_type ON icon.icon_type_id = icon_type.id + WHERE icon.icon_type_id = ? + """; + List params = new ArrayList<>(); + params.add(iconTypeId); + List iconVos = SQLiteUtil.queryForList(iconPath, sql, params, IconVo.class); + return ApiResponse.success(iconVos); + } + + @Operation(summary = "更新图标信息") + @PostMapping("/updateIconInfo") + public ApiResponse updateIconInfo(@Parameter(description = "图标ID") @RequestParam("iconId") String iconId, + @Parameter(description = "图标名称") @RequestParam(value = "iconName", required = false) String iconName) + throws SQLException { + String iconPath = getIconLibrary(); + if (iconPath == null) { + return ApiResponse.failure("请先创建或导入图标库"); + } + + // 无更新字段直接返回成功 + if (!StringUtils.hasText(iconName)) { + return ApiResponse.success(null); + } + + // 更新图标名称 + String sql = "UPDATE icon SET updated_at = ?, icon_name = ? WHERE id = ?"; + List params = new ArrayList<>(); + params.add(LocalDateTime.now()); + params.add(iconName); + params.add(iconId); + SQLiteUtil.executeUpdate(iconPath, sql, params); + return ApiResponse.success(null); + } + + @Operation(summary = "删除图标") + @PostMapping("/deleteIcon") + public ApiResponse deleteIcon(@Parameter(description = "图标ID") @RequestParam("iconId") String iconId) throws SQLException { + String iconPath = getIconLibrary(); + if (iconPath == null) { + return ApiResponse.failure("请先创建或导入图标库"); + } + + // 删除图标 + String sql = "DELETE FROM icon WHERE id = ?"; + List params = new ArrayList<>(); + params.add(iconId); + SQLiteUtil.executeUpdate(iconPath, sql, params); + return ApiResponse.success(null); + } + + /** + * 构建图标类型树形结构 + * + * @param iconTypes 图标类型列表 + * @return 树形结构列表 + */ + private List buildIconTypeTree(List iconTypes) { + // 转换为VO列表 + List treeNodes = iconTypes.stream() + .map(IconTypeVo::new) + .collect(Collectors.toList()); + + // 构建ID到VO的映射(便于快速查找父节点) + Map nodeMap = treeNodes.stream() + .collect(Collectors.toMap(IconTypeVo::getId, node -> node)); + + // 组装树形结构 + List rootNodes = new ArrayList<>(); + for (IconTypeVo node : treeNodes) { + String parentId = node.getParentId(); + if (parentId == null || parentId.isEmpty()) { + // 无父节点 → 根节点 + rootNodes.add(node); + } else { + // 有父节点 → 加入父节点的子列表 + IconTypeVo parentNode = nodeMap.get(parentId); + if (parentNode != null) { + parentNode.getChildren().add(node); + } + } + } + return rootNodes; + } + + /** + * 获取当前启用的图标库路径 + * + * @return 图标库路径(null表示无启用的图标库) + */ + private String getIconLibrary() { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(IconLibrary::getIsEnable, 1); + IconLibrary iconLibrary = iconLibraryService.getOne(queryWrapper); + return iconLibrary == null ? null : iconLibrary.getPath(); + } + + private void addIconLibrary(String iconPath) { + // 查询所有图标库并置为禁用 + List iconLibraries = iconLibraryService.list(); + for (IconLibrary iconLibrary : iconLibraries) { + iconLibrary.setIsEnable(0); + iconLibraryService.updateById(iconLibrary); + } + + // 检查路径是否已存在(存在则启用、不存在则新增) + LambdaQueryWrapper pathWrapper = new LambdaQueryWrapper<>(); + pathWrapper.eq(IconLibrary::getPath, iconPath); + IconLibrary existingIconLib = iconLibraryService.getOne(pathWrapper); + + if (existingIconLib != null) { + existingIconLib.setIsEnable(1); + iconLibraryService.updateById(existingIconLib); + } else { + // 新增图标库记录 + IconLibrary newIconLib = new IconLibrary(); + File iconFile = FileUtil.file(iconPath); + newIconLib.setId(UUID.fastUUID().toString(true)); + newIconLib.setPath(iconPath); + newIconLib.setName(FileUtil.extName(iconFile)); + newIconLib.setIsEnable(1); + iconLibraryService.save(newIconLib); + } + } +} diff --git a/src/main/java/com/yj/earth/business/controller/MilitaryLibraryController.java b/src/main/java/com/yj/earth/business/controller/MilitaryLibraryController.java new file mode 100644 index 0000000..e260390 --- /dev/null +++ b/src/main/java/com/yj/earth/business/controller/MilitaryLibraryController.java @@ -0,0 +1,387 @@ +package com.yj.earth.business.controller; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.lang.UUID; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.yj.earth.annotation.CheckAuth; +import com.yj.earth.business.domain.MilitaryLibrary; +import com.yj.earth.business.domain.MilitaryType; +import com.yj.earth.business.service.FileInfoService; +import com.yj.earth.business.service.MilitaryLibraryService; +import com.yj.earth.common.util.ApiResponse; +import com.yj.earth.common.util.SQLiteUtil; +import com.yj.earth.dto.militaryLibrary.AddMilitaryTypeDto; +import com.yj.earth.dto.militaryLibrary.CreateMilitaryLibraryDto; +import com.yj.earth.dto.militaryLibrary.DragMilitaryTypeDto; +import com.yj.earth.dto.militaryLibrary.UpdateMilitaryTypeNameDto; +import com.yj.earth.vo.MilitaryTypeVo; +import com.yj.earth.vo.MilitaryVo; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.io.File; +import java.io.IOException; +import java.sql.SQLException; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Tag(name = "军标库管理") +@CheckAuth +@RestController +@RequestMapping("/militaryLibrary") +public class MilitaryLibraryController { + @Resource + private MilitaryLibraryService militaryLibraryService; + @Resource + private FileInfoService fileInfoService; + + @Operation(summary = "创建军标库") + @PostMapping("/createMilitaryLibrary") + public ApiResponse createMilitaryLibrary(@RequestBody CreateMilitaryLibraryDto createMilitaryLibraryDto) { + try { + // 参数校验 + String folderPath = createMilitaryLibraryDto.getPath(); + String militaryName = createMilitaryLibraryDto.getName(); + // 处理路径、组合为完整军标库文件路径 + File parentDir = new File(folderPath); + File militaryFile = new File(parentDir, militaryName); + String militaryPath = militaryFile.getAbsolutePath().replace("\\", "/"); + // 检查父目录是否存在、不存在则创建 + if (!parentDir.exists()) { + boolean mkdirsSuccess = parentDir.mkdirs(); + if (!mkdirsSuccess) { + return ApiResponse.failure("创建父目录失败:" + folderPath); + } + } + // 检查军标库文件是否已存在 + if (militaryFile.exists()) { + if (militaryFile.isDirectory()) { + return ApiResponse.failure("同名目录已存在、无法创建文件:" + militaryPath); + } + return ApiResponse.failure("军标库文件已存在:" + militaryPath); + } + // 创建军标库文件 + boolean createSuccess = militaryFile.createNewFile(); + if (!createSuccess) { + return ApiResponse.failure("创建军标库文件失败:" + militaryPath); + } + // 添加军标库信息 + addMilitaryLibrary(militaryPath); + SQLiteUtil.initializationMilitary(militaryPath); + return ApiResponse.success(null); + } catch (Exception e) { + return ApiResponse.failure("创建军标库失败:" + e.getMessage()); + } + } + + @Operation(summary = "导入军标库") + @PostMapping("/importMilitaryLibrary") + public ApiResponse importMilitaryLibrary(@RequestParam("militaryPath") @Parameter(description = "军标库路径") String militaryPath) { + addMilitaryLibrary(militaryPath); + return ApiResponse.success(null); + } + + @Operation(summary = "添加军标类型") + @PostMapping("/addMilitaryType") + public ApiResponse addMilitaryType(@RequestBody AddMilitaryTypeDto addMilitaryTypeDto) throws SQLException, IllegalAccessException, InstantiationException { + String militaryPath = getMilitaryLibrary(); + if (militaryPath == null) { + return ApiResponse.failure("请先创建或导入军标库"); + } + // 检查父级是否存在 + String parentId = addMilitaryTypeDto.getParentId(); + if (parentId != null) { + String sql = "SELECT * FROM military_type WHERE id = ?"; + List params = new ArrayList<>(); + params.add(parentId); + MilitaryType militaryType = SQLiteUtil.queryForObject(militaryPath, sql, params, MilitaryType.class); + if (militaryType == null) { + return ApiResponse.failure("父级军标类型不存在"); + } + } + String sql = "INSERT INTO military_type " + + "(id, name, parent_id, tree_index, created_at) " + + "VALUES (?, ?, ?, ?, ?)"; + List params = new ArrayList<>(); + params.add(UUID.fastUUID().toString(true)); + params.add(addMilitaryTypeDto.getName()); + params.add(addMilitaryTypeDto.getParentId()); + params.add(0); + params.add(LocalDateTime.now()); + SQLiteUtil.executeUpdate(militaryPath, sql, params); + return ApiResponse.success(null); + } + + @Operation(summary = "删除军标类型") + @PostMapping("/deleteMilitaryType") + public ApiResponse deleteMilitaryType(@Parameter(description = "军标类型ID") @RequestParam("militaryTypeId") String militaryTypeId) throws SQLException { + String militaryPath = getMilitaryLibrary(); + if (militaryPath == null) { + return ApiResponse.failure("请先创建或导入军标库"); + } + String sql = "DELETE FROM military_type WHERE id = ?"; + List params = new ArrayList<>(); + params.add(militaryTypeId); + SQLiteUtil.executeUpdate(militaryPath, sql, params); + return ApiResponse.success(null); + } + + @Operation(summary = "修改军标类型名称") + @PostMapping("/updateMilitaryTypeName") + public ApiResponse updateMilitaryTypeName(@RequestBody UpdateMilitaryTypeNameDto updateMilitaryTypeNameDto) throws SQLException { + String militaryPath = getMilitaryLibrary(); + if (militaryPath == null) { + return ApiResponse.failure("请先创建或导入军标库"); + } + String sql = "UPDATE military_type SET name = ? WHERE id = ?"; + List params = new ArrayList<>(); + params.add(updateMilitaryTypeNameDto.getName()); + params.add(updateMilitaryTypeNameDto.getId()); + SQLiteUtil.executeUpdate(militaryPath, sql, params); + return ApiResponse.success(null); + } + + @Operation(summary = "军标类型列表") + @GetMapping("/militaryTypeList") + public ApiResponse militaryTypeTree() throws SQLException, IllegalAccessException, InstantiationException { + String militaryPath = getMilitaryLibrary(); + if (militaryPath == 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 military_type ORDER BY tree_index ASC + """; + List militaryTypes = SQLiteUtil.queryForList(militaryPath, sql, null, MilitaryType.class); + // 转换为树形结构 + List treeList = buildMilitaryTypeTree(militaryTypes); + return ApiResponse.success(treeList); + } + + @Operation(summary = "拖动军标类型树") + @PostMapping("/dragMilitaryType") + public ApiResponse dragMilitaryType(@RequestBody DragMilitaryTypeDto dragMilitaryTypeDto) throws SQLException { + String militaryPath = getMilitaryLibrary(); + if (militaryPath == null) { + return ApiResponse.failure("请先创建或导入军标库"); + } + + // 动态构建SQL和参数 + List updateFields = new ArrayList<>(); + List params = new ArrayList<>(); + + // 判断 parentId 是否存在 + if (dragMilitaryTypeDto.getParentId() != null) { + updateFields.add("parent_id = ?"); + params.add(dragMilitaryTypeDto.getParentId()); + } + + // 判断 treeIndex 是否存在 + if (dragMilitaryTypeDto.getTreeIndex() != null) { + updateFields.add("tree_index = ?"); + params.add(dragMilitaryTypeDto.getTreeIndex()); + } + + // 构建完整 SQL + String sql = "UPDATE military_type SET " + String.join(", ", updateFields) + " WHERE id = ?"; + params.add(dragMilitaryTypeDto.getId()); + SQLiteUtil.executeUpdate(militaryPath, sql, params); + return ApiResponse.success(null); + } + + @Operation(summary = "添加军标文件") + @PostMapping("/addMilitaryFile") + public ApiResponse addMilitaryFile(@RequestParam("files") MultipartFile[] files, @Parameter(description = "军标类型ID") @RequestParam("militaryTypeId") String militaryTypeId) throws IOException, SQLException { + // 获取最新的军标库路径 + String militaryPath = getMilitaryLibrary(); + if (militaryPath == null) { + return ApiResponse.failure("请先创建或导入军标库"); + } + // 循环处理每个上传的文件 + for (MultipartFile file : files) { + // 跳过空文件 + if (file.isEmpty()) { + continue; + } + // 获取文件信息 + String fileName = file.getOriginalFilename(); + if (fileName == null) { + continue; + } + String fileSuffix = FileUtil.extName(fileName); + String fileNameWithoutSuffix = FileUtil.mainName(fileName); + + // 构建插入SQL + String sql = "INSERT INTO military " + + "(id, military_type_id, military_name, military_type, data, created_at) " + + "VALUES (?, ?, ?, ?, ?, ?)"; + + String url = fileInfoService.uploadWithPreview(file); + List params = new ArrayList<>(); + params.add(UUID.fastUUID().toString(true)); + params.add(militaryTypeId); + params.add(fileNameWithoutSuffix); + params.add(fileSuffix); + params.add(url); + params.add(LocalDateTime.now()); + + // 执行插入操作 + SQLiteUtil.executeUpdate(militaryPath, sql, params); + } + + return ApiResponse.success(null); + } + + @Operation(summary = "根据军标类型查看军标列表") + @PostMapping("/militaryList") + public ApiResponse militaryList(@Parameter(description = "军标类型ID") @RequestParam("militaryTypeId") String militaryTypeId) throws SQLException, IllegalAccessException, InstantiationException { + // 获取最新的军标库 + String militaryPath = getMilitaryLibrary(); + if (militaryPath == null) { + return ApiResponse.failure("请先创建或导入军标库"); + } + // 多表联查、查询所有的军标 + String sql = """ + SELECT + military.id, + military.military_type_id as militaryTypeId, + military.military_name as militaryName, + military.military_type as militaryType, + military.data, + military.view, + military.created_at as createdAt, + military.updated_at as updatedAt, + military_type.name as militaryTypeName from + military JOIN military_type ON military.military_type_id = military_type.id + WHERE military.military_type_id = ? + """; + List params = new ArrayList<>(); + params.add(militaryTypeId); + List militaryVos = SQLiteUtil.queryForList(militaryPath, sql, params, MilitaryVo.class); + return ApiResponse.success(militaryVos); + } + + @Operation(summary = "更新军标信息") + @PostMapping("/uploadMilitaryInfo") + public ApiResponse uploadMilitaryInfo( + @Parameter(description = "军标ID") @RequestParam("militaryId") String militaryId, + @Parameter(description = "军标名称") @RequestParam(value = "militaryName", required = false) String militaryName) + throws SQLException { + + // 获取最新的军标库路径 + String militaryPath = getMilitaryLibrary(); + if (militaryPath == null) { + return ApiResponse.failure("请先创建或导入军标库"); + } + + // 如果没有需要更新的字段、直接返回成功 + if (!StringUtils.hasText(militaryName)) { + return ApiResponse.success(null); + } + + // 构建更新SQL和参数 + String sql = "UPDATE military SET updated_at = ?, military_name = ? WHERE id = ?"; + List params = new ArrayList<>(); + params.add(LocalDateTime.now()); + params.add(militaryName); + params.add(militaryId); + + // 执行更新 + SQLiteUtil.executeUpdate(militaryPath, sql, params); + return ApiResponse.success(null); + } + + + @Operation(summary = "删除军标") + @PostMapping("/deleteMilitary") + public ApiResponse deleteMilitary(@Parameter(description = "军标ID") @RequestParam("militaryId") String militaryId) throws SQLException { + String militaryPath = getMilitaryLibrary(); + if (militaryPath == null) { + return ApiResponse.failure("请先创建或导入军标库"); + } + String sql = "DELETE FROM military WHERE id = ?"; + List params = new ArrayList<>(); + params.add(militaryId); + SQLiteUtil.executeUpdate(militaryPath, sql, params); + return ApiResponse.success(null); + } + + private List buildMilitaryTypeTree(List militaryTypes) { + List treeNodes = militaryTypes.stream() + .map(militaryType -> new MilitaryTypeVo(militaryType)) + .collect(Collectors.toList()); + // 构建节点ID到节点的映射 + Map nodeMap = treeNodes.stream() + .collect(Collectors.toMap(MilitaryTypeVo::getId, node -> node)); + // 根节点列表 + List rootNodes = new ArrayList<>(); + // 为每个节点添加子节点 + for (MilitaryTypeVo node : treeNodes) { + String parentId = node.getParentId(); + if (parentId == null || parentId.isEmpty()) { + // 没有父节点的是根节点 + rootNodes.add(node); + } else { + // 找到父节点并添加为子节点 + MilitaryTypeVo parentNode = nodeMap.get(parentId); + if (parentNode != null) { + parentNode.getChildren().add(node); + } + } + } + + return rootNodes; + } + + private String getMilitaryLibrary() { + // 获取启用的军标库 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(MilitaryLibrary::getIsEnable, 1); + MilitaryLibrary militaryLibrary = militaryLibraryService.getOne(queryWrapper); + if (militaryLibrary == null) { + return null; + } + return militaryLibrary.getPath(); + } + + private void addMilitaryLibrary(String militaryPath) { + // 查询系统所有的军标库 + List militaryLibraries = militaryLibraryService.list(); + // 遍历并更新状态 + for (MilitaryLibrary militaryLibrary : militaryLibraries) { + // 设置启用状态为0 + militaryLibrary.setIsEnable(0); + militaryLibraryService.updateById(militaryLibrary); + } + + // 检查相同路径的军标库是否已存在 + LambdaQueryWrapper pathWrapper = new LambdaQueryWrapper<>(); + pathWrapper.eq(MilitaryLibrary::getPath, militaryPath); + MilitaryLibrary existingMilitary = militaryLibraryService.getOne(pathWrapper); + // 若存在相同路径的军标库、不做处理、仅仅更新状态为显示 + if (existingMilitary != null) { + existingMilitary.setIsEnable(1); + militaryLibraryService.updateById(existingMilitary); + return; + } else { + // 新增军标库 + MilitaryLibrary newMilitary = new MilitaryLibrary(); + File file = FileUtil.file(militaryPath); + newMilitary.setId(UUID.fastUUID().toString(true)); + newMilitary.setPath(militaryPath); + newMilitary.setName(FileUtil.extName(file)); + newMilitary.setIsEnable(1); + militaryLibraryService.save(newMilitary); + } + } +} diff --git a/src/main/java/com/yj/earth/business/controller/ModelLibraryController.java b/src/main/java/com/yj/earth/business/controller/ModelLibraryController.java new file mode 100644 index 0000000..99188f1 --- /dev/null +++ b/src/main/java/com/yj/earth/business/controller/ModelLibraryController.java @@ -0,0 +1,395 @@ +package com.yj.earth.business.controller; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.lang.UUID; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.yj.earth.annotation.CheckAuth; +import com.yj.earth.business.domain.ModelLibrary; +import com.yj.earth.business.domain.ModelType; +import com.yj.earth.business.service.FileInfoService; +import com.yj.earth.business.service.ModelLibraryService; +import com.yj.earth.common.util.ApiResponse; +import com.yj.earth.common.util.SQLiteUtil; +import com.yj.earth.dto.militaryLibrary.DragMilitaryTypeDto; +import com.yj.earth.dto.modelLibrary.AddModelTypeDto; +import com.yj.earth.dto.modelLibrary.CreateModelLibraryDto; +import com.yj.earth.dto.modelLibrary.DragModelTypeDto; +import com.yj.earth.dto.modelLibrary.UpdateModelTypeNameDto; +import com.yj.earth.vo.ModelTypeVo; +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.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.io.File; +import java.io.IOException; +import java.sql.SQLException; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Tag(name = "模型库管理") +@CheckAuth +@RestController +@RequestMapping("/modelLibrary") +public class ModelLibraryController { + @Resource + private ModelLibraryService modelLibraryService; + @Resource + private FileInfoService fileInfoService; + + @Operation(summary = "创建模型库") + @PostMapping("/createModelLibrary") + public ApiResponse createModelLibrary(@RequestBody CreateModelLibraryDto createModelLibraryDto) { + try { + // 参数校验 + String folderPath = createModelLibraryDto.getPath(); + String modelName = createModelLibraryDto.getName(); + // 处理路径、组合为完整模型库文件路径(.model后缀) + File parentDir = new File(folderPath); + File modelFile = new File(parentDir, modelName + ".model"); + String modelPath = modelFile.getAbsolutePath().replace("\\", "/"); + // 检查父目录是否存在、不存在则创建 + if (!parentDir.exists()) { + boolean mkdirsSuccess = parentDir.mkdirs(); + if (!mkdirsSuccess) { + return ApiResponse.failure("创建父目录失败:" + folderPath); + } + } + // 检查模型库文件是否已存在 + if (modelFile.exists()) { + if (modelFile.isDirectory()) { + return ApiResponse.failure("同名目录已存在、无法创建文件:" + modelPath); + } + return ApiResponse.failure("模型库文件已存在:" + modelPath); + } + // 创建模型库文件( + boolean createSuccess = modelFile.createNewFile(); + if (!createSuccess) { + return ApiResponse.failure("创建模型库文件失败:" + modelPath); + } + // 添加模型库信息 + addModelLibrary(modelPath); + SQLiteUtil.initializationModel(modelPath); + return ApiResponse.success(null); + } catch (Exception e) { + return ApiResponse.failure("创建模型库失败:" + e.getMessage()); + } + } + + @Operation(summary = "导入模型库") + @PostMapping("/importModelLibrary") + public ApiResponse importModelLibrary(@RequestParam("modelPath") @Parameter(description = "模型库路径") String modelPath) { + addModelLibrary(modelPath); + return ApiResponse.success(null); + } + + @Operation(summary = "添加模型类型") + @PostMapping("/addModelType") + public ApiResponse addModelType(@RequestBody AddModelTypeDto addModelTypeDto) throws SQLException, IllegalAccessException, InstantiationException { + String modelPath = getModelLibrary(); + if (modelPath == null) { + return ApiResponse.failure("请先创建或导入模型库"); + } + // 检查父级是否存在 + String parentId = addModelTypeDto.getParentId(); + if (parentId != null) { + String sql = "SELECT * FROM model_type WHERE id = ?"; + List params = new ArrayList<>(); + params.add(parentId); + ModelType modelType = SQLiteUtil.queryForObject(modelPath, sql, params, ModelType.class); + if (modelType == null) { + return ApiResponse.failure("父级模型类型不存在"); + } + } + String sql = "INSERT INTO model_type " + + "(id, name, parent_id, tree_index, created_at) " + + "VALUES (?, ?, ?, ?, ?)"; + List params = new ArrayList<>(); + params.add(UUID.fastUUID().toString(true)); + params.add(addModelTypeDto.getName()); + params.add(addModelTypeDto.getParentId()); + params.add(0); + params.add(LocalDateTime.now()); + SQLiteUtil.executeUpdate(modelPath, sql, params); + return ApiResponse.success(null); + } + + @Operation(summary = "修改模型类型名称") + @PostMapping("/updateModelTypeName") + public ApiResponse updateModelTypeName(@RequestBody UpdateModelTypeNameDto updateModelTypeNameDto) throws SQLException { + String modelPath = getModelLibrary(); + if (modelPath == null) { + return ApiResponse.failure("请先创建或导入模型库"); + } + String sql = "UPDATE model_type SET name = ? WHERE id = ?"; + List params = new ArrayList<>(); + params.add(updateModelTypeNameDto.getName()); + params.add(updateModelTypeNameDto.getId()); + SQLiteUtil.executeUpdate(modelPath, sql, params); + return ApiResponse.success(null); + } + + @Operation(summary = "删除模型类型") + @PostMapping("/deleteModelType") + public ApiResponse deleteModelType(@Parameter(description = "模型类型ID") @RequestParam("modelTypeId") String modelTypeId) throws SQLException { + String modelPath = getModelLibrary(); + if (modelPath == null) { + return ApiResponse.failure("请先创建或导入模型库"); + } + String sql = "DELETE FROM model_type WHERE id = ?"; + List params = new ArrayList<>(); + params.add(modelTypeId); + SQLiteUtil.executeUpdate(modelPath, sql, params); + return ApiResponse.success(null); + } + + @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 modelTypes = SQLiteUtil.queryForList(modelPath, sql, null, ModelType.class); + // 转换为树形结构 + List treeList = buildModelTypeTree(modelTypes); + return ApiResponse.success(treeList); + } + + @Operation(summary = "拖动模型类型树") + @PostMapping("/dragModelType") + public ApiResponse dragMilitaryType(@RequestBody DragModelTypeDto dragModelTypeDto) throws SQLException { + String militaryPath = getModelLibrary(); + if (militaryPath == null) { + return ApiResponse.failure("请先创建或导入模型库"); + } + + // 动态构建SQL和参数 + List updateFields = new ArrayList<>(); + List params = new ArrayList<>(); + + // 判断 parentId 是否存在 + if (dragModelTypeDto.getParentId() != null) { + updateFields.add("parent_id = ?"); + params.add(dragModelTypeDto.getParentId()); + } + + // 判断 treeIndex 是否存在 + if (dragModelTypeDto.getTreeIndex() != null) { + updateFields.add("tree_index = ?"); + params.add(dragModelTypeDto.getTreeIndex()); + } + + // 构建完整 SQL + String sql = "UPDATE model_type SET " + String.join(", ", updateFields) + " WHERE id = ?"; + params.add(dragModelTypeDto.getId()); + SQLiteUtil.executeUpdate(militaryPath, sql, params); + 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 { + // 获取最新的模型库路径 + String modelPath = getModelLibrary(); + if (modelPath == null) { + return ApiResponse.failure("请先创建或导入模型库"); + } + // 循环处理每个上传的文件 + for (MultipartFile file : files) { + // 跳过空文件 + if (file.isEmpty()) { + continue; + } + // 获取文件信息 + String fileName = file.getOriginalFilename(); + if (fileName == null) { + continue; + } + String fileSuffix = FileUtil.extName(fileName); + String fileNameWithoutSuffix = FileUtil.mainName(fileName); + + // 构建插入SQL + String sql = "INSERT INTO model " + + "(id, model_type_id, model_name, model_type, data, created_at) " + + "VALUES (?, ?, ?, ?, ?, ?)"; + + String url = fileInfoService.uploadWithPreview(file); + List params = new ArrayList<>(); + params.add(UUID.fastUUID().toString(true)); + params.add(modelTypeId); + params.add(fileNameWithoutSuffix); + params.add(fileSuffix); + params.add(url); + params.add(LocalDateTime.now()); + + // 执行插入操作 + SQLiteUtil.executeUpdate(modelPath, sql, params); + } + + return ApiResponse.success(null); + } + + @Operation(summary = "根据模型类型查看模型列表") + @PostMapping("/modelList") + public ApiResponse modelList(@Parameter(description = "模型类型ID") @RequestParam("modelTypeId") String modelTypeId) throws SQLException, IllegalAccessException, InstantiationException { + // 获取最新的模型库 + String modelPath = getModelLibrary(); + if (modelPath == null) { + return ApiResponse.failure("请先创建或导入模型库"); + } + // 多表联查、查询所有的模型 + String sql = """ + SELECT + model.id, + model.model_type_id as modelTypeId, + model.model_name as modelName, + model.model_type as modelType, + model.poster_type as posterType, + model.poster, + model.data, + model.view, + model.created_at as createdAt, + model.updated_at as updatedAt, + model_type.name as modelTypeName from + model JOIN model_type ON model.model_type_id = model_type.id + WHERE model.model_type_id = ? + """; + List params = new ArrayList<>(); + params.add(modelTypeId); + List modelVos = SQLiteUtil.queryForList(modelPath, sql, params, ModelVo.class); + return ApiResponse.success(modelVos); + } + + @Operation(summary = "更新模型信息") + @PostMapping("/uploadModelInfo") + public ApiResponse uploadModelInfo(@Parameter(description = "模型封面文件") @RequestParam(value = "file", required = false) MultipartFile file, @Parameter(description = "模型ID") @RequestParam("modelId") String modelId, @Parameter(description = "模型名称") @RequestParam(value = "modelName", required = false) String modelName) throws IOException, SQLException { + + // 获取最新的模型库路径 + String modelPath = getModelLibrary(); + if (modelPath == null) { + return ApiResponse.failure("请先创建或导入模型库"); + } + // 动态构建SQL更新语句和参数 + StringBuilder sql = new StringBuilder("UPDATE model SET updated_at = ? "); + List params = new ArrayList<>(); + // 始终更新时间 + params.add(LocalDateTime.now()); + // 处理封面文件 + if (file != null && !file.isEmpty()) { + String fileSuffix = FileUtil.extName(file.getOriginalFilename()); + String url = fileInfoService.uploadWithPreview(file); + sql.append(", poster_type = ?, poster = ? "); + params.add(fileSuffix); + params.add(url); + } + + // 处理模型名称 + if (StringUtils.hasText(modelName)) { + sql.append(", model_name = ? "); + params.add(modelName); + } + // 拼接WHERE条件 + sql.append("WHERE id = ?"); + params.add(modelId); + // 执行更新 + SQLiteUtil.executeUpdate(modelPath, sql.toString(), params); + return ApiResponse.success(null); + } + + @Operation(summary = "删除模型") + @PostMapping("/deleteModel") + public ApiResponse deleteModel(@Parameter(description = "模型ID") @RequestParam("modelId") String modelId) throws SQLException { + String modelPath = getModelLibrary(); + if (modelPath == null) { + return ApiResponse.failure("请先创建或导入模型库"); + } + String sql = "DELETE FROM model WHERE id = ?"; + List params = new ArrayList<>(); + params.add(modelId); + SQLiteUtil.executeUpdate(modelPath, sql, params); + return ApiResponse.success(null); + } + + private List buildModelTypeTree(List modelTypes) { + List treeNodes = modelTypes.stream() + .map(modelType -> new ModelTypeVo(modelType)) + .collect(Collectors.toList()); + // 构建节点ID到节点的映射 + Map nodeMap = treeNodes.stream() + .collect(Collectors.toMap(ModelTypeVo::getId, node -> node)); + // 根节点列表 + List rootNodes = new ArrayList<>(); + // 为每个节点添加子节点 + for (ModelTypeVo node : treeNodes) { + String parentId = node.getParentId(); + if (parentId == null || parentId.isEmpty()) { + // 没有父节点的是根节点 + rootNodes.add(node); + } else { + // 找到父节点并添加为子节点 + ModelTypeVo parentNode = nodeMap.get(parentId); + if (parentNode != null) { + parentNode.getChildren().add(node); + } + } + } + return rootNodes; + } + + private String getModelLibrary() { + // 获取启用的模型库 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(ModelLibrary::getIsEnable, 1); + ModelLibrary modelLibrary = modelLibraryService.getOne(queryWrapper); + if (modelLibrary == null) { + return null; + } + return modelLibrary.getPath(); + } + + private void addModelLibrary(String modelPath) { + // 查询系统所有的模型库 + List modelLibraries = modelLibraryService.list(); + // 遍历并更新状态 + for (ModelLibrary modelLibrary : modelLibraries) { + // 设置启用状态为0 + modelLibrary.setIsEnable(0); + modelLibraryService.updateById(modelLibrary); + } + + // 检查相同路径的模型库是否已存在 + LambdaQueryWrapper pathWrapper = new LambdaQueryWrapper<>(); + pathWrapper.eq(ModelLibrary::getPath, modelPath); + ModelLibrary existingModel = modelLibraryService.getOne(pathWrapper); + // 若存在相同路径的模型库、不做处理、仅仅更新状态为显示 + if (existingModel != null) { + existingModel.setIsEnable(1); + modelLibraryService.updateById(existingModel); + return; + } else { + // 新增模型库 + ModelLibrary newModel = new ModelLibrary(); + File file = FileUtil.file(modelPath); + newModel.setId(UUID.fastUUID().toString(true)); + newModel.setPath(modelPath); + newModel.setName(FileUtil.extName(file)); + newModel.setIsEnable(1); + modelLibraryService.save(newModel); + } + } +} diff --git a/src/main/java/com/yj/earth/business/domain/BusinessConfig.java b/src/main/java/com/yj/earth/business/domain/BusinessConfig.java new file mode 100644 index 0000000..204cf67 --- /dev/null +++ b/src/main/java/com/yj/earth/business/domain/BusinessConfig.java @@ -0,0 +1,40 @@ +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 com.baomidou.mybatisplus.annotation.TableName; + +import java.io.Serializable; +import java.time.LocalDateTime; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +@Data +public class BusinessConfig implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "主键") + @TableId(value = "id", type = IdType.ASSIGN_UUID) + private String id; + + @Schema(description = "键") + private String key; + + @Schema(description = "值") + private String value; + + @Schema(description = "创建时间") + @TableField(fill = FieldFill.INSERT) + private LocalDateTime createdAt; + + @Schema(description = "更新时间") + @TableField(fill = FieldFill.UPDATE) + private LocalDateTime updatedAt; +} diff --git a/src/main/java/com/yj/earth/business/domain/IconLibrary.java b/src/main/java/com/yj/earth/business/domain/IconLibrary.java new file mode 100644 index 0000000..370009c --- /dev/null +++ b/src/main/java/com/yj/earth/business/domain/IconLibrary.java @@ -0,0 +1,53 @@ +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 com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import java.time.LocalDateTime; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +/** + *

+ * + *

+ * + * @author 周志雄 + * @since 2025-09-24 + */ +@Getter +@Setter +@Accessors(chain = true) +@TableName("icon_library") +@Schema(name = "IconLibrary", description = "") +public class IconLibrary implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "主键") + @TableId(value = "id", type = IdType.ASSIGN_UUID) + private String id; + + @Schema(description = "生成文件夹路径") + private String path; + + @Schema(description = "图标库文件名称") + private String name; + + @Schema(description = "是否启用") + private Integer isEnable; + + @Schema(description = "创建时间") + @TableField(fill = FieldFill.INSERT) + private LocalDateTime createdAt; + + @Schema(description = "更新时间") + @TableField(fill = FieldFill.UPDATE) + private LocalDateTime updatedAt; +} diff --git a/src/main/java/com/yj/earth/business/domain/MilitaryLibrary.java b/src/main/java/com/yj/earth/business/domain/MilitaryLibrary.java new file mode 100644 index 0000000..7f67dde --- /dev/null +++ b/src/main/java/com/yj/earth/business/domain/MilitaryLibrary.java @@ -0,0 +1,42 @@ +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 com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import java.time.LocalDateTime; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +@Data +public class MilitaryLibrary implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "主键") + @TableId(value = "id", type = IdType.ASSIGN_UUID) + private String id; + + @Schema(description = "生成文件夹路径") + private String path; + + @Schema(description = "军标库文件名称") + private String name; + + @Schema(description = "是否启用") + private Integer isEnable; + + @Schema(description = "创建时间") + @TableField(fill = FieldFill.INSERT) + private LocalDateTime createdAt; + + @Schema(description = "更新时间") + @TableField(fill = FieldFill.UPDATE) + private LocalDateTime updatedAt; +} diff --git a/src/main/java/com/yj/earth/business/domain/ModelLibrary.java b/src/main/java/com/yj/earth/business/domain/ModelLibrary.java new file mode 100644 index 0000000..cf4ae83 --- /dev/null +++ b/src/main/java/com/yj/earth/business/domain/ModelLibrary.java @@ -0,0 +1,42 @@ +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 com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import java.time.LocalDateTime; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +@Data +public class ModelLibrary implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "主键") + @TableId(value = "id", type = IdType.ASSIGN_UUID) + private String id; + + @Schema(description = "生成文件夹路径") + private String path; + + @Schema(description = "模型库文件名称") + private String name; + + @Schema(description = "是否启用") + private Integer isEnable; + + @Schema(description = "创建时间") + @TableField(fill = FieldFill.INSERT) + private LocalDateTime createdAt; + + @Schema(description = "更新时间") + @TableField(fill = FieldFill.UPDATE) + private LocalDateTime updatedAt; +} diff --git a/src/main/java/com/yj/earth/business/mapper/BusinessConfigMapper.java b/src/main/java/com/yj/earth/business/mapper/BusinessConfigMapper.java new file mode 100644 index 0000000..19b464b --- /dev/null +++ b/src/main/java/com/yj/earth/business/mapper/BusinessConfigMapper.java @@ -0,0 +1,18 @@ +package com.yj.earth.business.mapper; + +import com.yj.earth.business.domain.BusinessConfig; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author 周志雄 + * @since 2025-09-22 + */ +@Mapper +public interface BusinessConfigMapper extends BaseMapper { + +} diff --git a/src/main/java/com/yj/earth/business/mapper/IconLibraryMapper.java b/src/main/java/com/yj/earth/business/mapper/IconLibraryMapper.java new file mode 100644 index 0000000..dbb6997 --- /dev/null +++ b/src/main/java/com/yj/earth/business/mapper/IconLibraryMapper.java @@ -0,0 +1,18 @@ +package com.yj.earth.business.mapper; + +import com.yj.earth.business.domain.IconLibrary; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author 周志雄 + * @since 2025-09-24 + */ +@Mapper +public interface IconLibraryMapper extends BaseMapper { + +} diff --git a/src/main/java/com/yj/earth/business/mapper/MilitaryLibraryMapper.java b/src/main/java/com/yj/earth/business/mapper/MilitaryLibraryMapper.java new file mode 100644 index 0000000..c87a2a8 --- /dev/null +++ b/src/main/java/com/yj/earth/business/mapper/MilitaryLibraryMapper.java @@ -0,0 +1,18 @@ +package com.yj.earth.business.mapper; + +import com.yj.earth.business.domain.MilitaryLibrary; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author 周志雄 + * @since 2025-09-23 + */ +@Mapper +public interface MilitaryLibraryMapper extends BaseMapper { + +} diff --git a/src/main/java/com/yj/earth/business/mapper/ModelLibraryMapper.java b/src/main/java/com/yj/earth/business/mapper/ModelLibraryMapper.java new file mode 100644 index 0000000..8ee6483 --- /dev/null +++ b/src/main/java/com/yj/earth/business/mapper/ModelLibraryMapper.java @@ -0,0 +1,18 @@ +package com.yj.earth.business.mapper; + +import com.yj.earth.business.domain.ModelLibrary; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author 周志雄 + * @since 2025-09-17 + */ +@Mapper +public interface ModelLibraryMapper extends BaseMapper { + +} diff --git a/src/main/java/com/yj/earth/business/service/BusinessConfigService.java b/src/main/java/com/yj/earth/business/service/BusinessConfigService.java new file mode 100644 index 0000000..485a9d4 --- /dev/null +++ b/src/main/java/com/yj/earth/business/service/BusinessConfigService.java @@ -0,0 +1,16 @@ +package com.yj.earth.business.service; + +import com.yj.earth.business.domain.BusinessConfig; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author 周志雄 + * @since 2025-09-22 + */ +public interface BusinessConfigService extends IService { + +} diff --git a/src/main/java/com/yj/earth/business/service/IconLibraryService.java b/src/main/java/com/yj/earth/business/service/IconLibraryService.java new file mode 100644 index 0000000..18f00d3 --- /dev/null +++ b/src/main/java/com/yj/earth/business/service/IconLibraryService.java @@ -0,0 +1,16 @@ +package com.yj.earth.business.service; + +import com.yj.earth.business.domain.IconLibrary; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author 周志雄 + * @since 2025-09-24 + */ +public interface IconLibraryService extends IService { + +} diff --git a/src/main/java/com/yj/earth/business/service/MilitaryLibraryService.java b/src/main/java/com/yj/earth/business/service/MilitaryLibraryService.java new file mode 100644 index 0000000..21df1ee --- /dev/null +++ b/src/main/java/com/yj/earth/business/service/MilitaryLibraryService.java @@ -0,0 +1,16 @@ +package com.yj.earth.business.service; + +import com.yj.earth.business.domain.MilitaryLibrary; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author 周志雄 + * @since 2025-09-23 + */ +public interface MilitaryLibraryService extends IService { + +} diff --git a/src/main/java/com/yj/earth/business/service/ModelLibraryService.java b/src/main/java/com/yj/earth/business/service/ModelLibraryService.java new file mode 100644 index 0000000..ed3e447 --- /dev/null +++ b/src/main/java/com/yj/earth/business/service/ModelLibraryService.java @@ -0,0 +1,16 @@ +package com.yj.earth.business.service; + +import com.yj.earth.business.domain.ModelLibrary; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author 周志雄 + * @since 2025-09-17 + */ +public interface ModelLibraryService extends IService { + +} diff --git a/src/main/java/com/yj/earth/business/service/impl/BusinessConfigServiceImpl.java b/src/main/java/com/yj/earth/business/service/impl/BusinessConfigServiceImpl.java new file mode 100644 index 0000000..f5a328a --- /dev/null +++ b/src/main/java/com/yj/earth/business/service/impl/BusinessConfigServiceImpl.java @@ -0,0 +1,20 @@ +package com.yj.earth.business.service.impl; + +import com.yj.earth.business.domain.BusinessConfig; +import com.yj.earth.business.mapper.BusinessConfigMapper; +import com.yj.earth.business.service.BusinessConfigService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author 周志雄 + * @since 2025-09-22 + */ +@Service +public class BusinessConfigServiceImpl extends ServiceImpl implements BusinessConfigService { + +} diff --git a/src/main/java/com/yj/earth/business/service/impl/IconLibraryServiceImpl.java b/src/main/java/com/yj/earth/business/service/impl/IconLibraryServiceImpl.java new file mode 100644 index 0000000..94daf47 --- /dev/null +++ b/src/main/java/com/yj/earth/business/service/impl/IconLibraryServiceImpl.java @@ -0,0 +1,20 @@ +package com.yj.earth.business.service.impl; + +import com.yj.earth.business.domain.IconLibrary; +import com.yj.earth.business.mapper.IconLibraryMapper; +import com.yj.earth.business.service.IconLibraryService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author 周志雄 + * @since 2025-09-24 + */ +@Service +public class IconLibraryServiceImpl extends ServiceImpl implements IconLibraryService { + +} diff --git a/src/main/java/com/yj/earth/business/service/impl/MilitaryLibraryServiceImpl.java b/src/main/java/com/yj/earth/business/service/impl/MilitaryLibraryServiceImpl.java new file mode 100644 index 0000000..fed6a52 --- /dev/null +++ b/src/main/java/com/yj/earth/business/service/impl/MilitaryLibraryServiceImpl.java @@ -0,0 +1,20 @@ +package com.yj.earth.business.service.impl; + +import com.yj.earth.business.domain.MilitaryLibrary; +import com.yj.earth.business.mapper.MilitaryLibraryMapper; +import com.yj.earth.business.service.MilitaryLibraryService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author 周志雄 + * @since 2025-09-23 + */ +@Service +public class MilitaryLibraryServiceImpl extends ServiceImpl implements MilitaryLibraryService { + +} diff --git a/src/main/java/com/yj/earth/business/service/impl/ModelLibraryServiceImpl.java b/src/main/java/com/yj/earth/business/service/impl/ModelLibraryServiceImpl.java new file mode 100644 index 0000000..00c550e --- /dev/null +++ b/src/main/java/com/yj/earth/business/service/impl/ModelLibraryServiceImpl.java @@ -0,0 +1,20 @@ +package com.yj.earth.business.service.impl; + +import com.yj.earth.business.domain.ModelLibrary; +import com.yj.earth.business.mapper.ModelLibraryMapper; +import com.yj.earth.business.service.ModelLibraryService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author 周志雄 + * @since 2025-09-17 + */ +@Service +public class ModelLibraryServiceImpl extends ServiceImpl implements ModelLibraryService { + +} diff --git a/src/main/resources/mapper/BusinessConfigMapper.xml b/src/main/resources/mapper/BusinessConfigMapper.xml new file mode 100644 index 0000000..8894aa3 --- /dev/null +++ b/src/main/resources/mapper/BusinessConfigMapper.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + id, key, value, created_at, updated_at + + + diff --git a/src/main/resources/mapper/IconLibraryMapper.xml b/src/main/resources/mapper/IconLibraryMapper.xml new file mode 100644 index 0000000..d0f6f5a --- /dev/null +++ b/src/main/resources/mapper/IconLibraryMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + id, path, name, is_enable, created_at, updated_at + + + diff --git a/src/main/resources/mapper/MilitaryLibraryMapper.xml b/src/main/resources/mapper/MilitaryLibraryMapper.xml new file mode 100644 index 0000000..8d207cc --- /dev/null +++ b/src/main/resources/mapper/MilitaryLibraryMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + id, path, name, is_enable, created_at, updated_at + + + diff --git a/src/main/resources/mapper/ModelLibraryMapper.xml b/src/main/resources/mapper/ModelLibraryMapper.xml new file mode 100644 index 0000000..a40aeb1 --- /dev/null +++ b/src/main/resources/mapper/ModelLibraryMapper.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + id, path, name, is_enable, created_at, updated_at + + +