export.go 2.2 KB
package service

import (
	"fmt"

	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/excelData/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"
)

// ExportCompanyUser 导出公司用户信息列表
func (srv ExcelDataService) ExportCompanyUser(companyUserListQuery *query.CompanyUserListQuery) (ExportCompanyUserData, error) {
	creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)
	result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
		Limit:          10000,
		CompanyId:      companyUserListQuery.Operator.CompanyId,
		OrganizationId: 0,
		DepartmentId:   0,
		UserName:       companyUserListQuery.UserName,
		DepName:        companyUserListQuery.DepartmentName,
		Phone:          "",
		UserType:       domain.UserTypeEmployee,
		InOrgIds:       companyUserListQuery.Operator.OrgIds,
		PullRealTime:   true,
	})
	if err != nil {
		return ExportCompanyUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
	}
	return ExportCompanyUserData{
		SourceData:    result.Users,
		SelectedField: companyUserListQuery.SelectedField,
	}, nil
}

// ExportCooperationUser 导出共创用户信息列表
func (srv ExcelDataService) ExportCooperationUser(companyUserListQuery *query.CooperationUserListQuery) (ExportCooperationUserData, error) {
	creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(companyUserListQuery.Operator)
	result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
		Limit:              10000,
		CompanyId:          companyUserListQuery.Operator.CompanyId,
		OrganizationId:     0,
		DepartmentId:       0,
		UserName:           companyUserListQuery.UserName,
		CooperationCompany: companyUserListQuery.CooperationCompany,
		Phone:              "",
		UserType:           domain.UserTypeCooperation,
		InOrgIds:           companyUserListQuery.Operator.OrgIds,
	})
	if err != nil {
		return ExportCooperationUserData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
	}
	return ExportCooperationUserData(result.Users), nil
}