service.go 2.0 KB
package service

import (
	"github.com/linmadan/egglib-go/core/application"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/common/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/common/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_basic"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)

type CommonService struct {
}

func NewCommonService(options map[string]interface{}) *CommonService {
	return &CommonService{}
}

//GetDictionaryByCode 根据code获取字典数据
func (srv *CommonService) GetDictionaryByCode(getDictionaryQuery *query.GetDictionaryByCodeQuery) (interface{}, error) {
	creationBasicGateway := allied_creation_basic.NewHttplibAlliedCreationBasic(domain.Operator{})
	result, err := creationBasicGateway.GetDictionarysByCode(allied_creation_basic.ReqGetDictionaryByCode{
		DictCode: getDictionaryQuery.DictCode,
	})
	if err != nil {
		return nil, err
	}
	return result, nil
}

//CompanySignUp 公司注册
func (srv *CommonService) CompanySignUp(signUpCommand *command.CompanySignUpCommand) (interface{}, error) {
	if err := signUpCommand.ValidateCommand(); err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	//校验验证码
	creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
	_, err := creationUserGateway.AuthCompanySignUp(allied_creation_user.ReqAuthCompanySignUp{
		CompanyName:      signUpCommand.CompanyName,
		Contacts:         signUpCommand.Contacts,
		IndustryCategory: signUpCommand.IndustryCategory,
		Password:         signUpCommand.Password,
		Phone:            signUpCommand.Phone,
		Scale:            signUpCommand.Scale,
	})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	return signUpCommand, nil
}