From 8a9e3a1307710ee7e6ac7ef73ece6ee8fc9e4ecc Mon Sep 17 00:00:00 2001
From: lyfO_o <764716047@qq.com>
Date: 星期二, 28 六月 2022 11:55:01 +0800
Subject: [PATCH] 菜单和登录
---
safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/LoginController.java | 14 ++++++-
safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/exception/GlobalExceptionHandler.java | 51 +++++++++++++++++++++++++
safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/MenuController.java | 45 ++++++++++++++++++++++
3 files changed, 108 insertions(+), 2 deletions(-)
diff --git a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/LoginController.java b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/LoginController.java
index e257ec2..608b319 100644
--- a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/LoginController.java
+++ b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/LoginController.java
@@ -2,7 +2,8 @@
import com.alibaba.fastjson.JSONObject;
import com.gkhy.safePlatform.account.rpc.apimodel.UserAccountService;
-import com.gkhy.safePlatform.account.rpc.apimodel.model.UserLoginRespDTO;
+import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.MenuRPCRespDTO;
+import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.UserLoginRPCRespDTO;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
@@ -10,6 +11,9 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
+
+import java.security.Principal;
+import java.util.List;
@RestController
@RequestMapping("/auth")
@@ -19,9 +23,15 @@
private UserAccountService userAccountService;
@RequestMapping("/login")
- public ResultVO<UserLoginRespDTO> authLogin(@RequestBody JSONObject loginForm){
+ public ResultVO<UserLoginRPCRespDTO> authLogin(@RequestBody JSONObject loginForm){
String username = loginForm.getString("username");
String password = loginForm.getString("password");
return userAccountService.authLogin(username, password);
}
+
+ @RequestMapping("/menu")
+ public ResultVO<List<MenuRPCRespDTO>> getMenu(Principal principal, Long projectId){
+ String userId = principal.getName();
+ return userAccountService.getMenu(Long.valueOf(userId), projectId);
+ }
}
diff --git a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/MenuController.java b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/MenuController.java
new file mode 100644
index 0000000..ccc7f7d
--- /dev/null
+++ b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/accountController/MenuController.java
@@ -0,0 +1,45 @@
+package com.gkhy.safePlatform.accountController;
+
+import com.gkhy.safePlatform.account.rpc.apimodel.UserAccountService;
+import com.gkhy.safePlatform.account.rpc.apimodel.model.req.MenuAddRPCReqDTO;
+import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.MenuModRPCReqDTO;
+import com.gkhy.safePlatform.commons.enums.ResultCodes;
+import com.gkhy.safePlatform.commons.vo.ResultVO;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.security.Principal;
+
+@RestController
+@RequestMapping("/menu")
+public class MenuController {
+
+ @DubboReference(check = false)
+ private UserAccountService userAccountService;
+
+
+ /**
+ * @Description: 新增菜单
+ */
+ @RequestMapping(value = "/add",method = RequestMethod.POST)
+ public ResultVO<String> addMenu(Principal principal, @RequestBody MenuAddRPCReqDTO menuAddDto) {
+ String userId = principal.getName();
+ userAccountService.addMenu(Long.valueOf(userId), menuAddDto);
+ return new ResultVO<>(ResultCodes.OK);
+ }
+
+
+ /**
+ * @Description: 新增菜单
+ */
+ @RequestMapping(value = "/mod",method = RequestMethod.POST)
+ public ResultVO<String> addMenu(Principal principal, @RequestBody MenuModRPCReqDTO menuModDto) {
+ String userId = principal.getName();
+ userAccountService.modMenu(Long.valueOf(userId), menuModDto);
+ return new ResultVO<>(ResultCodes.OK);
+ }
+
+}
diff --git a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/exception/GlobalExceptionHandler.java b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/exception/GlobalExceptionHandler.java
new file mode 100644
index 0000000..a8493d2
--- /dev/null
+++ b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/exception/GlobalExceptionHandler.java
@@ -0,0 +1,51 @@
+package com.gkhy.safePlatform.config.exception;
+
+
+import com.gkhy.safePlatform.commons.enums.ResultCodes;
+import com.gkhy.safePlatform.commons.exception.AusinessException;
+import com.gkhy.safePlatform.commons.exception.BusinessException;
+import com.gkhy.safePlatform.commons.vo.ResultVO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@ControllerAdvice
+public class GlobalExceptionHandler {
+
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+
+ /**
+ * 自定义异常
+ */
+ @ResponseBody
+ @ExceptionHandler(value = AusinessException.class)
+ public ResultVO AHandler(AusinessException e) {
+ logger.warn(e.getMessage());
+ return new ResultVO(e.getCode(),e.getMessage());
+ }
+
+
+ /**
+ * 通用异常
+ */
+ @ResponseBody
+ @ExceptionHandler(value = BusinessException.class)
+ public ResultVO AHandler(BusinessException e) {
+ logger.warn(e.getMessage());
+ return new ResultVO(e.getError());
+ }
+
+ /**
+ * 系统错误异常
+ */
+ @ResponseBody
+ @ExceptionHandler(value = Exception.class)
+ public ResultVO errorHandler(Exception e) {
+ e.printStackTrace();
+ logger.error(e.getMessage());
+ return new ResultVO(ResultCodes.SERVER_ERROR);
+ }
+}
--
Gitblit v1.9.2