pg_sign_up_person_service.go
2.5 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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"
)
// PgSignUpPersonService 个人注册服务
type PgSignUpPersonService struct {
transactionContext *pgTransaction.TransactionContext
}
// SignUp 个人注册服务
//
// registerPhone 注册人手机号
// password 密码
// companyInfo 注册公司信息
// userInfo 用户信息
func (ptr *PgSignUpPersonService) SignUp(account string, password string, userInfo *domain.UserInfo) (*domain.UserBase, error) {
var err error
// 前置验证
if len(account) == 0 || len(password) == 0 {
return nil, fmt.Errorf("账号密码不能为空")
}
var existsUser *domain.User
var userBase *domain.UserBase
createUserAccountService, _ := NewPgCreateUserAccountService(ptr.transactionContext)
if userBase, err = createUserAccountService.CreateUserAccount(account, password, userInfo); err != nil {
return nil, err
}
userBaseRepository, _ := repository.NewUserRepository(ptr.transactionContext)
if existsUser, err = userBaseRepository.FindOne(map[string]interface{}{"userBaseId": userBase.UserBaseId, "userType": domain.UserTypeVisitor}); err == nil && existsUser != nil {
return nil, fmt.Errorf("账号已存在")
}
// 4.创建用户、分配角色、关联组织、账号
var user *domain.User = &domain.User{
CompanyId: 0,
UserType: domain.UserTypeVisitor,
UserCode: "",
OrganizationId: 0,
DepartmentId: 0,
UserOrg: []*domain.Org{},
UserRole: []*domain.Role{},
FavoriteMenus: []string{},
CooperationInfo: &domain.CooperationInfo{},
EnableStatus: int(domain.UserStatusEnable),
UserInfo: userInfo,
Ext: &domain.Ext{
UserName: userInfo.UserName,
Phone: userInfo.Phone,
},
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
createUserService, _ := NewPgCreateUserService(ptr.transactionContext)
if user, err = createUserService.CreateUser(nil, user, password); err != nil {
return nil, err
}
return userBase, nil
}
func NewPgSignUpPersonService(transactionContext *pgTransaction.TransactionContext) (*PgSignUpPersonService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &PgSignUpPersonService{
transactionContext: transactionContext,
}, nil
}
}