user_adaptor.go 2.8 KB
package adaptor

import (
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway/translator"
)

type UserAdaptor struct {
}

func (adaptor *UserAdaptor) ToParticipator(companyId int64, orgId int64, userId int64, aRoleName string) (interface{}, error) {
	userServiceGateway := service_gateway.NewHttplibUserServiceGateway()
	response, err := userServiceGateway.GetUser(companyId, orgId, userId)
	if err != nil {
		return map[string]interface{}{}, err
	}
	if userTranslator, err := translator.NewUserTranslator(); err != nil {
		return map[string]interface{}{}, err
	} else {
		switch aRoleName {
		case "Relevant": // 相关人
			relevant, err := userTranslator.ToRelevantFromRepresentation(response)
			if err != nil {
				return map[string]interface{}{}, err
			}
			return relevant, nil
		case "Referrer": // 推荐人
			referrer, err := userTranslator.ToReferrerFromRepresentation(response)
			if err != nil {
				return map[string]interface{}{}, err
			}
			return referrer, nil
		case "Salesman": // 业务员
			salesman, err := userTranslator.ToSalesmanFromRepresentation(response)
			if err != nil {
				return map[string]interface{}{}, nil
			}
			return salesman, nil
		case "Undertaker": // 承接人
			undertaker, err := userTranslator.ToUndertakerFromRepresentation(response)
			if err != nil {
				return map[string]interface{}{}, nil
			}
			return undertaker, nil
		case "Operator": // 操作人
			operator, err := userTranslator.ToOperatorFromRepresentation(response)
			if err != nil {
				return map[string]interface{}{}, nil
			}
			return operator, nil
		case "User": // 用户
			user, err := userTranslator.ToUserFromRepresentation(response)
			if err != nil {
				return map[string]interface{}{}, nil
			}
			return user, nil
		case "Visitor": // 游客
			visitor, err := userTranslator.ToVisitorFromRepresentation(response)
			if err != nil {
				return map[string]interface{}{}, nil
			}
			return visitor, nil
		}
	}
	return map[string]interface{}{}, nil
}

func (adaptor *UserAdaptor) ToVisitor(companyId int64, orgId int64, userBaseId int64) (interface{}, error) {
	userServiceGateway := service_gateway.NewHttplibUserServiceGateway()
	response, err := userServiceGateway.GetUserInfo(companyId, orgId, userBaseId)
	if err != nil {
		return map[string]interface{}{}, err
	}
	if userTranslator, err := translator.NewUserTranslator(); err != nil {
		return map[string]interface{}{}, err
	} else {
		visitor, err := userTranslator.ToVisitorFromRepresentation(response)
		if err != nil {
			return map[string]interface{}{}, nil
		}
		return visitor, nil
	}
}

func NewUserAdaptor() (*UserAdaptor, error) {
	return &UserAdaptor{}, nil
}