| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.ManageAccount; |
| | | import com.moral.api.entity.ManageMenu; |
| | | import com.moral.api.entity.ManageRole; |
| | | import com.moral.api.mapper.ManageAccountMapper; |
| | | import com.moral.api.mapper.ManageMenuMapper; |
| | | import com.moral.api.mapper.ManageRoleMapper; |
| | | import com.moral.api.service.ManageAccountService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.util.AESUtils; |
| | | import com.moral.util.MD5Utils; |
| | | import com.moral.util.TokenUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class ManageAccountServiceImpl extends ServiceImpl<ManageAccountMapper, ManageAccount> implements ManageAccountService { |
| | | |
| | | @Value("${AES.KEY}") |
| | | private String AESKey; |
| | | @Resource |
| | | ManageAccountMapper accountMapper; |
| | | @Resource |
| | | ManageRoleMapper roleMapper; |
| | | @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<>(); |
| | | //接收参数 |
| | | String cyrpAccount = (String) paramters.get("account"); |
| | | String cyrpPassword = (String) paramters.get("password"); |
| | | //解密 |
| | | String account = AESUtils.decrypt(cyrpAccount, AESKey); |
| | | String password = AESUtils.decrypt(cyrpPassword, AESKey); |
| | | //查询是否存在 |
| | | 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", "用户不存在"); |
| | | return result; |
| | | } |
| | | //查询是否逻辑删除 |
| | | 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", "用户名密码错误"); |
| | | return result; |
| | | } |
| | | //查询角色 |
| | | List<ManageRole> roles = roleMapper.getManageRoleByAccountId(manageAccount.getId()); |
| | | 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", "用户尚未分配菜单"); |
| | | 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);//用户菜单 |
| | | 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", 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; |
| | | } |
| | | |
| | | |
| | | } |