'esun_lingxing_order_sync', 'shipment' => 'esun_lingxing_shipment_sync', ]; public function __construct(private readonly ResourceConnection $resource) { } /** @return array|null */ public function getRecord(string $type, int $id): ?array { $table = $type === 'log' ? 'esun_lingxing_sync_log' : (self::SYNC_TABLES[$type] ?? ''); if ($table === '' || $id <= 0) { return null; } $connection = $this->resource->getConnection(); $row = $connection->fetchRow( $connection->select() ->from($this->resource->getTableName($table)) ->where('entity_id = ?', $id) ->limit(1) ); return is_array($row) && $row !== [] ? $row : null; } /** @return array> */ public function getLogs(string $type, array $record): array { if ($type === 'log') { return [$record]; } if (!isset(self::SYNC_TABLES[$type])) { return []; } $connection = $this->resource->getConnection(); $select = $connection->select() ->from($this->resource->getTableName('esun_lingxing_sync_log')) ->where('entity_type = ?', $type) ->order('entity_id DESC'); $localId = (int)($record['entity_id'] ?? 0); $requestId = trim((string)($record['request_id'] ?? '')); if ($requestId !== '') { $select->where(sprintf( '(%s OR %s)', $connection->quoteInto('local_entity_id = ?', $localId), $connection->quoteInto('request_id = ?', $requestId) )); } else { $select->where('local_entity_id = ?', $localId); } return $connection->fetchAll($select); } }