mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-22 11:52:43 +08:00
added: 资源分类批量修改接口
This commit is contained in:
parent
a35a767514
commit
82ac97dbc5
@ -29,6 +29,7 @@ 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.ResourceCategoryChangeRequest;
|
||||
import xyz.playedu.api.request.backend.ResourceDestroyMultiRequest;
|
||||
import xyz.playedu.api.service.AdminUserService;
|
||||
import xyz.playedu.api.service.MinioService;
|
||||
@ -41,11 +42,6 @@ import xyz.playedu.api.types.paginate.ResourcePaginateFilter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
*
|
||||
* @create 2023/2/23 10:50
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/backend/v1/resource")
|
||||
public class ResourceController {
|
||||
@ -150,4 +146,31 @@ public class ResourceController {
|
||||
}
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.RESOURCE_DESTROY)
|
||||
@PutMapping("/category")
|
||||
public JsonResponse categoryChange(@RequestBody ResourceCategoryChangeRequest req) {
|
||||
if (req.getIds().size() == 0) {
|
||||
return JsonResponse.error("请选择需要删除的资源");
|
||||
}
|
||||
if (req.getCategoryId() <= 0) {
|
||||
return JsonResponse.error("请选择分类");
|
||||
}
|
||||
|
||||
List<Integer> ids = req.getIds();
|
||||
if (!backendBus.isSuperAdmin()) { // 非超管校验owner
|
||||
ids =
|
||||
resourceService.chunks(req.getIds()).stream()
|
||||
.filter(r -> r.getAdminId().equals(BCtx.getId()))
|
||||
.map(Resource::getId)
|
||||
.toList();
|
||||
if (ids.size() == 0) {
|
||||
return JsonResponse.error("无权限操作");
|
||||
}
|
||||
}
|
||||
|
||||
resourceService.categoryChange(ids, req.getCategoryId());
|
||||
|
||||
return JsonResponse.success();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2023 杭州白书科技有限公司
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package xyz.playedu.api.request.backend;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ResourceCategoryChangeRequest {
|
||||
@NotNull(message = "参数为空")
|
||||
private List<Integer> ids;
|
||||
|
||||
@NotNull(message = "请选择分类")
|
||||
@JsonProperty("category_id")
|
||||
private Integer categoryId;
|
||||
}
|
@ -24,11 +24,6 @@ import xyz.playedu.api.types.paginate.ResourcePaginateFilter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【resources】的数据库操作Service
|
||||
* @createDate 2023-02-23 10:50:26
|
||||
*/
|
||||
public interface ResourceService extends IService<Resource> {
|
||||
|
||||
PaginationResult<Resource> paginate(int page, int size, ResourcePaginateFilter filter);
|
||||
@ -58,4 +53,6 @@ public interface ResourceService extends IService<Resource> {
|
||||
Integer total(String type);
|
||||
|
||||
Integer duration(Integer id);
|
||||
|
||||
void categoryChange(List<Integer> ids, Integer categoryId);
|
||||
}
|
||||
|
@ -155,4 +155,9 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource>
|
||||
}
|
||||
return resourceVideo.getDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void categoryChange(List<Integer> ids, Integer categoryId) {
|
||||
relationService.rebuild(ids, categoryId);
|
||||
}
|
||||
}
|
||||
|
@ -23,24 +23,26 @@ import xyz.playedu.api.domain.ResourceCategoryRelation;
|
||||
import xyz.playedu.api.mapper.ResourceCategoryRelationMapper;
|
||||
import xyz.playedu.api.service.internal.ResourceCategoryRelationService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【resource_category】的数据库操作Service实现
|
||||
* @createDate 2023-03-08 16:54:56
|
||||
*/
|
||||
@Service
|
||||
public class ResourceCategoryRelationServiceImpl
|
||||
extends ServiceImpl<ResourceCategoryRelationMapper, ResourceCategoryRelation>
|
||||
implements ResourceCategoryRelationService {
|
||||
@Override
|
||||
public List<Integer> getRidsByCids(List<Integer> categoryIds) {
|
||||
List<ResourceCategoryRelation> relations =
|
||||
list(query().getWrapper().in("cid", categoryIds));
|
||||
if (relations == null) {
|
||||
return null;
|
||||
}
|
||||
return relations.stream().map(ResourceCategoryRelation::getRid).toList();
|
||||
public void rebuild(List<Integer> ids, Integer categoryId) {
|
||||
remove(query().getWrapper().in("rid", ids));
|
||||
List<ResourceCategoryRelation> data = new ArrayList<>();
|
||||
ids.forEach(
|
||||
(item) ->
|
||||
data.add(
|
||||
new ResourceCategoryRelation() {
|
||||
{
|
||||
setCid(categoryId);
|
||||
setRid(item);
|
||||
}
|
||||
}));
|
||||
saveBatch(data);
|
||||
}
|
||||
}
|
||||
|
@ -21,12 +21,6 @@ import xyz.playedu.api.domain.ResourceCategoryRelation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【resource_category】的数据库操作Service
|
||||
* @createDate 2023-03-08 16:54:56
|
||||
*/
|
||||
public interface ResourceCategoryRelationService extends IService<ResourceCategoryRelation> {
|
||||
|
||||
List<Integer> getRidsByCids(List<Integer> categoryIds);
|
||||
public void rebuild(List<Integer> ids, Integer categoryId);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user