mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-20 19:02:48 +08:00
优化代码
This commit is contained in:
parent
639f3065a2
commit
de6a9718f4
@ -42,11 +42,11 @@ public class BCtx {
|
||||
THREAD_LOCAL.remove();
|
||||
}
|
||||
|
||||
public static Integer getAdminUserID() {
|
||||
public static Integer getId() {
|
||||
return (Integer) get(KEY_ADMIN_USER_ID);
|
||||
}
|
||||
|
||||
public static void setAdminUserId(Integer userId) {
|
||||
public static void setId(Integer userId) {
|
||||
put(KEY_ADMIN_USER_ID, userId);
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ public class BackendBus {
|
||||
if (superRole == null) {
|
||||
return false;
|
||||
}
|
||||
List<Integer> roleIds = adminUserService.getRoleIdsByUserId(BCtx.getAdminUserID());
|
||||
List<Integer> roleIds = adminUserService.getRoleIdsByUserId(BCtx.getId());
|
||||
if (roleIds.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class CourseChapterController {
|
||||
return JsonResponse.error("当前章节下面存在课时无法删除");
|
||||
}
|
||||
chapterService.removeById(chapter.getId());
|
||||
ctx.publishEvent(new CourseChapterDestroyEvent(this, BCtx.getAdminUserID(), chapter.getCourseId(), chapter.getId()));
|
||||
ctx.publishEvent(new CourseChapterDestroyEvent(this, BCtx.getId(), chapter.getCourseId(), chapter.getId()));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
|
@ -191,7 +191,7 @@ public class CourseController {
|
||||
@DeleteMapping("/{id}")
|
||||
public JsonResponse destroy(@PathVariable(name = "id") Integer id) {
|
||||
courseService.removeById(id);
|
||||
ctx.publishEvent(new CourseDestroyEvent(this, BCtx.getAdminUserID(), id));
|
||||
ctx.publishEvent(new CourseDestroyEvent(this, BCtx.getId(), id));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class CourseHourController {
|
||||
}
|
||||
|
||||
CourseHour courseHour = hourService.create(courseId, chapterId, req.getSort(), req.getTitle(), type, req.getRid(), req.getDuration());
|
||||
ctx.publishEvent(new CourseHourCreatedEvent(this, BCtx.getAdminUserID(), courseHour.getCourseId(), courseHour.getChapterId(), courseHour.getId()));
|
||||
ctx.publishEvent(new CourseHourCreatedEvent(this, BCtx.getId(), courseHour.getCourseId(), courseHour.getChapterId(), courseHour.getId()));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ public class CourseHourController {
|
||||
|
||||
// 只需要发布一次event就可以了
|
||||
CourseHour firstHour = hours.get(0);
|
||||
ctx.publishEvent(new CourseHourCreatedEvent(this, BCtx.getAdminUserID(), firstHour.getCourseId(), firstHour.getChapterId(), firstHour.getId()));
|
||||
ctx.publishEvent(new CourseHourCreatedEvent(this, BCtx.getId(), firstHour.getCourseId(), firstHour.getChapterId(), firstHour.getId()));
|
||||
|
||||
return JsonResponse.success();
|
||||
}
|
||||
@ -154,7 +154,7 @@ public class CourseHourController {
|
||||
public JsonResponse destroy(@PathVariable(name = "courseId") Integer courseId, @PathVariable(name = "id") Integer id) throws NotFoundException {
|
||||
CourseHour courseHour = hourService.findOrFail(id, courseId);
|
||||
hourService.removeById(courseHour.getId());
|
||||
ctx.publishEvent(new CourseHourDestroyEvent(this, BCtx.getAdminUserID(), courseHour.getCourseId(), courseHour.getChapterId(), courseHour.getId()));
|
||||
ctx.publishEvent(new CourseHourDestroyEvent(this, BCtx.getId(), courseHour.getCourseId(), courseHour.getChapterId(), courseHour.getId()));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ public class DepartmentController {
|
||||
public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException {
|
||||
Department department = departmentService.findOrFail(id);
|
||||
departmentService.deleteById(department.getId());
|
||||
ctx.publishEvent(new DepartmentDestroyEvent(this, BCtx.getAdminUserID(), department.getId()));
|
||||
ctx.publishEvent(new DepartmentDestroyEvent(this, BCtx.getId(), department.getId()));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ public class ResourceCategoryController {
|
||||
public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException {
|
||||
ResourceCategory category = categoryService.findOrFail(id);
|
||||
categoryService.deleteById(category.getId());
|
||||
ctx.publishEvent(new ResourceCategoryDestroyEvent(this, BCtx.getAdminUserID(), category.getId()));
|
||||
ctx.publishEvent(new ResourceCategoryDestroyEvent(this, BCtx.getId(), category.getId()));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class ResourceController {
|
||||
filter.setName(name);
|
||||
|
||||
if (!backendBus.isSuperAdmin()) {// 非超管只能读取它自己上传的资源
|
||||
filter.setAdminId(BCtx.getAdminUserID());
|
||||
filter.setAdminId(BCtx.getId());
|
||||
}
|
||||
|
||||
PaginationResult<Resource> result = resourceService.paginate(page, size, filter);
|
||||
|
@ -40,7 +40,7 @@ public class UploadController {
|
||||
@PostMapping("/minio")
|
||||
public JsonResponse uploadMinio(@RequestParam HashMap<String, Object> params, MultipartFile file) throws ServiceException {
|
||||
String categoryIds = MapUtils.getString(params, "category_ids");
|
||||
Resource res = uploadService.storeMinio(BCtx.getAdminUserID(), file, categoryIds);
|
||||
Resource res = uploadService.storeMinio(BCtx.getId(), file, categoryIds);
|
||||
return JsonResponse.data(res);
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ public class UploadController {
|
||||
|
||||
// 视频素材保存
|
||||
Resource videoResource = resourceService.create(
|
||||
BCtx.getAdminUserID(),
|
||||
BCtx.getId(),
|
||||
req.getCategoryIds(),
|
||||
type,
|
||||
req.getOriginalFilename(),
|
||||
@ -104,7 +104,7 @@ public class UploadController {
|
||||
url
|
||||
);
|
||||
// 视频封面素材保存
|
||||
Resource posterResource = uploadService.storeBase64Image(BCtx.getAdminUserID(), req.getPoster(), null);
|
||||
Resource posterResource = uploadService.storeBase64Image(BCtx.getId(), req.getPoster(), null);
|
||||
// 视频的封面素材改为[隐藏 && 属于视频的子素材]
|
||||
resourceService.changeParentId(posterResource.getId(), videoResource.getId());
|
||||
// 视频信息
|
||||
|
@ -71,7 +71,7 @@ public class AdminMiddleware implements HandlerInterceptor {
|
||||
return responseTransform(response, 403, "当前管理员禁止登录");
|
||||
}
|
||||
|
||||
BCtx.setAdminUserId(payload.getSub());
|
||||
BCtx.setId(payload.getSub());
|
||||
BCtx.setAdminUser(adminUser);
|
||||
BCtx.setAdminPer(backendBus.adminUserPermissions(adminUser.getId()));
|
||||
|
||||
|
@ -35,7 +35,7 @@ public class BackendPermissionMiddlewareImpl {
|
||||
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
BackendPermissionMiddleware middleware = signature.getMethod().getAnnotation(BackendPermissionMiddleware.class);
|
||||
Integer adminUserId = BCtx.getAdminUserID();
|
||||
Integer adminUserId = BCtx.getId();
|
||||
HashMap<String, Boolean> permissions = backendBus.adminUserPermissions(adminUserId);
|
||||
if (permissions.get(middleware.slug()) == null) {
|
||||
return JsonResponse.error("权限不足", 403);
|
||||
|
Loading…
x
Reference in New Issue
Block a user