diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/common/CommonErrorCodeConstants.java b/dl-module-base/src/main/java/cn/iocoder/yudao/common/CommonErrorCodeConstants.java index cbafc1a1..44fa0ab3 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/common/CommonErrorCodeConstants.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/common/CommonErrorCodeConstants.java @@ -12,4 +12,5 @@ public interface CommonErrorCodeConstants extends ErrorCodeConstants { ErrorCode LOGIN_ACCOUNT_EXIST = new ErrorCode(2_002_000_004, "登录账号已存在"); ErrorCode LOGIN_ACCOUNT_NOT_EXIST = new ErrorCode(2_002_000_005, "登录账号不存在"); ErrorCode SYSTEM_ERROR = new ErrorCode(2_002_000_005, "系统错误"); + ErrorCode MISTAKEN_IDENTITY = new ErrorCode(2_002_000_006, "身份有误"); } diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java index 57119d88..cd1af150 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.rescue.app.controller.admin; +import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.common.CommonErrorCodeConstants; import cn.iocoder.yudao.framework.common.pojo.CommonResult; @@ -24,8 +25,12 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -304,62 +309,66 @@ public class SysLoginController { // return ajax; // } // -// /** -// * 获取App用户信息 -// * -// * @return 用户信息 -// */ -// @GetMapping("/getJcgfInfo") -// public AjaxResult getJcgfInfo() throws Exception { -// SysUser user = SecurityUtils.getLoginUser().getUser(); -// SysUser sysUser = userService.selectUserById(user.getUserId()); -// // 角色集合 -// Set roles = permissionService.getRolePermission(user); -// AjaxResult ajax = success(); -// ajax.put("user", sysUser); -// ajax.put("role", roles); -// if (CollectionUtil.isNotEmpty(roles)){ -// AtomicBoolean flag = new AtomicBoolean(false); -// roles.forEach(it->{ -// if (it.equals("jcgf")){ -// flag.set(true); -// } -// }); -// if (!flag.get()){ -// throw new Exception("身份有误"); -// } -// }else { -// throw new Exception("身份有误"); -// } -// -// return ajax; -// } -// //获取交警的信息 -// @GetMapping("/getJjInfo") -// public AjaxResult getJjInfo() throws Exception { -// SysUser user = SecurityUtils.getLoginUser().getUser(); -// SysUser sysUser = userService.selectUserById(user.getUserId()); -// // 角色集合 -// Set roles = permissionService.getRolePermission(user); -// AjaxResult ajax = success(); -// ajax.put("user", sysUser); -// ajax.put("role", roles); -// if (CollectionUtil.isNotEmpty(roles)){ -// AtomicBoolean flag = new AtomicBoolean(false); -// roles.forEach(it->{ -// if (it.equals("jjdd")){ -// flag.set(true); -// } -// }); -// if (!flag.get()){ -// throw new Exception("身份有误"); -// } -// }else { -// throw new Exception("身份有误"); -// } -// -// return ajax; -// } + /** + * 获取App用户信息 + * + * @return 用户信息 + */ + @GetMapping("/getJcgfInfo") + public CommonResult getJcgfInfo() throws Exception { + Map map = new HashMap<>(); + LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); + AdminUserRespDTO user = userService.getUser(loginUser.getId()); + // 角色集合 + List roleList = roleApi.getRoleList(); + List roleIdsByUserId = permissionApi.getRoleIdsByUserId(user.getId()); + List roles = roleList.stream().filter(item -> roleIdsByUserId.contains(item.getId())).collect(Collectors.toList()); + map.put("user", user); + map.put("role", roles); + if (CollectionUtil.isNotEmpty(roles)){ + AtomicBoolean flag = new AtomicBoolean(false); + roles.forEach(it->{ + if (it.getCode().equals("jcgf")){ + flag.set(true); + } + }); + if (!flag.get()){ + throw exception(CommonErrorCodeConstants.MISTAKEN_IDENTITY); + } + }else { + throw exception(CommonErrorCodeConstants.MISTAKEN_IDENTITY); + } + + return success(map); + } + //获取交警的信息 + @GetMapping("/getJjInfo") + public CommonResult getJjInfo() throws Exception { + Map map = new HashMap<>(); + LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); + AdminUserRespDTO user = userService.getUser(loginUser.getId()); + // 角色集合 + List roleList = roleApi.getRoleList(); + List roleIdsByUserId = permissionApi.getRoleIdsByUserId(user.getId()); + List roles = roleList.stream().filter(item -> roleIdsByUserId.contains(item.getId())).collect(Collectors.toList()); + map.put("user", user); + map.put("role", roles); + if (CollectionUtil.isNotEmpty(roles)){ + AtomicBoolean flag = new AtomicBoolean(false); + roles.forEach(it->{ + if (it.getCode().equals("jjdd")){ + flag.set(true); + } + }); + if (!flag.get()){ + throw exception(CommonErrorCodeConstants.MISTAKEN_IDENTITY); + } + }else { + throw exception(CommonErrorCodeConstants.MISTAKEN_IDENTITY); + } + + return success(map); + } // /** // * 获取App用户信息 // *