Browse Source

账户新增BUG修改

chenw 7 years ago
parent
commit
de1e7b98cf

+ 26 - 1
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/controller/AccountController.java

@@ -11,6 +11,7 @@ import com.usoftchina.saas.auth.client.annotation.IgnoreAuth;
 import com.usoftchina.saas.base.Result;
 import com.usoftchina.saas.commons.dto.ListReqDTO;
 import com.usoftchina.saas.context.BaseContextHolder;
+import com.usoftchina.saas.exception.BizException;
 import com.usoftchina.saas.exception.ExceptionCode;
 import com.usoftchina.saas.page.PageDefault;
 import com.usoftchina.saas.page.PageRequest;
@@ -18,6 +19,7 @@ import com.usoftchina.saas.utils.BeanMapper;
 import com.usoftchina.saas.utils.CollectionUtils;
 import com.usoftchina.saas.utils.RegexpUtils;
 import com.usoftchina.sso.api.SsoUserApi;
+import com.usoftchina.sso.dto.SsoCheckMobile;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -116,10 +118,20 @@ public class AccountController {
         Account account = null;
         // 根据手机号、邮箱、用户名片段判断是否已注册
         boolean checked = accountService.findByUsernameOrMobileOrEmail(accountAddDTO.getUsername(), accountAddDTO.getMobile(), accountAddDTO.getEmail());
+        //不存在 ——> 保存 , 存在 ——> 更新
         if (!checked) {
             account = BeanMapper.map(accountAddDTO, Account.class);
             account.setEnabled(true);
             accountService.save(account);
+        }else{
+            Account accountTemp = accountService.findByMobile(accountAddDTO.getMobile());
+            if (accountTemp == null){
+                accountTemp = accountService.findByEmail(accountAddDTO.getEmail());
+            }
+            account = BeanMapper.map(accountAddDTO, Account.class);
+            account.setEnabled(true);
+            account.setId(accountTemp.getId());
+            accountService.updateByPrimaryKeySelective(account);
         }
         account = accountService.findByMobile(accountAddDTO.getMobile());
         //绑定企业
@@ -137,7 +149,20 @@ public class AccountController {
      */
     @GetMapping("/checkMobile")
     public Result checkMobile(@RequestParam("mobile") String mobile){
-        return Result.success(ssoUserApi.checkMobile(mobile));
+        SsoCheckMobile ssoCheckMobile = ssoUserApi.checkMobile(mobile);
+        Long companyId = BaseContextHolder.getCompanyId();
+        if (ssoCheckMobile.isHasRegister()){
+            Account account = accountService.findByMobile(mobile);
+            if (account != null){
+                List<CompanyBaseVO> companyBaseVOList = companyService.findBaseByAccountId(account.getId());
+                for (CompanyBaseVO companyBaseVO : companyBaseVOList){
+                    if (companyBaseVO.getId().equals(companyId)){
+                        throw new BizException(ExceptionCode.USER_COMPANY_EXIST);
+                    }
+                }
+            }
+        }
+        return Result.success(ssoCheckMobile);
     }
 
     @GetMapping("/checkEmail")

+ 2 - 1
base-servers/account/account-server/src/main/java/com/usoftchina/saas/account/service/impl/AccountCenterServiceImpl.java

@@ -12,6 +12,7 @@ import com.usoftchina.saas.account.service.RoleService;
 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.BizException;
 import com.usoftchina.saas.exception.ExceptionCode;
 import com.usoftchina.saas.utils.BeanMapper;
 import com.usoftchina.saas.utils.StringUtils;
@@ -62,7 +63,7 @@ public class AccountCenterServiceImpl implements AccountCenterService {
         Company company = companyService.findByName(companyRegDTO.getName());
         if (null != company) {
             Account account = accountService.findByPrimaryKey(company.getCreatorId());
-            return Result.error(String.format(ExceptionCode.COMPANY_NAME_HASREGISTER.getMessage(), account.getRealname()+"("+account.getMobile()+")"));
+            throw new BizException(ExceptionCode.COMPANY_CODE_EXIST.getCode(), String.format(ExceptionCode.COMPANY_NAME_HASREGISTER.getMessage(), account.getRealname()+"("+account.getMobile()+")"));
         }
         company = companyService.findByBusinessCode(companyRegDTO.getBusinessCode());
         if (null != company) {

+ 1 - 0
framework/core/src/main/java/com/usoftchina/saas/exception/ExceptionCode.java

@@ -44,6 +44,7 @@ public enum ExceptionCode implements BaseExceptionCode {
     USER_NOT_ENABLE(53006, "用户禁止使用"),
     ROLE_NOT_EXIST(53020, "角色不存在"),
     MISSING_PERMISSIONS(53030, "权限缺失"),
+    USER_COMPANY_EXIST(53007, "企业已存在账户"),
 
     // 文件相关
     FOLDER_NOT_EXISTS(55000, "文件夹不存在"),