|
@@ -1,9 +1,14 @@
|
|
|
package com.sckw.auth.service.impl;
|
|
package com.sckw.auth.service.impl;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.sckw.auth.model.vo.req.LoginReqVo;
|
|
|
|
|
+import com.sckw.auth.model.vo.res.DeptInfoResVo;
|
|
|
|
|
+import com.sckw.auth.model.vo.res.EntInfoResVo;
|
|
|
|
|
+import com.sckw.auth.model.vo.res.LoginResVo;
|
|
|
|
|
+import com.sckw.core.utils.BeanUtils;
|
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.UUIDUtils;
|
|
import com.sckw.core.utils.UUIDUtils;
|
|
|
import com.sckw.redis.utils.RedissonUtils;
|
|
import com.sckw.redis.utils.RedissonUtils;
|
|
|
-import com.sckw.system.api.model.dto.req.LoginReqDto;
|
|
|
|
|
import com.sckw.system.api.model.dto.req.RegisterReqDto;
|
|
import com.sckw.system.api.model.dto.req.RegisterReqDto;
|
|
|
import com.sckw.system.api.model.dto.res.*;
|
|
import com.sckw.system.api.model.dto.res.*;
|
|
|
import com.sckw.auth.service.IIndexService;
|
|
import com.sckw.auth.service.IIndexService;
|
|
@@ -13,7 +18,9 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
@@ -26,34 +33,55 @@ public class IndexServiceImpl implements IIndexService {
|
|
|
private RedissonUtils redissonUtils;
|
|
private RedissonUtils redissonUtils;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public LoginResDto login(LoginReqDto reqDto) {
|
|
|
|
|
- /*1、根据账号密码或者手机号校验码登录,密码加密处理后面做*/
|
|
|
|
|
- KwsUserResDto kwsUser = remoteUserService.checkUserBase(reqDto.getUsername());
|
|
|
|
|
|
|
+ public LoginResVo login(LoginReqVo reqDto) {
|
|
|
|
|
+ /*1、根据账号密码或者手机号校验码登录, 手机号后面处理*/
|
|
|
|
|
+ KwsUserResDto kwsUser = remoteUserService.checkUserBase(reqDto.getAccount(), reqDto.getSystemType());
|
|
|
|
|
|
|
|
//密码校验
|
|
//密码校验
|
|
|
remoteUserService.checkPassword(reqDto.getPassword(), kwsUser.getPassword());
|
|
remoteUserService.checkPassword(reqDto.getPassword(), kwsUser.getPassword());
|
|
|
-
|
|
|
|
|
|
|
+ LoginResVo loginResVo = new LoginResVo();
|
|
|
|
|
+ BeanUtils.copyProperties(kwsUser, loginResVo);
|
|
|
|
|
|
|
|
/*2、登录成功,查询用户机构*/
|
|
/*2、登录成功,查询用户机构*/
|
|
|
|
|
+ EntInfoResVo entInfoResVo = new EntInfoResVo();
|
|
|
|
|
+ loginResVo.setEntInfo(entInfoResVo);
|
|
|
List<KwsUserDeptResDto> kwsUserDepts = remoteUserService.queryUserDeptByUserId(kwsUser.getId());
|
|
List<KwsUserDeptResDto> kwsUserDepts = remoteUserService.queryUserDeptByUserId(kwsUser.getId());
|
|
|
if (CollectionUtils.isEmpty(kwsUserDepts)) {
|
|
if (CollectionUtils.isEmpty(kwsUserDepts)) {
|
|
|
- //不用抛异常,可能没有认证
|
|
|
|
|
- log.info("");
|
|
|
|
|
|
|
+ //没有认证,没有所属机构
|
|
|
|
|
+ saveToCache(loginResVo);
|
|
|
|
|
+ return loginResVo;
|
|
|
}
|
|
}
|
|
|
List<Long> deptIds = kwsUserDepts.stream().map(KwsUserDeptResDto::getDeptId).toList();
|
|
List<Long> deptIds = kwsUserDepts.stream().map(KwsUserDeptResDto::getDeptId).toList();
|
|
|
List<KwsDeptResDto> kwsDepts = remoteUserService.queryDeptByIds(deptIds);
|
|
List<KwsDeptResDto> kwsDepts = remoteUserService.queryDeptByIds(deptIds);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(kwsDepts)) {
|
|
|
|
|
+ //数据不全,直接返回
|
|
|
|
|
+ saveToCache(loginResVo);
|
|
|
|
|
+ return loginResVo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<DeptInfoResVo> deptInfo = new ArrayList<>(4);
|
|
|
|
|
+ BeanUtils.copyProperties(kwsDepts, deptInfo);
|
|
|
|
|
+ entInfoResVo.setDeptInfo(deptInfo);
|
|
|
|
|
|
|
|
/*3、查企业*/
|
|
/*3、查企业*/
|
|
|
- List<Long> entIds = kwsDepts.stream().map(KwsDeptResDto::getEntId).toList();
|
|
|
|
|
- List<KwsEnterpriseResDto> kwsEnterprises = remoteUserService.queryEnterpriseByIds(entIds);
|
|
|
|
|
|
|
+ //目前一个人只能归属于一个企业,所以这里取第一个就行
|
|
|
|
|
+ Long entId = kwsDepts.get(0).getEntId();
|
|
|
|
|
+ KwsEnterpriseResDto kwsEnterprise = remoteUserService.queryEnterpriseById(entId);
|
|
|
|
|
+ if (Objects.isNull(kwsEnterprise)) {
|
|
|
|
|
+ saveToCache(loginResVo);
|
|
|
|
|
+ return loginResVo;
|
|
|
|
|
+ }
|
|
|
|
|
+ BeanUtils.copyProperties(kwsEnterprise, loginResVo);
|
|
|
|
|
|
|
|
/*4、以uuid作为主键存redis,也是会话token*/
|
|
/*4、以uuid作为主键存redis,也是会话token*/
|
|
|
- String key = UUIDUtils.get32UUID();
|
|
|
|
|
- redissonUtils.add(key, "");
|
|
|
|
|
|
|
+ saveToCache(loginResVo);
|
|
|
|
|
+ return loginResVo;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- /*5、组装返参*/
|
|
|
|
|
- //todo
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ private void saveToCache(LoginResVo loginResDto) {
|
|
|
|
|
+ String key = UUIDUtils.get32UUID();
|
|
|
|
|
+ loginResDto.setToken(key);
|
|
|
|
|
+ redissonUtils.add(key, JSON.toJSONString(loginResDto));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|