|
@@ -1,18 +1,27 @@
|
|
package cn.cslg.permission.service;
|
|
package cn.cslg.permission.service;
|
|
|
|
|
|
import cn.cslg.permission.common.core.base.RedisConf;
|
|
import cn.cslg.permission.common.core.base.RedisConf;
|
|
-import cn.cslg.permission.common.model.vo.LoginRecordVO;
|
|
|
|
-import cn.cslg.permission.common.model.vo.LoginVO;
|
|
|
|
-import cn.cslg.permission.common.model.vo.PersonnelVO;
|
|
|
|
-import cn.cslg.permission.common.model.vo.RoleVO;
|
|
|
|
|
|
+import cn.cslg.permission.common.core.business.LoginCacheKeyUtil;
|
|
|
|
+import cn.cslg.permission.common.core.business.SmsService;
|
|
|
|
+import cn.cslg.permission.common.model.dto.*;
|
|
|
|
+import cn.cslg.permission.common.model.qiaobi.PersonVipMessVO;
|
|
|
|
+import cn.cslg.permission.common.model.vo.*;
|
|
import cn.cslg.permission.common.utils.*;
|
|
import cn.cslg.permission.common.utils.*;
|
|
import cn.cslg.permission.common.utils.message.MessageUtils;
|
|
import cn.cslg.permission.common.utils.message.MessageUtils;
|
|
-import cn.cslg.permission.domain.Personnel;
|
|
|
|
-import cn.cslg.permission.domain.ReSetPasswordDTO;
|
|
|
|
-import cn.cslg.permission.domain.Tenant;
|
|
|
|
-import cn.cslg.permission.mapper.PersonnelMapper;
|
|
|
|
|
|
+import cn.cslg.permission.domain.*;
|
|
|
|
+import cn.cslg.permission.domain.associate.AssoFunctionModule;
|
|
|
|
+import cn.cslg.permission.domain.associate.AssoPersonnelMachine;
|
|
|
|
+import cn.cslg.permission.domain.qiaobi.AssoPersonVipType;
|
|
|
|
+import cn.cslg.permission.exception.ExceptionEnum;
|
|
|
|
+import cn.cslg.permission.exception.XiaoShiException;
|
|
|
|
+import cn.cslg.permission.mapper.*;
|
|
|
|
+import cn.cslg.permission.mapper.associate.AssoFunctionModuleMapper;
|
|
|
|
+import cn.cslg.permission.mapper.associate.AssoPersonnelMachineMapper;
|
|
|
|
+import cn.cslg.permission.mapper.qiaobi.AssoPersonVipTypeMapper;
|
|
import cn.cslg.permission.service.associate.PerDpService;
|
|
import cn.cslg.permission.service.associate.PerDpService;
|
|
import cn.cslg.permission.service.associate.PersonRoleService;
|
|
import cn.cslg.permission.service.associate.PersonRoleService;
|
|
|
|
+import cn.cslg.permission.service.associate.RoleFunctionDataService;
|
|
|
|
+import cn.cslg.permission.service.qiaobi.AssoPersonVipTypeService;
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import cn.hutool.captcha.CaptchaUtil;
|
|
import cn.hutool.captcha.CaptchaUtil;
|
|
import cn.hutool.captcha.CircleCaptcha;
|
|
import cn.hutool.captcha.CircleCaptcha;
|
|
@@ -22,18 +31,25 @@ import cn.hutool.crypto.SecureUtil;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
import eu.bitwalker.useragentutils.UserAgent;
|
|
import eu.bitwalker.useragentutils.UserAgent;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import javax.servlet.ServletRequest;
|
|
|
|
|
|
+import java.lang.System;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author 沈永艺
|
|
* @author 沈永艺
|
|
@@ -45,6 +61,8 @@ import java.util.concurrent.TimeUnit;
|
|
@Service
|
|
@Service
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
|
|
+ @Value("${inviteSignInLink}")
|
|
|
|
+ private String inviteSignInLink;
|
|
private final RedisUtil redisUtil;
|
|
private final RedisUtil redisUtil;
|
|
private final CacheUtils cacheUtils;
|
|
private final CacheUtils cacheUtils;
|
|
private final TenantService tenantService;
|
|
private final TenantService tenantService;
|
|
@@ -54,6 +72,24 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
private final SystemService systemService;
|
|
private final SystemService systemService;
|
|
private final LoginRecordService loginRecordService;
|
|
private final LoginRecordService loginRecordService;
|
|
private final HttpServletRequest request;
|
|
private final HttpServletRequest request;
|
|
|
|
+ private final RoleFunctionDataService roleFunctionDataService;
|
|
|
|
+ private final FunctionService functionService;
|
|
|
|
+ private final AssoPersonVipTypeService assoPersonVipTypeService;
|
|
|
|
+ private final AssoTenantVipTypeFunctionMapper assoTenantVipTypeFunctionMapper;
|
|
|
|
+ private final SmsService smsService;
|
|
|
|
+ private final ApplicationService applicationService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private PersonnelMapper personnelMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private FunctionMapper functionMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private AssoPersonnelMachineMapper assoPersonnelMachineMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private AssoFunctionModuleMapper assoFunctionModuleMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private PersonInvitationCodeMapper personInvitationCodeMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private AssoPersonVipTypeMapper assoPersonVipTypeMapper;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param loginVO 登录参数类
|
|
* @param loginVO 登录参数类
|
|
@@ -314,8 +350,390 @@ public class LoginService extends ServiceImpl<PersonnelMapper, Personnel> {
|
|
map.put("value2", personnel.getPersonnelName());
|
|
map.put("value2", personnel.getPersonnelName());
|
|
mailUtils.sendEmailMessage(map);
|
|
mailUtils.sendEmailMessage(map);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ //校验登录时参数
|
|
|
|
+ public EncryptionLoginVO loginCommonMethod(LoginCommonDTO vo, Personnel personnel,LoginRecordVO loginRecordVO) throws Exception {
|
|
|
|
+ Integer personnelId = personnel.getId();
|
|
|
|
+ List<AssoPersonVipType> personVipTypes = assoPersonVipTypeMapper.selectList(new LambdaQueryWrapper<AssoPersonVipType>()
|
|
|
|
+ .eq(AssoPersonVipType::getPersonId, personnelId));
|
|
|
|
+ if (org.springframework.util.CollectionUtils.isEmpty(personVipTypes)) {
|
|
|
|
+ loginRecordVO.setLoginResult("无权限");
|
|
|
|
+ loginRecordService.addLoginRecord(loginRecordVO);
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.PERMISSION_ERROR);
|
|
|
|
+ }
|
|
|
|
+ Long timeMillis = vo.getCurrentTimeMillis();
|
|
|
|
+ String appKey = vo.getAppKey();
|
|
|
|
+ String sign = vo.getSign();
|
|
|
|
+ String machineCode = vo.getMachineCode();
|
|
|
|
+ long currentTimeMillis = timeMillis / 1000;
|
|
|
|
+ long currentTimeSecond = System.currentTimeMillis() / 1000;
|
|
|
|
+ final long second = currentTimeSecond - currentTimeMillis;
|
|
|
|
+ if (second > 30) {
|
|
|
|
+ loginRecordVO.setLoginResult("请求时间超时");
|
|
|
|
+ loginRecordService.addLoginRecord(loginRecordVO);
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.THE_REQUEST_TIME_OVERTIME);
|
|
|
|
+ }
|
|
|
|
+ String appSecret = appKey + currentTimeMillis;
|
|
|
|
+ String md5Sign = SecureUtil.md5(appSecret);
|
|
|
|
+ if (Boolean.TRUE.equals(StringUtils.isEmpty(sign)) || !sign.equals(md5Sign)) {
|
|
|
|
+ loginRecordVO.setLoginResult("请求SIGN不一致,重新检查");
|
|
|
|
+ loginRecordService.addLoginRecord(loginRecordVO);
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.THE_SIGN_IS_NOT_SAME);
|
|
|
|
+ }
|
|
|
|
+ if (Boolean.TRUE.equals(StringUtils.isEmpty(machineCode))) {
|
|
|
|
+ loginRecordVO.setLoginResult("机器码不可为空");
|
|
|
|
+ loginRecordService.addLoginRecord(loginRecordVO);
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.THE_MACHINE_CODE_IS_NULL);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<AssoPersonnelMachine> machineList = assoPersonnelMachineMapper.selectList(new LambdaQueryWrapper<AssoPersonnelMachine>()
|
|
|
|
+ .eq(AssoPersonnelMachine::getPersonnelId, personnelId)
|
|
|
|
+ .ne(AssoPersonnelMachine::getMachineCode, SecureUtil.md5(machineCode)));
|
|
|
|
+ if (machineList.size() > 1) {
|
|
|
|
+ loginRecordVO.setLoginResult("同一账号新机登录不可超过两个");
|
|
|
|
+ loginRecordService.addLoginRecord(loginRecordVO);
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.DO_NOT_LOG_IN_TO_MORE_THAN_TWO_NEW_MACHINES_WITH_THE_SAME_ACCOUNT);
|
|
|
|
+ }
|
|
|
|
+ //人员信息中私钥或公钥为空则添加进去
|
|
|
|
+ this.updatePersonnel(personnel.getPrivateKey(), personnel.getPublicKey(), personnel.getSymmetryKey(), personnelId);
|
|
|
|
+ personnel = personnelMapper.selectById(personnel.getId());
|
|
|
|
+ //添加人员和机器关联
|
|
|
|
+ this.addOrUpdatePersonnelMachine(machineCode, personnel);
|
|
|
|
|
|
|
|
+ EncryptionLoginVO loginVO = new EncryptionLoginVO();
|
|
|
|
+ loginVO.setPrivateKey(personnel.getPrivateKey());
|
|
|
|
+ loginVO.setPersonId(personnelId);
|
|
|
|
+ loginVO.setPersonnelName(personnel.getPersonnelName());
|
|
|
|
+ loginVO.setPersonnelUserName(personnel.getPersonnelUserName());
|
|
|
|
+ loginVO.setPersonnelPhone(personnel.getPersonnelPhone());
|
|
|
|
+ loginVO.setMachineCode(vo.getMachineCode());
|
|
|
|
+ loginVO.setPersonnelConfig(personnel.getPersonConfig());
|
|
|
|
+ //Sa-token 登录方法 登录后 生成Token 如果集成了Redis的话 会自动存入Redis
|
|
|
|
+ StpUtil.login(personnel.getId());
|
|
|
|
+ loginVO.setToken(StpUtil.getTokenValue());
|
|
|
|
+ PersonVipMessVO personVipMessVO = assoPersonVipTypeService.getPersonVipMessage(personnelId);
|
|
|
|
+ loginVO.setPersonVipMessVO(personVipMessVO);
|
|
|
|
+ loginRecordVO.setLoginResult("成功");
|
|
|
|
+ loginRecordService.addLoginRecord(loginRecordVO);
|
|
|
|
+ return loginVO;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void addLoginRecord(Personnel personnel,LoginRecordVO loginRecordVO) {
|
|
|
|
+ loginRecordVO.setLoginSystem(3);
|
|
|
|
+ loginRecordVO.setPersonnelId(personnel.getId());
|
|
|
|
+ loginRecordVO.setTenantId(personnel.getTenantId());
|
|
|
|
+ //登录日志记录ip地址
|
|
|
|
+ loginRecordVO.setLoginIp(request.getRemoteAddr());
|
|
|
|
+ String ua = request.getHeader("User-Agent");
|
|
|
|
+ UserAgent userAgent = UserAgent.parseUserAgentString(ua);
|
|
|
|
+ //获取客户端操作系统
|
|
|
|
+ String os = userAgent.getOperatingSystem().getName();
|
|
|
|
+ //获取客户端浏览器
|
|
|
|
+ String browser = userAgent.getBrowser().getName();
|
|
|
|
+ //登录日志记录操作系统
|
|
|
|
+ loginRecordVO.setLoginOs(os);
|
|
|
|
+ //解析浏览器
|
|
|
|
+ loginRecordVO.setBrowser(browser);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 登录加密
|
|
|
|
+ *
|
|
|
|
+ * @param vo
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+// @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
|
+ public String loginByEncryption(EncryptionLoginDTO vo) throws Exception {
|
|
|
|
+ final String username = vo.getUsername();
|
|
|
|
+ final String password = vo.getPassword();
|
|
|
|
+ //用用户名查询人员信息
|
|
|
|
+ LambdaQueryWrapper<Personnel> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(Personnel::getPersonnelPhone, username)
|
|
|
|
+ .or()
|
|
|
|
+ .eq(Personnel::getPersonnelEmail, username)
|
|
|
|
+ .or()
|
|
|
|
+ .eq(Personnel::getPersonnelUserName, username);
|
|
|
|
+ //获取一条
|
|
|
|
+ Personnel personnel = this.getOne(queryWrapper, false);
|
|
|
|
+ //如果查不到 报错 用户名不存在
|
|
|
|
+ if (ObjectUtils.isEmpty(personnel)) {
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.THE_PERSONNEL_IS_NOT_EXIST);
|
|
|
|
+ }
|
|
|
|
+ LoginRecordVO loginRecordVO = new LoginRecordVO();
|
|
|
|
+ this.addLoginRecord(personnel, loginRecordVO);
|
|
|
|
+ if (personnel.getPersonnelStatus().equals(0)) {
|
|
|
|
+ loginRecordVO.setLoginResult("该用户不可用");
|
|
|
|
+ loginRecordService.addLoginRecord(loginRecordVO);
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.THE_PERSONNEL_IS_FORBIDDEN);
|
|
|
|
+ }
|
|
|
|
+ //校验密码是否正确
|
|
|
|
+ boolean isPassword = personnel.getPersonnelPassword().equals(SecureUtil.md5(password));
|
|
|
|
+ if (!isPassword) {
|
|
|
|
+ loginRecordVO.setLoginResult("密码错误");
|
|
|
|
+ loginRecordService.addLoginRecord(loginRecordVO);
|
|
|
|
+ //登录日志记录登录是否成功
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.LOGIN_PASSWORD_MISTAKE);
|
|
|
|
+ }
|
|
|
|
+ LoginCommonDTO commonDTO = new LoginCommonDTO();
|
|
|
|
+ commonDTO.setAppKey(vo.getAppKey());
|
|
|
|
+ commonDTO.setSign(vo.getSign());
|
|
|
|
+ commonDTO.setCurrentTimeMillis(vo.getCurrentTimeMillis());
|
|
|
|
+ commonDTO.setMachineCode(vo.getMachineCode());
|
|
|
|
+ EncryptionLoginVO loginVO = this.loginCommonMethod(commonDTO, personnel,loginRecordVO);
|
|
|
|
+ return Response.success(loginVO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
|
+ public void updatePersonnel(String privateKey, String publicKey, String symmetryKey, Integer personId) throws Exception {
|
|
|
|
+ if (StringUtils.isEmpty(privateKey) || StringUtils.isEmpty(publicKey) || Boolean.TRUE.equals(StringUtils.isEmpty(symmetryKey))) {
|
|
|
|
+ Map<String, String> map = RSAUtils.generateKey();
|
|
|
|
+ String publicKeyStr = map.get("publicKeyStr");
|
|
|
|
+ String privateKeyStr = map.get("privateKeyStr");
|
|
|
|
+ String generateKey = AESUtils.generateKey();
|
|
|
|
+ Personnel newPersonnel = personnelMapper.selectById(personId);
|
|
|
|
+ newPersonnel.setPrivateKey(privateKeyStr);
|
|
|
|
+ newPersonnel.setPublicKey(publicKeyStr);
|
|
|
|
+ newPersonnel.setSymmetryKey(generateKey);
|
|
|
|
+ newPersonnel.updateById();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 新增或修改人员机器码关联表
|
|
|
|
+ *
|
|
|
|
+ * @param machineCode
|
|
|
|
+ * @param personnel
|
|
|
|
+ */
|
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
|
+ public void addOrUpdatePersonnelMachine(String machineCode, Personnel personnel) {
|
|
|
|
+ AssoPersonnelMachine machine = assoPersonnelMachineMapper.selectOne(new LambdaQueryWrapper<AssoPersonnelMachine>()
|
|
|
|
+ .eq(AssoPersonnelMachine::getMachineCode, SecureUtil.md5(machineCode))
|
|
|
|
+ .eq(AssoPersonnelMachine::getPersonnelId, personnel.getId()));
|
|
|
|
+ if (ObjectUtils.isEmpty(machine)) {
|
|
|
|
+ AssoPersonnelMachine assoPersonnelMachine = new AssoPersonnelMachine();
|
|
|
|
+ assoPersonnelMachine.setPersonnelId(personnel.getId());
|
|
|
|
+ assoPersonnelMachine.setMachineCode(SecureUtil.md5(machineCode));
|
|
|
|
+ assoPersonnelMachine.setIfFirstActivation(true);
|
|
|
|
+ assoPersonnelMachine.setCreateUser(personnel.getCreateUser());
|
|
|
|
+ assoPersonnelMachine.setCreateTime(new Date());
|
|
|
|
+ assoPersonnelMachine.insert();
|
|
|
|
+ } else {
|
|
|
|
+ machine.setId(machine.getId());
|
|
|
|
+ machine.setIfFirstActivation(false);
|
|
|
|
+ machine.updateById();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void checkedRational(String sign, String appKey, long timeMillis) {
|
|
|
|
+ long currentTimeMillis = timeMillis / 1000;
|
|
|
|
+ long currentTimeSecond = System.currentTimeMillis() / 1000;
|
|
|
|
+ final long second = currentTimeSecond - currentTimeMillis;
|
|
|
|
+ if (second > 30) {
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.THE_REQUEST_TIME_OVERTIME);
|
|
|
|
+ }
|
|
|
|
+ String appSecret = appKey + currentTimeMillis;
|
|
|
|
+ String md5Sign = SecureUtil.md5(appSecret);
|
|
|
|
+
|
|
|
|
+ if (Boolean.TRUE.equals(StringUtils.isEmpty(sign)) || !sign.equals(md5Sign)) {
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.THE_SIGN_IS_NOT_SAME);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 功能模块化代码加密
|
|
|
|
+ *
|
|
|
|
+ * @param vo
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public String functionByEncryption(EncryptionFunctionDTO vo) throws Exception {
|
|
|
|
+ String sign = vo.getSign();
|
|
|
|
+ String appKey = vo.getAppKey();
|
|
|
|
+ String version = vo.getVersion();
|
|
|
|
+ if (Boolean.TRUE.equals(StringUtils.isEmpty(version))) {
|
|
|
|
+ version = "1.0.0.0";
|
|
|
|
+ }
|
|
|
|
+ this.checkedRational(sign, appKey, vo.getCurrentTimeMillis());
|
|
|
|
+ Integer userId = StpUtil.getLoginIdAsInt();
|
|
|
|
+// Integer userId = 3;
|
|
|
|
+ Personnel personnel = this.getById(userId);
|
|
|
|
+ if (ObjectUtils.isEmpty(personnel)) {
|
|
|
|
+ return Response.error(ResponseEnum.THE_TOKEN_IS_INVALID);
|
|
|
|
+ }
|
|
|
|
+ String publicKey = personnel.getPublicKey();
|
|
|
|
+ String symmetryKey = personnel.getSymmetryKey();
|
|
|
|
+ EncryptionFunctionFinalVO finalVO = new EncryptionFunctionFinalVO();
|
|
|
|
+ List<EncryptionFunctionVO> functionVOS = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ List<String> permissions = new ArrayList<>();
|
|
|
|
+ //1.获取该人员的权限id
|
|
|
|
+ List<Integer> functionIds = new ArrayList<>();
|
|
|
|
+ Integer vipId = assoPersonVipTypeService.getPersonVipId(personnel.getId());
|
|
|
|
+ if (vipId != null) {
|
|
|
|
+ List<AssoTenantVipTypeAndFunctionVO> vos = assoTenantVipTypeFunctionMapper.selectByTenantVipTypeId(vipId);
|
|
|
|
+ if (vos != null && vos.size() > 0) {
|
|
|
|
+ functionIds = vos.stream().map(AssoTenantVipTypeAndFunctionVO::getFunctionId).collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtils.isEmpty(functionIds)) {
|
|
|
|
+ //2.用IDList在功能表中查出对应功能信息
|
|
|
|
+ List<Function> functionList = functionService.listByIds(functionIds);
|
|
|
|
+ //3.获取该人员角色所有权限
|
|
|
|
+ functionList.forEach(i -> {
|
|
|
|
+ permissions.add(i.getFunctionPath());
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ List<EncryptionFunctionVO> list = this.loadFunctionVOS(permissions, 2, symmetryKey, version);
|
|
|
|
+ functionVOS.addAll(list);
|
|
|
|
+
|
|
|
|
+ List<String> permissions1 = new ArrayList<>();
|
|
|
|
+ //获取所有权限
|
|
|
|
+ LambdaQueryWrapper<Application> queryWrapper =new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(Application::getApplicationCode,appKey);
|
|
|
|
+ Application application =applicationService.getOne(queryWrapper,false);
|
|
|
|
+ List<Function> functionList1 = functionService.list(new LambdaQueryWrapper<Function>().eq(Function::getApplicationId,application.getId()));
|
|
|
|
+
|
|
|
|
+ functionList1.forEach(i -> {
|
|
|
|
+ permissions1.add(i.getFunctionPath());
|
|
|
|
+ });
|
|
|
|
+ permissions1.removeAll(permissions);
|
|
|
|
+ List<EncryptionFunctionVO> list1 = this.loadFunctionVOS(permissions1, 1, symmetryKey, version);
|
|
|
|
+ functionVOS.addAll(list1);
|
|
|
|
+ finalVO.setFunctionVOS(functionVOS);
|
|
|
|
+ String key = RSAUtils.encryptByPublicKey(symmetryKey, publicKey);
|
|
|
|
+ finalVO.setKey(key);
|
|
|
|
+ return Response.success(finalVO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<EncryptionFunctionVO> loadFunctionVOS(List<String> permissions, Integer type, String symmetryKey, String version) throws Exception {
|
|
|
|
+ List<EncryptionFunctionVO> functionVOS = new ArrayList<>();
|
|
|
|
+ if (permissions == null || permissions.size() <= 0) {
|
|
|
|
+ return functionVOS;
|
|
|
|
+ }
|
|
|
|
+ List<Function> functions = functionMapper.selectList(new LambdaQueryWrapper<Function>()
|
|
|
|
+ .in(Function::getFunctionPath, permissions));
|
|
|
|
+ for (Function function : functions) {
|
|
|
|
+ Integer functionId = function.getId();
|
|
|
|
+ String functionPath = function.getFunctionPath();
|
|
|
|
+ AssoFunctionModule functionModule = assoFunctionModuleMapper.selectOne(new LambdaQueryWrapper<AssoFunctionModule>()
|
|
|
|
+ .eq(AssoFunctionModule::getFunctionId, functionId)
|
|
|
|
+ .eq(AssoFunctionModule::getAuthType, type)
|
|
|
|
+ .eq(AssoFunctionModule::getVersion, version));
|
|
|
|
+ if (ObjectUtils.isNotEmpty(functionModule) && StringUtils.isNotEmpty(functionModule.getCode())) {
|
|
|
|
+ String moduleCode = functionModule.getCode();
|
|
|
|
+ String encryptInfo = AESUtils.encrypt(moduleCode, symmetryKey);
|
|
|
|
+ EncryptionFunctionVO functionVO = new EncryptionFunctionVO();
|
|
|
|
+ functionVO.setPermission(functionPath);
|
|
|
|
+ functionVO.setEncryptionModuleCode(encryptInfo);
|
|
|
|
+ functionVOS.add(functionVO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return functionVOS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //---------------------------------------二期开发--------------------------
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 发送验证码
|
|
|
|
+ *
|
|
|
|
+ * @param vo
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public String getPhoneCode(SendCodeDTO vo) {
|
|
|
|
+ String res = "发送验证码失败";
|
|
|
|
+ if (Boolean.TRUE.equals(StringUtils.isEmpty(vo.getPhoneNum()))) {
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.THE_PHONE_IS_NOT_EMPTY);
|
|
|
|
+ }
|
|
|
|
+ if (!RegexUtil.isPhoneLegal(vo.getPhoneNum())) {
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.THE_PHONE_FORMAT_ERROR);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotEmpty(vo.getPhoneNum())) {
|
|
|
|
+ String code = redisUtil.get(LoginCacheKeyUtil.getLoginCaptcha(vo.getPhoneNum()));
|
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotEmpty(code)) {
|
|
|
|
+ redisUtil.delete(LoginCacheKeyUtil.getLoginCaptcha(vo.getPhoneNum()));
|
|
|
|
+ }
|
|
|
|
+ //生成验证码
|
|
|
|
+ String random = RandomUtil.getSixRandom();
|
|
|
|
+ //手机号和验证码放进缓存 设置过期时间60s
|
|
|
|
+ redisUtil.set(LoginCacheKeyUtil.getLoginCaptcha(vo.getPhoneNum()), random);
|
|
|
|
+ redisUtil.expire(LoginCacheKeyUtil.getLoginCaptcha(vo.getPhoneNum()), 300L, TimeUnit.SECONDS);
|
|
|
|
+ //发送短信
|
|
|
|
+ smsService.sendMessage(vo.getPhoneNum(), random);
|
|
|
|
+ res = "发送验证码成功";
|
|
|
|
+ }
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 手机号登录
|
|
|
|
+ *
|
|
|
|
+ * @param dto
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+// @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
|
+ public String loginByPhone(PhoneLoginDTO dto) throws Exception {
|
|
|
|
+ //获取缓存中验证码
|
|
|
|
+ String code = redisUtil.get(LoginCacheKeyUtil.getLoginCaptcha(dto.getPhoneNum()));
|
|
|
|
+ if (Boolean.TRUE.equals(StringUtils.isEmpty(code))) {
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.THE_PHONE_CODE_IS_INVALID);
|
|
|
|
+ }
|
|
|
|
+ //校验验证码
|
|
|
|
+ if (Boolean.TRUE.equals(StringUtils.isEmpty(dto.getPhoneCode()))) {
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.THE_PHONE_CODE_IS_NOT_NULL);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!org.apache.commons.lang3.StringUtils.equals(code, dto.getPhoneCode())) {
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.THE_PHONE_CODE_IS_INCONFORMITY);
|
|
|
|
+ }
|
|
|
|
+ //校验验证码成功后使其失效
|
|
|
|
+ redisUtil.delete(LoginCacheKeyUtil.getLoginCaptcha(dto.getPhoneNum()));
|
|
|
|
+ //查询用户
|
|
|
|
+ LambdaQueryWrapper<Personnel> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isNotEmpty(dto.getPhoneNum())) {
|
|
|
|
+ queryWrapper.eq(Personnel::getPersonnelPhone, dto.getPhoneNum());
|
|
|
|
+ }
|
|
|
|
+ Personnel person = this.getOne(queryWrapper, false);
|
|
|
|
+ if (org.apache.commons.lang3.ObjectUtils.isEmpty(person)) {
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.THE_PERSONNEL_IS_NOT_EXIST);
|
|
|
|
+ }
|
|
|
|
+ LoginRecordVO loginRecordVO = new LoginRecordVO();
|
|
|
|
+ this.addLoginRecord(person, loginRecordVO);
|
|
|
|
+ if (person.getPersonnelStatus().equals(0)) {
|
|
|
|
+ loginRecordVO.setLoginResult("该用户不可用");
|
|
|
|
+ loginRecordService.addLoginRecord(loginRecordVO);
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.THE_PERSONNEL_IS_FORBIDDEN);
|
|
|
|
+ }
|
|
|
|
+ LoginCommonDTO commonDTO = new LoginCommonDTO();
|
|
|
|
+ commonDTO.setAppKey(dto.getAppKey());
|
|
|
|
+ commonDTO.setSign(dto.getSign());
|
|
|
|
+ commonDTO.setCurrentTimeMillis(dto.getCurrentTimeMillis());
|
|
|
|
+ commonDTO.setMachineCode(dto.getMachineCode());
|
|
|
|
+ EncryptionLoginVO loginVO = this.loginCommonMethod(commonDTO, person, loginRecordVO);
|
|
|
|
+ return Response.success(loginVO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String generateInvitationCode() {
|
|
|
|
+ Integer userId = null;
|
|
|
|
+ try {
|
|
|
|
+ userId = StpUtil.getLoginIdAsInt();
|
|
|
|
+ PersonInvitationCode assoPersoninvitationCode = personInvitationCodeMapper.selectOne(new LambdaQueryWrapper<PersonInvitationCode>()
|
|
|
|
+ .eq(PersonInvitationCode::getPersonId, userId));
|
|
|
|
+ String invitationCode = "";
|
|
|
|
+ if (ObjectUtils.isEmpty(assoPersoninvitationCode)) {
|
|
|
|
+ PersonInvitationCode personInvitationCode = new PersonInvitationCode();
|
|
|
|
+ personInvitationCode.setPersonId(userId);
|
|
|
|
+ personInvitationCode.setInvitationCode(RandomUtil.generateInvitationCode());
|
|
|
|
+ personInvitationCode.setCreateUser(userId);
|
|
|
|
+ personInvitationCode.insert();
|
|
|
|
+ invitationCode = personInvitationCode.getInvitationCode();
|
|
|
|
+ } else {
|
|
|
|
+ invitationCode = assoPersoninvitationCode.getInvitationCode();
|
|
|
|
+ }
|
|
|
|
+ return Response.success(inviteSignInLink + "?invitationCode=" + invitationCode);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ return Response.success(inviteSignInLink);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|