| | |
| | | @Resource |
| | | ManageMenuMapper manageMenuMapper; |
| | | |
| | | |
| | | /** |
| | | * @Description: 登陆 |
| | | * @Param: [paramters] |
| | | * @return: java.util.Map<java.lang.String , java.lang.Object> |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/3/11 |
| | | */ |
| | | @Override |
| | | public Map<String, Object> login(Map<String, Object> paramters) { |
| | | Map<String,Object> result = new HashMap<>(); |
| | | Map<String, Object> result = new HashMap<>(); |
| | | //接收参数 |
| | | String cyrpAccount = (String) paramters.get("account"); |
| | | String cyrpPassword = (String) paramters.get("password"); |
| | |
| | | QueryWrapper<ManageAccount> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("account", account); |
| | | ManageAccount manageAccount = accountMapper.selectOne(wrapper); |
| | | if(ObjectUtils.isEmpty(manageAccount)){ |
| | | result.put("accountId",-1); |
| | | result.put("msg","用户不存在"); |
| | | if (ObjectUtils.isEmpty(manageAccount)) { |
| | | result.put("accountId", -1); |
| | | result.put("msg", "用户不存在"); |
| | | return result; |
| | | } |
| | | //查询是否逻辑删除 |
| | | if(manageAccount.getIsDelete().equals("1")){ |
| | | result.put("accountId",-2); |
| | | result.put("msg","用户已被封禁"); |
| | | if (manageAccount.getIsDelete().equals("1")) { |
| | | result.put("accountId", -2); |
| | | result.put("msg", "用户已被封禁"); |
| | | return result; |
| | | } |
| | | //校验密码 |
| | | if(!MD5Utils.saltMD5Verify(password,manageAccount.getPassword())){ |
| | | result.put("accountId",-3); |
| | | result.put("msg","用户名密码错误"); |
| | | if (!MD5Utils.saltMD5Verify(password, manageAccount.getPassword())) { |
| | | result.put("accountId", -3); |
| | | result.put("msg", "用户名密码错误"); |
| | | return result; |
| | | } |
| | | //查询角色 |
| | | List<ManageRole> roles = roleMapper.getManageRoleByAccountId(manageAccount.getId()); |
| | | if(ObjectUtils.isEmpty(roles)){ |
| | | result.put("accountId",-4); |
| | | result.put("msg","用户尚未分配角色"); |
| | | if (ObjectUtils.isEmpty(roles)) { |
| | | result.put("accountId", -4); |
| | | result.put("msg", "用户尚未分配角色"); |
| | | return result; |
| | | } |
| | | //查询菜单 |
| | | List<ManageMenu> menus = manageMenuMapper.getParentChildrenMenusByRoles(roles); |
| | | if(ObjectUtils.isEmpty(menus)){ |
| | | result.put("accountId",-5); |
| | | result.put("msg","用户尚未分配菜单"); |
| | | if (ObjectUtils.isEmpty(menus)) { |
| | | result.put("accountId", -5); |
| | | result.put("msg", "用户尚未分配菜单"); |
| | | return result; |
| | | } |
| | | |
| | | //获取用户token,并且将基本信息存入缓存 |
| | | Map<String,Object> userInfo = new HashMap<>();//需要保存在缓存中用户的数据 |
| | | userInfo.put("accountId",manageAccount.getId());//用户Id |
| | | userInfo.put("userName",manageAccount.getUserName());//用户名称 |
| | | userInfo.put("roles",roles);//用户角色 |
| | | userInfo.put("menus",menus);//用户菜单 |
| | | Map<String, Object> tokenResult = TokenUtils.getToken(String.valueOf(manageAccount.getId()), userInfo); |
| | | if(tokenResult.get("code").equals(TokenUtils.error)){ |
| | | result.put("accountId",-6); |
| | | result.put("msg","生成token错误"); |
| | | return result; |
| | | } |
| | | Map<String, Object> userInfo = new HashMap<>();//需要保存在缓存中用户的数据 |
| | | userInfo.put("accountId", manageAccount.getId());//用户Id |
| | | userInfo.put("userName", manageAccount.getUserName());//用户名称 |
| | | userInfo.put("roles", roles);//用户角色 |
| | | userInfo.put("menus", menus);//用户菜单 |
| | | String token = TokenUtils.getToken(String.valueOf(manageAccount.getId()), userInfo); |
| | | |
| | | |
| | | //打包返回信息 |
| | | result.put("accountId",manageAccount.getId());//用户Id |
| | | result.put("userName",manageAccount.getUserName());//用户名称 |
| | | result.put("roles",roles);//用户角色 |
| | | result.put("menus",menus);//用户菜单 |
| | | result.put("token",tokenResult.get("token")); |
| | | result.put("accountId", manageAccount.getId());//用户Id |
| | | result.put("userName", manageAccount.getUserName());//用户名称 |
| | | result.put("roles", roles);//用户角色 |
| | | result.put("menus", menus);//用户菜单 |
| | | result.put("token", token); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * @Description: 注销 |
| | | * @Param: [paramters] |
| | | * @return: java.util.Map<java.lang.String , java.lang.Object> |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/3/11 |
| | | */ |
| | | @Override |
| | | public Map<String, Object> logout(Map<String, Object> paramters) { |
| | | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | } |