Files

129 lines
2.6 KiB
PHP
Raw Permalink Normal View History

2025-11-27 13:40:58 +08:00
<?php
declare(strict_types=1);
namespace App\Entity\Parse;
use App\Model\Company;
use App\Model\Platform;
use App\Model\Store;
use App\Model\Model as Entity;
2025-11-27 15:03:25 +08:00
use Hyperf\Collection\LazyCollection;
2026-01-30 13:32:49 +08:00
use PhpAmqpLib\Message\AMQPMessage;
2025-11-27 13:40:58 +08:00
/**
* EntityParseInterface 接口
*
* 定义消息解析器的标准接口
*/
interface EntityParseInterface
{
2025-11-27 15:03:25 +08:00
/**
* 消息数据验证
*
* 验证消息数据是否包含必需字段
*
* @param array $data
* @return bool
*/
public function messageValidate(array $data): bool;
2025-11-27 13:40:58 +08:00
/**
* 公司作用域匹配
*
2025-11-27 15:03:25 +08:00
* @param array $metadata
2025-11-27 13:40:58 +08:00
* @return Company
*/
2025-11-27 15:03:25 +08:00
public function companyScopeMatch(array $metadata): Company;
2025-11-27 13:40:58 +08:00
/**
* 平台作用域匹配
*
2025-11-27 15:03:25 +08:00
* @param array $metadata
2025-11-27 13:40:58 +08:00
* @return Platform
*/
2025-11-27 15:03:25 +08:00
public function platformScopeMatch(array $metadata): Platform;
2025-11-27 13:40:58 +08:00
/**
* 店铺作用域匹配
*
2025-11-27 15:03:25 +08:00
* @param array $metadata
2025-11-27 13:40:58 +08:00
* @return Store
*/
2025-11-27 15:03:25 +08:00
public function storeScopeMatch(array $metadata): Store;
2025-11-27 13:40:58 +08:00
/**
* 实体类型匹配
*
2025-11-27 15:03:25 +08:00
* 根据 metadata 返回实体模板实例
*
* @param array $metadata
2025-11-27 13:40:58 +08:00
* @return Entity
*/
2025-11-27 15:03:25 +08:00
public function entityMatch(array $metadata): Entity;
2025-11-27 13:40:58 +08:00
/**
* 实体数据映射
*
2025-11-27 15:03:25 +08:00
* 将原始数据转换为可填充到 Model 的数据集合
*
* @param array $rawData
* @return LazyCollection
2025-11-27 13:40:58 +08:00
*/
2025-11-27 15:03:25 +08:00
public function entityMap(array $rawData): LazyCollection;
2025-11-27 13:40:58 +08:00
/**
2025-12-12 11:20:36 +08:00
* 获取实体的唯一键字段(用于 upsert 的 uniqueBy 参数)
2025-11-27 13:40:58 +08:00
*
2025-12-12 11:20:36 +08:00
* 定义哪些字段组成唯一约束
*
* @return array 唯一键字段名数组
2025-11-27 13:40:58 +08:00
*/
2025-12-12 11:20:36 +08:00
public function getUniqueBy(): array;
/**
* 获取可更新的字段列表(用于 upsert 的 update 参数)
*
* 明确定义哪些字段在更新时可以被修改
* 通常需要排除:主键、唯一键、创建时间、关联 ID 等不应变更的字段
*
* @return array 可更新字段名数组
*/
public function getUpdateFields(): array;
2025-11-27 13:40:58 +08:00
/**
2025-11-27 15:03:25 +08:00
* 获取消息数据
2025-11-27 13:40:58 +08:00
*
2025-11-27 15:03:25 +08:00
* @return array
2025-11-27 13:40:58 +08:00
*/
2025-11-27 15:03:25 +08:00
public function getData(): array;
2025-11-27 13:40:58 +08:00
2025-12-12 11:20:36 +08:00
/**
* 获取消息对象
*
2026-01-30 13:32:49 +08:00
* @return AMQPMessage
2025-12-12 11:20:36 +08:00
*/
2026-01-30 13:32:49 +08:00
public function getMessage(): AMQPMessage;
2025-12-12 11:20:36 +08:00
2025-11-27 13:40:58 +08:00
/**
* 获取平台对象
*
* @return Platform
*/
public function getPlatform(): Platform;
/**
* 获取公司对象
*
* @return Company
*/
public function getCompany(): Company;
/**
* 获取店铺对象
*
* @return Store
*/
public function getStore(): Store;
}