|
|
@@ -1,366 +1,362 @@
|
|
|
-package com.nb.framework.web.service.impl;
|
|
|
-
|
|
|
-import cn.dev33.satoken.spring.SpringMVCUtil;
|
|
|
-import cn.dev33.satoken.stp.StpUtil;
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.hutool.crypto.digest.DigestUtil;
|
|
|
-import cn.hutool.http.useragent.UserAgent;
|
|
|
-import cn.hutool.http.useragent.UserAgentUtil;
|
|
|
-import cn.hutool.json.JSONObject;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import com.nb.common.Constants;
|
|
|
-import com.nb.common.MenuConstants;
|
|
|
-import com.nb.common.apply.ApplyManager;
|
|
|
-import com.nb.common.bo.LoginUser;
|
|
|
-import com.nb.common.bo.SysApplyBO;
|
|
|
-import com.nb.common.bo.SysRoleBO;
|
|
|
-import com.nb.common.bo.SysUserBO;
|
|
|
-import com.nb.common.dto.LoginDTO;
|
|
|
-import com.nb.common.enums.*;
|
|
|
-import com.nb.common.exception.CustomException;
|
|
|
-import com.nb.common.exception.apply.ApplyTokenParamException;
|
|
|
-import com.nb.common.exception.apply.NoExistAppKeyException;
|
|
|
-import com.nb.common.util.AddressUtil;
|
|
|
-import com.nb.common.util.IpUtil;
|
|
|
-import com.nb.common.util.SecurityUtil;
|
|
|
-import com.nb.framework.web.service.IUserService;
|
|
|
-import com.nb.system.common.vo.*;
|
|
|
-import com.nb.system.entity.SysApply;
|
|
|
-import com.nb.system.entity.SysMenu;
|
|
|
-import com.nb.system.entity.SysRole;
|
|
|
-import com.nb.system.entity.SysUser;
|
|
|
-import com.nb.system.properties.CaptchaProperties;
|
|
|
-import com.nb.system.service.ISysMenuService;
|
|
|
-import com.nb.system.service.ISysRoleService;
|
|
|
-import com.nb.system.service.ISysUserService;
|
|
|
-import com.nb.system.utils.CaptchaTool;
|
|
|
-import com.google.common.collect.Sets;
|
|
|
-import com.nb.system.utils.TenantUtil;
|
|
|
-import lombok.AllArgsConstructor;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-/**
|
|
|
- * 用户实现类
|
|
|
- *
|
|
|
- * @author Kevin
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-@Service
|
|
|
-@AllArgsConstructor
|
|
|
-@EnableConfigurationProperties(CaptchaProperties.class)
|
|
|
-public class UserServiceImpl implements IUserService {
|
|
|
-
|
|
|
- private final ISysMenuService sysMenuService;
|
|
|
-
|
|
|
- private final CaptchaTool captchaTool;
|
|
|
-
|
|
|
- private final CaptchaProperties captchaProperties;
|
|
|
-
|
|
|
- private final ISysUserService sysUserService;
|
|
|
-
|
|
|
- private final ISysRoleService sysRoleService;
|
|
|
-
|
|
|
- private final ApplyManager applyManager;
|
|
|
-
|
|
|
- @Override
|
|
|
- public String login(LoginDTO req) {
|
|
|
- if (StrUtil.isBlank(req.getGrantType())) {
|
|
|
- throw new CustomException("授权类型不能为空");
|
|
|
- }
|
|
|
- if (!GrantTypeEnum.contains(req.getGrantType())) {
|
|
|
- throw new CustomException("授权类型暂不支持");
|
|
|
- }
|
|
|
- //用户登录
|
|
|
- userLogin(req);
|
|
|
- //第三方应用登录
|
|
|
- applyLogin(req);
|
|
|
- return StpUtil.getTokenValue();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public UserInfoVO getUserInfo() {
|
|
|
- UserInfoVO userInfoVO = new UserInfoVO();
|
|
|
- SysUser sysUser = sysUserService.getById(StpUtil.getLoginIdAsLong());
|
|
|
- // 查询角色列表
|
|
|
- List<SysRole> sysRoleList = sysRoleService.listSysRoleByUserId(sysUser.getId());
|
|
|
- List<RoleInfoVO> roleInfoVOList = sysRoleList.stream().map(item -> {
|
|
|
- RoleInfoVO roleInfoVO = new RoleInfoVO();
|
|
|
- roleInfoVO.setRoleName(item.getRoleName());
|
|
|
- roleInfoVO.setValue(item.getRoleCode());
|
|
|
- return roleInfoVO;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- userInfoVO.setUserId(sysUser.getId().toString());
|
|
|
- userInfoVO.setUsername(sysUser.getAccount());
|
|
|
- userInfoVO.setRealName(sysUser.getNickname());
|
|
|
- userInfoVO.setAvatar(sysUser.getAvatar());
|
|
|
- userInfoVO.setDesc(sysUser.getRemarks());
|
|
|
- userInfoVO.setRoles(roleInfoVOList);
|
|
|
- userInfoVO.setIsSys(sysUser.getIsSys());
|
|
|
- userInfoVO.setTenantId(String.valueOf(sysUser.getTenantId()));
|
|
|
- userInfoVO.setTenantName(sysUser.getTenantName());
|
|
|
- return userInfoVO;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Set<String> getPermCode() {
|
|
|
- return SecurityUtil.getLoginUser().getPermissions();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<RouteItemVO> getMenuList() {
|
|
|
- List<SysMenu> sysMenuList;
|
|
|
- SysUserBO sysUserBO = SecurityUtil.getSysUser();
|
|
|
- if (SecurityUtil.isSuperAdmin()) {
|
|
|
- LambdaQueryWrapper<SysMenu> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- queryWrapper.eq(SysMenu::getStatus, StatusEnum.YES.getCode());
|
|
|
- queryWrapper.in(SysMenu::getMenuType, MenuTypeEnum.DIR.getCode(), MenuTypeEnum.MENU.getCode());
|
|
|
- queryWrapper.eq(!TenantUtil.isTuoRen(),SysMenu::getTenantMenu,true);
|
|
|
- sysMenuList = sysMenuService.list(queryWrapper);
|
|
|
- } else {
|
|
|
- sysMenuList = sysMenuService.listGrantMenuByUserId(sysUserBO.getId());
|
|
|
- }
|
|
|
- List<RouteItemVO> routeItemVOList = sysMenuList.stream()
|
|
|
- .filter(item -> item.getParentId().intValue() == 0)
|
|
|
- .sorted(Comparator.comparing(SysMenu::getSort))
|
|
|
- .map(item -> {
|
|
|
- RouteItemVO node = convertToRoute(item);
|
|
|
- node.setChildren(getChildrenList(item, sysMenuList));
|
|
|
- return node;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- return routeItemVOList;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public AccountInfoVO getAccountInfo() {
|
|
|
- LoginUser loginUser = SecurityUtil.getLoginUser();
|
|
|
- SysUser sysUser = sysUserService.getById(loginUser.getSysUser().getId());
|
|
|
- return BeanUtil.copyProperties(sysUser, AccountInfoVO.class);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void saveAccountInfo(AccountInfoVO req) {
|
|
|
- LoginUser loginUser = SecurityUtil.getLoginUser();
|
|
|
- SysUser entity = BeanUtil.copyProperties(req, SysUser.class);
|
|
|
- entity.setId(loginUser.getSysUser().getId());
|
|
|
- sysUserService.updateById(entity);
|
|
|
- }
|
|
|
-
|
|
|
- private List<RouteItemVO> getChildrenList(SysMenu root, List<SysMenu> list) {
|
|
|
- List<RouteItemVO> childrenList = list.stream()
|
|
|
- .filter(item -> item.getParentId().equals(root.getId()))
|
|
|
- .sorted(Comparator.comparing(SysMenu::getSort))
|
|
|
- .map(item -> {
|
|
|
- RouteItemVO node = convertToRoute(item);
|
|
|
- node.setChildren(getChildrenList(item, list));
|
|
|
- return node;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- return childrenList;
|
|
|
- }
|
|
|
-
|
|
|
- private RouteItemVO convertToRoute(SysMenu item) {
|
|
|
- RouteItemVO node = new RouteItemVO();
|
|
|
- node.setName(StrUtil.upperFirst(item.getRoutePath()));
|
|
|
- node.setPath(item.getRoutePath());
|
|
|
- node.setComponent(item.getComponent());
|
|
|
- // 一级目录
|
|
|
- if (Objects.equals(item.getMenuType(), MenuTypeEnum.DIR.getCode()) && item.getParentId().intValue() == 0) {
|
|
|
- node.setPath("/" + item.getRoutePath());
|
|
|
- node.setComponent(MenuConstants.LAYOUT);
|
|
|
- }
|
|
|
- // 外部链接
|
|
|
- if (Objects.equals(item.getMenuType(), MenuTypeEnum.MENU.getCode()) && Objects.equals(item.getLinkExternal(), LinkExternalEnum.YES.getCode())) {
|
|
|
- node.setComponent(MenuConstants.IFRAME);
|
|
|
- }
|
|
|
- RouteMetoVO routeMetoVO = new RouteMetoVO();
|
|
|
- routeMetoVO.setTitle(item.getMenuName());
|
|
|
- routeMetoVO.setIcon(item.getIcon());
|
|
|
- routeMetoVO.setHideMenu(StrUtil.isNotBlank(item.getVisible()) && item.getVisible().equals(VisibleEnum.HIDE.getCode()));
|
|
|
- // 菜单
|
|
|
- if (Objects.equals(item.getMenuType(), MenuTypeEnum.MENU.getCode())) {
|
|
|
- routeMetoVO.setIgnoreKeepAlive(item.getKeepalive().equals(KeepaliveEnum.YES.getCode()));
|
|
|
- }
|
|
|
- // 外部链接
|
|
|
- if (Objects.equals(item.getMenuType(), MenuTypeEnum.MENU.getCode()) && Objects.equals(item.getLinkExternal(), LinkExternalEnum.YES.getCode())) {
|
|
|
- // 内嵌
|
|
|
- if (Objects.equals(item.getFrame(), FrameEnum.YES.getCode())) {
|
|
|
- routeMetoVO.setFrameSrc(item.getLinkUrl());
|
|
|
- }
|
|
|
- // 外嵌
|
|
|
- if (item.getFrame().equals(FrameEnum.NO.getCode())) {
|
|
|
- node.setPath(item.getLinkUrl());
|
|
|
- }
|
|
|
- }
|
|
|
- node.setMeta(routeMetoVO);
|
|
|
- return node;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private void userLogin(LoginDTO req){
|
|
|
- SysUser sysUser = null;
|
|
|
- if (req.getGrantType().equals(GrantTypeEnum.USERNAME_PASSWORD.getCode())) {
|
|
|
- if (StrUtil.isBlank(req.getUsername())) {
|
|
|
- throw new CustomException("用户名不能为空");
|
|
|
- }
|
|
|
- if (StrUtil.isBlank(req.getPassword())) {
|
|
|
- throw new CustomException("密码不能为空");
|
|
|
- }
|
|
|
- if(captchaProperties.isEnable()){
|
|
|
- HttpServletRequest request = SpringMVCUtil.getRequest();
|
|
|
- String requestFrom = request.getHeader("RequestFrom");
|
|
|
- //来自app的请求不需要验证码
|
|
|
- if(!"TuoRenApp".equals(requestFrom)){
|
|
|
-// captchaTool.ver(req.getCodeKey(),req.getCode());
|
|
|
- }
|
|
|
- }
|
|
|
- sysUser = sysUserService.getOne(Wrappers.lambdaQuery(SysUser.class).eq(SysUser::getAccount, req.getUsername()));
|
|
|
- if (Objects.isNull(sysUser)) {
|
|
|
- log.info("登录用户:{}不存在", req.getUsername());
|
|
|
- throw new CustomException("登录用户不存在");
|
|
|
- }
|
|
|
- if (!SecurityUtil.matchesPassword(req.getPassword(), sysUser.getPassword())) {
|
|
|
- throw new CustomException("账号或密码不正确");
|
|
|
- }
|
|
|
- if (sysUser.getDelFlag().equals(DelFlagEnum.YES.getCode())) {
|
|
|
- log.info("登录用户:{}已被删除", req.getUsername());
|
|
|
- throw new CustomException("对不起,您的账号已被删除");
|
|
|
- }
|
|
|
- if (sysUser.getStatus().equals(StatusEnum.NO.getCode())) {
|
|
|
- log.info("登录用户:{}已被停用", req.getUsername());
|
|
|
- throw new CustomException("对不起,您的账号已被停用");
|
|
|
- }
|
|
|
- }else if (req.getGrantType().equals(GrantTypeEnum.MOBILE_CODE.getCode())) {
|
|
|
- if (StrUtil.isBlank(req.getMobile())) {
|
|
|
- throw new CustomException("手机号不能为空");
|
|
|
- }
|
|
|
- if (StrUtil.isBlank(req.getCode())) {
|
|
|
- throw new CustomException("验证码不能为空");
|
|
|
- }
|
|
|
- // TODO,短信验证码校验,自行实现
|
|
|
- if (!Objects.equals(req.getCode(), Constants.DEFAULT_SMS_CODE)) {
|
|
|
- throw new CustomException("账号或密码不正确");
|
|
|
- }
|
|
|
- sysUser = sysUserService.getOne(Wrappers.lambdaQuery(SysUser.class).eq(SysUser::getPhone, req.getMobile()));
|
|
|
- if (Objects.isNull(sysUser)) {
|
|
|
- log.info("登录用户:{}不存在", req.getUsername());
|
|
|
- throw new CustomException("登录用户不存在");
|
|
|
- }
|
|
|
- if (sysUser.getDelFlag().equals(DelFlagEnum.YES.getCode())) {
|
|
|
- log.info("登录用户:{}已被删除", req.getUsername());
|
|
|
- throw new CustomException("对不起,您的账号已被删除");
|
|
|
- }
|
|
|
- if (sysUser.getStatus().equals(StatusEnum.NO.getCode())) {
|
|
|
- log.info("登录用户:{}已被停用", req.getUsername());
|
|
|
- throw new CustomException("对不起,您的账号已被停用");
|
|
|
- }
|
|
|
- }else {
|
|
|
- return;
|
|
|
- }
|
|
|
- log.info("登录用户:{}", req.getUsername());
|
|
|
- SysUserBO sysUserBO = BeanUtil.copyProperties(sysUser, SysUserBO.class);
|
|
|
- // 查询角色列表
|
|
|
- List<SysRole> sysRoleList = sysRoleService.listSysRoleByUserId(sysUser.getId());
|
|
|
- // 设置角色列表
|
|
|
- sysUserBO.setRoles(sysRoleList.stream().map(item -> BeanUtil.copyProperties(item, SysRoleBO.class)).collect(Collectors.toList()));
|
|
|
- // 查询权限标识
|
|
|
- Set<String> permissions = Sets.newHashSet();
|
|
|
-// if (CollUtil.isNotEmpty(sysRoleList)&&
|
|
|
-// sysRoleList.stream().anyMatch(sysRole -> "admin".equalsIgnoreCase(sysRole.getRoleCode()))) {
|
|
|
-// permissions.add(Constants.ALL_PERMISSION);
|
|
|
+//package com.nb.framework.web.service.impl;
|
|
|
+//
|
|
|
+//import cn.dev33.satoken.spring.SpringMVCUtil;
|
|
|
+//import cn.dev33.satoken.stp.StpUtil;
|
|
|
+//import cn.hutool.core.bean.BeanUtil;
|
|
|
+//import cn.hutool.core.util.StrUtil;
|
|
|
+//import cn.hutool.crypto.digest.DigestUtil;
|
|
|
+//import cn.hutool.http.useragent.UserAgent;
|
|
|
+//import cn.hutool.http.useragent.UserAgentUtil;
|
|
|
+//import cn.hutool.json.JSONObject;
|
|
|
+//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+//import com.nb.common.Constants;
|
|
|
+//import com.nb.common.MenuConstants;
|
|
|
+//import com.nb.common.apply.ApplyManager;
|
|
|
+//import com.nb.common.bo.LoginUser;
|
|
|
+//import com.nb.common.bo.SysApplyBO;
|
|
|
+//import com.nb.common.bo.SysRoleBO;
|
|
|
+//import com.nb.common.bo.SysUserBO;
|
|
|
+//import com.nb.common.dto.TokenParameter;
|
|
|
+//import com.nb.common.enums.*;
|
|
|
+//import com.nb.core.exception.CustomException;
|
|
|
+//import com.nb.core.exception.apply.ApplyTokenParamException;
|
|
|
+//import com.nb.core.exception.apply.NoExistAppKeyException;
|
|
|
+//import com.nb.common.util.AddressUtil;
|
|
|
+//import com.nb.common.util.IpUtil;
|
|
|
+//import com.nb.common.util.SecurityUtil;
|
|
|
+//import com.nb.framework.web.service.IUserService;
|
|
|
+//import com.nb.system.common.vo.*;
|
|
|
+//import com.nb.system.entity.SysMenu;
|
|
|
+//import com.nb.system.entity.SysRole;
|
|
|
+//import com.nb.system.entity.SysUser;
|
|
|
+//import com.nb.system.properties.CaptchaProperties;
|
|
|
+//import com.nb.system.service.ISysMenuService;
|
|
|
+//import com.nb.system.service.ISysRoleService;
|
|
|
+//import com.nb.system.service.ISysUserService;
|
|
|
+//import com.nb.system.utils.CaptchaTool;
|
|
|
+//import com.google.common.collect.Sets;
|
|
|
+//import com.nb.system.utils.TenantUtil;
|
|
|
+//import lombok.AllArgsConstructor;
|
|
|
+//import lombok.extern.slf4j.Slf4j;
|
|
|
+//import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
+//import org.springframework.stereotype.Service;
|
|
|
+//
|
|
|
+//import javax.servlet.http.HttpServletRequest;
|
|
|
+//import java.util.*;
|
|
|
+//import java.util.stream.Collectors;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * 用户实现类
|
|
|
+// *
|
|
|
+// * @author Kevin
|
|
|
+// */
|
|
|
+//@Slf4j
|
|
|
+//@Service
|
|
|
+//@AllArgsConstructor
|
|
|
+//@EnableConfigurationProperties(CaptchaProperties.class)
|
|
|
+//public class UserServiceImpl implements IUserService {
|
|
|
+//
|
|
|
+// private final ISysMenuService sysMenuService;
|
|
|
+//
|
|
|
+// private final CaptchaTool captchaTool;
|
|
|
+//
|
|
|
+// private final CaptchaProperties captchaProperties;
|
|
|
+//
|
|
|
+// private final ISysUserService sysUserService;
|
|
|
+//
|
|
|
+// private final ISysRoleService sysRoleService;
|
|
|
+//
|
|
|
+// private final ApplyManager applyManager;
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public String login(TokenParameter req) {
|
|
|
+// if (StrUtil.isBlank(req.getGrantType())) {
|
|
|
+// throw new CustomException("授权类型不能为空");
|
|
|
+// }
|
|
|
+// if (!GrantTypeEnum.contains(req.getGrantType())) {
|
|
|
+// throw new CustomException("授权类型暂不支持");
|
|
|
+// }
|
|
|
+// //用户登录
|
|
|
+// userLogin(req);
|
|
|
+// //第三方应用登录
|
|
|
+// applyLogin(req);
|
|
|
+// return StpUtil.getTokenValue();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public UserInfoVO getUserInfo() {
|
|
|
+// UserInfoVO userInfoVO = new UserInfoVO();
|
|
|
+// SysUser sysUser = sysUserService.getById(StpUtil.getLoginIdAsLong());
|
|
|
+// // 查询角色列表
|
|
|
+// List<SysRole> sysRoleList = sysRoleService.listSysRoleByUserId(sysUser.getId());
|
|
|
+// List<RoleInfoVO> roleInfoVOList = sysRoleList.stream().map(item -> {
|
|
|
+// RoleInfoVO roleInfoVO = new RoleInfoVO();
|
|
|
+// roleInfoVO.setRoleName(item.getRoleName());
|
|
|
+// roleInfoVO.setValue(item.getRoleCode());
|
|
|
+// return roleInfoVO;
|
|
|
+// }).collect(Collectors.toList());
|
|
|
+// userInfoVO.setUserId(sysUser.getId().toString());
|
|
|
+// userInfoVO.setUsername(sysUser.getAccount());
|
|
|
+// userInfoVO.setRealName(sysUser.getNickname());
|
|
|
+// userInfoVO.setAvatar(sysUser.getAvatar());
|
|
|
+// userInfoVO.setDesc(sysUser.getRemarks());
|
|
|
+// userInfoVO.setRoles(roleInfoVOList);
|
|
|
+// userInfoVO.setIsSys(sysUser.getIsSys());
|
|
|
+// userInfoVO.setTenantId(String.valueOf(sysUser.getTenantId()));
|
|
|
+// userInfoVO.setTenantName(sysUser.getTenantName());
|
|
|
+// return userInfoVO;
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public Set<String> getPermCode() {
|
|
|
+// return SecurityUtil.getLoginUser().getPermissions();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<RouteItemVO> getMenuList() {
|
|
|
+// List<SysMenu> sysMenuList;
|
|
|
+// SysUserBO sysUserBO = SecurityUtil.getSysUser();
|
|
|
+// if (SecurityUtil.isSuperAdmin()) {
|
|
|
+// LambdaQueryWrapper<SysMenu> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+// queryWrapper.eq(SysMenu::getStatus, StatusEnum.YES.getCode());
|
|
|
+// queryWrapper.in(SysMenu::getMenuType, MenuTypeEnum.DIR.getCode(), MenuTypeEnum.MENU.getCode());
|
|
|
+// queryWrapper.eq(!TenantUtil.isTuoRen(),SysMenu::getTenantMenu,true);
|
|
|
+// sysMenuList = sysMenuService.list(queryWrapper);
|
|
|
// } else {
|
|
|
- permissions = sysMenuService.getPermissionsByUserId(sysUser.getId());
|
|
|
+// sysMenuList = sysMenuService.listGrantMenuByUserId(sysUserBO.getId());
|
|
|
+// }
|
|
|
+// List<RouteItemVO> routeItemVOList = sysMenuList.stream()
|
|
|
+// .filter(item -> item.getParentId().intValue() == 0)
|
|
|
+// .sorted(Comparator.comparing(SysMenu::getSort))
|
|
|
+// .map(item -> {
|
|
|
+// RouteItemVO node = convertToRoute(item);
|
|
|
+// node.setChildren(getChildrenList(item, sysMenuList));
|
|
|
+// return node;
|
|
|
+// }).collect(Collectors.toList());
|
|
|
+// return routeItemVOList;
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public AccountInfoVO getAccountInfo() {
|
|
|
+// LoginUser loginUser = SecurityUtil.getLoginUser();
|
|
|
+// SysUser sysUser = sysUserService.getById(loginUser.getSysUser().getId());
|
|
|
+// return BeanUtil.copyProperties(sysUser, AccountInfoVO.class);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void saveAccountInfo(AccountInfoVO req) {
|
|
|
+// LoginUser loginUser = SecurityUtil.getLoginUser();
|
|
|
+// SysUser entity = BeanUtil.copyProperties(req, SysUser.class);
|
|
|
+// entity.setId(loginUser.getSysUser().getId());
|
|
|
+// sysUserService.updateById(entity);
|
|
|
+// }
|
|
|
+//
|
|
|
+// private List<RouteItemVO> getChildrenList(SysMenu root, List<SysMenu> list) {
|
|
|
+// List<RouteItemVO> childrenList = list.stream()
|
|
|
+// .filter(item -> item.getParentId().equals(root.getId()))
|
|
|
+// .sorted(Comparator.comparing(SysMenu::getSort))
|
|
|
+// .map(item -> {
|
|
|
+// RouteItemVO node = convertToRoute(item);
|
|
|
+// node.setChildren(getChildrenList(item, list));
|
|
|
+// return node;
|
|
|
+// }).collect(Collectors.toList());
|
|
|
+// return childrenList;
|
|
|
+// }
|
|
|
+//
|
|
|
+// private RouteItemVO convertToRoute(SysMenu item) {
|
|
|
+// RouteItemVO node = new RouteItemVO();
|
|
|
+// node.setName(StrUtil.upperFirst(item.getRoutePath()));
|
|
|
+// node.setPath(item.getRoutePath());
|
|
|
+// node.setComponent(item.getComponent());
|
|
|
+// // 一级目录
|
|
|
+// if (Objects.equals(item.getMenuType(), MenuTypeEnum.DIR.getCode()) && item.getParentId().intValue() == 0) {
|
|
|
+// node.setPath("/" + item.getRoutePath());
|
|
|
+// node.setComponent(MenuConstants.LAYOUT);
|
|
|
+// }
|
|
|
+// // 外部链接
|
|
|
+// if (Objects.equals(item.getMenuType(), MenuTypeEnum.MENU.getCode()) && Objects.equals(item.getLinkExternal(), LinkExternalEnum.YES.getCode())) {
|
|
|
+// node.setComponent(MenuConstants.IFRAME);
|
|
|
+// }
|
|
|
+// RouteMetoVO routeMetoVO = new RouteMetoVO();
|
|
|
+// routeMetoVO.setTitle(item.getMenuName());
|
|
|
+// routeMetoVO.setIcon(item.getIcon());
|
|
|
+// routeMetoVO.setHideMenu(StrUtil.isNotBlank(item.getVisible()) && item.getVisible().equals(VisibleEnum.HIDE.getCode()));
|
|
|
+// // 菜单
|
|
|
+// if (Objects.equals(item.getMenuType(), MenuTypeEnum.MENU.getCode())) {
|
|
|
+// routeMetoVO.setIgnoreKeepAlive(item.getKeepalive().equals(KeepaliveEnum.YES.getCode()));
|
|
|
+// }
|
|
|
+// // 外部链接
|
|
|
+// if (Objects.equals(item.getMenuType(), MenuTypeEnum.MENU.getCode()) && Objects.equals(item.getLinkExternal(), LinkExternalEnum.YES.getCode())) {
|
|
|
+// // 内嵌
|
|
|
+// if (Objects.equals(item.getFrame(), FrameEnum.YES.getCode())) {
|
|
|
+// routeMetoVO.setFrameSrc(item.getLinkUrl());
|
|
|
+// }
|
|
|
+// // 外嵌
|
|
|
+// if (item.getFrame().equals(FrameEnum.NO.getCode())) {
|
|
|
+// node.setPath(item.getLinkUrl());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// node.setMeta(routeMetoVO);
|
|
|
+// return node;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// private void userLogin(TokenParameter req){
|
|
|
+// SysUser sysUser = null;
|
|
|
+// if (req.getGrantType().equals(GrantTypeEnum.USERNAME_PASSWORD.getCode())) {
|
|
|
+// if (StrUtil.isBlank(req.getUsername())) {
|
|
|
+// throw new CustomException("用户名不能为空");
|
|
|
+// }
|
|
|
+// if (StrUtil.isBlank(req.getPassword())) {
|
|
|
+// throw new CustomException("密码不能为空");
|
|
|
+// }
|
|
|
+// if(captchaProperties.isEnable()){
|
|
|
+// HttpServletRequest request = SpringMVCUtil.getRequest();
|
|
|
+// String requestFrom = request.getHeader("RequestFrom");
|
|
|
+// //来自app的请求不需要验证码
|
|
|
+// if(!"TuoRenApp".equals(requestFrom)){
|
|
|
+//// captchaTool.ver(req.getCodeKey(),req.getCode());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// sysUser = sysUserService.getOne(Wrappers.lambdaQuery(SysUser.class).eq(SysUser::getAccount, req.getUsername()));
|
|
|
+// if (Objects.isNull(sysUser)) {
|
|
|
+// log.info("登录用户:{}不存在", req.getUsername());
|
|
|
+// throw new CustomException("登录用户不存在");
|
|
|
+// }
|
|
|
+// if (!SecurityUtil.matchesPassword(req.getPassword(), sysUser.getPassword())) {
|
|
|
+// throw new CustomException("账号或密码不正确");
|
|
|
+// }
|
|
|
+// if (sysUser.getDelFlag().equals(DelFlagEnum.YES.getCode())) {
|
|
|
+// log.info("登录用户:{}已被删除", req.getUsername());
|
|
|
+// throw new CustomException("对不起,您的账号已被删除");
|
|
|
+// }
|
|
|
+// if (sysUser.getStatus().equals(StatusEnum.NO.getCode())) {
|
|
|
+// log.info("登录用户:{}已被停用", req.getUsername());
|
|
|
+// throw new CustomException("对不起,您的账号已被停用");
|
|
|
+// }
|
|
|
+// }else if (req.getGrantType().equals(GrantTypeEnum.MOBILE_CODE.getCode())) {
|
|
|
+// if (StrUtil.isBlank(req.getMobile())) {
|
|
|
+// throw new CustomException("手机号不能为空");
|
|
|
+// }
|
|
|
+// if (StrUtil.isBlank(req.getCode())) {
|
|
|
+// throw new CustomException("验证码不能为空");
|
|
|
+// }
|
|
|
+// // TODO,短信验证码校验,自行实现
|
|
|
+// if (!Objects.equals(req.getCode(), Constants.DEFAULT_SMS_CODE)) {
|
|
|
+// throw new CustomException("账号或密码不正确");
|
|
|
+// }
|
|
|
+// sysUser = sysUserService.getOne(Wrappers.lambdaQuery(SysUser.class).eq(SysUser::getPhone, req.getMobile()));
|
|
|
+// if (Objects.isNull(sysUser)) {
|
|
|
+// log.info("登录用户:{}不存在", req.getUsername());
|
|
|
+// throw new CustomException("登录用户不存在");
|
|
|
+// }
|
|
|
+// if (sysUser.getDelFlag().equals(DelFlagEnum.YES.getCode())) {
|
|
|
+// log.info("登录用户:{}已被删除", req.getUsername());
|
|
|
+// throw new CustomException("对不起,您的账号已被删除");
|
|
|
+// }
|
|
|
+// if (sysUser.getStatus().equals(StatusEnum.NO.getCode())) {
|
|
|
+// log.info("登录用户:{}已被停用", req.getUsername());
|
|
|
+// throw new CustomException("对不起,您的账号已被停用");
|
|
|
+// }
|
|
|
+// }else {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// log.info("登录用户:{}", req.getUsername());
|
|
|
+// SysUserBO sysUserBO = BeanUtil.copyProperties(sysUser, SysUserBO.class);
|
|
|
+// // 查询角色列表
|
|
|
+// List<SysRole> sysRoleList = sysRoleService.listSysRoleByUserId(sysUser.getId());
|
|
|
+// // 设置角色列表
|
|
|
+// sysUserBO.setRoles(sysRoleList.stream().map(item -> BeanUtil.copyProperties(item, SysRoleBO.class)).collect(Collectors.toList()));
|
|
|
+// // 查询权限标识
|
|
|
+// Set<String> permissions = Sets.newHashSet();
|
|
|
+//// if (CollUtil.isNotEmpty(sysRoleList)&&
|
|
|
+//// sysRoleList.stream().anyMatch(sysRole -> "admin".equalsIgnoreCase(sysRole.getRoleCode()))) {
|
|
|
+//// permissions.add(Constants.ALL_PERMISSION);
|
|
|
+//// } else {
|
|
|
+// permissions = sysMenuService.getPermissionsByUserId(sysUser.getId());
|
|
|
+//// }
|
|
|
+// // 登录
|
|
|
+// StpUtil.login(sysUser.getId());
|
|
|
+// LoginUser loginUser = new LoginUser();
|
|
|
+// loginUser.setToken(StpUtil.getTokenValue());
|
|
|
+// loginUser.setUserPlatform(UserPlatformEnum.WEB.getCode());
|
|
|
+// loginUser.setGrantType(req.getGrantType());
|
|
|
+// loginUser.setSysUser(sysUserBO);
|
|
|
+// loginUser.setIsSys(sysUser.getIsSys());
|
|
|
+// if (req.getGrantType().equals(GrantTypeEnum.USERNAME_PASSWORD.getCode())) {
|
|
|
+// loginUser.setUsername(req.getUsername());
|
|
|
+// }
|
|
|
+// if (req.getGrantType().equals(GrantTypeEnum.MOBILE_CODE.getCode())) {
|
|
|
+// loginUser.setUsername(req.getMobile());
|
|
|
+// }
|
|
|
+// loginUser.setLoginTime(new Date());
|
|
|
+// HttpServletRequest request = SpringMVCUtil.getRequest();
|
|
|
+// UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
|
|
+// String ipAddress = IpUtil.getClientIp(request);
|
|
|
+// loginUser.setIpAddress(ipAddress);
|
|
|
+// loginUser.setLoginLocation(AddressUtil.getRealAddressByIp(ipAddress));
|
|
|
+// loginUser.setBrowser(userAgent.getBrowser().getName());
|
|
|
+// loginUser.setOs(userAgent.getOs().getName());
|
|
|
+// loginUser.setPermissions(permissions);
|
|
|
+// // 设置用户信息
|
|
|
+// StpUtil.getTokenSession().set(Constants.LOGIN_USER_KEY, loginUser);
|
|
|
+// }
|
|
|
+//
|
|
|
+// private void applyLogin(TokenParameter req){
|
|
|
+// if (req.getGrantType().equals(GrantTypeEnum.APPKEY_APPSECRET.getCode())){
|
|
|
+// if (StrUtil.isBlank(req.getAppKey())) {
|
|
|
+// throw new ApplyTokenParamException("appKey不能为空");
|
|
|
+// }
|
|
|
+// if (StrUtil.isBlank(req.getTimestamp())) {
|
|
|
+// throw new ApplyTokenParamException("timestamp不能为空");
|
|
|
+// }
|
|
|
+// if (StrUtil.isBlank(req.getSign())) {
|
|
|
+// throw new ApplyTokenParamException("sign不能为空");
|
|
|
+// }
|
|
|
+// String appKey = req.getAppKey();
|
|
|
+// String appSecret = applyManager.getAppSecret(appKey);
|
|
|
+// if (StrUtil.isNullOrUndefined(appSecret)) {
|
|
|
+// throw new NoExistAppKeyException();
|
|
|
+// }
|
|
|
+// //验证签名
|
|
|
+// if (signCorrect(req.getSign(), req.getTimestamp(), req.getAppKey(), appSecret)) {
|
|
|
+// StpUtil.login(req.getAppKey());
|
|
|
+// LoginUser loginUser = new LoginUser();
|
|
|
+// SysApplyBO sysApply = new SysApplyBO();
|
|
|
+// sysApply.setAppKey(appKey);
|
|
|
+// sysApply.setTenantId(applyManager.getTenantId(appKey));
|
|
|
+// loginUser.setToken(StpUtil.getTokenValue());
|
|
|
+// loginUser.setUserPlatform(UserPlatformEnum.WEB.getCode());
|
|
|
+// loginUser.setGrantType(req.getGrantType());
|
|
|
+// loginUser.setSysApply(sysApply);
|
|
|
+// loginUser.setIsSys(false);
|
|
|
+// loginUser.setUsername(req.getAppKey());
|
|
|
+// loginUser.setLoginTime(new Date());
|
|
|
+// HttpServletRequest request = SpringMVCUtil.getRequest();
|
|
|
+// UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
|
|
+// String ipAddress = IpUtil.getClientIp(request);
|
|
|
+// loginUser.setIpAddress(ipAddress);
|
|
|
+// loginUser.setLoginLocation(AddressUtil.getRealAddressByIp(ipAddress));
|
|
|
+// loginUser.setBrowser(userAgent.getBrowser().getName());
|
|
|
+// loginUser.setOs(userAgent.getOs().getName());
|
|
|
+// loginUser.setPermissions(new HashSet<>(applyManager.getPermission(appKey)));
|
|
|
+// // 设置用户信息
|
|
|
+// StpUtil.getTokenSession().set(Constants.LOGIN_USER_KEY, loginUser);
|
|
|
+// }else {
|
|
|
+// throw new ApplyTokenParamException("签名错误");
|
|
|
+// }
|
|
|
+// }else {
|
|
|
+// return;
|
|
|
// }
|
|
|
- // 登录
|
|
|
- StpUtil.login(sysUser.getId());
|
|
|
- LoginUser loginUser = new LoginUser();
|
|
|
- loginUser.setToken(StpUtil.getTokenValue());
|
|
|
- loginUser.setUserPlatform(UserPlatformEnum.WEB.getCode());
|
|
|
- loginUser.setGrantType(req.getGrantType());
|
|
|
- loginUser.setSysUser(sysUserBO);
|
|
|
- loginUser.setIsSys(sysUser.getIsSys());
|
|
|
- if (req.getGrantType().equals(GrantTypeEnum.USERNAME_PASSWORD.getCode())) {
|
|
|
- loginUser.setUsername(req.getUsername());
|
|
|
- }
|
|
|
- if (req.getGrantType().equals(GrantTypeEnum.MOBILE_CODE.getCode())) {
|
|
|
- loginUser.setUsername(req.getMobile());
|
|
|
- }
|
|
|
- loginUser.setLoginTime(new Date());
|
|
|
- HttpServletRequest request = SpringMVCUtil.getRequest();
|
|
|
- UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
|
|
- String ipAddress = IpUtil.getClientIp(request);
|
|
|
- loginUser.setIpAddress(ipAddress);
|
|
|
- loginUser.setLoginLocation(AddressUtil.getRealAddressByIp(ipAddress));
|
|
|
- loginUser.setBrowser(userAgent.getBrowser().getName());
|
|
|
- loginUser.setOs(userAgent.getOs().getName());
|
|
|
- loginUser.setPermissions(permissions);
|
|
|
- // 设置用户信息
|
|
|
- StpUtil.getTokenSession().set(Constants.LOGIN_USER_KEY, loginUser);
|
|
|
- }
|
|
|
-
|
|
|
- private void applyLogin(LoginDTO req){
|
|
|
- if (req.getGrantType().equals(GrantTypeEnum.APPKEY_APPSECRET.getCode())){
|
|
|
- if (StrUtil.isBlank(req.getAppKey())) {
|
|
|
- throw new ApplyTokenParamException("appKey不能为空");
|
|
|
- }
|
|
|
- if (StrUtil.isBlank(req.getTimestamp())) {
|
|
|
- throw new ApplyTokenParamException("timestamp不能为空");
|
|
|
- }
|
|
|
- if (StrUtil.isBlank(req.getSign())) {
|
|
|
- throw new ApplyTokenParamException("sign不能为空");
|
|
|
- }
|
|
|
- String appKey = req.getAppKey();
|
|
|
- String appSecret = applyManager.getAppSecret(appKey);
|
|
|
- if (StrUtil.isNullOrUndefined(appSecret)) {
|
|
|
- throw new NoExistAppKeyException();
|
|
|
- }
|
|
|
- //验证签名
|
|
|
- if (signCorrect(req.getSign(), req.getTimestamp(), req.getAppKey(), appSecret)) {
|
|
|
- StpUtil.login(req.getAppKey());
|
|
|
- LoginUser loginUser = new LoginUser();
|
|
|
- SysApplyBO sysApply = new SysApplyBO();
|
|
|
- sysApply.setAppKey(appKey);
|
|
|
- sysApply.setTenantId(applyManager.getTenantId(appKey));
|
|
|
- loginUser.setToken(StpUtil.getTokenValue());
|
|
|
- loginUser.setUserPlatform(UserPlatformEnum.WEB.getCode());
|
|
|
- loginUser.setGrantType(req.getGrantType());
|
|
|
- loginUser.setSysApply(sysApply);
|
|
|
- loginUser.setIsSys(false);
|
|
|
- loginUser.setUsername(req.getAppKey());
|
|
|
- loginUser.setLoginTime(new Date());
|
|
|
- HttpServletRequest request = SpringMVCUtil.getRequest();
|
|
|
- UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
|
|
- String ipAddress = IpUtil.getClientIp(request);
|
|
|
- loginUser.setIpAddress(ipAddress);
|
|
|
- loginUser.setLoginLocation(AddressUtil.getRealAddressByIp(ipAddress));
|
|
|
- loginUser.setBrowser(userAgent.getBrowser().getName());
|
|
|
- loginUser.setOs(userAgent.getOs().getName());
|
|
|
- loginUser.setPermissions(new HashSet<>(applyManager.getPermission(appKey)));
|
|
|
- // 设置用户信息
|
|
|
- StpUtil.getTokenSession().set(Constants.LOGIN_USER_KEY, loginUser);
|
|
|
- }else {
|
|
|
- throw new ApplyTokenParamException("签名错误");
|
|
|
- }
|
|
|
- }else {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private boolean signCorrect(String sign,String timestamp,String appKey,String appSecret){
|
|
|
- JSONObject jsonObject = new JSONObject(true);
|
|
|
- jsonObject.putOpt("appKey",appKey)
|
|
|
- .putOpt("appSecret",appSecret)
|
|
|
- .putOpt("timestamp",timestamp);
|
|
|
- return DigestUtil.md5Hex(jsonObject.toString()).equalsIgnoreCase(sign);
|
|
|
- }
|
|
|
-}
|
|
|
+// }
|
|
|
+//
|
|
|
+// private boolean signCorrect(String sign,String timestamp,String appKey,String appSecret){
|
|
|
+// JSONObject jsonObject = new JSONObject(true);
|
|
|
+// jsonObject.putOpt("appKey",appKey)
|
|
|
+// .putOpt("appSecret",appSecret)
|
|
|
+// .putOpt("timestamp",timestamp);
|
|
|
+// return DigestUtil.md5Hex(jsonObject.toString()).equalsIgnoreCase(sign);
|
|
|
+// }
|
|
|
+//}
|