pg_create_user_account_service.go
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package domainService
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/repository"
"time"
)
// PgCreateUserAccountService 创建用户账号服务
type PgCreateUserAccountService struct {
transactionContext *pgTransaction.TransactionContext
}
// CreateUserAccount 创建账号服务
//
// registerAccount 注册账号
// password 密码
// userInfo 用户信息
func (ptr *PgCreateUserAccountService) CreateUserAccount(registerAccount string, password string, userInfo *domain.UserInfo) (*domain.UserBase, error) {
userBaseRepository, err := repository.NewUserBaseRepository(ptr.transactionContext)
if err != nil {
return nil, err
}
if len(password) == 0 {
return nil, fmt.Errorf("密码不能为空")
}
userBase := &domain.UserBase{
UserInfo: userInfo,
Account: registerAccount,
Password: password,
Im: &domain.Im{},
Status: int(domain.UserStatusEnable),
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
if existsUserBase, e := userBaseRepository.FindOne(map[string]interface{}{"account": registerAccount}); e == nil && existsUserBase != nil {
return existsUserBase, nil
}
if userBase, err = userBaseRepository.Save(userBase); err != nil {
return nil, err
}
return userBase, nil
}
func NewPgCreateUserAccountService(transactionContext *pgTransaction.TransactionContext) (*PgCreateUserAccountService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &PgCreateUserAccountService{
transactionContext: transactionContext,
}, nil
}
}