RecordFile.fromData constructor

RecordFile.fromData(
  1. int i,
  2. bool recordHead,
  3. Map data, {
  4. bool isTypeSearch = false,
})

Implementation

RecordFile.fromData(int i, bool recordHead, Map data,
    {bool isTypeSearch = false}) {
  this.record_head = recordHead;
  if (isTypeSearch == true) {
    this.record_name = data["record_name[$i]"];
    this.record_size = int.tryParse(data["record_size[$i]"] ?? "0")!;
  } else {
    this.record_name = data["record_name0[$i]"];
    this.record_size = int.tryParse(data["record_size0[$i]"] ?? "0")!;
  }
  record_alarm = 0;
  record_time = DateTime.now();
  List<String> splits = this.record_name?.split("_") ?? [];
  if (splits.length > 1 && splits[1].contains("010")) {
    record_alarm = 1;
  } else if (splits.length > 1 && splits[1].contains("011")) {
    record_alarm = 2;
  } else if (splits.length > 1 && splits[1].contains("012")) {
    record_alarm = 3;
  } else if (splits.length > 1 && splits[1].contains("013")) {
    record_alarm = 4;
  } else if (splits.length > 1 && splits[1].contains("014")) {
    //区域入侵
    record_alarm = 5;
  } else if (splits.length > 1 && splits[1].contains("015")) {
    //人逗留
    record_alarm = 6;
  } else if (splits.length > 1 && splits[1].contains("016")) {
    //车违停
    record_alarm = 7;
  } else if (splits.length > 1 && splits[1].contains("017")) {
    //越线检测
    record_alarm = 8;
  } else if (splits.length > 1 && splits[1].contains("018")) {
    //离岗检测
    record_alarm = 9;
  } else if (splits.length > 1 && splits[1].contains("019")) {
    //车辆逆行
    record_alarm = 10;
  } else if (splits.length > 1 && splits[1].contains("020")) {
    //包裹
    record_alarm = 11;
  }
  String date = splits[0];
  if (date != null) {
    int? year = int.tryParse(date.substring(0, 4));
    int? month = int.tryParse(date.substring(4, 6));
    int? day = int.tryParse(date.substring(6, 8));
    int? hour = int.tryParse(date.substring(8, 10));
    int? minute = int.tryParse(date.substring(10, 12));
    int? second = int.tryParse(date.substring(12, 14));
    if (year == null ||
        month == null ||
        day == null ||
        hour == null ||
        minute == null ||
        second == null) {
      return;
    }
    record_time = DateTime(year, month, day, hour, minute, second);
  }
}