mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:59:19 +08:00
feat: 迁移旧媒体文件到统一文件系统 sys/file
Backend: - SysFileController 新增 deleteFile + updateFile 接口 - 新增 SysFileUpdateDTO 用于更新文件元信息 - SysFileServiceImpl 实现 deleteFile + updateFile(带 companyId 校验) Frontend: - 导入订单页面改用 batchUploadFilesApi(返回 storagePath) - 文件管理页 media/file/index.vue 改用 system/file API - uploadFileApi → batchUploadFilesApi - url → accessUrl - updateFileApi 改用 system/file - FileEditModal 改用 system/file 类型和 API 旧媒体系统 (media/file) 不再使用,待后续清理。
This commit is contained in:
+18
@@ -5,12 +5,14 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequireRole;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.dto.BatchCreateOssFileDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.dto.BatchSignUrlDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.dto.SysFileFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.dto.SysFileUpdateDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.BatchSignUrlVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.SysFileUploadVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.SysFileVO;
|
||||
@@ -66,5 +68,21 @@ public class SysFileController {
|
||||
PageResultVO<SysFileVO> result = sysFileService.getFilePage(pageQueryDTO);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除文件")
|
||||
@DeleteMapping("/{fileId}")
|
||||
@RequireRole(description = "删除文件")
|
||||
public ApiResponse<Void> deleteFile(@PathVariable Long fileId) {
|
||||
sysFileService.deleteFile(fileId);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "更新文件元信息")
|
||||
@PutMapping("/{fileId}")
|
||||
@RequireRole(description = "更新文件")
|
||||
public ApiResponse<Void> updateFile(@PathVariable Long fileId, @Valid @RequestBody SysFileUpdateDTO dto) {
|
||||
sysFileService.updateFile(fileId, dto);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.file.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 更新文件元信息DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "更新文件元信息DTO")
|
||||
public class SysFileUpdateDTO {
|
||||
|
||||
@Schema(description = "标签,多个用逗号分隔")
|
||||
private String tags;
|
||||
|
||||
@Schema(description = "描述/备注")
|
||||
private String remark;
|
||||
}
|
||||
+16
@@ -6,6 +6,7 @@ import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.dto.BatchCreateOssFileDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.dto.BatchSignUrlDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.dto.SysFileFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.dto.SysFileUpdateDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.BatchSignUrlVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.SysFileUploadVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.SysFileVO;
|
||||
@@ -65,5 +66,20 @@ public interface SysFileService {
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResultVO<SysFileVO> getFilePage(PageQueryDTO<SysFileFilterDTO> pageQueryDTO);
|
||||
|
||||
/**
|
||||
* 删除文件记录(物理文件通过定时任务或OSS生命周期策略清理)
|
||||
*
|
||||
* @param id 文件ID
|
||||
*/
|
||||
void deleteFile(Long id);
|
||||
|
||||
/**
|
||||
* 更新文件元信息(标签、描述)
|
||||
*
|
||||
* @param id 文件ID
|
||||
* @param dto 更新内容
|
||||
*/
|
||||
void updateFile(Long id, SysFileUpdateDTO dto);
|
||||
}
|
||||
|
||||
|
||||
+28
@@ -658,5 +658,33 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFilePO> im
|
||||
// 构建分页结果
|
||||
return PageResultVO.create(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFile(Long id) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
SysFilePO file = this.getById(id);
|
||||
if (file == null || !file.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("文件不存在");
|
||||
}
|
||||
// 删除数据库记录(物理文件由OSS生命周期或定时任务清理)
|
||||
this.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFile(Long id, SysFileUpdateDTO dto) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
SysFilePO file = this.getById(id);
|
||||
if (file == null || !file.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("文件不存在");
|
||||
}
|
||||
// 更新元信息
|
||||
if (dto.getTags() != null) {
|
||||
file.setTags(dto.getTags());
|
||||
}
|
||||
if (dto.getRemark() != null) {
|
||||
file.setRemark(dto.getRemark());
|
||||
}
|
||||
this.updateById(file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,3 +65,20 @@ export async function getFilePageApi(params: PageQueryDTO<FileDTO.Filter>) {
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param fileId 文件ID
|
||||
*/
|
||||
export async function deleteFileApi(fileId: number) {
|
||||
return requestClient.delete(`/sys/file/${fileId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文件元信息
|
||||
* @param fileId 文件ID
|
||||
* @param data 更新内容
|
||||
*/
|
||||
export async function updateFileApi(fileId: number, data: { tags?: string; remark?: string }) {
|
||||
return requestClient.put(`/sys/file/${fileId}`, data);
|
||||
}
|
||||
|
||||
+3
-3
@@ -32,7 +32,7 @@ import {
|
||||
import { createImportTaskApi } from '#/api/ecommerce/import-task';
|
||||
import { getAllOrderStatusListApi } from '#/api/ecommerce/order-status';
|
||||
import { getShopPageApi } from '#/api/ecommerce/shop';
|
||||
import { uploadFileApi } from '#/api/media/file';
|
||||
import { batchUploadFilesApi } from '#/api/system/file';
|
||||
import { useImportTaskStore } from '#/store';
|
||||
|
||||
// 定义映射项数据结构
|
||||
@@ -759,7 +759,7 @@ const handleCreateTask = async () => {
|
||||
|
||||
// 先上传文件
|
||||
message.loading('正在上传文件...', 0);
|
||||
const fileInfo = await uploadFileApi(selectedFile.value);
|
||||
const [fileInfo] = await batchUploadFilesApi([selectedFile.value]);
|
||||
message.destroy();
|
||||
|
||||
// 构建字段映射 JSON(基于 ImportFieldDefInfoVO 结构)
|
||||
@@ -790,7 +790,7 @@ const handleCreateTask = async () => {
|
||||
shopId: selectedShopId.value!,
|
||||
type: 'order',
|
||||
fileName: selectedFile.value.name,
|
||||
filePath: fileInfo.url,
|
||||
filePath: fileInfo.storagePath,
|
||||
mapping: JSON.stringify(fullMapping),
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import type { FileDTO, FileVO } from '#/api/media/file/types';
|
||||
import type { FileDTO, FileVO } from '#/api/system/file/types';
|
||||
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Form, Input, message } from 'ant-design-vue';
|
||||
|
||||
import { updateFileApi } from '#/api/media/file';
|
||||
import { updateFileApi } from '#/api/system/file';
|
||||
|
||||
defineOptions({ name: 'FileEditModal' });
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { FileDTO, FileVO } from '#/api/media/file/types';
|
||||
import type { FileDTO, FileVO } from '#/api/system/file/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
@@ -23,8 +23,7 @@ import {
|
||||
batchUploadFilesApi,
|
||||
deleteFileApi,
|
||||
getFilePageApi,
|
||||
uploadFileApi,
|
||||
} from '#/api/media/file';
|
||||
} from '#/api/system/file';
|
||||
|
||||
import FileEditModal from './components/FileEditModal.vue';
|
||||
|
||||
@@ -212,7 +211,7 @@ function refreshTable() {
|
||||
const handleUpload = async (file: File) => {
|
||||
uploadLoading.value = true;
|
||||
try {
|
||||
await uploadFileApi(file);
|
||||
await batchUploadFilesApi([file]);
|
||||
message.success('文件上传成功');
|
||||
refreshTable();
|
||||
} catch {
|
||||
@@ -241,12 +240,12 @@ const handleEdit = (record: FileVO.Info) => {
|
||||
};
|
||||
|
||||
const handlePreview = (record: FileVO.Info) => {
|
||||
window.open(record.url, '_blank');
|
||||
window.open(record.accessUrl, '_blank');
|
||||
};
|
||||
|
||||
const handleDownload = (record: FileVO.Info) => {
|
||||
const link = document.createElement('a');
|
||||
link.href = record.url;
|
||||
link.href = record.accessUrl;
|
||||
link.download = record.filename;
|
||||
link.click();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user