|
|
@@ -58,14 +58,19 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
loginResVo.setRoleInfo(kwsRoleResDtos);
|
|
|
loginResVo.setClientType(reqDto.getClientType());
|
|
|
if (CollectionUtils.isEmpty(kwsRoleResDtos)) {
|
|
|
- //角色信息为空,没有认证
|
|
|
+ //用户-角色信息为空,没有认证
|
|
|
afterProcessor(loginResVo);
|
|
|
return loginResVo;
|
|
|
}
|
|
|
|
|
|
|
|
|
/*2、登录成功,查询用户机构*/
|
|
|
- List<Long> deptIds = kwsRoleResDtos.stream().map(KwsRoleResDto::getDeptId).toList();
|
|
|
+ List<KwsUserDeptResDto> kwsUserDeptResDtos = remoteUserService.queryUserDeptByUserId(userId);
|
|
|
+ if (CollectionUtils.isEmpty(kwsUserDeptResDtos)) {
|
|
|
+ throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> deptIds = kwsUserDeptResDtos.stream().map(KwsUserDeptResDto::getDeptId).toList();
|
|
|
List<KwsDeptResDto> kwsDepts = remoteUserService.queryDeptByIds(deptIds);
|
|
|
if (CollectionUtils.isEmpty(kwsDepts)) {
|
|
|
//数据不全,直接返回
|
|
|
@@ -77,13 +82,13 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
/*3、查企业*/
|
|
|
//目前一个人只能归属于一个企业,所以这里取第一个就行
|
|
|
Long entId = kwsDepts.get(0).getEntId();
|
|
|
- KwsEnterpriseResDto kwsEnterprise = remoteUserService.queryEnterpriseById(entId);
|
|
|
- if (Objects.isNull(kwsEnterprise)) {
|
|
|
+ KwsEnterpriseResDto kwsEnterpriseResDto = remoteUserService.queryEnterpriseById(entId);
|
|
|
+ if (Objects.isNull(kwsEnterpriseResDto)) {
|
|
|
//只要查出了机构,这个if其实不会进的,做保险起见还是加上判空
|
|
|
afterProcessor(loginResVo);
|
|
|
return loginResVo;
|
|
|
}
|
|
|
- BeanUtils.copyProperties(kwsEnterprise, entInfoResVo);
|
|
|
+ BeanUtils.copyProperties(kwsEnterpriseResDto, entInfoResVo);
|
|
|
|
|
|
/*4、生成token,一些信息存redis*/
|
|
|
afterProcessor(loginResVo);
|
|
|
@@ -99,7 +104,7 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
} else {
|
|
|
String key = Global.USER_LOGIN_CAPTCHA + reqDto.getSystemType() + Global.COLON + kwsUser.getAccount();
|
|
|
String captcha = RedissonUtils.getString(key);
|
|
|
- if (StringUtils.isBlank(captcha) || StringUtils.isBlank(reqDto.getCaptcha()) || !reqDto.getCaptcha().equals(captcha)){
|
|
|
+ if (StringUtils.isBlank(captcha) || StringUtils.isBlank(reqDto.getCaptcha()) || !reqDto.getCaptcha().equals(captcha)) {
|
|
|
throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.CAPCHA_ERROR);
|
|
|
}
|
|
|
RedissonUtils.delete(key);
|
|
|
@@ -108,22 +113,18 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param loginResVo 登录的返参
|
|
|
+ * @param loginResVo 登录的返参
|
|
|
* @desc: 生成token,存redis
|
|
|
* @author: czh
|
|
|
* @date: 2023/6/12
|
|
|
*/
|
|
|
private void afterProcessor(LoginResVo loginResVo) {
|
|
|
try {
|
|
|
- Long id = loginResVo.getId();
|
|
|
- String token = EncryUtil.encry(Global.PRI_KEY, String.valueOf(id));
|
|
|
- loginResVo.setToken(token);
|
|
|
- RedissonUtils.putString(Global.getFullUserLoginKey(loginResVo.getSystemType(), loginResVo.getId(), loginResVo.getClientType()), JSON.toJSONString(loginResVo), Global.PC_TOKEN_EXPIRE);
|
|
|
+ //设置token
|
|
|
+ loginResVo.setToken(EncryUtil.encry(Global.PRI_KEY, String.valueOf(loginResVo.getId())));
|
|
|
|
|
|
//异步存redis
|
|
|
- AsyncFactory.execute(new SaveMenuInfo(loginResVo.getId()));
|
|
|
- AsyncFactory.execute(new SaveLoginInfo(loginResVo, String.valueOf(loginResVo.getSystemType()), remoteUserService));
|
|
|
-
|
|
|
+ AsyncFactory.execute(new AsyncProcess(loginResVo, remoteUserService));
|
|
|
} catch (Exception e) {
|
|
|
throw new SystemException(HttpStatus.GLOBAL_EXCEPTION_CODE, HttpStatus.GLOBAL_EXCEPTION_MESSAGE);
|
|
|
}
|
|
|
@@ -132,7 +133,7 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = {})
|
|
|
public void register(RegisterReqVo reqVo) {
|
|
|
- /*1、校验验证码*/
|
|
|
+ /*校验验证码*/
|
|
|
String key = Global.USER_LOGIN_CAPTCHA + reqVo.getPhone() + Global.COLON + reqVo.getSystemType();
|
|
|
String sms = RedissonUtils.getString(key);
|
|
|
if (!reqVo.getCaptcha().equals(sms)) {
|
|
|
@@ -146,7 +147,6 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public void forgetPassword(ForgetPasswordReqVo reqDto) throws SystemException {
|
|
|
ForgetPasswordReqDto forgetPasswordReqDto = new ForgetPasswordReqDto();
|
|
|
@@ -155,20 +155,56 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- class SaveMenuInfo implements Runnable{
|
|
|
+ static class AsyncProcess implements Runnable {
|
|
|
|
|
|
- private final long id;
|
|
|
+ private final LoginResVo loginResVo;
|
|
|
+
|
|
|
+ private final RemoteUserService remoteUserService;
|
|
|
|
|
|
- public SaveMenuInfo(long id) {
|
|
|
- this.id = id;
|
|
|
+ public AsyncProcess(LoginResVo loginResVo, RemoteUserService remoteUserService) {
|
|
|
+ this.loginResVo = loginResVo;
|
|
|
+ this.remoteUserService = remoteUserService;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void run() {
|
|
|
+ //存基础信息
|
|
|
+ SaveBaseToCache(loginResVo);
|
|
|
+
|
|
|
+ //存菜单权限
|
|
|
+ SaveToCache(loginResVo);
|
|
|
+
|
|
|
+ //存登录记录信息
|
|
|
+ SaveLoginInfo(loginResVo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param loginResVo 返参
|
|
|
+ * @desc: 存基础信息
|
|
|
+ * @author: czh
|
|
|
+ * @date: 2023/6/28
|
|
|
+ */
|
|
|
+ private void SaveBaseToCache(LoginResVo loginResVo) {
|
|
|
+ //存用户登录信息
|
|
|
+ RedissonUtils.putString(Global.getFullUserLoginKey(loginResVo.getSystemType(), loginResVo.getId(), loginResVo.getClientType()), JSON.toJSONString(loginResVo), Global.PC_TOKEN_EXPIRE);
|
|
|
+
|
|
|
+ //单独存用户企业
|
|
|
+ RedissonUtils.putString(Global.getFullUserEntKey(loginResVo.getSystemType(), loginResVo.getId()), JSON.toJSONString(loginResVo.getEntInfo()), Global.PC_TOKEN_EXPIRE);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param loginResVo 登录返参
|
|
|
+ * @desc: 存缓存
|
|
|
+ * @author: czh
|
|
|
+ * @date: 2023/6/28
|
|
|
+ */
|
|
|
+ private void SaveToCache(LoginResVo loginResVo) {
|
|
|
//存权限菜单
|
|
|
+ long id = loginResVo.getId();
|
|
|
List<UserAccessMenuInfoResDto> userAccessMenuInfo = remoteUserService.queryUserAccessMenu(id);
|
|
|
if (CollectionUtils.isEmpty(userAccessMenuInfo)) {
|
|
|
- RedissonUtils.delete(Global.REDIS_SYS_MENU_PREFIX + id);
|
|
|
+ RedissonUtils.delete(Global.REDIS_SYS_MENU_PREFIX + loginResVo.getSystemType() + Global.COLON + id);
|
|
|
log.error("未查询到用户{}的菜单权限", id);
|
|
|
return;
|
|
|
}
|
|
|
@@ -182,24 +218,14 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
}
|
|
|
RedissonUtils.putSet(Global.REDIS_SYS_MENU_PREFIX + id, menus);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- class SaveLoginInfo implements Runnable {
|
|
|
-
|
|
|
- private final LoginResVo loginResVo;
|
|
|
-
|
|
|
- private final String clientType;
|
|
|
-
|
|
|
- private final RemoteUserService remoteUserService;
|
|
|
-
|
|
|
- public SaveLoginInfo(LoginResVo loginResVo, String clientType, RemoteUserService remoteUserService) {
|
|
|
- this.loginResVo = loginResVo;
|
|
|
- this.clientType = clientType;
|
|
|
- this.remoteUserService = remoteUserService;
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
+ /**
|
|
|
+ * @param loginResVo 登录返参
|
|
|
+ * @desc: 存登录记录信息
|
|
|
+ * @author: czh
|
|
|
+ * @date: 2023/6/28
|
|
|
+ */
|
|
|
+ private void SaveLoginInfo(LoginResVo loginResVo) {
|
|
|
long userId = loginResVo.getId();
|
|
|
UserLoginReqDto currentDayLogin = remoteUserService.currentDayLogin(userId);
|
|
|
UserLoginReqDto userLoginReqDto = new UserLoginReqDto();
|
|
|
@@ -212,9 +238,10 @@ public class AuthServiceImpl implements IAuthService {
|
|
|
userLoginReqDto.setFirst(Objects.isNull(currentDayLogin) ? Global.YES : Global.NO);
|
|
|
userLoginReqDto.setLock(Global.NO);
|
|
|
userLoginReqDto.setType(Global.NO);
|
|
|
- userLoginReqDto.setSource(clientType);
|
|
|
+ userLoginReqDto.setSource(loginResVo.getClientType());
|
|
|
remoteUserService.saveUserLogin(userLoginReqDto);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|