service.go 3.5 KB
package service

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

type CreditAccountService struct{}

func NewCreditAccountService(option map[string]interface{}) CreditAccountService {
	return CreditAccountService{}
}

//ListCreditAccount返回账期结算列表
func (srv *CreditAccountService) ListCreditAccount(listQuery *query.ListCreditAccountQuery) (int64, interface{}, error) {
	creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(listQuery.Operator)
	result, err := creationCooperationGateway.CreditAccountsSearch(allied_creation_cooperation.ReqCreditAccountsSearch{
		PageNumber:            int64(listQuery.PageNumber),
		PageSize:              int64(listQuery.PageSize),
		CreditAccountOrderNum: listQuery.CreditAccountOrderNum,
		ParticipatorName:      listQuery.Participator,
		CompanyId:             listQuery.Operator.CompanyId,
	})
	if err != nil {
		return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	listData := []dto.CreditAccountItem{}
	for i := range result.Grid.List {
		item := dto.ToCreditAccountItem(&result.Grid.List[i], listQuery.Operator.OrgId)
		listData = append(listData, *item)
	}
	return int64(result.Grid.Total), listData, nil
}

//GetCreditAccount 返回账期结算详情
func (srv *CreditAccountService) GetCreditAccount(getQuery *query.GetCreditAccountQuery) (interface{}, error) {
	creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(getQuery.Operator)
	result, err := creationCooperationGateway.CreditAccountGet(allied_creation_cooperation.ReqCreditAccountGet{
		CreditAccountId: getQuery.CreditAccountId,
	})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	return dto.ToCreditAccountItem(&result.CreditAccount, getQuery.Operator.OrgId), nil
}

//PayCreditAccount 支付账期结算
func (srv *CreditAccountService) PayCreditAccount(payCommand *command.PayCreditAccountCommand) (interface{}, error) {
	creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(payCommand.Operator)
	_, err := creationCooperationGateway.CreditAccountsPay(allied_creation_cooperation.ReqCreditAccountsPay{
		CreditAccountId:           payCommand.CreditAccountId,
		ActuallyPaidAmount:        payCommand.ActuallyPaidAmount,
		Remarks:                   payCommand.Remarks,
		PaymentDocumentAttachment: payCommand.Attachment,
	})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	return payCommand, nil
}

//RemoveCreditAccount 删除账期结算
func (srv *CreditAccountService) RemoveCreditAccount(removeCommand *command.RemoveCreditAccountCommand) (interface{}, error) {
	creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(removeCommand.Operator)
	_, err := creationCooperationGateway.CreditAccountRemove(allied_creation_cooperation.ReqCreditAccountRemove{
		CreditAccountId: removeCommand.CreditAccountId,
	})
	if err != nil {
		return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	return removeCommand, nil
}