|
|
@@ -7,11 +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;
|
|
|
@@ -19,7 +26,9 @@ import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
public class AccountCenterServiceImpl implements AccountCenterService {
|
|
|
@@ -29,11 +38,14 @@ public class AccountCenterServiceImpl implements AccountCenterService {
|
|
|
@Autowired
|
|
|
private AccountService accountService;
|
|
|
@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) {
|
|
|
@@ -59,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);
|
|
|
|
|
|
@@ -70,27 +82,26 @@ 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
|
|
|
- public List<CompanyRspDTO> getCompanyList(String mobile) {
|
|
|
- List<CompanyRspDTO> result = new ArrayList<CompanyRspDTO>();
|
|
|
+ public Map<String, Object> getCompanyList(String mobile) {
|
|
|
+ Map<String, Object> resultMap = new HashMap<String, Object>();
|
|
|
+ List<CompanyRspDTO> resultList = new ArrayList<CompanyRspDTO>();
|
|
|
+ resultMap.put("hasDefaultCompany", false);
|
|
|
+ resultMap.put("defaultCompanyId", -1);
|
|
|
//1、获取本SAAS系统的企业信息
|
|
|
List<CompanyRspDTO> companyRspDTOList = accountCompanyMapper.getCompanyListByAccountMobile(mobile);
|
|
|
//如果只有一条记录,将该企业设置为默认企业
|
|
|
@@ -99,21 +110,47 @@ public class AccountCenterServiceImpl implements AccountCenterService {
|
|
|
Long companyId = companyRspDTOList.get(0).getId();
|
|
|
accountCompanyMapper.bindDefault(accountId, companyId);
|
|
|
}
|
|
|
- result.addAll(companyRspDTOList);
|
|
|
+ resultList.addAll(companyRspDTOList);
|
|
|
//2、优软云返回的企业信息
|
|
|
- //TODO 通过接口获取优软云的企业信息
|
|
|
+ SsoUserSpaceList ssoUserSpaceList = ssoUserApi.getUserSpacesByMobile(mobile);
|
|
|
+ List<SsoUserSpace> ssoUserSpaces = ssoUserSpaceList.getSpaces();
|
|
|
|
|
|
//3、去重复
|
|
|
- /*for (CompanyRspDTO companyRspDTO : companyRspDTOList){
|
|
|
- for (CompanyBaseDTO companyBaseDTO : companyBaseDTOList){
|
|
|
- if (companyRspDTO.getName().equals(companyBaseDTO.getName())){
|
|
|
- companyBaseDTOList.remove(companyRspDTO);
|
|
|
+ for (CompanyRspDTO companyRspDTO : companyRspDTOList) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //构造返回数据
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|
|
|
- List<CompanyRspDTO> companyBaseRspDTOList = BeanMapper.mapList(companyBaseDTOList, CompanyRspDTO.class);
|
|
|
- result.addAll(companyBaseRspDTOList);*/
|
|
|
- return result;
|
|
|
+ resultMap.put("spaces", resultList);
|
|
|
+ return resultMap;
|
|
|
}
|
|
|
|
|
|
@Override
|