service.go 2.4 KB
package service

import (
	"github.com/linmadan/egglib-go/core/application"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/user/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/user/dto"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/user/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_user"
)

type UserService struct {
}

// 创建菜单服务
func (userService *UserService) SearchUser(cmd *query.ListUserQuery) (int64, interface{}, error) {
	creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(cmd.Operator)
	result, err := creationUserGateway.UserBaseSearch(allied_creation_user.ReqUserBaseSearch{
		Offset:         (cmd.PageNumber - 1) * cmd.PageSize,
		Limit:          cmd.PageSize,
		UserName:       cmd.UserName,
		OrgName:        cmd.OrgName,
		FetchOrgBelong: true,
	})
	if err != nil {
		return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	var users = make([]dto.UserBaseDto, 0)
	for i := range result.Users {
		item := &dto.UserBaseDto{}
		item.LoadDto(result.Users[i])
		users = append(users, *item)
	}
	return result.Count, users, nil
}

func (userService *UserService) EnableUser(cmd *command.EnableUserCommand) (interface{}, error) {
	creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(cmd.Operator)
	_, err := creationUserGateway.EnableUserBase(allied_creation_user.ReqEnableUserBase{
		UserBaseIds:  []int64{cmd.UserBaseId},
		EnableStatus: cmd.EnableStatus,
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	return struct{}{}, nil
}

func (userService *UserService) ResetPassword(cmd *command.ResetPasswordCommand) (interface{}, error) {
	creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(cmd.Operator)
	_, err := creationUserGateway.AuthResetPassword(allied_creation_user.ReqAuthResetPassword{
		Phone:    cmd.Account,
		Password: domain.DefaultPassword, //TL123456!
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	return struct{}{}, nil
}

func NewUserService(options map[string]interface{}) *UserService {
	newUserService := &UserService{}
	return newUserService
}