service.go 1.6 KB
package service

import (
	"github.com/linmadan/egglib-go/core/application"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/org/dto"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/org/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)

type OrgService struct {
}

//DepartmentsUsers 部门用户列表
func (srv OrgService) DepartmentsUsers(departmentsUsersQuery *query.DepartmentsUsersQuery) (interface{}, error) {
	creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
		departmentsUsersQuery.Operator)
	orgs, err := creationUserGateway.OrgGetSubDepartment(allied_creation_user.ReqOrgGetSubDepartment{
		OrgId: departmentsUsersQuery.Operator.OrgId,
	})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}

	users, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
		//Offset:         0,
		//Limit:          999,
		CompanyId:      departmentsUsersQuery.Operator.CompanyId,
		OrganizationId: departmentsUsersQuery.Operator.OrgId,
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	departmentUsersDto := &dto.DepartmentUsersDto{}
	if err := departmentUsersDto.LoadDto(departmentsUsersQuery.Type, orgs, users); err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	return departmentUsersDto, nil
}

func NewOrgService(options map[string]interface{}) *OrgService {
	newOrgService := &OrgService{}
	return newOrgService
}