service.go
3.2 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package service
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/command"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/serviceGateway"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
type UsersService struct {
}
func NewUsersService(option map[string]interface{}) *UsersService {
newUsersService := new(UsersService)
return newUsersService
}
func (service UsersService) UserLoginBySecretKey(cmd command.LoginBySecretKeyCommand) (interface{}, error) {
var err error
if err = cmd.ValidateCommand(); err != nil {
return nil, err
}
//向统一用户中心确认密钥信息并获取用户数据
ucenterService := serviceGateway.NewMmmUserCenterServiceGateway()
loginResp, err := ucenterService.RequestUCenterLoginBySecret(cmd.Secret)
if err != nil {
e := fmt.Sprintf("通过密钥(secret=%s)从统一用户中心获取数据失败:%s", cmd.Secret, err.Error())
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var (
companyRespository domain.CompanyRepository
userRespository domain.UsersRepository
companyData domain.Company
usersData domain.Users
)
if companyRespository, err = factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if userRespository, err = factory.CreateUsersRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
//检索本系统的公司数据判断公司权限
companyData, err = companyRespository.FindOne(map[string]interface{}{
"Id": loginResp.Data.Muid,
})
if err != nil {
e := fmt.Sprintf("获取公司(id=%d)数据失败:%s", loginResp.Data.Muid, err.Error())
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
if !companyData.EnableIsOk() {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "该公司没有操作权限")
}
//检索本系统的用户数据
usersData, err = userRespository.FindOne(map[string]interface{}{
"OpenId": loginResp.Data.Id,
"CompanyId": companyData.Id,
})
if err != nil {
e := fmt.Sprintf("获取用户(OpenId=%d;CompanyId=%d)数据失败:%s",
loginResp.Data.Id, companyData.Id, err.Error())
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
//确认用户权限
if !usersData.IsUsable() {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "用户被禁用")
}
err = transactionContext.CommitTransaction()
//生成token
return nil, nil
}
//GetAdminpPofile 登录后获取用户的权限配置数据
func (service UsersService) GetAdminpPofile() (interface{}, error) {
return nil, nil
}
//ValidateAdminpPermission 校验用户的操作权限
func (service UsersService) ValidateAdminpPermission() (interface{}, error) {
return nil, nil
}