allied-creation-user.go
1.9 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
package domainService
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/gateway/allied_creation_user"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/models"
)
type UserService struct {
internalUserService *allied_creation_user.HttpLibAlliedCreationUser
}
func (svr *UserService) User(id int) (*domain.User, error) {
rsp, err := svr.internalUserService.User(id)
if err != nil {
return nil, err
}
return svr.ToUser(rsp), nil
}
func (svr *UserService) Users(id []int) ([]*domain.User, error) {
rsp, err := svr.internalUserService.Users(id)
if err != nil {
return nil, err
}
result := make([]*domain.User, 0)
for i := range rsp {
result = append(result, svr.ToUser(rsp[i]))
}
return result, nil
}
func (svr *UserService) Organization(id int) (*domain.Org, error) {
rsp, err := svr.internalUserService.Organization(id)
if err != nil {
return nil, err
}
return svr.ToOrg(rsp), nil
}
func (svr *UserService) ToUser(from *models.User) *domain.User {
user := &domain.User{
UserId: from.UserId,
UserName: from.UserInfo.UserName,
EmployeeType: from.EmployeeType,
IcCardNumber: from.IcCardNumber,
Avatar: from.UserInfo.Avatar,
Phone: from.UserInfo.Phone,
}
if user.EmployeeType == 0 {
user.EmployeeType = 1 //默认正式员工
}
return user
}
func (svr *UserService) ToOrg(from *models.Organization) *domain.Org {
return &domain.Org{
OrgId: from.OrgId,
OrgName: from.OrgName,
}
}
//func(svr *UserService) ToOrg(from *models.Organization)*domain.Org{
//
//}
func NewUserService() *UserService {
return &UserService{
internalUserService: allied_creation_user.NewHttpLibAlliedCreationUser(constant.ALLIED_CREATION_USER_HOST),
}
}