增加付费片单,修复种子列表搜索排序
Change-Id: Ib645906c0f240f954676790daf2ff0e5f16f6e0a
diff --git a/src/main/java/com/example/myproject/config/GlobalExceptionHandler.java b/src/main/java/com/example/myproject/config/GlobalExceptionHandler.java
new file mode 100644
index 0000000..abcd055
--- /dev/null
+++ b/src/main/java/com/example/myproject/config/GlobalExceptionHandler.java
@@ -0,0 +1,29 @@
+package com.example.myproject.config;
+
+import cn.dev33.satoken.exception.NotLoginException;
+import cn.dev33.satoken.exception.NotPermissionException;
+import cn.dev33.satoken.exception.NotRoleException;
+import com.example.myproject.common.base.Result;
+import com.example.myproject.exception.BusinessException;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+@RestControllerAdvice
+public class GlobalExceptionHandler {
+
+ @ExceptionHandler(BusinessException.class)
+ public Result handleException(BusinessException e) {
+ // 这里可以根据不同的异常类型返回不同的结果
+ return Result.error(e.getMessage());
+ }
+
+ @ExceptionHandler(value = {NotLoginException.class})
+ public Result unLoginHandler(){
+ return Result.error(401, "您还未登录");
+ }
+ @ExceptionHandler(value = {NotRoleException.class, NotPermissionException.class})
+ public Result handlerException() {
+ return Result.error(403, "您没有权限");
+ }
+}
diff --git a/src/main/java/com/example/myproject/config/StpInterfaceImpl.java b/src/main/java/com/example/myproject/config/StpInterfaceImpl.java
new file mode 100644
index 0000000..8bf2c13
--- /dev/null
+++ b/src/main/java/com/example/myproject/config/StpInterfaceImpl.java
@@ -0,0 +1,48 @@
+package com.example.myproject.config;
+
+import cn.dev33.satoken.stp.StpInterface;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+
+import com.example.myproject.entity.Users;
+import com.example.myproject.repository.UserRepository;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 自定义权限加载接口实现类
+ */
+@Component // 保证此类被 SpringBoot 扫描,完成 Sa-Token 的自定义权限验证扩展
+@RequiredArgsConstructor
+public class StpInterfaceImpl implements StpInterface {
+ private final UserRepository userRepository;
+
+ /**
+ * 返回一个账号所拥有的权限码集合
+ */
+ @Override
+ public List<String> getPermissionList(Object loginId, String loginType) {
+ return new ArrayList<>();
+ }
+
+ /**
+ * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
+ */
+ @Override
+ @Transactional
+ public List<String> getRoleList(Object loginId, String loginType) {
+ List<String> list = new ArrayList<String>();
+ long id = 0;
+ if(loginId instanceof String){
+ id = Long.parseLong(loginId.toString());
+ }else{
+ id = (long) loginId;
+ }
+ Users user = userRepository.getById(id);
+ list.add(user.getLevelRole());
+ return list;
+ }
+
+}