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); } } 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); } } 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); } }