feat(admin): Java 补齐后台缺失能力(软件版本/图生视频管理/店铺记录列表)与菜单排序
将 Flask 后台仅本地实现、Java 缺失的模块落为原生端点(替代 15124 本地面,
向"单一 Java 后台、可退役 15124"收敛):
- softwareversion: GET /api/admin/versions、POST /api/admin/version(web_config +
公开桶 nanri-image/versions/ 直链,桌面端"检测更新"同表兼容)
- imagevideo 管理端: GET /api/admin/image-video-tasks、/{taskId}、
POST /download-zip(近3天 IMAGE_VIDEO_WORKFLOW,语义对齐 Flask)
- shopdatacrawl 管理端: GET /api/admin/shop-data-crawl-tasks(按店分组取最新结果,
窗口函数)、POST /download-zip(流式 + X-Archive-*-Count)
- 权限: 菜单同级拖拽排序 POST /column/reorder(事务内按序重排兄弟 sort_order);
PermissionMenuCreate/UpdateRequest 补 snake_case 别名兼容旧控制台 body
以上端点均 requireAdminOrInternal 鉴权;含 PermissionMenuService 早前已改动的
hasAnyAdminMenu 等菜单权限逻辑(本迁移一环)。
This commit is contained in:
+56
@@ -0,0 +1,56 @@
|
||||
package com.nanri.aiimage.modules.softwareversion.controller;
|
||||
|
||||
import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.modules.admin.support.AdminAuthSupport;
|
||||
import com.nanri.aiimage.modules.permission.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.modules.softwareversion.service.SoftwareVersionService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 客户端软件版本管理(替代 Flask /api/admin/versions、/api/admin/version 本地实现)。
|
||||
* <p>读写旧表 web_config;"数字人版本"走 digitalhuman 模块(/api/digital-human/versions),与本接口无关。
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/admin")
|
||||
@Tag(name = "客户端软件版本管理", description = "桌面客户端软件安装包版本管理:列表与上传,数据落 web_config 表")
|
||||
public class SoftwareVersionAdminController {
|
||||
|
||||
private final SoftwareVersionService softwareVersionService;
|
||||
private final AdminAuthSupport adminAuthSupport;
|
||||
|
||||
@GetMapping("/versions")
|
||||
@Operation(summary = "客户端软件版本列表", description = "按创建时间倒序返回全部版本(旧 web_config 表)")
|
||||
public ApiResponse<Map<String, Object>> listVersions(HttpServletRequest request) {
|
||||
AdminUserEntity operator = adminAuthSupport.requireAdminOrInternal(request);
|
||||
log.info("[software-version] 管理端查询客户端软件版本列表 operator={}", operator.getUsername());
|
||||
return ApiResponse.success(Map.of("items", softwareVersionService.listSoftwareVersions()));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/version", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@Operation(summary = "上传客户端软件版本", description = "multipart 表单:version 版本号 + file zip 安装包,上传 MinIO 并写入 web_config")
|
||||
public ApiResponse<Map<String, Object>> uploadVersion(
|
||||
HttpServletRequest request,
|
||||
@Parameter(description = "版本号,如 1.0.46") @RequestParam(value = "version", required = false) String version,
|
||||
@Parameter(description = "zip 安装包文件") @RequestParam(value = "file", required = false) MultipartFile file) {
|
||||
AdminUserEntity operator = adminAuthSupport.requireAdminOrInternal(request);
|
||||
log.info("[software-version] 管理端上传客户端软件版本开始 operator={} version={}", operator.getUsername(), version);
|
||||
Map<String, Object> result = softwareVersionService.uploadSoftwareVersion(version, file);
|
||||
return ApiResponse.success("上传成功", result);
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.nanri.aiimage.modules.softwareversion.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nanri.aiimage.modules.softwareversion.model.entity.SoftwareVersionEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SoftwareVersionMapper extends BaseMapper<SoftwareVersionEntity> {
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.nanri.aiimage.modules.softwareversion.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 客户端软件版本记录(对应旧表 web_config,桌面客户端"检测更新"与 Flask 时代共用同一张表)。
|
||||
* <p>注意:本表不是"数字人版本"(数字人走 biz_digital_human_version,勿混淆)。
|
||||
*/
|
||||
@Data
|
||||
@TableName("web_config")
|
||||
public class SoftwareVersionEntity {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/** 版本号,如 1.0.46 */
|
||||
private String version;
|
||||
|
||||
/** 安装包可公开访问的下载链接(MinIO path-style 直链) */
|
||||
private String fileUrl;
|
||||
|
||||
/** 创建时间,由数据库 CURRENT_TIMESTAMP 兜底 */
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
package com.nanri.aiimage.modules.softwareversion.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.modules.file.service.oss.OssStorageService;
|
||||
import com.nanri.aiimage.modules.softwareversion.mapper.SoftwareVersionMapper;
|
||||
import com.nanri.aiimage.modules.softwareversion.model.entity.SoftwareVersionEntity;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 客户端软件(桌面 ShuFuAI.exe)版本管理服务:读写 web_config 表,
|
||||
* 与 Flask 时代 /api/admin/versions、/api/admin/version 行为对齐(读取/追加写,无覆盖、无删除)。
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class SoftwareVersionService {
|
||||
|
||||
/** MinIO 对象 key 前缀,对齐 Flask bucket_path(oss_bucket_path 默认 nanri-image/) 的历史约定 */
|
||||
public static final String STORAGE_PATH_PREFIX = "nanri-image/versions/";
|
||||
|
||||
/** 与 Flask VERSION_UPLOAD_MAX_BYTES(默认 512MB)保持一致 */
|
||||
private static final long MAX_UPLOAD_BYTES = 512L * 1024 * 1024;
|
||||
|
||||
private static final DateTimeFormatter CREATED_AT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
||||
|
||||
/** 对齐 Python re.sub(r'[^\w.\-]', '_')(\w 含中文等 Unicode 字符),仅版本号片段防注入 */
|
||||
private static final Pattern UNSAFE_KEY_CHARS =
|
||||
Pattern.compile("[^\\w.\\-]", Pattern.UNICODE_CHARACTER_CLASS);
|
||||
|
||||
private final SoftwareVersionMapper softwareVersionMapper;
|
||||
private final OssStorageService ossStorageService;
|
||||
|
||||
/**
|
||||
* 版本列表:web_config 全量按创建时间倒序,与 Flask 返回结构一致
|
||||
* (items 内为 id / version / file_url / created_at)。
|
||||
*/
|
||||
public List<Map<String, Object>> listSoftwareVersions() {
|
||||
List<SoftwareVersionEntity> entities = softwareVersionMapper.selectList(
|
||||
new LambdaQueryWrapper<SoftwareVersionEntity>()
|
||||
.orderByDesc(SoftwareVersionEntity::getCreatedAt)
|
||||
.orderByDesc(SoftwareVersionEntity::getId));
|
||||
log.info("[software-version] 查询客户端软件版本列表 count={}", entities.size());
|
||||
List<Map<String, Object>> items = new ArrayList<>(entities.size());
|
||||
for (SoftwareVersionEntity entity : entities) {
|
||||
Map<String, Object> item = new LinkedHashMap<>();
|
||||
item.put("id", entity.getId());
|
||||
item.put("version", entity.getVersion() == null ? "" : entity.getVersion());
|
||||
item.put("file_url", entity.getFileUrl() == null ? "" : entity.getFileUrl());
|
||||
item.put("created_at", entity.getCreatedAt() == null
|
||||
? "" : entity.getCreatedAt().format(CREATED_AT_FORMATTER));
|
||||
items.add(item);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传客户端软件安装包:zip 上传 MinIO(key:nanri-image/versions/{安全版本号}.zip),
|
||||
* 并向 web_config 追加一条记录(不做"设为最新",桌面端按 created_at 倒序取第一条)。
|
||||
*/
|
||||
public Map<String, Object> uploadSoftwareVersion(String version, MultipartFile file) {
|
||||
String normalizedVersion = version == null ? "" : version.trim();
|
||||
if (normalizedVersion.isEmpty()) {
|
||||
throw new BusinessException("请填写版本号");
|
||||
}
|
||||
if (file == null || file.getOriginalFilename() == null || file.getOriginalFilename().trim().isEmpty()) {
|
||||
throw new BusinessException("请选择要上传的 zip 压缩包");
|
||||
}
|
||||
String originalFilename = file.getOriginalFilename().trim();
|
||||
if (!originalFilename.toLowerCase(Locale.ROOT).endsWith(".zip")) {
|
||||
throw new BusinessException("仅支持 .zip 格式");
|
||||
}
|
||||
long fileSize = file.getSize();
|
||||
if (fileSize <= 0) {
|
||||
throw new BusinessException("文件为空");
|
||||
}
|
||||
if (fileSize > MAX_UPLOAD_BYTES) {
|
||||
throw new BusinessException("文件超过允许的大小限制");
|
||||
}
|
||||
|
||||
long startedAt = System.nanoTime();
|
||||
log.info("[software-version] 上传客户端软件版本开始 version={} filename={} requestFileSize={}",
|
||||
normalizedVersion, originalFilename, fileSize);
|
||||
|
||||
File tempFile = null;
|
||||
try {
|
||||
tempFile = Files.createTempFile("software-version-", ".zip").toFile();
|
||||
file.transferTo(tempFile);
|
||||
log.info("[software-version] 临时文件已保存 version={} bytes={} elapsedMs={}",
|
||||
normalizedVersion, tempFile.length(), elapsedMs(startedAt));
|
||||
|
||||
String safeKey = safeVersionKey(normalizedVersion);
|
||||
String objectKey = STORAGE_PATH_PREFIX + safeKey + ".zip";
|
||||
// 上传后返回可直接公开下载的 URL,与桌面端"检测更新"返回的 file_url 格式一致
|
||||
String fileUrl = ossStorageService.uploadSoftwareVersionPackage(tempFile, objectKey);
|
||||
log.info("[software-version] MinIO 上传成功 version={} objectKey={} bytes={} url={} elapsedMs={}",
|
||||
normalizedVersion, objectKey, tempFile.length(), fileUrl, elapsedMs(startedAt));
|
||||
|
||||
SoftwareVersionEntity entity = new SoftwareVersionEntity();
|
||||
entity.setVersion(normalizedVersion);
|
||||
entity.setFileUrl(fileUrl);
|
||||
// 不显式写 created_at,走数据库 CURRENT_TIMESTAMP 默认值(与 Flask 行为一致)
|
||||
softwareVersionMapper.insert(entity);
|
||||
log.info("[software-version] 版本记录已写入 web_config id={} version={} elapsedMs={}",
|
||||
entity.getId(), normalizedVersion, elapsedMs(startedAt));
|
||||
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("version", normalizedVersion);
|
||||
result.put("file_url", fileUrl);
|
||||
return result;
|
||||
} catch (IOException e) {
|
||||
log.error("[software-version] 上传客户端软件版本文件处理失败 version={} filename={} err={}",
|
||||
normalizedVersion, originalFilename, e.getMessage(), e);
|
||||
throw new BusinessException("文件处理失败:" + e.getMessage());
|
||||
} catch (RuntimeException e) {
|
||||
log.error("[software-version] 上传客户端软件版本失败 version={} filename={} elapsedMs={} err={}",
|
||||
normalizedVersion, originalFilename, elapsedMs(startedAt), e.getMessage(), e);
|
||||
throw e;
|
||||
} finally {
|
||||
if (tempFile != null && tempFile.exists() && !tempFile.delete()) {
|
||||
log.warn("[software-version] 清理临时文件失败 path={}", tempFile.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private long elapsedMs(long startedAt) {
|
||||
return (System.nanoTime() - startedAt) / 1_000_000L;
|
||||
}
|
||||
|
||||
/** 将版本号转换为安全的 OSS 对象名片段:保留中文/字母/数字/._-,其余替换为 _,空则 unknown(对齐 Flask _safe_version_key)。 */
|
||||
private String safeVersionKey(String version) {
|
||||
String replaced = UNSAFE_KEY_CHARS.matcher(version).replaceAll("_");
|
||||
return replaced.isEmpty() ? "unknown" : replaced;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user