base_controller.go 1.9 KB
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())
	}
}