保誠-保戶業務員媒合平台
pamapi/src/main/java/com/pollex/pam/service/CustomerService.java
@@ -1,5 +1,7 @@
package com.pollex.pam.service;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
@@ -32,7 +34,13 @@
   }
   
   public String registerCustomer(CustomerRegisterDTO registDTO) {
      String account = registDTO.getContactType() == OtpLoginTypeEnum.EMAIL?registDTO.getEmail():registDTO.getPhone();
      boolean isCustomerExist = checkCustomerExist(registDTO);
      if(isCustomerExist) {
         throw new UsernameAlreadyUsedException();
      }else {
         String account = getCustomerAccount(registDTO);
      OtpTmp otpTmp = otpTmpService.findByAccountAndIndexKey(account, registDTO.getIndexKey());
       if(otpTmp.getStatus() == OtpTmpStatusEnum.VERRIFIED) {
          Customer customer = customerDTOMapper.toCustomer(registDTO);
@@ -42,6 +50,17 @@
       }else {
          throw new UsernameNotFoundException("Otp record not found");
       }
      }
      
   }
   private String getCustomerAccount(CustomerRegisterDTO registDTO) {
      return registDTO.getContactType() == OtpLoginTypeEnum.EMAIL?registDTO.getEmail():registDTO.getPhone();
   }
   private boolean checkCustomerExist(CustomerRegisterDTO registDTO) {
      String account = getCustomerAccount(registDTO);
      Optional<Customer> customer = customerRepository.findOneByEmailEqualsOrPhoneEquals(account, account);
      return customer.isPresent();
   }
}