|
@@ -5,9 +5,13 @@ import com.sckw.auth.model.vo.req.LoginReqVo;
|
|
|
import com.sckw.auth.model.vo.res.DeptInfoResVo;
|
|
import com.sckw.auth.model.vo.res.DeptInfoResVo;
|
|
|
import com.sckw.auth.model.vo.res.EntInfoResVo;
|
|
import com.sckw.auth.model.vo.res.EntInfoResVo;
|
|
|
import com.sckw.auth.model.vo.res.LoginResVo;
|
|
import com.sckw.auth.model.vo.res.LoginResVo;
|
|
|
|
|
+import com.sckw.system.api.model.dto.res.KwsRoleResDto;
|
|
|
|
|
+import com.sckw.core.exception.SystemException;
|
|
|
|
|
+import com.sckw.core.model.constant.Global;
|
|
|
import com.sckw.core.utils.BeanUtils;
|
|
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.EncryUtil;
|
|
|
|
|
+import com.sckw.core.web.constant.HttpStatus;
|
|
|
import com.sckw.redis.utils.RedissonUtils;
|
|
import com.sckw.redis.utils.RedissonUtils;
|
|
|
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.*;
|
|
@@ -42,16 +46,21 @@ public class IndexServiceImpl implements IIndexService {
|
|
|
LoginResVo loginResVo = new LoginResVo();
|
|
LoginResVo loginResVo = new LoginResVo();
|
|
|
BeanUtils.copyProperties(kwsUser, loginResVo);
|
|
BeanUtils.copyProperties(kwsUser, loginResVo);
|
|
|
|
|
|
|
|
- /*2、登录成功,查询用户机构*/
|
|
|
|
|
|
|
+ /*2、登录成功,查询角色信息*/
|
|
|
|
|
+ Long userId = kwsUser.getId();
|
|
|
|
|
+ List<KwsRoleResDto> kwsRoleResDtos = remoteUserService.queryRoleInfoByUserId(userId);
|
|
|
EntInfoResVo entInfoResVo = new EntInfoResVo();
|
|
EntInfoResVo entInfoResVo = new EntInfoResVo();
|
|
|
loginResVo.setEntInfo(entInfoResVo);
|
|
loginResVo.setEntInfo(entInfoResVo);
|
|
|
- List<KwsUserDeptResDto> kwsUserDepts = remoteUserService.queryUserDeptByUserId(kwsUser.getId());
|
|
|
|
|
- if (CollectionUtils.isEmpty(kwsUserDepts)) {
|
|
|
|
|
- //没有认证,没有所属机构
|
|
|
|
|
|
|
+ loginResVo.setRoleInfo(kwsRoleResDtos);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(kwsRoleResDtos)) {
|
|
|
|
|
+ //角色信息为空,没有认证
|
|
|
saveToCache(loginResVo);
|
|
saveToCache(loginResVo);
|
|
|
return loginResVo;
|
|
return loginResVo;
|
|
|
}
|
|
}
|
|
|
- List<Long> deptIds = kwsUserDepts.stream().map(KwsUserDeptResDto::getDeptId).toList();
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /*2、登录成功,查询用户机构*/
|
|
|
|
|
+ List<Long> deptIds = kwsRoleResDtos.stream().map(KwsRoleResDto::getDeptId).toList();
|
|
|
List<KwsDeptResDto> kwsDepts = remoteUserService.queryDeptByIds(deptIds);
|
|
List<KwsDeptResDto> kwsDepts = remoteUserService.queryDeptByIds(deptIds);
|
|
|
if (CollectionUtils.isEmpty(kwsDepts)) {
|
|
if (CollectionUtils.isEmpty(kwsDepts)) {
|
|
|
//数据不全,直接返回
|
|
//数据不全,直接返回
|
|
@@ -68,20 +77,31 @@ public class IndexServiceImpl implements IIndexService {
|
|
|
Long entId = kwsDepts.get(0).getEntId();
|
|
Long entId = kwsDepts.get(0).getEntId();
|
|
|
KwsEnterpriseResDto kwsEnterprise = remoteUserService.queryEnterpriseById(entId);
|
|
KwsEnterpriseResDto kwsEnterprise = remoteUserService.queryEnterpriseById(entId);
|
|
|
if (Objects.isNull(kwsEnterprise)) {
|
|
if (Objects.isNull(kwsEnterprise)) {
|
|
|
|
|
+ //只要查出了机构,这个if其实不会进的,做保险起见还是加上判空
|
|
|
saveToCache(loginResVo);
|
|
saveToCache(loginResVo);
|
|
|
return loginResVo;
|
|
return loginResVo;
|
|
|
}
|
|
}
|
|
|
- BeanUtils.copyProperties(kwsEnterprise, loginResVo);
|
|
|
|
|
|
|
+ BeanUtils.copyProperties(kwsEnterprise, entInfoResVo);
|
|
|
|
|
|
|
|
/*4、以uuid作为主键存redis,也是会话token*/
|
|
/*4、以uuid作为主键存redis,也是会话token*/
|
|
|
saveToCache(loginResVo);
|
|
saveToCache(loginResVo);
|
|
|
return loginResVo;
|
|
return loginResVo;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param loginResDto 登录的返参
|
|
|
|
|
+ * @desc: 生成token,存redis
|
|
|
|
|
+ * @author: czh
|
|
|
|
|
+ * @date: 2023/6/12
|
|
|
|
|
+ */
|
|
|
private void saveToCache(LoginResVo loginResDto) {
|
|
private void saveToCache(LoginResVo loginResDto) {
|
|
|
- String key = UUIDUtils.get32UUID();
|
|
|
|
|
- loginResDto.setToken(key);
|
|
|
|
|
- redissonUtils.add(key, JSON.toJSONString(loginResDto));
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ String token = EncryUtil.encry(Global.PRI_KEY, JSON.toJSONString(loginResDto));
|
|
|
|
|
+ loginResDto.setToken(token);
|
|
|
|
|
+ redissonUtils.add(token, JSON.toJSONString(loginResDto));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new SystemException(HttpStatus.GLOBAL_EXCEPTION_CODE, HttpStatus.GLOBAL_EXCEPTION_MESSAGE);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|