diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java index 160544c96d..735afcfffd 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/SsoServiceImpl.java @@ -86,6 +86,9 @@ public class SsoServiceImpl implements SsoService { @Resource private EpmetUserFeignClient epmetUserFeignClient; + @Autowired + private ThirdLoginServiceImpl thirdLoginService; + @Value("${epmet.third.urlPrefix}") private String epmetThirdUrlPrefix; @@ -230,8 +233,7 @@ public class SsoServiceImpl implements SsoService { String mobile = data.getString("phone"); //1、根据手机号查询政府端工作人员基本信息,校验用户是否存在 Result> staffData = epmetUserFeignClient.checkCustomerStaff(mobile); - String customerId = ""; - String userId = ""; + String customerId = "", userId = ""; if (null != staffData && staffData.getData().size() > 0) { //2、根据客户Id和手机号查询登陆用户信息(代码逻辑来源于web端登陆接口) CustomerStaffDTO staffDTO = staffData.getData().get(0); @@ -255,9 +257,8 @@ public class SsoServiceImpl implements SsoService { //5.生成token存到redis并返回 userTokenResultDTO = new UserTokenResultDTO(); userTokenResultDTO.setCustomerId(customerId); - String token = generateToken(AppClientConstant.APP_GOV, AppClientConstant.CLIENT_WEB, userId); + String token = ssoGetToken(AppClientConstant.APP_GOV, AppClientConstant.CLIENT_SSO, userId, customerId); userTokenResultDTO.setToken(token); - disposeTokenDto(AppClientConstant.APP_GOV, AppClientConstant.CLIENT_WEB, userId, token, customerId); // 6.发送登录事件 try { SpringContextUtils.getBean(ThirdLoginService.class).sendLoginEvent(userId, "数字社区登录", @@ -337,6 +338,38 @@ public class SsoServiceImpl implements SsoService { return token; } + private String ssoGetToken(String app, String client, String userId, String customerId) { + Map map = new HashMap<>(); + map.put("app", app); + map.put("client", client); + map.put("userId", userId); + String token = jwtTokenUtils.createToken(map); + log.info("app:" + app + ";client:" + client + ";userId:" + userId + ";生成token[" + token + "]"); + int expire = jwtTokenProperties.getExpire(); + + String orgIdPath = thirdLoginService.getOrgIdPath(userId); + String[] orgIdPathParts = orgIdPath.split(":"); + + GovTokenDto tokenDto = new GovTokenDto(); + tokenDto.setCustomerId(customerId); + tokenDto.setApp(app); + tokenDto.setClient(client); + tokenDto.setUserId(userId); + tokenDto.setToken(token); + tokenDto.setUpdateTime(System.currentTimeMillis()); + tokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); + tokenDto.setAgencyId(orgIdPathParts[orgIdPathParts.length - 1]); + tokenDto.setRootAgencyId(orgIdPathParts[0]); + tokenDto.setDeptIdList(thirdLoginService.getDeptartmentIdList(userId)); + tokenDto.setGridIdList(thirdLoginService.getGridIdList(userId)); + tokenDto.setRoleList(thirdLoginService.queryGovStaffRoles(userId, orgIdPathParts[orgIdPathParts.length - 1])); + tokenDto.setOrgIdPath(orgIdPath); + + cpUserDetailRedis.set(tokenDto, expire); + log.info("截止时间:" + DateUtils.format(jwtTokenUtils.getExpiration(token), "yyyy-MM-dd HH:mm:ss")); + return token; + } + /** * @Description 获取customerId * @Param appId