baseController.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
73
74
75
76
77
78
79
80
81
package controllers
import (
"github.com/linmadan/egglib-go/utils/json"
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
)
type baseController struct {
beego.BaseController
}
func (controller *baseController) returnPageListData(count int64, data interface{}, err error, pageNumber int) {
dataMap := map[string]interface{}{
"grid": map[string]interface{}{
"total": count,
//"pageNumber": pageNumber,
"list": data,
},
}
controller.Response(dataMap, err)
}
func (controller *baseController) returnListData(count int64, data interface{}, err error) {
dataMap := map[string]interface{}{
"total": count,
//"pageNumber": pageNumber,
"list": data,
}
controller.Response(dataMap, err)
}
func (controller *baseController) GetUserId() int64 {
return 1
}
func (controller *baseController) GetCompanyId() int64 {
return 1
}
func (controller *baseController) GetUserBaseId() int64 {
return 1
}
func (controller *baseController) GetOrgId() int64 {
return 1
}
func (controller *baseController) GetOperator() domain.Operator {
token := controller.Ctx.Input.Header("X-Mmm-Accesstoken")
loginToken := &domain.LoginToken{}
err := loginToken.ParseToken(token)
if err != nil {
log.Logger.Error(err.Error())
}
op := domain.Operator{
UserId: loginToken.UserId,
CompanyId: loginToken.CompanyId,
OrgId: loginToken.OrgId,
UserBaseId: loginToken.UserBaseId,
Phone: loginToken.Account,
Token: token,
}
// TODO:测试数据后期删除
if op.UserId == 0 {
op.UserId = 9
op.CompanyId = 23
op.OrgId = 45
op.UserBaseId = 5
}
// TODO:打印测试日志
log.Logger.Debug("operator " + json.MarshalToString(op))
return op
}
func Must(err error) {
if err != nil {
log.Logger.Error(err.Error())
}
}