mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-17 00:44:41 +08:00
资源video的时长记录
This commit is contained in:
@@ -2,6 +2,7 @@ package xyz.playedu.api.controller.backend;
|
||||
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import xyz.playedu.api.constant.BackendConstant;
|
||||
@@ -10,6 +11,7 @@ import xyz.playedu.api.domain.ResourceCategory;
|
||||
import xyz.playedu.api.request.backend.ResourceRequest;
|
||||
import xyz.playedu.api.service.ResourceCategoryService;
|
||||
import xyz.playedu.api.service.ResourceService;
|
||||
import xyz.playedu.api.service.ResourceVideoService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.ResourcePaginateFilter;
|
||||
@@ -27,6 +29,9 @@ public class ResourceController {
|
||||
@Autowired
|
||||
private ResourceService resourceService;
|
||||
|
||||
@Autowired
|
||||
private ResourceVideoService resourceVideoService;
|
||||
|
||||
@Autowired
|
||||
private ResourceCategoryService categoryService;
|
||||
|
||||
@@ -57,15 +62,46 @@ public class ResourceController {
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@Transactional
|
||||
public JsonResponse store(@RequestBody @Validated ResourceRequest req) {
|
||||
if (categoryService.getById(req.getCategoryId()) == null) {
|
||||
Integer categoryId = req.getCategoryId();
|
||||
if (categoryService.getById(categoryId) == null) {
|
||||
return JsonResponse.error("资源分类不存在");
|
||||
}
|
||||
if (!Arrays.asList(BackendConstant.RESOURCE_DISK_WHITELIST).contains(req.getDisk())) {
|
||||
String disk = req.getDisk();
|
||||
if (!Arrays.asList(BackendConstant.RESOURCE_DISK_WHITELIST).contains(disk)) {
|
||||
return JsonResponse.error("存储磁盘参数错误");
|
||||
}
|
||||
String extension = req.getExtension().toLowerCase();
|
||||
String type = BackendConstant.RESOURCE_EXT_2_TYPE.get(extension);
|
||||
if (type == null) {
|
||||
return JsonResponse.error("格式不支持");
|
||||
}
|
||||
|
||||
// 如果是视频则必须传递duration参数
|
||||
Integer duration = req.getDuration();
|
||||
boolean isVideoType = BackendConstant.RESOURCE_TYPE_VIDEO.equals(type);
|
||||
if (isVideoType) {
|
||||
if (duration == null || duration == 0) {
|
||||
return JsonResponse.error("duration参数必须存在且大于0");
|
||||
}
|
||||
}
|
||||
|
||||
Resource res = resourceService.create(
|
||||
categoryId,
|
||||
req.getName(),
|
||||
extension,
|
||||
req.getSize(),
|
||||
disk,
|
||||
req.getFileId(),
|
||||
req.getPath(),
|
||||
req.getUrl()
|
||||
);
|
||||
|
||||
if (isVideoType) {
|
||||
resourceVideoService.create(res.getId(), duration);
|
||||
}
|
||||
|
||||
Resource res = resourceService.create(req.getCategoryId(), req.getName(), req.getExtension(), req.getSize(), req.getDisk(), req.getFileId(), req.getPath(), req.getUrl());
|
||||
return JsonResponse.data(res);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user