controller.go
2.1 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
package controllers
import (
"github.com/beego/beego/v2/server/web/context"
"github.com/linmadan/egglib-go/web/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"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/log"
"strconv"
"strings"
)
func ResponseGrid(c beego.BaseController, total int64, data interface{}, err error) {
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(c.Ctx, err)
} else {
response = ResponseGridData(c.Ctx, total, data)
}
c.Data["json"] = response
c.ServeJSON()
}
func ResponseGridData(ctx *context.Context, total int64, data interface{}) utils.JsonResponse {
jsonResponse := utils.JsonResponse{}
jsonResponse["code"] = 0
jsonResponse["msg"] = "ok"
jsonResponse["data"] = map[string]interface{}{"grid": map[string]interface{}{
"total": total,
"list": data,
}}
ctx.Input.SetData("outputData", jsonResponse)
return jsonResponse
}
func Must(err error) {
if err != nil {
log.Logger.Error(err.Error())
}
}
// ParseOperateInfo 从头部解析操作对象信息
func ParseOperateInfo(c beego.BaseController) *domain.OperateInfo {
opt := &domain.OperateInfo{}
opt.UserId = header(c, constant.HeaderUserId)
opt.CompanyId = header(c, constant.HeaderCompanyId)
opt.OrgId = header(c, constant.HeaderOrgId)
orgIdList := c.Ctx.Input.Header(constant.HeaderOrgIds)
splitOrgIdList := strings.Split(orgIdList, constant.CUSTOMER_ACCOUNT_DELIMITER)
for i := range splitOrgIdList {
orgId, _ := strconv.Atoi(splitOrgIdList[i])
if orgId == 0 {
continue
}
opt.OrgIds = append(opt.OrgIds, orgId)
}
// 默认公司组织
//if opt.CompanyId == 0 {
// opt.CompanyId = 1
//}
//if opt.OrgId == 0 {
// opt.OrgId = 1
//}
return opt
}
func header(c beego.BaseController, key string) int {
if len(c.Ctx.Input.Header(key)) == 0 {
return 0
}
res, err := strconv.Atoi(c.Ctx.Input.Header(key))
if err != nil {
log.Logger.Error(err.Error())
return 0
}
return res
}