mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-07-26 03:49:31 +08:00
资源分类增加检测api
This commit is contained in:
parent
a3bb8be72e
commit
48602be6c0
@ -6,12 +6,16 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import xyz.playedu.api.PlayEduBContext;
|
||||
import xyz.playedu.api.constant.BPermissionConstant;
|
||||
import xyz.playedu.api.constant.BackendConstant;
|
||||
import xyz.playedu.api.domain.Resource;
|
||||
import xyz.playedu.api.domain.ResourceCategory;
|
||||
import xyz.playedu.api.event.ResourceCategoryDestroyEvent;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||
import xyz.playedu.api.request.backend.ResourceCategoryRequest;
|
||||
import xyz.playedu.api.service.CourseService;
|
||||
import xyz.playedu.api.service.ResourceCategoryService;
|
||||
import xyz.playedu.api.service.ResourceService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
|
||||
import java.util.*;
|
||||
@ -28,6 +32,12 @@ public class ResourceCategoryController {
|
||||
@Autowired
|
||||
private ResourceCategoryService categoryService;
|
||||
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
|
||||
@Autowired
|
||||
private ResourceService resourceService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext ctx;
|
||||
|
||||
@ -79,6 +89,39 @@ public class ResourceCategoryController {
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.RESOURCE_CATEGORY)
|
||||
@GetMapping("/{id}/destroy")
|
||||
public JsonResponse preDestroy(@PathVariable Integer id) {
|
||||
List<Integer> courseIds = categoryService.getCourseIdsById(id);
|
||||
List<Integer> rids = categoryService.getRidsById(id);
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("courses", new ArrayList<>());
|
||||
data.put("videos", new ArrayList<>());
|
||||
data.put("images", new ArrayList<>());
|
||||
|
||||
if (courseIds != null && courseIds.size() > 0) {
|
||||
data.put("courses", courseService.chunks(courseIds, new ArrayList<>() {{
|
||||
add("id");
|
||||
add("title");
|
||||
}}));
|
||||
}
|
||||
|
||||
if (rids != null && rids.size() > 0) {
|
||||
Map<String, List<Resource>> resources = resourceService.chunks(rids, new ArrayList<>() {{
|
||||
add("id");
|
||||
add("admin_id");
|
||||
add("type");
|
||||
add("name");
|
||||
add("url");
|
||||
}}).stream().collect(Collectors.groupingBy(Resource::getType));
|
||||
data.put("videos", resources.get(BackendConstant.RESOURCE_TYPE_VIDEO));
|
||||
data.put("images", resources.get(BackendConstant.RESOURCE_TYPE_IMAGE));
|
||||
}
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.RESOURCE_CATEGORY)
|
||||
@DeleteMapping("/{id}")
|
||||
public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException {
|
||||
|
@ -29,4 +29,8 @@ public interface ResourceCategoryService extends IService<ResourceCategory> {
|
||||
|
||||
String compParentChain(Integer parentId) throws NotFoundException;
|
||||
|
||||
List<Integer> getCourseIdsById(Integer id);
|
||||
|
||||
List<Integer> getRidsById(Integer id);
|
||||
|
||||
}
|
||||
|
@ -27,4 +27,6 @@ public interface ResourceService extends IService<Resource> {
|
||||
|
||||
List<Resource> chunks(List<Integer> ids);
|
||||
|
||||
List<Resource> chunks(List<Integer> ids, List<String> fields);
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,17 @@
|
||||
package xyz.playedu.api.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import xyz.playedu.api.domain.ResourceCategory;
|
||||
import xyz.playedu.api.domain.ResourceCategoryRelation;
|
||||
import xyz.playedu.api.domain.ResourceCourseCategory;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.service.ResourceCategoryService;
|
||||
import xyz.playedu.api.mapper.ResourceCategoryMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import xyz.playedu.api.service.internal.ResourceCategoryRelationService;
|
||||
import xyz.playedu.api.service.internal.ResourceCourseCategoryService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@ -21,6 +26,12 @@ import java.util.List;
|
||||
public class ResourceCategoryServiceImpl extends ServiceImpl<ResourceCategoryMapper, ResourceCategory>
|
||||
implements ResourceCategoryService {
|
||||
|
||||
@Autowired
|
||||
private ResourceCourseCategoryService resourceCourseCategoryService;
|
||||
|
||||
@Autowired
|
||||
private ResourceCategoryRelationService resourceCategoryRelationService;
|
||||
|
||||
@Override
|
||||
public List<ResourceCategory> listByParentId(Integer id) {
|
||||
return list(query().getWrapper().eq("parent_id", id).orderByAsc("sort"));
|
||||
@ -154,7 +165,16 @@ public class ResourceCategoryServiceImpl extends ServiceImpl<ResourceCategoryMap
|
||||
}
|
||||
return parentChain;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Integer> getCourseIdsById(Integer id) {
|
||||
return resourceCourseCategoryService.list(resourceCourseCategoryService.query().getWrapper().eq("category_id", id)).stream().map(ResourceCourseCategory::getCourseId).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getRidsById(Integer id) {
|
||||
return resourceCategoryRelationService.list(resourceCategoryRelationService.query().getWrapper().eq("cid", id)).stream().map(ResourceCategoryRelation::getRid).toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -150,6 +150,11 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
|
||||
public List<Resource> chunks(List<Integer> ids) {
|
||||
return list(query().getWrapper().in("id", ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Resource> chunks(List<Integer> ids, List<String> fields) {
|
||||
return list(query().getWrapper().in("id", ids).select(fields));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user