baseController.go 1.1 KB
package controllers

import (
	"log"
	"strconv"

	"github.com/linmadan/egglib-go/web/beego"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
)

type baseController struct {
	beego.BaseController
}

func (controller *baseController) GetUserId() int64 {
	str := controller.Ctx.Input.Header("userId")
	userId, _ := strconv.Atoi(str)
	return int64(userId)
}

func (controller *baseController) GetCompanyId() int64 {
	str := controller.Ctx.Input.Header("companyId")
	companyId, _ := strconv.Atoi(str)
	log.Println("============>companyId", str)
	return int64(companyId)
}

func (controller *baseController) GetUserBaseId() int64 {
	str := controller.Ctx.Input.Header("userBaseId")
	userBaseId, _ := strconv.Atoi(str)
	return int64(userBaseId)
}

func (controller *baseController) GetOrgId() int64 {
	str := controller.Ctx.Input.Header("orgId")
	orgId, _ := strconv.Atoi(str)
	return int64(orgId)
}

func (controller *baseController) GetOperator() domain.Operator {
	return domain.Operator{
		UserId:     controller.GetUserId(),
		CompanyId:  controller.GetCompanyId(),
		OrgId:      controller.GetOrgId(),
		UserBaseId: controller.GetUserBaseId(),
	}
}