cooperation_application.go 4.7 KB
package service

import (
	"github.com/linmadan/egglib-go/core/application"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/cooperationApplication/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/cooperationApplication/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
)

// 共创申请管理
type CooperationApplicationService struct {
}

// 审核共创申请
func (cooperationApplicationService *CooperationApplicationService) AuditCooperationApplication(
	auditCooperationApplicationCommand *command.AuditCooperationApplicationCommand) (interface{}, error) {
	if err := auditCooperationApplicationCommand.ValidateCommand(); err != nil {
		return nil, application.ThrowError(application.ARG_ERROR, err.Error())
	}
	creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
		auditCooperationApplicationCommand.Operator)

	_, err := creationCooperationGateway.CooperationApplicationsBatchApproval(allied_creation_cooperation.ReqCooperationApplicationBatchApproval{
		CooperationApplicationIds:         auditCooperationApplicationCommand.CooperationApplicationId,
		CooperationApplicationDescription: auditCooperationApplicationCommand.CooperationApplicationVerifyDescription,
		Action:                            auditCooperationApplicationCommand.CooperationApplicationStatus,
		Code:                              "BatchApproval",
	})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}

	return auditCooperationApplicationCommand, nil
}

// 返回共创申请管理
func (cooperationApplicationService *CooperationApplicationService) GetCooperationApplication(getCooperationApplicationQuery *query.GetCooperationApplicationQuery) (interface{}, error) {
	if err := getCooperationApplicationQuery.ValidateQuery(); err != nil {
		return nil, application.ThrowError(application.ARG_ERROR, err.Error())
	}
	creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(getCooperationApplicationQuery.Operator)
	applicationResult, err := creationCooperationGateway.CooperationApplicationGet(allied_creation_cooperation.ReqCooperationApplicationGet{
		CooperationApplicationId: getCooperationApplicationQuery.CooperationApplicationId,
	})
	//if err != nil {
	//	return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	//}
	//objectResult, err := creationCooperationGateway.CooperationProjectGet(allied_creation_cooperation.ReqCooperationProjectGet{
	//	CooperationProjectId: applicationResult.CooperationProject.CooperationProjectID,
	//})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	//return dto.ToCooperationApplicationInfo(&applicationResult.CooperationApplication, &objectResult.CooperationProject), nil
	return applicationResult, nil
}

// 返回共创申请管理列表
func (cooperationApplicationService *CooperationApplicationService) ListCooperationApplication(
	listCooperationApplicationQuery *query.ListCooperationApplicationQuery) (int64, interface{}, error) {
	if err := listCooperationApplicationQuery.ValidateQuery(); err != nil {
		return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
	}
	cooperationApplicationStatus := 0
	if listCooperationApplicationQuery.WaitAuditOnly {
		cooperationApplicationStatus = 1
	}

	creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(listCooperationApplicationQuery.Operator)
	result, err := creationCooperationGateway.CooperationApplicationsSearch(allied_creation_cooperation.ReqCooperationApplicationSearch{
		ApplicantName:                listCooperationApplicationQuery.ApplicantName,
		CooperationApplicationStatus: cooperationApplicationStatus,
		CooperationProjectName:       listCooperationApplicationQuery.ProjectName,
		PageNumber:                   listCooperationApplicationQuery.PageNumber,
		PageSize:                     listCooperationApplicationQuery.PageSize,
		CompanyId:                    int(listCooperationApplicationQuery.Operator.CompanyId),
	})
	if err != nil {
		return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	//var dataList []dto.CooperationApplicationItem
	//for i := range result.Grid.List {
	//	item := dto.ToCooperationApplicationItem(&result.Grid.List[i])
	//	dataList = append(dataList, *item)
	//}
	return int64(result.Grid.Total), result.Grid.List, nil
}

func NewCooperationApplicationService(options map[string]interface{}) *CooperationApplicationService {
	newCooperationApplicationService := &CooperationApplicationService{}
	return newCooperationApplicationService
}