content: package com.amos.think.user.command;
  
  import com.amos.think.common.exception.ThinkBizException;
  import com.amos.think.domain.gateway.UserGateway;
  import com.amos.think.domain.user.UserEntity;
  import com.amos.think.dto.UserRegisterCmd;
  import com.amos.think.dto.data.ErrorCode;
  import com.amos.think.dto.data.UserVO;
  import com.amos.think.user.assembler.UserAssembler;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Component;
  
  /**
   * UserAddCmdExe
   *
   * @author <a href="mailto:daoyuan0626@gmail.com">amos.wang</a>
   * @date 2021/1/10
   */
  @Component
  public class UserRegisterCmdExe {
  
      @Autowired
      private UserGateway userGateway;
  
      public UserVO execute(UserRegisterCmd cmd) {
          // check 用户名是否重复
          if (userGateway.checkByUsername(null, cmd.getUsername())) {
              throw new ThinkBizException(ErrorCode.B_USER_USERNAME_REPEAT);
          }
  
          UserEntity userEntity = userGateway.save(UserAssembler.toEntity(cmd));
  
          return UserAssembler.toValueObject(userEntity);
      }
  
  }
  