|
|
@@ -7,14 +7,18 @@ import com.usoftchina.saas.account.po.Company;
|
|
|
import com.usoftchina.saas.account.service.AccountCenterService;
|
|
|
import com.usoftchina.saas.account.service.AccountService;
|
|
|
import com.usoftchina.saas.account.service.CompanyService;
|
|
|
+import com.usoftchina.saas.auth.api.AuthApi;
|
|
|
+import com.usoftchina.saas.auth.dto.TokenDTO;
|
|
|
import com.usoftchina.saas.base.Result;
|
|
|
import com.usoftchina.saas.exception.ExceptionCode;
|
|
|
import com.usoftchina.saas.utils.BeanMapper;
|
|
|
import com.usoftchina.saas.utils.StringUtils;
|
|
|
import com.usoftchina.sso.api.SsoUserApi;
|
|
|
+import com.usoftchina.sso.api.SsoUserSpaceApi;
|
|
|
import com.usoftchina.sso.dto.SsoUserSpace;
|
|
|
import com.usoftchina.sso.dto.SsoUserSpaceList;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
@@ -36,11 +40,12 @@ public class AccountCenterServiceImpl implements AccountCenterService {
|
|
|
@Autowired
|
|
|
private SsoUserApi ssoUserApi;
|
|
|
@Autowired
|
|
|
+ private SsoUserSpaceApi ssoUserSpaceApi;
|
|
|
+ @Autowired
|
|
|
+ private AuthApi authApi;
|
|
|
+ @Autowired
|
|
|
private AccountCompanyMapper accountCompanyMapper;
|
|
|
|
|
|
- private final String ACCOUNTCNETER_URL_DEV = "http://192.168.253.12:32323";
|
|
|
- //private final String ACCOUNTCNETER_URL_PROD = "https://sso.ubtob.com";
|
|
|
-
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public Result saveCompanyAccount(CompanyAccountDTO companyAccountDTO) {
|
|
|
@@ -66,9 +71,9 @@ public class AccountCenterServiceImpl implements AccountCenterService {
|
|
|
companyService.save(company);
|
|
|
//b. 同步企业信息到优软云 ——> 创建企业
|
|
|
if ("0".equals(type)) {
|
|
|
- String result = postToAccount(company.getName(), company.getBusinessCode(), accountRegDTO.getUu());
|
|
|
- accountCompanyMapper.insert(accountId, company.getId());
|
|
|
+ String result = ssoUserSpaceApi.registerLogin(company.getName(), company.getBusinessCode(), Long.parseLong(accountRegDTO.getUu()));
|
|
|
}
|
|
|
+ accountCompanyMapper.insert(accountId, company.getId());
|
|
|
//2.更新账户信息
|
|
|
Account account = BeanMapper.map(accountRegDTO, Account.class);
|
|
|
|
|
|
@@ -77,22 +82,18 @@ public class AccountCenterServiceImpl implements AccountCenterService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 将企业信息同步到优软云
|
|
|
- * @param spaceName
|
|
|
- * @param businesscode
|
|
|
- * @param uu
|
|
|
- * @return
|
|
|
- */
|
|
|
- private String postToAccount(String spaceName, String businesscode, String uu) {
|
|
|
- String url = "/sso/userspace/register/admin";
|
|
|
- RestTemplate restTemplate = new RestTemplate();
|
|
|
- MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<>();
|
|
|
- requestEntity.add("spaceName", spaceName);
|
|
|
- requestEntity.add("businessCode", businesscode);
|
|
|
- requestEntity.add("userUU", uu);
|
|
|
- String result = restTemplate.postForObject(ACCOUNTCNETER_URL_DEV + url, requestEntity, String.class);
|
|
|
- return result;
|
|
|
+ @Override
|
|
|
+ public boolean updateCompanyAccount(CompanyAccountDTO companyAccountDTO) {
|
|
|
+ CompanyRegDTO companyRegDTO = companyAccountDTO.getCompanyRegDTO();
|
|
|
+ AccountRegDTO accountRegDTO = companyAccountDTO.getAccountRegDTO();
|
|
|
+ Long accountId = accountService.findByMobile(accountRegDTO.getMobile()).getId();
|
|
|
+ //更新企业信息
|
|
|
+ companyService.update(companyRegDTO);
|
|
|
+ //更新账户信息
|
|
|
+ Account account = BeanMapper.map(accountRegDTO, Account.class);
|
|
|
+ account.setId(accountId);
|
|
|
+ accountService.updateByPrimaryKeySelective(account);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -116,27 +117,37 @@ public class AccountCenterServiceImpl implements AccountCenterService {
|
|
|
|
|
|
//3、去重复
|
|
|
for (CompanyRspDTO companyRspDTO : companyRspDTOList) {
|
|
|
- for (SsoUserSpace ssoUserSpace : ssoUserSpaces) {
|
|
|
- if (companyRspDTO.getName().equals(ssoUserSpace.getSpaceName())){
|
|
|
- ssoUserSpaces.remove(ssoUserSpace);
|
|
|
+ for (int i = 0; i < ssoUserSpaces.size(); i++){
|
|
|
+ if (companyRspDTO.getName().equals(ssoUserSpaces.get(i).getSpaceName())){
|
|
|
+ //更新公司UU号
|
|
|
+ if (StringUtils.isEmpty(companyRspDTO.getUu())){
|
|
|
+ companyService.updateUUByPrimaryKey(companyRspDTO.getId(), ssoUserSpaces.get(i).getSpaceUU());
|
|
|
+ }
|
|
|
+ ssoUserSpaces.remove(ssoUserSpaces.get(i));
|
|
|
}
|
|
|
}
|
|
|
if (companyRspDTO.isDefault_()){
|
|
|
resultMap.put("hasDefaultCompany", true);
|
|
|
resultMap.put("defaultCompanyId", companyRspDTO.getId());
|
|
|
+ TokenDTO tokenDTO = authApi.switchCompany(companyRspDTO.getId()).getData();
|
|
|
+ resultMap.put("token", tokenDTO);
|
|
|
}
|
|
|
}
|
|
|
//构造返回数据
|
|
|
- for (SsoUserSpace ssoUserSpace : ssoUserSpaces){
|
|
|
- CompanyRspDTO companyRspDTO = new CompanyRspDTO(
|
|
|
- ssoUserSpace.getSpaceName(),
|
|
|
- ssoUserSpace.getBusinessCode(),
|
|
|
- ssoUserSpace.getRegAddress(),
|
|
|
- false,
|
|
|
- false,
|
|
|
- ssoUserSpace.getSpaceUU().toString()
|
|
|
- );
|
|
|
- resultList.add(companyRspDTO);
|
|
|
+ if (ssoUserSpaces.size() > 0) {
|
|
|
+ for (SsoUserSpace ssoUserSpace : ssoUserSpaces) {
|
|
|
+ CompanyRspDTO companyRspDTO = new CompanyRspDTO(
|
|
|
+ ssoUserSpace.getSpaceName(),
|
|
|
+ ssoUserSpace.getBusinessCode(),
|
|
|
+ ssoUserSpace.getRegAddress(),
|
|
|
+ false,
|
|
|
+ false,
|
|
|
+ ssoUserSpace.getSpaceUU().toString(),
|
|
|
+ ssoUserSpace.getAdmin().getVipName(),
|
|
|
+ 0l
|
|
|
+ );
|
|
|
+ resultList.add(companyRspDTO);
|
|
|
+ }
|
|
|
}
|
|
|
resultMap.put("spaces", resultList);
|
|
|
return resultMap;
|