|
@@ -1,5 +1,6 @@
|
|
|
package com.poteviohealth.cgp.sso.module.system.controller.admin.userclient;
|
|
package com.poteviohealth.cgp.sso.module.system.controller.admin.userclient;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import com.poteviohealth.cgp.sso.framework.common.enums.CommonStatusEnum;
|
|
import com.poteviohealth.cgp.sso.framework.common.enums.CommonStatusEnum;
|
|
|
import com.poteviohealth.cgp.sso.framework.common.pojo.CommonResult;
|
|
import com.poteviohealth.cgp.sso.framework.common.pojo.CommonResult;
|
|
|
import com.poteviohealth.cgp.sso.framework.common.pojo.PageResult;
|
|
import com.poteviohealth.cgp.sso.framework.common.pojo.PageResult;
|
|
@@ -7,10 +8,12 @@ import com.poteviohealth.cgp.sso.framework.common.util.object.BeanUtils;
|
|
|
import com.poteviohealth.cgp.sso.framework.security.core.util.SecurityFrameworkUtils;
|
|
import com.poteviohealth.cgp.sso.framework.security.core.util.SecurityFrameworkUtils;
|
|
|
import com.poteviohealth.cgp.sso.module.system.controller.admin.user.vo.user.UserSyncReqVO;
|
|
import com.poteviohealth.cgp.sso.module.system.controller.admin.user.vo.user.UserSyncReqVO;
|
|
|
import com.poteviohealth.cgp.sso.module.system.controller.admin.userclient.vo.*;
|
|
import com.poteviohealth.cgp.sso.module.system.controller.admin.userclient.vo.*;
|
|
|
|
|
+import com.poteviohealth.cgp.sso.module.system.dal.dataobject.dept.DeptDO;
|
|
|
import com.poteviohealth.cgp.sso.module.system.dal.dataobject.oauth2.OAuth2ClientDO;
|
|
import com.poteviohealth.cgp.sso.module.system.dal.dataobject.oauth2.OAuth2ClientDO;
|
|
|
import com.poteviohealth.cgp.sso.module.system.dal.dataobject.user.AdminUserDO;
|
|
import com.poteviohealth.cgp.sso.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
import com.poteviohealth.cgp.sso.module.system.dal.dataobject.userclient.UserClientDO;
|
|
import com.poteviohealth.cgp.sso.module.system.dal.dataobject.userclient.UserClientDO;
|
|
|
import com.poteviohealth.cgp.sso.module.system.enums.ErrorCodeConstants;
|
|
import com.poteviohealth.cgp.sso.module.system.enums.ErrorCodeConstants;
|
|
|
|
|
+import com.poteviohealth.cgp.sso.module.system.service.dept.DeptService;
|
|
|
import com.poteviohealth.cgp.sso.module.system.service.oauth2.OAuth2ClientService;
|
|
import com.poteviohealth.cgp.sso.module.system.service.oauth2.OAuth2ClientService;
|
|
|
import com.poteviohealth.cgp.sso.module.system.service.user.AdminUserService;
|
|
import com.poteviohealth.cgp.sso.module.system.service.user.AdminUserService;
|
|
|
import com.poteviohealth.cgp.sso.module.system.service.userclient.UserClientService;
|
|
import com.poteviohealth.cgp.sso.module.system.service.userclient.UserClientService;
|
|
@@ -55,6 +58,9 @@ public class UserClientController {
|
|
|
@Resource
|
|
@Resource
|
|
|
private OAuth2ClientService oAuth2ClientService;
|
|
private OAuth2ClientService oAuth2ClientService;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private DeptService deptService;
|
|
|
|
|
+
|
|
|
@Resource
|
|
@Resource
|
|
|
private RestTemplate restTemplate;
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
|
@@ -177,7 +183,7 @@ public class UserClientController {
|
|
|
HttpEntity< Map<String, Object>> httpEntity = new HttpEntity<>(dataMap);
|
|
HttpEntity< Map<String, Object>> httpEntity = new HttpEntity<>(dataMap);
|
|
|
try {
|
|
try {
|
|
|
ResponseEntity exchange = restTemplate.postForEntity(oAuth2Client.getSyncUserInfoUrl(), httpEntity,Object.class);
|
|
ResponseEntity exchange = restTemplate.postForEntity(oAuth2Client.getSyncUserInfoUrl(), httpEntity,Object.class);
|
|
|
- System.out.println(exchange);
|
|
|
|
|
|
|
+ log.info("###################",exchange);
|
|
|
if(exchange.getStatusCode()== HttpStatus.OK){
|
|
if(exchange.getStatusCode()== HttpStatus.OK){
|
|
|
Map<String,Object> resultRemote = (Map)exchange.getBody();
|
|
Map<String,Object> resultRemote = (Map)exchange.getBody();
|
|
|
if(Objects.nonNull(resultRemote)){
|
|
if(Objects.nonNull(resultRemote)){
|
|
@@ -210,12 +216,36 @@ public class UserClientController {
|
|
|
dataMap.put("mobile", user.getMobile());
|
|
dataMap.put("mobile", user.getMobile());
|
|
|
String signature = TransmitSecurityUtil.constructSignature(oAuth2Client.getSecret(), nonce, timestamp, dataMap);
|
|
String signature = TransmitSecurityUtil.constructSignature(oAuth2Client.getSecret(), nonce, timestamp, dataMap);
|
|
|
String url = constructUrl(syncUserInfoUrl, nonce, signature, timestamp, oAuth2Client.getClientId());
|
|
String url = constructUrl(syncUserInfoUrl, nonce, signature, timestamp, oAuth2Client.getClientId());
|
|
|
|
|
+ //获取机构信息
|
|
|
|
|
+ String companyName = null;
|
|
|
|
|
+ String deptName = null;
|
|
|
|
|
+ String deptCode = null;
|
|
|
|
|
+ if(Objects.nonNull(user.getDeptId())){
|
|
|
|
|
+ DeptDO dept = deptService.getDept(user.getDeptId());
|
|
|
|
|
+ if(dept.getParentId().compareTo(DeptDO.PARENT_ID_ROOT)!=0){
|
|
|
|
|
+ Set<Long> deptIds = Arrays.stream(dept.getTreePath().split(",")).map(s->Long.parseLong(s.trim())).collect(Collectors.toSet());
|
|
|
|
|
+ List<DeptDO> deptList = deptService.getDeptList(deptIds);
|
|
|
|
|
+ Map<Long,DeptDO> deptMap = deptList.stream().collect(Collectors.toMap(DeptDO::getParentId,Function.identity()));
|
|
|
|
|
+ DeptDO rootDept = deptMap.get(0L);
|
|
|
|
|
+ if(Objects.nonNull(rootDept)){
|
|
|
|
|
+ DeptDO company = deptMap.get(rootDept.getId());
|
|
|
|
|
+ if (Objects.nonNull(company)){
|
|
|
|
|
+ companyName = company.getName();
|
|
|
|
|
+ DeptDO deptOrg = deptMap.get(company.getId());
|
|
|
|
|
+ if(Objects.nonNull(deptOrg)){
|
|
|
|
|
+ deptName = deptOrg.getName();
|
|
|
|
|
+ deptCode = deptOrg.getCode();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
//头部信息
|
|
//头部信息
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
|
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
|
|
headers.set(HEADER, Objects.nonNull(oAuth2Client.getAppId())? oAuth2Client.getAppId(): oAuth2Client.getClientId());
|
|
headers.set(HEADER, Objects.nonNull(oAuth2Client.getAppId())? oAuth2Client.getAppId(): oAuth2Client.getClientId());
|
|
|
HttpEntity<UserSsoVo> httpEntity = new HttpEntity<>(new UserSsoVo(user.getUsername()
|
|
HttpEntity<UserSsoVo> httpEntity = new HttpEntity<>(new UserSsoVo(user.getUsername()
|
|
|
- , user.getNickname(), user.getIdNumber(), user.getMobile(), null, null, null),
|
|
|
|
|
|
|
+ , user.getNickname(), user.getIdNumber(), user.getMobile(), null, companyName, deptName,deptName,deptCode),
|
|
|
headers);
|
|
headers);
|
|
|
ResponseEntity exchange = restTemplate.postForEntity(url, httpEntity,Object.class);
|
|
ResponseEntity exchange = restTemplate.postForEntity(url, httpEntity,Object.class);
|
|
|
System.out.println(exchange);
|
|
System.out.println(exchange);
|