export.go 8.2 KB
package service

import (
	"fmt"

	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_manufacture"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/cost_structured"

	"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{SourceData: result.Users, SelectedField: companyUserListQuery.SelectedField}, nil
}

// ExportCooperationUser 导出共创用户信息列表
func (srv ExcelDataService) ExportProducts(cmd *query.SearchProductQuery) (ExportProductsData, error) {
	creationUserGateway := allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(cmd.Operator)
	result, err := creationUserGateway.SearchProduct(allied_creation_manufacture.SearchProductRequest{
		ProductName:     cmd.ProductName,
		ProductCategory: cmd.ProductCategory,
	})
	if err != nil {
		return ExportProductsData{}, fmt.Errorf("获取企业用户数据失败:%w", err)
	}
	return ExportProductsData{SourceData: result.Grid.List, SelectedField: cmd.SelectedField}, nil
}

// ExportEmployeeProductive 导出员工产能
func (srv ExcelDataService) ExportEmployeeProductive(cmd *query.ManufactureEmployeeProductiveQuery) (ExportEmployeeProductiveData, error) {
	creationUserGateway := allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(cmd.Operator)
	result, err := creationUserGateway.SearchEmployeeProductive(allied_creation_manufacture.SearchEmployeeProductiveRequest{
		WorkshopName: cmd.WorkshopName,
		LineName:     cmd.LineName,
		SectionName:  cmd.SectionName,
		UserName:     cmd.UserName,
		EmployeeType: cmd.EmployeeType,
		BeginTime:    cmd.BeginTime,
		EndTime:      cmd.EndTime,
	})
	if err != nil {
		return ExportEmployeeProductiveData{}, fmt.Errorf("获取员工产能数据失败:%w", err)
	}
	return ExportEmployeeProductiveData{SourceData: result.Grid.List, SelectedField: cmd.SelectedField}, nil
}

// ExportEmployeeProductive 导出车间产能
func (srv ExcelDataService) ExportWorkshopProductive(cmd *query.ManufactureWorkshopProductiveQuery) (ExportWorkshopProductiveData, error) {
	creationUserGateway := allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(cmd.Operator)
	result, err := creationUserGateway.SearchWorkshopProductive(allied_creation_manufacture.SearchWorkshopProductiveRequest{
		SectionName:     cmd.SectionName,
		PlanProductName: cmd.PlanProductName,
		BeginTime:       cmd.BeginTime,
		EndTime:         cmd.EndTime,
	})
	if err != nil {
		return ExportWorkshopProductiveData{}, fmt.Errorf("获取员工产能数据失败:%w", err)
	}
	return ExportWorkshopProductiveData{SourceData: result.Grid.List, SelectedField: cmd.SelectedField}, nil
}

// ExportSecondLevelRecord 二级废品
func (srv ExcelDataService) ExportSecondLevelRecord(cmd *query.ManufactureSecondLevelRecordQuery) (ExportSecondLevelData, error) {
	creationUserGateway := allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(cmd.Operator)
	result, err := creationUserGateway.SearchSecondLevelRecord(allied_creation_manufacture.SearchSecondLevelRecordRequest{
		WorkshopName: cmd.WorkshopName,
		BatchNumber:  cmd.BatchNumber,
		UserName:     cmd.UserName,
		LineName:     cmd.LineName,
		SectionName:  cmd.SectionName,
		EmployeeType: cmd.EmployeeType,
		BeginTime:    cmd.BeginTime,
		EndTime:      cmd.EndTime,
	})
	if err != nil {
		return ExportSecondLevelData{}, fmt.Errorf("获取二级废品数据失败:%w", err)
	}
	return ExportSecondLevelData{SourceData: result.Grid.List, SelectedField: cmd.SelectedField}, nil
}

// ExportEmployeeAttendanceStatics 导出员工工时
func (srv ExcelDataService) ExportEmployeeAttendanceStatics(cmd *query.ManufactureExportEmployeeAttendanceStaticsQuery) (ExportEmployeeAttendanceStaticsData, error) {
	creationUserGateway := allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(cmd.Operator)
	result, err := creationUserGateway.SearchEmployeeAttendanceStatics(*cmd.SearchEmployeeAttendanceStaticsRequest)
	if err != nil {
		return ExportEmployeeAttendanceStaticsData{}, fmt.Errorf("获取员工工时数据失败:%w", err)
	}
	return ExportEmployeeAttendanceStaticsData{SourceData: result.Grid.List, SelectedField: cmd.SelectedField}, nil
}

// ExportWorkshopAttendanceStatics 导出车间工时
func (srv ExcelDataService) ExportWorkshopAttendanceStatics(cmd *query.ManufactureExportWorkshopAttendanceStaticsQuery) (ExportWorkshopAttendanceStaticsData, error) {
	creationUserGateway := allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(cmd.Operator)
	result, err := creationUserGateway.SearchWorkshopWorkTimeStatics(*cmd.SearchWorkshopWorkTimeStaticsRequest)
	if err != nil {
		return ExportWorkshopAttendanceStaticsData{}, fmt.Errorf("获取车间工时数据失败:%w", err)
	}
	return ExportWorkshopAttendanceStaticsData{SourceData: result.Grid.List, SelectedField: cmd.SelectedField}, nil
}

// ExportDailyFillingAbnormalLog 导出每日 填报异常日志记录
func (srv ExcelDataService) ExportDailyFillingAbnormalLog(cmd *query.CostDailyFillingAbnormalLogQuery) (ExportDailyFillingAbnormalLog, error) {
	creationUserGateway := cost_structured.NewHttpLibCostStructured(cmd.Operator)
	cmd.PageNumber = 1
	cmd.PageSize = 10000
	result, err := creationUserGateway.SearchDailyFillingAbnormalLog(*cmd.SearchDailyFillingAbnormalLogRequest)
	if err != nil {
		return ExportDailyFillingAbnormalLog{}, fmt.Errorf("获取每日填报异常日志记录数据失败:%w", err)
	}
	return ExportDailyFillingAbnormalLog{SourceData: result.Grid.List, SelectedField: cmd.SelectedField}, nil
}

// ExportRewardSummary 导出功过奖惩明细
func (srv ExcelDataService) ExportRewardSummary(cmd *query.ManufactureExportRewardSummaryQuery) (ExportRewardSummaryData, error) {
	creationUserGateway := allied_creation_manufacture.NewHttpLibAlliedCreationManufacture(cmd.Operator)
	cmd.PageNumber = 1
	cmd.PageSize = 10000
	result, err := creationUserGateway.SearchRewardSummary(*cmd.SearchRewardSummaryRequest)
	if err != nil {
		return ExportRewardSummaryData{}, fmt.Errorf("获取功过奖惩明细数据失败:%w", err)
	}
	return ExportRewardSummaryData{SourceData: result.Grid.List}, nil
}