mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-22 20:02:42 +08:00
资源批量删除接口 && 资源列表返回管理员信息
This commit is contained in:
parent
debcddc468
commit
5af91191de
@ -52,6 +52,13 @@ public class AdminPermissionCheck implements ApplicationRunner {
|
||||
setSlug(BPermissionConstant.RESOURCE_CATEGORY);
|
||||
}},
|
||||
});
|
||||
put("资源", new AdminPermission[]{
|
||||
new AdminPermission() {{
|
||||
setSort(0);
|
||||
setName("删除");
|
||||
setSlug(BPermissionConstant.RESOURCE_DESTROY);
|
||||
}},
|
||||
});
|
||||
put("学员", new AdminPermission[]{
|
||||
new AdminPermission() {{
|
||||
setSort(0);
|
||||
|
@ -25,10 +25,11 @@ public class BPermissionConstant {
|
||||
|
||||
public final static String COURSE = "course";
|
||||
|
||||
public final static String RESOURCE_DESTROY = "resource-destroy";
|
||||
|
||||
public final static String DATA_USER_NAME = "data-user-name";
|
||||
public final static String DATA_USER_EMAIL = "data-user-email";
|
||||
public final static String DATA_USER_ID_CARD = "data-user-id-card";
|
||||
|
||||
public final static String DATA_ADMIN_EMAIL = "data-admin-email";
|
||||
|
||||
}
|
||||
|
@ -6,10 +6,15 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import xyz.playedu.api.PlayEduBContext;
|
||||
import xyz.playedu.api.bus.BackendBus;
|
||||
import xyz.playedu.api.constant.BPermissionConstant;
|
||||
import xyz.playedu.api.constant.BackendConstant;
|
||||
import xyz.playedu.api.domain.AdminUser;
|
||||
import xyz.playedu.api.domain.Resource;
|
||||
import xyz.playedu.api.domain.ResourceVideo;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||
import xyz.playedu.api.request.backend.ResourceDestroyMultiRequest;
|
||||
import xyz.playedu.api.service.AdminUserService;
|
||||
import xyz.playedu.api.service.MinioService;
|
||||
import xyz.playedu.api.service.ResourceService;
|
||||
import xyz.playedu.api.service.ResourceVideoService;
|
||||
@ -28,6 +33,9 @@ import java.util.stream.Collectors;
|
||||
@RequestMapping("/backend/v1/resource")
|
||||
public class ResourceController {
|
||||
|
||||
@Autowired
|
||||
private AdminUserService adminUserService;
|
||||
|
||||
@Autowired
|
||||
private ResourceService resourceService;
|
||||
|
||||
@ -76,9 +84,17 @@ public class ResourceController {
|
||||
data.put("videos_extra", resourceVideosExtra);
|
||||
}
|
||||
|
||||
// 操作人
|
||||
data.put("admin_users", new HashMap<>());
|
||||
if (result.getData().size() > 0) {
|
||||
Map<Integer, String> adminUsers = adminUserService.chunks(result.getData().stream().map(Resource::getAdminId).toList()).stream().collect(Collectors.toMap(AdminUser::getId, AdminUser::getName));
|
||||
data.put("admin_users", adminUsers);
|
||||
}
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.RESOURCE_DESTROY)
|
||||
@DeleteMapping("/{id}")
|
||||
@Transactional
|
||||
public JsonResponse destroy(@PathVariable(name = "id") Integer id) throws NotFoundException {
|
||||
@ -86,7 +102,7 @@ public class ResourceController {
|
||||
// 删除文件
|
||||
minioService.removeByPath(resource.getPath());
|
||||
// 如果是视频资源文件则删除对应的时长关联记录
|
||||
if (resource.getType().equals(BackendConstant.RESOURCE_TYPE_VIDEO)) {
|
||||
if (BackendConstant.RESOURCE_TYPE_VIDEO.equals(resource.getType())) {
|
||||
resourceVideoService.removeByRid(resource.getId());
|
||||
}
|
||||
// 删除资源记录
|
||||
@ -94,4 +110,25 @@ public class ResourceController {
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.RESOURCE_DESTROY)
|
||||
@PostMapping("/destroy-multi")
|
||||
@Transactional
|
||||
public JsonResponse multiDestroy(@RequestBody ResourceDestroyMultiRequest req) {
|
||||
if (req.getIds() == null || req.getIds().size() == 0) {
|
||||
return JsonResponse.error("请选择需要删除的资源");
|
||||
}
|
||||
List<Resource> resources = resourceService.chunks(req.getIds());
|
||||
if (resources == null || resources.size() == 0) {
|
||||
return JsonResponse.success();
|
||||
}
|
||||
for (Resource resourceItem : resources) {
|
||||
minioService.removeByPath(resourceItem.getPath());
|
||||
if (BackendConstant.RESOURCE_TYPE_VIDEO.equals(resourceItem.getType())) {
|
||||
resourceVideoService.removeByRid(resourceItem.getId());
|
||||
}
|
||||
resourceService.removeById(resourceItem.getId());
|
||||
}
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package xyz.playedu.api.request.backend;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/3/13 10:41
|
||||
*/
|
||||
@Data
|
||||
public class ResourceDestroyMultiRequest {
|
||||
|
||||
private List<Integer> ids;
|
||||
|
||||
}
|
@ -40,4 +40,6 @@ public interface AdminUserService extends IService<AdminUser> {
|
||||
void removeRelateRolesByUserId(Integer userId);
|
||||
|
||||
void passwordChange(AdminUser user, String password);
|
||||
|
||||
List<AdminUser> chunks(List<Integer> ids);
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.ResourcePaginateFilter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【resources】的数据库操作Service
|
||||
@ -23,4 +25,6 @@ public interface ResourceService extends IService<Resource> {
|
||||
|
||||
void storeResourceVideo(Integer rid, Integer duration, String poster);
|
||||
|
||||
List<Resource> chunks(List<Integer> ids);
|
||||
|
||||
}
|
||||
|
@ -176,6 +176,11 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser
|
||||
newUser.setPassword(newPassword);
|
||||
updateById(newUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdminUser> chunks(List<Integer> ids) {
|
||||
return list(query().getWrapper().in("id", ids));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -145,6 +145,11 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
|
||||
public void storeResourceVideo(Integer rid, Integer duration, String poster) {
|
||||
resourceVideoService.create(rid, duration, poster);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Resource> chunks(List<Integer> ids) {
|
||||
return list(query().getWrapper().in("id", ids));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user