67 lines
3.0 KiB
Dart
67 lines
3.0 KiB
Dart
|
|
// 功能描述:用户可见的配送人员、资质、配送点及订单交付快照;版本:1.0.0。
|
|||
|
|
class DeliveryProduct {
|
|||
|
|
const DeliveryProduct({required this.name, required this.quantity});
|
|||
|
|
final String name;
|
|||
|
|
final int quantity;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// 只接受本人配送接口的显式事实;不可用能力保留布尔状态,不由客户端猜测。
|
|||
|
|
class DeliveryDetail {
|
|||
|
|
DeliveryDetail.fromJson(Map<String, Object?> data)
|
|||
|
|
: identity = _required(data, 'identity'),
|
|||
|
|
orderNo = _required(data, 'order_no'),
|
|||
|
|
statusName = _required(data, 'status_name'),
|
|||
|
|
statusMessage = _required(data, 'status_message'),
|
|||
|
|
address = _required(data, 'address'),
|
|||
|
|
contactName = _required(data, 'contact_name'),
|
|||
|
|
contactPhoneMasked = _required(data, 'contact_phone_masked'),
|
|||
|
|
stationName = _text(data, 'station_name'),
|
|||
|
|
deliveryName = _text(data, 'delivery_name'),
|
|||
|
|
deliveryAddress = _text(data, 'delivery_address'),
|
|||
|
|
staffName = _text(data, 'staff_name'),
|
|||
|
|
staffAvatar = _text(data, 'staff_avatar'),
|
|||
|
|
credentialType = _text(data, 'credential_type'),
|
|||
|
|
appointmentAt = DateTime.parse(_required(data, 'appointment_at')).toLocal(),
|
|||
|
|
trackUpdatedAt = _date(data['track_updated_at']),
|
|||
|
|
staffAssigned = _flag(data, 'staff_assigned'),
|
|||
|
|
credentialVerified = _flag(data, 'credential_verified'),
|
|||
|
|
trackAvailable = _flag(data, 'track_available'),
|
|||
|
|
controlledCallAvailable = _flag(data, 'controlled_call_available'),
|
|||
|
|
messageAvailable = _flag(data, 'message_available'),
|
|||
|
|
vehicleConfigured = _flag(data, 'vehicle_configured'),
|
|||
|
|
products = List.unmodifiable([
|
|||
|
|
for (final row in data['products'] as List)
|
|||
|
|
DeliveryProduct(
|
|||
|
|
name: _required(Map<String, Object?>.from(row as Map), 'name'),
|
|||
|
|
quantity: (row['quantity'] as int?) ?? 0,
|
|||
|
|
),
|
|||
|
|
]) {
|
|||
|
|
if (products.any((item) => item.quantity < 1)) throw const FormatException('配送商品数量异常');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
final String identity, orderNo, statusName, statusMessage, address, contactName;
|
|||
|
|
final String contactPhoneMasked, stationName, deliveryName, deliveryAddress, staffName;
|
|||
|
|
final String staffAvatar;
|
|||
|
|
final String credentialType;
|
|||
|
|
final DateTime appointmentAt;
|
|||
|
|
final DateTime? trackUpdatedAt;
|
|||
|
|
final bool staffAssigned, credentialVerified, trackAvailable;
|
|||
|
|
final bool controlledCallAvailable, messageAvailable, vehicleConfigured;
|
|||
|
|
final List<DeliveryProduct> products;
|
|||
|
|
|
|||
|
|
static String _text(Map<String, Object?> data, String key) => data[key] as String? ?? '';
|
|||
|
|
static String _required(Map<String, Object?> data, String key) {
|
|||
|
|
final value = _text(data, key);
|
|||
|
|
if (value.trim().isEmpty) throw FormatException('配送资料不完整:$key');
|
|||
|
|
return value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static bool _flag(Map<String, Object?> data, String key) {
|
|||
|
|
if (data[key] is! bool) throw FormatException('配送状态异常:$key');
|
|||
|
|
return data[key] as bool;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static DateTime? _date(Object? value) =>
|
|||
|
|
value == null ? null : DateTime.tryParse('$value')?.toLocal();
|
|||
|
|
}
|