feat: 重构局域网数据同步与物理药瓶生命周期(Bottle Entity),实现开新瓶、软删除与多端精确余量核算
This commit is contained in:
+33
-15
@@ -4,12 +4,16 @@ class DoseRecord {
|
||||
final String id;
|
||||
final DateTime startTime;
|
||||
final DateTime endTime;
|
||||
final int flixotidePuffs; // 辅舒酮喷数
|
||||
final int ventolinPuffs; // 万托林喷数
|
||||
final bool rinsedMouth; // 是否漱口
|
||||
final bool washedFace; // 是否洗脸
|
||||
final bool isPrime; // 是否为试喷扣除
|
||||
final int flixotidePuffs; // 辅舒酮喷数
|
||||
final int ventolinPuffs; // 万托林喷数
|
||||
final String? flixotideBottleId; // 关联的辅舒酮药瓶 UUID
|
||||
final String? ventolinBottleId; // 关联的万托林药瓶 UUID
|
||||
final bool rinsedMouth; // 是否漱口
|
||||
final bool washedFace; // 是否洗脸
|
||||
final bool isPrime; // 是否为试喷扣除
|
||||
final bool isDeleted; // 软删除墓碑标记
|
||||
final String? note;
|
||||
final DateTime updatedAt; // UTC 更新时间
|
||||
|
||||
DoseRecord({
|
||||
required this.id,
|
||||
@@ -17,39 +21,53 @@ class DoseRecord {
|
||||
required this.endTime,
|
||||
this.flixotidePuffs = 0,
|
||||
this.ventolinPuffs = 0,
|
||||
this.flixotideBottleId,
|
||||
this.ventolinBottleId,
|
||||
this.rinsedMouth = true,
|
||||
this.washedFace = true,
|
||||
this.isPrime = false,
|
||||
this.isDeleted = false,
|
||||
this.note,
|
||||
});
|
||||
DateTime? updatedAt,
|
||||
}) : updatedAt = updatedAt ?? DateTime.now().toUtc();
|
||||
|
||||
Duration get duration => endTime.difference(startTime);
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'startTime': startTime.toIso8601String(),
|
||||
'endTime': endTime.toIso8601String(),
|
||||
'startTime': startTime.toUtc().toIso8601String(),
|
||||
'endTime': endTime.toUtc().toIso8601String(),
|
||||
'flixotidePuffs': flixotidePuffs,
|
||||
'ventolinPuffs': ventolinPuffs,
|
||||
'flixotideBottleId': flixotideBottleId,
|
||||
'ventolinBottleId': ventolinBottleId,
|
||||
'rinsedMouth': rinsedMouth,
|
||||
'washedFace': washedFace,
|
||||
'isPrime': isPrime,
|
||||
'isDeleted': isDeleted,
|
||||
'note': note,
|
||||
'updatedAt': updatedAt.toUtc().toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
factory DoseRecord.fromMap(Map<String, dynamic> map) {
|
||||
return DoseRecord(
|
||||
id: map['id'] as String,
|
||||
startTime: DateTime.parse(map['startTime'] as String),
|
||||
endTime: DateTime.parse(map['endTime'] as String),
|
||||
flixotidePuffs: map['flixotidePuffs'] as int? ?? 0,
|
||||
ventolinPuffs: map['ventolinPuffs'] as int? ?? 0,
|
||||
rinsedMouth: map['rinsedMouth'] as bool? ?? true,
|
||||
washedFace: map['washedFace'] as bool? ?? true,
|
||||
isPrime: map['isPrime'] as bool? ?? false,
|
||||
startTime: DateTime.parse(map['startTime'] as String? ?? (map['start_time'] as String)).toUtc(),
|
||||
endTime: DateTime.parse(map['endTime'] as String? ?? (map['end_time'] as String)).toUtc(),
|
||||
flixotidePuffs: map['flixotidePuffs'] as int? ?? (map['flixotide_puffs'] as int? ?? 0),
|
||||
ventolinPuffs: map['ventolinPuffs'] as int? ?? (map['ventolin_puffs'] as int? ?? 0),
|
||||
flixotideBottleId: map['flixotideBottleId'] as String? ?? (map['flixotide_bottle_id'] as String?),
|
||||
ventolinBottleId: map['ventolinBottleId'] as String? ?? (map['ventolin_bottle_id'] as String?),
|
||||
rinsedMouth: map['rinsedMouth'] as bool? ?? ((map['rinsed_mouth'] as int? ?? 1) == 1),
|
||||
washedFace: map['washedFace'] as bool? ?? ((map['washed_face'] as int? ?? 1) == 1),
|
||||
isPrime: map['isPrime'] as bool? ?? ((map['is_prime'] as int? ?? 0) == 1),
|
||||
isDeleted: map['isDeleted'] as bool? ?? ((map['is_deleted'] as int? ?? 0) == 1),
|
||||
note: map['note'] as String?,
|
||||
updatedAt: map['updatedAt'] != null
|
||||
? DateTime.parse(map['updatedAt'] as String).toUtc()
|
||||
: (map['updated_at'] != null ? DateTime.parse(map['updated_at'] as String).toUtc() : DateTime.now().toUtc()),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user