【问题标题】:Generate a Unique Key for Banking Transactions为银行交易生成唯一密钥
【发布时间】:2017-02-28 21:38:37
【问题描述】:

我想通过 HBCI 持续导入银行交易。 问题是,它们既没有唯一的密钥,也没有确切的时间戳(时间戳仅在日期分辨率上,即始终为 12AM)。

这是我从 API 获得的数据

在所有字段上生成哈希会导致误报(如果有人在同一天使用相同目的的文本传输相同的值等等)

如何避免重复导入并生成唯一键?

【问题讨论】:

  • 显而易见的解决方案是使用自动增量键。但是,我了解您希望使用通过 hbci 导入的数据字段来组成您的唯一密钥,并且如果在相同的本地和远程帐户之间的同一日期发生多个具有相同价值的交易,这将产生重复。请确认。
  • 我可以添加一个自动增量,但我仍然必须确定我已经转移了哪些交易。
  • 在这里遇到了同样的问题。我正在考虑简单地计算同一天的 auf 语句数。毕竟:如果两个语句完全相同,只要不存储两次,首先存储哪个语句并不重要。
  • @Juergen:这就是我在回答中所做的,对吧?并且账户表上可能有两次完全相同的语句,也应该导入两次。

标签: php algorithm banking


【解决方案1】:
/**
 * Generate a unique ID per transaction
 * We assume, that all transactions of a day are always present in the fetched transactions
 * (after a while, very old transactions might not appear)
 * So we generate a continues key per day, combine it with the date and have a globally unique key
 *
 * @return Transaction[]
 */
public static function getKeyedTransactions()
{
    $transactions = self::getTransactions();
    $result = [];
    $dateCounters = array();
    foreach($transactions as $transaction) {
        $date = $transaction->getDate()->format('Ymd');
        if (!isset($dateCounters[$date])) {
            $dateCounters[$date] = 0;
        }
        $dateCounters[$date]++;
        $uniqId = $date . sprintf('%05d', $dateCounters[$date]);
        $result[$uniqId] = $transaction;
    }
    return $result;
}

【讨论】:

  • 我认为:$date = $transaction->getBookingDate()->format('Ymd');做得更好。
猜你喜欢
  • 2010-09-08
  • 2023-04-04
  • 2013-07-18
  • 2012-04-09
  • 1970-01-01
  • 1970-01-01
  • 2012-03-04
  • 2015-03-06
  • 1970-01-01
相关资源
最近更新 更多