From 24efeb25a043698b6a1d5d5b38266b0343ec85fc Mon Sep 17 00:00:00 2001 From: Nick Zeng Date: Wed, 26 Nov 2025 13:41:15 +0800 Subject: [PATCH] update --- backend/app/Model/Platform.php | 29 ++++++ backend/app/Platform/EntityParse.php | 95 +++++++++++++++++++ backend/app/Platform/EntityParseInterface.php | 24 +++++ backend/composer.json | 2 +- 4 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 backend/app/Model/Platform.php create mode 100644 backend/app/Platform/EntityParse.php create mode 100644 backend/app/Platform/EntityParseInterface.php diff --git a/backend/app/Model/Platform.php b/backend/app/Model/Platform.php new file mode 100644 index 0000000..9ae9daa --- /dev/null +++ b/backend/app/Model/Platform.php @@ -0,0 +1,29 @@ +platform = $this->platformScopeMatch($this->message); + $this->company = $this->companyScopeMatch($this->message); + $this->store = $this->storeScopeMatch($this->message); + + if(!$this->platform instanceof Platform || !isset($this->platform->id)){ + throw new InvalidArgumentException('platform is undefined'); + } + + if(!$this->company instanceof Platform || !isset($this->company->id)){ + throw new InvalidArgumentException('company is undefined'); + } + + if(!$this->store instanceof Platform || !isset($this->store->id)){ + throw new InvalidArgumentException('store is undefined'); + } + } + + public function companyScopeMatch(ConsumerMessageInterface $message): Company + { + // TODO: Implement companyScopeMatch() method. + } + + public function platformScopeMatch(ConsumerMessageInterface $message): Platform + { + $platformName = Str::of($message->getExchange())->before('.')->ucfirst()->toString(); + + $platform = Platform::where('name','=',$platformName)->first(); + + // 确保实例化的对象是 Entity 类型 + if (!$platform) { + throw new InvalidArgumentException("PLatform name {$platformName} not exist!"); + } + + return $platform; + + } + + public function storeScopeMatch(ConsumerMessageInterface $message): Store + { + // TODO: Implement storeScopeMatch() method. + } + + public function entityMatch(ConsumerMessageInterface $message): Entity + { + // 从路由键中提取实体名称,例如 'order.tmall' -> 'Order' + $entityName = Str::of($message->getRoutingKey())->before('.')->ucfirst()->toString(); + + // 构建完整的类名 + $entityClass = "App\\Model\\{$entityName}"; + + // 检查类是否存在 + if (!class_exists($entityClass)) { + throw new InvalidArgumentException("Entity class {$entityClass} does not exist"); + } + + // 实例化实体对象 + $entity = new $entityClass(); + + // 确保实例化的对象是 Entity 类型 + if (!$entity instanceof Entity) { + throw new InvalidArgumentException("Class {$entityClass} is not an instance of Entity"); + } + + return $entity; + } + + public function entityMap(array $data, Entity $entity): Entity + { + // TODO: Implement entityMap() method. + // entityMap 方法应该返回一个 属性已被更新设置的数据模型,而非默认空状态的 Entity + + return $this->entityMatch($this->message); + } +} \ No newline at end of file diff --git a/backend/app/Platform/EntityParseInterface.php b/backend/app/Platform/EntityParseInterface.php new file mode 100644 index 0000000..631beca --- /dev/null +++ b/backend/app/Platform/EntityParseInterface.php @@ -0,0 +1,24 @@ +=8.1", - "composer": "*", + "composer": "^2.7", "96qbhy/hyperf-auth": "^3.1", "casbin/casbin": "^4.0", "hyperf/amqp": "^3.1",