rest_user_service.go 3.2 KB
package domain_service

import (
	"encoding/json"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway/adaptor"
)

type UserService struct {
}

// ReferrerFrom 获取推荐人
func (service *UserService) ReferrerFrom(companyId int64, orgId int64, userId int64) (*domain.Referrer, error) {
	var returnData *domain.Referrer
	if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
		return nil, err
	} else {
		if referrer, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Referrer"); err != nil {
			return nil, err
		} else {
			err := json.Unmarshal(referrer.([]byte), returnData)
			if err != nil {
				return nil, err
			}
			return returnData, nil
		}
	}
}

// UndertakerFrom 获取承接人
func (service *UserService) UndertakerFrom(companyId int64, orgId int64, userId int64) (*domain.Undertaker, error) {
	var returnData *domain.Undertaker
	if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
		return nil, err
	} else {
		if referrer, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Undertaker"); err != nil {
			return nil, err
		} else {
			err := json.Unmarshal(referrer.([]byte), returnData)
			if err != nil {
				return nil, err
			}
			return returnData, nil
		}
	}
}

// RelevantFrom 获取相关人
func (service *UserService) RelevantFrom(companyId int64, orgId int64, userId int64) (*domain.Relevant, error) {
	var returnData *domain.Relevant
	if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
		return nil, err
	} else {
		if referrer, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Relevant"); err != nil {
			return nil, err
		} else {
			err := json.Unmarshal(referrer.([]byte), returnData)
			if err != nil {
				return nil, err
			}
			return returnData, nil
		}
	}
}

// SalesmanFrom 获取业务员
func (service *UserService) SalesmanFrom(companyId int64, orgId int64, userId int64) (*domain.Salesman, error) {
	var returnData *domain.Salesman
	if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
		return nil, err
	} else {
		if referrer, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Salesman"); err != nil {
			return nil, err
		} else {
			err := json.Unmarshal(referrer.([]byte), returnData)
			if err != nil {
				return nil, err
			}
			return returnData, nil
		}
	}
}

// OperatorFrom 获取操作人
func (service *UserService) OperatorFrom(companyId int64, orgId int64, userId int64) (*domain.User, error) {
	var returnData *domain.User
	if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
		return nil, err
	} else {
		if referrer, err := userAdaptor.ToParticipator(companyId, orgId, userId, "Operator"); err != nil {
			return nil, err
		} else {
			err := json.Unmarshal(referrer.([]byte), returnData)
			if err != nil {
				return nil, err
			}
			return returnData, nil
		}
	}
}

func (service *UserService) UserInMenu(companyId int64, orgId int64, userId int64, code string) (bool, error) {
	return false, nil
}

func (service *UserService) UserInOrganization(companyId int64, orgId int64, userId int64) (bool, error) {
	return false, nil
}

func NewUserService() (*UserService, error) {
	return &UserService{}, nil
}