diff --git a/internal/bootstrap/worker_services.go b/internal/bootstrap/worker_services.go index dbdf7fe2..8e202630 100644 --- a/internal/bootstrap/worker_services.go +++ b/internal/bootstrap/worker_services.go @@ -4,6 +4,7 @@ import ( assetAutoRenewalApp "github.com/break/junhong_cmp_fiber/internal/application/assetautorenewal" cardObservationApp "github.com/break/junhong_cmp_fiber/internal/application/cardobservation" carrierThresholdApp "github.com/break/junhong_cmp_fiber/internal/application/carrierthreshold" + employeecollectionApp "github.com/break/junhong_cmp_fiber/internal/application/employeecollection" walletapp "github.com/break/junhong_cmp_fiber/internal/application/wallet" assetAutoRenewalInfra "github.com/break/junhong_cmp_fiber/internal/infrastructure/assetautorenewal" auditInfra "github.com/break/junhong_cmp_fiber/internal/infrastructure/audit" @@ -154,6 +155,8 @@ func initWorkerServices(stores *queue.WorkerStores, deps *WorkerDependencies) *q stores.PersonalCustomer, stores.PersonalCustomerPhone, ) + // 批量订购线下支付建单需在订单事务内生成员工代收款账单,与 API 进程保持一致。 + orderService.SetEmployeeCollectionBillCreation(employeecollectionApp.NewBillCreationService(auditWriter)) orderService.SetLifecycleAudit(auditWriter) orderService.SetPaymentIntegrationLog(integrationlog.NewRepository(deps.DB)) walletOutbox := outbox.NewRepository() diff --git a/internal/bootstrap/worker_services_test.go b/internal/bootstrap/worker_services_test.go new file mode 100644 index 00000000..98a42bfd --- /dev/null +++ b/internal/bootstrap/worker_services_test.go @@ -0,0 +1,28 @@ +package bootstrap + +import ( + "reflect" + "testing" + + orderSvc "github.com/break/junhong_cmp_fiber/internal/service/order" + "github.com/break/junhong_cmp_fiber/pkg/queue" + "go.uber.org/zap" +) + +// 批量订购线下支付在 Worker 内建单,订单服务必须注入员工代收款建账能力, +// 否则每行都会以“员工代收款建账能力未配置”失败。 +func TestInitWorkerServices_OrderServiceHasEmployeeCollectionBillCreation(t *testing.T) { + services := initWorkerServices(&queue.WorkerStores{}, &WorkerDependencies{Logger: zap.NewNop()}) + + svc, ok := services.AssetPackageOrderCreator.(*orderSvc.Service) + if !ok { + t.Fatalf("AssetPackageOrderCreator 类型为 %T,期望 *order.Service", services.AssetPackageOrderCreator) + } + billCreation := reflect.ValueOf(svc).Elem().FieldByName("billCreation") + if !billCreation.IsValid() { + t.Fatal("order.Service 缺少 billCreation 字段,请同步更新本测试") + } + if billCreation.IsNil() { + t.Fatal("Worker 订单服务未注入员工代收款建账能力") + } +}