|
@@ -0,0 +1,99 @@
|
|
|
|
|
+package cn.tr.module.sys.oauth2.controller;
|
|
|
|
|
+
|
|
|
|
|
+import cn.tr.core.exception.ServiceException;
|
|
|
|
|
+import cn.tr.core.exception.TRExcCode;
|
|
|
|
|
+import cn.tr.core.pojo.CommonResult;
|
|
|
|
|
+import cn.tr.module.common.annotation.Log;
|
|
|
|
|
+import cn.tr.module.sys.exception.CustomException;
|
|
|
|
|
+import cn.tr.module.sys.oauth2.bean.LoginUser;
|
|
|
|
|
+import cn.tr.module.sys.oauth2.granter.IAccountOperator;
|
|
|
|
|
+import cn.tr.module.sys.oauth2.utils.SecurityUtil;
|
|
|
|
|
+import cn.tr.module.sys.oauth2.vo.AccountInfoVO;
|
|
|
|
|
+import cn.tr.module.sys.oauth2.vo.UserPassVo;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
+
|
|
|
|
|
+import static cn.tr.core.exception.TRExcCode.USER_ERROR_A0154;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @author zzy
|
|
|
|
|
+ * @version 1.0
|
|
|
|
|
+ * @description: AccountController.java
|
|
|
|
|
+ * @date 2026/1/20 10:27
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+@AllArgsConstructor
|
|
|
|
|
+@RestController
|
|
|
|
|
+@Tag(name = "账号信息接口")
|
|
|
|
|
+public class AccountController {
|
|
|
|
|
+ private final List<IAccountOperator> accountOperatorList;
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "修改密码")
|
|
|
|
|
+ @PostMapping("/updatePass")
|
|
|
|
|
+ public CommonResult<Boolean> updatePass(@RequestBody @Validated UserPassVo userPassVo){
|
|
|
|
|
+ if (getAccountOperator().updatePass(userPassVo.getOldPass(), userPassVo.getNewPass())){
|
|
|
|
|
+ return CommonResult.success();
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return CommonResult.error(USER_ERROR_A0154);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Log(title = "获取当前用户信息")
|
|
|
|
|
+ @Operation(summary = "获取当前用户信息")
|
|
|
|
|
+ @PostMapping("/getUserInfo")
|
|
|
|
|
+ public CommonResult getUserInfo(){
|
|
|
|
|
+ return CommonResult.success(getAccountOperator().getUserInfo());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Log(title = "获取权限集合")
|
|
|
|
|
+ @Operation(summary = "获取当前用户权限集合")
|
|
|
|
|
+ @PostMapping("/getPermCode")
|
|
|
|
|
+ public CommonResult getPermCode(){
|
|
|
|
|
+ return CommonResult.success(getAccountOperator().getPermCode());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Log(title = "获取菜单集合")
|
|
|
|
|
+ @Operation(summary = "获取当前用户菜单集合")
|
|
|
|
|
+ @PostMapping("/getMenuList")
|
|
|
|
|
+ public CommonResult getMenuList(){
|
|
|
|
|
+ return CommonResult.success(getAccountOperator().getMenuList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Log(title = "获取当前用户账户信息")
|
|
|
|
|
+ @Operation(summary = "获取当前用户账户信息")
|
|
|
|
|
+ @PostMapping("/getAccountInfo")
|
|
|
|
|
+ public CommonResult getAccountInfo(){
|
|
|
|
|
+ return CommonResult.success(getAccountOperator().getAccountInfo());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Log(title = "保存当前用户信息")
|
|
|
|
|
+ @Operation(summary = "保存当前用户信息")
|
|
|
|
|
+ @PostMapping("/saveAccountInfo")
|
|
|
|
|
+ public CommonResult saveAccountInfo(@RequestBody @Validated AccountInfoVO req){
|
|
|
|
|
+ getAccountOperator().saveAccountInfo(req);
|
|
|
|
|
+ return CommonResult.success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private IAccountOperator getAccountOperator(){
|
|
|
|
|
+ LoginUser loginUser = SecurityUtil.getLoginUser();
|
|
|
|
|
+ Optional<IAccountOperator> accountOperator = accountOperatorList.stream()
|
|
|
|
|
+ .filter(operator -> operator.matchGrantType(loginUser.getGrantType()))
|
|
|
|
|
+ .findFirst();
|
|
|
|
|
+ if(accountOperator.isPresent()){
|
|
|
|
|
+ return accountOperator.get();
|
|
|
|
|
+ }
|
|
|
|
|
+ throw new CustomException(String.format("登录方式【%s】不存在",loginUser.getGrantType().getDesc()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|