mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-07 01:34:05 +08:00
新增: 资源名称和分类编辑接口
This commit is contained in:
parent
147da9f38a
commit
12056f648f
@ -26,11 +26,6 @@ import xyz.playedu.api.service.AdminPermissionService;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
*
|
||||
* @create 2023/2/20 14:31
|
||||
*/
|
||||
@Component
|
||||
public class AdminPermissionCheck implements ApplicationRunner {
|
||||
|
||||
@ -122,6 +117,15 @@ public class AdminPermissionCheck implements ApplicationRunner {
|
||||
.RESOURCE_DESTROY);
|
||||
}
|
||||
},
|
||||
new AdminPermission() {
|
||||
{
|
||||
setSort(10);
|
||||
setName("编辑");
|
||||
setSlug(
|
||||
BPermissionConstant
|
||||
.RESOURCE_UPDATE);
|
||||
}
|
||||
},
|
||||
});
|
||||
// 学员
|
||||
put(
|
||||
|
@ -35,8 +35,6 @@ public class BPermissionConstant {
|
||||
public static final String DEPARTMENT_CUD = "department-cud";
|
||||
public static final String DEPARTMENT_USER_LEARN = "department-user-learn";
|
||||
|
||||
public static final String RESOURCE_CATEGORY = "resource-category";
|
||||
|
||||
public static final String USER_INDEX = "user-index";
|
||||
public static final String USER_STORE = "user-store";
|
||||
public static final String USER_UPDATE = "user-update";
|
||||
@ -48,7 +46,9 @@ public class BPermissionConstant {
|
||||
public static final String COURSE_USER = "course-user";
|
||||
public static final String COURSE_USER_DESTROY = "course-user-destroy";
|
||||
|
||||
public static final String RESOURCE_CATEGORY = "resource-category";
|
||||
public static final String RESOURCE_DESTROY = "resource-destroy";
|
||||
public static final String RESOURCE_UPDATE = "resource-update";
|
||||
|
||||
public static final String SYSTEM_CONFIG = "system-config";
|
||||
|
||||
|
@ -25,7 +25,6 @@ import xyz.playedu.api.bus.BackendBus;
|
||||
import xyz.playedu.api.constant.BPermissionConstant;
|
||||
import xyz.playedu.api.domain.AdminUser;
|
||||
import xyz.playedu.api.event.AdminUserLoginEvent;
|
||||
import xyz.playedu.api.exception.JwtLogoutException;
|
||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||
import xyz.playedu.api.middleware.ImageCaptchaCheckMiddleware;
|
||||
import xyz.playedu.api.request.backend.LoginRequest;
|
||||
@ -84,7 +83,7 @@ public class LoginController {
|
||||
}
|
||||
|
||||
@PostMapping("/logout")
|
||||
public JsonResponse logout() throws JwtLogoutException {
|
||||
public JsonResponse logout() {
|
||||
authService.logout();
|
||||
return JsonResponse.success("success");
|
||||
}
|
||||
|
@ -15,9 +15,12 @@
|
||||
*/
|
||||
package xyz.playedu.api.controller.backend;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
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.BCtx;
|
||||
@ -29,8 +32,8 @@ 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.request.backend.ResourceUpdateRequest;
|
||||
import xyz.playedu.api.service.AdminUserService;
|
||||
import xyz.playedu.api.service.MinioService;
|
||||
import xyz.playedu.api.service.ResourceService;
|
||||
@ -147,30 +150,14 @@ 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());
|
||||
|
||||
@PutMapping("/{id}")
|
||||
@SneakyThrows
|
||||
public JsonResponse update(
|
||||
@RequestBody @Validated ResourceUpdateRequest req,
|
||||
@PathVariable(name = "id") Integer id) {
|
||||
Resource resource = resourceService.findOrFail(id);
|
||||
resourceService.updateNameAndCategoryId(
|
||||
resource.getId(), req.getName(), req.getCategoryId());
|
||||
return JsonResponse.success();
|
||||
}
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 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.exception;
|
||||
|
||||
public class JwtLogoutException extends Exception {
|
||||
public JwtLogoutException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public JwtLogoutException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JwtLogoutException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public JwtLogoutException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
protected JwtLogoutException(
|
||||
String message,
|
||||
Throwable cause,
|
||||
boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
@ -19,13 +19,7 @@ import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
*
|
||||
* @create 2023/3/13 10:41
|
||||
*/
|
||||
@Data
|
||||
public class ResourceDestroyMultiRequest {
|
||||
|
||||
private List<Integer> ids;
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 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.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
@Data
|
||||
public class ResourceUpdateRequest {
|
||||
|
||||
@NotBlank(message = "请输入资源名")
|
||||
@Length(min = 1, max = 254, message = "资源名长度在1-254个字符之间")
|
||||
private String name;
|
||||
|
||||
@NotNull(message = "category_id参数不存在")
|
||||
@JsonProperty("category_id")
|
||||
private Integer categoryId;
|
||||
}
|
@ -54,5 +54,5 @@ public interface ResourceService extends IService<Resource> {
|
||||
|
||||
Integer duration(Integer id);
|
||||
|
||||
void categoryChange(List<Integer> ids, Integer categoryId);
|
||||
void updateNameAndCategoryId(Integer id, String name, Integer categoryId);
|
||||
}
|
||||
|
@ -157,7 +157,19 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void categoryChange(List<Integer> ids, Integer categoryId) {
|
||||
relationService.rebuild(ids, categoryId);
|
||||
@Transactional
|
||||
public void updateNameAndCategoryId(Integer id, String name, Integer categoryId) {
|
||||
Resource resource = new Resource();
|
||||
resource.setId(id);
|
||||
resource.setName(name);
|
||||
updateById(resource);
|
||||
|
||||
relationService.rebuild(
|
||||
id,
|
||||
new ArrayList<>() {
|
||||
{
|
||||
add(categoryId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -31,18 +31,21 @@ public class ResourceCategoryRelationServiceImpl
|
||||
extends ServiceImpl<ResourceCategoryRelationMapper, ResourceCategoryRelation>
|
||||
implements ResourceCategoryRelationService {
|
||||
@Override
|
||||
public void rebuild(List<Integer> ids, Integer categoryId) {
|
||||
remove(query().getWrapper().in("rid", ids));
|
||||
public void rebuild(Integer resourceId, List<Integer> categoryIds) {
|
||||
remove(query().getWrapper().eq("rid", resourceId));
|
||||
|
||||
List<ResourceCategoryRelation> data = new ArrayList<>();
|
||||
ids.forEach(
|
||||
(item) ->
|
||||
data.add(
|
||||
new ResourceCategoryRelation() {
|
||||
{
|
||||
setCid(categoryId);
|
||||
setRid(item);
|
||||
}
|
||||
}));
|
||||
categoryIds.forEach(
|
||||
categoryId -> {
|
||||
data.add(
|
||||
new ResourceCategoryRelation() {
|
||||
{
|
||||
setCid(categoryId);
|
||||
setRid(resourceId);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
saveBatch(data);
|
||||
}
|
||||
}
|
||||
|
@ -22,5 +22,5 @@ import xyz.playedu.api.domain.ResourceCategoryRelation;
|
||||
import java.util.List;
|
||||
|
||||
public interface ResourceCategoryRelationService extends IService<ResourceCategoryRelation> {
|
||||
public void rebuild(List<Integer> ids, Integer categoryId);
|
||||
void rebuild(Integer resourceId, List<Integer> categoryIds);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user