paymentLoad method

Future<EasyPacket<bool>> paymentLoad({
  1. required ComPage<Payment> comPage,
  2. required bool reload,
  3. required int start,
  4. required int end,
})

加载交易账单列表,reload为true时清除缓存重新加载,返回值EasyPacket.extra字段为true时表示已加载全部数据

Implementation

Future<EasyPacket<bool>> paymentLoad({required ComPage<Payment> comPage, required bool reload, required int start, required int end}) async {
  if (reload) comPage.pgcache.clear(); //清除缓存
  final last = comPage.pgcache.isEmpty ? 3742732800000 : comPage.pgcache.last.time; //2088-08-08 00:00:00 毫秒值 3742732800000
  final nin = <ObjectId>[]; //排除重复
  for (int i = comPage.pgcache.length - 1; i >= 0; i--) {
    final item = comPage.pgcache[i];
    if (item.time != last) break;
    nin.add(item.id);
  }
  comPage.pgasync = DateTime.now().microsecondsSinceEpoch; //设置最近一次异步加载的识别号(防止并发加载导致数据混乱)
  final response = await _aliveClient.websocketRequest('paymentLoad', data: {'bsid': bsid, 'last': last, 'nin': nin, 'pgasync': comPage.pgasync, 'start': start, 'end': end});
  if (response.ok) {
    final pgasync = response.data!['pgasync'] as int;
    final totalcnt = response.data!['totalcnt'] as int;
    final paymentList = response.data!['paymentList'] as List;
    if (pgasync == comPage.pgasync) {
      for (var data in paymentList) {
        comPage.pgcache.add(Payment.fromJson(data));
      }
      comPage.total = totalcnt;
      return response.cloneExtra(paymentList.isEmpty || comPage.total == comPage.pgcache.length); //是否已加载全部数据
    } else {
      _aliveClient.logError(['paymentLoad =>', '远程响应号已过期 $pgasync']);
      return response.requestTimeoutError().cloneExtra(null); //说明本次响应不是最近一次异步加载,直接遗弃数据,当成超时错误处理
    }
  } else {
    return response.cloneExtra(null);
  }
}