feat: 功能优化
This commit is contained in:
@@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.tik.file.service.TikUserFileService;
|
||||
import cn.iocoder.yudao.module.tik.file.vo.app.AppTikUserFilePageReqVO;
|
||||
import cn.iocoder.yudao.module.tik.file.vo.app.AppTikUserFileRespVO;
|
||||
import cn.iocoder.yudao.module.tik.file.vo.app.UpdateDisplayNameReqVO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -113,5 +114,12 @@ public class AppTikUserFileController {
|
||||
return success(userFileService.completeUpload(request));
|
||||
}
|
||||
|
||||
@PostMapping("/update-display-name")
|
||||
@Operation(summary = "更新文件显示名称")
|
||||
public CommonResult<Boolean> updateDisplayName(@RequestBody @Valid UpdateDisplayNameReqVO reqVO) {
|
||||
userFileService.updateDisplayName(reqVO.getFileId(), reqVO.getDisplayName());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -83,5 +83,9 @@ public class TikUserFileDO extends TenantBaseDO {
|
||||
* 视频时长(秒)
|
||||
*/
|
||||
private Integer duration;
|
||||
/**
|
||||
* 显示名称(用户可重命名,去除文件后缀)
|
||||
*/
|
||||
private String displayName;
|
||||
|
||||
}
|
||||
|
||||
@@ -94,5 +94,13 @@ public interface TikUserFileService {
|
||||
*/
|
||||
Object completeUpload(Object request);
|
||||
|
||||
/**
|
||||
* 更新文件显示名称
|
||||
*
|
||||
* @param fileId 文件编号
|
||||
* @param displayName 新的显示名称
|
||||
*/
|
||||
void updateDisplayName(Long fileId, String displayName);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -244,17 +244,20 @@ public class TikUserFileServiceImpl implements TikUserFileService {
|
||||
throw exception(FILE_NOT_EXISTS, "文件记录保存失败:无法获取文件ID");
|
||||
}
|
||||
|
||||
// 处理视频封面
|
||||
// 处理视频封面和文件名
|
||||
String fileName = file.getOriginalFilename();
|
||||
String fileType = file.getContentType();
|
||||
String coverUrl = handleCoverUpload(coverBase64, fileName, fileType, baseDirectory);
|
||||
// 处理显示名称(去除文件后缀)
|
||||
String displayName = FileUtil.mainName(fileName);
|
||||
|
||||
// 9. 创建文件记录(保存完整路径,包含封面URL和Base64)
|
||||
TikUserFileDO userFile = new TikUserFileDO()
|
||||
.setUserId(userId)
|
||||
.setFileId(infraFileId) // 关联infra_file表,用于后续通过FileService管理文件
|
||||
.setFileName(file.getOriginalFilename()) // 保存原始文件名,用于展示
|
||||
.setFileType(file.getContentType())
|
||||
.setFileName(fileName) // 保留原始文件名(系统标识)
|
||||
.setDisplayName(displayName) // 设置显示名称(无后缀,用户可编辑)
|
||||
.setFileType(fileType)
|
||||
.setFileCategory(fileCategory)
|
||||
.setFileSize(file.getSize())
|
||||
.setFileUrl(fileUrl)
|
||||
@@ -668,12 +671,15 @@ public class TikUserFileServiceImpl implements TikUserFileService {
|
||||
// 4. 处理视频封面
|
||||
String baseDirectory = ossInitService.getOssDirectoryByCategory(userId, fileCategory);
|
||||
String coverUrl = handleCoverUpload(coverBase64, fileName, fileType, baseDirectory);
|
||||
// 处理显示名称(去除文件后缀)
|
||||
String displayName = FileUtil.mainName(fileName);
|
||||
|
||||
// 5. 保存到 tik_user_file 表
|
||||
TikUserFileDO userFile = new TikUserFileDO()
|
||||
.setUserId(userId)
|
||||
.setFileId(infraFileId)
|
||||
.setFileName(fileName)
|
||||
.setFileName(fileName) // 保留原始文件名(系统标识)
|
||||
.setDisplayName(displayName) // 设置显示名称(无后缀,用户可编辑)
|
||||
.setFileType(fileType)
|
||||
.setFileCategory(fileCategory)
|
||||
.setFileSize(fileSize)
|
||||
@@ -699,5 +705,24 @@ public class TikUserFileServiceImpl implements TikUserFileService {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDisplayName(Long fileId, String displayName) {
|
||||
Long userId = SecurityFrameworkUtils.getLoginUserId();
|
||||
|
||||
// 验证文件存在且属于当前用户
|
||||
TikUserFileDO fileDO = userFileMapper.selectById(fileId);
|
||||
if (fileDO == null || !fileDO.getUserId().equals(userId)) {
|
||||
throw exception(FILE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 更新显示名称
|
||||
userFileMapper.updateById(new TikUserFileDO()
|
||||
.setId(fileId)
|
||||
.setDisplayName(displayName));
|
||||
|
||||
log.info("[updateDisplayName][用户({})更新文件({})显示名称成功,新名称({})]",
|
||||
userId, fileId, displayName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,9 @@ public class AppTikUserFileRespVO {
|
||||
@Schema(description = "文件名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "test.mp4")
|
||||
private String fileName;
|
||||
|
||||
@Schema(description = "显示名称(用户可重命名,去除文件后缀)", example = "test")
|
||||
private String displayName;
|
||||
|
||||
@Schema(description = "文件类型(video/image/document等)", example = "video")
|
||||
private String fileType;
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package cn.iocoder.yudao.module.tik.file.vo.app;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 更新文件显示名称 Request VO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Schema(description = "用户 App - 更新文件显示名称 Request VO")
|
||||
@Data
|
||||
public class UpdateDisplayNameReqVO {
|
||||
|
||||
@Schema(description = "文件编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "文件编号不能为空")
|
||||
private Long fileId;
|
||||
|
||||
@Schema(description = "显示名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "我的视频")
|
||||
@Size(max = 50, message = "显示名称长度不能超过50个字符")
|
||||
@NotNull(message = "显示名称不能为空")
|
||||
private String displayName;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user