mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-23 12:32:41 +08:00
优化资源分类id必填
This commit is contained in:
parent
26a26c52c2
commit
0037b9e9ae
@ -57,29 +57,16 @@ public class ResourceController {
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public JsonResponse store(@RequestBody @Validated ResourceRequest request) {
|
||||
if (categoryService.getById(request.getCategoryId()) == null) {
|
||||
public JsonResponse store(@RequestBody @Validated ResourceRequest req) {
|
||||
if (categoryService.getById(req.getCategoryId()) == null) {
|
||||
return JsonResponse.error("资源分类不存在");
|
||||
}
|
||||
if (!Arrays.asList(BackendConstant.RESOURCE_DISK_WHITELIST).contains(request.getDisk())) {
|
||||
if (!Arrays.asList(BackendConstant.RESOURCE_DISK_WHITELIST).contains(req.getDisk())) {
|
||||
return JsonResponse.error("存储磁盘参数错误");
|
||||
}
|
||||
|
||||
Resource resource = new Resource();
|
||||
|
||||
resource.setCategoryId(request.getCategoryId());
|
||||
resource.setName(request.getName());
|
||||
resource.setExtension(request.getExtension());
|
||||
resource.setSize(request.getSize());
|
||||
resource.setDisk(request.getDisk());
|
||||
resource.setFileId(request.getFileId());
|
||||
resource.setPath(request.getPath());
|
||||
resource.setUrl(request.getUrl());
|
||||
resource.setCreatedAt(new Date());
|
||||
|
||||
resourceService.save(resource);
|
||||
|
||||
return JsonResponse.success();
|
||||
Resource res = resourceService.create(req.getCategoryId(), req.getName(), req.getExtension(), req.getSize(), req.getDisk(), req.getFileId(), req.getPath(), req.getUrl());
|
||||
return JsonResponse.data(res);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
|
@ -12,12 +12,12 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import xyz.playedu.api.config.MinioConfig;
|
||||
import xyz.playedu.api.constant.BackendConstant;
|
||||
import xyz.playedu.api.domain.Resource;
|
||||
import xyz.playedu.api.service.ResourceCategoryService;
|
||||
import xyz.playedu.api.service.ResourceService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
import xyz.playedu.api.util.HelperUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
@ -31,6 +31,9 @@ public class UploadController {
|
||||
@Autowired
|
||||
private ResourceService resourceService;
|
||||
|
||||
@Autowired
|
||||
private ResourceCategoryService resourceCategoryService;
|
||||
|
||||
@Autowired
|
||||
private MinioConfig minioConfig;
|
||||
|
||||
@ -39,7 +42,6 @@ public class UploadController {
|
||||
|
||||
@PostMapping("/image")
|
||||
public JsonResponse image(@RequestParam HashMap<String, Object> params, MultipartFile file) {
|
||||
Integer categoryId = MapUtils.getInteger(params, "category_id", 0);
|
||||
if (file == null || file.isEmpty() || file.getOriginalFilename() == null) {
|
||||
return JsonResponse.error("请上传文件");
|
||||
}
|
||||
@ -49,6 +51,11 @@ public class UploadController {
|
||||
return JsonResponse.error("格式不支持");
|
||||
}
|
||||
|
||||
Integer categoryId = MapUtils.getInteger(params, "category_id", 0);
|
||||
if (resourceCategoryService.getById(categoryId) == null) {
|
||||
return JsonResponse.error("分类不存在");
|
||||
}
|
||||
|
||||
String filename = file.getOriginalFilename();
|
||||
String ext = HelperUtil.fileExt(filename);
|
||||
if (!Arrays.asList(BackendConstant.UPLOAD_IMAGE_EXT_WL).contains(ext)) {
|
||||
@ -71,19 +78,8 @@ public class UploadController {
|
||||
|
||||
String url = minioConfig.getDomain() + minioConfig.getBucket() + "/" + savePath;
|
||||
|
||||
Resource resource = new Resource();
|
||||
resource.setCategoryId(categoryId);
|
||||
resource.setName(oldFilename);
|
||||
resource.setExtension(ext);
|
||||
resource.setSize(file.getSize());
|
||||
resource.setDisk("minio");
|
||||
resource.setFileId("");
|
||||
resource.setPath(savePath);
|
||||
resource.setUrl(url);
|
||||
resource.setCreatedAt(new Date());
|
||||
resourceService.save(resource);
|
||||
|
||||
return JsonResponse.data(resource);
|
||||
Resource res = resourceService.create(categoryId, oldFilename, ext, file.getSize(), "minio", "", savePath, url);
|
||||
return JsonResponse.data(res);
|
||||
} catch (Exception e) {
|
||||
return JsonResponse.error("系统错误");
|
||||
}
|
||||
|
@ -14,4 +14,6 @@ public interface ResourceService extends IService<Resource> {
|
||||
|
||||
PaginationResult<Resource> paginate(int page, int size, ResourcePaginateFilter filter);
|
||||
|
||||
Resource create(Integer categoryId, String filename, String ext, Long size, String disk, String fileId, String path, String url);
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ import org.springframework.stereotype.Service;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.ResourcePaginateFilter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【resources】的数据库操作Service实现
|
||||
@ -43,6 +45,22 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
|
||||
|
||||
return pageResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource create(Integer categoryId, String filename, String ext, Long size, String disk, String fileId, String path, String url) {
|
||||
Resource resource = new Resource();
|
||||
resource.setCategoryId(categoryId);
|
||||
resource.setName(filename);
|
||||
resource.setExtension(ext);
|
||||
resource.setSize(size);
|
||||
resource.setDisk(disk);
|
||||
resource.setFileId(fileId);
|
||||
resource.setPath(path);
|
||||
resource.setUrl(url);
|
||||
resource.setCreatedAt(new Date());
|
||||
save(resource);
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user